Skip to main content

FlashMLA (SGLang fork)

A fork of deepseek-ai/FlashMLA, packaged as a standalone wheel for SGLang.

It differs from upstream in three ways:

  • Upstream's current kernels are carried verbatim. csrc/ is a byte-for-byte copy of upstream's NVIDIA sources, so syncing is a directory replacement rather than a merge. The Huawei Ascend NPU target is not carried.
  • The kernels upstream dropped are kept. Upstream's 2026.09.30 release removed Hopper (SM90), dense MLA decoding, and the V3.2 / V3.2-no-RoPE / V4 KV cache formats. SGLang still serves all of them, so they live on in csrc_legacy/ as a frozen snapshot, built as a second extension with its own op namespace. See csrc_legacy/README.md.
  • One Python surface for both. Every entry point takes use_legacy=False; passing True routes the same call to the frozen kernels. There is no separate compatibility module.

Upstream's documentation of the kernels themselves — KV cache formats, the indices tensor, the fused norm-RoPE-attn-RoPE-cast kernel and its weight permutation — still applies and is not duplicated here.

Requirements

  • CUDA 13.1 and above. CUDA 13.2+ is recommended: it provides the native cvt.rn.bf16x2 conversions the quantized decoding kernels use, and without them they fall back to a slower widening through FP32.
  • PyTorch 2.10 and above.
  • An SM100 / SM103 GPU for the current kernels; the frozen kernels additionally cover SM90.

Wheels are built against PyTorch's stable C++ ABI and CPython's Limited API (abi3, CPython 3.10+), so one wheel serves every PyTorch 2.10+ and CPython 3.10+ combination, subject to the GPU architectures compiled into it.

Installation

git clone https://github.com/sgl-project/FlashMLA.git flash-mla
cd flash-mla
git submodule update --init --recursive
pip install -v . --no-build-isolation

--no-build-isolation is required: setup.py imports torch while building, and this repository does not declare it as a PEP 518 build requirement.

Install ninja first, and make sure it is on PATH as an executable. Without it PyTorch falls back to the distutils backend, which ignores MAX_JOBS and compiles a couple of translation units at a time — minutes become hours, and the only sign is one line of warning early in the log.

Build-time switches:

variable default effect
FLASH_MLA_BUILD_LEGACY 1 Build the frozen csrc_legacy/ extension. 0 ships only the current kernels; use_legacy=True then raises.
FLASH_MLA_BUILD_DENSE_PREFILL 0 Build the CUTLASS dense FMHA prefill/backward. It is half the extension's object code for an op SGLang never calls, so it is off by default; the ops stay registered and raise if called.
FLASH_MLA_SKIP_REG_SPILL_CHECK unset Skip the post-build register-spill check. A debugging escape hatch; released wheels are built with the check on.
NVCC_THREADS 32 nvcc --threads.

After the build, a register-spill check runs over the produced .so. CUTLASS kernels are exempt; if any kernel defined by this repository spills, the build fails.

Tests

python tests/test-sparse-prefill.py
python tests/test-sparse-decode.py
python tests/test-fused-norm-rope-attn-rope-cast.py

The fused-kernel test additionally needs TileLang, Tile-Kernels and DeepGEMM. Tests for the frozen kernels live in tests/legacy/.

Acknowledgement

FlashMLA is DeepSeek's work, inspired by the FlashAttention 2&3 and CUTLASS projects.

@misc{flashmla2025,
      title={FlashMLA: Efficient Multi-head Latent Attention Kernels},
      author={Jiashi Li and Shengyu Liu and Yuanhang Sun},
      year={2025},
      publisher = {GitHub},
      howpublished = {\url{https://github.com/deepseek-ai/FlashMLA}},
}

Metadata

Release files for sgl-flash-mla 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for sgl-flash-mla 1.0.0
File Interpreter ABI Platform
sgl_flash_mla-1.0.0-cp310-abi3-manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
sgl_flash_mla-1.0.0-cp310-abi3-manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details

Total release size: 19.6 MB

Release files / sgl_flash_mla-1.0.0-cp310-abi3-manylinux2014_x86_64.whl

Download URL sgl_flash_mla-1.0.0-cp310-abi3-manylinux2014_x86_64.whl
Size 9.9 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
95d2761376337af4568dbadedc1807b0d90e4d8383c63fa859518a34937392b3
BLAKE2b-256 checksum
How to use checksums
a9f1f349cde7a0ed3a1ce36f82c9caad3ea5321cd300b61e3971021569058d54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / sgl_flash_mla-1.0.0-cp310-abi3-manylinux2014_aarch64.whl

Download URL sgl_flash_mla-1.0.0-cp310-abi3-manylinux2014_aarch64.whl
Size 9.7 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
f0343ebca376ec11868d61848137f05786710672d7329a5ec1c1c902301b0ca3
BLAKE2b-256 checksum
How to use checksums
b78981e306103e0943f3ff1aeffa82f766a1fa9d55c100db133041d289d8d1e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for sgl-flash-mla 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page