QNN export failure for PARSeq text recognition model
🐛 Describe the bug
I have a fork of the PARSeq repository with slight modifications for Executorch compatibility that is failing to export for QNN using the build_executorch_binary method. I followed the deeplab_v3 example, which appeared to successfully export. I have tested with versions 2.37 and 2.40 of the QNN SDK.
I have attached 3 stacktraces for the errors I encountered. The first is for the "aten.linear.default" op resulting in NPEs for the weight_tensor being sent to define_tensor. The 2nd is for the "aten.ge.Scalar" op not being present in the node_visitors map during is_node_supported. The final is when I have excluded both of the ops above and get a an error stating "AssertionError: Failed to generate Qnn context binary".
null_tensor_stacktrace.txt keyerror_stacktrace.txt qnn_context_stacktrace.txt
Example of the script used when attempting to export: export_executorch_qualcomm.py
Versions
PyTorch version: 2.9.0+cu128 Is debug build: False CUDA used to build PyTorch: 12.8 ROCM used to build PyTorch: N/A
OS: Ubuntu 24.04.3 LTS (x86_64) GCC version: (Ubuntu 14.2.0-4ubuntu2~24.04) 14.2.0 Clang version: 18.1.3 (1ubuntu1) CMake version: version 4.1.0 Libc version: glibc-2.39
Python version: 3.12.11 | packaged by conda-forge | (main, Jun 4 2025, 14:45:31) [GCC 13.3.0] (64-bit runtime) Python platform: Linux-6.8.0-86-generic-x86_64-with-glibc2.39 Is CUDA available: True CUDA runtime version: 13.0.88 CUDA_MODULE_LOADING set to: GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3090 GPU 1: NVIDIA GeForce RTX 4090
Nvidia driver version: 580.95.05 cuDNN version: Probably one of the following: /usr/lib/x86_64-linux-gnu/libcudnn.so.9.14.0 /usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.14.0 /usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.14.0 /usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.14.0 /usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.14.0 /usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.14.0 /usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.14.0 /usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.14.0 Is XPU available: False HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True
CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 46 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 24 On-line CPU(s) list: 0-23 Vendor ID: GenuineIntel Model name: 12th Gen Intel(R) Core(TM) i9-12900K CPU family: 6 Model: 151 Thread(s) per core: 2 Core(s) per socket: 16 Socket(s): 1 Stepping: 2 CPU(s) scaling MHz: 95% CPU max MHz: 5200,0000 CPU min MHz: 800,0000 BogoMIPS: 6374,40 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities Virtualization: VT-x L1d cache: 640 KiB (16 instances) L1i cache: 768 KiB (16 instances) L2 cache: 14 MiB (10 instances) L3 cache: 30 MiB (1 instance) NUMA node(s): 1 NUMA node0 CPU(s): 0-23 Vulnerability Gather data sampling: 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 Reg file data sampling: Mitigation; Clear Register File Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Not affected 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; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected
Versions of relevant libraries: [pip3] executorch==1.0.0 [pip3] numpy==2.1.2 [pip3] nvidia-cublas-cu12==12.8.4.1 [pip3] nvidia-cuda-cupti-cu12==12.8.90 [pip3] nvidia-cuda-nvrtc-cu12==12.8.93 [pip3] nvidia-cuda-runtime-cu12==12.8.90 [pip3] nvidia-cudnn-cu12==9.10.2.21 [pip3] nvidia-cufft-cu12==11.3.3.83 [pip3] nvidia-curand-cu12==10.3.9.90 [pip3] nvidia-cusolver-cu12==11.7.3.90 [pip3] nvidia-cusparse-cu12==12.5.8.93 [pip3] nvidia-cusparselt-cu12==0.7.1 [pip3] nvidia-nccl-cu12==2.27.5 [pip3] nvidia-nvjitlink-cu12==12.8.93 [pip3] nvidia-nvtx-cu12==12.8.90 [pip3] onnx==1.19.0 [pip3] onnx_graphsurgeon==0.5.8 [pip3] onnx-ir==0.1.9 [pip3] onnxruntime-gpu==1.21.0 [pip3] onnxscript==0.5.2 [pip3] pytorch-lightning==2.5.5 [pip3] torch==2.9.0 [pip3] torchao==0.14.0 [pip3] torchmetrics==1.8.2 [pip3] torchvision==0.24.0 [pip3] triton==3.5.0 [pip3] vit-pytorch==1.12.4 [conda] executorch 1.0.0 pypi_0 pypi [conda] numpy 2.1.2 pypi_0 pypi [conda] nvidia-cublas-cu12 12.8.4.1 pypi_0 pypi [conda] nvidia-cuda-cupti-cu12 12.8.90 pypi_0 pypi [conda] nvidia-cuda-nvrtc-cu12 12.8.93 pypi_0 pypi [conda] nvidia-cuda-runtime-cu12 12.8.90 pypi_0 pypi [conda] nvidia-cudnn-cu12 9.10.2.21 pypi_0 pypi [conda] nvidia-cufft-cu12 11.3.3.83 pypi_0 pypi [conda] nvidia-curand-cu12 10.3.9.90 pypi_0 pypi [conda] nvidia-cusolver-cu12 11.7.3.90 pypi_0 pypi [conda] nvidia-cusparse-cu12 12.5.8.93 pypi_0 pypi [conda] nvidia-cusparselt-cu12 0.7.1 pypi_0 pypi [conda] nvidia-nccl-cu12 2.27.5 pypi_0 pypi [conda] nvidia-nvjitlink-cu12 12.8.93 pypi_0 pypi [conda] nvidia-nvtx-cu12 12.8.90 pypi_0 pypi [conda] pytorch-lightning 2.5.5 pypi_0 pypi [conda] torch 2.9.0 pypi_0 pypi [conda] torchao 0.14.0 pypi_0 pypi [conda] torchmetrics 1.8.2 pypi_0 pypi [conda] torchvision 0.24.0 pypi_0 pypi [conda] triton 3.5.0 pypi_0 pypi [conda] vit-pytorch 1.12.4 pypi_0 pypi
cc @cccclai @winskuo-quic @shewu-quic @haowhsu-quic @DannyYuyang-quic @cbilgin
After you add these ops to the skip list, were you able to get the model or still failing?
"aten.linear.default", # Causes NPE (weight_tensor is None when calling define_tensor)
"aten.ge.Scalar", # Causes KeyError (not in node_visitors during is_node_supported method)
Also, is the script in the description the one we can use to repro?
After you add these ops to the skip list, were you able to get the model or still failing?
"aten.linear.default", # Causes NPE (weight_tensor is None when calling define_tensor) "aten.ge.Scalar", # Causes KeyError (not in node_visitors during is_node_supported method)Also, is the script in the description the one we can use to repro?
Yes, it still fails after adding those ops to the skip list. The result from that test is in the qnn_context_stacktrace.txt file. The script I linked can be used to reproduce the errors yes. There is a comment in the file for the required dependencies as well.
@haowhsu-quic @shewu-quic @winskuo-quic @chenweng-quic @DannyYuyang-quic let's see how to help on this
Hi @Fredrik00,
I'm working on reproducing the error. Also, I'm interested in why linear failed. Could you please try convert_linear_to_conv to check if it results in an error?
Based on my current investigation, the reason for the linear failure is that the weight node is not a static node, but instead the output of the split_with_sizes node. You can apply this patch to resolve the issue. I will also create a PR to address it. I am still investigating the other error.
diff --git a/backends/qualcomm/builders/op_linear.py b/backends/qualcomm/builders/op_linear.py
index d5ac153b8d..5d62901595 100644
--- a/backends/qualcomm/builders/op_linear.py
+++ b/backends/qualcomm/builders/op_linear.py
@@ -56,12 +56,12 @@ class LinearVisitor(NodeVisitor):
[-1, 1]
)
- weight_tensor = get_parameter(weight_node, self.edge_program)
+ weight_tensor = self.get_tensor(weight_node, node)
weight_tensor_wrapper = self.define_tensor(
weight_node,
node,
weight_tensor,
- PyQnnWrapper.Qnn_TensorType_t.QNN_TENSOR_TYPE_STATIC,
+ PyQnnWrapper.Qnn_TensorType_t.QNN_TENSOR_TYPE_NATIVE,
nodes_to_wrappers,
)
linear_input_tensors.append(weight_tensor_wrapper)
@shewu-quic I attempted to export as well using convert_linear_to_conv and got an error for this line:
tgt_mask = query_mask = torch.triu(torch.ones((num_steps, num_steps), dtype=torch.bool, device=self._device), 1)
Is this the other error you are investigating? I thought maybe the issue was the torch.triu operation, as I assumed it to be less common, but in an attempt to rewrite that part of the code I noticed it is actually failing on the torch.ones/torch.full operation instead.
Yes, there are certain operation validations related to triu, as index_put and slice are not supported for the bool type in QNN.
I can successfully export pte with three partitions using the code below and this PR. However, aten.where.self, which is generated from MultiheadAttention, causes prepare failed in QNN. If you could rewrite this part, it would help enable full delegation in QNN backend.
And also I found strange behavior which cause preparation failed about library loading when I load library via ctypes.CDLL(xxx, mode=ctypes.RTLD_GLOBAL). I am still under investigation. You can set QNN_SDK_ROOT and LD_LIBRARY_PATH to avoid this issue such as export LD_LIBRARY_PATH=/path/to/qnn/2.37.0.250724/lib/x86_64-linux-clang and export QNN_SDK_ROOT=/path/to/qnn/2.37.0.250724/.
model_name = "parseq"
export_mode = 'executorch'
backends = [
"vulkan",
"xnnpack"
]
model = prepare_export_model(model_name, export_mode)
image = get_dummy_input()
# Test model forward pass for debugging purposes
# model(image)
inputs = (image,)
build_executorch_binary(
model,
inputs,
"SM8650",
"parseq_qualcomm.pte",
[inputs],
skip_node_op_set={
"aten.full.default", # avoid zero input for QNN Graph. If other operations can be fully delegated, this skip may be removed.
"aten.where.self" # prepare failed from MultiheadAttention.
},
skip_node_id_set={
"aten_view_copy_default_136" # prepare failed in QNN 2.37, but successful in QNN 2.40
}
)