You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
dequantize_per_channel writes float into a Half or Double out tensor when out_dtype is not given #25877
can_use_optimized_dequantize_per_channel (kernels/quantized/cpu/op_dequantize.cpp) only rejects a non-float output when out_dtype is given; it never looks at out.scalar_type(). With a contiguous int8 input, no out_dtype and a Half or Double out, the kernel takes the optimized path, which writes through out.mutable_data_ptr<float>(). In portable mode that write is not type-checked: a Half output gets 4 bytes per element in a 2-byte buffer, and a Double output gets garbage. The generic path, which dispatches on out.scalar_type(), would return the right values. I found this by reading the code while working on #25824.
Minimal C++ reproduction (added to kernels/quantized/test/op_dequantize_test.cpp):
With a Double out the values are 1.50324e+10 and 0, and the test binary then crashes. Through quantized_ops_aot_lib (ATen mode), the same call raises RuntimeError: expected scalar type Float but found Half instead. A program exported the usual way allocates a float output when out_dtype is not given, so it does not hit this path; a direct kernel call or a program with a non-float output does.
I would expect the optimized path to be used only for a float out. I have a one-condition fix with a test and will open a PR linked to this issue.
Versions
ExecuTorch built from main at d34221b, PyTorch 2.15.0+cpu, Ubuntu 24.04 on WSL2, x86_64.
This issue was written with the help of Claude Code (Anthropic); I verified the reproduction.
Activity