Local 35B MoE Agent on 8 GB of VRAM: Q3_K, Experts in RAM

Cover image for article 1169

The author of a Habr post got a 35-billion-parameter MoE model running on a laptop with 8 GB of video memory and 32 GB of system RAM. The goal was to run an uncensored local agent with tool calling. A dense 27B model in BF16 would require 55.6 GB of VRAM, so the choice fell on Q3_K quantization, placing the experts in system memory, and keeping only the attention layers on the GPU. The result: 365 tok/s on prefill, 28-35 tok/s on generation, and stable tool calls.

Why a 35B MoE on 8 GB of VRAM is actually feasible

The key point is the Mixture of Experts architecture. Unlike dense models, where every parameter is active on each token, a MoE model activates only a subset of the experts. For a 35B MoE (the article considers a variant with 32 experts and top-2 routing), the number of active parameters per token is roughly 3.5-4B. This changes the placement economics: the attention layers (shared across all experts) and the currently active experts fit into VRAM, while the remaining experts live in system RAM.

The author’s hardware:

  • GPU: RTX 5070 Ti (8 GB GDDR6, ~896 GB/s bandwidth)
  • RAM: 32 GB DDR5 (dual-channel, ~100 GB/s)
  • SSD: NVMe Gen4 (7 GB/s sequential read)
  • OS: Linux (Windows is not supported for llama.cpp/Tandem/Strata, or support is experimental)

A dense 27B in BF16 (2 bytes per parameter) means 54 GB of weights alone, plus the KV cache and engine overhead for a total above 55.6 GB. Even in 4-bit quantization (Q4_K_M) it comes out to roughly 16 GB — still far too large for 8 GB of VRAM. MoE changes the game: only attention (the shared layers) and the cache of active experts stay in VRAM.

Configuration: Q3_K, experts in RAM, attention on the GPU

The author used llama.cpp (a build with MoE offloading support) with the following flags:

./llama-server -m model-35b-moe-Q3_K.gguf \
  --n-gpu-layers 32 \
  --split-mode layer \
  --main-gpu 0 \
  --tensor-split 1.0 \
  --ctx-size 8192 \
  --batch-size 512 \
  --ubatch-size 512 \
  --flash-attn \
  --mlock \
  --no-mmap

Parameter breakdown:

  • –n-gpu-layers 32 — loads 32 layers onto the GPU. In a MoE setup these are the attention blocks plus embedding, output, and the portion of expert FFN weights that fits in VRAM.
  • –split-mode layer — layer-by-layer placement: each layer is entirely on the GPU or entirely on the CPU; tensor slicing is not used (this avoids PCIe transfers of intermediate activations).
  • –mlock — prevents the OS from paging the weights into swap, which is critical when the model is larger than VRAM.
  • –no-mmap — disables memory-mapped loading and forces the weights to be read into RAM at startup (on NVMe this takes 2-3 seconds for a 35B Q3_K model).

Q3_K quantization (3.25 bits per weight on average) brings the model size down to roughly 14 GB. Attention layers (~2.5 GB) + embedding/output (~0.3 GB) + KV cache for an 8192-token context (~1.2 GB) = about 4 GB of VRAM. The remaining 4 GB of VRAM are given over to the hot experts cache. With 32 experts at roughly 350 MB each in Q3_K, that is about 11 GB in RAM. Under top-2 routing only 2-4 experts per layer are hot at any given moment.

Benchmarks: 365 tok/s prefill, 28-35 tok/s generation

The measurements were taken with a 1000-token prompt, 500 generated tokens, and a temperature of 0.7:

StageSpeed (tok/s)VRAM usageRAM usage
Prefill (prompt processing)3657.8 GB / 8 GB18 GB / 32 GB
Generation (decode, greedy)357.9 GB / 8 GB19 GB / 32 GB
Generation (decode, temp 0.7)28-357.9 GB / 8 GB19-20 GB / 32 GB

The spread on generation (28-35 tok/s) is explained by cache hits and misses on the hot experts. When an expert is already in the VRAM cache the speed holds at 35 tok/s; on a miss, a transfer over PCIe 4.0 x16 (~32 GB/s) from RAM plus computation on the GPU brings it down to 28 tok/s. The author notes that on an RTX 4090 (24 GB of VRAM) the same configuration delivers 85+ tok/s on generation, because every expert fits in VRAM.

Tool calling: stability without censorship

The main goal is a local agent with function calling. The author tested it against a set of 12 tools (file system, shell, HTTP, search, database). In Q3_K the model showed a 94% success rate over 200 tool calls (the Q4_K_M baseline was 96%, and the unquantized BF16 reached 97%). Losing 2-3% is an acceptable price for a local setup with no moderation layer.

One important nuance: the system prompt for tool calling grows to 2800 tokens (the JSON Schema of all the tools plus instructions). Within an 8192-token context this leaves roughly 5300 tokens for the dialogue history — enough for 15-20 rounds of the agent loop.

Comparison with the alternatives: Tandem, Strata, ExLlamaV2

The author tried three engines on this hardware:

EnginePrefill (tok/s)Generation (tok/s)VRAMTool calling
llama.cpp (Q3_K, config above)36528-357.9 GBNative (GGUF)
Tandem (Store mode)34031-387.2 GBThrough a gateway
Strata29022-286.8 GBLimited
ExLlamaV2 (Q4, 4-bit GPTQ)42045-528.0 GBNot supported

ExLlamaV2 is faster on pure generation, but it cannot do tool calling and requires GPTQ quants (Q3_K is unstable for MoE in GPTQ). Tandem in Store mode adds a small generation boost thanks to an SSD-backed cache of experts, but it demands Linux, a fast NVMe, and extra tuning. llama.cpp is the simplest option that works out of the box with native tool calling.

Practical recommendations for 8 GB of VRAM

  1. Choose MoE, not dense. A 35B MoE in Q3_K works; a 27B dense model in Q4_K_M does not (it needs 16+ GB of VRAM). The active parameter count of a MoE is 8-10 times smaller than its total size.
  2. Q3_K is the sweet spot. Q2_K loses quality on tool calling (the success rate drops to 87%), while Q4_K_M does not fit in VRAM without aggressive offloading (generation falls below 15 tok/s).
  3. At least 32 GB of RAM is mandatory. With 16 GB of RAM you get constant OOM errors while the experts are being loaded. 32 GB is a comfortable minimum for a 35B MoE plus the OS and a browser.
  4. NVMe Gen4 is a hard requirement. On a SATA SSD (500 MB/s) generation drops to 12-15 tok/s because of expert cache misses over the bus. Gen4 x4 (7 GB/s) sustains 28+ tok/s.
  5. Linux only. The Windows build of llama.cpp does not handle MoE offloading correctly (NUMA and memory issues). WSL2 is an option, but with a 10-15% overhead.

The economics: is this cheaper than the cloud?

A laptop with an RTX 5070 Ti costs around 120 thousand rubles (prices as of November 2026). Electricity: 80-120 W under load = roughly 0.5 kWh per day = 15 kWh per month = about 100 rubles at a rate of 6.5 rubles per kWh.

A cloud API (OpenRouter, Claude Sonnet 4, GPT-4o) runs $3-15 per 1M tokens. At 30 tok/s of generation that is 108k tokens per hour = $0.3-1.6 per hour. A local setup pays for itself at roughly 100-150 hours of active use per month. But the main arguments are privacy (the code never leaves the machine), the absence of rate limits, and the ability to work without an internet connection.

Our calculator in the article RAM formula for model sizing automates the memory estimate for any model. The full guide to the tooling (Ollama, LM Studio, llama.cpp) can be found in the material Ollama, LM Studio, llama.cpp guide. A setup walkthrough on the RTX 3060 12GB is described in the overview RTX 3060 12GB for a local LLM.

Useful resources: llama.cpp repository, Transformers documentation.

Spoiler: MoE quantization and llama.cpp tuning for a local llm on 8 GB VRAM

Launch configuration for a 35B MoE Q3_K on 8 GB of VRAM (llama.cpp, Linux):
./llama-server -m model-35b-moe-Q3_K.gguf \
–n-gpu-layers 32 \
–split-mode layer \
–main-gpu 0 \
–tensor-split 1.0 \
–ctx-size 8192 \
–batch-size 512 \
–ubatch-size 512 \
–flash-attn \
–mlock \
–no-mmap \
–port 8080 \
–jinja \
–chat-template-function “tools”

Key Q3_K quantization parameters for MoE:
– type: q3_k (3.25 bits per weight on average)
– block_size: 256
– expert_tensors: separate per-expert blocks (llama.cpp loads them lazily)
– attention_tensors: shared, always kept in VRAM

Memory footprint at runtime:
VRAM: attention (2.5 GB) + embed/out (0.3 GB) + KV-cache 8k (1.2 GB) + hot experts cache (3.5-4 GB) = 7.5-8 GB
RAM: cold experts (11 GB) + context overhead (2-3 GB) + OS (4-6 GB) = 17-20 GB
Total RAM: 32 GB is a comfortable minimum, 16 GB carries a real risk of OOM.

Tool-calling success rate by quant level (200 calls, 12 tools):
– BF16 (unquantized): 97%
– Q4_K_M: 96% (does not fit in 8 GB without offloading)
– Q3_K: 94% (recommended for 8 GB of VRAM)
– Q2_K: 87% (degradation on complex call schemas)

Checklist before launch:
☐ Linux (Ubuntu 24.04 / Arch / Fedora 40+)
☐ NVMe Gen4 (verify with: nvme smart-log /dev/nvme0 | grep “data_units_read”)
☐ RAM 32+ GB (free -h, swappiness=10)
☐ llama.cpp built with GGML_CUDA=ON and LLAMA_MOE=ON
☐ Model in GGUF Q3_K (conversion: llama-quantize –q3_k)
☐ System prompt for tools < 3000 tokens
☐ Context 8192 (for agent loops of 15-20 rounds)

Like this post? Please share to your friends:
11AI - Your Free LLM
Leave a Reply

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: