Understanding Large-Scale MoE Architecture: Sparse Attention and Inference Cost

    This article explains the key design choices behind modern large-scale Mixture-of-Experts (MoE) models, using the DeepSeek-V3 technical report as the primary reference. It covers the difference between total and activated parameters, shared versus routed experts, why long context is expensive and how sparse attention and MLA address it, Hyper-Connections, native multi-token prediction with speculative decoding, BF16 vs FP8 precision, and practical guidance for benchmarking and calculating per-task inference cost. A selection checklist is included for developers evaluating these models.

    Introduction: Total Parameters vs. Activated Parameters

    Parameter count is often treated as a proxy for model capability, but for developers it is more useful to distinguish two metrics. Total parameters determine the model’s capacity ceiling, while the number of parameters activated per token determines the compute cost of each inference pass. The Mixture-of-Experts (MoE) architecture is the canonical design that decouples these two.

    This article uses the publicly available DeepSeek-V3 technical report as its primary reference to explain several key design choices in today’s large-scale MoE models. All specific figures come from that report; data from other models is only cited when the source is explicitly noted.

    1. Sparse Activation: Trading Capacity for Controllable Compute

    MoE replaces the feed-forward network layers with multiple expert networks. A gating network (the Router) selects a small subset of experts for each token, while the rest stay idle. This allows the model to have a very large total parameter count while keeping the per-forward-pass compute relatively small.

    The main published configuration of DeepSeek-V3:

    Metric Value (source: DeepSeek-V3 technical report)
    Total parameters 671B
    Activated parameters per token 37B
    Routed experts per layer 256
    Routed experts activated per token 8
    Shared experts 1
    Layers 61
    Hidden dimension 7168
    Context window 128K

    Based on these numbers, each token uses only about 5.5% of the parameters (37B out of 671B). In other words, the inference compute of an MoE model is close to that of a dense model in the tens-of-billions range, while its capacity approaches that of a model with hundreds of billions of parameters.

    This design has an easily overlooked cost. All expert parameters must reside in GPU memory or a memory pool, even though only a small fraction is used at any time. In deployment, the bottleneck is usually memory capacity and inter-GPU communication bandwidth, not the activated parameter count. So when assessing the hardware requirements of an MoE model, look at both total and activated parameters.

    2. Shared Experts vs. Routed Experts

    In DeepSeek-V3, each layer has one shared expert in addition to the routed experts. The shared expert participates in the computation of every token and mainly handles general linguistic patterns and cross-domain fundamentals. Routed experts are selected on demand by the gating network and tend to specialize in particular patterns or domains.

    The benefit of this division is that general knowledge does not need to be duplicated across every routed expert, reducing redundancy and making the specialization of routed experts cleaner. The report also notes that DeepSeek-V3 uses an auxiliary-loss-free load-balancing strategy, adjusting routing bias to prevent a small number of experts from being over-selected. Load imbalance leaves some experts idle while others are overloaded, which directly slows down both training and inference.

    3. Attention: Where Does Long-Context Cost Come From?

    Understanding long-context cost requires separating two phases. In the prefill phase, the entire input is processed at once, and standard attention compute grows quadratically with context length L. In the decoding phase, one token is generated at a time, but the full historical key-value cache (KV Cache) must be read, so memory usage grows linearly with L and often becomes the bottleneck.

    Grouped-Query Attention (GQA) reduces the KV cache size by letting multiple query heads share key-value heads. Multi-head Latent Attention (MLA) goes further by compressing keys and values into a low-rank latent space for storage. DeepSeek-V2 and V3 both adopt MLA.

    Sparse attention is another approach. The core idea: each query attends to only a small subset of historical positions. A typical implementation has two steps: a lightweight indexer first scores the historical positions, then the main attention computes only over the top-K scoring positions. The following pseudocode is illustrative only and not runnable:

    1. # Pseudocode: illustrates the idea only
    2. scores = indexer.score(query, kv_cache) # Lightweight scoring; still scans history
    3. top_idx = scores.topk(k).indices # Select the top-K positions
    4. out = attention(query, kv_cache[top_idx]) # Main attention computes only these K positions

    Two caveats. First, the indexer itself still scores all historical positions, so the per-query cost grows linearly with L rather than dropping to a constant. Sparse attention reduces the quadratic cost of the main attention; it does not eliminate all overhead. Second, sparse selection discards information from unselected positions. Whether the model retains its quality depends on how the indexer is trained and on the task type.

    Regarding “how long a context is supported,” distinguish the theoretical limit from the practically usable length. The maximum length in a model’s configuration only reflects what the positional encoding and inference framework allow. The truly usable length should be judged by the vendor’s published evaluations, especially long-context retrieval tests. DeepSeek-V3’s published configuration supports a 128K context; when evaluating the model, rely on this figure and your own measurements.

    4. Multi-Stream Residuals: Widening the Information Channel

    A standard Transformer layer has a single residual stream through which information flows between layers. Hyper-Connections (proposed by ByteDance’s Seed team in 2024) expand this residual stream into multiple parallel channels and let the model learn how to mix information across them.

    Potential benefits include: different channels carrying different types of information, mitigated information loss in deep networks, and more gradient paths during training. The costs are additional memory and communication overhead, and the contribution of each channel must be validated through ablation studies. For developers, the right way to judge an architectural change is its effect at equal compute, not the conceptual description in a paper.

    5. Native Multi-Token Prediction and Speculative Decoding

    Multi-Token Prediction (MTP) trains additional prediction heads so the model predicts several future tokens simultaneously during training. At inference time, these extra heads can act as a draft model: they quickly generate a few candidate tokens, which the main model then verifies in a single pass, directly emitting the accepted ones. This is the basic workflow of speculative decoding.

    Compared with a separate small model bolted on afterwards, a native draft model shares the main model’s training process, so its output distribution is closer and its candidate tokens typically have a higher acceptance rate. However, the actual speedup depends on the acceptance rate, batch size, and hardware. With large batches, compute resources are tighter and the benefit of speculative decoding shrinks. Measure throughput on your own workload rather than applying vendor-advertised speedup figures directly.

    6. Precision: BF16 vs. FP8

    BF16 is a common 16-bit floating-point format for training and inference, offering good precision. FP8 compresses weights and parts of the computation to 8 bits; on hardware with FP8 tensor core support, it reduces the memory footprint of weights and increases matrix multiplication throughput. The actual speedup depends on the hardware model, operator implementation, and batch shapes—there is no universal multiplier.

    FP8 precision loss is typically controlled through block-wise quantization. The MX (Microscaling) family of formats shares a scaling factor across small blocks (commonly 32 elements per the OCP specification), which preserves accuracy better than a single scaling factor for an entire tensor. Some vendors release FP8 weights directly; before deploying, check the quantization method, calibration data, and evaluation results described on the release page.

    7. Benchmarks and Cost Accounting

    Public benchmarks carry data contamination risk. Pretraining data may contain test questions or their variants, so cross-model leaderboard comparisons have limited credibility. A more reliable approach is to build a private evaluation set:

    • Draw samples from your real business scenarios, covering the main use cases and common failure modes;
    • Separately test instruction following, long-context retrieval (e.g., inserting key information into a long document and asking the model to find it), and the format correctness of tool calls;
    • For the same set of tasks, record each model’s success rate, average input/output token counts, and number of retries.

    Cost accounting should center on “cost per successful task” rather than comparing list prices. A commonly used formula:

    Cost per task = (average input tokens × input price + average output tokens × output price) ÷ task success rate

    This formula amortizes the cost of failed retries into successful tasks. If your system supports caching, factor the cache hit rate into the input token calculation. If you use speculative decoding, convert the accelerated throughput into latency and concurrency costs as well.

    Be careful with same-tier comparisons too. Flagship MoE models are often priced between lightweight models and top-tier proprietary models, and they suit different scenarios. Conclusions are only meaningful when models are compared on the same tasks under the same evaluation conditions.

    8. Model Selection Checklist

    Before making a selection, confirm each item:

    • Have you evaluated on your own business data, recording success rates and failure types?
    • Have you tested long-context tasks at realistic lengths, rather than relying on the maximum length in the configuration?
    • Can your deployment handle the required memory, GPU count, and communication bandwidth—not just the activated parameter count?
    • Have you calculated total cost on a per-successful-task basis, including caching and retries?
    • If you plan to use FP8 or speculative decoding, have you benchmarked them on your target hardware and workload?
    • Have you recorded the model version, quantization method, and evaluation conditions for later reproduction and comparison?

    The main design patterns in today’s large-scale MoE models fall into four categories: sparse activation to control compute, sparse attention to support long context, multi-stream residuals to widen information channels, and native draft models to improve decoding efficiency. Most of these components have been validated in public research; what matters is how they are combined and how they perform on specific tasks.

    For developers, more valuable than chasing release hype is understanding what bottleneck each design addresses, what it costs, and which scenarios it fits. Only by evaluating and accounting with these questions in mind can you quickly judge, at the next model release, whether it will actually benefit your business.