Skip to content

Place pt2e input observers after in-place writes through views - #5046

Closed
msluszniak wants to merge 2 commits into
pytorch:mainfrom
msluszniak:ms/pt2e-in-place-write-observers
Closed

msluszniak wants to merge 2 commits into
pytorch:mainfrom
msluszniak:ms/pt2e-in-place-write-observers

Conversation

@msluszniak

@msluszniak msluszniak commented Oct 31, 2026 •

Copy link
Copy Markdown

Fixes #5040.

prepare_pt2e now replaces in-place ops on tensors created in the graph with their functional variants (through select/slice/diagonal/as_strided views) before annotation. Writes to inputs and buffers are unchanged.

Test: test_quantize_buffer_filled_in_place_through_view (fails on main for both quantizers). pt2e suites pass locally.

prepare_pt2e inserted an input observer right after the producer, so a tensor
filled later through a view (e.g. buf.select(0, 0).copy_(x)) was observed, and
after convert read, before the write. Observers on such a view chain also made
the write land on a dequantized copy.

Fixes pytorch#5040
@pytorch-bot

pytorch-bot Bot commented Oct 31, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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.

@msluszniak
msluszniak requested a review from vkuzo as a code owner October 31, 2026 11:27
@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 31, 2026
@jerryzh168

jerryzh168 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

I think to simplify the flow we don't want to support inplace ops, an easier way is probably to change inplace ops to non-inplace first and then run the normal flow (downstream lowering can add inplace ops back if needed), or skip quantizing inplace ops

@msluszniak

Copy link
Copy Markdown
Author

I think to simplify the flow we don't want to support inplace ops, an easier way is probably to change inplace ops to non-inplace first and then run the normal flow (downstream lowering can add inplace ops back if needed)

Sure, I can rewrite this one to work the way you described it.

@jerryzh168

jerryzh168 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

@msluszniak can you add this to the quantizer you are using? core pt2e flow probably should not take a side on whether to change inplace ops to non inplace ops or just skip quantizing these

@msluszniak

Copy link
Copy Markdown
Author

Thanks, moved it into the ExecuTorch XNNPACK and QNN quantizers: pytorch/executorch#24499. Closing this one.

@msluszniak msluszniak closed this Nov 3, 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.

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

2 participants