Sparse MoE and Ultra-Long Context: Architecture Design for Next-Generation Large Language Models

    This article explains the architecture of next-generation large language models that combine sparse Mixture-of-Experts (MoE) with ultra-long context. It covers the numerical problems in linear attention and how KDA addresses them, gated MLA for KV cache efficiency, Attention Residuals for cross-layer information flow, Quantile Balancing for expert load balancing, and a four-stage context extension from 8K to 1M tokens.

    1. Why New Architecture Designs Are Needed

    Multimodal inputs and million-token contexts create two kinds of pressure on a model. First, encoding visual and audio inputs increases sequence length and compute. Second, once parameter counts reach the trillion scale, both training and inference costs rise sharply.

    The inference cost of a dense Transformer grows quickly with parameter count, so Mixture-of-Experts (MoE) has become a common way to increase model capacity. In an MoE model, each token passes through only a few experts. Total parameters are large, but the compute per token stays manageable. As the number of experts grows, however, routing imbalance and expert under-training become more pronounced.

    Linear attention reduces the computation from quadratic to linear in sequence length, but it is not necessarily faster on accelerators such as GPUs. The main reasons are low-precision numerics and parallel efficiency. This article pursues three goals: keep attention at linear complexity while making good use of matrix multiplication units, train sparse MoE models stably at a very low activation ratio, and give the model long-range reasoning ability.

    2. Numerical Issues in Linear Attention and How KDA Handles Them

    2.1 A Hidden Bottleneck in Chunked Computation

    Take Delta Rule-style linear attention as an example. Its state update includes a cumulative decay factor. When the computation is split into chunks, the diagonal blocks require the reciprocal of this decay factor. If the cumulative decay becomes very large, the reciprocal can overflow or underflow in low-precision formats such as BF16.

    A common engineering workaround handles these positions separately with an explicit, position-by-position loop. This keeps the numerics correct, but it adds branches to the compute graph, and the Tensor Core matrix multiplication cannot be fully used on the diagonal blocks.

    2.2 KDA’s Lower-Bounded Decay Parameterization

    KDA (Kimi Delta Attention) is one implementation of linear attention. Traditional log-decay parameterizations, such as those based on a Negative-Softplus transform, have no lower bound. The dynamic range of the decay factor can span several orders of magnitude, which can trigger numerical problems at some time steps.

    According to public materials, KDA changes the decay parameterization to a scaled Sigmoid form with a fixed lower bound. The example lower bound given is -5. This bound limits the range of the reciprocal scaling factor within a chunk, keeping it inside the range that low-precision formats can represent.

    The expected benefits are threefold:

    • Diagonal and off-diagonal blocks can follow the same dense matrix multiplication path, which reduces kernel branches.
    • Matrix multiplication unit utilization is expected to improve.
    • The parameterization enforces numerical safety directly, so the model relies less on runtime clipping.

    The premise of a unified dense kernel is that the lower bound, the precision format (BF16 or FP16), and the kernel implementation meet the design conditions. Public materials do not provide complete throughput comparison data. They also do not explain how the lower bound of -5 was chosen or how the upper bound of the reciprocal factor was derived. Readers should rely on their own test results.

    2.3 Gated Multi-Head Latent Attention and the KV Cache

    In long-context inference, the size of the KV cache directly affects memory usage and throughput. Multi-head Latent Attention (MLA) compresses the KV cache through a low-rank latent representation. Gated MLA adds a learnable gate on top of this design.

    A common position for the gate is after the attention output. The gate score is computed from the current input and mapped to a value between 0 and 1 by a sigmoid. It then scales the attention output channel by channel. The model can therefore reduce the contribution of some channels based on the input content. Whether this mechanism effectively reduces noise in million-token contexts needs to be verified through ablation experiments.

    3. Attention Residuals: A Cross-Layer Information Channel

    In a deep Transformer, local features extracted by shallow layers can be diluted after many nonlinear transformations. Standard residual connections mainly address gradient propagation. They do not provide an explicit channel for information to pass across layers.

    Attention Residuals (AttnRes) add block-level cross-layer connections. These connections let later layers read the attention results of earlier layers, not only their hidden-state outputs. The potential benefits include more stable deep representations, reuse of some attention results, and, under certain parallelism schemes, less communication for the tensors passed between layers.

    When this design is combined with expert parallelism and sequence parallelism, normalization and synchronization overhead must be handled. According to available information, the related scheme controls the extra overhead through its dimension design and normalization strategy. Specific communication volume data has not been published.

    4. Load Balancing and Activation Stability in Sparse MoE

    4.1 Two Problems with Sparse Activation

    According to public materials, one trillion-parameter model has 896 routed experts in total, and each token activates only a single-digit number of them. Its active parameters can therefore be kept at the hundred-billion scale. This design, with large total capacity and sparse activation per token, creates two main challenges.

    The first is routing imbalance. A few experts are selected frequently, while most experts receive almost no tokens, so the effective capacity shrinks. Traditional auxiliary losses can impose balance constraints, but their strength is hard to calibrate. If the loss is too weak, the load stays imbalanced. If it is too strong, it interferes with optimization of the main task.

    The second is expert under-training. Each expert receives few tokens, so the training signal for each expert and the signals for coordinated training are both weaker.

    4.2 Quantile Balancing (QB)

    Quantile Balancing (QB) does not add a balancing term to the loss function. Instead, it adjusts routing decisions during the forward pass. The approach can be summarized in three steps:

    1. Count the load of each expert in the current batch.
    2. Compute quantiles of the loads, and use them as thresholds to separate high-load experts from low-load experts.
    3. Reduce the routing bias for experts above the threshold, and increase it slightly for experts below the threshold.

    The update can be written as b_i ← b_i − γ·sign(L_i − Q_q), where L_i is the load of expert i, Q_q is the q-th quantile, and γ is the step size. This is an illustrative notation for the approach. Public materials do not give the exact formula, so any implementation should refer to the original paper or code.

    QB has two advantages. It adds no loss term. The routing bias affects only expert selection and does not directly change the gradient objective of each expert.

    Two points need attention in practice. First, the number of tokens per batch must be large enough, or the load statistics will be very noisy. Second, the relationship between QB, the capacity factor, and the token dropping policy needs to be confirmed separately.

    4.3 Activation Functions and Gradient Propagation

    Under sparse routing, an expert may receive only a few tokens. If the activation function outputs zero for most inputs, those tokens get almost no gradient updates. The Dead ReLU problem of ReLU-type activations therefore deserves more attention in sparse settings.

    According to available information, the model uses a SiTU-GLU-type activation function, whose output range is bounded. This can prevent variance from being amplified exponentially during deep propagation. Public materials do not yet include a full definition or comparison experiments for this function, so this section reports only its design goal.

    5. Training Strategy: Scaling from 8K to 1M

    5.1 Progressive Context Extension

    Training directly from scratch at 1M tokens is computationally expensive, and the gradient signal for long-range dependencies is sparse. Progressive extension is a more practical approach.

    Public materials describe four stages:

    • Stage 1, 8K context: learns basic semantics and local dependencies.
    • Stage 2, 64K context: introduces medium-range dependencies.
    • Stage 3, 256K context: strengthens document-level dependencies.
    • Stage 4, 1M context: trains ultra-long context capability.