Running a 35B MoE Model on 8GB VRAM: A Practical Guide to Local Deployment
This article walks through deploying a 35B-parameter Mixture-of-Experts (MoE) model on a machine with only 8GB of VRAM. It explains why active parameters determine speed while total parameters determine whether the model fits, how to budget VRAM and system memory, why KV Cache becomes the real bottleneck in long conversations, how to interpret memory-bound decoding throughput, and how to evaluate output quality. It closes with a practical split between local and cloud inference and a deployment checklist.
1. Where the Problem Starts: Total Parameters vs. Active Parameters
Dense models scale predictably: more parameters mean more VRAM, and per-token compute rises at the same rate. Sparse Mixture-of-Experts (MoE) breaks that linear relationship. The model holds a large total parameter count, but each token passes through only the few experts selected by the router, so the parameters activated per step are far smaller than the total.
This is the technical basis for claims like “3B active parameters match a 27B dense model”: knowledge capacity comes mainly from total parameters, while per-step compute and memory traffic are determined by active parameters. Understanding this is the prerequisite for deciding whether a small machine can run the model: active parameters determine speed; total parameters determine whether it fits. The two have to be budgeted separately.
2. VRAM and Memory Budget: Do the Math Before You Start
The most common reason local deployment fails is not the model but an unclear budget. The basic formula:
def estimate(total_params, weight_bits, ctx_len,layers, kv_heads, head_dim, kv_bits=16):# Weight footprint (multiply by 1.05-1.1 in practice for# alignment and metadata overhead)weight_gb = total_params * weight_bits / 8 / 1e9# KV Cache: one copy each for K and V, per layer, per tokenkv_gb = 2 * layers * kv_heads * head_dim * ctx_len * kv_bits / 8 / 1e9return weight_gb, kv_gb
For 35B total parameters at 4-bit weights, the weights alone come to roughly 17-18GB, which will not fit in 8GB of VRAM. You need a hybrid residency scheme that spans VRAM and system memory: keep the attention layers, shared layers, and hot experts in VRAM, leave the remaining experts in memory, and let the runtime swap them in on demand. 16GB of system memory is the “just barely enough” tier, since 2-3GB must be reserved for the OS and context, leaving very little real headroom.
Engineering essentials:
- Quantization bit width comes first: 4-bit is the sweet spot for consumer hardware; 8-bit usually blows the budget outright.
- Keep routing-related modules at higher precision: the router and normalization layers are precision-sensitive, so quantization offers little gain and carries real risk.
- Place experts by tier: split experts into hot and cold tiers by access frequency, and keep hot experts resident in VRAM.
- Budget context separately: with long contexts, KV Cache alone can reach several GB, so measure before scaling up.
3. KV Cache: The Real Hidden Killer of Long Contexts
A typical scenario from testing: by the fourth turn of a multi-turn conversation, the context has accumulated past 20,000 tokens and speed drops noticeably. The cause is not the weights but the KV Cache, which grows linearly with context, and every generated token requires re-reading the entire KV history.
Mitigations, ordered by cost-effectiveness:
- Cap the context window: enforce a hard limit with rolling summarization instead of concatenating history indefinitely.
- Quantize the KV Cache: dropping KV from 16-bit to 8-bit halves the footprint, with usually acceptable accuracy loss.
- Grouped-query attention (GQA)-style structures: far fewer KV heads than Q heads, which saves several times the space by design.
- Prefix reuse: compute and cache fixed prefixes such as the system prompt only once.
- Sliding window / local attention: trade very long-range dependencies for a stable memory curve.
4. Reading the Speed Numbers: Why “It Runs” Isn’t “It’s Usable”
Decoding is memory-bound, not compute-bound: every token requires reading the weights activated for that step plus the entire KV Cache. The theoretical ceiling is roughly:
tokens/s ≈ effective memory bandwidth / bytes read per token
At 4-bit, 3B active parameters are about 1.5GB, which with sufficient bandwidth could reach tens of tokens/s. But under hybrid residency, cold experts must be swapped in over the PCIe link, whose bandwidth is one to two orders of magnitude below VRAM bandwidth. In practice that lands around a dozen tokens/s: usable, but clearly slower than a cloud service.
Suggested optimization order:
- Raise the hot-expert hit rate to reduce swap-ins;
- Shorten the context to reduce per-step KV reads;
- Increase batch concurrency (if VRAM allows) to amortize fixed overhead through throughput;
- Separate prefill from decode: first-token latency on long prompts is governed by prefill, so measure interaction feel for each phase.
5. Quality Evaluation: Don’t Draw Conclusions from Active Parameters
“Small active parameter count matches a large dense model” should be treated as an observation on specific tasks, not a universal law. The rigorous approach is to build a small evaluation set covering four task types: knowledge Q&A, long-document summarization, code generation, and structured output. Fix temperature and prompts, then compare accuracy, format compliance, and human preference. Also note that MoE behaves more complexly under fine-tuning, merging, and quantization; expert imbalance can degrade some capabilities, so the evaluation must include before-and-after quantization comparisons.
6. Dividing Work Between Local and Cloud
Local inference keeps data in-house, works offline, and has zero marginal cost; its limits are the VRAM ceiling and the speed ceiling. A sound architecture is layered: sensitive data and high-frequency light tasks go to a local small model, while complex reasoning and long-context tasks call general-purpose cloud compute. Decouple the two with a message queue, unify observability with logging and monitoring/alerting services, version model weights and datasets in object storage, and run inference instances on a container platform for elastic scaling. This preserves compliance boundaries and avoids holding idle hardware for peak demand.
7. Deployment Checklist
- Budget weights, KV Cache, and runtime overhead separately, with 15% headroom;
- Run a small correctness regression after quantization, then stress-test speed;
- Cap the context and add rolling summarization to avoid a collapse in responsiveness after the fifth turn;
- Record first-token latency and steady-state generation speed separately;
- Build comparison data across quantization states and context lengths, and decide with data rather than impressions.
Summary: MoE turns “running a large model on a small machine” from impossible into an engineering problem. The real barrier has shifted from compute to budget management and context governance. Get the VRAM math right, keep KV Cache under control, and place hot experts correctly, and even an 8GB-VRAM device can deliver a usable local inference experience.
