Long-Context LLMs at the Million-Token Scale: Technical Evolution and Engineering Practices

    This article explains why million-token context windows have become an engineering threshold for large language models, and what it takes to serve them affordably. It covers the two core bottlenecks—quadratic attention cost and linearly growing KV cache—and how hybrid attention designs combine compressed sparse attention with heavy-compression attention to cut per-token compute and cache usage. It also reviews capability areas that determine real usability (agents and coding, world knowledge, and reasoning), breaks down the three-part pricing model for long-context serving, and shows how cache hit rate becomes the main cost lever through stable prefixes. Finally, it addresses interface compatibility, adaptation to domestic accelerators, and a practical deployment checklist covering rate limiting, monitoring, and provider portability.

    1. Why “Million-Token Context” Became a New Engineering Threshold

    Over the past two years, the focus of LLM competition has shifted from parameter count to effective context window. The reason is straightforward: real workloads such as repository-level code understanding, long-document review, and multi-step AI Agent task chains all require the model to see enough information in a single pass. But once the context grows from tens of thousands of tokens to one million, the question is no longer whether the content fits. It is whether the compute bill and GPU memory can absorb it.

    Two bottlenecks are widely recognized. First, the computational complexity of attention grows quadratically with sequence length. Second, the KV (Key-Value) cache expands linearly with sequence length, consuming GPU memory directly and limiting how many requests a single card can serve concurrently. As a result, a usable million-token context solution must answer the question at two layers at once: the algorithm architecture and the serving engineering.

    2. Hybrid Attention: The Core Idea for Cutting Long-Context Cost

    A typical approach among recently published technical routes is a hybrid attention architecture that combines different attention mechanisms by layer or by block:

    • Compressed sparse attention: historical tokens are first compressed and filtered so that only the segments most relevant to the current query participate in computation, bringing the quadratic cost back to near-linear.
    • Heavy-compression attention: remote history is modeled at a coarse granularity with a higher compression ratio, preserving long-range semantics and topic consistency.

    The engineering value of this combination is that it allocates the “accurate but expensive” and “cheap but coarse” paths according to need. Paired with a sparsely activated expert structure (for example, a design with 1.6T total parameters and roughly 49B activated per token), the model can retain knowledge capacity while each forward pass goes through only a small subset of parameters.

    The effect is quantifiable in public data: in million-token context scenarios, per-token inference floating-point operations can drop to about 27% of the previous generation in the same series, and KV cache usage is about 10%. For developers, these two numbers mean a change of order of magnitude in the concurrency the same batch of GPUs can carry.

    An illustrative capacity estimation logic (not a specific product interface):

    1. # Rough estimate of memory and compute pressure for long-context inference
    2. def estimate(kv_bytes_per_token, ctx_len, concurrency, flops_per_token):
    3. kv_total = kv_bytes_per_token * ctx_len * concurrency
    4. flops = flops_per_token * ctx_len * concurrency
    5. return {"kv_gb": kv_total / 1024**3, "flops_tflops": flops / 1e12}
    6. # After compression, per-token cache and compute drop significantly; swap the coefficients to compare
    7. print(estimate(kv_bytes_per_token=8, ctx_len=1_000_000, concurrency=8, flops_per_token=2_000))

    3. Capability Dimensions: Agents, World Knowledge, and Reasoning

    A long context is only the entry ticket. What truly determines usability is three categories of capability:

    1. Agent and coding ability. On evaluations targeting real repository-level bug fixes, leading open-source models already reach a pass rate of around 80 or above, approaching the threshold of “a patch that can be adopted directly.” This requires long-range dependency tracking, tool calling, and multi-step planning.
    2. World knowledge. Open-source models still trail top closed-source models slightly in knowledge breadth, but in most enterprise scenarios retrieval augmentation can close the gap.
    3. Reasoning performance. On math, science and engineering, and competition-style programming tasks, first-tier open-source models now rival top closed-source models, showing that the view “open source is not enough for hard problems” is outdated.

    4. Cost Structure: Understanding Cache Hits and Tiered Pricing

    Billing for long-context serving is typically split into three parts: input that hits the cache, input that misses the cache, and output. For one product series during a limited-time promotion, the published magnitudes were about CNY 0.025 per million tokens for cache hits, about CNY 3 per million tokens for cache misses, and about CNY 6 per million tokens for output, with pricing adjusting to one quarter of the original rate after the promotion ends.

    The direct takeaway for developers is that the cache hit rate is the cost lever. Fixing stable prefixes—system prompts, tool definitions, repository indexes—at the very front lets repeated requests hit the cache in large numbers.

    1. # Improve cache hits with a stable prefix to lower long-context cost
    2. SYSTEM = "You are a senior code review assistant. Project conventions and directory index follow..." # unchanged
    3. def build_messages(changed_files, question):
    4. return [
    5. {"role": "system", "content": SYSTEM},
    6. {"role": "user", "content": f"Changed files:\n{changed_files}\n\nQuestion: {question}"},
    7. ]

    Also plan for constraints: limited by high-end compute supply, throughput for such services is limited early on, and unit prices still have room to fall as new-generation accelerator cards and super-node deployments ship in volume. Rate limiting and retries should be treated as the normal state in architecture design.

    5. Interface Compatibility and Domestic Accelerator Adaptation

    The biggest risk in production is lock-in. A more mature strategy is to choose services that are compatible with mainstream open interface specifications (both chat-completion style and message style), so business code only needs a small adapter layer to migrate. Baidu AI Cloud’s related model services are also designed around a common interface specification and unified authentication, making it easier to build an observable call chain on general cloud products such as container platforms, logging services, and monitoring and alerting.

    On the compute side, domestic accelerators (such as training and inference cards and super-node solutions from some vendors) have completed adaptation for mainstream long-context models. When migrating, focus on three metrics: operator coverage, memory fragmentation, and communication topology.

    6. Deployment Checklist

    • Are stable contents placed first to maximize cache hits;
    • Are very long inputs segmented into summaries and retrieval recall to avoid meaningless full concatenation;
    • Are three layers of limits set for context length, concurrency, and timeout;
    • Are monitoring and alerting used to track time to first token, throughput, and cache hit rate;
    • Is an interface adapter layer retained to ensure multi-provider switchability.

    Conclusion: million-token context has moved from “capability demonstration” into a “cost engineering” stage. Hybrid attention and sparse activation are the main line for cost reduction, cache hit rate and compute supply determine the actual bill, and interface neutrality plus domestic adaptation determine long-term maintainability.