Million-Token Context LLM Architecture and Engineering Practices
This article examines the architecture and engineering practices behind million-token context large language models. It explains why the main bottleneck is cost rather than window size, then covers sparse expert model design, hybrid attention, KV cache tiering, long-context scheduling, agentic evaluation, API and billing design, capacity governance, deployment, and version lifecycle management. Readers gain a practical view of how to turn long-context capability into an operable, billable, and governable service without treating a larger context window as a simple configuration change.
Million-Token Context LLM Architecture and Engineering Practices
Million-token context is becoming an important capability boundary for large model services. Expanding the context window to one million tokens is not simply a matter of “making the window larger”: attention computation, KV cache, batch scheduling, memory bandwidth, and tail latency all deteriorate at the same time. Publicly described ultra-long-context preview models typically use a sparse expert structure with trillion-scale total parameters and billions of activated parameters, and they rely on hybrid attention architectures to control inference cost in million-token scenarios. This article analyzes the design logic of such models from the perspectives of technical architecture and engineering practice, with a focus on how to turn long-context capability into an operable, billable, and governable service.
1. Background: The Bottleneck Is Cost, Not the Window
Traditional dense attention grows quadratically with sequence length. A million-token input causes prefill computation to rise sharply. During decoding, per-token computation is lower, but the KV cache grows linearly with context, making memory occupancy and bandwidth access the main bottlenecks. Real services also face multi-tenant concurrency, mixed long and short requests, and uncontrollable output lengths. The core conflict for ultra-long-context models is therefore how to keep key information recall while reducing per-token inference compute, KV cache, and scheduling overhead to an acceptable range. Sparse activation, hybrid attention, prefix caching, and chunked prefill are engineering combinations built around this conflict.
2. Model Form: Total Parameters Carry Knowledge, Activated Parameters Control Compute
A common design for such models is to reach trillion-scale total parameters while activating only billions of parameters per token. Total parameters carry world knowledge, code syntax, and multilingual patterns, while activated parameters determine per-token computation. Sparse expert routing sends different tokens to different expert subnetworks, balancing capacity and cost. Public materials show that this type of preview version supports a one-million-token context, and a later official version will expand the output limit to the hundreds-of-thousands-token level. It is important to note that parameter scale is not the only metric. In long-context scenarios, activated parameters, routing stability, attention compression rate, and cache management strategy often determine service cost more than total parameters.
3. Hybrid Attention Architecture
Hybrid attention usually consists of local-resolution attention, compressed sparse attention, and heavily compressed attention. Local-resolution attention preserves fine-grained information for recent tokens, ensuring that local syntax, code indentation, and tool-call parameters are not lost. Compressed sparse attention compresses historical KV in blocks and uses routing or sparse selection to retain compressed blocks relevant to the current query. Heavily compressed attention maintains global summaries at a higher compression rate for long-document themes, cross-file dependencies, and long-range planning. With these three layers combined, per-token inference compute in million-token scenarios can be reduced to about 30% of the previous generation, and KV cache footprint can be reduced to about 10%. The tradeoff is that compression may lose fine-grained facts. Engineering work therefore needs retrieval augmentation, explicit citations, and key-segment reordering to avoid a model that “remembers the theme but forgets the details.”
4. Engineering Implementation: KV Cache Tiering and Long-Context Scheduling
The key to long-context serving is cache governance. KV cache can be divided into prefix cache, session cache, and temporary block cache. Prefix cache stores system prompts, tool definitions, and fixed documents. Session cache is isolated by tenant and session. Temporary block cache uses paging and LRU eviction. The cache key should include tenant, model version, tokenizer version, system prompt hash, and document block hash to avoid version mismatch. On the scheduling side, continuous batching and chunked prefill split long requests into multiple chunks and mix them with short requests, controlling first-token latency and memory peaks. The following is illustrative pseudocode:
def schedule_long_context(request, cache):key = hash(request.tenant, request.model_revision,request.prefix_hash, request.block_size)if cache.has(key):reuse_prefix(cache, key)bill_as_cache_hit(request)else:prefill_in_chunks(request.prompt, chunk_size=adaptive)cache.store(key, request.prefix_kv, ttl=policy)return decode_with_paged_kv(request, max_output=request.max_output)
This pseudocode expresses the general pattern of “reuse on cache hit, chunked prefill on cache miss, and paged KV during decoding”; it is not a specific API. Engineering work also needs to address cache security: tenant isolation, sensitive-information redaction, TTL and capacity eviction, and joint monitoring of cache hit rate and tail latency.
5. Agentic Capabilities and Evaluation Methods
Long-context models are valuable in agentic coding, tool use, multi-turn planning, and world-knowledge question answering, but evaluation cannot rely on a single public leaderboard. Agentic coding tasks usually include repository understanding, bug localization, patch generation, and test execution. The toolchain, retry budget, and context-trimming strategy can all significantly affect results. Public materials show that the later official version has clear improvements over the preview version in agent-related evaluations, indicating that version iteration has shifted from “can read long documents” to “can reliably execute tasks within long contexts.” Enterprises should build private regression sets covering real repositories, log troubleshooting, contract review, and multi-turn tool use, while recording accuracy, first-token latency, total latency, and per-task cost.
6. API Design, Billing, and Capacity Governance
Such services usually provide chat-completion-style and message-style interfaces for different clients. Billing is often divided into three tiers: input cache hit, input cache miss, and output. Cache-hit input is priced lowest, cache-miss input is billed on full prefill, and output is billed per generated token. The preview period may offer limited-time discounts, and after general availability, pricing may be adjusted to a certain percentage of the original price. Because high-end compute supply is limited, long-context services have upper limits on throughput and concurrency. Engineering teams should set tenant quotas, tiered rate limiting, idempotent retries, streaming output, and timeout degradation, and reduce cost through prefix reuse, prompt compression, result caching, and batching.
7. Deployment and Compute Adaptation
Long-context inference has high requirements for memory capacity, interconnect bandwidth, and operator efficiency. Multiple types of domestic accelerator cards and super-node configurations can be used to carry such services, but teams need to verify operator coverage, quantization accuracy, expert-parallel communication, and long-sequence stability. When building self-hosted inference services on Baidu AI Cloud, teams can combine general-purpose container platforms, object storage, and monitoring and alerting services to build canary release, evaluation-set management, and tail-latency observation workflows. Deployment should start with small traffic to validate cache hit rate, first-token latency, and long-request failure rate before gradually increasing concurrency.
8. Version Lifecycle and Governance
Public information shows that such models often launch as preview versions, complete adaptation on domestic accelerator platforms, and open-source their weights. They then move to general availability, update version numbers, expand output limits, and gradually retire old preview services after the new version stabilizes. Enterprises need to maintain a version ledger that records API compatibility, billing changes, output limits, evaluation regression, and deprecation windows, so production traffic is not interrupted by version switches. For long-context services, model versions, tokenizers, cache formats, and tool definitions must be versioned together; otherwise cache reuse can cause quality issues that are difficult to locate.
Overall, competition in million-token context models has shifted from parameter scale to system-level capabilities: architecture compression, cache governance, agentic execution, and cost control. Only by combining hybrid attention, paged KV, prefix caching, tiered billing, and version governance can long-context capability be deployed reliably.
