executorch icon indicating copy to clipboard operation
executorch copied to clipboard

Exception: An error occurred when running the 'InsertIOQDQ' pass after the following passes: ['FoldQDQ', 'InsertRequantize']

Open ThreeD-H opened this issue 9 months ago • 4 comments

🐛 Describe the bug

An error occurred when exporting the model based on tag v1.0.1 using the following command

python examples/qualcomm/oss_scripts/llama/llama.py -b build-android  -m SA8295 -c --temperature 0 --model_mode hybrid --max_seq_len 1024 --prefill_ar_len 128 --decoder_model qwen2_5-0_5b --prompt "I would like to learn python, could you teach me with a simple example?" --tasks wikitext --limit 1

+-----------------------------+----------------------+ | Config | Value | +=============================+======================+ | custom_annotation | () | +-----------------------------+----------------------+ | decoder_model_version | qwen2_5 | +-----------------------------+----------------------+ | get_kv_io_bit_width | 16 | +-----------------------------+----------------------+ | get_logits_output_bit_width | 16 | +-----------------------------+----------------------+ | group_size | 16 | +-----------------------------+----------------------+ | instruct_model | False | +-----------------------------+----------------------+ | masked_softmax | True | +-----------------------------+----------------------+ | num_sharding | 1 | +-----------------------------+----------------------+ | ptq | QuantDtype.use_16a8w | +-----------------------------+----------------------+ | r1 | False | +-----------------------------+----------------------+ | r2 | False | +-----------------------------+----------------------+ | r3 | True | +-----------------------------+----------------------+ | repo_id | Qwen/Qwen2.5-0.5B | +-----------------------------+----------------------+ | seq_mse_candidates | 0 | +-----------------------------+----------------------+ | transform_weight | False | +-----------------------------+----------------------+ [INFO] [Qnn ExecuTorch]: Initialize Qnn backend parameters for Qnn executorch backend type 2 [INFO] [Qnn ExecuTorch]: Caching: Caching is in SAVE MODE. [INFO] [Qnn ExecuTorch]: Running level=3 optimization. [INFO] [Qnn ExecuTorch]: Running level=3 optimization. INFO:executorch.backends.qualcomm.qnn_preprocess:Processing Method(0): (1/73) Traceback (most recent call last): File "/home/admin1/miniconda3/envs/executorch/lib/python3.12/site-packages/torch/fx/passes/infra/pass_manager.py", line 276, in call res = fn(module) ^^^^^^^^^^ File "/home/admin1/miniconda3/envs/executorch/lib/python3.12/site-packages/torch/fx/passes/infra/pass_base.py", line 46, in call res = self.call(graph_module) ^^^^^^^^^^^^^^^^^^^^^^^ File "/home/admin1/executorch/backends/qualcomm/_passes/insert_io_qdq.py", line 151, in call self._insert(graph_module) File "/home/admin1/executorch/backends/qualcomm/_passes/insert_io_qdq.py", line 147, in _insert self.q_dq_map[n.meta[QCOM_QUANT_ATTRS][QCOM_ENCODING]], ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ KeyError: <EdgeOpOverload: quantized_decomposed.dequantize_per_tensor.default>: schema = quantized_decomposed::dequantize_per_tensor(Tensor input, float scale, int zero_point, int quant_min, int quant_max, ScalarType dtype, *, ScalarType? out_dtype=None) -> Tensor

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/home/admin1/executorch/examples/qualcomm/oss_scripts/llama/llama.py", line 1343, in main export_llama(args) File "/home/admin1/executorch/examples/qualcomm/oss_scripts/llama/llama.py", line 1317, in export_llama compile(args, decoder_model_config, pte_filename, tokenizer, chat_template) File "/home/admin1/executorch/examples/qualcomm/oss_scripts/llama/llama.py", line 811, in compile edge_prog_mgr = to_edge_transform_and_lower_to_qnn( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/admin1/executorch/backends/qualcomm/utils/utils.py", line 445, in to_edge_transform_and_lower_to_qnn return to_edge_transform_and_lower( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/admin1/executorch/exir/program/_program.py", line 114, in wrapper return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/home/admin1/executorch/exir/program/_program.py", line 1371, in to_edge_transform_and_lower edge_manager = edge_manager.to_backend(method_to_partitioner) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/admin1/executorch/exir/program/_program.py", line 114, in wrapper return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/home/admin1/executorch/exir/program/_program.py", line 1672, in to_backend new_edge_programs = to_backend(method_to_programs_and_partitioners) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/admin1/miniconda3/envs/executorch/lib/python3.12/functools.py", line 912, in wrapper return dispatch(args[0].class)(*args, **kw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/admin1/executorch/exir/backend/backend_api.py", line 762, in _ lower_all_submodules_to_backend( File "/home/admin1/executorch/exir/backend/backend_api.py", line 591, in lower_all_submodules_to_backend backend_name_to_subclass[backend_id].preprocess_multimethod( File "/home/admin1/executorch/backends/qualcomm/qnn_preprocess.py", line 164, in preprocess_multimethod py_op_wrappers = QnnBackend._build_op_wrappers( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/admin1/executorch/backends/qualcomm/qnn_preprocess.py", line 47, in _build_op_wrappers graph_module = QnnPassManager().transform_for_preprocess_pipeline(edge_program) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/admin1/executorch/backends/qualcomm/_passes/qnn_pass_manager.py", line 246, in transform_for_preprocess_pipeline self._transform(exported_program.graph_module) File "/home/admin1/executorch/backends/qualcomm/_passes/qnn_pass_manager.py", line 130, in _transform return self(graph_module).graph_module ^^^^^^^^^^^^^^^^^^ File "/home/admin1/miniconda3/envs/executorch/lib/python3.12/site-packages/torch/fx/passes/infra/pass_manager.py", line 302, in call raise Exception(msg) from e # noqa: TRY002 ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Exception: An error occurred when running the 'InsertIOQDQ' pass after the following passes: ['FoldQDQ', 'InsertRequantize']

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/admin1/executorch/examples/qualcomm/oss_scripts/llama/llama.py", line 1354, in main() File "/home/admin1/executorch/examples/qualcomm/oss_scripts/llama/llama.py", line 1349, in main raise Exception(e) Exception: An error occurred when running the 'InsertIOQDQ' pass after the following passes: ['FoldQDQ', 'InsertRequantize'] [INFO] [Qnn ExecuTorch]: Destroy Qnn backend parameters [INFO] [Qnn ExecuTorch]: Destroy Qnn context [INFO] [Qnn ExecuTorch]: Destroy Qnn device [INFO] [Qnn ExecuTorch]: Destroy Qnn backend

Versions

Collecting environment information... PyTorch version: 2.9.0+cpu Is debug build: False CUDA used to build PyTorch: Could not collect ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.5 LTS (x86_64) GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04.2) 11.4.0 Clang version: Could not collect CMake version: version 3.31.10 Libc version: glibc-2.35

Python version: 3.12.12 | packaged by Anaconda, Inc. | (main, Oct 21 2025, 20:16:04) [GCC 11.2.0] (64-bit runtime) Python platform: Linux-6.8.0-101-generic-x86_64-with-glibc2.35 Is CUDA available: False CUDA runtime version: Could not collect CUDA_MODULE_LOADING set to: N/A GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4090 GPU 1: NVIDIA GeForce RTX 4090 GPU 2: NVIDIA GeForce RTX 4090

Nvidia driver version: 580.126.09 cuDNN version: Could not collect Is XPU available: False HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True Caching allocator config: N/A

CPU: 架构: x86_64 CPU 运行模式: 32-bit, 64-bit Address sizes: 46 bits physical, 57 bits virtual 字节序: Little Endian CPU: 48 在线 CPU 列表: 0-47 厂商 ID: GenuineIntel 型号名称: Intel(R) Xeon(R) Silver 4310 CPU @ 2.10GHz CPU 系列: 6 型号: 106 每个核的线程数: 2 每个座的核数: 12 座: 2 步进: 6 CPU 最大 MHz: 3300.0000 CPU 最小 MHz: 800.0000 BogoMIPS: 4200.00 标记: 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 pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect wbnoinvd dtherm ida arat pln pts vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid fsrm md_clear pconfig flush_l1d arch_capabilities 虚拟化: VT-x L1d 缓存: 1.1 MiB (24 instances) L1i 缓存: 768 KiB (24 instances) L2 缓存: 30 MiB (24 instances) L3 缓存: 36 MiB (2 instances) NUMA 节点: 2 NUMA 节点0 CPU: 0-11,24-35 NUMA 节点1 CPU: 12-23,36-47 Vulnerability Gather data sampling: Mitigation; Microcode Vulnerability Indirect target selection: Vulnerable Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable Vulnerability Reg file data sampling: Not affected 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; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop Vulnerability Srbds: Not affected Vulnerability Tsa: Not affected Vulnerability Tsx async abort: Not affected Vulnerability Vmscape: Not affected

Versions of relevant libraries: [pip3] executorch==1.0.1 [pip3] numpy==2.2.6 [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] pytorch_tokenizers==1.1.0 [pip3] torch==2.9.0+cpu [pip3] torchao==0.14.0 [pip3] torchdata==0.11.0 [pip3] torchtune==0.6.1 [pip3] triton==3.6.0 [conda] executorch 1.0.1 pypi_0 pypi [conda] numpy 2.2.6 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-tokenizers 1.1.0 pypi_0 pypi [conda] torch 2.9.0+cpu pypi_0 pypi [conda] torchao 0.14.0 pypi_0 pypi [conda] torchdata 0.11.0 pypi_0 pypi [conda] torchtune 0.6.1 pypi_0 pypi [conda] triton 3.6.0 pypi_0 pypi

cc @cccclai @cbilgin

ThreeD-H avatar Feb 26 '26 10:02 ThreeD-H

Seems like this may be related to https://github.com/pytorch/executorch/pull/17194, which was reverted in https://github.com/pytorch/executorch/pull/17385

@ThreeD-H can you try with the fix and see if it works for you?

cc @abhinaykukkadapu on qualcomm here as well.

lucylq avatar Feb 28 '26 00:02 lucylq

@ThreeD-H I’m not sure whether this is exactly the same issue, but I observed a failure in a related code path.

Specifically, when a quantized node is directly consumed by output, et attempts to insert a dq based on QCOM_ENCODING. However, not all encodings appear to be covered in q_dq_map, and the current logic assumes the mapping always exists.

I locally added a guard to skip dq insertion when the encoding is missing. This prevents the failure, although it’s obviously not a proper fix.

`

     # insert dq before output or fold mix_quantization q if applicable
        users = list(n.users.keys())
        if n.meta.get(QCOM_QUANT_ATTRS) and any(
            user.op == "output" for user in users
        ) and  (n.meta[QCOM_QUANT_ATTRS][QCOM_ENCODING] in self.q_dq_map): # **workaround**
            self._insert_dequant_node(
                graph_module,
                n,
                self.q_dq_map[n.meta[QCOM_QUANT_ATTRS][QCOM_ENCODING]],

`

yujiaoliang avatar Feb 28 '26 02:02 yujiaoliang

@ThreeD-H I’m not sure whether this is exactly the same issue, but I observed a failure in a related code path.

Specifically, when a quantized node is directly consumed by output, et attempts to insert a dq based on QCOM_ENCODING. However, not all encodings appear to be covered in q_dq_map, and the current logic assumes the mapping always exists.

I locally added a guard to skip dq insertion when the encoding is missing. This prevents the failure, although it’s obviously not a proper fix.

`

     # insert dq before output or fold mix_quantization q if applicable
        users = list(n.users.keys())
        if n.meta.get(QCOM_QUANT_ATTRS) and any(
            user.op == "output" for user in users
        ) and  (n.meta[QCOM_QUANT_ATTRS][QCOM_ENCODING] in self.q_dq_map): # **workaround**
            self._insert_dequant_node(
                graph_module,
                n,
                self.q_dq_map[n.meta[QCOM_QUANT_ATTRS][QCOM_ENCODING]],

`

After I switched to the main branch, qwen3-0.6B was exported successfully, but Qwen2.5-0.5B still had this error

class Qwen2_5_0_5BQuantRecipe(StaticLLMQuantRecipe):
    default_quant_dtype = QuantDtype.use_16a8w

    def __init__(self, verbose: bool = False):
        super().__init__()

        self.recipe = QuantRecipe(
            self.default_quant_dtype,
            False,
            act_observer=MinMaxObserver,
            granularity=QuantGranularity.PER_TENSOR,
            verbose=verbose,
        ).add_node_target(
            {
                torch.ops.aten.conv2d.default,
            },
            QuantDtype.use_16a8w,
            False,
            act_observer=MinMaxObserver,
            granularity=QuantGranularity.PER_CHANNEL,
            extra_kwargs={"block_size": (1, 16, 1, 1)},
        )
        self.recipe.custom_quant_annotations.append(annotate_kv_8bit)

ThreeD-H avatar Feb 28 '26 07:02 ThreeD-H

Re-opening this as #18601 was filed to resolve this after the Qwen bug report cc @abhinaykukkadapu

nil-is-all avatar Mar 31 '26 17:03 nil-is-all