QNNRev is a Python and C toolkit for inspecting Qualcomm QNN / QAIRT Hexagon HTP context binaries, intercepting hnnx::Deserializer runlists, unpacking tiled weights and quantization parameters (Xsb, Fi, flat constants), reconstructing canonical W8A16 QDQ ONNX graphs, and driving SDK recompilation across QAIRT versions.
Developed and published by Chromatic. Send product feedback to feedback@chromatic.hu.
Note
QNNRev does not redistribute Qualcomm QAIRT SDK binaries, Hexagon toolchains, or third-party model weights. Features that invoke libQnnHtp.so, qairt-converter, DLCQuantizer, or qnn-context-binary-generator expect user-supplied SDK installations under their respective terms.
- Static container & extent parsing: Reads QNN context binary headers (
container_version3 andcontainer_version4+PICKLE/containers),hnnx::DeserializerTLVs (Sz,Vr,Op,Mm,M\xef), and0x71c43c9bconstant-extent tables in 64-byte units (docs/ARCHITECTURE.md). - Native execution & deserializer hook:
native/htp_deser_tap.c(LD_PRELOAD) capturesextract_const_extent_table/extract_const_extent_datamappings,Graph::do_executerunlists (runlist.jsonl), and optionally untiles HTP Crouton intermediate activations. - Tapless weight & constant unpacking: Maps
Constop pointers through recorded DMA extents directly back into.binfile offsets (Xsbint8 tiles,Fiinterleaved float scale + int32 bias pairs, and flat tensors) acrossgeneric,bert,bert-multihead, andvitprofiles. - ONNX reconstruction: Exports unpacked quantized weights and LayerNorm / embedding parameters to canonical float+QDQ ONNX models runnable under
onnxruntimeCPU EP or QAIRT tools. - SDK compilation & parity verification: Builds plans or executes ORT-QNN EP (
onnxruntime-qnn, QAIRT < 2.40) and standalone QAIRT SDK (qairt-converter→DLCQuantizer→qnn-context-binary-generator, QAIRT 2.40+) workflows, plus raw and deviational cosine verification (qnnrev verify). - Evidence-bound IR & adapters: Includes static adapters for QAIRT 2.26 (
0xb) and QAIRT 2.39 wide containers (0x1c3340c0sequencer metadata), an evidence-bound JSON IR validator, and numerical classification helpers (qnnrev.validation).
Python 3.10+ and GCC (for the optional LD_PRELOAD interceptor) are required.
git clone https://github.com/Has-X/QNNRev.git
cd QNNRev
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
make -C native libhtp_deser_tap.so# Inspect a context binary, .zip/.minn package, or directory
qnnrev inspect model.bin
# Unpack constants/weights from a context binary + native/htp_deser_tap.c capture dir
qnnrev unpack --model auto --ctx model.bin --deser-dir deser_out/ --out weights.npz
# Export unpacked weights to ONNX (bert | bert-multihead | vit)
qnnrev decompile --arch bert --weights weights.npz --out model.onnx
# Emit a standalone QAIRT SDK compilation plan (dry-run) or execute compilation
qnnrev compile --onnx model.onnx --out-dir build_htp/ --htp-extended-opts \
--input-dim t_0=1,128 --input-dim t_1=1,128 --input-list calib.txt --dry-run
# Verify probe outputs (raw + deviational cosine)
qnnrev verify --a htp_out/ --a-dtype u16 --a-scale 0.001 --a-offset -32768 \
--b ref_out/ --b-dtype f32 --htp-executedEnvironment variables used by qnnrev compile:
| Variable | Purpose |
|---|---|
QAIRT_SDK_ROOT |
Default QAIRT SDK root (e.g., /opt/qairt/current) |
QNN_SDK_ROOT |
Fallback QNN / QAIRT SDK root when QAIRT_SDK_ROOT is unset |
QNNREV_PY64 |
x86_64 Python interpreter for qairt-converter / DLCQuantizer |
QNNREV_EMUBUNDLE_DIR |
Optional sysroot/LLVM directory when running x86_64 QAIRT tools under ld-linux-x86-64.so.2 on aarch64 hosts |
QNNREV_LD_LINUX |
Override dynamic linker path for cross-arch x86_64 SDK execution |
- docs/ARCHITECTURE.md — Context binary containers (v3 & v4+),
hnnx::DeserializerTLVs,0x71c43c9bextent geometry,Xsb/Fipacking, and IR design. - docs/COMPILATION.md — ORT-EP vs standalone QAIRT SDK compilation rules, extended HTP graph options, and asymmetric quantization requirements.
- docs/NATIVE_TOOLS.md — Building and using
libhtp_deser_tap.so(LD_PRELOAD) andvload_batch.
- ONNX architectural exporters (
bert,bert-multihead,vit) reconstruct parameterized transformer encoder families; arbitrary unknown graphs should use--model generic(unpack_htp_generic) or the SSA graph inqnnrev.core.runlistto inspect tensor bindings directly. vload_batchrequires Qualcomm QAIRT SDK headers (include/QNN) to compile and a target Hexagon runtime /libQnnHtp.soto execute.- Taps vs. tapless unpacking:
unpackrecovers constants purely from context bytes +extents.jsonl+runlist.jsonl; activation quantization scales come from op metadata inrunlist.jsonl, whereas dynamic runtime values require running underlibhtp_deser_tap.soorvload_batch.
python -m compileall -q qnnrev tests
pytest -v
make -C native libhtp_deser_tap.soQNNRev is licensed under the GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later). See LICENSE and NOTICE.
