Skip to content

Qualcomm: reject a delegate whose QNN graph I/O does not match its si… - #22239

Open
psiddh wants to merge 1 commit into
pytorch:mainfrom
psiddh:qnn-aot-io-binding-check
Open

Qualcomm: reject a delegate whose QNN graph I/O does not match its si…#22239
psiddh wants to merge 1 commit into
pytorch:mainfrom
psiddh:qnn-aot-io-binding-check

Conversation

@psiddh

@psiddh psiddh commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

…gnature

At runtime the delegate binds its arguments positionally, walking the tensor lists recovered from the context binary and consuming one argument per tensor the name prefixes mark as bindable. A graph that publishes more bindable I/O than the program passes therefore reads past the end of the argument list on device, where all it leaves behind is a fault address and two counts.

Everything needed to catch that is already in hand at the end of _build_op_wrappers: nodes_to_wrappers holds every tensor that will be serialized into the binary, under the names the runtime will read, and the delegated program carries the signature those names have to agree with. Compare them there and report the offending names, rather than letting the disagreement reach a device.

The comparison uses the runtime's own rules so the two cannot drift: an "input_"-prefixed tensor binds an input, an "output_"-prefixed tensor binds an output, and anything carrying "mutbuf_" is skipped, since mutable buffers are threaded through separately and never consume an argument. Prebuilt context binaries return earlier in the same function and never reach the check; preprocess_multimethod runs it once per program against that program's own signature; tensor-dump mode promotes native tensors to APP_READ without giving them an output_ prefix, so they are excluded too.

Checked against ten real lowerings -- single input/output, multi-input, multi-output, partially-consumed multi-output and a mutable buffer, each in fp16 and quantized -- with no false positives. The unit tests drive the comparison directly with stub wrapper names, covering the matching case, a mutable buffer that must not consume an argument, and a surplus on either side.

One case is worth knowing about: a model returning the same tensor twice has two user_outputs but one output_-prefixed wrapper, so this fires. That is a real defect today, since the runtime's output loop never fills the second argument, and the fix belongs on the runtime side rather than in weakening the check.

…gnature

At runtime the delegate binds its arguments positionally, walking the tensor
lists recovered from the context binary and consuming one argument per tensor
the name prefixes mark as bindable. A graph that publishes more bindable I/O
than the program passes therefore reads past the end of the argument list on
device, where all it leaves behind is a fault address and two counts.

Everything needed to catch that is already in hand at the end of
_build_op_wrappers: nodes_to_wrappers holds every tensor that will be serialized
into the binary, under the names the runtime will read, and the delegated
program carries the signature those names have to agree with. Compare them there
and report the offending names, rather than letting the disagreement reach a
device.

The comparison uses the runtime's own rules so the two cannot drift: an
"input_"-prefixed tensor binds an input, an "output_"-prefixed tensor binds an
output, and anything carrying "mutbuf_" is skipped, since mutable buffers are
threaded through separately and never consume an argument. Prebuilt context
binaries return earlier in the same function and never reach the check;
preprocess_multimethod runs it once per program against that program's own
signature; tensor-dump mode promotes native tensors to APP_READ without giving
them an output_ prefix, so they are excluded too.

Checked against ten real lowerings -- single input/output, multi-input,
multi-output, partially-consumed multi-output and a mutable buffer, each in fp16
and quantized -- with no false positives. The unit tests drive the comparison
directly with stub wrapper names, covering the matching case, a mutable buffer
that must not consume an argument, and a surplus on either side.

One case is worth knowing about: a model returning the same tensor twice has two
user_outputs but one output_-prefixed wrapper, so this fires. That is a real
defect today, since the runtime's output loop never fills the second argument,
and the fix belongs on the runtime side rather than in weakening the check.

Authored with assistance from Claude Code.
Copilot AI lite review requested due to automatic review settings August 27, 2026 21:13
@pytorch-bot

pytorch-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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 Aug 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

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.

2 participants