Skip to content

fix(pt2e): insert activation input observers before consumer node - #5041

Open
devtyagi3909 wants to merge 1 commit into
pytorch:mainfrom
devtyagi3909:fix-prepare-pt2e-input-observer-placement
Open

devtyagi3909 wants to merge 1 commit into
pytorch:mainfrom
devtyagi3909:fix-prepare-pt2e-input-observer-placement

Conversation

@devtyagi3909

Copy link
Copy Markdown

fixes #5040

what changed

activation input observers were previously placed right after the producer node with insert_obs_or_fq (graph.inserting_after(arg)). when an intermediate buffer is mutated in-place or written through views prior to consumption (like buf = x.new_zeros(...); buf.select(0, 0).copy_(x); conv(buf)), the observer was inserted before the write completed, observing zeros and causing the consumer to ignore the input.

updated _maybe_insert_input_observer_for_arg_or_kwarg to insert activation input observers before the consumer node (with graph.inserting_before(node):). get_attr nodes (weights/params) continue inserting after arg to preserve parameter quantization node order.

test plan

added test_inplace_view_write_activation_input_observed in test/quantization/pt2e/test_quantize_pt2e.py verifying that in-place view writes propagate through quantization. all 75 pt2e unit tests pass.

Fixes pytorch#5040

When inserting input observers in prepare_pt2e, intermediate activation tensors
were previously observed immediately after their producing node via
insert_obs_or_fq (inserting_after(arg)). If the activation undergoes in-place
mutations or writes through views prior to being consumed (e.g. new_zeros followed
by select().copy_()), the observer was placed before the mutation, capturing
uninitialized/zero data and causing the quantized consumer to ignore inputs.

Update _maybe_insert_input_observer_for_arg_or_kwarg to insert activation input
observers immediately before the consumer node using inserting_before(node), while
preserving insertion after get_attr nodes for static parameters/weights.

Signed-off-by: DEV TYAGI <[email protected]>
@pytorch-bot

pytorch-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/5041

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 Oct 30, 2026

This branch has not been deployed

No deployments
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.

prepare_pt2e observes a tensor before an in-place write through a view, so the quantized model ignores its input

1 participant