Repository navigation
spec : MTP draft vocabulary from a file of token ids (--spec-draft-mtp-vocab-file) - #295
Draft
huppiflupp wants to merge 1 commit into
Draft
huppiflupp wants to merge 1 commit into
huppiflupp wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
--spec-draft-mtp-vocab Nlets 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.llama_context_params::mtp_draft_vocab_file(NULL = off, default), new option and envLLAMA_ARG_SPEC_DRAFT_MTP_VOCAB_FILE.#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.tests/test-mtp-draft-vocabgets 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./propsreportsmtp_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
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 servertimings, accepted/drafted fromdraft_n_accepted/draft_n.With context depth (same server settings,
-c 65536, code prompt behind a block oftests/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):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 newfile 32768case (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).--spec-draft-mtp-vocab Nitself.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
--spec-draft-mtp-vocab, measured on gfx1151.llama-benchywas 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