Fix constant_fold cleanup for shared get_attr targets#4542
Draft
Kevin-Li-2025 wants to merge 1 commit into
Draft
Fix constant_fold cleanup for shared get_attr targets#4542Kevin-Li-2025 wants to merge 1 commit into
Kevin-Li-2025 wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4542
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
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
Fixes
constant_foldcleanup when multipleget_attrnodes reference the same module attribute.Before this change,
constant_folddeleted the underlying GraphModule attribute as soon as it found one deadget_attrnode. If another liveget_attrnode still referenced the same target, the graph became invalid and failed linting with:This patch keeps the existing dead-node cleanup, but only deletes the underlying attribute when no other live
get_attrnode still uses the same target.Test plan
PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=. /tmp/torchao-test-venv/bin/python -m unittest test.quantization.pt2e.test_quantize_pt2e.TestConstantFold.test_shared_get_attr_target_stays_liveruff check torchao/quantization/pt2e/constant_fold.py test/quantization/pt2e/test_quantize_pt2e.pygit diff --checkFixes #4420.