kernels-bot commited on
Commit
fe2c5b8
·
verified ·
1 Parent(s): bdb8213

Uploaded using `kernel-builder`.

Browse files
Files changed (1) hide show
  1. README.md +35 -2
README.md CHANGED
@@ -11,7 +11,7 @@ This is the repository card of kernels-community/flash-attn2 that has been pushe
11
  # make sure `kernels` is installed: `pip install -U kernels`
12
  from kernels import get_kernel
13
 
14
- kernel_module = get_kernel("kernels-community/flash-attn2", version=3)
15
  flash_attn_func = kernel_module.flash_attn_func
16
 
17
  flash_attn_func(...)
@@ -25,12 +25,45 @@ flash_attn_func(...)
25
  - `flash_attn_varlen_kvpacked_func`
26
  - `flash_attn_varlen_qkvpacked_func`
27
  - `flash_attn_with_kvcache`
 
28
  - `fwd`
29
  - `varlen_fwd`
30
  - `bwd`
31
  - `varlen_bwd`
32
  - `fwd_kvcache`
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  ## Benchmarks
35
 
36
- Benchmarking script is available for this kernel. Run `kernels benchmark kernels-community/flash-attn2 --version 3`.
 
11
  # make sure `kernels` is installed: `pip install -U kernels`
12
  from kernels import get_kernel
13
 
14
+ kernel_module = get_kernel("kernels-community/flash-attn2", version=4)
15
  flash_attn_func = kernel_module.flash_attn_func
16
 
17
  flash_attn_func(...)
 
25
  - `flash_attn_varlen_kvpacked_func`
26
  - `flash_attn_varlen_qkvpacked_func`
27
  - `flash_attn_with_kvcache`
28
+ - `flash_attn_interface`
29
  - `fwd`
30
  - `varlen_fwd`
31
  - `bwd`
32
  - `varlen_bwd`
33
  - `fwd_kvcache`
34
 
35
+ ## Low-level ops
36
+
37
+ `flash_attn_interface` is part of the public API and mirrors the upstream
38
+ `flash_attn.flash_attn_interface` module. Besides the high-level functions,
39
+ these four functions are supported entry points:
40
+
41
+ - `flash_attn_interface._flash_attn_forward`
42
+ - `flash_attn_interface._flash_attn_backward`
43
+ - `flash_attn_interface._flash_attn_varlen_forward`
44
+ - `flash_attn_interface._flash_attn_varlen_backward`
45
+
46
+ The upstream `_wrapped_*` aliases of these four functions are available as
47
+ well. They are Torch custom ops with upstream's signatures. They have no autograd,
48
+ always return the softmax LSE, and are traceable by `torch.compile`. Use them
49
+ when you need the LSE or drive the backward pass yourself, for instance in
50
+ ring or context-parallel attention. The names keep their upstream leading
51
+ underscore so code written against the `flash_attn` package ports unchanged.
52
+
53
+ Dropout is supported. The CUDA build uses the Torch stable ABI and cannot read
54
+ the CUDA generator itself, so the forward is handed a generator and reserves
55
+ its Philox seed and offset through the dispatcher, exactly as the non-stable
56
+ build did. Masks are therefore bit-identical to earlier kernel versions and to
57
+ the pip `flash_attn` package for the same `torch.manual_seed`, including under
58
+ activation checkpointing and CUDA graph capture.
59
+
60
+ Torch 2.10 to 2.12 cannot pass a generator through the stable ABI. There the
61
+ kernel draws its seed and offset from the default generator instead, which is
62
+ reproducible under `torch.manual_seed` but not bit-identical to other Torch
63
+ versions, and the `gen` argument of `fwd`/`varlen_fwd` raises a `ValueError`.
64
+
65
+ `return_softmax` requires `dropout_p > 0`.
66
+
67
  ## Benchmarks
68
 
69
+ Benchmarking script is available for this kernel. Run `kernels benchmark kernels-community/flash-attn2 --version 4`.