fix(cadence): fix or-precedence bug in check_out_zero_point_is_min_range#20608
Open
durvesh1992 wants to merge 1 commit into
Open
fix(cadence): fix or-precedence bug in check_out_zero_point_is_min_range#20608durvesh1992 wants to merge 1 commit into
durvesh1992 wants to merge 1 commit into
Conversation
check_out_zero_point_is_min_range had:
elif out_dtype == torch.uint8 or torch.uint16:
which Python parses as `(out_dtype == torch.uint8) or (torch.uint16)`.
torch.uint16 is always truthy, so the branch matched for every dtype
that is not int8/int16 and the trailing `return False` became dead code.
As a result the function returned `out_zero_point == 0` for unrelated
dtypes (e.g. float32, int32) instead of False.
This gates Add+ReLU fusion in quantizer/patterns.py, so an output whose
dtype is not a supported quant type but whose zero point is 0 would
wrongly pass the check. Compare each dtype explicitly.
Add a unit test covering signed, unsigned, and non-quant dtypes.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20608
Note: Links to docs will display an error until the docs builds have been completed.
|
|
This PR needs a
|
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
check_out_zero_point_is_min_range(backends/cadence/aot/quantizer/utils.py) contained an operator-precedence bug:Python parses this as
(out_dtype == torch.uint8) or (torch.uint16). Sincetorch.uint16is a (truthy) dtype object, theelifis effectively alwaysTruefor any dtype that isn'tint8/int16, and the trailingreturn Falseis dead code.Effect: for unrelated dtypes such as
float32orint32, the function returnedout_zero_point == 0instead ofFalse.The function gates Add+ReLU fusion in
quantizer/patterns.py(AddReluPattern.get_anchors), so an output whose dtype is not a supported quant type but whose zero point happens to be 0 would wrongly pass the check.Fix: compare
out_dtypeagainst each dtype explicitly:Test plan
Adds
backends/cadence/aot/tests/test_quantizer_utils.pycovering signed (int8/int16), unsigned (uint8/uint16), and non-quant (float32/int32) dtypes.test_non_quant_dtype_is_falsefails (float32/int32with zero point 0 returnTrue).Run: