Skip to content

spec : MTP draft vocabulary from a file of token ids (--spec-draft-mtp-vocab-file) - #295

Draft
huppiflupp wants to merge 1 commit into
halo-box:masterfrom
huppiflupp:pr/mtp-vocab-file
Draft

huppiflupp wants to merge 1 commit into
halo-box:masterfrom
huppiflupp:pr/mtp-vocab-file

Conversation

@huppiflupp

Copy link
Copy Markdown

Overview

--spec-draft-mtp-vocab N lets the MTP draft head score only the token ids < N (plus control tokens). That works because BPE ids roughly follow merge order, but the ids < N still contain many tokens a given model rarely emits, and they miss frequent high ids (for example German words on Qwen3.6).

This PR adds --spec-draft-mtp-vocab-file FNAME: with --spec-draft-mtp-vocab N, the draft head scores the first N distinct token ids listed in the file (one per line, e.g. ranked by how often the model emits them) plus control and user-defined tokens, instead of the ids < N. It reuses the existing row-subset machinery (llama_model::mtp_draft_vocab_get, the scatter into a -inf row). Verification is unchanged. Builds on #101 and #289.

  • New llama_context_params::mtp_draft_vocab_file (NULL = off, default), new option and env LLAMA_ARG_SPEC_DRAFT_MTP_VOCAB_FILE.
  • The file is read before the subset lock; the cache key is (N, buffer type, the sorted ids), so contexts with the same ids share one subset, a rewritten file is not served stale, and two paths to one file do not build two copies.
  • Strict parsing: blank lines and # lines are skipped, anything else that is not a whole token id rejects the file (falls back to the full vocabulary with an error log). Fewer than N ids logs a warning, no ids is an error.
  • Without the file nothing changes (byte-identical outputs, see below).
  • tests/test-mtp-draft-vocab gets a file case: N from a fixed shuffle of the vocabulary next to an ids < N context with the same N and a full-vocabulary reference.
  • /props reports mtp_vocab_file; the fit path passes the file too; a warning if the file is given without N.

The ids file used below has 49152 lines, ranked by token frequency in Qwen3.6-35B-A3B's own generated output (the list and its builder are not part of this PR).

Measurements

Device:     Ryzen AI Max+ 395 / GMKtec EVO-X2 mini-PC
Memory:     128 GB LPDDR5X-8000
Power:      STAPM 120 W, PPT fast 140 W / slow 120 W (set with ryzenadj), power_dpm_force_performance_level auto
BIOS:       UMA split 512 MB
Kernel:     7.2.6-201.nobara.fc44.x86_64, ttm.pages_limit=31457280 ttm.page_pool_size=31457280
Backend:    Vulkan RADV, Mesa 26.2.3
Build:      -DGGML_VULKAN=ON -DGGML_NATIVE=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DLLAMA_CURL=OFF
Baseline:   762a42c73 (master), built from source in this session, same flags
Change:     defe47718
Model:      Qwen3.6-35B-A3B, Unsloth UD-IQ4_XS experts, dense trunk requantized to IQ4_XS (imatrix), with its MTP head

llama-server, -c 32768 -fa 1 -ub 2048 -np 1 --spec-type draft-mtp --spec-draft-mtp-vocab 49152, temperature 0, thinking off, 512 generated tokens, 2 runs each (both runs listed). Prompts: a Python module with tests (code), a 600-word German story (prose), a step-by-step explanation of the sieve of Eratosthenes (reasoning). tok/s from the server timings, accepted/drafted from draft_n_accepted/draft_n.

draft n-max run code tok/s (acc/draft) prose tok/s (acc/draft) reasoning tok/s (acc/draft)
2 baseline, ids < 49152 135.0, 137.5 (330/361) 88.3, 88.4 (218/583) 109.7, 109.4 (278/465)
2 change, ids file 135.7, 136.8 (328/364) 95.6, 95.3 (241/538) 119.5, 118.5 (298/424)
2 gain +0.0 % +8.0 % +8.6 %
3 baseline, ids < 49152 144.7, 144.8 (364/440) 79.2, 79.2 (229/842) 105.3, 105.4 (302/622)
3 change, ids file 148.5, 148.6 (368/428) 87.6, 88.2 (258/755) 122.6, 123.0 (333/532)
3 gain +2.6 % +11.0 % +16.6 %

With context depth (same server settings, -c 65536, code prompt behind a block of tests/corpus/correctness-prose.txt, 2 runs, gen tok/s). Depths are 9000 and 24136 tokens, not the 12000/32000 I aimed at (my characters-per-token guess was low):

depth 0 depth 9000 depth 24136
n-max 2 baseline 137.2, 137.5 124.0, 124.5 112.2, 112.3
n-max 2 change, no file 135.7, 137.4 124.2, 124.9 112.5, 112.3
n-max 2 change, ids file 136.0, 136.1 124.8, 123.8 111.9, 112.0
n-max 3 baseline 144.1, 143.7 135.0, 135.7 119.8, 119.8
n-max 3 change, ids file 147.9, 148.5 136.2, 135.4 120.2, 119.9

On code the file changes little; the gain is on prose and reasoning, where the ids < N miss frequent tokens.

Correctness:

  • test-mtp-draft-vocab -m <model above> -ngl 99: PASS, all 48 checks OK, including the new file 32768 case (file context, ids < N context with the same N, and a full-vocabulary reference alive at the same time; the file context is -inf exactly outside its ids + control tokens and matches the reference inside).
  • Without the file the change is byte-identical to the baseline: all 6 replies of the depth run (n-max 2, depths 0/9000/24136, 2 runs) are the same text.
  • With the file the draft changes, verification does not. The texts differ from the baseline in some runs (n-max 2: 2 of 6 equal; n-max 3: 0 of 6), because a different number of accepted drafts changes the verify batch shapes and with them the rounding. Same behavior as changing --spec-draft-mtp-vocab N itself.

Additional information

I use this on the two Qwen3.6-35B-A3B services on my box together with other patches; the numbers above are this change alone on top of master.

Requirements

  • I have read and agree with the contributing guidelines
  • This change is Strix Halo specific, or justified by measurements on Strix Halo. It extends this fork's own --spec-draft-mtp-vocab, measured on gfx1151.
  • AI usage disclosure: AGENT-AUTHORED. Claude (Opus 5.5, Claude Code) wrote the code, the test, the commit message and this description, built both trees and ran all measurements on my machine; a separate local code-review pass found 10 issues that were fixed before this PR. I reviewed the results and own the PR.
  • What was NOT verified: llama-benchy was not run (only the llama-server timings above); depths 12000/32000/64000 were not run as such (9000 and 24136 instead); the four-corpus logit comparison was not run (the change only touches the draft context, verification is unchanged and the no-file path is byte-identical); no backend other than Vulkan RADV; only Qwen3.6-35B-A3B, not qwen35 dense or qwen4exp; the ids file builder is not part of this PR.

🤖 Generated with Claude Code

…p-vocab-file)

With --spec-draft-mtp-vocab N the draft head scores the token ids < N. A file of ids ranked by how often the model emits them keeps the same N rows but drops rarely used low ids and keeps frequent high ids. The new option takes the first N ids of such a file, control and user-defined tokens stay as before. Verification is unchanged.

Assisted-by: Claude Opus 5.5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant