Ultra-Long Context LLMs: Architecture Redesign and Engineering Practice
Supporting a long context window is not the same as performing stably and cheaply on it. This article covers how ultra-long context LLMs are being redesigned across sparse mixture-of-experts (MoE) architecture, dynamic sparse attention, joint training and inference optimization, serving systems, and agent reinforcement learning. It also outlines criteria for evaluating these models.
1. Why Ultra-Long Context Requires a Full-Stack Redesign
Large language model context windows have grown from tens of thousands of tokens to the million-token range. Developers have quickly found that supporting a long context and delivering stable, low-cost performance on it are two different things. Scaling parameters on an existing architecture only adds capacity. When context length grows from roughly 200K to 1M tokens, attention computation, memory use, and inference latency all degrade, roughly quadratically or linearly. The theoretical capability does not translate into production usability.
As a result, leading engineering teams are moving toward a full-stack redesign for long-horizon tasks. Instead of treating long context as an isolated feature, they advance four areas at once: sparse architecture, joint training and inference, inference serving systems, and agent reinforcement learning. This article breaks down that engineering system based on publicly documented technical approaches.
A commercially viable ultra-long context solution typically has the following characteristics. It uses a large-scale sparse MoE architecture to limit compute per token. It uses dynamic sparse attention (DSA) to cut wasted computation in long-sequence attention. It applies multi-token prediction (MTP) with speculative decoding at inference time. It also introduces long-sequence adaptation during training rather than patching the inference side afterward. In the open-source community, some frontier models have released their weights under permissive MIT-style licenses, which allow private deployment and further fine-tuning. This removes licensing barriers for enterprise adoption.
2. Core Architecture Innovation 1: Sparse MoE and Per-Token Compute Control
2.1 The Engineering Value of Sparse Activation
In dense models, inference cost is tightly coupled to total parameter count. Doubling parameters roughly doubles inference cost. Sparse MoE architectures replace the feed-forward network with many expert subnetworks, and each token is routed to only a few of them. This keeps total parameter scale very large while holding the number of activated parameters per token within an acceptable range. In publicly documented practice, a common configuration has total parameters in the hundreds of billions, with tens of billions activated per token. The activation ratio falls between 5% and 10%.
This large-capacity, low-activation design matters especially for ultra-long context. Long-text inference is autoregressive, producing one token at a time. Fewer active parameters mean fewer FLOPs per decoding step, which keeps the total inference cost of million-token workloads manageable.
2.2 Additional Challenges of MoE in Long-Context Settings
MoE is not free. Load balancing across experts, communication overhead in expert parallelism, and expert caching strategies for long sequences all significantly affect real throughput. In practice, teams typically combine the following techniques:
- Auxiliary losses or routing constraints: Prevent a few experts from becoming overloaded, which can cause collapse and long-tail latency.
- Hybrid expert and tensor parallelism: Reduce the share of cross-device communication in multi-device deployments.
- Popularity-aware grouping: Place experts that are frequently activated together on the same compute node.
3. Core Architecture Innovation 2: Dynamic Sparse Attention and Cross-Layer Index Reuse
3.1 The Hidden Cost of Conventional DSA
Dynamic sparse attention selects the top-K most relevant key-value pairs for each query token at each layer. This reduces complexity from quadratic to near-linear. However, index computation itself carries overhead. Every Transformer layer independently computes query-key dot-product scores, sorts them, and applies top-K selection. At million-token scale, per-layer index computation becomes a new bottleneck. Attention compute drops, but the cost shifts to the indexing stage.
3.2 Cross-Layer Index Reuse
A typical optimization for this problem is cross-layer index sharing. Within a group of consecutive layers, only the first layer runs a lightweight indexer and extracts the top-K attention indices. The subsequent layers reuse these indices directly and skip repeated dot-product scoring and selection. The rationale is that attention distributions in adjacent layers are highly correlated. Index reuse therefore has a controllable effect on model accuracy while saving substantial compute.
The benefits are twofold. First, attention-related FLOPs per token drop by a large factor. Public technical materials have cited reductions approaching 3x, though the exact figure depends on how many layers share an index and on the indexer design. Second, the intermediate memory used for index computation shrinks considerably, which eases memory pressure on long sequences.
3.3 Introduce It During Training, Not as an Inference Patch
An important engineering decision is easy to overlook. Index reuse should be introduced in the middle of training, for example when the sequence length is extended to around 100K tokens. This lets the model learn to adapt to reused indices during training. If cross-layer reuse is enabled only at inference time, the model encounters attention patterns it never saw during training, and its long-text comprehension can degrade noticeably. This reflects a general principle: long-context capability must come from base model training, and inference-side optimizations can only add incremental gains.
4. Inference Acceleration: Combining MTP Speculative Decoding with KV Cache Sharing
4.1 Multi-Token Prediction for Speculative Decoding
Autoregressive decoding runs serially, one token at a time, and it is a major source of latency in long-context inference. With multi-token prediction (MTP), the model predicts several subsequent tokens in a single forward pass. The main model then verifies these drafts in parallel, and the verified tokens are accepted together. The key metric is the average acceptance length of speculative decoding. Each additional accepted token reduces the number of end-to-end decoding steps. Publicly available material reports that an optimized MTP configuration raised the average acceptance length from about 4.5 to about 5.5, which yields roughly a 20% improvement in overall inference performance.
4.2 KV Cache Sharing
If the MTP draft head and the main model, or different layers, each maintain separate KV caches, memory usage becomes unmanageable at long sequence lengths. KVShare-style mechanisms let the draft model share the same key-value cache with the main model and reuse intermediate results across layers. As a result, predicting one more token adds almost no mem
