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
TUNED STOCK FLAGS CEILING FROM MEASURED BANDWIDTH
Run it
./serve.sh
| Model | Qwen/Qwen4-35B-A3B on Hugging Face · Apache-2.0 |
|---|---|
| Weights | GGUF UD-Q4_K_M (imatrix), 35.18 GB from unsloth/Qwen4-35B-A3B-GGUFQwen4-35B-A3B-UD-Q4_K_M-00001-of-00002.gguf at 3ef64303abd0Two 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. |
| Engine | llama.cpp master at 59b716523 · CUDA sm_86 build |
| Placement | Every 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. |
| Hardware | NVIDIA 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. |
| API | OpenAI-compatible /v1 (llama-server) on port 8112 |
| Key flags | QW_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) |
- 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.
Measured results
| Metric | Conditions | Measured | Stock | Ceiling | Source line |
|---|---|---|---|---|---|
| Decode | default (MTP n 2, q8_0 KV, 3800 MiB MoE cache), empty context, thinking off, coding answers, median of three runs | 61.4 tok/s | 37.2 | 120 | RESULTS.md:32 |
| default at 32k depth | 54.9 tok/s | 35.7 | RESULTS.md:33 | ||
| default at 120k depth | 42.5 tok/s | RESULTS.md:34 | |||
| nospec profile, empty context | 49.9 tok/s | RESULTS.md:32 | |||
| Prefill | 8k prompt, default | 458.8 tok/s | 376.3 | RESULTS.md:35 | |
| 8k prompt, nospec profile | 617 tok/s | 376.3 | RESULTS.md:35 | ||
| 32k prompt, default | 430.2 tok/s | 375.8 | RESULTS.md:36 | ||
| 124.5k prompt, default | 431.7 tok/s | RESULTS.md:37 | |||
| Time to first token | 124.5k prompt, default | 288 s | RESULTS.md:37 | ||
| Needles | 3/3 exact at 64.4k and 124.5k (49% / 95% of the window) | 3/3 found | RESULTS.md:38 | ||
| Quality | codeeval, thinking on (effort low) | 8/8 tasks | RESULTS.md:74 | ||
| codeeval, thinking off | 7/8 tasks | RESULTS.md:75 | |||
| VRAM peak | card total incl. desktop, default | 11,774 MiB | RESULTS.md:39 | ||
| RAM peak | RSS, default | 29,374 MiB | RESULTS.md:40 | ||
| Startup | ready, warm page cache, default | 2-3 s | RESULTS.md:41 |
Reproductions
None yet. If you ran this on your own 3060, report your numbers and they appear here with your hardware.
Thanks
- Qwen The 15 mtp.* tensors grafted back into the 3D coder came from Qwen3.5-4B; Kintsugi-27B is built on Qwen3.8-27B.
- Unsloth The Mainline_Support files are the max-speed options of the Inkling recipe (41.4 tok/s whole-on-GPU); UD-Q3_K_XL was the smaller-expert test on Flint.
- llama.cpp (ggml-org and contributors) The engine for Flint, the 3D coder and Inkling-2-Mini, and the base of the Kintsugi fork.
- ggml-org Flint-Q4_K_M.gguf and Inkling-2-Mini-IQ4_NL.gguf are the files the two recipes serve; the Q8_0 files are the KLD references.
- Hugging Face Every model, quant and drafter in these recipes is fetched from the Hub at a pinned revision and checked against the API's sha256; the base model's MTP tensors were fetched with HTTP range requests.
- 0xSero / Sybil Solutions The tuning method behind the Flint and Inkling recipes; its q8_0 KV gotcha is one we confirmed on Flint.
- Rui Carmo The lead for the QW_OMP_PASSIVE switch: measured here as about half the server CPU time for 4–9% less decode.
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 onreads 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 64is 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,highandxhighwork. - The server holds the shared GPU lock for its whole life and needs
GPU_RUN_MEM=44G(set byserve.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 intools/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 inruns/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=1is 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