executorch icon indicating copy to clipboard operation
executorch copied to clipboard

Qualcomm: on V68 the strict quantizer lets LayerNorm and 16a16w conv fall back to CPU

Open INHA-SW opened this issue 2 weeks ago • 0 comments

🐛 Describe the bug

On HTP V68 (QcomChipset.QCM6490; my device is the QCS6490), the strict QnnQuantizer lets LayerNorm and 16a16w Conv2d through although V68 cannot run them, so they fall back to CPU without an error. strict=True is the default and should raise a ValueError when quantization constraints are not met (docstring); for MatMul it does.

V68 does not support 16-bit weights with 16-bit activations, and the default use_16a8w gives 16-bit specs to the LayerNorm weight and to the MatMul second input, so it is affected too.

import torch
from executorch.backends.qualcomm.quantizer.quantizer import QnnQuantizer, QuantDtype
from executorch.backends.qualcomm.serialization.qc_schema import QcomChipset
from executorch.backends.qualcomm.utils.utils import (
    generate_htp_compiler_spec,
    generate_qnn_executorch_compiler_spec,
    to_edge_transform_and_lower_to_qnn,
)
from torchao.quantization.pt2e.quantize_pt2e import convert_pt2e, prepare_pt2e


class MatMul(torch.nn.Module):
    def forward(self, q, k):
        return q @ k.transpose(-1, -2)


torch.manual_seed(0)
cases = {
    "16a8w matmul": (MatMul(), (torch.randn(1, 8, 32), torch.randn(1, 8, 32)), QuantDtype.use_16a8w),
    "16a8w layer_norm": (torch.nn.Sequential(torch.nn.Linear(32, 32), torch.nn.LayerNorm(32)), (torch.randn(1, 8, 32),), QuantDtype.use_16a8w),
    "16a16w conv2d": (torch.nn.Conv2d(8, 16, 3), (torch.randn(1, 8, 16, 16),), QuantDtype.use_16a16w),
    "16a8w conv2d": (torch.nn.Conv2d(8, 16, 3), (torch.randn(1, 8, 16, 16),), QuantDtype.use_16a8w),
}
specs = generate_qnn_executorch_compiler_spec(
    soc_model=QcomChipset.QCM6490, backend_options=generate_htp_compiler_spec(use_fp16=False)
)
for name, (model, inputs, dtype) in cases.items():
    quantizer = QnnQuantizer(soc_model=QcomChipset.QCM6490)  # strict=True by default
    quantizer.set_default_quant_config(dtype)
    try:
        prepared = prepare_pt2e(torch.export.export(model.eval(), inputs).module(), quantizer)
    except ValueError as e:
        print(f"{name}: prepare raises ValueError: {e}")
        continue
    prepared(*inputs)
    lowered = to_edge_transform_and_lower_to_qnn(convert_pt2e(prepared), inputs, specs)
    calls = [str(n.target) for n in lowered.exported_program().graph.nodes if n.op == "call_function"]
    on_cpu = sorted({c.split(".")[-2] for c in calls if "delegate" not in c and "getitem" not in c and "quantize" not in c})
    print(f"{name}: lowered, {sum('delegate' in c for c in calls)} QNN partition(s), on CPU: {on_cpu}")

On main:

16a8w matmul: prepare raises ValueError: Validation failed for node matmul with target aten.matmul.default
16a8w layer_norm: lowered, 1 QNN partition(s), on CPU: ['native_layer_norm']
16a16w conv2d: lowered, 0 QNN partition(s), on CPU: ['convolution']
16a8w conv2d: lowered, 1 QNN partition(s), on CPU: []

LayerNorm and the 16a16w conv pass prepare, QNN rejects them during partitioning (Value 68, expected >= 73 in the log), and they run on CPU.

The V73 check (validate_16a16w_support) compares the weight dtype with torch.int32 in the Conv2d, Linear, TransposeConv2d and LayerNorm validators, but 16-bit weight specs use torch.int16, so the check never runs for them; MatMul compares with torch.int16. LayerNorm.validate also reads normalized_shape (args[1]) as its weight. When those four comparisons use torch.int16 and LayerNorm reads args[2], all three cases raise at prepare:

16a8w matmul: prepare raises ValueError: Validation failed for node matmul with target aten.matmul.default
16a8w layer_norm: prepare raises ValueError: Validation failed for node layer_norm with target aten.layer_norm.default
16a16w conv2d: prepare raises ValueError: Validation failed for node conv2d with target aten.conv2d.default
16a8w conv2d: lowered, 1 QNN partition(s), on CPU: []

Raising at prepare matches the docstring, but the default 16a8w flow would then stop there on V68 for any model with LayerNorm, where it now runs LayerNorm on CPU. Is the CPU fallback intended here, or should strict mode raise in this case?

For RF-DETR Nano on my QCS6490, I gave the LayerNorm weight and the MatMul second input 8-bit specs under 16a8w. Device person AP was 0.576, against 0.580 for fp32, on 100 COCO val2017 images (with the bias fix in #25199).

Versions

ExecuTorch from source at main ec5e3cf (2026-11-18), torch 2.14.0+cpu, torchao 0.18.0+cpu, QAIRT 2.51.0.260929, Linux x86-64; the device numbers were measured on main 12dac4a, QCS6490.

collect_env output
Collecting environment information...
PyTorch version: 2.14.0+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.5 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
Clang version: 18.1.3 (1ubuntu1)
CMake version: version 3.28.3
Libc version: glibc-2.39

Python version: 3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-6.17.0-35-generic-x86_64-with-glibc2.39
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: False
Caching allocator config: N/A

CPU:
Architecture:                            x86_64
CPU op-mode(s):                          32-bit, 64-bit
Address sizes:                           52 bits physical, 57 bits virtual
Byte Order:                              Little Endian
CPU(s):                                  48
On-line CPU(s) list:                     0-47
Vendor ID:                               AuthenticAMD
Model name:                              AMD Ryzen Threadripper PRO 9965WX 24-Cores
CPU family:                              26
Model:                                   8
Thread(s) per core:                      2
Core(s) per socket:                      24
Socket(s):                               1
Stepping:                                1
Frequency boost:                         enabled
CPU(s) scaling MHz:                      41%
CPU max MHz:                             5489.7642
CPU min MHz:                             1223.6230
BogoMIPS:                                8386.95
Flags:                                   fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good amd_lbr_v2 nopl xtopology nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpuid_fault cpb cat_l3 cdp_l3 hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp ibrs_enhanced vmmcall fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local user_shstk avx_vnni avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic v_spec_ctrl vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid bus_lock_detect movdiri movdir64b overflow_recov succor smca fsrm avx512_vp2intersect flush_l1d debug_swap amd_lbr_pmc_freeze
Virtualization:                          AMD-V
L1d cache:                               1.1 MiB (24 instances)
L1i cache:                               768 KiB (24 instances)
L2 cache:                                24 MiB (24 instances)
L3 cache:                                128 MiB (4 instances)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-47
Vulnerability Gather data sampling:      Not affected
Vulnerability Ghostwrite:                Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Old microcode:             Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Mitigation; Reduced Speculation
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; Enhanced / Automatic IBRS; IBPB conditional; STIBP always-on; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Mitigation; IBPB before exit to userspace

Versions of relevant libraries:
[pip3] numpy==1.26.4
[pip3] torch==2.14.0+cpu
[pip3] torchao==0.18.0+cpu
[pip3] torchvision==0.29.0+cpu
[conda] Could not collect

Prepared with the help of Claude Code; I reviewed it before posting.

cc @cccclai @winskuo-quic @shewu-quic @haowhsu-quic @DannyYuyang-quic @qti-horodnic @cbilgin @abhinaykukkadapu @psiddh

INHA-SW avatar Nov 18 '26 08:11 INHA-SW