qnn-debug

Diagnose and fix MNN QNN backend errors, accuracy issues, and operator support on Qualcomm HTP.

16.0k|2.4k|Updated Apr 15, 2019
One-click install
npx skills add https://github.com/alibaba/MNN --skill qnn-debug
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: qnn-debug
Source: https://github.com/alibaba/MNN/tree/main/skills/qnn-debug
Command: npx skills add https://github.com/alibaba/MNN --skill qnn-debug

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires onnx, onnxruntime, numpy, and includes scripts (resource) and references (resource) components.

What problem does it solve?

Debugging the MNN QNN (Qualcomm HTP/NPU) backend is hard: runtime errors like 1002/6000/1003/6004, wrong inference results, fp16 precision gaps, and missing operator support all require deep backend knowledge. This Skill provides a systematic workflow to locate the first failing operator, distinguish real bugs from hardware fp16 accumulation, and add or adapt QNN operators.

Core Features & Use Cases

  • Intermediate tensor dump comparison: Uses MNN2QNNModel with --dump_intermediate_outputs to export all QNN intermediate tensors in one pass and compare them against a CPU fp32 baseline to pinpoint the first failing operator.
  • Bug vs precision triage: Compares QNN-fp16 against CPU-fp16 and OpenCL-fp16 baselines to separate genuine operator bugs from HTP fp16 accumulation, with an error-pattern lookup table and error-code reference.
  • Operator implementation guidance: Walks through adding or adapting QNN operators by consulting SDK docs (MasterOpDef, HtpOpDefSupplement, SupportedOps), following existing operator templates, and verifying with probe scripts.
  • Use Case: A model produces garbage output on the NPU with error 6000. The Skill guides you to retry with shapeMutable=false, dump intermediate tensors, bisect to the first bad operator, and fix the QNN implementation.

Quick Start

Ask the assistant to debug why my MNN model gives wrong results on the QNN NPU backend and locate the first failing operator.

Frequently Asked Questions about qnn-debug

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I debug wrong inference results on the MNN QNN backend?

First establish a trusted CPU fp32 baseline with testMNNFromOnnx.py, then use MNN2QNNModel with --dump_intermediate_outputs to export all QNN intermediate tensors in one run. Compare each tensor against the CPU baseline to find the first operator whose input is good but output is bad.

How do I fix QNN error 1002 or 6000 in MNN?

Error 1002 means graphFinalize failed and 6000 means graphExecute failed. First try running with shapeMutable=false, which avoids a known input-copy issue. If it persists, enable QNN error logs in QNNBackend.cpp and check which operator violates constraints in HtpOpDefSupplement.html.

How do I tell a real QNN operator bug from fp16 precision loss?

Compare QNN-fp16 against CPU-fp16, which acts as a well-behaved fp16 floor using fp32 accumulators. A sudden error jump at one operator where CPU-fp16 stays clean indicates a real bug, while smooth synchronized growth across both indicates fp16 accumulation.

How do I add a new operator to the MNN QNN backend?

First check SupportedOps.html, MasterOpDef.html, and HtpOpDefSupplement.html in the QNN SDK docs for input counts, parameter names, and HTP constraints. Then copy the closest existing operator template in source/backend/qnn/execution, register it in QNNUtils.cpp, and verify with the probe scripts.

Why does my QNN model fail only with dynamic input shapes?

The QNN online path does not copy model inputs in Session_Input_User mode (shapeMutable=true), so the first operator reads all zeros or graphExecute fails with error 6000. Setting shapeMutable=false routes input copying through Session_Input_Inside and fixes it without code changes.

What are the limitations of the QNN intermediate tensor dump?

The dump significantly increases graph outputs, memory usage, and execution time, so it is only for accuracy debugging, never for performance measurement or release builds. Existing finalized offline graphs cannot be retrofitted; you must regenerate a debug model with --dump_intermediate_outputs.