Inference Optimization for MoE
local graph
Chapter 7 — Inference Optimization for MoE
Section titled “Chapter 7 — Inference Optimization for MoE”Expert Loading, Caching, and Memory Hierarchy Management
Section titled “Expert Loading, Caching, and Memory Hierarchy Management”The fundamental challenge of serving large MoE models is the mismatch between model memory requirements and available GPU memory. A model with 236 billion total parameters like DeepSeek-V2 requires approximately 472 GB of memory to store weights in bfloat16, far exceeding the 80 GB available on a single H100 GPU. Tensor parallelism and expert parallelism can distribute this memory across multiple GPUs, but for many deployment scenarios - particularly edge, on-premise, or cost-sensitive cloud deployments - a more memory-efficient approach is needed. Expert offloading addresses this by keeping only the most frequently used experts in fast GPU memory and loading additional experts from CPU memory or NVMe storage on demand.
Expert caching policy design determines which experts reside in the GPU memory cache and which are offloaded to slower memory tiers. The simplest policy is LFU (Least Frequently Used) caching, which evicts the experts with the lowest cumulative access frequency. LFU caching works well when request distributions are stable, as the most popular experts will naturally accumulate in cache. LRU (Least Recently Used) caching evicts the experts not accessed in the longest time, which works better when request distributions shift over time or when expert access patterns are correlated with recent request history. Predictive caching - pre-loading experts expected to be needed based on routing patterns in previous layers of the same request - can dramatically reduce cache miss rates by exploiting the temporal locality of expert access within a single inference request.
Predictive expert prefetching exploits the observation that routing decisions in a MoE model are correlated across layers: if token x is routed to expert 3 in layer 5, it is more likely to be routed to a subset of specific experts in layer 6 than a random expert. By building a routing predictor - either a lightweight neural network that predicts future routing from the current token representation, or a statistical lookup table trained on routing patterns observed during warmup - the serving system can begin loading the likely-needed experts for the next layer while the current layer computation is in progress, effectively hiding the load latency behind compute. Implementations of expert prefetching on consumer hardware have demonstrated inference throughput improvements of 40 to 60 percent compared to reactive loading.
Expert quantization is particularly valuable for MoE serving because the total parameter count that must be stored grows linearly with the number of experts, making per-expert memory savings directly proportional to serving cost. 4-bit quantization of expert weights using GPTQ, AWQ, or ExLlamaV2 can reduce per-expert memory requirements by a factor of four relative to bfloat16, enabling much larger models to fit in a given memory budget with modest quality degradation. Quantization of the gating network must be handled more carefully, as errors in gating scores can cause routing changes that have outsized quality impact relative to the small number of parameters involved in the gating computation.
Flash-attention style implementations for the expert dispatch and gather operations - the all-to-all communication steps in distributed MoE serving - can significantly reduce the memory bandwidth consumption of these operations. Standard dispatch implementations require materializing the full routing table and token assignment as a dense matrix operation, consuming memory proportional to the product of batch size and expert count. Sparse dispatch implementations that work directly with the sparse routing assignments - similar to how FlashAttention works with sparse attention patterns - reduce memory consumption to proportional to the product of batch size and k, providing immediate memory savings for typical k=2 deployments.
MoE Inference Memory Hiyeracthy
GPU HBM ┌────────────────────────────────┐ (Fastest, Smalles!) │ Cached Experts [Cached][Experts] │──┐ └──────────────┬─────────────────┘ │ Preflech ▼ │ (10s µs latency) Preflech ┌────────────────────────────────┐ │ (10s-100s │ CPU DRAM │──┘ µs latency) │ Officaded Experts │ └──────────────┬─────────────────┘ ▼ Evict NVMe Storage ┌────────────────────────────────┐ (10s µs latency) (Large!) │ NVMe Storage │──┘ │ Archived Experts │ └────────────────────────────────┘ (Slowest, Largest)
Time (ms) │ Expert A Load │ Expert A Compute │ Expert B Compute │ Expert B Compute │ Preflech Expert C │ Preflech Expert C[!visual-conversion] The three memory tiers, their labels, and the timeline rows are transcribed top to bottom as printed (misspellings such as “Hiyeracthy”, “Preflech”, “Officaded” kept). Lost: the bar lengths on the timeline, which have no time values.
Speculative Decoding for MoE Models
Section titled “Speculative Decoding for MoE Models”Speculative decoding - the technique of using a small draft model to propose multiple candidate tokens that are then verified in parallel by the large target model - has become a standard optimization for dense LLM serving, providing 2-4x decoding speedups with zero quality degradation. Adapting speculative decoding to MoE models requires careful consideration of how the routing decisions of the draft model relate to the routing decisions of the target model. If the draft and target models make very different routing decisions on the same tokens, the speculative execution will have low acceptance rates and the overhead of draft generation will not be justified by the speedup from parallel verification.
Draft model selection for MoE speculative decoding offers several architectural options. A natural choice is a smaller dense model that serves as the draft for the larger MoE target, exploiting the fact that a 7 billion parameter dense model can serve as a surprisingly effective draft for a 47 billion parameter MoE model if they were trained on similar data. Alternatively, one or more of the smaller experts from the target MoE model can be used as a draft, exploiting the fact that the expert’s knowledge is a subset of the full model’s knowledge and its routing behavior may correlate with the full model’s routing. Expert-as-draft approaches have the advantage that no separate draft model needs to be maintained, but the disadvantage that the expert has much lower quality than the full model.
Speculative routing - predicting the routing decisions of future MoE layers before computing those layers - is a distinct optimization that can be combined with token-level speculative decoding. If the routing decisions in layer i+1 can be predicted with high accuracy from the token representations in layer i, the expert weights for layer i+1 can be loaded in parallel with the computation of layer i, eliminating the serial load-compute dependency that causes latency in expert-offloading deployments. The accuracy of routing prediction varies by model and layer: some layers have highly predictable routing (95 percent or more accuracy from the previous layer representation) while others are less predictable, requiring adaptive prefetching strategies that balance prediction accuracy against the cost of unnecessary expert loading.
Medusa-style speculative decoding adapted for MoE adds multiple prediction heads to the MoE model that independently predict the next k tokens, allowing the model to generate multiple candidate completions in a single forward pass. The routing decisions for each speculative token can be predicted from the main sequence routing pattern, enabling the speculative tokens to be verified through a single forward pass that processes all speculative continuations simultaneously. This approach has been implemented for Mixtral-class models and shows throughput improvements of 2.5-3.5x in low-batch serving scenarios, with quality preservation verified through careful statistical testing of acceptance rate and output distribution.
Batch-level speculative decoding is an extension of the standard approach that allows different requests in the same serving batch to benefit from speculative decoding simultaneously, even when they are at different positions in their generation sequences. Standard speculative decoding requires all requests in the batch to be at the same stage of generation for the speculation to be synchronized. Continuous batching with per-request speculation states allows different requests to proceed at different rates, with the speculative decoding benefit applied per-request rather than per-batch. Implementing this efficiently for MoE models requires careful management of the per-request routing state and careful scheduling of expert dispatch operations across requests at different speculation stages.

Specultaive Decoding for MOE (as printed): a small draft model generates 5 candidate tokens; the MoE target model verifies them in parallel; outcomes “All 5 Accepted (Fast-forward)”, “First 3 Accepted (Partial Acceptance)”, “First 3 Accepted, 4th (Single Token Accept)”; sequential vs. speculative decode timeline, “SPEEDUP: ~2-3x”.
Dynamic Batching and Continuous Batching for MoE
Section titled “Dynamic Batching and Continuous Batching for MoE”Continuous batching, also known as iteration-level batching or in-flight batching, is the standard technique for maximizing GPU utilization in LLM serving by allowing new requests to join the batch at each decode step rather than waiting for all requests in a batch to complete. For MoE models, continuous batching has additional considerations: as the batch composition changes at each step, the distribution of tokens across experts changes, potentially causing expert load imbalance that increases with the diversity of the request set. Serving systems must monitor per-expert load across the continuously changing batch and may need to adjust expert capacity allocations dynamically to avoid quality degradation from load-induced token dropping.
Request batching strategies for MoE serving can exploit routing correlation to improve expert utilization. If requests are batched such that tokens within the batch tend to route to the same experts - for example, by grouping requests on similar topics or from the same domain - expert utilization will be higher and the overhead of routing diverse tokens to many different experts will be lower. Domain-aware batching has been implemented in some production MoE serving systems and shows measurable throughput improvements for workloads with identifiable domain clusters, at the cost of increased queuing latency for requests that arrive in a domain-imbalanced order.
Disaggregated prefill and decode serving is an emerging deployment pattern for LLM serving that has particular relevance for MoE models. In disaggregated serving, prefill computation (processing the input prompt) is performed on a dedicated set of compute-heavy machines optimized for throughput, while decode computation is performed on a separate set of memory-bandwidth-heavy machines optimized for low latency. For MoE models, this disaggregation is particularly beneficial because prefill and decode have very different expert utilization profiles: prefill processes many tokens in parallel, achieving high expert utilization, while decode processes one token at a time per request, achieving low expert utilization unless the batch is large. Disaggregating these workloads allows each to be served on infrastructure optimized for its specific characteristics.
Expert parallelism in distributed MoE serving assigns different experts to different GPU devices, allowing expert computation to be parallelized across the serving cluster. In a system with 8 experts per layer and 8 GPUs, each GPU can host one expert per layer, and tokens are dispatched to the GPU hosting their selected expert via all-to-all communication. This parallelism strategy scales naturally with the number of experts and can support serving MoE models that exceed the memory capacity of any single GPU. The primary challenge is the all-to-all communication latency and bandwidth, which becomes the bottleneck as the number of GPUs increases and the amount of data exchanged per step grows linearly with batch size.

Token dispatch across eight GPUs, each hosting experts, with a batch processing timeline (routing/dispatch, expert compute, all-to-all) and a network bandwidth utilization bar chart.