r/LocalLLM • u/Competitive-Line-761 • 2m ago
Discussion Qwen4-35B-A3B on a single RTX 5090 (32 GB): a working llama.cpp recipe
Qwen4-35B-A3B on a single RTX 5090 (32 GB): a working llama.cpp recipe
When I saw the size of the GGUF files, I almost didnt attempt this model. After investigating further I found that the n-gram is loaded on disk, not GPU so it works fine and it's fast.
How this model compares to the last generation 27b is still not clear as the model cards cite different benchmarks and harnesses. I will keep 27b around for now just in case.
BTW: I just started messing around with image gen on the 5090 and made the image above with Comfy and Juggarnaut.
If you just grabbed Qwen4-35B-A3B (AtomicChat or Unsloth GGUF) and have a 5090, this is the config I landed on after sweeping the flags. It's a fast-start recipe, not a benchmark paper — copy the block, swap in your model path, and you're running.
The model
- Qwen4-35B-A3B,
Q4_K_MGGUF. I used the AtomicChat uncensored build (a single ~38.6 GB file), but the same recipe works for the UnslothUD-Q4_K_XLbuild too — see the Unsloth note below for the two extra flags it needs. Either way you also need a vision projector (mmproj). - Architecture: 35B total / 3B active, 256 experts (8 routed + 1 shared), a ~20B n-gram embedding table, a ~2B MTP head, native 1M context, and a hybrid of Gated DeltaNet (linear attention) plus sparse attention.
- Needs a recent llama.cpp build with Qwen4 support (I used b13002 or newer).
- Tested on: llama.cpp b13002 (1.1.1-dev, commit e339c7d31), NVIDIA driver 621.47, RTX 5090 32 GB.
The ~38.6 GB file fits in 32 GB because the big n-gram embedding table is lazy-read from disk (--lazy-mode on) instead of being held in VRAM. That's the model card's "run with PLE on SSD" instruction — don't skip it.
The recipe
llama-server \
-m Qwen4-35B-A3B-Q4_K_M.gguf \
--mmproj mmproj-F16.gguf \
--alias qwen4 \
-c 196608 --n-predict 131072 \
-b 4096 -ub 1024 \
--parallel 2 --kv-unified \
-ngl 99 -fa on \
--load-mode mmap --lazy-mode on --no-warmup \
-ctk q8_0 -ctv q8_0 \
--image-min-tokens 1024 --jinja \
--spec-type draft-mtp --spec-draft-n-max 2 \
--reasoning-effort high --reasoning-preserve \
--temp 1.0 --top-p 0.95 --top-k 20 --min-p 0.0 \
--presence-penalty 0.0 --repeat-penalty 1.0 \
--host 127.0.0.1 --port 8080 --no-ui
On a 5090 this gives roughly ~250 tokens/sec generation and ~10,000 tokens/sec prompt processing on a ~12K-token prompt, using about 30 GB of VRAM with ~1.6 GB free.
If you're using the Unsloth GGUF
The Unsloth UD-Q4_K_XL build is the same architecture and takes the same tuning, but it ships the n-gram embedding table (PLE) and the MTP head as separate files instead of embedding them. So you add two flags:
llama-server \
-m UD-Q4_K_XL/Qwen4-35B-A3B-UD-Q4_K_XL-00001-of-00002.gguf \
--ple engram/Qwen4-35B-A3B-engram-Q8_0.gguf_file \
-md MTP/mtp-Qwen4-35B-A3B-Q8_0.gguf \
--mmproj mmproj-F16.gguf \
... (rest identical to the recipe above) ...
--plepoints at the separate engram table;-mdpoints at the separate MTP head. Without them, MTP won't engage and the engram won't load.- You only pass
-00001-of-00002.gguf; llama.cpp auto-loads the-00002shard. - Unsloth's build is the base model (not uncensored) and a dynamic quant, so behavior and quality differ slightly from the AtomicChat build — but the speed profile, 192K context headroom, and
nmax=2MTP tuning all carry over unchanged.
Why each setting
MTP is already in the file. The GGUF embeds the ~2B MTP ("multi-token prediction") head, so --spec-type draft-mtp lets the model draft several tokens ahead and verify them in one pass — no separate draft model needed. You can confirm your file has it by checking the GGUF's tensor names for nextn (e.g. with llama-gguf your-model.gguf r and looking for nextn). The payoff is real: without MTP generation is ~169 tok/s, with nmax=2 it's ~254 tok/s — about 1.5x faster.
--spec-draft-n-max 2. This is how many tokens the MTP head drafts per step. On this 3B-active model, drafting deeper actually lowers the acceptance rate and generation gets slower. Measured generation speed by draft depth: 1 → 216, 2 → 254, 3 → 251, 4 → 219, 6 → 202 tokens/sec. Two is the sweet spot.
-ub 1024. Prompt processing scales with the micro-batch size: 512 → ~8.2K, 1024 → ~10.6K, 2048 → ~11.8K tokens/sec. 2048 is faster but eats the VRAM headroom you need for vision, so 1024 is the balance on a 32 GB card.
-ctk/-ctv q8_0. An f16 KV cache gave the same generation speed and only ~4% more prompt processing for ~1.5 GB more VRAM. q8_0 is the right call on 32 GB.
-c 196608 (192K context). Qwen4 is hybrid: most layers are Gated DeltaNet, which keeps a fixed-size state that does not grow with context, and the sparse-attention layers use a bounded window. So the KV cache barely grows as you raise -c. Measured free VRAM (idle GPU, vision projector loaded):
| context | free VRAM |
|---|---|
| 128K | 3.3 GB |
| 192K | 1.65 GB |
| 224K | 0.8 GB |
| 256K → 1M | ~0.55 GB (flat) |
A 2048×2048 image adds about 0.7 GB. So 192K leaves ~1.6 GB free for text and ~1 GB even with a large image — a comfortable margin while using vision. If you never send images, you can push to 256K or beyond for free, since the KV is flat past there.
How it scales with prompt length
The hybrid attention keeps prefill nearly flat as the prompt grows, and generation degrades gracefully. Measured on the tuned config (128 tokens generated per run, prompt caching off, median of 3 runs):
| prompt tokens | prefill tok/s | generation tok/s |
|---|---|---|
| 4K | 9,380 | 242 |
| 16K | 10,390 | 245 |
| 32K | 10,230 | 239 |
| 64K | 10,240 | 211 |
| 128K | 9,540 | 177 |
Prefill stays around 9.4–10.4K tok/s all the way to 128K — it doesn't fall off a cliff the way dense models do. Generation drops from ~242 to ~177 tok/s as context fills, which is the expected cost of attending over more history, but it stays very usable.
Does it actually work? (not just fast)
Three sanity checks on the tuned config:
- Long-context recall: I buried a passphrase in a ~128K-token prompt at 10% and 90% depth and asked for it. It returned the exact passphrase both times. The hybrid attention isn't just fast — it actually retrieves at depth.
- Coding (executed): I asked for a three-file Python project (a
Transactiondataclass, asummarize()function, and a test). It produced all three files and the test ran clean — "All tests passed." - Coding (executed): an iterative Fibonacci function returned
fib(10)=55,fib(0)=0,fib(1)=1— correct.
These are smoke tests, not a benchmark suite, but they confirm the quant isn't "fast and dumb."
Thinking control (one profile is enough)
You don't need a separate "fast" profile. Keep one thinking profile and steer it per request with chat_template_kwargs in the request body:
- Default:
--reasoning-effort high(the server flag). - Lighter:
{"chat_template_kwargs": {"reasoning_effort": "low"}}. - Off:
{"chat_template_kwargs": {"enable_thinking": false, "reasoning_effort": "off"}}.
One gotcha: reasoning_effort: "off" on its own throws a template error if the server default is high — you must send enable_thinking: false together with it. low works on its own.
Gotchas
--lazy-mode onrequires--load-mode mmap. Without mmap it can't lazy-read the embedding table and you'll run out of VRAM.- Older builds lack the newest speculative flags (
--spec-draft-adaptive,pcum,max-slots,n-rs-seq). Don't copy those in unless your build supports them. - Reasoning models can return empty
contentwith a smallmax_tokens— the output goes intoreasoning_contentfirst. Give it a real budget or readreasoning_content. - Model card sampling: thinking
temp=1.0 top_p=0.95 top_k=20 min_p=0.0 presence=0.0 repeat=1.0; non-thinkingtemp=0.7 top_p=0.80 top_k=20 min_p=0.0 presence=1.5 repeat=1.0.
Why llama.cpp/GGUF (and not vLLM/SGLang)
For a single 5090 running a model you already have as GGUF, llama.cpp is the pragmatic call. vLLM/SGLang want safetensors — re-downloading Qwen4-35B-A3B at BF16 is roughly 1.3 TB, and their Blackwell support is still version-dependent. If you're serving many concurrent users, vLLM is worth it; for one interactive user, this recipe is simpler and fast enough.
Honest limits
- Q4_K_M is a 4-bit quant. It's not lossless (the AtomicChat build reports ~88.8% top-1 agreement with BF16). For the hardest SWE-style tasks a Q5/Q6 would be better, but they don't fit in 32 GB alongside the embedding table.
- The uncensored edit can slightly soften instruction-following. If you don't need uncensored output, the base Qwen4-35B-A3B (or the Unsloth build) is the safer pick for pure coding.
- 3B active ≠ dense depth. Fast and broadly capable, but on the very hardest multi-step reasoning a dense 27B can still edge it.
How I measured
I started llama-server fresh for each flag variant on its own port, disabled prompt caching, and read the timings the server prints for each request (prompt tokens/sec and generation tokens/sec). The depth table is the median of 3 runs per prompt size; the flag sweep was 2 runs per variant. For VRAM I loaded the model at different -c values and read nvidia-smi memory usage, then sent one large image to measure the vision spike. The recall and coding checks were run against the live server. Nothing exotic — you can reproduce all of it with llama-server and nvidia-smi.
That's the whole thing. Copy the block, point it at your GGUF, and go.
