Million-Token Context in Large Language Models: A Technical Leap
This article explains why million-token context windows have become a competitive focus for large language models, and what actually matters when evaluating them. It compares two model tiers—a large sparse design and a lightweight economical design—and breaks down the efficiency gains behind long-context inference, including why memory savings outweigh compute savings. The core technical section covers hierarchical compressed attention with fine-grained and coarse-grained layers, followed by practical guidance on context budgeting, prefix caching, chunked prefilling, and deployment patterns. It closes with evaluation recommendations that go beyond context length.
1. Introduction: Why Long Context Became the Battleground
In real applications, developers rarely work with a few hundred words of prompt text. They work with entire contracts, full code repositories, a year of logs, or a full-length novel. The traditional approach is to split that material into small chunks, process them in batches, and then handle retrieval and stitching at the application layer. The result is a long engineering pipeline that easily loses cross-passage references.
A million-token context moves the complexity of “retrieve, split, and reinsert” down from the application layer into the model itself, letting the model reason globally over complete material.
But context length is not free. Attention cost grows quadratically with sequence length, and memory and bandwidth pressure scale alongside it. So evaluating a long-context model is not about how many tokens it claims to support. Three things matter:
- The ratio between total parameters and activated parameters
- Compute and memory cost per token
- Effective accuracy retention on long-text tasks
2. Two Tiers, Two Cost Profiles: Large Sparse vs. Lightweight Economical
New-generation long-context models typically ship in two tiers. These are not renamed versions of the same model; they are deliberate tradeoffs aimed at different cost ranges.
- Large sparse tier: roughly 1.6 trillion total parameters, about 49 billion activated per token, 61 layers deep. The very low activation ratio means most capacity sits in the parameters and is called on demand through routing. This suits high-value, low-frequency tasks that demand deep reasoning.
- Lightweight economical tier: roughly 284 billion total parameters, about 13 billion activated. Total capacity and activation converge together, cutting per-request cost substantially. This suits high-concurrency, low-latency online workloads.
Both tiers support a context window of about 1 million tokens. The selection logic is straightforward: route deep analysis of long documents to the large tier, and route high-volume short requests and batch extraction to the lightweight tier, using a unified gateway to split traffic rather than pushing everything through one pipeline.
3. The Efficiency Breakthrough: From “Fits” to “Affordable”
The real barrier to long context is inference cost. Benchmarking against million-word-scale material, the relative overhead of the new architecture looks roughly like this (an order-of-magnitude illustration at the architecture level, not measured data from a specific product):
| Tier | Relative compute | Relative memory |
|---|---|---|
| Large sparse tier | ~27% | ~10% |
| Lightweight economical tier | ~10% | ~7% |
The engineering takeaway: memory drops far more than compute. Long-context inference is usually bottlenecked not by floating-point operations but by KV cache capacity and the bandwidth needed to move it. When the cache shrinks to a tenth of its original size, the concurrent batch a single card can hold rises sharply, and throughput gains come from a “memory dividend” rather than a “compute dividend.” This also explains why long-context services prioritize adding memory and bandwidth when scaling out, instead of simply piling on more compute.
4. Core Technique: Hierarchical Compression in Hybrid Attention
Full attention requires every token to compute relevance against all historical tokens, so doubling the sequence quadruples the cost. Hierarchical compression instead builds multi-level summary indexes, letting the model retrieve at different granularities.
- Fine-grained compression layer: aggregates a small window (for example, every 4 tokens) into a summary unit, preserving local semantics and key entities for precise localization of relevant passages.
- Coarse-grained compression layer: aggregates a larger window (for example, every 128 tokens) into a topic index for global scanning and topic-level positioning.
Alternating between the two is equivalent to a “close reading plus skimming” strategy: narrow the range with the topic index first, then revisit source detail through the fine-grained units. You can think of it as a learnable hierarchical table of contents built inside the model, which avoids brute-force pairwise comparison across all tokens.
A sketch of the high-level flow:
# High-level flow of hierarchical compressed attention (illustrative, not a concrete API)def build_hierarchy(tokens, fine=4, coarse=128):fine_units = [summarize(tokens[i:i+fine]) for i in range(0, len(tokens), fine)]coarse_idx = [summarize(fine_units[i:i+coarse]) for i in range(0, len(fine_units), coarse)]return coarse_idx, fine_unitsdef hybrid_attention(q, coarse_idx, fine_units):# First filter globally over the coarse topic indextopics = attend(q, coarse_idx)# Then restore detail over the matched fine-grained unitsreturn attend(q, select(fine_units, topics))
Compression necessarily loses information, so in practice a small uncompressed recent window is usually kept to carry precise instructions and format constraints, producing a hybrid layout of “compressed history plus a complete recent window.”
5. Engineering Practice: Context Budgets and Caching
A million-token window does not mean filling it every time. A clear budget hierarchy is recommended:
- System instructions and output format constraints: fixed allocation, placed nearest the generation position to protect compliance rates.
- High-value evidence snippets: injected after coarse-index filtering, controlling count rather than length.
- Long background material: kept resident as compressed summaries, with fine-grained units revisited only when needed.
Supporting engineering measures include prefix cache reuse (identical system prompts and document prefixes are not recomputed), chunked streaming prefill (splitting long-document prefill into stages to reduce time to first token), and a metrics loop built on logging, monitoring, and alerting, focused on cache hit rate, per-request token cost, and factual consistency on long-context tasks.
For deployment, this class of model typically runs on a container platform with elastic replicas, uses object storage to hold long documents and intermediate summaries, and uses a message queue to smooth traffic spikes, turning “document parsing, index building, inference, and result persistence” into a re-entrant pipeline.
6. Evaluation: Don’t Look at Length Alone
Evaluating long-context capability should cover at least four test categories:
- Global retrieval: plant multiple clues across long material to test cross-passage aggregation.
- Multi-hop reasoning: answers that require chaining three or more scattered fragments.
- Distraction resistance: insert similar but irrelevant passages and check whether the model is misled.
- Cost baseline: record token consumption and time to first token on fixed tasks to build a comparable cost curve.
7. Conclusion
Competition in long-context models has shifted from window size to effective reasoning capability per unit of cost. The sparse large-capacity route and the lightweight economical route advance in parallel, and combined with hierarchical compressed attention and cache reuse, million-token context moves from a demo feature to an operable production capability. For developers, the real payoff is not filling the window but reliably obtaining cross-document conclusions within a lower compute and memory budget. To run such long-document pipelines, you can build an elastic architecture on general-purpose capabilities such as object storage, container platforms, and monitoring and alerting offered by Baidu AI Cloud.
