Efficient inference of Multi-Head Latent Attention (MLA) is challenged by deploying the DeepSeek-R1 671B model on a single Multi-GPU server. This paper introduces FlashMLA-ETAP, a novel framework that enhances MLA inference for the single-instance deployment scenario on NVIDIA H20 GPUs. We propose the Efficient Transpose Attention Pipeline (ETAP), which reconfigures attention computation through transposition to align the KV context length with the \(M\)-dimension in WGMMA operations, significantly reducing redundant computations. FlashMLA-ETAP achieves a 2.78x speedup over FlashMLA at 64K sequence length (batch size 16), with 5.24x and 4.94x improvements over FlashAttention-3 and FlashInfer, respectively, while maintaining numerical stability with a 15.2x lower RMSE (\(1.25 \times 10^{-5}\)) than FlashAttention-3. Furthermore, ETAP's design enables seamless integration into frameworks like FlashAttention-3 and FlashInfer, supported by a detailed theoretical analysis. Our work addresses a critical gap in resource-constrained inference, offering a scalable solution for mid-tier GPUs and paving the way for broader adoption in hardware-aware optimization. Code is available at https://github.com/pengcuo/FlashMLA-ETAP.
翻译:多头潜在注意力(MLA)的高效推理面临在单台多GPU服务器上部署DeepSeek-R1 671B模型的挑战。本文提出FlashMLA-ETAP,一种在NVIDIA H20 GPU上增强单实例部署场景下MLA推理性能的新型框架。我们提出了高效转置注意力流水线(ETAP),通过转置重构注意力计算,使得KV上下文长度与WGMMA操作中的\(M\)维度对齐,从而显著减少冗余计算。在序列长度64K(批大小16)下,FlashMLA-ETAP相较FlashMLA实现了2.78倍加速,相较于FlashAttention-3和FlashInfer分别提升了5.24倍和4.94倍,同时保持数值稳定性,其均方根误差(RMSE)比FlashAttention-3低15.2倍(\(1.25 \times 10^{-5}\))。此外,ETAP的设计使其能够无缝集成到FlashAttention-3和FlashInfer等框架中,并辅以详细的理论分析。我们的工作填补了资源受限推理场景中的关键空白,为中端GPU提供了可扩展的解决方案,并为硬件感知优化开辟了更广泛的应用前景。代码开源地址:https://github.com/pengcuo/FlashMLA-ETAP。