Sparse Compressed Attention Architecture for Million-Token Contexts: A Technical Breakdown

    This article breaks down a sparse compressed attention architecture designed for million-token contexts. It explains why long-context models combine compression with sparsity, how attention and expert layers are arranged, how multi-hyper-connections replace standard residuals, and how compressed sparse attention splits KV across sliding-window, compressed, and index channels. It also covers heavy compression, hash-routed experts, multi-token prediction, and key engineering considerations for deployment.

    1. Why Long Contexts Need Both Compression and Sparsity

    Standard self-attention scales quadratically with sequence length, while the memory footprint of the KV cache grows linearly. As the context expands from a few thousand tokens to the million-token range, the bottleneck quickly shifts from compute to memory bandwidth and cache capacity.

    The emerging consensus in the industry is that relying on sparsity alone—allowing each token to attend to only part of the history—loses long-range information, while relying on compression alone—reducing the history to a small set of representations—loses detail. As a result, new-generation long-context designs generally adopt a combined structure of a “compressed backbone plus local fine inspection.” A preview release of an open-source trillion-parameter language model is a representative example: roughly 1.6T total parameters, about 49B activated parameters, native support for million-token contexts, and a pure language model form.

    2. Overall Structure: Alternating Layer Types and Expert Layer Differentiation

    The model has 61 layers. Attention layers and expert layers are not stacked homogeneously; they are arranged alternately by design:

    • Attention layers come in three forms: compressed sparse attention (compression ratio of about 4:1), heavily compressed attention (compression ratio of about 128:1), and sliding-window attention.
    • Expert layers come in two forms: standard sparse expert layers and hash-routed expert layers.
    • The first three layers use hash expert layers, with attention configurations of heavy compression, heavy compression, and compressed sparse, respectively. The remaining 58 layers use standard expert layers, with the two compressed attention types alternating. The final layer converges to sliding-window attention, followed by a multi-token prediction module at the end.

    This arrangement—heavy compression as the foundation in the early stage, mixed fine inspection in the middle, and local convergence at the end—essentially places attention mechanisms with different cost-benefit ratios where they fit best: shallow layers handle the global semantic skeleton, while deeper layers handle fine-grained modeling.

    3. Connecting Attention and Expert Layers: Multi-Hyper-Connections

    Traditional residuals add a sublayer’s output directly back to the backbone. This structure instead uses multi-hyper-connections (mHC) as the bridge. In implementation, mHC adds pre-processing and post-processing steps beyond a residual: pre-processing projects the backbone representation into multiple routable signals, and post-processing folds the sublayer output back into the backbone according to weights. The benefits are richer gradient paths and more thorough inter-layer information reuse. The cost is several small projection matrices per layer and additional memory reads and writes. In engineering, these small operators must be fused; otherwise, they become memory-access hotspots.

    4. Compressed Sparse Attention: Division of Labor Across Three KV Paths

    The key to compressed sparse attention is splitting KV into complementary channels rather than relying on a single strategy:

    1. Sliding-window channel: each token computes attention only with tokens inside the window. The KV cache only needs to store window-sized entries, cyclically overwriting beyond that. Its memory footprint is constant and it handles local syntax and short-range dependencies.
    2. Compressed channel: compresses the history into fewer representations at a fixed ratio (such as 4:1) and handles mid- to long-range semantics.
    3. Index channel: builds a lightweight index over the compressed representations, performing coarse filtering first and fine computation second, reducing quadratic complexity to near-linear.

    Pseudocode illustration (data flow only, not a specific interface):

    1. # q: [B, H, S, D]; win_kv: ring buffer; c_kv: compressed KV; idx: index table
    2. local = attn(q, ring_read(win_kv, window_size)) # constant memory
    3. cand = idx.topk(q, c_kv, k=64) # coarse candidate filtering
    4. global = attn(q, gather(c_kv, cand)) # sparse fine computation
    5. out = gate_local * local + gate_global * global # gated fusion

    5. Heavily Compressed Attention: The 128:1 Trade-off

    Heavy compression pushes the compression ratio to about 128:1, resulting in extremely low cache usage. It is suitable for shallow layers that provide a global overview. Its risk is irreversible information loss, so it must be backed by two things: the fine-inspection capability of subsequent compressed sparse layers, and joint optimization with local channels during training rather than an add-on at inference time. If the compression ratio does not match the layer position, the “middle-section forgetting” phenomenon in long documents becomes noticeably worse.

    6. Hash Expert Layers and Multi-Token Prediction

    Hash routing replaces a learnable gate with deterministic hashing, stably mapping tokens to fixed experts. The benefits are naturally balanced load and predictable routing communication, making it suitable for stable feature bucketing in the shallowest layers. Deeper layers use standard learnable routing in exchange for expressiveness. The multi-token prediction module at the end predicts multiple future tokens at once and can serve as a draft source for speculative decoding during inference, improving throughput.

    7. Engineering Implementation Notes

    • Cache tiering: keep the window cache resident; store the compressed cache per layer or in shared groups; the index table can use lower precision.
    • Operator fusion: fuse the pre- and post-processing of multi-hyper-connections and the gated fusion to reduce memory access.
    • Capacity planning: activated parameters determine compute, while total parameters determine memory and parallel partitioning strategy. Elastic scaling and long-term stability monitoring can be combined with container platforms and monitoring and alerting systems.
    • Evaluation dimensions: beyond general capabilities, build separate test cases for long-range retrieval, cross-section reasoning, and ultra-long document summarization.

    8. Conclusion

    The core idea behind this class of architecture is not mysterious: use low-cost channels to guarantee coverage, high-cost channels to guarantee precision, indexing to reduce complexity, and changes to the connection scheme to enable more stable deep-layer training. Understanding this trade-off framework has more long-term value than memorizing the specific parameters of a particular version.