Sparse Attention and Million-Token Context: A Technical Breakdown of Next-Generation LLM Architectures
This article breaks down the architecture of a new generation of large language models built for long-context and AI agent workloads. It explains the decoupling of total parameters from activated parameters, the shift from dense attention to low-rank compressed sparse attention with reusable indexes, multi-path residual streams, and shared experts. It also covers the engineering implications of 1M-token context, how to evaluate models beyond public leaderboards, and practical guidance on cost, routing, and context governance.
1. From More Parameters to More Effective Compute
A recent wave of open-source large language models targets long-context and agent scenarios. They share three traits: larger total parameter counts, tightly constrained activated parameters per token, and context windows that jump from hundreds of thousands to a million tokens. These are not isolated metrics but expressions of one design philosophy: spend limited compute on the information that the current step actually needs, while keeping inference cost under control.
Two concepts are easy to confuse:
- Total parameters: the model weight size, which determines the upper bound of knowledge capacity and expressiveness, and mainly affects memory footprint and loading cost.
- Activated parameters: the number of parameters that actually participate in computation during the forward pass of each token, which determines the compute cost of a single inference step.
When total parameters grow from about 295B to about 770B (roughly 2.6x) while activated parameters grow only from about 21B to about 49B (roughly 2.3x), knowledge capacity is growing faster than per-step compute. This decoupling of capacity and compute amplifies the gains of the sparse expert approach: most weights stay silent in any single forward pass, and only the few experts selected by the router take part in computation.
2. Three Leaps in Attention: From Dense to Sparse to Reusable Indexes
The real bottleneck for long context is not parameters but the quadratic complexity of attention. The evolution path validated in the industry looks roughly like this:
- Multi-head attention (MHA): the most complete expressiveness, but the highest memory and compute cost.
- Grouped-query attention (GQA) and multi-query attention (MQA): compress the cache by sharing key-value heads; the mainstream approach of the previous generation.
- Low-rank compressed multiplicative attention (MLA-style) combined with sparse selection: first compress keys and values into a low-dimensional latent space, then let a lightweight indexer pick the few positions most relevant to the current query, and run full attention computation only on those positions.
The key engineering detail of the new generation is the combination of sparse selection and index reuse. The execution logic works like this: given a long history context, a lightweight index module first scores all positions and selects roughly the top 2,048 most relevant to the current query, and the main attention processes only that subset. Not every layer repeats this work. For example, all 78 layers enable sparse attention, but only about 21 layers run the full indexer, while the remaining ~57 layers directly reuse the position indexes already selected by earlier layers.
The benefits are explicit:
- Compute: the cost of index scoring is amortized across a few layers, so total cost for long sequences drops from roughly quadratic to nearly linear.
- Cache consistency: multiple layers share the same index, making key-value cache read/write patterns more regular and better suited to batching and paged management.
- Scalability: when context grows from 256K to 1M (about 4x), the incremental cost comes mainly from cache capacity rather than compute.
The pseudocode below is illustrative only and shows the control flow of “index once, reuse across layers”:
# Illustrative control flow only, not any specific implementationdef forward_layer(x, kv_cache, shared_index=None, run_indexer=False):q = project_query(x)if run_indexer:# Lightweight scoring, select top-k relevant positionsshared_index = indexer.score_and_select(q, kv_cache, top_k=2048)# Main attention computes only on the selected positionsattn_out = sparse_attention(q, kv_cache, shared_index)return attn_out, shared_index# Only about 21 of 78 layers recompute the index; the rest reuse itindex = Nonefor layer_id in range(78):x, index = forward_layer(x, kv_cache, shared_index=index,run_indexer=(layer_id in indexer_layers))
3. Multi-Path Residual Streams and Shared Experts
Beyond attention, two structural changes are worth noting.
The first is multi-path residual streams. A traditional Transformer uses a single residual channel, with information stacked layer by layer along one main path. With four residual streams, information at different semantic levels can propagate in parallel and be injected across layers, easing the information bottleneck and gradient coupling of deep networks. The practical effect is that even with slightly fewer layers (for example, 80 down to 78), the model can maintain or even improve the expressive power of effective depth.
The second is the combination of routing and shared experts. The number of routed experts increases from 192 to 256, each token still activates Top-8, and an additional shared expert is introduced. The shared expert carries general knowledge and high-frequency patterns, avoiding duplicated learning of common representations across all routed experts, while routed experts focus on specialized domains to improve parameter utilization. This is the common approach for sparse models to balance capacity expansion with constant compute.
In addition, the draft layer (MTP, multi-token prediction) grows from about 3.8B to about 10B (about 0.7B activated), meaning higher-quality drafts for native speculative decoding, which, together with a larger activation budget, can improve decoding throughput without sacrificing quality. For open precision, official FP8 (such as MXFP8-style formats) is added alongside BF16, providing more direct support for memory and bandwidth optimization on the inference side.
4. What Breaking the 1M Context Barrier Means in Practice
A million-token context is not just about being able to fit more in. The real challenges are effective utilization and cost control:
- Memory and bandwidth: the key-value cache grows linearly with length, and low-rank compression plus sparse selection directly determine how much concurrency a single card can handle.
- Long-document retrieval quality: the recall of the indexer determines whether key information is selected, which requires dedicated evaluation on long-document QA and cross-section reasoning.
- Scheduling and paging: ultra-long sequences typically need paged cache management and prefix reuse to turn hit rate into actual throughput.
- Agent scenarios: multi-turn tool calls and long history accumulation make stable reuse of early context a hard requirement, and the gains from sparse attention plus index reuse are most visible here.
5. How to Read Public Benchmarks Rationally
The reference value of public benchmarks is declining due to data contamination, prompt sensitivity, and overlap between evaluation sets and training distributions. A more reliable approach is to build private evaluation sets close to your own business:
- Scenario tiers: build separate sets for long-document understanding, code generation and repair, structured office output, and scientific computing and data analysis.
- Metric combinations: beyond accuracy, add first-token latency, cost per thousand tokens, long-context recall, and format compliance rate.
- Baselines: include at least the previous generation model and one general baseline to avoid single-point conclusions.
- Regression mechanism: integrate evaluation into continuous integration so regressions run automatically when models or prompts change.
6. Cost and Model Selection: Put Price in Context
To judge whether a model is cost-effective, do not look at unit price alone; look at cost per unit of effective output. A suggested process:
- Clarify the input/output ratio: long-document scenarios have input far exceeding output, so input price carries more weight.
- Account for cache gains: prefix reuse and paged caching can significantly amortize the cost of repeated context.
- Assess sparse gains: when activated parameters are far smaller than total parameters, the compute needed for the same throughput is lower.
- Watch precision options: official low-precision formats can reduce memory and bandwidth pressure, but quality regression must be validated.
Within the same generation, a mid-tier positioning often appears: more expensive than the lightweight version, cheaper than the flagship. A reasonable use for such models is to put the long-context and agent main path on the mid-tier and push high-frequency simple tasks down to the lightweight tier, forming tiered routing that often costs less overall than using the flagship for everything.
7. Implementation Recommendations
- Tiered routing: dispatch by task complexity to models of different sizes, balancing cost and quality.
- Context governance: do retrieval and summarization compression first, then enter long context, instead of blindly filling the window.
- Structured output: use schema constraints and validation retries to ensure format compliance for office and business output.
- Observability: use logging services, monitoring alerts, and tracing to locate latency and failure points in long-context scenarios.
- Elastic scaling: build asynchronous batch processing on container platforms and message queues, separating long tasks from online requests.
- Data and model hosting: use object storage to manage corpora and artifacts, and combine with the general cloud capabilities offered by Baidu AI Cloud for deployment and operations, avoiding coupling to specific proprietary interfaces.
8. Conclusion
The core competitiveness of next-generation long-context models has shifted from “larger parameters” to “less compute per step and more accurate information per layer.” Decoupling total from activated parameters, sparse attention with index reuse, and multi-path residual streams with shared experts together form a reusable technical thread. For developers, success is determined not by leaderboard rank but by three engineering fundamentals: private evaluation, a cost framework, and context governance.
