A 35B Model at 128k Context on Two RTX 3060s: One Flag Decides 6 or 40 Tokens a Second

Qwen4-35B-A3B running on two RTX 3060 cards at 128k context

Qwen4-35B-A3B running on two RTX 3060 cards at 128k context

I spent an hour telling myself this model would not run here. The arithmetic was clean: a 35B mixture-of-experts at 4 bits is about 20 GB of weights, my cards hold 12 GB each, and every guide says a model that does not fit one card is a model you should not bother with. Then I opened LM Studio, loaded the thing, and read 42 tokens a second off its own log.

That is the interesting part of this post — not that a 35B model runs on consumer hardware, which has been true for a while, but which rule I had been applying correctly for months and which one was simply folklore. The model now serves every session of my agent at 128k context, q4_0 KV cache, between 41 and 47 tokens a second, and I never touched a
single tuning knob to get there.

The machine

CPU Ryzen 7 5700X, 8 cores / 16 threads
RAM 31 GiB DDR4
GPUs 2× RTX 3060 12 GB — one on PCIe 4.0 ×4, one on ×16, no P2P
Storage model on a SATA SSD, system on an SSD, an older HDD for archives
OS Linux Mint 22.3, kernel 7.0, NVIDIA 595.112.07

The model is Qwen4-35B-A3B, 35 billion parameters with 3 billion active per token, in an uncensored community quant: Qwen4-35B-A3B-Uncensored-AD-IQ4_XS.gguf, 33 GB on disk plus a 0.8 GB vision projector.

What the file actually is

The architecture token says qwen4exp, and it is not a plain transformer stack. Read out of the GGUF by the engine’s own loader:

blocks            41   (40 + 1 MTP head)
ctx_train         1,048,576
embedding         2048
heads             16
KV heads          2
key / value len   256 / 256
experts           256, top-8, expert FFN 512
ssm               conv 4, state 128, groups 16, inner 4096
recurrent_layers  most blocks true → Gated DeltaNet

Two lines matter. The first is 256 experts, top-8: each token routes through eight of them, so the model reads roughly a twelfth of itself per step. The second is recurrent_layers: most of the 40 blocks are Gated DeltaNet layers, which keep a constant-size state instead of growing a KV cache with every token. Only about ten blocks are full attention.

That second line is why the context request I actually wanted — 128k — turned out to be the cheap part of the problem.

Why 128k costs less than the default

With two KV heads of 256 dimensions each, a token costs 1024 values per attention layer per side. At q4_0, about 0.55 bytes per value, across ten attention layers:

2 KV heads × (256 + 256) = 1024 values per token, per layer
q4_0                         ≈ 0.55 B per value
10 attention layers of 40
131,072 tokens              ≈ 0.75 GB of KV cache

Three quarters of a gigabyte. LM Studio’s own default on this box was 16k context, four parallel slots, f16 cache — about 1.3 GB — so my “expensive” 128k setting is actually the cheaper one, and it is eight times the window. The recurring intuition that context is the thing you trade away is wrong on this architecture: the weights are the budget, and everything else is rounding.

Where the 35.4 GB model lives: 10.9 GB on each card, 18.7 GB of locked RAM

The flag that decides everything

Two walls, both found the hard way, both about placement rather than speed.

The first is -ngl. Every guide ends with -ngl 99, offload everything. Next to --fit, which lets the loader place the stack itself, it is not just redundant, it aborts:

common_fit_params: failed to fit params to free device memory:
n_gpu_layers already set by user to 999, abort

And when forced through anyway, the recurrent core cannot be spread the way an ordinary transformer can, so the loader asks for the whole thing at once on the first card:

ggml_backend_cuda_buffer_type_alloc_buffer: allocating 10546.59 MiB
on device 0: cudaMalloc failed: out of memory

Drop the flag. --fit on splits the stack across both cards — 10.9 GB and 11.0 GB on mine — and the model loads in 38 seconds.

The second wall is the loading mode, and it is the whole story of this post’s speed. This model carries a 20.5-billion-parameter n-gram table. With --load-mode mmap the table is memory-mapped and read on demand, which sounds efficient and behaves like this:

Decode speed with mmap versus mmap+mlock: 6.4, 28.3, 37.9 and 39.95 tokens per second

Six tokens a second on the first request, because every token waits for table pages to arrive from the SSD. Warm it reaches 28, which is still half of what the hardware can do. Change one flag to --load-mode mmap+mlock and the table is pinned in RAM — 18.7 GB of it — and the same model, prompt and context decode at 37.9 at first, then 41 to 47 tokens a second once repeated runs warm it.

There is no tuning in that jump. It is the difference between a model that reads its own parameters from disk at generation time and one that does not.

The numbers

Decode, warm 37.2 t/s cold table → 41.1–47.1 t/s once it settles
Prefill, ~31.5k-token prompt (uncached) 497.7 and 523.6 t/s — 65–98 s to first token
Decode on those long-context requests 33.77–33.81 t/s
Context / KV 131,072 tokens, q4_0, one slot
VRAM ~10.9 GB + ~11.0 GB of 12 GB each
RAM 15.8–18.7 GB resident (locked table)
Cold load ~38 s
First agent turn through Hermes 1 min 50 s — 29k-token harness prefix at ~500 t/s, then full decode speed

For comparison, LM Studio’s GUI on the same file measured 41.05–42.39 t/s decode and 283–313 t/s prompt evaluation at 16k, four slots, f16 KV. Moving to 128k, q4_0 and a single slot costs nothing measurable in decode — my range overlaps that one. The window was never the expensive part.

What it costs

Being honest about the bill: 21.9 of the 24 GB on those two cards are now spoken for, and 18.7 GB of RAM with them. A model this size resident is a model that owns the machine. My local vision model — a 2B model that used to load on demand — can no longer find the room to start while this one is running. Speech-to-text and text-to-speech are fine, because they are small and run alongside; a second 20 GB model is not.

That is the actual decision a daily driver forces, and it is worth stating plainly rather than discovering later: one big model resident and everything else small, or two medium models and neither of them this good.

How it is wired

It is a plain systemd --user unit running the llama.cpp 2.86.0 build that ships inside LM Studio — the first build I found that knows qwen4exp — pointed at the GGUF in LM Studio’s model directory, with MemoryMax=26G so that a bad fit dies instead of taking the desktop down with it. It is deliberately not enabled at boot, because a unit that wants 21.9 GB of VRAM has no business racing the rest of the machine at login.

Hermes talks to it as an ordinary OpenAI-compatible provider on 127.0.0.1:18450. One practical note for anyone wiring a reasoning model into an agent loop: give it a few hundred tokens of budget. My first test asked for a two-word answer with max_tokens set to 80 and got an empty content field, because the answer was still being written into reasoning_content.

What this does not prove

  • Three decode measurements and one long-context request. That is a receipt, not a benchmark suite.
  • The 42 t/s LM Studio figure comes from that app’s own log with different batch and slot settings; treat the five percent gap as approximate.
  • No agentic evaluation. “Works” here means decode speed, prefill speed, and a correct answer after a 31k-token prompt.
  • One of the two cards sits on a PCIe 4.0 ×4 link. At 3 billion active parameters that is not the bottleneck; on a dense model it would be.

The launch script, the unit file and the measurement script are in the repository, along with the raw timings. If you have two 12 GB cards and 32 GB of RAM, the two flags above are the difference between a model you try once and a model you use every day.

share:


Discover more from Khaled Mimoune

Subscribe to get the latest posts sent to your email.

Comments

Leave a Reply