Skip to content

Qualcomm AI Engine Direct - Replace in-place writes before annotation - #25202

Open
msluszniak wants to merge 3 commits into
pytorch:mainfrom
msluszniak:ms/qnn-quantizer-in-place-writes
Open

msluszniak wants to merge 3 commits into
pytorch:mainfrom
msluszniak:ms/qnn-quantizer-in-place-writes

Conversation

@msluszniak

Copy link
Copy Markdown
Contributor

Summary

QNN half of #24499 (split per review). QnnQuantizer now runs ReplaceInplaceOpsPass in transform_for_annotation, so observers see values written in place through a view (pytorch/ao#5040). Depends on #24499, which adds the pass.

Test plan

New test_quantizer_observes_buffer_after_in_place_write in qualcomm test_passes.py: fails on main, passes with QAIRT 2.47.

cc @psiddh @nil-is-all

prepare_pt2e observes a tensor before a later in-place write through a view,
so the quantized model ignores what was written (torchvision's batch_images
fills new_full with copy_). Add a replace_in_place_ops transform that rewrites
such writes to their functional variants, and call it from
XNNPACKQuantizer.transform_for_annotation. Writes to graph inputs and buffers
are kept.
A write was rewritten even when the written view, or the in-place op's
result, was used again afterwards, so a second write or read through it
saw the old value. The alias check also missed unbind/split getitems. Keep
those writes, and leave direct in-place ops alone, since later reads
already use the in-place node.

Rewrite only copy_, fill_, zero_ and arithmetic writes through select,
slice and diagonal, compute val for the new nodes under the fake mode, and
copy only provenance meta. Make the transform a PassBase,
ReplaceInplaceOpsPass, and log the writes it keeps.
prepare_pt2e observes a tensor before a later in-place write through a view,
so the quantized model ignores what was written. QnnQuantizer also annotates
select, so its observers split the view chain and copy_ wrote into a
dequantized copy of the buffer. Run ReplaceInplaceOpsPass in
QnnQuantizer.transform_for_annotation.
@pytorch-bot

pytorch-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25202

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 19 Awaiting Approval

As of commit 7396ca2 with merge base 5c81773 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

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 Nov 18, 2026
@msluszniak

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: qualcomm"

@pytorch-bot pytorch-bot Bot added the release notes: qualcomm Changes to the Qualcomm backend delegate label Nov 18, 2026
@executorch-triage executorch-triage Bot added the community: contribution PRs coming from community (excluding hardware partners) label Nov 18, 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. community: contribution PRs coming from community (excluding hardware partners) release notes: qualcomm Changes to the Qualcomm backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant