Add reproduction bundle: raw A/B results, harness, notes
Browse files- README.md +130 -0
- ab_base.json +101 -0
- ab_driver.sh +13 -0
- ab_mtp.json +101 -0
- mtp_ab.py +47 -0
- mtp_bench.py +49 -0
- mtp_n3.json +74 -0
- run_mtp_ab2.sh +25 -0
README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Ternary-Bonsai-2-27B + in-file MTP: reproduction bundle (RTX 4080 SUPER, Ada/SM89)
|
| 2 |
+
|
| 3 |
+
Raw measurements, scripts and notes for the two discussions:
|
| 4 |
+
|
| 5 |
+
- official model repo: https://huggingface.co/prism-ml/Ternary-Bonsai-2-27B-gguf/discussions/23
|
| 6 |
+
- drafter repo: https://huggingface.co/ProCreations/Ternary-Bonsai-2-27B-MTP/discussions/2
|
| 7 |
+
|
| 8 |
+
**Headline**: with the MTP block packaged *inside* the target GGUF (so the draft context is created against the
|
| 9 |
+
target and shares its vocabulary), MTP speculative decoding gives a **median 1.338x decode speedup**
|
| 10 |
+
(range 1.23x–1.70x, aggregate draft acceptance **68.1%**, 803/1180) on a single 16 GB Ada card — after
|
| 11 |
+
working around a hard guard in the official fork that refuses the MTP graph on Hadamard-folded weights.
|
| 12 |
+
|
| 13 |
+
## Environment
|
| 14 |
+
|
| 15 |
+
| item | value |
|
| 16 |
+
|---|---|
|
| 17 |
+
| GPU | NVIDIA RTX 4080 SUPER, 16376 MiB (Ada, SM89) |
|
| 18 |
+
| Driver / toolkit | CUDA UMD 13.3, CUDA toolkit 13.3.73 |
|
| 19 |
+
| Host | WSL2 (kernel 5.15), 32-core CPU, 46 GB RAM |
|
| 20 |
+
| 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`) |
|
| 21 |
+
| Runtime | built from `runtime/prism-dflash2-source.tar.gz`, sha256 `8c0f589673b25574f27f013bb3278824384eb35eb984034a2445af3c437b9d05`, base `d8f26ee`, `-DCMAKE_CUDA_ARCHITECTURES=89` |
|
| 22 |
+
|
| 23 |
+
The published prebuilt runtime archive is CUDA 13.3 **SM120 (Blackwell) only**, so on Ada it has to be built from
|
| 24 |
+
the source they ship. Build on 32 cores: 484 targets, ~9 minutes.
|
| 25 |
+
|
| 26 |
+
One gotcha worth knowing: with `nvcc` not on `PATH`, CMake fails with `CMAKE_CUDA_COMPILER-NOTFOUND` unless the
|
| 27 |
+
compiler is passed explicitly:
|
| 28 |
+
|
| 29 |
+
```
|
| 30 |
+
cmake -S llama -B llama/build -G Ninja -DGGML_CUDA=ON \
|
| 31 |
+
-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
|
| 32 |
+
-DCMAKE_CUDA_ARCHITECTURES=89 -DCMAKE_BUILD_TYPE=Release -DLLAMA_CURL=OFF
|
| 33 |
+
cmake --build llama/build -j 28 --target llama-server llama-bench
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
## The blocker on the official fork, and the fix
|
| 37 |
+
|
| 38 |
+
`prism-b10683-d8f26ee` refuses to create the MTP context for this file:
|
| 39 |
+
|
| 40 |
+
```
|
| 41 |
+
E llama_init_from_model: failed to initialize the context: Hadamard-latent table 'token_embd.weight' is read without the inverse transform
|
| 42 |
+
E common_speculative_init_result: failed to create MTP context
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
The guard is `llama_verify_hadamard_graph` (both strings are visible in `libllama.so`); no flag bypasses it. The MTP
|
| 46 |
+
graph reads `token_embd` with a plain `ggml_get_rows`, but the table is stored in the rotated (Hadamard-latent) basis.
|
| 47 |
+
The fix is to apply the inverse transform to that lookup — `runtime/bonsai-mtp-embedding.patch` in the drafter repo
|
| 48 |
+
does exactly that in `src/models/qwen35.cpp::graph_mtp`, and the source archive already contains it.
|
| 49 |
+
|
| 50 |
+
## Results
|
| 51 |
+
|
| 52 |
+
### A/B, 12 prompts x 5 categories, n_predict = 128
|
| 53 |
+
|
| 54 |
+
Both arms identical except `--spec-type`:
|
| 55 |
+
|
| 56 |
+
```
|
| 57 |
+
llama-server -m Ternary-Bonsai-2-27B-PQ2_0-MTP-Q8_0.gguf \
|
| 58 |
+
-ngl 99 -fa on -c 262144 -ctk q4_0 -ctv q4_0 -np 1 -t 16 --temp 0 \
|
| 59 |
+
--spec-type none # arm A
|
| 60 |
+
--spec-type draft-mtp --spec-draft-n-max 2 # arm B
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
Sampling: `POST /completion`, `temperature=0, top_k=1, seed=7, cache_prompt=false`. Acceptance is read from the
|
| 64 |
+
response `timings` object (`draft_n`, `draft_n_accepted`) — `llama-cli` does not print acceptance, only the server does.
|
| 65 |
+
|
| 66 |
+
| # | prompt (abbrev.) | baseline t/s | draft-mtp t/s | speedup | acceptance | accepted/drafted |
|
| 67 |
+
|---|---|---:|---:|---:|---:|---:|
|
| 68 |
+
| R1 | reasoning prose | 67.2 | 88.0 | 1.31x | 57.6% | 68/118 |
|
| 69 |
+
| R2 | reasoning prose | 65.4 | 82.0 | 1.25x | 47.7% | 62/130 |
|
| 70 |
+
| R3 | reasoning prose | 66.6 | 84.6 | 1.27x | 57.6% | 68/118 |
|
| 71 |
+
| C1 | Python continuation | 67.1 | 99.8 | 1.49x | 77.0% | 77/100 |
|
| 72 |
+
| C2 | Python continuation | 67.4 | 114.8 | 1.70x | 94.3% | 83/88 |
|
| 73 |
+
| C3 | async Python | 67.7 | 89.2 | 1.32x | 62.5% | 70/112 |
|
| 74 |
+
| M1 | step-by-step math | 68.1 | 97.2 | 1.43x | 72.1% | 75/104 |
|
| 75 |
+
| M2 | probability recursion | 68.2 | 84.0 | 1.23x | 54.5% | 66/121 |
|
| 76 |
+
| F1 | JSON repetition | 68.3 | 111.5 | 1.63x | 90.0% | 81/90 |
|
| 77 |
+
| F2 | list continuation | 68.3 | 112.3 | 1.64x | 92.1% | 82/89 |
|
| 78 |
+
| Z1 | Chinese rewrite | 68.5 | 91.7 | 1.34x | 64.5% | 71/110 |
|
| 79 |
+
| **median** | | **67.5** | **90.4** | **1.338x** | **68.1%** | **803/1180** |
|
| 80 |
+
|
| 81 |
+
By category: code 1.32–1.70x (acceptance 62–94%), format/repetitive 1.63–1.64x (90–92%), math 1.23–1.43x,
|
| 82 |
+
reasoning prose 1.25–1.31x (48–58%). The pattern is the usual one: speculation pays where text is predictable.
|
| 83 |
+
|
| 84 |
+
> A 12th prompt (a second Chinese prompt) stopped after 1 token with `stop_type=eos` and empty content in **both**
|
| 85 |
+
> arms — an artifact of raw `/completion` without a chat template, not a model defect. It is recorded in
|
| 86 |
+
> `ab_base.json` / `ab_mtp.json` and excluded from the statistics above.
|
| 87 |
+
|
| 88 |
+
### Draft length
|
| 89 |
+
|
| 90 |
+
`--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%).
|
| 91 |
+
Roughly a wash; lower draft length favors repetitive text, higher favors code.
|
| 92 |
+
|
| 93 |
+
### Prefix reuse (same config, no speculation)
|
| 94 |
+
|
| 95 |
+
Re-sending an **identical** 12,485-token prompt evaluates only `prompt_n = 4` tokens in 0.28 s (0.4 s wall). So a
|
| 96 |
+
continuing conversation does not repay prefill; switching conversations does (single KV slot, `-np 1`).
|
| 97 |
+
|
| 98 |
+
### 16 GB VRAM: KV precision is the trap, context size is not
|
| 99 |
+
|
| 100 |
+
| config (`-c 262144`) | prefill (12.5k prompt) | decode | VRAM |
|
| 101 |
+
|---|---:|---:|---:|
|
| 102 |
+
| PQ2_0 + MTP, `-ctk q8_0 -ctv q8_0` | **101 → 35 t/s** (10,240 tokens took 293 s) | — | 15.7 GiB |
|
| 103 |
+
| PQ2_0 + MTP, `-ctk q4_0 -ctv q4_0` | **1726 t/s** | 90.4 t/s (median) | 15.7 GiB |
|
| 104 |
+
| PTQ1_0 (no MTP), `-ctk q4_0 -ctv q4_0` | 1073 t/s | ~76 t/s | 12.4 GiB |
|
| 105 |
+
|
| 106 |
+
The `common_fit_params: failed to fit params to free device memory` warning appears in the q4_0/262144 state too,
|
| 107 |
+
but performance is unaffected — the prefill collapse tracks **KV cache size**, not the warning. Also note PQ2_0
|
| 108 |
+
prefill here is 1.6x faster than PTQ1_0 at the same context, consistent with the model card.
|
| 109 |
+
|
| 110 |
+
## Files
|
| 111 |
+
|
| 112 |
+
| file | what |
|
| 113 |
+
|---|---|
|
| 114 |
+
| `mtp_ab.py` | the 12-prompt A/B harness (reads `draft_n`/`draft_n_accepted` from timings) |
|
| 115 |
+
| `ab_driver.sh` | launches one arm as a transient unit, runs the harness, tears down |
|
| 116 |
+
| `mtp_bench.py` | smaller 3-prompt quick bench |
|
| 117 |
+
| `run_mtp_ab2.sh` | single-arm driver |
|
| 118 |
+
| `ab_base.json`, `ab_mtp.json` | raw per-prompt results and timings for both arms |
|
| 119 |
+
| `mtp_n3.json` | `--spec-draft-n-max 3` arm |
|
| 120 |
+
|
| 121 |
+
## What was NOT measured
|
| 122 |
+
|
| 123 |
+
The official 14-benchmark suite; multi-run means per prompt (each prompt was run once); contexts beyond 262,144;
|
| 124 |
+
CPU-only runs; DFlash2 head comparison. These are single-machine measurements and should be read as such.
|
| 125 |
+
|
| 126 |
+
## Credits
|
| 127 |
+
|
| 128 |
+
Model: `prism-ml/Ternary-Bonsai-2-27B-gguf` (Apache 2.0). MTP head, patch and patched runtime source:
|
| 129 |
+
`ProCreations/Ternary-Bonsai-2-27B-MTP`. This bundle only records an independent reproduction on Ada/SM89 plus
|
| 130 |
+
the measurement protocol.
|
ab_base.json
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"tag": "base",
|
| 3 |
+
"results": [
|
| 4 |
+
{
|
| 5 |
+
"name": "R1 reasoning",
|
| 6 |
+
"tps": 67.15504778583991,
|
| 7 |
+
"n": 128,
|
| 8 |
+
"wall": 2.0080041885375977,
|
| 9 |
+
"dn": 0,
|
| 10 |
+
"da": 0
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"name": "R2 reasoning",
|
| 14 |
+
"tps": 65.42088811688807,
|
| 15 |
+
"n": 128,
|
| 16 |
+
"wall": 2.139404773712158,
|
| 17 |
+
"dn": 0,
|
| 18 |
+
"da": 0
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"name": "R3 reasoning",
|
| 22 |
+
"tps": 66.57294035379063,
|
| 23 |
+
"n": 128,
|
| 24 |
+
"wall": 2.1015982627868652,
|
| 25 |
+
"dn": 0,
|
| 26 |
+
"da": 0
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"name": "C1 code",
|
| 30 |
+
"tps": 67.10459016532035,
|
| 31 |
+
"n": 128,
|
| 32 |
+
"wall": 2.090456962585449,
|
| 33 |
+
"dn": 0,
|
| 34 |
+
"da": 0
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"name": "C2 code",
|
| 38 |
+
"tps": 67.42175492988403,
|
| 39 |
+
"n": 128,
|
| 40 |
+
"wall": 2.083451509475708,
|
| 41 |
+
"dn": 0,
|
| 42 |
+
"da": 0
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"name": "C3 code",
|
| 46 |
+
"tps": 67.66148585688477,
|
| 47 |
+
"n": 128,
|
| 48 |
+
"wall": 2.074040412902832,
|
| 49 |
+
"dn": 0,
|
| 50 |
+
"da": 0
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"name": "M1 math",
|
| 54 |
+
"tps": 68.12873433977892,
|
| 55 |
+
"n": 128,
|
| 56 |
+
"wall": 2.061222791671753,
|
| 57 |
+
"dn": 0,
|
| 58 |
+
"da": 0
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"name": "M2 math",
|
| 62 |
+
"tps": 68.19275245279128,
|
| 63 |
+
"n": 128,
|
| 64 |
+
"wall": 2.051217794418335,
|
| 65 |
+
"dn": 0,
|
| 66 |
+
"da": 0
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"name": "F1 format",
|
| 70 |
+
"tps": 68.31218345102393,
|
| 71 |
+
"n": 128,
|
| 72 |
+
"wall": 2.0777087211608887,
|
| 73 |
+
"dn": 0,
|
| 74 |
+
"da": 0
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"name": "F2 format",
|
| 78 |
+
"tps": 68.30072108351834,
|
| 79 |
+
"n": 128,
|
| 80 |
+
"wall": 2.0450594425201416,
|
| 81 |
+
"dn": 0,
|
| 82 |
+
"da": 0
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"name": "Z1 chinese",
|
| 86 |
+
"tps": 68.48945693792805,
|
| 87 |
+
"n": 128,
|
| 88 |
+
"wall": 2.0459251403808594,
|
| 89 |
+
"dn": 0,
|
| 90 |
+
"da": 0
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"name": "Z2 chinese",
|
| 94 |
+
"tps": 0.0,
|
| 95 |
+
"n": 1,
|
| 96 |
+
"wall": 0.21819567680358887,
|
| 97 |
+
"dn": 0,
|
| 98 |
+
"da": 0
|
| 99 |
+
}
|
| 100 |
+
]
|
| 101 |
+
}
|
ab_driver.sh
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -u
|
| 3 |
+
B=/home/zyl/bonsai2/mtp-runtime/source/llama/build/bin
|
| 4 |
+
TAG=$1; shift
|
| 5 |
+
systemctl --user stop llama-bonsai-mtp.service 2>/dev/null; systemctl --user stop llama-bonsai.service 2>/dev/null
|
| 6 |
+
systemctl --user stop "mtpab-$TAG.service" 2>/dev/null; sleep 2
|
| 7 |
+
systemd-run --user --collect --unit="mtpab-$TAG" /bin/bash -c "cd $B && LD_LIBRARY_PATH=$B HOME=/home/zyl \
|
| 8 |
+
./llama-server -m /home/zyl/models/Ternary-Bonsai-2-27B-PQ2_0-MTP-Q8_0.gguf \
|
| 9 |
+
-ngl 99 -fa on -c 262144 -ctk q4_0 -ctv q4_0 -np 1 -t 16 --temp 0 \
|
| 10 |
+
--host 127.0.0.1 --port 8080 -a bonsai-mtp $* > /home/zyl/bonsai2/logs/ab-$TAG.log 2>&1" >/dev/null 2>&1
|
| 11 |
+
for i in $(seq 1 60); do sleep 3; curl -s --max-time 3 -o /dev/null http://127.0.0.1:8080/health 2>/dev/null && break; done
|
| 12 |
+
python3 /home/zyl/bonsai2/mtp_ab.py 8080 "$TAG" 128
|
| 13 |
+
systemctl --user stop "mtpab-$TAG.service"
|
ab_mtp.json
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"tag": "mtp",
|
| 3 |
+
"results": [
|
| 4 |
+
{
|
| 5 |
+
"name": "R1 reasoning",
|
| 6 |
+
"tps": 88.02853510813647,
|
| 7 |
+
"n": 128,
|
| 8 |
+
"wall": 1.6208324432373047,
|
| 9 |
+
"dn": 118,
|
| 10 |
+
"da": 68
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"name": "R2 reasoning",
|
| 14 |
+
"tps": 82.02894394516592,
|
| 15 |
+
"n": 128,
|
| 16 |
+
"wall": 1.7505979537963867,
|
| 17 |
+
"dn": 130,
|
| 18 |
+
"da": 62
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"name": "R3 reasoning",
|
| 22 |
+
"tps": 84.59436668127641,
|
| 23 |
+
"n": 128,
|
| 24 |
+
"wall": 1.700646162033081,
|
| 25 |
+
"dn": 118,
|
| 26 |
+
"da": 68
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"name": "C1 code",
|
| 30 |
+
"tps": 99.84433717511283,
|
| 31 |
+
"n": 128,
|
| 32 |
+
"wall": 1.4969289302825928,
|
| 33 |
+
"dn": 100,
|
| 34 |
+
"da": 77
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"name": "C2 code",
|
| 38 |
+
"tps": 114.81222325282013,
|
| 39 |
+
"n": 128,
|
| 40 |
+
"wall": 1.3252921104431152,
|
| 41 |
+
"dn": 88,
|
| 42 |
+
"da": 83
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"name": "C3 code",
|
| 46 |
+
"tps": 89.18871278214709,
|
| 47 |
+
"n": 128,
|
| 48 |
+
"wall": 1.635740041732788,
|
| 49 |
+
"dn": 112,
|
| 50 |
+
"da": 70
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"name": "M1 math",
|
| 54 |
+
"tps": 97.22071245175326,
|
| 55 |
+
"n": 128,
|
| 56 |
+
"wall": 1.5286304950714111,
|
| 57 |
+
"dn": 104,
|
| 58 |
+
"da": 75
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"name": "M2 math",
|
| 62 |
+
"tps": 84.00415390619317,
|
| 63 |
+
"n": 128,
|
| 64 |
+
"wall": 1.715515375137329,
|
| 65 |
+
"dn": 121,
|
| 66 |
+
"da": 66
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"name": "F1 format",
|
| 70 |
+
"tps": 111.53372929270928,
|
| 71 |
+
"n": 128,
|
| 72 |
+
"wall": 1.3411991596221924,
|
| 73 |
+
"dn": 90,
|
| 74 |
+
"da": 81
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"name": "F2 format",
|
| 78 |
+
"tps": 112.33182289782492,
|
| 79 |
+
"n": 128,
|
| 80 |
+
"wall": 1.3317580223083496,
|
| 81 |
+
"dn": 89,
|
| 82 |
+
"da": 82
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"name": "Z1 chinese",
|
| 86 |
+
"tps": 91.65472869839459,
|
| 87 |
+
"n": 128,
|
| 88 |
+
"wall": 1.5930490493774414,
|
| 89 |
+
"dn": 110,
|
| 90 |
+
"da": 71
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"name": "Z2 chinese",
|
| 94 |
+
"tps": 0.0,
|
| 95 |
+
"n": 1,
|
| 96 |
+
"wall": 0.21099615097045898,
|
| 97 |
+
"dn": 0,
|
| 98 |
+
"da": 0
|
| 99 |
+
}
|
| 100 |
+
]
|
| 101 |
+
}
|
mtp_ab.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""多 prompt A/B:12 条 × 5 类,temp0/topk1/seed7/n=128,读 timings 的 draft 计数。"""
|
| 3 |
+
import json, sys, time, urllib.request, statistics
|
| 4 |
+
|
| 5 |
+
PORT = int(sys.argv[1]); TAG = sys.argv[2]; NP = int(sys.argv[3]) if len(sys.argv) > 3 else 128
|
| 6 |
+
URL = f"http://127.0.0.1:{PORT}/completion"
|
| 7 |
+
H = {"Content-Type":"application/json","Authorization":"Bearer sk-lan-97f1c41bb1642ab23f810c65"}
|
| 8 |
+
|
| 9 |
+
P = {
|
| 10 |
+
"R1 reasoning": "Quantum computing exploits superposition and entanglement to perform computations that are intractable for classical machines. The principal obstacle in practice is decoherence, which",
|
| 11 |
+
"R2 reasoning": "The reason ternary weights appeal to hardware designers is not only the storage density. A ternary multiply accumulator can be implemented as",
|
| 12 |
+
"R3 reasoning": "When a large language model is quantized below two bits per weight, the failure mode that appears first is usually not factual recall but rather",
|
| 13 |
+
"C1 code": "def merge_intervals(intervals):\n \"\"\"Merge overlapping intervals.\"\"\"\n if not intervals:\n return []\n intervals = sorted(intervals)\n merged = [intervals[0]]\n for start, end in intervals[1:]:\n",
|
| 14 |
+
"C2 code": "class RingBuffer:\n def __init__(self, capacity):\n self.capacity = capacity\n self.buf = [None] * capacity\n self.head = 0\n self.size = 0\n\n def push(self, item):\n",
|
| 15 |
+
"C3 code": "async def fetch_all(session, urls, concurrency=8):\n sem = asyncio.Semaphore(concurrency)\n async def one(u):\n async with sem:\n async with session.get(u) as r:\n",
|
| 16 |
+
"M1 math": "A train leaves at 09:15 and travels 240 km at an average speed of 96 km/h. It then waits 20 minutes and returns at 80 km/h. Step by step, the arrival time back is",
|
| 17 |
+
"M2 math": "We flip a fair coin until we see two heads in a row. Let E be the expected number of flips. Setting up the recursion gives",
|
| 18 |
+
"F1 format": "Output the JSON object for a user record with fields name, age, city, tags (array), then output it again, then again, then again:",
|
| 19 |
+
"F2 format": "Item 1: alpha\nItem 2: beta\nItem 3: gamma\nItem 4: delta\nItem 5:",
|
| 20 |
+
"Z1 chinese": "把下面这段技术说明改写成更通俗的中文,保持信息不丢:折叠旋转基把正交变换折进权重,运行时只需对激活做一次同构变换即可。改写结果:",
|
| 21 |
+
"Z2 chinese": "请用中文解释为什么三值权重(-1、0、+1)在存储上比 int4 更省,并给一个具体数字例子。回答:",
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
def run(name, prompt):
|
| 25 |
+
body = json.dumps({"prompt": prompt, "n_predict": NP, "temperature": 0.0,
|
| 26 |
+
"top_k": 1, "seed": 7, "cache_prompt": False}).encode()
|
| 27 |
+
t0 = time.time()
|
| 28 |
+
try:
|
| 29 |
+
r = json.load(urllib.request.urlopen(urllib.request.Request(URL, data=body, headers=H), timeout=1800))
|
| 30 |
+
except Exception as e:
|
| 31 |
+
print(f" {name:14} 失败: {e}"); return None
|
| 32 |
+
wall = time.time() - t0; t = r.get("timings", {})
|
| 33 |
+
dn, da = t.get("draft_n") or 0, t.get("draft_n_accepted") or 0
|
| 34 |
+
tps = t.get("predicted_per_second", 0.0)
|
| 35 |
+
print(f" {name:14} {tps:6.1f} t/s | {t.get('predicted_n'):4} tok | {wall:5.1f}s wall | "
|
| 36 |
+
f"acc {da/dn*100:5.1f}% ({da}/{dn})" if dn else f" {name:14} {tps:6.1f} t/s | {t.get('predicted_n'):4} tok | no draft")
|
| 37 |
+
return {"name": name, "tps": tps, "n": t.get("predicted_n"), "wall": wall, "dn": dn, "da": da}
|
| 38 |
+
|
| 39 |
+
print(f"[{TAG}] n_predict={NP} prompts={len(P)}")
|
| 40 |
+
res = [x for x in (run(k, v) for k, v in P.items()) if x]
|
| 41 |
+
tps = [r["tps"] for r in res]
|
| 42 |
+
tot_n = sum(r["n"] for r in res); tot_w = sum(r["wall"] for r in res)
|
| 43 |
+
dn = sum(r["dn"] for r in res); da = sum(r["da"] for r in res)
|
| 44 |
+
print(f" ---- {TAG}: 均值 {statistics.mean(tps):.1f} t/s | 中位 {statistics.median(tps):.1f} | "
|
| 45 |
+
f"端到端 {tot_n/tot_w:.1f} t/s | 接受率 {da/dn*100:.1f}% ({da}/{dn})" if dn else
|
| 46 |
+
f" ---- {TAG}: 均值 {statistics.mean(tps):.1f} t/s | 中位 {statistics.median(tps):.1f} | 端到端 {tot_n/tot_w:.1f} t/s")
|
| 47 |
+
json.dump({"tag": TAG, "results": res}, open(f"/home/zyl/bonsai2/ab_{TAG}.json","w"), indent=1)
|
mtp_bench.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""A/B 测 MTP 接受率与速度:同一 prompt 集、temp0/topk1/seed7,读 timings 的 draft_n/draft_n_accepted。"""
|
| 3 |
+
import json, sys, time, urllib.request
|
| 4 |
+
|
| 5 |
+
PORT = int(sys.argv[1]) if len(sys.argv) > 1 else 8080
|
| 6 |
+
TAG = sys.argv[2] if len(sys.argv) > 2 else "run"
|
| 7 |
+
NP = int(sys.argv[3]) if len(sys.argv) > 3 else 96
|
| 8 |
+
URL = f"http://127.0.0.1:{PORT}/completion"
|
| 9 |
+
H = {"Content-Type": "application/json",
|
| 10 |
+
"Authorization": "Bearer sk-lan-97f1c41bb1642ab23f810c65"}
|
| 11 |
+
|
| 12 |
+
PROMPTS = {
|
| 13 |
+
"V(reasoning)": ("Quantum computing exploits superposition and entanglement to perform "
|
| 14 |
+
"computations that are intractable for classical machines. The principal "
|
| 15 |
+
"obstacle in practice is decoherence, which"),
|
| 16 |
+
"P(repetitive)": "The capital of France is",
|
| 17 |
+
"C(code)": ("def merge_intervals(intervals):\n \"\"\"Merge overlapping intervals.\"\"\"\n"
|
| 18 |
+
" if not intervals:\n return []\n intervals = sorted(intervals)\n merged = [intervals[0]]\n for start, end in intervals[1:]:\n"),
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
def run(name, prompt):
|
| 22 |
+
body = json.dumps({"prompt": prompt, "n_predict": NP, "temperature": 0.0,
|
| 23 |
+
"top_k": 1, "seed": 7, "cache_prompt": False}).encode()
|
| 24 |
+
t0 = time.time()
|
| 25 |
+
try:
|
| 26 |
+
r = json.load(urllib.request.urlopen(
|
| 27 |
+
urllib.request.Request(URL, data=body, headers=H), timeout=1800))
|
| 28 |
+
except Exception as e:
|
| 29 |
+
print(f" {name:14} 请求失败: {e}"); return None
|
| 30 |
+
wall = time.time() - t0
|
| 31 |
+
t = r.get("timings", {})
|
| 32 |
+
dn, da = t.get("draft_n"), t.get("draft_n_accepted")
|
| 33 |
+
acc = (da / dn) if (dn and da is not None) else None
|
| 34 |
+
print(f" {name:14} gen {t.get('predicted_per_second',0):6.1f} t/s | {t.get('predicted_n'):4} tok | "
|
| 35 |
+
f"wall {wall:5.1f}s | draft {dn if dn is not None else '-'}"
|
| 36 |
+
f"{f'/{da}' if da is not None else ''}"
|
| 37 |
+
f"{f' = {acc*100:.1f}%' if acc is not None else ''}")
|
| 38 |
+
return {"name": name, "tps": t.get("predicted_per_second"), "n": t.get("predicted_n"),
|
| 39 |
+
"wall": wall, "draft_n": dn, "draft_accepted": da, "acc": acc,
|
| 40 |
+
"prompt_ms": t.get("prompt_ms"), "timings": t}
|
| 41 |
+
|
| 42 |
+
print(f"[{TAG}] n_predict={NP}")
|
| 43 |
+
res = [x for x in (run(k, v) for k, v in PROMPTS.items()) if x]
|
| 44 |
+
json.dump({"tag": TAG, "results": res}, open(f"/home/zyl/bonsai2/mtp_{TAG}.json", "w"), indent=1)
|
| 45 |
+
if res:
|
| 46 |
+
tot_n = sum(r["n"] for r in res); tot_w = sum(r["wall"] for r in res)
|
| 47 |
+
dn = sum(r["draft_n"] or 0 for r in res); da = sum(r["draft_accepted"] or 0 for r in res)
|
| 48 |
+
print(f" 合计: {tot_n} tok / {tot_w:.1f}s = {tot_n/tot_w:.1f} t/s | "
|
| 49 |
+
f"draft {dn}→{da}" + (f" ({da/dn*100:.1f}%)" if dn else ""))
|
mtp_n3.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"tag": "n3",
|
| 3 |
+
"results": [
|
| 4 |
+
{
|
| 5 |
+
"name": "V(reasoning)",
|
| 6 |
+
"tps": 88.1621441033446,
|
| 7 |
+
"n": 96,
|
| 8 |
+
"wall": 1.2502977848052979,
|
| 9 |
+
"draft_n": 117,
|
| 10 |
+
"draft_accepted": 56,
|
| 11 |
+
"acc": 0.47863247863247865,
|
| 12 |
+
"prompt_ms": 169.653,
|
| 13 |
+
"timings": {
|
| 14 |
+
"cache_n": 0,
|
| 15 |
+
"prompt_n": 32,
|
| 16 |
+
"prompt_ms": 169.653,
|
| 17 |
+
"prompt_per_token_ms": 5.30165625,
|
| 18 |
+
"prompt_per_second": 188.62030143881924,
|
| 19 |
+
"predicted_n": 96,
|
| 20 |
+
"predicted_ms": 1077.56,
|
| 21 |
+
"predicted_per_token_ms": 11.342736842105262,
|
| 22 |
+
"predicted_per_second": 88.1621441033446,
|
| 23 |
+
"draft_n": 117,
|
| 24 |
+
"draft_n_accepted": 56
|
| 25 |
+
}
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"name": "P(repetitive)",
|
| 29 |
+
"tps": 103.1431518375767,
|
| 30 |
+
"n": 96,
|
| 31 |
+
"wall": 1.1303412914276123,
|
| 32 |
+
"draft_n": 99,
|
| 33 |
+
"draft_accepted": 61,
|
| 34 |
+
"acc": 0.6161616161616161,
|
| 35 |
+
"prompt_ms": 100.431,
|
| 36 |
+
"timings": {
|
| 37 |
+
"cache_n": 0,
|
| 38 |
+
"prompt_n": 5,
|
| 39 |
+
"prompt_ms": 100.431,
|
| 40 |
+
"prompt_per_token_ms": 20.086199999999998,
|
| 41 |
+
"prompt_per_second": 49.785424819029984,
|
| 42 |
+
"predicted_n": 96,
|
| 43 |
+
"predicted_ms": 921.05,
|
| 44 |
+
"predicted_per_token_ms": 9.695263157894736,
|
| 45 |
+
"predicted_per_second": 103.1431518375767,
|
| 46 |
+
"draft_n": 99,
|
| 47 |
+
"draft_n_accepted": 61
|
| 48 |
+
}
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"name": "C(code)",
|
| 52 |
+
"tps": 111.25203034955388,
|
| 53 |
+
"n": 96,
|
| 54 |
+
"wall": 1.087364912033081,
|
| 55 |
+
"draft_n": 91,
|
| 56 |
+
"draft_accepted": 64,
|
| 57 |
+
"acc": 0.7032967032967034,
|
| 58 |
+
"prompt_ms": 131.773,
|
| 59 |
+
"timings": {
|
| 60 |
+
"cache_n": 0,
|
| 61 |
+
"prompt_n": 54,
|
| 62 |
+
"prompt_ms": 131.773,
|
| 63 |
+
"prompt_per_token_ms": 2.4402407407407405,
|
| 64 |
+
"prompt_per_second": 409.7956333998619,
|
| 65 |
+
"predicted_n": 96,
|
| 66 |
+
"predicted_ms": 853.917,
|
| 67 |
+
"predicted_per_token_ms": 8.9886,
|
| 68 |
+
"predicted_per_second": 111.25203034955388,
|
| 69 |
+
"draft_n": 91,
|
| 70 |
+
"draft_n_accepted": 64
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
]
|
| 74 |
+
}
|
run_mtp_ab2.sh
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# 用法: run_mtp_ab.sh <tag> <额外 llama-server 参数...>
|
| 3 |
+
set -u
|
| 4 |
+
TAG=$1; shift
|
| 5 |
+
MODEL=/home/zyl/models/Ternary-Bonsai-2-27B-PQ2_0-MTP-Q8_0.gguf
|
| 6 |
+
UNIT=bonsai-mtp-$TAG
|
| 7 |
+
LOG=/home/zyl/bonsai2/logs/mtp-$TAG.log
|
| 8 |
+
systemctl --user stop llama-bonsai.service 2>/dev/null
|
| 9 |
+
systemctl --user stop "$UNIT.service" 2>/dev/null
|
| 10 |
+
sleep 2
|
| 11 |
+
systemd-run --user --collect --unit="$UNIT" /bin/bash -c \
|
| 12 |
+
"cd /home/zyl/bonsai2/mtp-runtime/source/llama/build/bin && LD_LIBRARY_PATH=/home/zyl/bonsai2/mtp-runtime/source/llama/build/bin HOME=/home/zyl \
|
| 13 |
+
./llama-server -m $MODEL -ngl 99 -fa on -c 131072 -ctk q4_0 -ctv q4_0 -np 1 \
|
| 14 |
+
-t 16 --temp 0 --host 127.0.0.1 --port 8080 -a bonsai-mtp $* > $LOG 2>&1" 2>&1 | tail -1
|
| 15 |
+
for i in $(seq 1 60); do
|
| 16 |
+
sleep 3
|
| 17 |
+
curl -s --max-time 3 -o /dev/null http://127.0.0.1:8080/health 2>/dev/null && break
|
| 18 |
+
systemctl --user is-active -q "$UNIT" || { echo "!! 单元退出,日志尾部:"; tail -5 "$LOG"; exit 1; }
|
| 19 |
+
done
|
| 20 |
+
echo "== 服务就绪 (${TAG}) =="
|
| 21 |
+
grep -aiE "nextn|mtp|spec|draft" "$LOG" | head -5
|
| 22 |
+
python3 /home/zyl/bonsai2/mtp_bench.py 8080 "$TAG" 96
|
| 23 |
+
echo "== 服务端日志里的接受率行 =="
|
| 24 |
+
grep -a "draft acceptance" "$LOG" | tail -3
|
| 25 |
+
systemctl --user stop "$UNIT.service"
|