AB
AiBoss
project

FlashMLA - DeepSeek's open-source, high-efficiency MLA decoding kernel, designed specifically for Hopper architecture GPUs.

FlashMLA is an open-source, high-efficiency MLA (Multi-Head Linear Attention) decoding kernel from DeepSeek, optimized for NVIDIA Hopper architecture GPUs and designed specifically for handling variable-length sequences. It optimizes key-value pairs...

What is FlashMLA?

FlashMLA is an open-source, high-efficiency MLA (Multi-Head Linear Attention) decoding kernel from DeepSeek, optimized for NVIDIA Hopper architecture GPUs and designed specifically for handling variable-length sequences. It improves memory and computational efficiency through optimized key-value caching and the adoption of the BF16 data format. On an H800 SXM5 GPU, FlashMLA achieves a memory bandwidth of up to 3000 GB/s and computational performance of up to 580 TFLOPS.

FlashMLA's design is inspired by FlashAttention 2 & 3 and the Cutlass project, supporting techniques such as pagination caching and low-rank compression, further optimizing memory management and computational performance. It is suitable for inference tasks in Large Language Models (LLMs) and performs exceptionally well in Natural Language Processing (NLP) scenarios requiring efficient decoding. Developers can install it via a simple command (…).python setup.py installQuickly deploy and run benchmark test scripts.python tests/test_flash_mla.pyVerify performance.

Main functions of FlashMLA

  • BF16 Precision SupportSupports BF16 data format, balancing performance and efficiency.
  • Paged Key-Value CacheIt adopts a page-based key-value caching mechanism with a block size of 64, enabling more granular memory management.
  • Ultimate performanceOn the H800 SXM5 GPU, FlashMLA can achieve a bandwidth of 3000 GB/s in memory-constrained scenarios and a computing power of 580 TFLOPS in compute-constrained scenarios.

FlashMLA Technical Principles

  • Block scheduling and parallel computingThrough a block scheduling mechanism, FlashMLA can decompose computing tasks into multiple small blocks for parallel processing, making full use of the GPU's parallel computing capabilities.
  • Optimized memory access modeFlashMLA significantly improves performance when processing large-scale data by optimizing memory access patterns and reducing memory access overhead.

How to use FlashMLA

  • Environmental preparationFlashMLA requires the following hardware and software environment:
    • hardwareNVIDIA Hopper architecture GPUs (such as the H800 SXM5).
    • softwareCUDA 12.3 or later; PyTorch 2.0 or later.
  • Install FlashMLAInstall FlashMLA using the following command:
python setup.py install
  • Run benchmark testsAfter installation, you can run the following command to perform a performance test: (This script will verify the performance of FlashMLA in the current environment, such as on an H800 SXM5 GPU, it can achieve a bandwidth of 3000 GB/s under memory-constrained configuration and a computing power of 580 TFLOPS under compute-constrained configuration.)
python tests/test_flash_mla.py
  • Using FlashMLAThe following is a typical code example for using FlashMLA:
from flash_mla import get_mla_metadata, flash_mla_with_kvcache

# 获取元数据和分块信息
tile_scheduler_metadata, num_splits = get_mla_metadata(cache_seqlens, s_q * h_q // h_kv, h_kv)
# 在多层解码中调用 FlashMLA
for i in
range(num_layers):
 o_i, lse_i = flash_mla_with_kvcache(
 q_i, kvcache_i, block_table, cache_seqlens, dv,
 tile_scheduler_metadata, num_splits, causal=True
)
  • More detailsThe complete code and documentation can be viewed in the GitHub repository.

FlashMLA project address

Application scenarios of FlashMLA

  • Natural Language Processing (NLP) TasksFlashMLA is suitable for natural language processing tasks requiring efficient decoding, such as machine translation, text generation, sentiment analysis, and question answering systems. It is optimized for variable-length sequences, significantly improving inference efficiency.
  • Large Language Model (LLM) InferenceFlashMLA is designed specifically for inference scenarios involving large language models. By optimizing key-value caching and parallel decoding mechanisms, it reduces hardware resource requirements while improving inference speed.
  • Real-time interactive applicationsIn applications requiring rapid response, such as conversational AI, real-time translation, and content recommendation, FlashMLA provides low-latency inference capabilities, enhancing the user experience.
  • High-performance computing requirementsFlashMLA performs exceptionally well on the H800 SXM5 GPU, with a memory bandwidth of up to 3000 GB/s and a computing performance of up to 580 TFLOPS, making it suitable for high-performance computing tasks.
  • Industry SolutionsFlashMLA can be used for efficient applications in vertical industries such as finance, healthcare, and education. Through customized deployment, it can meet the high-performance requirements of specific industries.