Compressed Attention and Mixture-of-Experts Design for Efficient Large Language Models

    This article examines a heterogeneous architecture for very large language models that combines layer-specific attention compression with mixture-of-experts routing. It outlines a reference configuration with about 1.6T total parameters, 49B activated parameters, and support for roughly 1M context, then explains the roles of sliding window attention, compressed sparse attention, and heavy compression attention. The discussion focuses on the two-way KV cache and index-selection mechanism in compressed sparse attention, along with hash MoE versus regular MoE, multi-path hybrid connections, multi-token prediction, and practical engineering considerations for balancing quality, throughput, and memory use.

    Compressed Attention and Mixture-of-Experts Design for Efficient Large Language Models

    As very large language models continue to evolve toward long context, sparse activation, and heterogeneous computation, a single attention mechanism and a single expert structure are increasingly insufficient for balancing quality, throughput, and memory footprint at the same time. One approach worth studying is to introduce attention compression strategies of different granularity at different model depths, while using mixture-of-experts to increase parameter capacity without increasing computation proportionally. Using a representative very large language model architecture as an example, this article reviews its overall computation flow, attention modules, expert modules, and connection scheme, with emphasis on the two-way KV cache and index-selection mechanism in compressed sparse attention.

    1. Overall Architecture and Design Goals

    In one reference configuration, the model has about 1.6T total parameters, about 49B activated parameters, and supports inference with roughly 1M context. It is a pure language model. The core goal of this configuration is not simply to stack parameters, but to keep the effective computation of a single inference pass within an acceptable range through sparse activation and attention compression. The model has 61 layers in total. The first 3 layers use hash mixture-of-experts, paired with heavy compression attention, heavy compression attention, and compressed sparse attention, respectively. The following 58 layers use regular mixture-of-experts, with compressed sparse attention and heavy compression attention used alternately; the final layer uses sliding window attention. A multi-token prediction module is attached at the end of the model to provide denser prediction signals during training.

    From the computation-flow perspective, the embedding enters the first three layers, passes through attention and hash mixture-of-experts, then enters the following 58 layers with alternating attention and regular mixture-of-experts, and finally produces output through the multi-token prediction head. The inter-layer connection does not use a single residual path. Instead, it uses multi-path hybrid connections, with additional pre-processing and post-processing steps in the implementation. This layer-wise heterogeneous design shows that a long-context model does not need to use the same attention mechanism in every layer. Instead, it can configure local dependencies, long-range coarse-grained dependencies, and global semantic routing separately.

    2. Division of Work Across Three Attention Modules

    Sliding window attention handles local dependencies. Each token computes attention only with tokens inside the window, and the KV cache only needs to store KV values for the window size; once the window is exceeded, the cache overwrites in a circular manner. This ring buffer significantly reduces memory growth and is suitable for capturing nearby syntax and local coreference relationships. The cost is that information outside the window is invisible, so it must work together with compressed pathways.

    Compressed sparse attention handles “indexed compressed long-range information.” Its compression ratio is about 4:1, and its core is a two-way KV channel. The first path is the sliding window attention path, which is responsible for high-fidelity local information. The second path is the compression path: the input state passes through a compressor and then updates the compressed KV cache. Each output produces T compressed KV values, which are then filtered by an index module so that no more than topK compressed tokens participate in subsequent attention. The role of the index module is to perform relevance filtering within the compressed coarse-grained representation, avoiding having all compressed tokens participate in computation.

    Heavy compression attention raises the compression ratio to about 128:1 and models long-range dependencies at a coarser granularity. It has lower computational cost and is suitable for providing a broad context overview in shallow layers or alternating layers. The three attention types form a hierarchical combination: high-fidelity local attention, mid-range compressed selection, and long-range heavy compression. This controls the KV cache while retaining multi-scale information.

    3. Two-Way KV Mechanism in Compressed Sparse Attention

    In a single-step decoder scenario, the input shape can be abstracted as [1, hidden_size]. After KV downsampling, the KV cache shape is [1, head_dim]. Here, head_dim is split into RoPE dimensions and remaining dimensions: one part applies RoPE to inject positional information, and the remaining part is quantized to reduce storage and bandwidth. The window KV cache stores values according to the window size and overwrites circularly when the window is exceeded.

    The compression path maintains a compressed KV cache. The compressor outputs T compressed KV tokens at a time, and the index module filters them according to the relevance between the current query and the compressed tokens, retaining no more than topK. In this way, subsequent attention is computed only over window tokens and a small number of compressed tokens, and computational complexity no longer grows linearly with the full context. A simplified single-step flow can be represented as follows:

    1. x = embed(token)
    2. for layer in layers:
    3. if layer.attn == SWA:
    4. kv = window_cache.update(x)
    5. x = attention(x, kv)
    6. elif layer.attn == CSA:
    7. win_kv = window_cache.update(x)
    8. comp_kv = compressor.update(x)
    9. idx = index_select(comp_kv, topK)
    10. x = attention(x, win_kv + comp_kv[idx])
    11. elif layer.attn == HCA:
    12. comp_kv = heavy_compressor.update(x)
    13. x = attention(x, comp_kv)
    14. x = mHC(x, attn_out)
    15. x = moe[layer](x)
    16. logits = mtp_head(x)

    The key trade-offs of this mechanism are compression ratio, topK, and index accuracy. A higher compression ratio means a smaller cache but greater information loss; a larger topK means higher fidelity but higher computation and bandwidth. The index module needs to be stable, low-overhead, and compatible with quantized KV representations.

    4. Mixture-of-Experts and Hash Routing

    There are two types of mixture-of-experts modules: regular MoE and hash MoE. Regular MoE selects Top-k experts through a learnable router, and deeper semantic features are better suited to this dynamic routing. Hash MoE assigns tokens through fixed hashing, which has low routing overhead and more stable load, making it suitable for the first three relatively shallow layers where features are not yet fully semanticized. The model has 1.6T total parameters and 49B activated parameters, indicating that only a small number of experts are activated in each forward pass, thereby expanding capacity while controlling compute.

    From an engineering perspective, attention must be paid to expert load balancing, capacity factor, cross-device communication, and routing jitter. Hash routing reduces the uncertainty of learned routing, while regular routing provides semantic adaptation. Combining the two by layer is a practical compromise.

    5. Multi-Path Hybrid Connections and Multi-Token Prediction

    The inter-layer connection uses multi-path hybrid connections. Compared with an ordinary residual connection, it adds pre-processing and post-processing. Pre-processing performs normalization, projection, or gating on the input, while post-processing scales and fuses the sublayer output, so that outputs from heterogeneous modules such as attention and experts flow into the backbone more smoothly. The multi-token prediction module is located at the end of the model. It provides additional prediction targets during training, gives the model denser supervision signals in a single forward pass, and can be combined with verification or acceptance strategies during decoding.

    6. Engineering Implications

    First, long-context optimization cannot rely on only one type of compression. Local, compressed, and heavy-compression attention should be allocated by layer. Second, KV cache management should distinguish between window cache and compressed cache: the window cache uses circular overwriting, while the compressed cache works with index filtering. Third, quantization and RoPE splitting should be considered together for numerical stability. Fourth, layer-wise use of hash MoE and regular MoE can balance shallow-layer stability with deep-layer expressiveness. Fifth, observable metrics such as cache hit rate, compressed-token retention rate, expert load, and routing entropy should be established to continuously evaluate the balance between quality and throughput.

    Overall, the value of this type of architecture lies in decoupling four dimensions: parameter scale, context length, activated computation, and cache footprint. Mixture-of-experts expands capacity, sparse activation controls computation, multi-scale compressed attention controls long-context cost, and multi-path connections plus multi-token prediction improve training stability and signal density. These principles offer transferable reference value for the design of general very large language models.