[Qualcomm] LayerNorm V68 architecture guard reads normalized_shape instead of weight and checks the wrong dtype
QnnQuantizer(strict=True, soc_model=QcomChipset.QCM6490) does not reject the
default A16/W16 LayerNorm annotation on HTP V68. The explicit architecture check
in LayerNorm.validate reads node.args[1] (normalized_shape), rather than the
weight at node.args[2], and compares the weight dtype with torch.int32 although
the annotator assigns torch.int16.
This is an early-validation defect, separate from the V68 annotation workaround discussed in #18280. It does not imply that V68 supports A16/W16 LayerNorm, nor that correcting the guard alone makes a whole detector run with W8A16.
Environment
- ExecuTorch main
12dac4aa042b66a7229e8d7d3af2bdde8c9f262f - Python 3.12.3, PyTorch 2.14.0+cpu, TorchAO 0.18.0, Linux x86_64
- QAIRT 2.51.0.260929, with the native adapters built against the same SDK
- Target QCM6490 / HTP V68; small compiled controls also run on physical QCS6490
Reproduction
With the QNN backend built and QNN_SDK_ROOT / library paths configured:
import torch
from executorch.backends.qualcomm.quantizer.quantizer import QnnQuantizer, QuantDtype
from executorch.backends.qualcomm.serialization.qc_schema import QcomChipset
from torchao.quantization.pt2e.quantize_pt2e import prepare_pt2e
quantizer = QnnQuantizer(soc_model=QcomChipset.QCM6490, strict=True)
assert quantizer.backend_opinfo.get_all_supported_ops() # exclude the no-SDK fallback
quantizer.set_default_quant_config(QuantDtype.use_16a8w)
model = torch.export.export(
torch.nn.LayerNorm(32).eval(), (torch.randn(1, 8, 32),)
).module()
prepared = prepare_pt2e(model, quantizer) # unexpectedly succeeds
The default annotator promotes LayerNorm's weight to signed INT16 even with
use_16a8w. In this environment the SDK supplies 15 LayerNorm constraint variants;
the failure is not caused by missing op-info. The generic constraint validator
can skip an unmatched datatype combination, leaving the explicit architecture
guard important here.
Expected: strict preparation rejects this unsupported A16/W16 combination, like
the MatMul architecture guard does. Observed: preparation succeeds. Lowering this
tiny default case leaves aten.native_layer_norm on CPU, while the explicit
A16/U8-weight control produces a QNN delegate and executes on QCS6490.
Candidate correction and tests
In backends/qualcomm/quantizer/annotators/htp_rules.py, LayerNorm.validate:
- weight_node = node.args[1]
+ weight_node = node.args[2] if len(node.args) > 2 else None
...
- and weight_qspec.dtype == torch.int32
+ and weight_qspec.dtype == torch.int16
The annotator also reads optional weight/bias arguments unconditionally / with
incorrect length checks. Direct annotation of exported affine-free
aten.layer_norm.default(x, [32]) raises IndexError. The companion safe reads are:
weight_node = node.args[2] if len(node.args) > 2 else None
bias_node = node.args[3] if len(node.args) > 3 else None
Locally tested with real exported FX nodes and the imported upstream annotator / validator, without SDK or validator stubs: both layer_norm variants, V68 rejection, V73 acceptance, A8 and A16/U8 controls, affine-free nodes, optional-argument preparation, and the strict-QnnQuantizer reproduction above. Four unittest methods report three assertion failures and one error before the candidate correction; all four pass after it. These tests concern annotation/validation, not detector AP.
For context, an A16/U8 LayerNorm and a small attention graph with A16/U8 MatMul operands both compile and execute with this latest stack on QCS6490. Full RF-DETR Nano has further export/lowering requirements under investigation; this report is deliberately limited to the reproducible LayerNorm defect.
Prepared with assistance from OpenAI Codex; the reproductions and device controls were executed in the environment above.
cc @cbilgin @psiddh