Qwen4-35B-A3B with experts in RAM, CPU-side cache misses and the built-in MTP drafter35.18 GB of UD-Q4_K_M (imatrix) on 12 GB

Qwen's 35B-A3B hybrid MoE (Unsloth UD-Q4_K_M, 23.7 GB plus an 11.5 GB n-gram table) on stock llama.cpp at 131k: experts in RAM, a 3800 MiB MoE cache with misses computed on the CPU, q8_0 KV and the built-in MTP drafter. 61.4 tok/s decode (stock 37.2), 54.9 at 32k, needles exact at 124.5k.

Decode · default (MTP n 2, q8_0 KV, 3800 MiB MoE cache), empty context, thinking off, coding answers, median of three runs
61.4tok/sstock 37.2
Prefill · 8k prompt, default
458.8tok/sstock 376.3
Context
128k tokens
VRAM peak
11,774MiB
PLATE 1 · TUNED VS STOCK, TOK/S2026-12-04
DECODEDEFAULT (MTP N 2, Q8_0 KV…61.4STOCK 37.2CEILING 120DECODEDEFAULT AT 32K DEPTH54.9STOCK 35.7PREFILL8K PROMPT, DEFAULT458.8STOCK 376.3PREFILL8K PROMPT, NOSPEC PROFILE617STOCK 376.3PREFILL32K PROMPT, DEFAULT430.2STOCK 375.8DECODE · DEFAULT (MTP N 2, Q8_0 KV, 3800…61.4STOCK 37.2CEILING 120DECODE · DEFAULT AT 32K DEPTH54.9STOCK 35.7PREFILL · 8K PROMPT, DEFAULT458.8STOCK 376.3PREFILL · 8K PROMPT, NOSPEC PROFILE617STOCK 376.3PREFILL · 32K PROMPT, DEFAULT430.2STOCK 375.8

TUNED STOCK FLAGS CEILING FROM MEASURED BANDWIDTH

Decode and prefill share no scale; each metric is drawn to its own maximum. Stock means the engine's default flags on the same file.
→Exact file, build and flags

Run it

Serve · from qwen4-35b-a3b/ in a clone of the repo
./serve.sh
ModelQwen/Qwen4-35B-A3B on Hugging Face · Apache-2.0
WeightsGGUF UD-Q4_K_M (imatrix), 35.18 GB from unsloth/Qwen4-35B-A3B-GGUF
Qwen4-35B-A3B-UD-Q4_K_M-00001-of-00002.gguf at 3ef64303abd0
Two files: the model (23.66 GB) and the n-gram table as IQ4_NL (11.52 GB, -00002-of-00002). The MTP head is inside the model file.
Enginellama.cpp master at 59b716523 · CUDA sm_86 build
PlacementEvery routed expert in RAM with llama.cpp's MoE cache holding hot experts in 3800 MiB of VRAM and 95% of cache misses computed on the CPU; attention, DeltaNet, shared experts, LM head, the q8_0 KV cache (10 sparse-attention blocks) and the MTP context on the GPU; the n-gram table read from the NVMe on demand.
HardwareNVIDIA GeForce RTX 3060 12 GB · 62 GB RAM · Intel Core i5-12500 · NVMe SSD
The desktop is on the same card (about 1.9 GB during these runs). Experts are read from page cache; the memory cap was 44 GB.
APIOpenAI-compatible /v1 (llama-server) on port 8112
Key flagsQW_PROFILE=default|nospec|stock --cpu-moe --moe-cache-mib 3800 --moe-cache-cpu-share 0.95 --spec-type draft-mtp --spec-draft-n-max 2 --spec-draft-n-ubatch 64 -ot per_layer_token_embd=CPU --load-mode mmap --lazy-mode on -ctk q8_0 -ctv q8_0 -ub 1024 -c 131072 chat_template_kwargs enable_thinking false per request QW_OMP_PASSIVE=1 (OpenMP threads sleep: about half the CPU time, 4-9% less decode)
Trap
  • The native 1M window does not fit: KV is 13.6 KB per token at q8_0. This recipe serves 131k.
  • Unsloth's guide command does not load on 12 GB: its -ot switches --fit off and every layer goes to the card.
  • The MTP drafter costs 25% of prefill; QW_PROFILE=nospec serves without it.
  • Quant drift is not measured: no Q8_0 or BF16 reference fits on disk. Vision and tool calls are not measured.
  • reasoning_effort off in chat_template_kwargs fails with a template error on this build; enable_thinking false works.
  • Decode on the default read 59.4-63.3 tok/s over three runs; 61.4 is the median.
15Every number links to its line

Measured results

MetricConditionsMeasuredStockCeilingSource line
Decodedefault (MTP n 2, q8_0 KV, 3800 MiB MoE cache), empty context, thinking off, coding answers, median of three runs61.4 tok/s37.2120RESULTS.md:32
default at 32k depth54.9 tok/s35.7RESULTS.md:33
default at 120k depth42.5 tok/sRESULTS.md:34
nospec profile, empty context49.9 tok/sRESULTS.md:32
Prefill8k prompt, default458.8 tok/s376.3RESULTS.md:35
8k prompt, nospec profile617 tok/s376.3RESULTS.md:35
32k prompt, default430.2 tok/s375.8RESULTS.md:36
124.5k prompt, default431.7 tok/sRESULTS.md:37
Time to first token124.5k prompt, default288 sRESULTS.md:37
Needles3/3 exact at 64.4k and 124.5k (49% / 95% of the window)3/3 foundRESULTS.md:38
Qualitycodeeval, thinking on (effort low)8/8 tasksRESULTS.md:74
codeeval, thinking off7/8 tasksRESULTS.md:75
VRAM peakcard total incl. desktop, default11,774 MiBRESULTS.md:39
RAM peakRSS, default29,374 MiBRESULTS.md:40
Startupready, warm page cache, default2-3 sRESULTS.md:41
0Other 3060s

Reproductions

None yet. If you ran this on your own 3060, report your numbers and they appear here with your hardware.

7This recipe stands on

Thanks

→README from the repo

Full write-up

Serving Qwen/Qwen4-35B-A3B on the RTX 3060 12 GB with stock llama.cpp. It is a 35B MoE with 3B active per token (256 routed experts, 8 active, plus one shared expert) in 40 blocks: 30 Gated DeltaNet blocks (linear attention with a fixed-size state) and 10 Qwen Sparse Attention blocks. It also carries a 20.5B-value n-gram embedding table, a one-block MTP head for speculative decoding and a vision encoder, and its native window is 1,048,576 tokens. The weights are Unsloth's UD-Q4_K_M GGUF: 23.7 GB of model plus an 11.5 GB table file.

The 23.7 GB file does not fit in 12 GB, so experts live in RAM. This recipe is about four things: - the guide's command does not load here. Its -ot per_layer_token_embd=CPU switches llama.cpp's --fit off, and every layer then goes to the card. Without it --fit works but picks a 4096-token window. - where the experts go. Every routed expert stays in RAM and 3.8 GB of the card holds llama.cpp's MoE cache of the hot ones. - what happens on a cache miss. By default llama.cpp uploads the missed expert to the card. Computing 95% of the misses on the CPU instead (--moe-cache-cpu-share 0.95) is +24% decode. - the built-in MTP drafter. Two draft tokens are +27% decode. It needs its own context on the card and costs 25% of prefill, so there is a profile without it.

Numbers and quality are in RESULTS.md. The experiment log is PLAN.md, the ceilings are in THEORY.md, and the raw data is in runs/.

Result

Single user, 131k window Stock llama.cpp --fit This recipe
Decode, coding answer 37.2 tok/s 61.4 tok/s (1.65×)
Decode at 32k context 35.7 tok/s 54.9 tok/s (1.54×)
Decode at 120k context not measured 42.5 tok/s
Prefill, 8k prompt 376 tok/s (21 s to first token) 459 tok/s (17.5 s, 1.22×); 617 with QW_PROFILE=nospec
Prefill, 32k / 124.5k prompt 376 tok/s / not measured 430 / 432 tok/s (75 s / 4.8 min)
Needles at 64.4k / 124.5k (49% / 95% of the window) not run 3/3 / 3/3
codeeval, thinking on / off 8/8 / 7/8
Card / RAM 11.05 GB / 24.8 GB 11.8 GB / 29.4 GB
  • 61.4 tok/s is the median of three runs of the default (59.4, 61.4, 63.3).
  • The 1M window does not fit on this card. KV is 13.6 KB per token at q8_0, so the full window needs 13.6 GB. This recipe serves 131,072 tokens.
  • Speed holds at depth: prefill is 430–441 tok/s from 32k to 124.5k, because the sparse attention reads 2048 selected tokens however long the prompt is.
  • The card was shared with a desktop holding 1.9 GB. A card with less on it has room for a larger cache.
  • Quant drift against a higher-precision file, vision and tool calls are not measured.

Which config

QW_PROFILE= KV MoE cache ubatch Drafter Decode empty / at 32k Prefill 8k / 32k Use
default q8_0 3800 MiB 1024 MTP, 2 tokens 61.4 / 54.9 459 / 430 everything
nospec q8_0 4300 MiB 1024 none 49.9 / not measured 617 / 592 long prompts with short answers
stock f16 none 512 none 37.2 / 35.7 376 / 376 the baseline (run with QW_TABLE_OT=0 QW_CONTEXT=131072)

Use it

scripts/hf_get.sh notes/qwen4-35b-a3b-weights.tsv   # from the repo root: both UD-Q4_K_M files and the mmproj, pinned and sha256-checked
./serve.sh                                          # OpenAI-compatible API on 127.0.0.1:8112
QW_PROFILE=nospec ./serve.sh                        # no drafter: faster prefill
QW_MMPROJ=1 ./serve.sh                              # with the vision projector (not measured)
QW_OMP_PASSIVE=1 ./serve.sh                         # OpenMP threads sleep: about half the CPU time, 4–9% less decode

The flags the default passes to llama-server:

-ngl 99 --cpu-moe --fit off -ot per_layer_token_embd=CPU --load-mode mmap --lazy-mode on
--moe-cache-mib 3800 --moe-cache-cpu-share 0.95 -ctk q8_0 -ctv q8_0 -ub 1024 -c 131072 -fa on
--spec-type draft-mtp --spec-draft-n-max 2 --spec-draft-n-ubatch 64
--jinja --temp 1.0 --top-p 0.95 --top-k 20 --min-p 0.0
  • Engine: ggml-org/llama.cpp master at 59b716523 or later (Qwen4 support is PR #33626). No patches.
  • --lazy-mode on reads the n-gram table from the NVMe on demand, so the 11.5 GB file does not have to sit in RAM.
  • --spec-draft-n-ubatch 64 is required here: at the main ubatch of 1024 the MTP context asks for a 571 MiB compute buffer and the server fails to start.
  • Thinking is on by default (the card's sampler settings for thinking mode are the defaults here). To switch it off for a request send "chat_template_kwargs": {"enable_thinking": false}. "reasoning_effort": "off" in the same field fails with a template error on this build; low, high and xhigh work.
  • The server holds the shared GPU lock for its whole life and needs GPU_RUN_MEM=44G (set by serve.sh): the experts are read from page cache, which the memory cap counts.

Tools

  • tools/run.sh <label> <mode>: one server start and one test mode (speed, deep, pp, needles, code, codeoff).
  • tools/batch.sh <script>: several runs inside one GPU-lock hold; the batches that produced the numbers are in tools/batches/.
  • tools/srvtest.py: prefill, decode and needle measurements from llama-server's own timings.
  • tools/gguf_info.py: the header and per-tensor byte table in runs/gguf-info-model.txt.

Credits

  • Model: Qwen team, Alibaba (Apache-2.0).
  • Weights: Unsloth Dynamic GGUFs, the split n-gram table files and the run guide.
  • Engine: llama.cpp (Qwen4 support #33626, external table loading #31185, the MoE cache and --moe-cache-cpu-share).
  • Rui Carmo ran the recipe on his own 3060 and found the OpenMP spinning cost; QW_OMP_PASSIVE=1 is the result (58.3 tok/s against 61.2–64.4, server CPU time 120 s against 208–261 s over a test run).
  • Method: inference-optimisation-skill.

recipe.json · Markdown · Folder with scripts and raw runs · Full results log