Preserve buffer mutation tracking for index_put_ in convert_pt2e#4241
Preserve buffer mutation tracking for index_put_ in convert_pt2e#4241MagellaX wants to merge 1 commit intopytorch:mainfrom
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4241
Note: Links to docs will display an error until the docs builds have been completed. ❌ 9 New FailuresAs of commit 2ce4c2e with merge base 6e7a6e9 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
any takes @jerryzh168 ?? |
|
@claude review please |
|
Claude finished @andrewor14's task in 5m 20s —— View job Code Review for PR #4241
SummaryThis PR addresses a real bug: The fix uses op schema introspection ( CorrectnessThe core approach is sound. The
Issues1. Style inconsistency in the test — The test imports and uses 2. Comment is now misleading — The comment says "didn't find corresponding quantize op and info for the activation_post_process" but now this branch also handles the 3. Naming: The function name Edge Cases to Consider4. Interaction with The constant folding code at 5. Non-ATen ops without The Test ReviewThe test (
One minor suggestion: the test could also verify that the value argument (args[2]) of VerdictThe fix is correct and well-targeted. The main feedback items are (1) the style inconsistency with |
What changed
This fixes PT2E convert for modules that mutate a registered buffer via
index_put_.Previously, the convert path was lowering the observed destination buffer to
quantize -> dequantizebeforeindex_put_. That changed the mutation from the real buffer to a temporary tensor, so after re-export:buffers_to_mutatedisappearedfold_quantize=True, the buffer input could also get folded into_frozen_param0This PR preserves observed inputs when they feed a write-alias argument, so the converted graph still mutates the original buffer. It also adds a regression test covering both
fold_quantize=Falseandfold_quantize=Trueusing the exact repro from#4138.Why
This issue is really a mutation-preservation bug in
convert_pt2e, not just a constant-folding issue.By keeping the original mutable buffer input intact at the write site, re-export preserves both:
inputs_to_buffersbuffers_to_mutateValidation
ruff checkon touched filespython -m compileall torchao/quantization/pt2e/convert.py test/quantization/pt2e/test_quantize_pt2e.pyfold_quantize=Falsefold_quantize=Truepython -m pytest %TEMP%/test_issue4138_repro.py -q1 passedaddresses #4138