This is the repository card of kernels-community/flash-attn2 that has been pushed on the Hub. It was built to be used with the kernels library. This card was automatically generated.

How to use

# make sure `kernels` is installed: `pip install -U kernels`
from kernels import get_kernel

kernel_module = get_kernel("kernels-community/flash-attn2", version=4)
flash_attn_func = kernel_module.flash_attn_func

flash_attn_func(...)

Available functions

  • flash_attn_func
  • flash_attn_kvpacked_func
  • flash_attn_qkvpacked_func
  • flash_attn_varlen_func
  • flash_attn_varlen_kvpacked_func
  • flash_attn_varlen_qkvpacked_func
  • flash_attn_with_kvcache
  • flash_attn_interface
  • fwd
  • varlen_fwd
  • bwd
  • varlen_bwd
  • fwd_kvcache

Low-level ops

flash_attn_interface is part of the public API and mirrors the upstream flash_attn.flash_attn_interface module. Besides the high-level functions, these four functions are supported entry points:

  • flash_attn_interface._flash_attn_forward
  • flash_attn_interface._flash_attn_backward
  • flash_attn_interface._flash_attn_varlen_forward
  • flash_attn_interface._flash_attn_varlen_backward

The upstream _wrapped_* aliases of these four functions are available as well. They are Torch custom ops with upstream's signatures. They have no autograd, always return the softmax LSE, and are traceable by torch.compile. Use them when you need the LSE or drive the backward pass yourself, for instance in ring or context-parallel attention. The names keep their upstream leading underscore so code written against the flash_attn package ports unchanged.

Dropout is supported. The CUDA build uses the Torch stable ABI and cannot read the CUDA generator itself, so the forward is handed a generator and reserves its Philox seed and offset through the dispatcher, exactly as the non-stable build did. Masks are therefore bit-identical to earlier kernel versions and to the pip flash_attn package for the same torch.manual_seed, including under activation checkpointing and CUDA graph capture.

Torch 2.10 to 2.12 cannot pass a generator through the stable ABI. There the kernel draws its seed and offset from the default generator instead, which is reproducible under torch.manual_seed but not bit-identical to other Torch versions, and the gen argument of fwd/varlen_fwd raises a ValueError.

return_softmax requires dropout_p > 0.

Benchmarks

Benchmarking script is available for this kernel. Run kernels benchmark kernels-community/flash-attn2 --version 4.

Downloads last month
9,299
bsd-3-clause
Supported hardwares new
CUDA
8.09.010.012.0
GPU
B300
288GB
DGX Spark
GB10
128GB
GPU
RTX PRO 6000 WS
96GB
GPU
RTX PRO 6000 Max-Q
96GB
GPU
RTX PRO 5000
48GB
GPU
RTX PRO 4500 WS
32GB
RTX
RTX 5090
32GB
RTX
RTX 5090 D
32GB
GPU
RTX PRO 4000
24GB
GPU
RTX PRO 4000 SFF
24GB
RTX
RTX 5090 Mobile
24GB
GPU
RTX PRO 2000
16GB
RTX
RTX 5080
16GB
RTX
RTX 5080 Mobile
16GB
RTX
RTX 5070 Ti
16GB
RTX
RTX 5060 Ti
16GB
RTX
RTX 5070
12GB
RTX
RTX 5070 Ti Mobile
12GB
RTX
RTX 5070 Mobile
8GB
RTX
RTX 5060
8GB
RTX
RTX 5060 Mobile
8GB
RTX
RTX 5050
8GB
RTX
RTX 5050 Mobile
8GB
NVIDIA SXM
B200
192GB
NVIDIA SXM
H200
141GB
GPU
H20
96GB
GPU
RTX 5880 Ada
48GB
GPU
RTX 2000 Ada
16GB
RTX
RTX 4080 SUPER
16GB
RTX
RTX 4070 Ti Super
16GB
RTX
RTX 4070 Super
12GB
GPU
H800
80GB
GPU
L40s
48GB
GPU
L20
48GB
RTX
RTX 4090D
24GB
RTX
RTX 5000 Ada
32GB
GPU
L4
24GB
GPU
RTX 4500 Ada
24GB
RTX
RTX 4000 Ada
20GB
RTX
RTX 4000 SFF Ada
20GB
RTX
RTX 4090 Mobile
16GB
RTX
RTX 4060 Ti
8GB
RTX
RTX 4090 Laptop
16GB
Jetson
Jetson Orin NX 16GB
16GB
GPU
RTX 3500 Ada Mobile
12GB
RTX
RTX 4080 Mobile
12GB
RTX
RTX 4070
12GB
RTX
RTX 4070 Ti
12GB
RTX
RTX 4080 Laptop
12GB
RTX
RTX 4070 Mobile
8GB
RTX
RTX 4060
8GB
RTX
RTX 4070 Laptop
8GB
RTX
RTX 4060 Laptop
8GB
Jetson
Jetson Orin NX 8GB
8GB
Jetson
Jetson Orin Nano 8GB
8GB
RTX
RTX 4050 Laptop
6GB
Jetson
Jetson Orin Nano 4GB
4GB
NVIDIA SXM
H100
80GB
GPU
A800
40GB
Jetson
Jetson AGX Orin 64GB
64GB
GPU
L40
48GB
GPU
RTX 6000 Ada
48GB
Jetson
Jetson AGX Orin 32GB
32GB
RTX
RTX 4090
24GB
RTX
RTX 3090 Ti
24GB
RTX
RTX 4080
16GB
RTX
RTX 3070 Ti Mobile
8GB
RTX
RTX 3050
8GB
RTX
RTX 3050 Mobile
4GB
GPU
RTX A2000 Embedded
4GB
GPU
RTX A5000
8GB
GPU
A30
24GB
GPU
A10
24GB
GPU
RTX A5000 Max-Q
16GB
GPU
RTX A5000 Mobile
16GB
GPU
RTX A4000
16GB
GPU
A2
16GB
RTX
RTX 3080 Mobile
16GB
GPU
RTX A3000 Mobile
6GB
GPU
RTX A2000
6GB
RTX
RTX 3080 Ti
12GB
RTX
RTX 3060
12GB
GPU
RTX A4000 Max-Q
8GB
GPU
RTX A4000 Mobile
8GB
GPU
RTX A2000 Max-Q
4GB
GPU
RTX A2000 Mobile
4GB
RTX
RTX 3070 Ti
8GB
RTX
RTX 3060 Mobile
6GB
GPU
RTX 2050 Mobile
4GB
GPU
A100
80GB
GPU
RTX A6000
48GB
GPU
A40
48GB
RTX
RTX 3090
24GB
RTX
RTX 3080
12GB
RTX
RTX 3070
8GB
RTX
RTX 3060 Ti
8GB
XPU
Intel Arc
Arc Pro B70
32GB
Intel Arc
Arc B60
24GB
Intel Arc
Arc B50
16GB
Intel Arc
Arc B570
10GB
Intel Arc
Arc B580
12GB
Intel Arc
Arc A770
8GB
Intel Arc
Arc A750
8GB
Intel Arc
Arc A380
6GB
OS
linux
Arch
x86_64aarch64
Kernel Builder
d054906