Skip to content

Fix constant_fold cleanup for shared get_attr targets#4542

Draft
Kevin-Li-2025 wants to merge 1 commit into
pytorch:mainfrom
Kevin-Li-2025:kevin/fix-constant-fold-shared-getattr
Draft

Fix constant_fold cleanup for shared get_attr targets#4542
Kevin-Li-2025 wants to merge 1 commit into
pytorch:mainfrom
Kevin-Li-2025:kevin/fix-constant-fold-shared-getattr

Conversation

@Kevin-Li-2025

Copy link
Copy Markdown

Summary

Fixes constant_fold cleanup when multiple get_attr nodes reference the same module attribute.

Before this change, constant_fold deleted the underlying GraphModule attribute as soon as it found one dead get_attr node. If another live get_attr node still referenced the same target, the graph became invalid and failed linting with:

Node shared_1 target shared references nonexistent attribute shared

This patch keeps the existing dead-node cleanup, but only deletes the underlying attribute when no other live get_attr node 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_live
  • ruff check torchao/quantization/pt2e/constant_fold.py test/quantization/pt2e/test_quantize_pt2e.py
  • git diff --check

Fixes #4420.

@pytorch-bot

pytorch-bot Bot commented Jun 28, 2026

Copy link
Copy Markdown

🔗 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.

@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 Jun 28, 2026
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

constant_fold deletes shared get_attr target while another get_attr for the same target is still live

1 participant