Link the GitHub repo (method/code) and add long-context results
Browse files
README.md
CHANGED
|
@@ -1,143 +1,170 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
pretty_name: Ternary-Bonsai-2-27B + in-file MTP reproduction (Ada/SM89)
|
| 4 |
-
tags:
|
| 5 |
-
- ternary
|
| 6 |
-
- speculative-decoding
|
| 7 |
-
- mtp
|
| 8 |
-
- llama.cpp
|
| 9 |
-
- bonsai
|
| 10 |
-
---
|
| 11 |
-
|
| 12 |
-
# Ternary-Bonsai-2-27B + in-file MTP: reproduction bundle (RTX 4080 SUPER, Ada/SM89)
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
```
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
| 86 |
-
|
|
| 87 |
-
|
|
| 88 |
-
|
|
| 89 |
-
|
|
| 90 |
-
|
|
| 91 |
-
|
|
| 92 |
-
|
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
| 115 |
-
|
|
| 116 |
-
|
|
| 117 |
-
|
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
`
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
pretty_name: Ternary-Bonsai-2-27B + in-file MTP reproduction (Ada/SM89)
|
| 4 |
+
tags:
|
| 5 |
+
- ternary
|
| 6 |
+
- speculative-decoding
|
| 7 |
+
- mtp
|
| 8 |
+
- llama.cpp
|
| 9 |
+
- bonsai
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Ternary-Bonsai-2-27B + in-file MTP: reproduction bundle (RTX 4080 SUPER, Ada/SM89)
|
| 13 |
+
|
| 14 |
+
> **This repository holds the raw data. The method (build script, harness, launch units, write-up) lives on GitHub:**
|
| 15 |
+
> **<https://github.com/zhaoyilun/bonsai2-27b-mtp-repro>**
|
| 16 |
+
>
|
| 17 |
+
> Both are the same piece of work: the GitHub repo has the code and the how-to, this dataset has the
|
| 18 |
+
> measurements it produced. Cross-linked in both directions.
|
| 19 |
+
|
| 20 |
+
Raw measurements, scripts and notes for the two discussions:
|
| 21 |
+
|
| 22 |
+
- official model repo: https://huggingface.co/prism-ml/Ternary-Bonsai-2-27B-gguf/discussions/23
|
| 23 |
+
- drafter repo: https://huggingface.co/ProCreations/Ternary-Bonsai-2-27B-MTP/discussions/2
|
| 24 |
+
|
| 25 |
+
**Headline**: with the MTP block packaged *inside* the target GGUF (so the draft context is created against the
|
| 26 |
+
target and shares its vocabulary), MTP speculative decoding gives a **median 1.338x decode speedup**
|
| 27 |
+
(range 1.23x–1.70x, aggregate draft acceptance **68.1%**, 803/1180) on a single 16 GB Ada card — after
|
| 28 |
+
working around a hard guard in the official fork that refuses the MTP graph on Hadamard-folded weights.
|
| 29 |
+
|
| 30 |
+

|
| 31 |
+
|
| 32 |
+
## Environment
|
| 33 |
+
|
| 34 |
+
| item | value |
|
| 35 |
+
|---|---|
|
| 36 |
+
| GPU | NVIDIA RTX 4080 SUPER, 16376 MiB (Ada, SM89) |
|
| 37 |
+
| Driver / toolkit | CUDA UMD 13.3, CUDA toolkit 13.3.73 |
|
| 38 |
+
| Host | WSL2 (kernel 5.15), 32-core CPU, 46 GB RAM |
|
| 39 |
+
| Model | `ProCreations/Ternary-Bonsai-2-27B-MTP` → `Ternary-Bonsai-2-27B-PQ2_0-MTP-Q8_0.gguf`, 7.66 GB, sha256 `3cb3f0056d2e34ee44245a64396004a21f8492573d6ce1266ec4b7222c131dd4` (matches the publisher's `SHA256SUMS`) |
|
| 40 |
+
| Runtime | built from `runtime/prism-dflash2-source.tar.gz`, sha256 `8c0f589673b25574f27f013bb3278824384eb35eb984034a2445af3c437b9d05`, base `d8f26ee`, `-DCMAKE_CUDA_ARCHITECTURES=89` |
|
| 41 |
+
|
| 42 |
+
The published prebuilt runtime archive is CUDA 13.3 **SM120 (Blackwell) only**, so on Ada it has to be built from
|
| 43 |
+
the source they ship. Build on 32 cores: 484 targets, ~9 minutes.
|
| 44 |
+
|
| 45 |
+
One gotcha worth knowing: with `nvcc` not on `PATH`, CMake fails with `CMAKE_CUDA_COMPILER-NOTFOUND` unless the
|
| 46 |
+
compiler is passed explicitly:
|
| 47 |
+
|
| 48 |
+
```
|
| 49 |
+
cmake -S llama -B llama/build -G Ninja -DGGML_CUDA=ON \
|
| 50 |
+
-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
|
| 51 |
+
-DCMAKE_CUDA_ARCHITECTURES=89 -DCMAKE_BUILD_TYPE=Release -DLLAMA_CURL=OFF
|
| 52 |
+
cmake --build llama/build -j 28 --target llama-server llama-bench
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
## The blocker on the official fork, and the fix
|
| 56 |
+
|
| 57 |
+
`prism-b10683-d8f26ee` refuses to create the MTP context for this file:
|
| 58 |
+
|
| 59 |
+
```
|
| 60 |
+
E llama_init_from_model: failed to initialize the context: Hadamard-latent table 'token_embd.weight' is read without the inverse transform
|
| 61 |
+
E common_speculative_init_result: failed to create MTP context
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
The guard is `llama_verify_hadamard_graph` (both strings are visible in `libllama.so`); no flag bypasses it. The MTP
|
| 65 |
+
graph reads `token_embd` with a plain `ggml_get_rows`, but the table is stored in the rotated (Hadamard-latent) basis.
|
| 66 |
+
The fix is to apply the inverse transform to that lookup — `runtime/bonsai-mtp-embedding.patch` in the drafter repo
|
| 67 |
+
does exactly that in `src/models/qwen35.cpp::graph_mtp`, and the source archive already contains it.
|
| 68 |
+
|
| 69 |
+
## Results
|
| 70 |
+
|
| 71 |
+
### A/B, 12 prompts x 5 categories, n_predict = 128
|
| 72 |
+
|
| 73 |
+
Both arms identical except `--spec-type`:
|
| 74 |
+
|
| 75 |
+
```
|
| 76 |
+
llama-server -m Ternary-Bonsai-2-27B-PQ2_0-MTP-Q8_0.gguf \
|
| 77 |
+
-ngl 99 -fa on -c 262144 -ctk q4_0 -ctv q4_0 -np 1 -t 16 --temp 0 \
|
| 78 |
+
--spec-type none # arm A
|
| 79 |
+
--spec-type draft-mtp --spec-draft-n-max 2 # arm B
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
Sampling: `POST /completion`, `temperature=0, top_k=1, seed=7, cache_prompt=false`. Acceptance is read from the
|
| 83 |
+
response `timings` object (`draft_n`, `draft_n_accepted`) — `llama-cli` does not print acceptance, only the server does.
|
| 84 |
+
|
| 85 |
+
| # | prompt (abbrev.) | baseline t/s | draft-mtp t/s | speedup | acceptance | accepted/drafted |
|
| 86 |
+
|---|---|---:|---:|---:|---:|---:|
|
| 87 |
+
| R1 | reasoning prose | 67.2 | 88.0 | 1.31x | 57.6% | 68/118 |
|
| 88 |
+
| R2 | reasoning prose | 65.4 | 82.0 | 1.25x | 47.7% | 62/130 |
|
| 89 |
+
| R3 | reasoning prose | 66.6 | 84.6 | 1.27x | 57.6% | 68/118 |
|
| 90 |
+
| C1 | Python continuation | 67.1 | 99.8 | 1.49x | 77.0% | 77/100 |
|
| 91 |
+
| C2 | Python continuation | 67.4 | 114.8 | 1.70x | 94.3% | 83/88 |
|
| 92 |
+
| C3 | async Python | 67.7 | 89.2 | 1.32x | 62.5% | 70/112 |
|
| 93 |
+
| M1 | step-by-step math | 68.1 | 97.2 | 1.43x | 72.1% | 75/104 |
|
| 94 |
+
| M2 | probability recursion | 68.2 | 84.0 | 1.23x | 54.5% | 66/121 |
|
| 95 |
+
| F1 | JSON repetition | 68.3 | 111.5 | 1.63x | 90.0% | 81/90 |
|
| 96 |
+
| F2 | list continuation | 68.3 | 112.3 | 1.64x | 92.1% | 82/89 |
|
| 97 |
+
| Z1 | Chinese rewrite | 68.5 | 91.7 | 1.34x | 64.5% | 71/110 |
|
| 98 |
+
| **median** | | **67.5** | **90.4** | **1.338x** | **68.1%** | **803/1180** |
|
| 99 |
+
|
| 100 |
+
By category: code 1.32–1.70x (acceptance 62–94%), format/repetitive 1.63–1.64x (90–92%), math 1.23–1.43x,
|
| 101 |
+
reasoning prose 1.25–1.31x (48–58%). The pattern is the usual one: speculation pays where text is predictable.
|
| 102 |
+
|
| 103 |
+
> A 12th prompt (a second Chinese prompt) stopped after 1 token with `stop_type=eos` and empty content in **both**
|
| 104 |
+
> arms — an artifact of raw `/completion` without a chat template, not a model defect. It is recorded in
|
| 105 |
+
> `ab_base.json` / `ab_mtp.json` and excluded from the statistics above.
|
| 106 |
+
|
| 107 |
+
### Draft length
|
| 108 |
+
|
| 109 |
+
`--spec-draft-n-max 2` vs `3` on a 3-prompt quick set: 82.4 vs 83.0 t/s total (acceptance 69.9% vs 59.0%).
|
| 110 |
+
Roughly a wash; lower draft length favors repetitive text, higher favors code.
|
| 111 |
+
|
| 112 |
+
### Long context (chat path, natural text, exact depths via /tokenize)
|
| 113 |
+
|
| 114 |
+
| depth (tokens) | prefill t/s (MTP) | decode t/s (MTP) | acceptance | decode t/s (no spec) | MTP speedup |
|
| 115 |
+
|---:|---:|---:|---:|---:|---:|
|
| 116 |
+
| 8,020 | 1855 | 86.9 | 65.8% | 63.0 | 1.38x |
|
| 117 |
+
| 31,939 | 1674 | 62.4 | 52.2% | 53.7 | 1.16x |
|
| 118 |
+
| 64,084 | 1332 | 55.4 | 67.9% | 43.4 | 1.28x |
|
| 119 |
+
| 127,870 | 974 | 46.1 | 82.3% | 33.3 | 1.38x |
|
| 120 |
+
| 191,099 | 722 | 35.0 | 84.1% | 26.5 | 1.32x |
|
| 121 |
+
|
| 122 |
+
Decode falls hard with depth (87 -> 35 t/s with MTP; 63 -> 26.5 without) — that is KV cache traffic, and it
|
| 123 |
+
dominates long-context interactivity far more than the weight packing does. MTP's edge does **not** decay with
|
| 124 |
+
depth (1.16-1.38x); acceptance actually rises (66% -> 84%) because a long natural-text context constrains the
|
| 125 |
+
continuation while the draft's own cost stays flat.
|
| 126 |
+
|
| 127 |
+
Gotcha for anyone measuring this: `timings.prompt_n` reports only the **newly evaluated** tokens. A
|
| 128 |
+
191k-token prompt can come back as `prompt_n = 63745` because llama-server reuses the cached prefix; the server
|
| 129 |
+
log shows `n_tokens = 191139, truncated = 0`, so nothing is being dropped. Interleaving a short "cache buster"
|
| 130 |
+
request does not evict the checkpoints — use `POST /tokenize` for the true length, or sum the incremental
|
| 131 |
+
`prompt_ms` across a cumulative ladder.
|
| 132 |
+
|
| 133 |
+
### Prefix reuse (same config, no speculation)
|
| 134 |
+
|
| 135 |
+
Re-sending an **identical** 12,485-token prompt evaluates only `prompt_n = 4` tokens in 0.28 s (0.4 s wall). So a
|
| 136 |
+
continuing conversation does not repay prefill; switching conversations does (single KV slot, `-np 1`).
|
| 137 |
+
|
| 138 |
+
### 16 GB VRAM: KV precision is the trap, context size is not
|
| 139 |
+
|
| 140 |
+
| config (`-c 262144`) | prefill (12.5k prompt) | decode | VRAM |
|
| 141 |
+
|---|---:|---:|---:|
|
| 142 |
+
| PQ2_0 + MTP, `-ctk q8_0 -ctv q8_0` | **101 → 35 t/s** (10,240 tokens took 293 s) | — | 15.7 GiB |
|
| 143 |
+
| PQ2_0 + MTP, `-ctk q4_0 -ctv q4_0` | **1726 t/s** | 90.4 t/s (median) | 15.7 GiB |
|
| 144 |
+
| PTQ1_0 (no MTP), `-ctk q4_0 -ctv q4_0` | 1073 t/s | ~76 t/s | 12.4 GiB |
|
| 145 |
+
|
| 146 |
+
The `common_fit_params: failed to fit params to free device memory` warning appears in the q4_0/262144 state too,
|
| 147 |
+
but performance is unaffected — the prefill collapse tracks **KV cache size**, not the warning. Also note PQ2_0
|
| 148 |
+
prefill here is 1.6x faster than PTQ1_0 at the same context, consistent with the model card.
|
| 149 |
+
|
| 150 |
+
## Files
|
| 151 |
+
|
| 152 |
+
| file | what |
|
| 153 |
+
|---|---|
|
| 154 |
+
| `mtp_ab.py` | the 12-prompt A/B harness (reads `draft_n`/`draft_n_accepted` from timings) |
|
| 155 |
+
| `ab_driver.sh` | launches one arm as a transient unit, runs the harness, tears down |
|
| 156 |
+
| `mtp_bench.py` | smaller 3-prompt quick bench |
|
| 157 |
+
| `run_mtp_ab2.sh` | single-arm driver |
|
| 158 |
+
| `ab_base.json`, `ab_mtp.json` | raw per-prompt results and timings for both arms |
|
| 159 |
+
| `mtp_n3.json` | `--spec-draft-n-max 3` arm |
|
| 160 |
+
|
| 161 |
+
## What was NOT measured
|
| 162 |
+
|
| 163 |
+
The official 14-benchmark suite; multi-run means per prompt (each prompt was run once); contexts beyond 262,144;
|
| 164 |
+
CPU-only runs; DFlash2 head comparison. These are single-machine measurements and should be read as such.
|
| 165 |
+
|
| 166 |
+
## Credits
|
| 167 |
+
|
| 168 |
+
Model: `prism-ml/Ternary-Bonsai-2-27B-gguf` (Apache 2.0). MTP head, patch and patched runtime source:
|
| 169 |
+
`ProCreations/Ternary-Bonsai-2-27B-MTP`. This bundle only records an independent reproduction on Ada/SM89 plus
|
| 170 |
+
the measurement protocol.
|