Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags: [qhexrt, hexagon, npu, qnn, llm, deepseek-r1, qwen2]
|
| 4 |
+
base_model: deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
# DeepSeek-R1-Distill-Qwen-1.5B — Hexagon NPU (QHexRT) bundle
|
| 9 |
+
|
| 10 |
+
A prebuilt **QHexRT** bundle that runs **DeepSeek-R1-Distill-Qwen-1.5B** fully on the **Qualcomm Hexagon NPU**
|
| 11 |
+
(no CPU/GPU in the compute loop). Drop the arch dir on a device and run with `qhx_generate`.
|
| 12 |
+
|
| 13 |
+
- **Arch present:** `v81/` — **Hexagon v81** (Snapdragon 8 Elite Gen 2 class, SM8850, `soc_model 87`).
|
| 14 |
+
- **Arch-pinned:** a context binary won't load on another Hexagon arch (the `soc_model`+`dsp_arch` are baked
|
| 15 |
+
in). Each arch is its own flat `<arch>/` dir.
|
| 16 |
+
|
| 17 |
+
## What's optimized
|
| 18 |
+
- **GQA-native decode** (12 query / 2 KV heads grouped, no `repeat_interleave`), in-graph attention with a
|
| 19 |
+
fixed-MAXCTX (1024) KV cache + 1D causal mask, **NPU lm-head**, host embed lookup + RoPE (θ=1e4) + sampler.
|
| 20 |
+
- **fp16 throughout** (decode/prefill/lm-head). W8 weight-only quant is available but **degrades this small
|
| 21 |
+
model** (first token correct, continuation drifts) — fp16 is the validated greedy-exact bundle.
|
| 22 |
+
- **v81 f16-attention-overflow fix (critical for this family):** Qwen2/2.5 has **no QK-norm**, so q/k stay
|
| 23 |
+
unnormalized (|k| up to ~400) and the attention `q·k` products overflow fp16 (>65504) on the HTP → garbage.
|
| 24 |
+
The export folds the `1/sqrt(d)` scale **into q before** the matmul and computes the self-score as a
|
| 25 |
+
**matmul** (HMX f32-accumulate, not an fp16 reduce). Math-identical; makes decode **greedy-exact** on v81.
|
| 26 |
+
|
| 27 |
+
## Files (`v81/`)
|
| 28 |
+
| file | role |
|
| 29 |
+
|---|---|
|
| 30 |
+
| `DeepSeek-R1-Distill-Qwen-1.5B.json` | QHexRT manifest (the declarative run plan) |
|
| 31 |
+
| `deepseekr1distillqwen15b_prefill_f16.bin` | prefill context (fp16) |
|
| 32 |
+
| `deepseekr1distillqwen15b_decode_f16.bin` | decode context (fp16) |
|
| 33 |
+
| `deepseekr1distillqwen15b_lmhead_f16.bin` | lm-head context (fp16) |
|
| 34 |
+
| `deepseekr1distillqwen15b_embed_f16.bin` | input embedding table (fp16, host lookup) |
|
| 35 |
+
| `tokenizer.json` | tokenizer |
|
| 36 |
+
|
| 37 |
+
## Run
|
| 38 |
+
```bash
|
| 39 |
+
hf download runanywhere/deepseek_r1_distill_qwen_1_5b_HNPU --local-dir ds15b
|
| 40 |
+
adb push ds15b/v81 /data/local/tmp/wq/ds15b # PowerShell + native paths on Windows
|
| 41 |
+
# QNN runtime libs (libQnnHtp.so/libQnnSystem.so + v81 HTP skel) come from the QAIRT SDK, not this repo
|
| 42 |
+
adb shell "cd /data/local/tmp/wq && LD_LIBRARY_PATH=. \
|
| 43 |
+
./qhx_generate ds15b/DeepSeek-R1-Distill-Qwen-1.5B.json libQnnHtp.so libQnnSystem.so ds15b \
|
| 44 |
+
64 'The capital of France is'"
|
| 45 |
+
```
|
| 46 |
+
Tool arg order is invariant: `<tool> <manifest> libQnnHtp.so libQnnSystem.so <artifacts_root> …`.
|
| 47 |
+
|
| 48 |
+
## Measured (v81 / SM8850, qhx_generate)
|
| 49 |
+
- **Parity:** **greedy-exact** vs the HF fp32 reference — 10/10 gold tokens
|
| 50 |
+
(`"The capital of France is"` → `" Paris, and the capital of Germany is Berlin."`), and generalizes
|
| 51 |
+
(e.g. `"What is 15 multiplied by 6?"` → coherent step-by-step reasoning).
|
| 52 |
+
- **Decode:** ~13.5 tok/s (73.9 ms/tok), MAXCTX 1024.
|
| 53 |
+
|
| 54 |
+
## Caveats
|
| 55 |
+
- **fp16 bundle** (validated). W8 weight-only was tried but degrades this small model (W4 is
|
| 56 |
+
HTP-toolchain-blocked); fp16 is shipped for correctness.
|
| 57 |
+
- Decode-over-prompt seeding (no batched-prefill path at runtime). **v81-pinned** — won't load on other
|
| 58 |
+
Hexagon arches; re-finalize per arch.
|