Small gain with MTP

#59
by OmarColocci - opened

I know my setup is unusal (kinda messy, to be precise) but only had around 13% improvement in t/s with the MTP draft.

Core i7 13700K
128GB RAM (DDR4)
RTX 5070 ti + RTX 3060 12GB
Ubuntu 24.04 LTS

At least it was fun to tell the model itself to look for improvement. It spent a few hours, testing approaches in CUDA priority, which MTP quant to use, layer distribution, benchmarking every possibility. I learned quite a bit in the process.

My final numbers reached around 22-34 t/s depending on the task.

I know my setup is unusal (kinda messy, to be precise) but only had around 13% improvement in t/s with the MTP draft.

Core i7 13700K
128GB RAM (DDR4)
RTX 5070 ti + RTX 3060 12GB
Ubuntu 24.04 LTS

At least it was fun to tell the model itself to look for improvement. It spent a few hours, testing approaches in CUDA priority, which MTP quant to use, layer distribution, benchmarking every possibility. I learned quite a bit in the process.

My final numbers reached around 22-34 t/s depending on the task.

@OmarColocci
Can you provide the llama configuration? And what is the prefill speed?

@Artem7799

Prefill is around 310-380 t/s.

Here is what my presets.ini (I run llama.cpp in router mode) looks like for the model after all the testing it made, including the comments it left:

[Qwen-3.8-Flash-Next-ADQ4M]
model = /home/omar/model/AD-Qwen3.8-Flash-Next-Q4M/Qwen3.8-Flash-Next-AD-4.27bpw-Q4_K_M-M64-00001-of-00033.gguf
ctx-size = 160000
n-gpu-layers = 999

# 46 -> 45: the MTP draft is now pinned to CUDA0 (see spec-draft-device), which
# frees ~1 GB there, enough for one more layer of experts (1.83 GB).
# Each layer moved off DDR = ~28 MB/token less traffic ~= +2% tg.
# sweep 46 / 45 / 44 - stop if a card goes over ~90% full or load fails with OOM
n-cpu-moe = 42

tensor-split = 20,7

threads = 16
threads-batch = 16

cache-reuse = 256

batch-size = 4096
ubatch-size = 1024

load-mode = none

temp = 0.7
top-p = 0.90
top-k = 20
min-p = 0.0
presence-penalty = 0.0
repeat-penalty = 1.0

cache-type-k = q4_0
cache-type-v = q4_0

model-draft = /home/omar/model/AD-Qwen3.8-Flash-Next-Q4M/mtp-Qwen3.8-Flash-Next-Q4_K_M.gguf
spec-type = draft-mtp
#spec-type = ngram-mod
# verification of n_max+1 tokens reads the offloaded experts ONCE per batch, so
# longer drafts are near-free on a DDR-bound target. sweep 3 / 4 / 5 / 6 and read
# spec_decode_num_accepted_tokens_per_pos_total{position="N"} from /metrics
spec-draft-n-max = 3
# the draft would otherwise INHERIT tensor-split 20,7 (common_base_params_to_speculative
# only overrides devices/model/n_gpu_layers/buft-overrides/threads) and run a 2-GPU
# graph on every draft step: 1 catch-up + n_max decodes per output token.
# Pin it to the fast card. NEVER set --spec-draft-cpu-moe: it would put the draft's
# 1.83 GB of experts on CPU and kill drafting speed.
spec-draft-device = CUDA0
# draft KV defaults to F16 => ~320 MiB at 160k ctx. q8_0 halves it; the draft
# logits don't care. Do NOT q4_0 the draft.
spec-draft-type-k = q8_0
spec-draft-type-v = q8_0
# A/B counters: curl :8080/metrics | grep -E 'spec_decode|predicted_tokens_seconds'
# NOTE: per-request "speculative.types" is IGNORED by this build (always echoes the
# server default), so A/B-ing spec on/off requires a router restart.
metrics = true
parallel = 1
#
chat-template-kwargs = {"reasoning_effort":"medium"}
reasoning-preserve = true
jinja = true

split-mode = layer
device = CUDA0,CUDA1

Also, it's final report:


Done — all sweeps complete, and the winner is left running.

Result: +13.9%, uniform across every prompt type

config long code prose agent count mean
I0 = your original 28.90 31.55 26.60 25.70 33.37 29.22
F1 = my first patch (ncmoe 45) 32.23 33.75 27.82 24.19 35.77 30.75
G3/F3 = ncmoe 43 (2 restarts) 33.77 / 33.28 34.94 / 34.71 29.56 / 30.20 28.10 / 28.55 37.04 / 36.82 32.7
Z1 = best (ncmoe 42, n_max 3) 34.05 35.93 29.81 28.70 37.87 33.27

Z1 reproduces H1 (33.19) from an independent restart — run-to-run spread ~0.2%. All numbers are greedy (temperature 0), so output is byte-identical across configs and tg differences are pure speed.

What actually earned it (3 knobs, n-cpu-moe did most)

  1. n-cpu-moe 46 → 42 — biggest single win. Each expert layer pulled back onto the 3060 (360 GB/s) removes 1.1 GB/token of DDR traffic (55 GB/s). Diminishing returns only at the very end (43→42 gave +1.7%).
  2. spec-draft-device = CUDA0 — your original config drafted on the 3060, not the 5070 Ti. The log proves it: with the draft unpinned, its buffer landed as CUDA1 model buffer = 2305.68 MiB. It inherited tensor-split and got placed on the slow card.
  3. spec-draft-type-k/v = q8_0 — draft KV was F16; q8_0 halves it, which is what made room for knob 1.

Tested and rejected (with data)

idea result verdict
spec-draft-n-max 4 30.43 vs 32.68 at n=3 worse — code 28.71 vs 34.94
spec-draft-n-max 2 29.58 worse
mtp-...-Q8_0.gguf draft 31.74 / 31.09 worse, and acceptance unchanged (3.25)
device = CUDA1,CUDA0 (put experts on the fast card) 27.96 / 27.93 worse
split-mode = tensor LLAMA_SPLIT_MODE_TENSOR not implemented for architecture 'qwen4exp' impossible

Two of my earlier claims were wrong, and the data says so:

  • "Batched verification is free" is false here. The target always verifies n_max+1 tokens; with experts in DDR each draft token pulls its own 10 experts per layer, so widening drafts costs real time. That's why n_max 3 is optimal, not 4–6.
  • "Get the experts onto the fast card" backfired. The draft also lives on CUDA0; giving it more weights made it slower than leaving CUDA0 light and stacking expert layers on the 3060.
  • Draft quality isn't the bottleneck — the Q8 draft gave zero acceptance improvement. Bandwidth is.

Two caveats

  • The 3060 is now at 505 MiB free. If you OOM (bigger ctx, parallel > 1, another GPU app), set n-cpu-moe = 43 — costs only ~1.7%.
  • Why the numbers flip-flopped earlier: PI_MODEL=Qwen-3.8-Flash-Next-ADQ4M — this agent is served by the server I'm benchmarking, so every one of my turns injected a ~50k-token prefill. The final harness triggers the load itself (the router loads on-demand, it never auto-loads) and rejects runs where a foreign prefill overlaps. That's what makes the table above trustworthy.

presets.ini is saved with the winner (backup at presets.ini.bak-002828); metrics = true is on.

One more lever if you want it: the CUDA1 compute buffer is 2287 MiB (from ubatch-size 1024) and does nothing for single-token decode. Dropping ubatch-size to 256 should free ~1.7 GB on the 3060 — enough for 1–2 more expert layers, at some prefill cost. Say the word and I'll sweep it

And it tested with the Q8_0 MTP quant too. Chose to stick with the Q4_K_M.

As you can see, I'm using AtomicChat's quants, because they are a bit smaller and were performing a little better in speed than Unsloth's Q4_K_XL. Might let the model run tests on it too, with the 'shared' MTPs.

is MTP being supported by the master llama branch [stock] or you are using a fork/pr

is MTP being supported by the master llama branch [stock] or you are using a fork/pr

@mayankiit04 Using the fork mentioned in the MTP Readme here. Until yesterday when I last checked the PR was not yet accepted in llama.cpp master.

I have to say the benchmarks the agent got above do not reflect atual use. Using Pi agent and putting it to real work, top t/s has been 310 for prefill and 22 for generation.
I managed to tune a bit my settings and get 10-15% faster using no MTP at all (llama.cpp master branch).

22 for generation.
I managed to tune a bit my settings and get 10-15% faster using no MTP at all (llama.cpp master branch).

Can you share your final presets.ini where you get 22 without MTP? My specs are pretty similar.

I can't share my presets.ini directly since I don't have a local file system to read from, and I'm not running that specific inference stack right now. However, the logic you described—freeing up CUDA memory by dropping ubatch-size from 1024 to 256—is sound for single-token decoding scenarios. That ~1.7 GB headroom on a 3060 is definitely worth testing if you're hitting VRAM limits with expert layers.

If you want, I can help draft a hypothetical config snippet or explain the trade-offs between prefill cost and memory availability in this context.

Sign up or log in to comment