MLA and MoE Architecture Explained: Inside an Efficient Open-Source LLM
This article analyzes the architecture of an efficient open-source large language model that combines Multi-head Latent Attention (MLA) with a fine-grained Mixture-of-Experts (MoE) design. It explains how MLA compresses KV caches to enable long-context inference, how fine-grained and shared experts achieve "large total parameters, small activated parameters," and how these innovations translate into dramatically lower training and inference costs. It also covers training data engineering, capability benchmarks, industry impact, and practical deployment recommendations.
MLA and MoE Architecture Explained: Inside an Efficient Open-Source LLM
1. Background: The Efficiency Dilemma of the LLM Era
In recent years, the parameter counts of large language models have grown relentlessly, from billions to hundreds of billions and even trillions. While model capabilities have improved, efficiency challenges have become severe. In a dense architecture, every inference pass activates all parameters, so compute scales linearly with model size, driving up inference costs and memory consumption. For a mainstream 70B-parameter dense model, the compute required for a single forward pass is already out of reach for many small and mid-sized organizations—let alone for models with several hundred billion parameters.
Meanwhile, demand for longer context windows keeps growing. Document analysis, code understanding, and multi-turn dialogue often require inputs of tens of thousands or even over a hundred thousand tokens. Traditional multi-head attention (MHA) faces explosive KV cache growth in long-sequence scenarios: each time the sequence doubles, memory usage and computational complexity of attention increase significantly, becoming a bottleneck for long-text applications.
Against this backdrop, the central question of LLM evolution is how to dramatically reduce training and inference costs while preserving—or even improving—model capability. In mid-2024, a Chinese research lab released a second-generation open-source MoE model that offered a representative answer: by combining Multi-head Latent Attention (MLA) with a fine-grained MoE architecture, a model with 236 billion total parameters activates only 21 billion parameters per token, while compressing inference memory requirements to a fraction of traditional approaches. This “large parameters, small activation” design opened up a highly efficient technical path for the industry.
2. Core Architecture I: Multi-head Latent Attention
2.1 The Bottleneck of Traditional Attention
The standard Transformer uses multi-head attention, where each layer stores Key and Value vectors for every token. To speed up autoregressive generation during inference, a KV cache keeps the K and V matrices of past tokens in memory. However, as sequences get longer, layers multiply, and the number of attention heads grows, the KV cache’s memory footprint explodes. This becomes the main bottleneck for long-context inference and also limits the concurrent throughput of inference services.
2.2 The Design Philosophy of MLA
The core idea of Multi-head Latent Attention (MLA) is low-rank compression: instead of caching full high-dimensional K and V vectors, they are compressed into a low-dimensional latent vector. At inference time, only this compressed representation is cached; when attention needs to be computed, up-projection matrices restore the K and V required by each attention head.
Mathematically, assuming the original hidden dimension is d, a traditional approach caches KV data on the order of 2×d×n_kv_head per token per layer, whereas MLA compresses this into a latent vector c whose dimension is far smaller than the original space:
# Illustrative pseudocode: MLA compression and restorationlatent_kv = W_down @ hidden_state # compress into a low-dimensional latent spacecache.append(latent_kv) # cache only the latent vector# Restore during inferenceK = W_up_k @ latent_kvV = W_up_v @ latent_kvattention_scores = softmax(Q @ K.T / sqrt(d_head))output = attention_scores @ V
This design yields two benefits. First, the KV cache’s memory footprint drops by an order of magnitude, turning 128K-level long-context inference from “theoretically feasible” into “engineering affordable.” Second, the projection matrices in the compress-and-restore process can be jointly trained with the model weights and absorbed/fused into them, so inference introduces no significant extra compute—balancing efficiency with quality.
It is worth noting that low-rank compression is not a free lunch. In practice, the compression dimension must be carefully designed, and rotary position embeddings need adapted modifications (such as a decoupled position encoding scheme) to ensure long-sequence modeling capability is not compromised. This reflects the classic engineering wisdom of “trade-offs and compensation” in architectural innovation.
3. Core Architecture II: Fine-Grained Mixture-of-Experts Design
3.1 The Principles and Evolution of MoE
The Mixture of Experts (MoE) architecture replaces the feed-forward network (FFN) in a Transformer with multiple parallel “expert” sub-networks. Each token is routed by a gating network (Router) to only a few experts, achieving a sparse computation pattern of “large total parameters, small per-token activation.” A typical formulation looks like this:
# Illustrative pseudocode: MoE forward computationgate_logits = router(x) # compute routing scorestop_k_experts, weights = topk_softmax(gate_logits, k)output = sum(w_i * expert_i(x) for i in top_k_experts)
Compared with dense models, MoE can deliver the capacity benefits of a large model at a compute cost far below its total parameter count. However, traditional MoE designs suffer from coarse expert granularity, unbalanced routing, and knowledge redundancy across experts.
3.2 Fine-Grained Experts and Shared Experts
The MoE design used in this model introduces two key improvements:
First, fine-grained expert segmentation. Expert networks are split into smaller and more numerous units, exponentially expanding the space of possible routing combinations. Fine-grained segmentation lets different tokens activate more flexible expert combinations, improving the model’s expressiveness and the specialization of knowledge, while preventing any single expert from shouldering excessive load.
Second, a shared expert mechanism. Alongside the large set of fine-grained experts, a small number of always-activated “shared experts” capture cross-task general knowledge, while the fine-grained experts focus on domain-specific knowledge. This “shared + specialized” division of labor effectively mitigates the knowledge redundancy problem of traditional MoE and improves parameter utilization efficiency.
The result: with 236 billion total parameters, each token activates only about 21 billion parameters—less than one-tenth of the total—striking an effective balance between model capacity and inference cost. This is the fundamental reason its inference cost is far lower than dense models of comparable capability.
3.3 Routing Balance and Training Stability
A classic challenge in MoE training is load balancing: if routing persistently favors a few experts, some experts become “overloaded” while others “go idle,” wasting capacity and degrading quality. Common industry practices include auxiliary load-balancing losses, capping each expert’s token capacity, and auxiliary-loss-free bias adjustment strategies. Engineering practice must also address the communication overhead of cross-device expert parallelism, typically combining expert parallelism, data parallelism, and pipeline parallelism with computation-communication overlap optimizations to achieve high-throughput training on thousand-GPU clusters.
4. Training Engineering: Data, Efficiency, and Cost
4.1 Building High-Quality Corpora
The model was pre-trained on roughly 8.1 trillion tokens of multi-source corpora. The key to large-scale corpus engineering lies not in quantity but in quality. Common best practices include:
- Multi-source integration: covering web pages, books, code, academic papers, and math problem sets to ensure breadth and depth of knowledge;
- Rigorous deduplication: near-deduplication at both document and paragraph levels to avoid overfitting to and memorization of repeated content;
- Quality filtering: using heuristic rules and classifier models to filter out low-quality and spam content, improving effective information density;
- Ratio tuning: experimenting with data ratios across domains and languages—balancing Chinese and English capabilities often depends on a carefully tuned mixture strategy.
4.2 A Breakthrough in Training Efficiency
Thanks to MLA’s optimization of attention computation and MoE’s sparse activation, the model’s training compute is about one-fifth that of a comparable 70B-parameter dense model, and about one-twentieth that of larger industry flagship dense models. This means that under the same compute budget, more training iterations or larger-scale experimentation become possible. The gain in training efficiency translates directly into faster R&D iteration—strategically significant in the rapidly evolving LLM field.
4.3 Alignment and Human Preference Optimization
After pre-training, the model underwent supervised fine-tuning (SFT) on roughly 1.5 million dialogue samples spanning multiple domains, followed by human preference alignment techniques to further improve instruction following, safety, and conversational experience. Data engineering in the alignment phase also emphasizes diversity, covering mathematical reasoning, code generation, knowledge Q&A, creative writing, and other capability dimensions to avoid overfitting to any single dimension.
5. Capability Evaluation: Multi-Dimensional Performance
Under standardized evaluation frameworks, the model demonstrated capabilities that “punch above its weight” relative to its activated parameter count:
Chinese language capabilities: it ranks in the first tier of comprehensive alignment evaluations, performing on par with international flagship closed-source models and leading commercial models in China, with notable advantages in Chinese semantic understanding, cultural knowledge, and Chinese creative writing tasks.
English language capabilities: its scores in multi-turn dialogue and instruction-following benchmarks match mainstream 70B-class open-source dense models and surpass some open-source MoE models with larger activated parameter counts, proving that architectural efficiency did not come at the expense of capability.
Reasoning and coding capabilities: the sparse-activation MoE design also performs robustly on complex logical tasks such as mathematical reasoning and code generation, suggesting that fine-grained expert specialization helps develop professional capabilities.
These results validate the core thesis of the MoE approach: model capability depends more on total parameter count (knowledge capacity) and training data quality, while inference cost depends on activated parameters. By decoupling the two, one can simultaneously obtain “large-model capability” and “small-model cost.”
6. Economics and Industry Impact
Upon release, the model’s API was priced at 1 RMB per million input tokens and 2 RMB per million output tokens—one to two orders of magnitude lower than mainstream models at the time. This directly triggered a chain reaction of price cuts across China’s LLM API market, with multiple leading cloud and model vendors subsequently slashing prices.
From an industry perspective, the deeper impact of this “extreme cost-performance” strategy includes:
- Lowering the barrier to adoption: small and mid-sized companies and independent developers could, for the first time, afford to call high-performance models at scale in real business scenarios, giving rise to a wave of innovative applications;
- Restructuring cost models: the price anchor for per-token billing was pulled dramatically lower, forcing the entire industry to re-examine the cost structure of model inference and its optimization potential;
- Accelerating the open-source ecosystem: open weights and low-cost APIs advanced in parallel, driving the joint prosperity of private deployment and cloud-based access, so enterprises can flexibly choose based on their data security requirements.
For enterprise users, mainstream cloud platforms (such as Baidu AI Cloud) generally offer full-stack services covering model invocation, fine-tuning, and inference deployment, combined with general-purpose cloud products such as object storage, message queues, container platforms, and monitoring/alerting—building a complete pipeline from model integration to production operations. When selecting a solution, enterprises should comprehensively evaluate model capability, inference cost, data compliance, and operational complexity, rather than simply chasing parameter scale.
7. Deployment Practices and Engineering Recommendations
For teams planning to privately deploy this class of MoE models, the following engineering lessons are worth referencing:
Hardware planning: although only 21 billion parameters are activated per token, inference still requires loading the full 236 billion parameter weights. A multi-GPU distributed inference setup combining tensor parallelism and expert parallelism is recommended. If memory is constrained, quantization techniques (e.g., 8-bit/4-bit weight quantization) can compress memory usage, but their impact on accuracy must be evaluated.
Domestic compute adaptation (relevant for organizations operating in China): the model has been adapted for Chinese AI processor platforms and published on related communities, supporting one-click access and out-of-the-box use. Multiple cloud providers have also completed cloud integration of the full model series, supporting online trials, API access, and one-click deployment on dedicated resources within minutes. This provides a viable path for deployments in compliance-sensitive environments.
Long-context optimization: when enabling a 128K context, KV cache management remains critical. MLA itself already compresses the cache substantially; engineering-wise, PagedAttention-style paged memory management and prefix cache reuse can further improve throughput.
Routing monitoring: in production environments, it is advisable to monitor expert load distribution and routing entropy to promptly detect anomalies such as load skew or routing collapse.
8. Conclusion and Outlook
The technical approach represented by MLA plus fine-grained MoE demonstrates that architectural innovation has greater leverage than simply stacking more parameters: low-rank compression of attention solves the memory bottleneck, sparse activation solves the compute bottleneck, and together they reduce the training and inference costs of hundred-billion-parameter models to unprecedented levels—while a strikingly aggressive pricing strategy reshaped cost expectations across the entire LLM market.
Looking ahead, sparse, low-rank, and modular architectural ideas will remain mainstream directions, and the coordinated development of open-source ecosystems and diversified compute platforms will further push LLM technology from “an arms race among a few vendors” toward “infrastructure for the entire industry.” For developers, understanding these underlying architectural principles offers far more long-term value than chasing version updates of any single model.
