Architecture Challenges and Practices for Deploying Ultra-Large MoE Models
As Large Language Models scale in parameters and context length, deploying ultra-large Mixture-of-Experts (MoE) models shifts the bottleneck from training to efficient inference. This article explores the architectural challenges of handling complex attention runtime state spaces in hybrid attention mechanisms. It details engineering practices for multi-level KV cache pools, prefix caching adaptation, sparsification acceleration, and distributed deployment strategies to enable effective online serving of million-token context models.
I. Background: New Requirements for Inference Systems Driven by Model Architecture Evolution
In recent years, Large Language Models (LLMs) have continuously expanded in two dimensions: parameter scale and context length. Taking the new generation of Mixture-of-Experts (MoE) architectures as an example, the industry has seen ultra-large models with total parameters reaching the trillion level while only activating tens of billions of parameters, supporting ultra-long contexts of up to a million tokens. While these models have achieved significant breakthroughs at the algorithm level, the true hurdle for deployment has shifted from “can the model be trained” to “can the inference system serve it efficiently.”
It is important to emphasize that the core challenge these models bring to inference engines is not superficial issues like “the model is larger” or “there are more experts,” but rather the explosion of complexity in the attention runtime state space. Traditional inference frameworks are accustomed to treating the KV cache as a set of raw key-value tensors organized by layer, maintaining a uniformly shaped cache pool for each layer. However, when a model introduces Sliding Window Attention (SWA) in every layer and dynamically switches between various compression attention mechanisms, this “one pool per layer” assumption is completely broken.
This article will outline the implementation path of these hybrid attention models in inference frameworks from a general technical perspective, focusing on key issues such as multi-level KV cache pool design, prefix cache adaptation, sparsification acceleration, and distributed deployment.
II. State Management Challenges Brought by Hybrid Attention
2.1 Coexistence of Multiple Attention Mechanisms
New-generation efficient models typically adopt a combined attention design:
- Sliding Window Attention (SWA): Retains only the complete KV of the most recent W tokens per layer to capture local dependencies.
- Coarse-grained Compression Attention: Compresses historical tokens into larger blocks (e.g., every 128 tokens) into summary vectors, providing a low-cost global view.
- Fine-grained Compression Attention: Saves intermediate precision information in smaller blocks (e.g., every 4 tokens), paired with a lightweight indexer for top-k selection, balancing precision and cost.
This means that during the inference process of a single request, its historical information is simultaneously saved in three granularities and multiple coordinate systems: complete token coordinates, sliding window physical pool, coarse-grained compression pool, fine-grained compression pool, indexer pool, and the intermediate state pool of the compression process itself.
2.2 Fundamental Refactoring of Inference Frameworks
Inference frameworks can no longer treat the KV cache as a “raw KV block per layer.” They must answer a series of new questions:
- How to maintain mapping relationships between pools: How does the physical position of a logical token correspond across the window pool, compression pool, and indexer pool?
- How to reuse prefix cache: When two requests share a prefix, do they share the complete KV, the compressed summary, or both? How to handle boundary misalignment of compression blocks?
- How to be compatible with CUDA Graph: Graph capture requires fixed memory addresses and shapes. How can multi-pool structures be incorporated into static graphs?
- How to plan VRAM: The capacity of the compression pool has a sub-linear relationship with the original context length, meaning the quota calculation logic must be rewritten.
III. Engineering Implementation of Multi-Level KV Cache Pools
3.1 Overall Design of Pooling
The common practice in industry inference frameworks is to split caches of different granularities into independent memory pools, each with its own allocator and page table:
Logical token sequence├── SWA physical pool (ring window, addressed by token)├── Fine-grained compression pool (one compressed vector per 4 tokens)├── Coarse-grained compression pool (one summary vector per 128 tokens)└── Indexer pool (lightweight representation for top-k retrieval)
The pools are associated through unified “request-level metadata”: the metadata records the start and end page numbers, compression boundary alignment status, and sliding window progress for that request across all pools.
3.2 Prefix Cache Adaptation
Traditional prefix caching uses token sequences as keys for radix tree matching. Under a multi-pool structure, radix tree nodes must simultaneously record the physical intervals of multiple pools. There are two key engineering details:
- Alignment Truncation: The shared prefix must be truncated to the compression block boundary. Otherwise, the incomplete tail block cannot directly reuse the compressed vector, triggering a “tail re-compression.”
- Shadow Radix Tree: A separate logical radix tree is maintained for the compression pool, running in parallel with the token-level radix tree. This allows information from pure compression layers to be shared across requests, avoiding the repeated computation of summaries for million-level contexts.
3.3 Incremental Compression Pipeline
The prefill phase is no longer a simple layer-by-layer forward pass, but a “compute while compressing” pipeline: whenever a compression block is filled, a compression operator is immediately triggered to generate the summary of the corresponding granularity and write it to the respective pool. The decoding phase only requires a small compression when the window fills a grid. To hide compression overhead, practices often fuse or asynchronously schedule compression kernels with attention kernels, forming a specialized “flash compression” operator.
IV. Sparsification and Acceleration Technologies
4.1 Lightning Top-K Retrieval
The core of fine-grained compression attention is to first score all historical blocks using an indexer, and then select top-k blocks for fine-grained attention. When the context reaches the million level, the number of candidate blocks is massive, making scoring and sorting a bottleneck itself. Engineering optimization directions include: designing index scoring as low-rank small matrix multiplication (which can be batched and pipelined), adopting block-wise top-k selection algorithms, and utilizing hardware reduction primitives to avoid global sorting.
4.2 Hierarchical Sparse Offloading
Under ultra-long contexts, even compressed caches may exceed single-GPU VRAM. Hierarchical offloading (asynchronously moving cold data to host memory) needs to address:
- Popularity Determination: Using top-k hit rate as the block-level popularity metric, rather than simple recent access time.
- Prefetch Overlap: Predicting the blocks needed for the next layer based on current index scoring trends and initiating transfers in advance.
- Consistency: Whether offloading the compression pool or the window pool, a consistent view must be maintained with request metadata to prevent mapping errors between pools during the swap-in/swap-out process.
4.3 Multi-Step Prediction Decoding
Multi-Token Prediction (MTP) technology uses an additional lightweight prediction head to generate multiple candidate tokens in a single forward pass, which are then verified via speculative decoding. Under a multi-pool structure, the adaptation key points for MTP are: draft steps should only operate on the window pool and a few compression blocks, and after verification, batch commit to all pools to avoid cache pollution from intermediate states.
V. Distributed Deployment Strategies
5.1 Combination of Parallel Dimensions
Deploying ultra-large MoE models typically requires a combination of multiple parallel strategies:
- Expert Parallelism (EP): Distributing different experts to different devices, combined with global distribution at the routing layer.
- Tensor Parallelism (TP): Splitting large matrices in dense layers.
- Context Parallelism (CP): Splitting long sequences along the sequence dimension, with multiple GPUs collaborating to complete attention computation, a key support for million-level contexts.
- Data Parallelism Attention (DP Attention): For MoE models, the attention part can be data-parallel by request, while the expert part uses EP, reducing communication overhead.
5.2 Prefill and Decode Disaggregation
Ultra-long context prefill is compute-intensive, while decoding is memory-intensive; the resource profiles of the two differ vastly. Prefill-decode disaggregation (PD disaggregation) has become a standard, but the multi-pool structure brings new challenges to disaggregated deployment: what prefill nodes transmit to decode nodes is not just raw KV, but also data from compression pools of various granularities and indexer pools. The transmission protocol needs to schedule channels per pool, manage block granularity, and support incremental transmission. Otherwise, the overhead of migrating a million-token request would be unacceptable.
VI. Deployment Practice Recommendations
- Start design from the state model: Draw the lifecycle and mapping relationships of each cache pool first before touching the code.
- Prioritize compression boundary alignment: Unify alignment rules across all stages—request scheduling, prefix matching, and cross-node transmission.
- Decouple operators and scheduling: Standardize the interfaces for compression, retrieval, and sparse attention operators to facilitate replacing underlying implementations.
- Leverage platform capabilities: In enterprise deployments, you can build elastic inference clusters relying on general container platforms, object storage, and monitoring. For instance, using Baidu AI Cloud’s container and storage services, one can quickly set up an inference cluster supporting PD disaggregation and track key metrics like compression cache hit rate through a unified monitoring system.
VII. Conclusion
The real test that the new generation of ultra-large MoE models poses to inference systems lies in the evolution of the attention state space from a “single KV pool” to a “family of pools with multiple granularities and coordinate systems.” The key engineering paths for deployment include: unified metadata management for multi-level cache pools, prefix cache design oriented towards compression blocks, sparse retrieval and hierarchical offloading, and the coordination of context parallelism with PD disaggregation. Only by connecting these stages into a runnable, observable, and tunable pipeline can the capabilities of ultra-large context models truly be transformed into usable online services.
