Rebuilding LLMs for Million-Token Contexts: Architecture and Engineering Practices
This article examines how a trillion-parameter, sparse mixture-of-experts model was architected to support a default one-million-token context window efficiently. It explains why long context is essential for multi-turn agents, repository-level code understanding, and long-document tasks; breaks down the system redesign across attention, expert routing, and kernel or memory optimizations; and outlines practical strategies for balancing cost and performance, along with deployment limitations and selection guidance.
Rebuilding LLMs for Million-Token Contexts: Architecture and Engineering Practices
1. Introduction: A Capability Leap Without a Warm-Up
In late April 2026, an open-source model series released a preview version and opened its weights at the same time. Two numbers on the spec sheet stood out: total parameters in the trillion range and a default context window of one million tokens. In evaluations, it placed in the top tier across coding, math, agentic tasks, and long-text understanding, approaching the level of the leading closed-source models.
What deserves repeated reading by engineering teams is not the leaderboard ranking, but the technical report released alongside the weights. The report’s title itself signals the focus: an efficient million-token context intelligence. The emphasis is not on how much text can be stuffed in, but on whether the model still runs and remains affordable once the context is that long.
Before diving into the technical details, two common misconceptions need to be cleared up:
- The smaller version is not a distilled product of the larger one. Both model tiers are independently pretrained sparse expert models. They differ only in total parameters and activation ratio, and their training data mixes and scheduling strategies are independent as well.
- Long context is not a toggleable option. Both tiers support a million-token window by default. The serving side no longer maintains separate routing for “long-text models” and “short-text models,” which directly simplifies the dispatch logic of the inference gateway.
The typical specs of the two versions can be summarized as follows:
| Tier | Total Parameters | Activated Parameters per Token | Default Context |
|---|---|---|---|
| Large | ~1.6T | ~49B | 1M |
| Small | ~284B | ~13B | 1M |
The key engineering implication is this: total parameters determine the “stock cost” of memory and bandwidth, while activated parameters determine the “flow cost” per token. A trillion total parameters paired with 49B activated parameters means model capacity and inference compute are decoupled. This is the first pillar that makes the whole design work.
2. Why Million-Token Context Is Necessary
Early discussions of long context often raised the objection that “a few thousand tokens are enough for ordinary conversations—is this just another round of the parameter arms race?” That objection basically disappeared once the team actually deployed an open-source agent framework as a personal assistant. Three types of scenarios are the main consumers.
Scenario 1: Multi-Turn Agent Tasks
A coding agent running for 30 turns appends the following to the context each turn: user instructions, several source files, command execution results and standard output, and the model’s own reasoning traces. Each item ranges from thousands to tens of thousands of tokens, and 30 turns easily accumulate into hundreds of thousands of tokens. The previous generation of models discarded the historical chain of thought when a new message arrived. That was not a design preference but a passive trade-off under capacity constraints—there was no room to keep it.
Scenario 2: Repository-Level Code Understanding
A medium-sized project with hundreds of files and over a hundred thousand lines of code tokenizes to roughly 800,000 to 1.2 million tokens. For cross-file refactoring, interface consistency checks, or full dependency mapping, a 128K window can only cover part of the code. The model is forced to answer without seeing everything, and the hallucination rate rises accordingly.
Scenario 3: Long Documents and Persistent Memory
Contract review, log troubleshooting, long meeting notes, and an agent’s long-term memory store all share one trait: a single input already exceeds the window. For these tasks, the core metric is not time to first token but information recall accuracy in the middle and tail sections of an extremely long input.
The conclusion is clear: long context is not a marketing parameter but a prerequisite for agents to move from “toy” to “trustworthy.”
3. Three Layers of System-Level Rebuilding
The truly hardcore part is the layer-by-layer rework from the attention mechanism to compute kernels. It can be broken down into three layers.
3.1 Attention: Decoupling from Quadratic Complexity
Standard full attention grows quadratically in compute and memory with sequence length, which is unacceptable at one million tokens. The mainstream industry approach combines sparsification and hierarchical design:
- Sparse attention patterns: Replace global attention with a combination of local windows and a few global anchors, pushing complexity back to near-linear.
- Multi-stage compression: First compress long history at the block level, then apply attention over the compressed representations, preserving backbone information and discarding redundant details.
- Positional encoding extrapolation: Adjust the base frequency and scaling strategy of rotary positional encodings so that a shorter window used in training can extrapolate stably to longer ranges during inference.
Engineering-wise, the cost must be acknowledged: sparsification sacrifices some “direct connection between any two points” capability. This requires targeted compensation for retrieval-type tasks, such as keeping a few high-bandwidth global channels.
3.2 Sparse Experts: Decoupling Capacity from Compute
A trillion parameters cannot be fully activated, so the design uses fine-grained expert partitioning plus a routing mechanism, activating only about 3% of the parameters per token. This brings three direct benefits:
- Compute per token drops, flattening the compute curve for long sequences.
- Experts can be distributed across different devices, shifting memory pressure from “fitting on a single card” to “carried by a cluster.”
- Capacity growth is decoupled from latency growth; scaling mainly means adding devices rather than changing the model.
The cost is uneven routing load and expert-parallel communication overhead, which need to be managed with standard techniques such as capacity factors, load-balancing losses, and redundant experts.
3.3 Kernels and Memory: Turning Theoretical Efficiency into Actual Throughput
This layer is the least visible but the most decisive for the bill:
- Fused operators: Combine attention, normalization, activation, and other steps to reduce memory round trips.
- Paged key-value cache: Chunk the cache and allocate on demand; with prefix reuse, multi-turn conversations and shared system prompts are computed only once.
- Quantization and low-precision storage: Store weights and cache at lower bit widths, trading a controllable amount of precision for several times the capacity.
- Pipeline parallelism and overlapped scheduling: Overlap communication with computation to hide the synchronization waits of expert parallelism.
The following is a schematic capacity estimation logic (showing only order-of-magnitude relationships, not specific product data):
# Rough estimate of key-value cache memory usage (in bytes)def kv_cache_bytes(layers, kv_heads, head_dim, seq_len, batch, bytes_per_elem=1):# 2 = two copies for key and valuereturn 2 * layers * kv_heads * head_dim * seq_len * batch * bytes_per_elem# Order-of-magnitude demo for one million tokens, single requestprint(kv_cache_bytes(layers=60, kv_heads=8, head_dim=128,seq_len=1_000_000, batch=1) / 1024**3)
The formula shows that the key-value cache grows linearly with sequence length and often exceeds the weights themselves, becoming the primary bottleneck. Therefore, paged reuse and low-precision storage are not optimization items but prerequisites for feasibility.
4. Balancing Performance and Cost
Long-context capability ultimately has to land on an operable service. The recommended order of progression is:
- Tiered routing: First use a small window for fast responses, and escalate to the long window only when the small window is insufficient, avoiding full-price payment for every request.
- Prefix cache reuse: Force stable content such as system prompts, tool definitions, and code repository indexes through the cache.
- Context compression: Summarize historical reasoning traces, keeping conclusions and key evidence while discarding process noise.
- Retrieval and long-window collaboration: First use retrieval to narrow the candidate set, then hand it to the long window for global consistency judgment.
- Observability: Build monitoring and alerts for token distribution, cache hit rate, and mid-section recall accuracy, and drive tuning with data.
If built on general cloud capabilities, a relatively stable combination is to use a container platform to host the inference cluster, object storage for weights and datasets, a message queue for request peak shaving, and logging plus monitoring and alerting services for observability.
5. Limitations and Selection Guidance
Three limitations need to be stated objectively: sparse attention still incurs losses on tasks that require precise association between any two points; the deployment threshold for trillion-scale weights is high, so small and medium-sized teams are better off starting with a smaller tier; and the preview version still needs continued refinement in tool-call stability and tail-section recall for extremely long inputs.
For selection, if the task is repository-level refactoring, long-document review, or long-cycle agents, the benefits of a long window far outweigh the cost. If short conversations dominate, prioritize optimizing the cache and routing rather than blindly pursuing the maximum window size.
6. Conclusion
The core conclusion of this round of technical evolution is a single sentence: long context is systems engineering, not a single-point parameter. Attention sparsification solves feasibility, sparse experts solve economics, and kernel and memory management solve deployability. Without any one of the three, a million tokens is just a poster. For developers, understanding these three layers is more valuable than memorizing any leaderboard ranking.
