Ultra-Long Context Sparse LLMs: Architecture Design and Training Stability
This article explains the main engineering challenges of building large language models that combine large parameter counts, long context windows, and long-horizon reasoning. It covers sparse Mixture-of-Experts activation, numerical stability in chunked linear attention with bounded log-decay, block-level attention residuals for cross-layer information reuse, and auxiliary-loss-free load balancing for MoE routing.
1. Background: Bottlenecks When Scale, Context Length, and Reasoning Improve Together
Three paths to better LLM capability (parameter scale, context length, and long-horizon reasoning) constrain one another. As parameter count grows, the cost of each forward pass in a dense model grows linearly. Mixture-of-Experts (MoE) architectures decouple total parameter count from per-token compute by activating only a small subset of experts for each token. As context grows, the compute and memory cost of standard self-attention grows quadratically with sequence length. Agent applications also require the model to keep its goal consistent across dozens of tool-calling rounds, which places higher demands on reinforcement learning in the post-training stage.
Each of these three problems has well-established mitigations. When they are combined in a single model, however, numerical stability and communication overhead at each step amplify one another. The sections below analyze the key technical points in order, from low-level operators to training strategies.
2. Sparse Activation: Trade-offs Between Total and Active Parameters
The key metric for MoE is the activation ratio, which is the proportion of active parameters to total parameters. Take a publicly disclosed trillion-scale sparse model as an example. It has about 2.8 trillion total parameters and about 104 billion active parameters, an activation ratio of under 4%. Per-step compute at inference is therefore close to that of a dense model with tens of billions of parameters, while its knowledge capacity is far larger.
Higher sparsity makes training harder, mainly in three ways:
- Uneven expert load. Some experts are rarely selected, so their parameters cannot be trained adequately.
- Routing decisions are sensitive to numerical error. Small fluctuations can cause frequent expert switching and oscillations in the loss curve.
- Communication overhead grows with the number of experts and the distributed partitioning scheme, so it must be designed together with the parallelism strategy.
More experts are not always better. In practice, teams must balance expert granularity, the number of experts activated per token, and communication bandwidth.
3. Numerical Issues in Linear Attention and Bounded Log-Decay Parameterization
Linear attention replaces softmax with a decomposable kernel function or a decay mechanism, which reduces computational complexity to linear in sequence length. During training, it is usually computed in parallel by chunks. Within each chunk, the causal computation is exact. Across chunks, information passes through state recurrence.
Within-chunk computation has a common pain point. Decayed linear attention normalizes using the reciprocal of the cumulative decay factor. When the decay factor approaches zero, its reciprocal can overflow in low-precision formats such as BF16, and the products can underflow to zero. To avoid these risks, many implementations handle diagonal blocks separately. Diagonal blocks contain interactions between adjacent tokens within a chunk, and these implementations process them with a scalar path over position pairs instead. Because diagonal blocks then cannot use dense matrix-multiplication units, overall throughput drops noticeably.
One approach is to limit the range of the log-decay, converting an unbounded parameterization into a bounded one. An illustrative example follows:
import torchdef bounded_log_decay(raw: torch.Tensor, g_min: float = -5.0) -> torch.Tensor:# Map the raw output to the (g_min, 0) interval so that each step's decay factor falls within (e^g_min, 1)return g_min * torch.sigmoid(raw)
With a bounded interval, the cumulative decay within a 16-token block has a deterministic lower bound, and its reciprocal scaling factor also falls within the representable numerical range. As a result, all tile types, both diagonal and off-diagonal, can use the dense matrix-multiplication path uniformly, without a special branch for diagonal blocks.
This approach offers three benefits:
- Operator implementation is more uniform, which reduces kernel branches and maintenance cost.
- Diagonal and off-diagonal blocks have consistent throughput, which improves overall hardware utilization.
- Handling of sequence position information is simpler, which makes extrapolation to longer sequences easier.
The lower bound also limits how quickly the model can forget within a single step. For this reason, g_min must be chosen through ablation experiments specific to the task. Numerical stability alone is not enough to select it.
4. Block Attention Residuals: Cross-Layer Information Reuse
In deep Transformers, information passes from layer to layer through residual additions. As depth increases, later layers tend to be dominated by the accumulated sum of early representations. A fixed-weight aggregation scheme limits the expressive power of deep layers.
The block attention residual approach divides the network into several blocks. The input to each block is computed by attention-weighting the summary representations of earlier blocks, rather than by simple addition. In this way, deeper layers can selectively read features from shallower layers.
This design has two more engineering benefits. First, block-level summaries require fewer intermediate activations to be stored, which reduces memory pressure. Second, cross-device communication can happen at block granularity, which reduces the number of per-layer synchronizations. The block size must balance expressive power against communication frequency. Larger blocks mean less communication but coarser information selection within each block.
5. MoE Load Balancing: Moving Beyond Auxiliary Losses
The traditional approach adds an auxiliary load-balancing loss term to the training objective. The weight of this term is hard to tune. If the weight is too large, the term interferes with the language modeling objective. If it is too small, expert load remains skewed.
Another class of methods adjusts routing biases directly. The core idea is to track the share of tokens each expert has recently received, then adjust its bias based on where that share sits in the overall distribution, for example relative to its quantiles. Overloaded experts get a lower bias, and underloaded experts get a higher one. Because this approach adds no extra loss gradient, the language modeling objective is not disturbed.
Implementation requires attention to the following:
- The statistics window must be long enough to avoid oscillations caused by small-batch noise.
