Overview
TyphoonMLA is a hybrid attention kernel designed to supercharge Large Language Model (LLM) inference for architectures utilizing Multi-Head Latent Attention (MLA), such as DeepSeek-v3 and Kimi K2. By strategically mixing two different mathematical formulations of MLA—"naive" for shared prefixes and "absorb" for unique user content—it achieves up to a 3.24x speedup in attention throughput with a negligible 3% memory overhead.
The Bottleneck in Multi-Head Latent Attention
Modern LLMs increasingly use MLA to reduce the massive memory footprint of the KV-cache (the roadmap of previous tokens the model needs to reference). MLA allows for two distinct implementation styles:
- Naive: Keeps the cache uncompressed. It is computationally efficient but creates a severe memory bandwidth bottleneck during standard decoding.
- Absorb: Keeps the cache compressed. It saves memory bandwidth but requires significantly more mathematical operations (FLOPs) to process.
Current state-of-the-art kernels, like FlashMLA, default to the Absorb method because decoding is usually limited by memory retrieval speeds. However, the authors identify a massive missed opportunity: Shared Prefixes.
In scenarios like long system prompts (which can span tens of thousands of tokens), parallel reasoning (Tree-of-Thought), or speculative decoding, many queries attend to the exact same data. In these compute-bound scenarios, the Absorb method's high operation count becomes a bottleneck, and its memory-saving benefits are wasted on data that is already being heavily reused.
TyphoonMLA: A Hybrid Approach
To solve this inefficiency, the authors introduce TyphoonMLA, a hybrid kernel that partitions the attention calculation based on data reuse.
- The Naive Path for Shared Prefixes: For the part of the KV-cache shared across the batch (like a long system prompt), TyphoonMLA uses the naive formulation. Since this data is read once and reused many times, the bottleneck shifts from memory speed to raw computation. The naive approach requires fewer operations per token, making it much faster here.
- The Absorb Path for Unique Tokens: For the "non-shared" part of the cache (the specific conversation history of each user), the kernel uses the absorb formulation. This keeps the unique data compressed, minimizing memory bandwidth usage where it matters most.
- The Merge: The results from both paths are combined using a "CombineLSE" function—similar to the logic used in FlashAttention—to ensure mathematical equivalence to standard MLA.
- Dynamic Fallback: The kernel includes a "break-even" logic. If the batch size is too small to benefit from data reuse, it automatically falls back to a pure Absorb implementation to avoid performance penalties.
Performance and Insights
The authors evaluated TyphoonMLA using queries drawn from MMLU, GSM8K, and SimpleQA, simulating various real-world system prompt lengths (such as the ~26k token Claude-4 system prompt).
- Eliminating the "Absorb" Tax: While the absorption trick is famous for saving memory, it increases the total number of multiply-accumulate operations (MACs). The paper highlights that when data is shared, models should stop paying this computational "tax."
- Compute vs. Memory Bound: Using Roofline models, the paper provides a rigorous theoretical analysis showing exactly when the bottleneck shifts. For DeepSeek-v3 on an Ascend NPU, the "break-even" point where the hybrid approach starts winning is a batch size of 61.
- Throughput Gains: TyphoonMLA achieved attention throughput speedups of up to 3x on Huawei Ascend NPUs and 3.24x on NVIDIA GPUs compared to existing state-of-the-art kernels like FlashMLA. For a full DeepSeek-v3 model, it boosted total end-to-end token generation throughput by up to 1.48x.
- Zero Accuracy Loss: Because the method is mathematically identical to standard MLA, it requires no retraining or fine-tuning, acting as a "drop-in" optimization.
Limitations and Future Directions
These impressive gains come at the cost of only a 3% increase in HBM (memory) usage, as only the shared prefix needs to be stored in its uncompressed form. However, in extremely memory-constrained environments, this slight trade-off might be a factor.
Additionally, the performance gain is directly tied to the length of the shared prefix and the batch size. If every user has a completely unique prompt with no shared components, TyphoonMLA behaves exactly like a standard Absorb kernel. Future work suggests extending this logic to handle more complex "tree-structured" KV-caches, which are common in advanced sampling techniques like Beam Search or Medusa-style speculative decoding.
Summary updated