Local LLM Deployment: A Practical Guide to Running Large MoE Models on Two GPUs
This guide walks through a practical, reproducible approach to deploying a large mixture-of-experts (MoE) model locally on a standard two-GPU setup. It explains why "just loading the weights" often fails in practice, how to budget VRAM, memory bandwidth, and context length before tuning, and the four engine-side problems that must be solved: consistency across heterogeneous KV cache pools, dual reference counting with lazy reclamation, unified scheduling across prefill, decode, and speculative decoding paths, and integration of a single-layer speculative head. It also includes step-by-step deployment instructions, sample launch configuration semantics, and a troubleshooting checklist for OOM, high time-to-first-token, low throughput, long-context jitter, and ineffective speculative decoding. Readers will learn the core methodology: budget first, optimize second; unify the cache view first, tune performance second.
1. Why Running Locally Is Harder Than It Looks
When teams attempt their first local deployment of a very large model, they often run into a counterintuitive situation: the weights load, the process does not crash, but throughput is unusable, time-to-first-token swings wildly, and memory overflows as soon as the context grows a little. The root cause is usually not “insufficient compute” but three mismatches: VRAM capacity versus weight precision, memory bandwidth versus the access pattern of the decode phase, and cache management strategy versus the model’s attention structure.
Consider a typical local deployment: a team runs a mixed-precision MoE model with roughly 284 billion total parameters and about 13 billion activated parameters on two accelerator cards with 96GB of VRAM each. The checkpoint uses 4-bit weights for the expert layers and 8-bit for the attention and dense feed-forward layers. The intent behind this design is clear: one set of weights can cover all hardware that supports 4-bit compute, so different generations of accelerator cards are supported at once. The benefit for the deployer is “universal weights”; the cost is that the engine must handle two numeric precisions, three KV cache pools, and two compression states simultaneously.
2. Budget First: VRAM, Bandwidth, and Context
2.1 VRAM Budget
The VRAM footprint of mixed-precision weights can be roughly estimated as:
Weight VRAM ≈ parameter count × bytes per parameterExample: 284B × 0.5 Byte (4-bit) ≈ 142GB (experts only)Plus 8-bit attention/dense layers, framework overhead, activations, and temporary buffers
Conclusion: 192GB across two cards is a configuration that “just fits with very little headroom,” so stability has to come from quantized checkpoints, sharding strategy, and cache limits.
2.2 Bandwidth Budget
During decode, every generated token requires reading the activated expert weights once. The smaller the activated parameter count and the smaller the batch, the more likely memory bandwidth becomes the bottleneck. For small-batch scenarios, prioritize higher parallelism and better operator fusion rather than blindly increasing batch size.
2.3 Context Budget
For million-token context, the key is not compute but cache. Hybrid sparse attention splits each layer into a combination of “sliding window + compression”: one approach applies 4:1 compression and then takes top-512 sparse selection, while another applies 128:1 compression and goes dense. Under very long context, per-token attention compute and cache usage can be reduced to a small fraction of traditional dense attention, which is the fundamental reason long context is practical at all.
3. Four Problems the Engine Must Actually Solve
3.1 Consistency Across Heterogeneous Cache Pools
With a sliding window pool, two compressed-state pools, and a dense pool coexisting, the traditional assumption that “prefix caching only tracks token sequences” breaks down. A workable approach is to index “virtual full token slots” with a radix tree, then project them onto each physical pool to form shadow structures. Compressed states are carried by a ring buffer, with an address mapping like:
physical address = page number × ring length + (position % ring length)
The benefit is that once a page is released, the ring is invalidated automatically, with no extra tracking required.
3.2 Dual Reference Counting and Lazy Reclamation
Each tree node maintains two counters: one for the “full/compressed shadow” and one for the sliding window only. When the window counter reaches zero, only the window slots are marked as tombstones; the node and the compressed shadow remain in the tree for continued reuse, avoiding thrashing from repeated rebuilds.
3.3 Unified Scheduling Across Three Execution Paths
Prefill, decode, and speculative decoding have completely different cache read/write patterns. In engineering terms, the scheduler should use “virtual slots” as a unified view and push the differences between paths down into the projection layer, rather than writing three separate branches in the business layer.
3.4 Integrating a Single-Layer Speculative Head
When the model ships with a lightweight speculative head in one layer, the draft and verification steps must share the same cache view, or the acceptance rate collapses. The recommendation is to fix an upper bound on accepted length first, then relax it gradually.
4. Reproducible Deployment Steps
- Environment setup: align driver and runtime versions, and confirm both 4-bit and 8-bit operators are available.
- Parallel partitioning: for two cards, prefer tensor parallelism and place expert layers by shard to avoid frequent cross-card communication.
- Cache limits: start with conservative values, observe peak VRAM, then raise by 5%–10% each time.
- Precision strategy: experts at 4-bit, attention and dense at 8-bit; do not mix in unverified quantization schemes.
- Layered validation: first verify correctness with short context, then long-context stability, then stress-test throughput.
- Observability: set up monitoring and log alerts for time-to-first-token, per-token latency, cache hit rate, and peak VRAM.
Sample launch parameters (pseudocode, expressing configuration semantics only):
engine.launch(tensor_parallel=2,expert_quant="fp4", dense_quant="fp8",context_len=1048576,kv_pool={"swa":128, "compress_a":512, "compress_b":"dense"},speculative={"enabled":true, "max_draft":3})
5. Common Issues and Tuning Checklist
- VRAM overflow: lower the cache limit and concurrency first, then consider shortening the context.
- High time-to-first-token: check prefill chunk size and whether the compression path is being hit.
- Throughput not improving: confirm whether bandwidth is the limit, and improve parallelism and fusion rather than piling on batch size.
- Long-context jitter: verify the ring buffer mapping and page release logic.
- Speculative decoding ineffective: confirm the draft and main model share the same cache view.
6. Conclusion
The core methodology for fast local deployment of a large MoE model comes down to one sentence: budget first, optimize second; unify the cache view first, tune performance second. Once the three budgets—VRAM, bandwidth, and context—are clear, and the consistency and reclamation strategy for heterogeneous caches is correct, even an ordinary two-card environment can stably serve inference with million-token context. To further reduce operational overhead, you can combine general cloud capabilities such as container platforms, object storage, logging services, and monitoring alerts to standardize environment packaging, model distribution, and observability.
