Skip to content

Accept float32 scales in the quantized quantize and dequantize kernels - #25874

Open
AxelNoun wants to merge 1 commit into
pytorch:mainfrom
AxelNoun:fix/et-3-quantize-float-scale
Open

AxelNoun wants to merge 1 commit into
pytorch:mainfrom
AxelNoun:fix/et-3-quantize-float-scale

Conversation

@AxelNoun

@AxelNoun AxelNoun commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

quantize_per_channel and dequantize_per_tensor.tensor checked for a float64 scale with ET_CHECK_MSG, so a float32 scale aborted the process, and quantize_per_tensor.tensor failed with InvalidArgument (reproduction in #25873). They now accept Float and Double scales, as dequantize_per_channel already does; quantize_per_token, which goes through quantize_per_channel, gets the same. Other scale dtypes are still rejected, and float64 scales give the same results as before. choose_qparams keeps its float64 output, like the eager op, and the Cadence copies of these kernels are left as they are.

This touches quantize_per_channel_out like #25824; whichever lands second, I will rebase it.

Fixes #25873

Test plan

New C++ cases: QuantizePerChannelFloatScale (axes 0 and 1), QuantizePerTokenFloatScale, and TensorArgOverloadFloatScale for quantize (which also checks that a Half scale still fails with InvalidArgument) and for dequantize. Before the change they aborted on the scale dtype check, or returned error 0x12.

cmake --build cmake-out --target quantized_kernels_test
./cmake-out/kernels/test/quantized_kernels_test   # 98 tests passed
ctest --output-on-failure                         # 90/90 passed

Through the Python runtime, the three ops with float32 scales now match eager PyTorch exactly on 4096 random values per case, for int8, uint8 and int16. pytest exir runtime/test kernels/quantized/test fails only where it already fails on main in my build (XNNPACK and demo backends, not built).

This PR was authored with the help of Claude Code (Anthropic); I reviewed and tested it.

cc @nil-is-all

quantize_per_channel and dequantize_per_tensor.tensor checked for a float64
scale with ET_CHECK_MSG, so a float32 scale aborted the process.
quantize_per_tensor.tensor failed with InvalidArgument through the runtime
and aborted through its context-free overload. They now accept Float and
Double scales, as dequantize_per_channel already does, which also lets
quantize_per_token, built on quantize_per_channel, take float32 scales.
Other scale dtypes are still rejected.
@pytorch-bot

pytorch-bot Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25874

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 18 Awaiting Approval

As of commit ee7bffc with merge base 12eeda1 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@AxelNoun

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: ops & kernels"

@pytorch-bot pytorch-bot Bot added the release notes: ops & kernels Changes to the opset and any new / changed kernel implementations label Nov 30, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 30, 2026
@executorch-triage executorch-triage Bot added the community: contribution PRs coming from community (excluding hardware partners) label Dec 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. community: contribution PRs coming from community (excluding hardware partners) release notes: ops & kernels Changes to the opset and any new / changed kernel implementations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant