|
Download README.md from zhaokeqi/bonsai2-27b-mtp-repro: direct link, hf CLI and curl.
- Browser
- Download file 9.77 kB
-
https://huggingface.co/datasets/zhaokeqi/bonsai2-27b-mtp-repro/resolve/main/README.md
- Command line
-
hf download hf://datasets/zhaokeqi/bonsai2-27b-mtp-repro/README.md
-
curl -L -o README.md https://huggingface.co/datasets/zhaokeqi/bonsai2-27b-mtp-repro/resolve/main/README.md
9.77 kB
| license: apache-2.0 | |
| pretty_name: Ternary-Bonsai-2-27B + in-file MTP reproduction (Ada/SM89) | |
| tags: | |
| - ternary | |
| - speculative-decoding | |
| - mtp | |
| - llama.cpp | |
| - bonsai | |
| # Ternary-Bonsai-2-27B + in-file MTP: reproduction bundle (RTX 4080 SUPER, Ada/SM89) | |
| > **This repository holds the raw data. The method (build script, harness, launch units, write-up) lives on GitHub:** | |
| > **<https://github.com/zhaoyilun/bonsai2-27b-mtp-repro>** | |
| > | |
| > Both are the same piece of work: the GitHub repo has the code and the how-to, this dataset has the | |
| > measurements it produced. Cross-linked in both directions. | |
| Raw measurements, scripts and notes for the two discussions: | |
| - official model repo: https://huggingface.co/prism-ml/Ternary-Bonsai-2-27B-gguf/discussions/23 | |
| - drafter repo: https://huggingface.co/ProCreations/Ternary-Bonsai-2-27B-MTP/discussions/2 | |
| **Headline**: with the MTP block packaged *inside* the target GGUF (so the draft context is created against the | |
| target and shares its vocabulary), MTP speculative decoding gives a **median 1.338x decode speedup** | |
| (range 1.23x–1.70x, aggregate draft acceptance **68.1%**, 803/1180) on a single 16 GB Ada card — after | |
| working around a hard guard in the official fork that refuses the MTP graph on Hadamard-folded weights. | |
|  | |
| ## Environment | |
| | item | value | | |
| |---|---| | |
| | GPU | NVIDIA RTX 4080 SUPER, 16376 MiB (Ada, SM89) | | |
| | Driver / toolkit | CUDA UMD 13.3, CUDA toolkit 13.3.73 | | |
| | Host | WSL2 (kernel 5.15), 32-core CPU, 46 GB RAM | | |
| | 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`) | | |
| | Runtime | built from `runtime/prism-dflash2-source.tar.gz`, sha256 `8c0f589673b25574f27f013bb3278824384eb35eb984034a2445af3c437b9d05`, base `d8f26ee`, `-DCMAKE_CUDA_ARCHITECTURES=89` | | |
| The published prebuilt runtime archive is CUDA 13.3 **SM120 (Blackwell) only**, so on Ada it has to be built from | |
| the source they ship. Build on 32 cores: 484 targets, ~9 minutes. | |
| One gotcha worth knowing: with `nvcc` not on `PATH`, CMake fails with `CMAKE_CUDA_COMPILER-NOTFOUND` unless the | |
| compiler is passed explicitly: | |
| ``` | |
| cmake -S llama -B llama/build -G Ninja -DGGML_CUDA=ON \ | |
| -DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \ | |
| -DCMAKE_CUDA_ARCHITECTURES=89 -DCMAKE_BUILD_TYPE=Release -DLLAMA_CURL=OFF | |
| cmake --build llama/build -j 28 --target llama-server llama-bench | |
| ``` | |
| ## The blocker on the official fork, and the fix | |
| `prism-b10683-d8f26ee` refuses to create the MTP context for this file: | |
| ``` | |
| E llama_init_from_model: failed to initialize the context: Hadamard-latent table 'token_embd.weight' is read without the inverse transform | |
| E common_speculative_init_result: failed to create MTP context | |
| ``` | |
| The guard is `llama_verify_hadamard_graph` (both strings are visible in `libllama.so`); no flag bypasses it. The MTP | |
| graph reads `token_embd` with a plain `ggml_get_rows`, but the table is stored in the rotated (Hadamard-latent) basis. | |
| The fix is to apply the inverse transform to that lookup — `runtime/bonsai-mtp-embedding.patch` in the drafter repo | |
| does exactly that in `src/models/qwen35.cpp::graph_mtp`, and the source archive already contains it. | |
| ## Results | |
| ### A/B, 12 prompts x 5 categories, n_predict = 128 | |
| Both arms identical except `--spec-type`: | |
| ``` | |
| llama-server -m Ternary-Bonsai-2-27B-PQ2_0-MTP-Q8_0.gguf \ | |
| -ngl 99 -fa on -c 262144 -ctk q4_0 -ctv q4_0 -np 1 -t 16 --temp 0 \ | |
| --spec-type none # arm A | |
| --spec-type draft-mtp --spec-draft-n-max 2 # arm B | |
| ``` | |
| Sampling: `POST /completion`, `temperature=0, top_k=1, seed=7, cache_prompt=false`. Acceptance is read from the | |
| response `timings` object (`draft_n`, `draft_n_accepted`) — `llama-cli` does not print acceptance, only the server does. | |
| | # | prompt (abbrev.) | baseline t/s | draft-mtp t/s | speedup | acceptance | accepted/drafted | | |
| |---|---|---:|---:|---:|---:|---:| | |
| | R1 | reasoning prose | 67.2 | 88.0 | 1.31x | 57.6% | 68/118 | | |
| | R2 | reasoning prose | 65.4 | 82.0 | 1.25x | 47.7% | 62/130 | | |
| | R3 | reasoning prose | 66.6 | 84.6 | 1.27x | 57.6% | 68/118 | | |
| | C1 | Python continuation | 67.1 | 99.8 | 1.49x | 77.0% | 77/100 | | |
| | C2 | Python continuation | 67.4 | 114.8 | 1.70x | 94.3% | 83/88 | | |
| | C3 | async Python | 67.7 | 89.2 | 1.32x | 62.5% | 70/112 | | |
| | M1 | step-by-step math | 68.1 | 97.2 | 1.43x | 72.1% | 75/104 | | |
| | M2 | probability recursion | 68.2 | 84.0 | 1.23x | 54.5% | 66/121 | | |
| | F1 | JSON repetition | 68.3 | 111.5 | 1.63x | 90.0% | 81/90 | | |
| | F2 | list continuation | 68.3 | 112.3 | 1.64x | 92.1% | 82/89 | | |
| | Z1 | Chinese rewrite | 68.5 | 91.7 | 1.34x | 64.5% | 71/110 | | |
| | **median** | | **67.5** | **90.4** | **1.338x** | **68.1%** | **803/1180** | | |
| By category: code 1.32–1.70x (acceptance 62–94%), format/repetitive 1.63–1.64x (90–92%), math 1.23–1.43x, | |
| reasoning prose 1.25–1.31x (48–58%). The pattern is the usual one: speculation pays where text is predictable. | |
| > A 12th prompt (a second Chinese prompt) stopped after 1 token with `stop_type=eos` and empty content in **both** | |
| > arms — an artifact of raw `/completion` without a chat template, not a model defect. It is recorded in | |
| > `ab_base.json` / `ab_mtp.json` and excluded from the statistics above. | |
| ### Draft length | |
| `--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%). | |
| Roughly a wash; lower draft length favors repetitive text, higher favors code. | |
| ### Independent verification (third party) | |
| Both the failure and the fix were reproduced on entirely different hardware — **RDNA3 / ROCm 6.4 / Windows 11** | |
| (RX 7900 XTX, gfx1100) — reported on [PR #205](https://github.com/PrismML-Eng/llama.cpp/pull/205#issuecomment-5742011541): | |
| identical `latent lookup 'mtp_tok_embd-64'` failure without the patch, then **decode 41.6 -> 75.9 t/s (1.82x)** with | |
| it at **0.82 acceptance** and 2.64 tokens committed per round. On this machine (Ada/CUDA) the same fix gives | |
| ~67 -> ~90 t/s (1.34x) at 0.68 aggregate acceptance. | |
| The multiples differ because the **baselines** differ: speculation pays more where the target decodes slower, since | |
| the draft's roughly fixed per-round cost is then a smaller fraction of a round. The depth sweep below shows the same | |
| effect along the context axis — decode falls 87 -> 35 t/s while acceptance rises 66% -> 84%. | |
| ### Long context (chat path, natural text, exact depths via /tokenize) | |
| | depth (tokens) | prefill t/s (MTP) | decode t/s (MTP) | acceptance | decode t/s (no spec) | MTP speedup | | |
| |---:|---:|---:|---:|---:|---:| | |
| | 8,020 | 1855 | 86.9 | 65.8% | 63.0 | 1.38x | | |
| | 31,939 | 1674 | 62.4 | 52.2% | 53.7 | 1.16x | | |
| | 64,084 | 1332 | 55.4 | 67.9% | 43.4 | 1.28x | | |
| | 127,870 | 974 | 46.1 | 82.3% | 33.3 | 1.38x | | |
| | 191,099 | 722 | 35.0 | 84.1% | 26.5 | 1.32x | | |
| Decode falls hard with depth (87 -> 35 t/s with MTP; 63 -> 26.5 without) — that is KV cache traffic, and it | |
| dominates long-context interactivity far more than the weight packing does. MTP's edge does **not** decay with | |
| depth (1.16-1.38x); acceptance actually rises (66% -> 84%) because a long natural-text context constrains the | |
| continuation while the draft's own cost stays flat. | |
| Gotcha for anyone measuring this: `timings.prompt_n` reports only the **newly evaluated** tokens. A | |
| 191k-token prompt can come back as `prompt_n = 63745` because llama-server reuses the cached prefix; the server | |
| log shows `n_tokens = 191139, truncated = 0`, so nothing is being dropped. Interleaving a short "cache buster" | |
| request does not evict the checkpoints — use `POST /tokenize` for the true length, or sum the incremental | |
| `prompt_ms` across a cumulative ladder. | |
| ### Prefix reuse (same config, no speculation) | |
| Re-sending an **identical** 12,485-token prompt evaluates only `prompt_n = 4` tokens in 0.28 s (0.4 s wall). So a | |
| continuing conversation does not repay prefill; switching conversations does (single KV slot, `-np 1`). | |
| ### 16 GB VRAM: KV precision is the trap, context size is not | |
| | config (`-c 262144`) | prefill (12.5k prompt) | decode | VRAM | | |
| |---|---:|---:|---:| | |
| | PQ2_0 + MTP, `-ctk q8_0 -ctv q8_0` | **101 → 35 t/s** (10,240 tokens took 293 s) | — | 15.7 GiB | | |
| | PQ2_0 + MTP, `-ctk q4_0 -ctv q4_0` | **1726 t/s** | 90.4 t/s (median) | 15.7 GiB | | |
| | PTQ1_0 (no MTP), `-ctk q4_0 -ctv q4_0` | 1073 t/s | ~76 t/s | 12.4 GiB | | |
| The `common_fit_params: failed to fit params to free device memory` warning appears in the q4_0/262144 state too, | |
| but performance is unaffected — the prefill collapse tracks **KV cache size**, not the warning. Also note PQ2_0 | |
| prefill here is 1.6x faster than PTQ1_0 at the same context, consistent with the model card. | |
| ## Files | |
| | file | what | | |
| |---|---| | |
| | `mtp_ab.py` | the 12-prompt A/B harness (reads `draft_n`/`draft_n_accepted` from timings) | | |
| | `ab_driver.sh` | launches one arm as a transient unit, runs the harness, tears down | | |
| | `mtp_bench.py` | smaller 3-prompt quick bench | | |
| | `run_mtp_ab2.sh` | single-arm driver | | |
| | `ab_base.json`, `ab_mtp.json` | raw per-prompt results and timings for both arms | | |
| | `mtp_n3.json` | `--spec-draft-n-max 3` arm | | |
| ## What was NOT measured | |
| The official 14-benchmark suite; multi-run means per prompt (each prompt was run once); contexts beyond 262,144; | |
| CPU-only runs; DFlash2 head comparison. These are single-machine measurements and should be read as such. | |
| ## Credits | |
| Model: `prism-ml/Ternary-Bonsai-2-27B-gguf` (Apache 2.0). MTP head, patch and patched runtime source: | |
| `ProCreations/Ternary-Bonsai-2-27B-MTP`. This bundle only records an independent reproduction on Ada/SM89 plus | |
| the measurement protocol. | |