quantize_per_channel and dequantize_per_tensor.tensor abort the process on a float32 scale

Đang mở
#25,873 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@AxelNoun đang làm issue này rồi.

Từ ngày 30/11/2026.

  • #25874 của @AxelNoun — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
cpp, python, pytorch
Lĩnh vực
backend, machine-learning

Hướng nghiên cứu

Read kernels/quantized/cpu/op_quantize.cpp around quantize_per_channel_out and op_dequantize.cpp around dequantize_per_tensor_tensor_args_out; compare their scale handling with dequantize_per_channel. The report includes a Python reproduction using float32 scales and says C++ tests are part of the proposed fix. Done means the affected operations accept float32 scales without aborting and their results match eager; pull request #25874 is already open.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

🐛 Describe the bug

quantize_per_channel_out (kernels/quantized/cpu/op_quantize.cpp) and dequantize_per_tensor_tensor_args_out (op_dequantize.cpp) require a float64 scale tensor and check it with ET_CHECK_MSG, so a float32 scale aborts the process instead of execute() returning an error. quantize_per_tensor.tensor refuses it too, with InvalidArgument. The eager ops accept float32 scales, and dequantize_per_channel already does. I found this while comparing the runtime's outputs with eager on small exported programs.

import torch
import executorch.kernels.quantized  # registers the out variants
from executorch.exir import to_edge
from executorch.runtime import Runtime

scales = torch.tensor([0.1, 0.5, 2.0])  # float32
zero_points = torch.tensor([0, -3, 4])

class M(torch.nn.Module):
    def forward(self, t):
        return torch.ops.quantized_decomposed.quantize_per_channel(
            t, scales, zero_points, 0, -128, 127, torch.int8
        )

x = torch.randn(3, 4) * 3
prog = to_edge(torch.export.export(M(), (x,))).to_executorch()
Runtime.get().load_program(prog.buffer).load_method("forward").execute([x])
[op_quantize.cpp:452] In function quantize_per_channel_out(), assert failed (scale.scalar_type() == ScalarType::Double): scale.scalar_type() 6 is not double type

The process is then killed by SIGABRT, on axes 0, 1 and -1 alike. dequantize_per_tensor.tensor with a float32 scale aborts at op_dequantize.cpp:345 (Expected scale to be Double tensor received: 6), and quantize_per_tensor.tensor fails with error 0x12. With float64 scales all three run and match eager.

I would expect float32 scales to be read like float64 ones, as dequantize_per_channel does. I have a small fix with C++ tests and will open a PR linked to this issue.

Versions

ExecuTorch built from main at e67ec4e (Python bindings and quantized_ops_aot_lib built from source), PyTorch 2.15.0+cpu, Python 3.12.3, Ubuntu 24.04 on WSL2, x86_64.

This issue was written with the help of Claude Code (Anthropic); I verified the reproduction.

Ngôn ngữ chính
Python
Star
5.2k
Fork
1.3k
Merge trung bình
1 ngày 7 giờ
Pull request đã merge (30 ngày)
644

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của pytorch/executorch

Tất cả issue của pytorch/executorch

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.