Skip to content

Qualcomm AI Engine Direct - do not annotate non-float activations - #23027

Open
psiddh wants to merge 1 commit into
pytorch:mainfrom
psiddh:qnn-nonfloat-activation-guard
Open

psiddh wants to merge 1 commit into
pytorch:mainfrom
psiddh:qnn-nonfloat-activation-guard

Conversation

@psiddh

@psiddh psiddh commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Observers only work with float tensors, so a quantization spec on an integer or boolean activation makes convert_pt2e emit a quantize_per_tensor whose dtype assert fires on the following export. Annotators guard the operands they look at - Cat, Stack, Embedding, Where and IndexPut each carry their own check - but annotate_single_in, Chunk, IndexCopy and SliceScatter annotate whatever they are given, so an int64 activation still reaches an observer. slice_scatter over an int64 cache index, the shape HuggingFace's cache_position update takes, is the case that surfaced this.

Enforce the invariant once after annotation instead of adding a fifth per-op guard. Note _is_float_tensor cannot simply be negated for this: it also returns False for the list and tuple outputs of native_layer_norm and max.dim, which are legitimately annotated, so the sweep tests the dtype of single tensor values only and leaves every float annotation untouched.

cc @cbilgin

@pytorch-bot

pytorch-bot Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 130 New Failures, 2 Unrelated Failures, 7 Unclassified Failures

As of commit 4033b26 with merge base ed72896 (image):

NEW FAILURES - The following jobs have failed:

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

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 Sep 22, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: psiddh / name: Siddartha Pothapragada (4033b26)

@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.

@psiddh psiddh added the module: qnn Issues related to Qualcomm's QNN delegate and code under backends/qualcomm/ label Sep 28, 2026
@psiddh
psiddh marked this pull request as ready for review September 29, 2026 18:35
Copilot AI balanced review requested due to automatic review settings September 29, 2026 18:35

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 review overview

🟢 Approval recommended

The centralized cleanup correctly preserves aggregate outputs while preventing unsupported observers, with focused regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Centralizes QNN quantization cleanup so integer and boolean activations never receive observers.

Changes:

  • Removes non-floating-point input and output quantization specs after annotation.
  • Adds an end-to-end slice_scatter regression test.
File Description
backends/​qualcomm/​quantizer/​rules.py Adds non-float annotation cleanup.
backends/​qualcomm/​quantizer/​quantizer.py Runs cleanup after annotation.
backends/​qualcomm/​tests/​test_passes.py Tests annotation and conversion behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Observers only work with float tensors, so a quantization spec on an integer or
boolean activation makes convert_pt2e emit a quantize_per_tensor whose dtype
assert fires on the following export. Annotators guard the operands they look
at - Cat, Stack, Embedding, Where and IndexPut each carry their own check - but
annotate_single_in, Chunk, IndexCopy and SliceScatter annotate whatever they are
given, so an int64 activation still reaches an observer. slice_scatter over an
int64 cache index, the shape HuggingFace's cache_position update takes, is the
case that surfaced this.

Enforce the invariant once after annotation instead of adding a fifth per-op
guard. Note _is_float_tensor cannot simply be negated for this: it also returns
False for the list and tuple outputs of native_layer_norm and max.dim, which are
legitimately annotated, so the sweep tests the dtype of single tensor values
only and leaves every float annotation untouched.

Covered by a unittest and by a test in the rework framework; both fail before
the change with an output_qspec on the int64 slice_scatter.
Copilot AI balanced review requested due to automatic review settings September 29, 2026 22:08
@psiddh
psiddh force-pushed the qnn-nonfloat-activation-guard branch from 7000c6d to 4033b26 Compare September 29, 2026 22:08

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 review overview

🟢 Approval recommended

The centralized cleanup preserves structured outputs while removing unsupported non-floating tensor qspecs, with regression coverage across both quantizer test suites.

Review effort: Balanced
Findings: None

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. module: qnn Issues related to Qualcomm's QNN delegate and code under backends/qualcomm/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants