Skip to content

Take the optimized dequantize_per_channel path only for a float output - #25878

Open
AxelNoun wants to merge 1 commit into
pytorch:mainfrom
AxelNoun:fix/et-8-dequantize-optimized-out-dtype
Open

AxelNoun wants to merge 1 commit into
pytorch:mainfrom
AxelNoun:fix/et-8-dequantize-optimized-out-dtype

Conversation

@AxelNoun

@AxelNoun AxelNoun commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

can_use_optimized_dequantize_per_channel decided from out_dtype whether the output is float, so without out_dtype a contiguous int8 input took the optimized path even for a Half or Double out, and that path writes float (reproduction in #25877). For a Half out that is an out-of-bounds write. The helper and dequantize_per_channel_optimized now check out.scalar_type(), which check_dequantize_per_tensor_args already ties to out_dtype when one is given. Half and Double outputs go through the generic path; other non-float outputs now stop at its "Unhandled output dtype" check. Float outputs take the optimized path as before. I kept out as the source of the output dtype, as the generic path already does, rather than treating a missing out_dtype as float.

This touches the same function as #25824; whichever lands second, I will rebase it.

Fixes #25877

Test plan

New C++ test DequantizePerChannelOutputDtypeFromOut (Double and Half out, 1-D and 2-D input, no out_dtype). Before the change the Double cases returned wrong values and the test binary then crashed.

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

Through quantized_ops_aot_lib, the same call with a Half or Double out used to raise expected scalar type Float; it now returns the expected values. 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

can_use_optimized_dequantize_per_channel decided from out_dtype whether the
output is float, so without out_dtype a contiguous int8 input took the
optimized path for any out, and that path writes float: a Half out got an
out-of-bounds write and a Double out wrong values. Check out.scalar_type()
in the helper and in dequantize_per_channel_optimized instead. Half and
Double outs now go through the generic path; other non-float outs reach its
"Unhandled output dtype" check instead of being written as float.
@pytorch-bot

pytorch-bot Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⚠️ 18 Awaiting Approval

As of commit 010f202 with merge base 035df43 (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.

@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 Dec 1, 2026
@AxelNoun

AxelNoun commented Dec 1, 2026

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 Dec 1, 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.

dequantize_per_channel writes float into a Half or Double out tensor when out_dtype is not given

1 participant