Sparse Activation and KV Compression: How Efficient LLM Inference Architectures Work
Large language models gain capability from scale, but inference cost grows with every parameter and every token of context. This article breaks down two architectural techniques that address this: sparse activation via Mixture of Experts (MoE), which decouples total parameter count from per-token compute, and Multi-head Latent Attention (MLA), which compresses the KV Cache through low-rank projection. It covers routing and load balancing, memory estimation with concrete numbers, the engineering stack behind 128K long-context support, training data considerations, and practical deployment guidance for teams evaluating such models.
I. Background: The Tension Between Parameter Scale and Inference Cost
The capability of large language models correlates strongly with parameter count and training data volume. But as parameters scale up, per-inference compute and memory footprint rise accordingly. For enterprise users, training is a one-time expense, while inference costs accumulate continuously with usage. Reducing the compute cost per token while preserving model capability is therefore one of the core problems in LLM engineering.
This problem can be split into two sub-problems:
- Compute: how many parameters each token passes through during the forward pass.
- Memory: how much memory the intermediate states of past tokens (the KV Cache) consume during inference—especially acute in long-context scenarios.
The architectural approaches covered in this article address each of these. Sparse activation reduces compute, while latent attention compresses the cache.
II. Sparse Activation: Reducing Per-Token Compute with Mixture of Experts
2.1 Dense vs. Sparse Models
In a dense model, every token activates all parameters. The larger the model, the more compute per token.
The Mixture of Experts (MoE) approach splits the feed-forward network into multiple expert sub-networks, with a router selecting a small number of experts for each token while the rest stay idle. This decouples total parameter count from the parameters actually activated per token. Total parameters determine the model’s knowledge capacity; activated parameters determine the compute cost of each inference.
2.2 How Routing Works
The router is typically a small linear layer that scores each expert. After normalization, the top-k highest-scoring experts are selected for computation. The following pseudocode illustrates the process:
function moe_forward(x, experts, router, top_k):logits = router(x) // raw score per expertprobs = softmax(logits) // normalize into probabilities(weights, idx) = topk(probs, top_k) // select top_k expertsweights = weights / sum(weights) // renormalize selected expert weightsout = zeros_like(x)for k in 1..top_k:for each token t:e = idx[t, k]out[t] += weights[t, k] * experts[e](x[t])return out
This code is for illustration only. Real implementations batch together the tokens assigned to the same expert to improve hardware utilization.
2.3 Load Balancing: The Hard Part of Sparse Models
If the router consistently favors a few experts, two problems arise: overloaded experts slow training convergence, while unused experts waste parameters. Common engineering countermeasures include:
- Adding an auxiliary load-balancing term to the training loss that penalizes uneven expert utilization;
- Setting a capacity limit per expert, dropping or rerouting tokens beyond it;
- Introducing shared experts that stay always active to carry general knowledge, reducing duplicated learning across experts.
2.4 Quantifying the Activation Ratio
According to public information, the referenced model has roughly 236 billion total parameters and activates about 21 billion per token—an activation ratio of about 8.9%. This means per-inference compute is close to that of a dense model in the 20-billion range, while knowledge capacity comes from the full parameter pool.
Note that actual latency is also affected by communication overhead, memory bandwidth, and batching strategy; speed cannot be inferred by parameter ratio alone.
III. Latent Attention: Compressing KV Cache Memory Overhead
3.1 Why the KV Cache Becomes a Bottleneck
During autoregressive generation, each new token requires the Key and Value vectors of all previous tokens. To avoid recomputation, these vectors are cached—the KV Cache. Its memory footprint can be roughly estimated as:
Per-sequence KV Cache memory ≈ 2 × layers × per-layer KV dimension × sequence length × bytes per element
The longer the context, the larger the cache. At 128K context, the cache often exceeds the model weights themselves, becoming the main constraint on concurrency and throughput.
3.2 The Low-Rank Compression Idea
The core idea of Multi-head Latent Attention (MLA): instead of caching the full multi-head Keys and Values directly, the hidden state is first projected into a low-dimensional latent vector, and only this latent vector is cached. During attention computation, Keys and Values are reconstructed from it.
This reduces the cache dimension from “heads × head dimension × 2” to the latent dimension, at the cost of some additional up-projection compute. It is a trade of compute for memory.
3.3 A Simplified Implementation Sketch
# Caching stagec_kv = W_down * h // compress the hidden state into a low-dimensional latent vector; only c_kv is cached# Computation stagek = W_up_k * c_kv // reconstruct Key from the latent vectorv = W_up_v * c_kv // reconstruct Value from the latent vector
A real architecture must also handle positional encoding separately. Applying RoPE (Rotary Position Embedding) directly to the compressed Keys interferes with matrix-merging optimizations during inference, so a decoupled positional encoding branch is typically used. This detail is easy to overlook in engineering implementations.
3.4 An Example Memory Estimation
The following uses a set of hypothetical parameters to illustrate the order of magnitude; these values do not represent any actual model’s configuration:
- 60 layers, hidden dimension 5120, half-precision storage (2 bytes per element);
- Standard multi-head attention caches K and V per token per layer: 2 × 5120 = 10,240 elements;
- With a latent dimension of 512, only 512 elements need to be cached per token per layer—a compression ratio of roughly 20x.
At a 128K (131,072) token context, the standard cache is approximately:
60 × 10,240 × 2 bytes × 131,072 ≈ 161 GB
After compression, roughly 8 GB. This estimate covers a single sequence’s cache only, excluding batching and other runtime overhead.
IV. Engineering Requirements for Supporting 128K Long Context
Supporting long contexts typically requires several engineering measures working together:
- Positional encoding extension: adjusting the frequency or interpolation of positional encodings so the model remains stable at positions beyond its training length.
- Long-sequence training: gradually increasing sequence length in the later stages of training so the model learns to locate information across long-range dependencies.
- Attention kernel optimization: using blockwise attention implementations to reduce peak memory from intermediate results.
- Chunked prefill: splitting very long inputs into segments processed sequentially, avoiding filling memory in one shot.
- Paged cache management: dividing the KV Cache into fixed-size blocks allocated on demand, reducing memory fragmentation.
These measures complement each other. Missing any one of them noticeably degrades long-context usability.
V. Training Data and Training Pipeline
5.1 Pretraining
According to public information, the referenced model was pretrained on roughly 8.1 trillion tokens of high-quality, multi-source corpus. Typical data processing includes deduplication, quality filtering, sensitive-content filtering, and deduplication against evaluation sets to avoid inflated benchmark results. The exact corpus composition should be confirmed against the official technical report.
5.2 Supervised Fine-Tuning
After pretraining, the model was fine-tuned on roughly 1.5 million multi-domain dialogue sessions, teaching it to respond in instruction-following formats. The quality and diversity of fine-tuning data directly affect real-world conversational performance.
5.3 Subsequent Alignment
Beyond supervised fine-tuning, common industry practice includes preference alignment steps to improve helpfulness and safety. Public materials describe the specific alignment methods only briefly; readers should verify against the original report.
VI. Interpreting Performance and Efficiency Claims
Public materials offer the following assessments of the referenced model:
- Chinese-language overall capability ranks in the top tier domestically in China;
- English capability is comparable to 70B-class dense open-source models;
- On training efficiency, the materials cite roughly 5x that of a 70B dense model and about 20x that of a certain closed-source flagship model.
These figures depend on specific benchmarks and cost accounting. Testing conditions vary significantly across teams, so always verify the original report’s test setup before citing; do not treat them as universal conclusions.
VII. Selection and Deployment Recommendations
7.1 Define Your Business Metrics First
Before choosing a model, establish your core metrics: time to first token, overall throughput, cost per request, and the context length you actually need. These metrics often trade off against each other—for example, raising concurrency typically increases per-request latency.
7.2 Estimate Memory Requirements
Sparse activation reduces compute, not memory. All expert parameters still need to reside in GPU memory (or be distributed across multiple GPUs) at inference time. The following example computes the memory floor for weights alone:
function estimate_weight_memory_gib(total_params_billion, bytes_per_param):total_bytes = total_params_billion * 1e9 * bytes_per_paramreturn total_bytes / (1024 * 1024 * 1024)estimate_weight_memory_gib(236, 2) // roughly 440 GiB at half precision
Real deployments must also reserve space for the KV Cache, activations, and communication buffers. Weight memory is only a lower bound.
7.3 Build a Business-Relevant Evaluation Set
Generic leaderboard scores do not directly reflect business performance. Build an evaluation set tailored to your own scenarios, and separately test information retrieval and localization in long documents. Evaluation samples should cover your real input length distribution, not just short texts.
7.4 Typical Inference Service Components
An inference service typically includes:
- Container platform: handles resource scheduling and elastic scaling;
- Object storage: stores model weights, evaluation data, and log samples;
- Logging, monitoring, and alerting: tracks latency, memory usage, and error rates with threshold-based alerts;
- Batching and cache management: dynamically forms batches based on request length to reduce idle compute.
VIII. Limitations and Caveats
- Sparse routing can be unstable on out-of-distribution inputs; test thoroughly on your target domain;
- Low-rank compression adds up-projection compute, offering limited benefit in short-context scenarios;
- Usable context length is not the same as comprehension quality—separately evaluate reasoning and citation ability on long texts;
- Public performance and efficiency figures should be verified against original reports to avoid distortions from repeated retelling;
- Compression techniques such as quantization and distillation interact with sparse architectures and latent attention; revalidate results after any changes.
