Skip to content

Qualcomm: let the 8a8w QAT activation spec share an observer with per… - #22238

Open
psiddh wants to merge 1 commit into
pytorch:mainfrom
psiddh:qnn-qat-act-symmetric
Open

Qualcomm: let the 8a8w QAT activation spec share an observer with per…#22238
psiddh wants to merge 1 commit into
pytorch:mainfrom
psiddh:qnn-qat-act-symmetric

Conversation

@psiddh

@psiddh psiddh commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

…-channel

QNN carries two activation specs: the default config for most ops and the per-channel config for conv and linear. PT2E gives an edge one observer only when the producer's output qspec and the consumer's input qspec agree on every attribute _union_input_edge_with compares -- dtype, is_dynamic, quant_min, quant_max, qscheme, ch_axis, scale, zero_point. observer_or_fake_quant_ctr is deliberately excluded, so this is about attribute values, not spec identity or SharedQuantizationSpec.

get_8a8w_qnn_qat_config built its activation spec unconditionally in the symmetric shape: ch_axis=0, no quant_min/quant_max, with only qscheme switching on act_symmetric. get_qat_per_channel_quant_config branches properly, so on the default asymmetric path the two disagree on quant_min, quant_max and ch_axis. Every per-channel conv output meeting a default-config consumer then gets two observers instead of one, which convert_pt2e materializes as a dequantize immediately followed by a requantize. On a conv-relu-conv model with no BatchNorm, QAT produced three such clusters where PTQ produced none.

Split on act_symmetric the way get_8a8w_qnn_ptq_config already does. Passing explicit uint8 bounds for per_tensor_affine is a numerical no-op -- the observer already defaults to 0/255, and scale, zero_point and fake-quant output are bit-identical either way -- it only makes the attributes visible to the comparison.

Two tests. The first compares the default and per-channel activation specs across every QUANT_CONFIG_DICT entry using PT2E's own _has_same_attr; it carries a _KNOWN_UNSHAREABLE list for the eight 16-bit act_symmetric combinations, where the default configs set quant_min/quant_max unconditionally while the per-channel config omits them. Repairing those changes the observed zero_point on a path that works today, so it is left for a follow-up; the list asserts they still mismatch, so it fails if anything shifts. The second test is the end-to-end guard, counting quantize nodes fed directly by a dequantize.

Both fail without the fix: 3 != 0, and mismatched on ['quant_min', 'quant_max', 'ch_axis'].

test_passes.py already runs in OSS CI by name, so no workflow change is needed.

…-channel

QNN carries two activation specs: the default config for most ops and the
per-channel config for conv and linear. PT2E gives an edge one observer only
when the producer's output qspec and the consumer's input qspec agree on every
attribute _union_input_edge_with compares -- dtype, is_dynamic, quant_min,
quant_max, qscheme, ch_axis, scale, zero_point. observer_or_fake_quant_ctr is
deliberately excluded, so this is about attribute values, not spec identity or
SharedQuantizationSpec.

get_8a8w_qnn_qat_config built its activation spec unconditionally in the
symmetric shape: ch_axis=0, no quant_min/quant_max, with only qscheme switching
on act_symmetric. get_qat_per_channel_quant_config branches properly, so on the
default asymmetric path the two disagree on quant_min, quant_max and ch_axis.
Every per-channel conv output meeting a default-config consumer then gets two
observers instead of one, which convert_pt2e materializes as a dequantize
immediately followed by a requantize. On a conv-relu-conv model with no
BatchNorm, QAT produced three such clusters where PTQ produced none.

Split on act_symmetric the way get_8a8w_qnn_ptq_config already does. Passing
explicit uint8 bounds for per_tensor_affine is a numerical no-op -- the observer
already defaults to 0/255, and scale, zero_point and fake-quant output are
bit-identical either way -- it only makes the attributes visible to the
comparison.

Two tests. The first compares the default and per-channel activation specs
across every QUANT_CONFIG_DICT entry using PT2E's own _has_same_attr; it carries
a _KNOWN_UNSHAREABLE list for the eight 16-bit act_symmetric combinations, where
the default configs set quant_min/quant_max unconditionally while the
per-channel config omits them. Repairing those changes the observed zero_point
on a path that works today, so it is left for a follow-up; the list asserts they
still mismatch, so it fails if anything shifts. The second test is the
end-to-end guard, counting quantize nodes fed directly by a dequantize.

Both fail without the fix: 3 != 0, and mismatched on
['quant_min', 'quant_max', 'ch_axis'].

test_passes.py already runs in OSS CI by name, so no workflow change is needed.

Authored with assistance from Claude Code.
Copilot AI lite review requested due to automatic review settings August 27, 2026 21:11
@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/22238

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.

3 participants