Views
No views yet
| GPU | Compute Capability |
|---|---|
| A100 | sm_80 |
| A10 / A30 | sm_86 |
| Ada / L40 | sm_89 |
pip install kernels1import torch
2from kernels import get_kernel
3
4fa2 = get_kernel("pranay5255/flash-attn-v2-ampere")
5
6# Tensor layout: [batch, seqlen, num_heads, head_dim]
7q = torch.randn(2, 1024, 8, 64, dtype=torch.float16, device="cuda")
8k = torch.randn(2, 1024, 8, 64, dtype=torch.float16, device="cuda")
9v = torch.randn(2, 1024, 8, 64, dtype=torch.float16, device="cuda")
10
11# Standard forward pass
12out = fa2.forward(q, k, v)
13
14# With causal mask
15out = fa2.forward(q, k, v, is_causal=True)
16
17# With custom softmax scale
18out = fa2.forward(q, k, v, softmax_scale=0.125)fa2.forward(q, k, v, ...)| Parameter | Type | Default | Description |
|---|---|---|---|
q, k, v | torch.Tensor | required | Shape [batch, seqlen, num_heads, head_dim]. Must be contiguous, on CUDA. |
softmax_scale | float | 1/sqrt(head_dim) | Scale applied before softmax. |
is_causal | bool | False | Apply causal (upper-triangular) mask. |
m_block_size | int | 128 | Tile size for the Q dimension. |
n_block_size | int | 64 | Tile size for the K/V dimension. |
num_threads | int | 128 | Threads per CTA. |
out | torch.Tensor | None | Optional pre-allocated output. |
torch.Tensor of shape [batch, seqlen_q, num_heads, head_dim], same dtype as input.torch.float16, torch.bfloat16head_dim must be a multiple of 8 (16-byte alignment).1[general]
2name = "flash_attn_v2_ampere"
3backends = ["cuda"]
4
5[kernel.flash_attn_v2]
6backend = "cuda"
7src = ["kernel_src/flash_attention_v2.cu"]
8cuda-capabilities = ["8.0"]