Decoding the Ultra-Scale MoE Architecture: Long-Context Compressed Attention in Practice

    This article breaks down an ultra-scale Mixture-of-Experts (MoE) language model designed for long-context inference, focusing on how compressed attention, sparse activation, and layered expert routing work together. It covers the overall layer structure, dual-path compressed sparse attention with KV indexing, 128:1 heavy compression, hash versus conventional MoE routing, multi-token prediction, and practical engineering trade-offs around memory, throughput, quantization, and evaluation.

    Decoding the Ultra-Scale MoE Architecture: Long-Context Compressed Attention in Practice

    1. Why the “Large Parameters, Long Context” Pressure Must Be Solved at the Architecture Level

    Ultra-scale language models are facing two growth curves at the same time: parameter counts keep climbing, and context windows are expanding from thousands of tokens to the million-token range. Parameter growth brings stronger expressive power, but it also makes full activation prohibitively expensive. Context growth preserves information completeness, yet it causes attention computation and the KV cache to balloon quadratically and linearly, respectively. In engineering practice, there are usually three mitigation paths: sparse computation, compressed representations, and finer-grained memory scheduling. Publicly available technical approaches in recent years tend to stack all three rather than optimize a single point.

    A typical design is a pure language model with roughly 1.6T total parameters and about 49B activated parameters per token, natively supporting inference with a context length of around 1M. Its core idea can be summarized as “sparse activation + hierarchical compressed attention + multi-token prediction.” The following sections break it down layer by layer: overall structure, compressed attention, mixture of experts, and training objectives.

    2. Overall Structure: Alternating Layer Types and Hierarchical Sparse Experts

    The model has 61 layers in total, divided into two segments:

    • The first 3 layers use hash-routed expert layers, paired with heavy compressed attention, heavy compressed attention, and compressed sparse attention, respectively.
    • The remaining 58 layers use conventional routed expert layers, with attention alternating between heavy compression and compressed sparse attention; the final layer uses sliding window attention.
    • A multi-token prediction head is attached at the end to assist in predicting subsequent tokens.

    This arrangement of “heavy compression at the front, alternation in the middle, and a local window at the tail” is not arbitrary: shallow layers focus more on the global semantic skeleton and are suited to high compression ratios, while deep layers require finer local discrimination and therefore retain a combination of local windows and moderate compression.

    Inter-layer connections use a hybrid connection scheme with pre- and post-processing. Compared with a standard residual connection, it inserts one pre-processing and one post-processing step before and after the main path, used to align the representation scale and statistical properties of different sub-layers. A sketch is shown below:

    1. # Pseudocode: hybrid connection with pre- and post-processing
    2. x_pre = hc_pre(x) # normalization/projection to align scale
    3. y = attention_or_moe(x_pre) # sub-layer computation
    4. x = hc_post(y, x) # fuse the main path with the sub-layer output

    In engineering practice, hc_pre typically handles normalization and channel projection, while hc_post handles gated or scaled fusion. The benefit is that different types of sub-layers (compressed attention, expert layers) can be stacked stably on the same main path, reducing degradation in deep layers.

    3. Compressed Sparse Attention: Dual-Path KV and Index Selection

    The key to compressed sparse attention is splitting the KV into a “local exact path” and a “global compressed path,” then using an index module to perform selection. Taking the decoding stage (sequence length of 1, batch size of 1) as an example, the input shape is [1, hidden_size].

    3.1 Local Exact Path: Sliding Window

    The first path is formed by sliding window attention, where each token computes attention only with tokens inside the window. The KV cache only needs to store a window-sized number of entries; once exceeded, entries are overwritten cyclically, keeping memory usage constant. The flow is as follows: the input is passed through KV downsampling to obtain [1, head_dim], where the front segment applies RoPE according to the rotary position embedding dimensions and the remaining dimensions are quantized, after which it is written into the window cache.

    1. # Pseudocode: writing and overwriting window KV
    2. kv = kv_downsample(x) # [1, head_dim]
    3. kv[:, :rope_dim] = rope(kv[:, :rope_dim])
    4. kv[:, rope_dim:] = quantize(kv[:, rope_dim:])
    5. window_cache.push_overwrite(kv) # cyclically overwrite once the window length is exceeded

    3.2 Global Compressed Path: Compressor and Index

    The second path is the compression channel. The input state first goes through the compression module, which produces T compressed KV entries each time and updates the compressed cache; these T entries then enter the index module, which keeps no more than topK of them by relevance for use in attention computation. A compression ratio of 4:1 means every 4 original tokens are compressed into 1 representation, shrinking the candidate set by an order of magnitude while maintaining a global view.

    The index module usually does two things: first, scoring (similarity to the current query or the output of a lightweight prediction head); second, TopK selection and any necessary deduplication. Three points need attention in engineering:

    1. Numerical stability of scoring and selection, to avoid score drift under long contexts;
    2. Static versus dynamic TopK strategies; static is convenient for batching, while dynamic saves more compute but introduces branching;
    3. The update timing of compressed entries; updating by block can amortize the overhead.

    4. Heavy Compressed Attention: The 128:1 Extreme Compression and Its Applicability Boundary

    Heavy compressed attention pushes the compression ratio to 128:1, meaning every 128 tokens are compressed into 1 entry. It is suited to shallow layers and scenarios that need long-range skeleton information, trading extremely low cache cost for global awareness. The cost is noticeable loss of detail, so it should not independently handle fine-grained tasks and is usually combined with compressed sparse attention or a local window.

    Its compression module shares the same structure as the one described earlier; the difference is that the compression block is larger and there are fewer cache entries. In practice, “hierarchical compression” can be used: first obtain an intermediate representation at 4:1, then aggregate it into 128:1, reducing the information smoothing caused by a one-shot large-span aggregation.

    5. Mixture of Experts: The Division of Labor Between Conventional and Hash Routing

    There are two types of expert layers:

    • Conventional MoE: a routing network selects TopN experts for each token, offering strong expressive power, but routing load balancing and communication overhead are the main challenges;
    • Hash MoE: a hash function determines the expert, routing is deterministic and requires no learned gating, load is naturally balanced, and it is suited to stable representations in shallow layers.

    The first 3 layers use hash routing, which can provide stable gradients and balanced load early in training; the remaining 58 layers use conventional routing and carry the main expressive workload. In engineering, attention should be paid to All-to-All communication under expert parallelism, capacity factor settings, and dropping strategies, to avoid pipeline bubbles caused by long-tail tokens.

    6. Multi-Token Prediction: A Trade-off Between Training Signal and Inference Gains

    The multi-token prediction head at the end predicts tokens at farther positions in addition to the next token. It brings two kinds of benefits: during training, it provides denser supervision signals and improves representation quality; during inference, it can work with speculative decoding to verify multiple candidates in a single forward pass, reducing latency. Note that it only adds a small number of parameters and computation without changing the main-path cache structure, making it a cost-effective design.

    7. Engineering Implementation: Memory, Throughput, and Evaluation

    1. Memory: the window cache is constant, while the compressed cache grows linearly with context but with a very small coefficient; estimate the peak based on the compression ratio and TopK, and reserve space for fragmentation.
    2. Throughput: compression and indexing can overlap with expert computation; under batching, a fixed TopK is recommended to reduce branching.
    3. Quantization: quantize only non-RoPE dimensions, and make sure the calibration set covers the long-context distribution.
    4. Evaluation: in addition to general benchmarks, add long-context retrieval, cross-segment reasoning, and consistency tests before and after compression.

    For cloud deployment, elastic scaling can be combined with a container platform, object storage can hold model weights, monitoring and alerting can track cache hit rates and expert load, and a logging service can help locate long-tail latency.

    8. Summary

    The value of this architecture lies in combining “sparse activation, compressed attention, local windows, and multi-token prediction” into a stackable layer template: shallow layers use high compression to see the global picture, deep layers use moderate compression plus local windows to see details, and hierarchical experts balance stability and expressiveness. For engineering teams, the key is not to copy the layer configuration, but to understand the trade-offs among compression ratio, TopK, window length, and expert capacity, and to design an observable, rollback-capable deployment plan accordingly.