FlashAttention-3 forward kernels packaged for SGLang
Maintained. Last release 3 weeks ago, commits in 2 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install sgl-fa3README as published on PyPI with version 0.1.0.
sgl-fa3
The FlashAttention-3 forward kernels SGLang
serves with, packaged as a standalone wheel. Until this package existed they
were compiled into sglang-kernel as sgl_kernel.flash_ops.
The kernels come from ../hopper in this repository; this directory holds the
torch op registration, the Python wrapper, the tests and the wheel build script.
The build image, the wheel retag script and the release index script live in
sgl-project/sglang, next to those of the other SGLang-built wheels.
What is built
-
Forward only (
FLASHATTENTION_DISABLE_BACKWARD); sparse mask kernels off by default. -
Only the variants SGLang reaches, so the wheel stays under PyPI's file size limit:
- no append-KV / rotary path (
FLASHATTENTION_DISABLE_APPENDKV): SGLang writes the KV cache itself; - split, non-TMA paged and softcap kernels for varlen only
(
FLASHATTENTION_VARLEN_ONLY_SPLIT_PAGED_SOFTCAP); a dense call that needs one is run as varlen with a full-lengthseqused_k, which gives the same result; - no Q/K 64 with V 256 (
FLASHATTENTION_DISABLE_HDIMDIFF64_256); absorbed MLA uses V 512.
Calls that need a compiled-out variant raise instead of running something else.
- no append-KV / rotary path (
-
sm_90a, plussm_80/sm_86(A100, A10, L40, 4090). No SM100+ targets. -
BF16, FP16 and FP8 (E4M3).
-
x86_64 Linux, CUDA 13.0 (
+cu130), one abi3 wheel for CPython 3.10+. -
Pinned to
torch==2.14.1: the extension uses the regular torch C++ ABI, so a release only loads against the torch it was built with.
Usage
from sgl_fa3 import flash_attn_varlen_func, flash_attn_with_kvcache, get_scheduler_metadata
The ops are registered as torch.ops.sgl_fa3.fwd and
torch.ops.sgl_fa3.get_scheduler_metadata.
Building
sgl_fa3/scripts/build.sh 3.10 13.0 /path/to/sglang