Repository navigation
Conversation
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.
🔗 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.
|
Contributor
Author
|
@pytorchbot label "release notes: ops & kernels" |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
can_use_optimized_dequantize_per_channeldecided fromout_dtypewhether the output is float, so withoutout_dtypea contiguous int8 input took the optimized path even for a Half or Doubleout, and that path writes float (reproduction in #25877). For a Halfoutthat is an out-of-bounds write. The helper anddequantize_per_channel_optimizednow checkout.scalar_type(), whichcheck_dequantize_per_tensor_argsalready ties toout_dtypewhen 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 keptoutas the source of the output dtype, as the generic path already does, rather than treating a missingout_dtypeas 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 Halfout, 1-D and 2-D input, noout_dtype). Before the change the Double cases returned wrong values and the test binary then crashed.Through
quantized_ops_aot_lib, the same call with a Half or Doubleoutused to raiseexpected scalar type Float; it now returns the expected values.pytest exir runtime/test kernels/quantized/testfails 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