Scaling to 1M Tokens: Architecture Upgrades and Inference Optimization for Long-Context LLMs

    This article explains the technical changes behind a new large language model that extends its API context window to one million tokens. It covers the hybrid CSA and HCA attention mechanisms, manifold-constrained hyper-connections, the Muon optimizer, and the mixture-of-experts design. It also reviews the gains in compute, KV cache usage, and output throughput, the post-training approach based on full-vocabulary policy distillation, the TileLang operator library, and deployment considerations on Baidu AI Cloud.

    As large language model applications expand, the ability to process contexts of one million tokens has become an important measure of a model’s overall capability. A team recently rolled out a new generation of large model on its API service. The model extends the context window to one million tokens and also delivers significant improvements in its underlying architecture and inference efficiency. This update marks a new stage for long-text processing, one defined by cost-effectiveness and high throughput. This article examines the core logic of the upgrade across four areas: architecture innovation, inference optimization, post-training strategy, and deployment practice.

    I. Core Architecture Innovations: Balancing Efficiency and Performance

    The new model underwent a deep architectural redesign. Instead of relying on a single attention mechanism, it introduces hybrid CSA and HCA attention mechanisms. It also combines manifold-constrained hyper-connections with a new Muon optimizer. Together, these choices lay the groundwork for stable training at large parameter scales and efficient inference.

    1. Hybrid Attention and Manifold-Constrained Hyper-Connections

    When processing a million tokens, the quadratic complexity of standard self-attention causes computation and memory costs to grow sharply. The new hybrid attention mechanism alternates or combines different attention submodules across shallow and deep layers. This reduces redundant computation in global attention. Manifold-constrained hyper-connections optimize how information flows between network layers. By applying geometric constraints in a manifold space, this technique alleviates the vanishing gradients and representation degradation common in deep mixture-of-experts (MoE) models. It also substantially improves the model’s ability to capture complex long-range dependencies.

    2. Application of the Muon Optimizer

    Traditional AdamW optimizers often struggle in very large model training because their update rules are sensitive to gradient noise. The new model adopts the Muon optimizer, which combines momentum accumulation with matrix orthogonalization. The orthogonalization step projects the update direction onto an orthogonal basis, which keeps the step size of each parameter update more stable. At the trillion-parameter training scale, this produces faster convergence and better generalization.

    3. Parameter Scale and Sparse Activation

    The new generation offers two core versions: a professional version and a lightweight version. The professional version has 1.6 trillion total parameters, with about 49B activated per inference step. The lightweight version has about 284B total parameters, with about 13B activated. This MoE-based sparse activation design keeps a large knowledge capacity while limiting the actual compute per inference. It is a key factor in achieving cost-effective inference.

    II. Inference Performance Breakthroughs: Dual Optimization of Compute and Memory

    Inference cost is the biggest obstacle to deploying long-context models. The KV cache memory footprint and per-token compute grow linearly or even faster as context length increases. This upgrade makes significant progress in this area.

    1. Extreme Compression of Memory and Compute

    In million-token context scenarios, the professional version needs only about 27% of the single-token inference compute and 10% of the KV cache of the previous-generation model. The lightweight version reduces compute overhead to 10% and KV cache to 7%. On the same hardware, the system can therefore support longer input contexts and more concurrent requests.

    1. # Pseudocode example: estimating and comparing KV cache usage for long contexts
    2. def estimate_kv_cache(seq_len, num_layers, hidden_size, num_kv_heads, compression_ratio):
    3. # Base memory footprint (FP16)
    4. base_cache = 2 * seq_len * num_layers * hidden_size * num_kv_heads
    5. # Apply the compression ratio of the new architecture
    6. optimized_cache = base_cache * compression_ratio
    7. return optimized_cache
    8. # Compared with traditional architectures, the new architecture reduces memory usage to one-tenth of the original

    2. Significant Throughput Improvement

    Thanks to much lower compute overh