High-Throughput LLM Inference on 12GB VRAM: Expert Layering and Heterogeneous Scheduling
This article explains how to keep LLM inference throughput usable when the model does not fit in 12GB of VRAM, a common situation with MoE architectures whose total parameter count reaches tens of billions while only a few billion are activated per token. It covers three layers of design: keeping hot experts resident in VRAM with dynamic residency based on routing statistics, running overflow experts in parallel on the CPU while the accelerator handles resident experts and attention, and generating kernels at runtime behind a backend-agnostic operator abstraction. A tuning checklist and serving notes close the article.
1. The Real Bottleneck: VRAM Capacity in Local Inference
Local LLM inference has long been constrained by VRAM capacity. Take a Mixture-of-Experts (MoE) model as an example: with a total parameter count between three billion and thirty billion and only a few billion activated parameters, the weight footprint can still land in the range of roughly ten to twenty-something GB even after low-bit quantization. For a consumer GPU with 12GB of VRAM, failing to hold all expert weights is the norm rather than the exception.
Conventional inference engines facing this scenario usually have only two options. One is to refuse to load the model and report insufficient VRAM. The other is to offload the overflow portion wholesale to host memory and let the CPU fill in the computation serially. The cost of the latter is that every decoding step goes through a full weight transfer and synchronization, with PCIe bandwidth acting as a hard ceiling; measured throughput often drops to single-digit tokens/s, which makes interactive use impractical.
So the essence of the problem is not “can it fit” but “how to keep throughput high when it does not fit.” This requires the engine to shift from static placement to dynamic scheduling, treating VRAM as a scarce resource that needs careful orchestration.
2. Key Idea 1: Expert Layering and Dynamic Residency
The MoE structure is naturally suited to layering. Each token is routed to only a few experts, which means the weights actually participating in computation at any moment are only a small fraction of the total. On this basis, “hot experts” can stay resident in VRAM while “cold experts” remain in host memory, with the resident set continuously adjusted according to the observed routing distribution.
Three things need to be solved in engineering:
- Sliding-window aggregation of routing statistics, so transient spikes do not mislead the scheduler;
- Timing of swap-in and swap-out prefetch, so transfer latency is hidden behind compute latency as much as possible;
- Damping of churn in the resident set, to prevent frequent swapping from amplifying bandwidth consumption.
The scheduling logic can be sketched as:
on_route(token):experts = router(token)for e in experts:if e in vram: continueif prefetch_queue.has(e): continueenqueue_async_copy(e, host -> vram)evict_cold(now - window)
Compared with fixed offloading, dynamic residency spends effective bandwidth on the weights that are actually used, and this is the main source of the throughput gain.
3. Key Idea 2: Parallel Execution on CPU and Accelerator
Merely swapping in and out is still serial thinking. A more aggressive approach is to compute the experts that do not fit in VRAM directly on the CPU in parallel, while the accelerator continues processing the resident experts and the attention part, with a final reduction that merges results according to the routing.
For this heterogeneous parallelism to hold, several conditions must be met:
- The computation graph must be splittable into independently submittable tasks with a clear reduction point at the end;
- The host-side thread pool and the device-side streams need a non-blocking dependency description, avoiding implicit global synchronization;
- The reduction order must correspond strictly to the routing weights, otherwise numerical results are not reproducible;
- The gap between memory bandwidth and VRAM bandwidth must be reflected in how parallelism is set; the CPU side is better off with fewer but contiguous large-block computations.
The gain in practice comes from time overlap: while the CPU takes on part of the experts, the device is not idle, so the overall step time is determined by the maximum of the two rather than their sum.
4. Key Idea 3: Runtime Kernel Compilation and Backend Abstraction
Heterogeneous execution raises the bar for kernel portability. One workable path is to generate device code from high-level tensor expressions at runtime and compile it just in time, caching the compiled artifacts to amortize first-launch overhead; at the same time, operators are abstracted into backend-agnostic scheduling descriptions, so the same logic can target both a general GPU programming interface and a cross-platform graphics/compute API.
The benefits are avoiding lock-in to a single vendor ecosystem and external C++ base libraries, a lighter deployment footprint, and a clearer degradation path: full residency when VRAM is sufficient, automatic entry into heterogeneous mode when VRAM is tight, and a fallback to pure CPU execution when hardware acceleration is unavailable.
5. Practical Notes and Tuning Checklist
- Quantization choice: prefer a tier that is slightly smaller than VRAM to guarantee full residency; if overflow is unavoidable, pick a quantization format that is slightly larger but better aligned in structure, reducing dequantization overhead.
- Context and batch size: the KV cache also consumes VRAM, and long contexts squeeze the space available for expert residency, so reserve a fixed budget for the cache.
- Speculative decoding: a draft-verify mechanism can significantly improve decoding throughput, but monitor the acceptance rate; when it is too low, the overhead increases instead.
- Prefill optimization: chunked prefill, operator fusion, and parallelism tuning can bring first-token latency into an acceptable range.
- Serving integration: expose interfaces compatible with mainstream ecosystem conventions (both session-style and message-style), so existing front ends and orchestration systems can integrate smoothly.
- Observability: when deploying on a container platform or cloud host, it is advisable to connect logging and monitoring/alerting services and continuously collect VRAM usage, swap counts, routing distribution, and throughput curves.
If the services above are hosted on general capabilities from Baidu AI Cloud, a container platform can handle elastic scaling, object storage can distribute models and compilation caches, and monitoring/alerting can track VRAM and throughput metrics, moving a local experiment smoothly into an operable service form.
6. Conclusion
“A model larger than VRAM” is not an insurmountable obstacle. With three layers of design, expert layering and dynamic residency, parallel execution on CPU and accelerator, and runtime kernel compilation with backend-agnostic abstraction, a device with 12GB-class VRAM can still achieve usable decoding throughput. What really determines the outcome is not the hardware specification itself, but whether the scheduling strategy spends scarce bandwidth on the weights that are actually used, and whether the engineering implementation can push the synchronization cost of heterogeneous execution low enough.
