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 }}
quantize_per_tensor and quantize_per_channel give wrong values on AArch64 for a zero point far from the quantized range聽#25969
On AArch64, the float to int8/uint8 path of quantize_per_tensor and quantize_per_channel (quantize_arm in kernels/quantized/cpu/op_quantize.cpp) narrows the rounded value to int16 with saturation, then adds the zero point cast to int16. The callers also cast the zero point to int32 first. When the zero point does not fit, or when the value saturates before the addition, the result differs from the scalar path and from the eager op, and the vectorized elements disagree with the scalar tail of the same tensor.
I found this by reading the code while working on #25824; I do not have a model that hits it, since such zero points are far outside the usual range.
With nine float32 values, so that eight go through the vector loop (tf is a Float factory, out a Char tensor):
quantize_per_tensor_out(tf.full({9}, -39990), 1.0, 40000, -128, 127, ScalarType::Char, out);
// eager and x86-64: 10 everywhere. AArch64: -128 x 8, then 10quantize_per_tensor_out(tf.full({9}, 40000), 1.0, -32768, -128, 127, ScalarType::Char, out);
// eager and x86-64: 127 everywhere. AArch64: -1 x 8, then 127quantize_per_tensor_out(tf.full({9}, 1), 1.0, 4294967301, -128, 127, ScalarType::Char, out);
// eager and x86-64: 127 everywhere. AArch64: 6 everywhere
quantize_per_channel to uint8 with the first input gives 0 x 8, then 10. I have a small fix that sends such zero points to the scalar path, with a C++ test, and will open a PR linked to this issue.
Versions
ExecuTorch built from main at 9b9fa24, quantized_kernels_test cross-compiled with aarch64-linux-gnu-g++ 13.3.0 and run under qemu-aarch64 8.2.2 (I have no ARM hardware), eager reference from PyTorch 2.15.0+cpu, Ubuntu 24.04 on WSL2.
This issue was written with the help of Claude Code (Anthropic); I verified the reproduction.
Activity