Skip to content

Qualcomm AI Engine Direct - Preserve partition metadata on single-output delegate getitem nodes#20805

Open
DannyYuyang-quic wants to merge 1 commit into
pytorch:mainfrom
CodeLinaro:dev1/danny/fix_delegate-getitem-metadata
Open

Qualcomm AI Engine Direct - Preserve partition metadata on single-output delegate getitem nodes#20805
DannyYuyang-quic wants to merge 1 commit into
pytorch:mainfrom
CodeLinaro:dev1/danny/fix_delegate-getitem-metadata

Conversation

@DannyYuyang-quic

Copy link
Copy Markdown
Contributor

Summary

The single-output path in create_submodule_from_nodes copied only "val" onto the manually-built getitem, dropping other partition meta (e.g. QNN's q_tensor_io tag) that the multi-output path keeps via propagate_meta, leaving backend IO-tagging passes with wrong delegate dtype/spec.

Fix by propagating full meta then dropping nn_module_stack/source_fn_stack, matching the multi-output path.

The single-output path in `create_submodule_from_nodes` copied only "val"
onto the manually-built getitem, dropping other partition meta (e.g. QNN's
q_tensor_io tag) that the multi-output path keeps via propagate_meta,
leaving backend IO-tagging passes with wrong delegate dtype/spec.

Fix by propagating full meta then dropping nn_module_stack/source_fn_stack, matching the multi-output path.
@pytorch-bot

pytorch-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⚠️ 11 Awaiting Approval

As of commit 3b99a81 with merge base 2265ab8 (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 Jul 9, 2026
@DannyYuyang-quic

DannyYuyang-quic commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@psiddh @larryliu0820 @JacobSzwejbka Hi,
We ran into a node metadata loss issue while sharding Gemma4 into multiple shards, and it traces back to create_submodule_from_nodes in exir/lowered_backend_module.py. Sharding produces multiple delegates, some single-output, some multi-output, and the single-output ones are exactly what triggers this bug:
The getitem node for a single-output delegate drops the metadata carried by its upstream delegate output, whereas multi-output delegates preserve it. I put together a couple of before/after diagrams and wanted to run my understanding (and the fix) by you.

What's happening and Root cause

We use TagQuantIO Pass to tag the partition input/output with q_tensor_io=uint16 in node's metadata before to_backend, and BuildQuantIO Pass uses that tag to assign delegate IO's dtype/spec after to_backend.

single-output and multi-output take two different paths:

Fix

Bring the single-output branch in line with multi-output: use replace_all_uses_with(proxy_out, propagate_meta=True) to carry the full meta, then pop nn_module_stack / source_fn_stack. Now both paths behave the same, and we still make sure the source-tracking meta doesn't leak onto the delegate getitem. (see Graph 2).

[Graph 1] Before the fix: getitem is missing q_tensor_io [Graph 2] After the fix: getitem carries q_tensor_io=torch.uint16
call_delegate_before_changes call_delegate_after_changes

Question

I wanted to check with you, since you have more historical background here, was the single-output branch only copying val on purpose? My change makes it "copy everything + pop the source-tracking keys" to match the multi-output path, but I might be missing some context. Are there any side effects or edge cases I should be aware of? Happy to adjust the approach if there's a better way to handle this.

Thanks so much for taking a look!!

cc: @shewu-quic @haowhsu-quic @winskuo-quic

@winskuo-quic
winskuo-quic requested a review from psiddh July 16, 2026 00:27
@DannyYuyang-quic DannyYuyang-quic changed the title Preserve partition metadata on single-output delegate getitem nodes Qualcomm AI Engine Direct - Preserve partition metadata on single-output delegate getitem nodes Jul 20, 2026
@DannyYuyang-quic

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 Jul 20, 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. release notes: qualcomm Changes to the Qualcomm backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant