Kernels:
Trusted publisher
Uploaded using `kernel-builder`.
Browse files- build/torch-stable-abi210-cu126-aarch64-linux/__init__.py +424 -0
- build/torch-stable-abi210-cu126-aarch64-linux/_flash_attn2_cuda_460047c.abi3.so +3 -0
- build/torch-stable-abi210-cu126-aarch64-linux/_ops.py +9 -0
- build/torch-stable-abi210-cu126-aarch64-linux/flash_attn_interface.py +1708 -0
- build/torch-stable-abi210-cu126-aarch64-linux/metadata.json +37 -0
- build/torch-stable-abi210-cu126-aarch64-linux/metadata.json.sigstore +1 -0
- build/torch-stable-abi210-cu126-aarch64-linux/symbols.json +1273 -0
- build/torch-stable-abi210-cu128-aarch64-linux/__init__.py +424 -0
- build/torch-stable-abi210-cu128-aarch64-linux/_flash_attn2_cuda_460047c.abi3.so +3 -0
- build/torch-stable-abi210-cu128-aarch64-linux/_ops.py +9 -0
- build/torch-stable-abi210-cu128-aarch64-linux/flash_attn_interface.py +1708 -0
- build/torch-stable-abi210-cu128-aarch64-linux/metadata.json +39 -0
- build/torch-stable-abi210-cu128-aarch64-linux/metadata.json.sigstore +1 -0
- build/torch-stable-abi210-cu128-aarch64-linux/symbols.json +1273 -0
- build/torch-stable-abi210-cu130-aarch64-linux/__init__.py +424 -0
- build/torch-stable-abi210-cu130-aarch64-linux/_flash_attn2_cuda_460047c.abi3.so +3 -0
- build/torch-stable-abi210-cu130-aarch64-linux/_ops.py +9 -0
- build/torch-stable-abi210-cu130-aarch64-linux/flash_attn_interface.py +1708 -0
- build/torch-stable-abi210-cu130-aarch64-linux/metadata.json +39 -0
- build/torch-stable-abi210-cu130-aarch64-linux/metadata.json.sigstore +1 -0
- build/torch-stable-abi210-cu130-aarch64-linux/symbols.json +1273 -0
- build/torch-stable-abi210-cu132-aarch64-linux/__init__.py +424 -0
- build/torch-stable-abi210-cu132-aarch64-linux/_flash_attn2_cuda_460047c.abi3.so +3 -0
- build/torch-stable-abi210-cu132-aarch64-linux/_ops.py +9 -0
- build/torch-stable-abi210-cu132-aarch64-linux/flash_attn_interface.py +1708 -0
- build/torch-stable-abi210-cu132-aarch64-linux/metadata.json +39 -0
- build/torch-stable-abi210-cu132-aarch64-linux/metadata.json.sigstore +1 -0
- build/torch-stable-abi210-cu132-aarch64-linux/symbols.json +1273 -0
- build/torch-stable-abi210-cu134-aarch64-linux/__init__.py +424 -0
- build/torch-stable-abi210-cu134-aarch64-linux/_flash_attn2_cuda_460047c.abi3.so +3 -0
- build/torch-stable-abi210-cu134-aarch64-linux/_ops.py +9 -0
- build/torch-stable-abi210-cu134-aarch64-linux/flash_attn_interface.py +1708 -0
- build/torch-stable-abi210-cu134-aarch64-linux/metadata.json +39 -0
- build/torch-stable-abi210-cu134-aarch64-linux/metadata.json.sigstore +1 -0
- build/torch-stable-abi210-cu134-aarch64-linux/symbols.json +1273 -0
build/torch-stable-abi210-cu126-aarch64-linux/__init__.py
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 |
+
from . import flash_attn_interface
|
| 6 |
+
from ._ops import ops as flash_attn_ops
|
| 7 |
+
from .flash_attn_interface import (
|
| 8 |
+
# helper to set up the Philox random number generator for dropout
|
| 9 |
+
_philox_generator,
|
| 10 |
+
# reexported for convenience to be used in the high-level API functions
|
| 11 |
+
flash_attn_func,
|
| 12 |
+
flash_attn_kvpacked_func,
|
| 13 |
+
flash_attn_qkvpacked_func,
|
| 14 |
+
flash_attn_varlen_func,
|
| 15 |
+
flash_attn_varlen_kvpacked_func,
|
| 16 |
+
flash_attn_varlen_qkvpacked_func,
|
| 17 |
+
flash_attn_with_kvcache,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
__all__ = [
|
| 21 |
+
# High-level API (with autograd support)
|
| 22 |
+
"flash_attn_func",
|
| 23 |
+
"flash_attn_kvpacked_func",
|
| 24 |
+
"flash_attn_qkvpacked_func",
|
| 25 |
+
"flash_attn_varlen_func",
|
| 26 |
+
"flash_attn_varlen_kvpacked_func",
|
| 27 |
+
"flash_attn_varlen_qkvpacked_func",
|
| 28 |
+
"flash_attn_with_kvcache",
|
| 29 |
+
# Upstream interface module. Its `_flash_attn_forward`, `_flash_attn_backward`,
|
| 30 |
+
# `_flash_attn_varlen_forward` and `_flash_attn_varlen_backward` are supported
|
| 31 |
+
# low-level entry points with upstream's signatures: Torch custom ops without
|
| 32 |
+
# autograd that return the LSE and are traceable by torch.compile. The autograd
|
| 33 |
+
# Functions above are built on top of them.
|
| 34 |
+
"flash_attn_interface",
|
| 35 |
+
# Low-level ops (no autograd)
|
| 36 |
+
"fwd",
|
| 37 |
+
"varlen_fwd",
|
| 38 |
+
"bwd",
|
| 39 |
+
"varlen_bwd",
|
| 40 |
+
"fwd_kvcache",
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def fwd(
|
| 45 |
+
q: torch.Tensor,
|
| 46 |
+
k: torch.Tensor,
|
| 47 |
+
v: torch.Tensor,
|
| 48 |
+
out: Optional[torch.Tensor] = None,
|
| 49 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 50 |
+
p_dropout: float = 0.0,
|
| 51 |
+
softmax_scale: Optional[float] = None,
|
| 52 |
+
is_causal: bool = False,
|
| 53 |
+
window_size_left: int = -1,
|
| 54 |
+
window_size_right: int = -1,
|
| 55 |
+
softcap: float = 0.0,
|
| 56 |
+
return_softmax: bool = False,
|
| 57 |
+
gen: Optional[torch.Generator] = None,
|
| 58 |
+
) -> List[torch.Tensor]:
|
| 59 |
+
"""
|
| 60 |
+
Forward pass for multi-head attention.
|
| 61 |
+
|
| 62 |
+
Args:
|
| 63 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 64 |
+
k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 65 |
+
v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 66 |
+
out: Optional output tensor, same shape as q
|
| 67 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 68 |
+
p_dropout: Dropout probability
|
| 69 |
+
softmax_scale: Scale factor for softmax
|
| 70 |
+
is_causal: Whether to use causal attention
|
| 71 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 72 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 73 |
+
softcap: Soft cap for attention weights
|
| 74 |
+
return_softmax: Whether to return softmax weights
|
| 75 |
+
gen: Optional random number generator
|
| 76 |
+
|
| 77 |
+
Returns:
|
| 78 |
+
List of tensors: [output, softmax_lse, (softmax if return_softmax)]
|
| 79 |
+
"""
|
| 80 |
+
if softmax_scale is None:
|
| 81 |
+
attention_head_dim = q.shape[-1]
|
| 82 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 83 |
+
|
| 84 |
+
gen = _philox_generator(q, p_dropout, gen)
|
| 85 |
+
return flash_attn_ops.fwd(
|
| 86 |
+
q,
|
| 87 |
+
k,
|
| 88 |
+
v,
|
| 89 |
+
out,
|
| 90 |
+
alibi_slopes,
|
| 91 |
+
p_dropout,
|
| 92 |
+
softmax_scale,
|
| 93 |
+
is_causal,
|
| 94 |
+
window_size_left,
|
| 95 |
+
window_size_right,
|
| 96 |
+
softcap,
|
| 97 |
+
return_softmax,
|
| 98 |
+
gen,
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def varlen_fwd(
|
| 103 |
+
q: torch.Tensor,
|
| 104 |
+
k: torch.Tensor,
|
| 105 |
+
v: torch.Tensor,
|
| 106 |
+
cu_seqlens_q: torch.Tensor,
|
| 107 |
+
cu_seqlens_k: torch.Tensor,
|
| 108 |
+
out: Optional[torch.Tensor] = None,
|
| 109 |
+
seqused_k: Optional[torch.Tensor] = None,
|
| 110 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 111 |
+
block_table: Optional[torch.Tensor] = None,
|
| 112 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 113 |
+
max_seqlen_q: int = 0,
|
| 114 |
+
max_seqlen_k: int = 0,
|
| 115 |
+
p_dropout: float = 0.0,
|
| 116 |
+
softmax_scale: Optional[float] = None,
|
| 117 |
+
zero_tensors: bool = False,
|
| 118 |
+
is_causal: bool = False,
|
| 119 |
+
window_size_left: int = -1,
|
| 120 |
+
window_size_right: int = -1,
|
| 121 |
+
softcap: float = 0.0,
|
| 122 |
+
return_softmax: bool = False,
|
| 123 |
+
gen: Optional[torch.Generator] = None,
|
| 124 |
+
) -> List[torch.Tensor]:
|
| 125 |
+
"""
|
| 126 |
+
Forward pass for multi-head attention with variable sequence lengths.
|
| 127 |
+
|
| 128 |
+
Args:
|
| 129 |
+
q: Query tensor of shape [total_q, num_heads, head_size]
|
| 130 |
+
k: Key tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 131 |
+
v: Value tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 132 |
+
cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]
|
| 133 |
+
cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]
|
| 134 |
+
out: Optional output tensor of shape [total_q, num_heads, head_size]
|
| 135 |
+
seqused_k: Optional tensor specifying how many keys to use per batch element [batch_size]
|
| 136 |
+
leftpad_k: Optional left padding for keys of shape [batch_size]
|
| 137 |
+
block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]
|
| 138 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 139 |
+
max_seqlen_q: Maximum sequence length for queries
|
| 140 |
+
max_seqlen_k: Maximum sequence length for keys
|
| 141 |
+
p_dropout: Dropout probability
|
| 142 |
+
softmax_scale: Scale factor for softmax
|
| 143 |
+
zero_tensors: Whether to zero tensors before computation
|
| 144 |
+
is_causal: Whether to use causal attention
|
| 145 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 146 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 147 |
+
softcap: Soft cap for attention weights
|
| 148 |
+
return_softmax: Whether to return softmax weights
|
| 149 |
+
gen: Optional random number generator
|
| 150 |
+
|
| 151 |
+
Returns:
|
| 152 |
+
List of tensors: [output, softmax_lse, (softmax if return_softmax)]
|
| 153 |
+
"""
|
| 154 |
+
if softmax_scale is None:
|
| 155 |
+
attention_head_dim = q.shape[-1]
|
| 156 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 157 |
+
|
| 158 |
+
gen = _philox_generator(q, p_dropout, gen)
|
| 159 |
+
return flash_attn_ops.varlen_fwd(
|
| 160 |
+
q,
|
| 161 |
+
k,
|
| 162 |
+
v,
|
| 163 |
+
out,
|
| 164 |
+
cu_seqlens_q,
|
| 165 |
+
cu_seqlens_k,
|
| 166 |
+
seqused_k,
|
| 167 |
+
leftpad_k,
|
| 168 |
+
block_table,
|
| 169 |
+
alibi_slopes,
|
| 170 |
+
max_seqlen_q,
|
| 171 |
+
max_seqlen_k,
|
| 172 |
+
p_dropout,
|
| 173 |
+
softmax_scale,
|
| 174 |
+
zero_tensors,
|
| 175 |
+
is_causal,
|
| 176 |
+
window_size_left,
|
| 177 |
+
window_size_right,
|
| 178 |
+
softcap,
|
| 179 |
+
return_softmax,
|
| 180 |
+
gen,
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def bwd(
|
| 185 |
+
dout: torch.Tensor,
|
| 186 |
+
q: torch.Tensor,
|
| 187 |
+
k: torch.Tensor,
|
| 188 |
+
v: torch.Tensor,
|
| 189 |
+
out: torch.Tensor,
|
| 190 |
+
softmax_lse: torch.Tensor,
|
| 191 |
+
dq: Optional[torch.Tensor] = None,
|
| 192 |
+
dk: Optional[torch.Tensor] = None,
|
| 193 |
+
dv: Optional[torch.Tensor] = None,
|
| 194 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 195 |
+
p_dropout: float = 0.0,
|
| 196 |
+
softmax_scale: Optional[float] = None,
|
| 197 |
+
is_causal: bool = False,
|
| 198 |
+
window_size_left: int = -1,
|
| 199 |
+
window_size_right: int = -1,
|
| 200 |
+
softcap: float = 0.0,
|
| 201 |
+
deterministic: bool = False,
|
| 202 |
+
gen: Optional[torch.Generator] = None,
|
| 203 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 204 |
+
) -> List[torch.Tensor]:
|
| 205 |
+
"""
|
| 206 |
+
Backward pass for multi-head attention.
|
| 207 |
+
|
| 208 |
+
Args:
|
| 209 |
+
dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 210 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 211 |
+
k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 212 |
+
v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 213 |
+
out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 214 |
+
softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]
|
| 215 |
+
dq: Optional gradient tensor for queries, same shape as q
|
| 216 |
+
dk: Optional gradient tensor for keys, same shape as k
|
| 217 |
+
dv: Optional gradient tensor for values, same shape as v
|
| 218 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 219 |
+
p_dropout: Dropout probability
|
| 220 |
+
softmax_scale: Scale factor for softmax
|
| 221 |
+
is_causal: Whether to use causal attention
|
| 222 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 223 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 224 |
+
softcap: Soft cap for attention weights
|
| 225 |
+
deterministic: Whether to use deterministic algorithms
|
| 226 |
+
gen: Optional random number generator
|
| 227 |
+
rng_state: Optional RNG state from forward pass
|
| 228 |
+
|
| 229 |
+
Returns:
|
| 230 |
+
List of tensors: [dq, dk, dv]
|
| 231 |
+
"""
|
| 232 |
+
if softmax_scale is None:
|
| 233 |
+
attention_head_dim = q.shape[-1]
|
| 234 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 235 |
+
|
| 236 |
+
return flash_attn_ops.bwd(
|
| 237 |
+
dout,
|
| 238 |
+
q,
|
| 239 |
+
k,
|
| 240 |
+
v,
|
| 241 |
+
out,
|
| 242 |
+
softmax_lse,
|
| 243 |
+
dq,
|
| 244 |
+
dk,
|
| 245 |
+
dv,
|
| 246 |
+
alibi_slopes,
|
| 247 |
+
p_dropout,
|
| 248 |
+
softmax_scale,
|
| 249 |
+
is_causal,
|
| 250 |
+
window_size_left,
|
| 251 |
+
window_size_right,
|
| 252 |
+
softcap,
|
| 253 |
+
deterministic,
|
| 254 |
+
gen,
|
| 255 |
+
rng_state,
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def varlen_bwd(
|
| 260 |
+
dout: torch.Tensor,
|
| 261 |
+
q: torch.Tensor,
|
| 262 |
+
k: torch.Tensor,
|
| 263 |
+
v: torch.Tensor,
|
| 264 |
+
out: torch.Tensor,
|
| 265 |
+
softmax_lse: torch.Tensor,
|
| 266 |
+
cu_seqlens_q: torch.Tensor,
|
| 267 |
+
cu_seqlens_k: torch.Tensor,
|
| 268 |
+
dq: Optional[torch.Tensor] = None,
|
| 269 |
+
dk: Optional[torch.Tensor] = None,
|
| 270 |
+
dv: Optional[torch.Tensor] = None,
|
| 271 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 272 |
+
max_seqlen_q: int = 0,
|
| 273 |
+
max_seqlen_k: int = 0,
|
| 274 |
+
p_dropout: float = 0.0,
|
| 275 |
+
softmax_scale: Optional[float] = None,
|
| 276 |
+
zero_tensors: bool = False,
|
| 277 |
+
is_causal: bool = False,
|
| 278 |
+
window_size_left: int = -1,
|
| 279 |
+
window_size_right: int = -1,
|
| 280 |
+
softcap: float = 0.0,
|
| 281 |
+
deterministic: bool = False,
|
| 282 |
+
gen: Optional[torch.Generator] = None,
|
| 283 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 284 |
+
) -> List[torch.Tensor]:
|
| 285 |
+
"""
|
| 286 |
+
Backward pass for multi-head attention with variable sequence lengths.
|
| 287 |
+
|
| 288 |
+
Args:
|
| 289 |
+
dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 290 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 291 |
+
k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 292 |
+
v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 293 |
+
out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 294 |
+
softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]
|
| 295 |
+
cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]
|
| 296 |
+
cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]
|
| 297 |
+
dq: Optional gradient tensor for queries, same shape as q
|
| 298 |
+
dk: Optional gradient tensor for keys, same shape as k
|
| 299 |
+
dv: Optional gradient tensor for values, same shape as v
|
| 300 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 301 |
+
max_seqlen_q: Maximum sequence length for queries
|
| 302 |
+
max_seqlen_k: Maximum sequence length for keys
|
| 303 |
+
p_dropout: Dropout probability
|
| 304 |
+
softmax_scale: Scale factor for softmax
|
| 305 |
+
zero_tensors: Whether to zero tensors before computation
|
| 306 |
+
is_causal: Whether to use causal attention
|
| 307 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 308 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 309 |
+
softcap: Soft cap for attention weights
|
| 310 |
+
deterministic: Whether to use deterministic algorithms
|
| 311 |
+
gen: Optional random number generator
|
| 312 |
+
rng_state: Optional RNG state from forward pass
|
| 313 |
+
|
| 314 |
+
Returns:
|
| 315 |
+
List of tensors: [dq, dk, dv]
|
| 316 |
+
"""
|
| 317 |
+
if softmax_scale is None:
|
| 318 |
+
attention_head_dim = q.shape[-1]
|
| 319 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 320 |
+
|
| 321 |
+
return flash_attn_ops.varlen_bwd(
|
| 322 |
+
dout,
|
| 323 |
+
q,
|
| 324 |
+
k,
|
| 325 |
+
v,
|
| 326 |
+
out,
|
| 327 |
+
softmax_lse,
|
| 328 |
+
dq,
|
| 329 |
+
dk,
|
| 330 |
+
dv,
|
| 331 |
+
cu_seqlens_q,
|
| 332 |
+
cu_seqlens_k,
|
| 333 |
+
alibi_slopes,
|
| 334 |
+
max_seqlen_q,
|
| 335 |
+
max_seqlen_k,
|
| 336 |
+
p_dropout,
|
| 337 |
+
softmax_scale,
|
| 338 |
+
zero_tensors,
|
| 339 |
+
is_causal,
|
| 340 |
+
window_size_left,
|
| 341 |
+
window_size_right,
|
| 342 |
+
softcap,
|
| 343 |
+
deterministic,
|
| 344 |
+
gen,
|
| 345 |
+
rng_state,
|
| 346 |
+
)
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
def fwd_kvcache(
|
| 350 |
+
q: torch.Tensor,
|
| 351 |
+
kcache: torch.Tensor,
|
| 352 |
+
vcache: torch.Tensor,
|
| 353 |
+
k: Optional[torch.Tensor] = None,
|
| 354 |
+
v: Optional[torch.Tensor] = None,
|
| 355 |
+
seqlens_k: Optional[torch.Tensor] = None,
|
| 356 |
+
rotary_cos: Optional[torch.Tensor] = None,
|
| 357 |
+
rotary_sin: Optional[torch.Tensor] = None,
|
| 358 |
+
cache_batch_idx: Optional[torch.Tensor] = None,
|
| 359 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 360 |
+
block_table: Optional[torch.Tensor] = None,
|
| 361 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 362 |
+
out: Optional[torch.Tensor] = None,
|
| 363 |
+
softmax_scale: Optional[float] = None,
|
| 364 |
+
is_causal: bool = False,
|
| 365 |
+
window_size_left: int = -1,
|
| 366 |
+
window_size_right: int = -1,
|
| 367 |
+
softcap: float = 0.0,
|
| 368 |
+
is_rotary_interleaved: bool = False,
|
| 369 |
+
num_splits: int = 1,
|
| 370 |
+
) -> List[torch.Tensor]:
|
| 371 |
+
"""
|
| 372 |
+
Forward pass for multi-head attention with KV cache.
|
| 373 |
+
|
| 374 |
+
Args:
|
| 375 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 376 |
+
kcache: Key cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 377 |
+
vcache: Value cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 378 |
+
k: Optional new keys tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]
|
| 379 |
+
v: Optional new values tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]
|
| 380 |
+
seqlens_k: Optional sequence lengths for keys of shape [batch_size]
|
| 381 |
+
rotary_cos: Optional rotary cosine tensor of shape [seqlen_ro, rotary_dim/2]
|
| 382 |
+
rotary_sin: Optional rotary sine tensor of shape [seqlen_ro, rotary_dim/2]
|
| 383 |
+
cache_batch_idx: Optional indices to index into the KV cache
|
| 384 |
+
leftpad_k: Optional left padding for keys of shape [batch_size]
|
| 385 |
+
block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]
|
| 386 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 387 |
+
out: Optional output tensor, same shape as q
|
| 388 |
+
softmax_scale: Scale factor for softmax
|
| 389 |
+
is_causal: Whether to use causal attention
|
| 390 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 391 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 392 |
+
softcap: Soft cap for attention weights
|
| 393 |
+
is_rotary_interleaved: Whether rotary embeddings are interleaved
|
| 394 |
+
num_splits: Number of splits for computation
|
| 395 |
+
|
| 396 |
+
Returns:
|
| 397 |
+
List of tensors: [output, softmax_lse]
|
| 398 |
+
"""
|
| 399 |
+
if softmax_scale is None:
|
| 400 |
+
attention_head_dim = q.shape[-1]
|
| 401 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 402 |
+
|
| 403 |
+
return flash_attn_ops.fwd_kvcache(
|
| 404 |
+
q,
|
| 405 |
+
kcache,
|
| 406 |
+
vcache,
|
| 407 |
+
k,
|
| 408 |
+
v,
|
| 409 |
+
seqlens_k,
|
| 410 |
+
rotary_cos,
|
| 411 |
+
rotary_sin,
|
| 412 |
+
cache_batch_idx,
|
| 413 |
+
leftpad_k,
|
| 414 |
+
block_table,
|
| 415 |
+
alibi_slopes,
|
| 416 |
+
out,
|
| 417 |
+
softmax_scale,
|
| 418 |
+
is_causal,
|
| 419 |
+
window_size_left,
|
| 420 |
+
window_size_right,
|
| 421 |
+
softcap,
|
| 422 |
+
is_rotary_interleaved,
|
| 423 |
+
num_splits,
|
| 424 |
+
)
|
build/torch-stable-abi210-cu126-aarch64-linux/_flash_attn2_cuda_460047c.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:de41e0887afd71fca22cc0b2f75a0fa132461ee98943529fb073f6767a33056b
|
| 3 |
+
size 446708200
|
build/torch-stable-abi210-cu126-aarch64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _flash_attn2_cuda_460047c
|
| 3 |
+
ops = torch.ops._flash_attn2_cuda_460047c
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_flash_attn2_cuda_460047c::{op_name}"
|
build/torch-stable-abi210-cu126-aarch64-linux/flash_attn_interface.py
ADDED
|
@@ -0,0 +1,1708 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2023, Tri Dao.
|
| 2 |
+
|
| 3 |
+
from typing import Optional, Sequence, Tuple, Union
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
import torch.nn as nn
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
# # isort: off
|
| 10 |
+
# # We need to import the CUDA kernels after importing torch
|
| 11 |
+
# USE_TRITON_ROCM = os.getenv("FLASH_ATTENTION_TRITON_AMD_ENABLE", "FALSE") == "TRUE"
|
| 12 |
+
# if USE_TRITON_ROCM:
|
| 13 |
+
# from .flash_attn_triton_amd import interface_fa as flash_attn
|
| 14 |
+
# else:
|
| 15 |
+
# import flash_attn_2_cuda as flash_attn
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
from ._ops import ops as flash_attn
|
| 19 |
+
from ._ops import add_op_namespace_prefix
|
| 20 |
+
|
| 21 |
+
# # isort: on
|
| 22 |
+
|
| 23 |
+
# Torch >= 2.13 can pass a Generator through the stable ABI. Older versions reject the argument
|
| 24 |
+
# before the kernel runs, so there the CUDA op has to draw its Philox seed and offset itself.
|
| 25 |
+
_STABLE_ABI_GENERATOR = torch.__version__ >= "2.13"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def maybe_contiguous(x):
|
| 29 |
+
return x.contiguous() if x is not None and x.stride(-1) != 1 else x
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def _get_device():
|
| 33 |
+
if torch.xpu.is_available():
|
| 34 |
+
return "xpu"
|
| 35 |
+
elif torch.cuda.is_available():
|
| 36 |
+
return "cuda"
|
| 37 |
+
else:
|
| 38 |
+
return "cpu"
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def _get_block_size_n(device, head_dim, is_dropout, is_causal):
|
| 42 |
+
assert head_dim <= 256
|
| 43 |
+
|
| 44 |
+
if device.type == "xpu":
|
| 45 |
+
if head_dim <= 96:
|
| 46 |
+
return 64
|
| 47 |
+
elif head_dim <= 128:
|
| 48 |
+
return 32
|
| 49 |
+
elif head_dim <= 256:
|
| 50 |
+
return 64
|
| 51 |
+
else:
|
| 52 |
+
return 32
|
| 53 |
+
|
| 54 |
+
# This should match the block sizes in the CUDA kernel
|
| 55 |
+
major, minor = torch.cuda.get_device_capability(device)
|
| 56 |
+
is_sm8x = (
|
| 57 |
+
major == 8 and minor > 0
|
| 58 |
+
) # Only include sm86 and sm89, exclude sm80 (A100)
|
| 59 |
+
is_sm80 = major == 8 and minor == 0
|
| 60 |
+
is_sm90 = major == 9 and minor == 0
|
| 61 |
+
if head_dim <= 32:
|
| 62 |
+
return 128
|
| 63 |
+
if head_dim <= 64:
|
| 64 |
+
return 128 if not is_dropout else 64
|
| 65 |
+
elif head_dim <= 96:
|
| 66 |
+
return 64
|
| 67 |
+
elif head_dim <= 128:
|
| 68 |
+
if is_sm8x:
|
| 69 |
+
return 64 if (not is_dropout and is_causal) else 32
|
| 70 |
+
else:
|
| 71 |
+
return 64 if not is_dropout else 32
|
| 72 |
+
elif head_dim <= 192:
|
| 73 |
+
return 64
|
| 74 |
+
elif head_dim <= 224:
|
| 75 |
+
return 64
|
| 76 |
+
elif head_dim <= 256:
|
| 77 |
+
return 64
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def round_multiple(x, m):
|
| 81 |
+
return (x + m - 1) // m * m
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def _philox_generator(
|
| 85 |
+
q: torch.Tensor, dropout_p: float, generator: Optional[torch.Generator] = None
|
| 86 |
+
) -> Optional[torch.Generator]:
|
| 87 |
+
"""The generator to hand to `fwd` / `varlen_fwd`.
|
| 88 |
+
|
| 89 |
+
With dropout on CUDA this is the default generator unless one is given, so the kernel reserves
|
| 90 |
+
its seed and offset exactly like the non-stable build (see set_params_philox in flash_api.cpp).
|
| 91 |
+
"""
|
| 92 |
+
if not q.is_cuda:
|
| 93 |
+
return generator
|
| 94 |
+
if dropout_p <= 0:
|
| 95 |
+
return None
|
| 96 |
+
if not _STABLE_ABI_GENERATOR:
|
| 97 |
+
if generator is not None:
|
| 98 |
+
raise ValueError(
|
| 99 |
+
"flash_attn2: passing a generator to the CUDA kernel requires torch >= 2.13; "
|
| 100 |
+
"seed the default generator with torch.manual_seed instead"
|
| 101 |
+
)
|
| 102 |
+
return None
|
| 103 |
+
if generator is None:
|
| 104 |
+
generator = torch.cuda.default_generators[q.device.index]
|
| 105 |
+
return generator
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
@torch.library.custom_op(
|
| 109 |
+
add_op_namespace_prefix("_flash_attn_forward"),
|
| 110 |
+
mutates_args=(),
|
| 111 |
+
device_types=_get_device(),
|
| 112 |
+
# Tells torch.compile the forward draws random numbers, so it is never deduplicated or
|
| 113 |
+
# recomputed (e.g. under activation checkpointing).
|
| 114 |
+
tags=(torch.Tag.nondeterministic_seeded,),
|
| 115 |
+
)
|
| 116 |
+
def _flash_attn_forward(
|
| 117 |
+
q: torch.Tensor,
|
| 118 |
+
k: torch.Tensor,
|
| 119 |
+
v: torch.Tensor,
|
| 120 |
+
dropout_p: float,
|
| 121 |
+
softmax_scale: float,
|
| 122 |
+
causal: bool,
|
| 123 |
+
window_size_left: int,
|
| 124 |
+
window_size_right: int,
|
| 125 |
+
softcap: float,
|
| 126 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 127 |
+
return_softmax: bool,
|
| 128 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 129 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 130 |
+
gen = _philox_generator(q, dropout_p)
|
| 131 |
+
out, softmax_lse, S_dmask, rng_state = flash_attn.fwd(
|
| 132 |
+
q,
|
| 133 |
+
k,
|
| 134 |
+
v,
|
| 135 |
+
None,
|
| 136 |
+
alibi_slopes,
|
| 137 |
+
dropout_p,
|
| 138 |
+
softmax_scale,
|
| 139 |
+
causal,
|
| 140 |
+
window_size_left,
|
| 141 |
+
window_size_right,
|
| 142 |
+
softcap,
|
| 143 |
+
return_softmax,
|
| 144 |
+
gen,
|
| 145 |
+
)
|
| 146 |
+
return out, softmax_lse, S_dmask, rng_state
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_forward"))
|
| 150 |
+
def _flash_attn_forward_fake(
|
| 151 |
+
q: torch.Tensor,
|
| 152 |
+
k: torch.Tensor,
|
| 153 |
+
v: torch.Tensor,
|
| 154 |
+
dropout_p: float,
|
| 155 |
+
softmax_scale: float,
|
| 156 |
+
causal: bool,
|
| 157 |
+
window_size_left: int,
|
| 158 |
+
window_size_right: int,
|
| 159 |
+
softcap: float,
|
| 160 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 161 |
+
return_softmax: bool,
|
| 162 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 163 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 164 |
+
batch_size, seqlen_q, num_heads, head_size = q.shape
|
| 165 |
+
seqlen_k = k.shape[1]
|
| 166 |
+
out = torch.empty_like(q)
|
| 167 |
+
softmax_lse = torch.empty(
|
| 168 |
+
(batch_size, num_heads, seqlen_q),
|
| 169 |
+
dtype=torch.float32,
|
| 170 |
+
device=q.device,
|
| 171 |
+
layout=q.layout,
|
| 172 |
+
)
|
| 173 |
+
p = torch.empty((0,), dtype=q.dtype, device=q.device, layout=q.layout)
|
| 174 |
+
if return_softmax:
|
| 175 |
+
p = torch.empty(
|
| 176 |
+
(
|
| 177 |
+
batch_size,
|
| 178 |
+
num_heads,
|
| 179 |
+
round_multiple(seqlen_q, 128),
|
| 180 |
+
round_multiple(seqlen_k, 128),
|
| 181 |
+
),
|
| 182 |
+
dtype=q.dtype,
|
| 183 |
+
device=q.device,
|
| 184 |
+
layout=q.layout,
|
| 185 |
+
)
|
| 186 |
+
rng_state = torch.empty((2,), dtype=torch.int64, device=q.device)
|
| 187 |
+
|
| 188 |
+
return out, softmax_lse, p, rng_state
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
_wrapped_flash_attn_forward = flash_attn._flash_attn_forward # upstream alias, see CARD.md
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
@torch.library.custom_op(
|
| 195 |
+
add_op_namespace_prefix("_flash_attn_varlen_forward"),
|
| 196 |
+
mutates_args=(),
|
| 197 |
+
device_types=_get_device(),
|
| 198 |
+
tags=(torch.Tag.nondeterministic_seeded,),
|
| 199 |
+
)
|
| 200 |
+
def _flash_attn_varlen_forward(
|
| 201 |
+
q: torch.Tensor,
|
| 202 |
+
k: torch.Tensor,
|
| 203 |
+
v: torch.Tensor,
|
| 204 |
+
cu_seqlens_q: torch.Tensor,
|
| 205 |
+
cu_seqlens_k: torch.Tensor,
|
| 206 |
+
max_seqlen_q: int,
|
| 207 |
+
max_seqlen_k: int,
|
| 208 |
+
dropout_p: float,
|
| 209 |
+
softmax_scale: float,
|
| 210 |
+
causal: bool,
|
| 211 |
+
window_size_left: int = -1,
|
| 212 |
+
window_size_right: int = -1,
|
| 213 |
+
softcap: float = 0.0,
|
| 214 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 215 |
+
return_softmax: bool = False,
|
| 216 |
+
block_table: Optional[torch.Tensor] = None,
|
| 217 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 218 |
+
seqused_k: Optional[torch.Tensor] = None,
|
| 219 |
+
zero_tensors: bool = False,
|
| 220 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 221 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 222 |
+
gen = _philox_generator(q, dropout_p)
|
| 223 |
+
out, softmax_lse, S_dmask, rng_state = flash_attn.varlen_fwd(
|
| 224 |
+
q,
|
| 225 |
+
k,
|
| 226 |
+
v,
|
| 227 |
+
None,
|
| 228 |
+
cu_seqlens_q,
|
| 229 |
+
cu_seqlens_k,
|
| 230 |
+
seqused_k,
|
| 231 |
+
leftpad_k,
|
| 232 |
+
block_table,
|
| 233 |
+
alibi_slopes,
|
| 234 |
+
max_seqlen_q,
|
| 235 |
+
max_seqlen_k,
|
| 236 |
+
dropout_p,
|
| 237 |
+
softmax_scale,
|
| 238 |
+
zero_tensors,
|
| 239 |
+
causal,
|
| 240 |
+
window_size_left,
|
| 241 |
+
window_size_right,
|
| 242 |
+
softcap,
|
| 243 |
+
return_softmax,
|
| 244 |
+
gen,
|
| 245 |
+
)
|
| 246 |
+
# if out.isnan().any() or softmax_lse.isnan().any():
|
| 247 |
+
# breakpoint()
|
| 248 |
+
return out, softmax_lse, S_dmask, rng_state
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_varlen_forward"))
|
| 252 |
+
def _flash_attn_varlen_forward_fake(
|
| 253 |
+
q: torch.Tensor,
|
| 254 |
+
k: torch.Tensor,
|
| 255 |
+
v: torch.Tensor,
|
| 256 |
+
cu_seqlens_q: torch.Tensor,
|
| 257 |
+
cu_seqlens_k: torch.Tensor,
|
| 258 |
+
max_seqlen_q: int,
|
| 259 |
+
max_seqlen_k: int,
|
| 260 |
+
dropout_p: float,
|
| 261 |
+
softmax_scale: float,
|
| 262 |
+
causal: bool,
|
| 263 |
+
window_size_left: int = -1,
|
| 264 |
+
window_size_right: int = -1,
|
| 265 |
+
softcap: float = 0.0,
|
| 266 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 267 |
+
return_softmax: bool = False,
|
| 268 |
+
block_table: Optional[torch.Tensor] = None,
|
| 269 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 270 |
+
seqused_k: Optional[torch.Tensor] = None,
|
| 271 |
+
zero_tensors: bool = False,
|
| 272 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 273 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 274 |
+
paged_kv = block_table is not None
|
| 275 |
+
batch_size = cu_seqlens_q.numel() - 1
|
| 276 |
+
total_q, num_heads, _ = q.shape
|
| 277 |
+
|
| 278 |
+
out = torch.empty_like(q)
|
| 279 |
+
softmax_lse = torch.empty(
|
| 280 |
+
(num_heads, total_q), dtype=torch.float32, device=q.device, layout=q.layout
|
| 281 |
+
)
|
| 282 |
+
p = torch.empty((0,), dtype=q.dtype, device=q.device, layout=q.layout)
|
| 283 |
+
seqlen_q_rounded = round_multiple(max_seqlen_q, 128)
|
| 284 |
+
seqlen_k_rounded = round_multiple(max_seqlen_k, 128)
|
| 285 |
+
if return_softmax:
|
| 286 |
+
p = torch.empty(
|
| 287 |
+
(batch_size, num_heads, seqlen_q_rounded, seqlen_k_rounded),
|
| 288 |
+
dtype=q.dtype,
|
| 289 |
+
device=q.device,
|
| 290 |
+
layout=q.layout,
|
| 291 |
+
)
|
| 292 |
+
rng_state = torch.empty((2,), dtype=torch.int64, device=q.device)
|
| 293 |
+
return out, softmax_lse, p, rng_state
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
_wrapped_flash_attn_varlen_forward = flash_attn._flash_attn_varlen_forward # upstream alias, see CARD.md
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
@torch.library.custom_op(
|
| 300 |
+
add_op_namespace_prefix("_flash_attn_backward"),
|
| 301 |
+
mutates_args=("dq", "dk", "dv"),
|
| 302 |
+
device_types=_get_device(),
|
| 303 |
+
)
|
| 304 |
+
def _flash_attn_backward(
|
| 305 |
+
dout: torch.Tensor,
|
| 306 |
+
q: torch.Tensor,
|
| 307 |
+
k: torch.Tensor,
|
| 308 |
+
v: torch.Tensor,
|
| 309 |
+
out: torch.Tensor,
|
| 310 |
+
softmax_lse: torch.Tensor,
|
| 311 |
+
dq: Optional[torch.Tensor],
|
| 312 |
+
dk: Optional[torch.Tensor],
|
| 313 |
+
dv: Optional[torch.Tensor],
|
| 314 |
+
dropout_p: float,
|
| 315 |
+
softmax_scale: float,
|
| 316 |
+
causal: bool,
|
| 317 |
+
window_size_left: int,
|
| 318 |
+
window_size_right: int,
|
| 319 |
+
softcap: float,
|
| 320 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 321 |
+
deterministic: bool,
|
| 322 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 323 |
+
) -> torch.Tensor:
|
| 324 |
+
# dq, dk, dv are allocated by us so they should already be contiguous
|
| 325 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 326 |
+
(
|
| 327 |
+
dq,
|
| 328 |
+
dk,
|
| 329 |
+
dv,
|
| 330 |
+
softmax_d,
|
| 331 |
+
) = flash_attn.bwd(
|
| 332 |
+
dout,
|
| 333 |
+
q,
|
| 334 |
+
k,
|
| 335 |
+
v,
|
| 336 |
+
out,
|
| 337 |
+
softmax_lse,
|
| 338 |
+
dq,
|
| 339 |
+
dk,
|
| 340 |
+
dv,
|
| 341 |
+
alibi_slopes,
|
| 342 |
+
dropout_p,
|
| 343 |
+
softmax_scale,
|
| 344 |
+
causal,
|
| 345 |
+
window_size_left,
|
| 346 |
+
window_size_right,
|
| 347 |
+
softcap,
|
| 348 |
+
deterministic,
|
| 349 |
+
None,
|
| 350 |
+
rng_state,
|
| 351 |
+
)
|
| 352 |
+
return softmax_d
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_backward"))
|
| 356 |
+
def _flash_attn_backward_fake(
|
| 357 |
+
dout: torch.Tensor,
|
| 358 |
+
q: torch.Tensor,
|
| 359 |
+
k: torch.Tensor,
|
| 360 |
+
v: torch.Tensor,
|
| 361 |
+
out: torch.Tensor,
|
| 362 |
+
softmax_lse: torch.Tensor,
|
| 363 |
+
dq: Optional[torch.Tensor],
|
| 364 |
+
dk: Optional[torch.Tensor],
|
| 365 |
+
dv: Optional[torch.Tensor],
|
| 366 |
+
dropout_p: float,
|
| 367 |
+
softmax_scale: float,
|
| 368 |
+
causal: bool,
|
| 369 |
+
window_size_left: int,
|
| 370 |
+
window_size_right: int,
|
| 371 |
+
softcap: float,
|
| 372 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 373 |
+
deterministic: bool,
|
| 374 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 375 |
+
) -> torch.Tensor:
|
| 376 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 377 |
+
if dq is None:
|
| 378 |
+
dq = torch.empty_like(q)
|
| 379 |
+
if dk is None:
|
| 380 |
+
dk = torch.empty_like(k)
|
| 381 |
+
if dv is None:
|
| 382 |
+
dv = torch.empty_like(v)
|
| 383 |
+
batch_size, seqlen_q, num_heads, _ = q.shape
|
| 384 |
+
softmax_d = torch.empty(
|
| 385 |
+
(batch_size, num_heads, round_multiple(seqlen_q, 128)),
|
| 386 |
+
device=q.device,
|
| 387 |
+
dtype=torch.float32,
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
return softmax_d
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
_wrapped_flash_attn_backward = flash_attn._flash_attn_backward # upstream alias, see CARD.md
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
@torch.library.custom_op(
|
| 397 |
+
add_op_namespace_prefix("_flash_attn_varlen_backward"),
|
| 398 |
+
mutates_args=("dq", "dk", "dv"),
|
| 399 |
+
device_types=_get_device(),
|
| 400 |
+
)
|
| 401 |
+
def _flash_attn_varlen_backward(
|
| 402 |
+
dout: torch.Tensor,
|
| 403 |
+
q: torch.Tensor,
|
| 404 |
+
k: torch.Tensor,
|
| 405 |
+
v: torch.Tensor,
|
| 406 |
+
out: torch.Tensor,
|
| 407 |
+
softmax_lse: torch.Tensor,
|
| 408 |
+
dq: Optional[torch.Tensor],
|
| 409 |
+
dk: Optional[torch.Tensor],
|
| 410 |
+
dv: Optional[torch.Tensor],
|
| 411 |
+
cu_seqlens_q: torch.Tensor,
|
| 412 |
+
cu_seqlens_k: torch.Tensor,
|
| 413 |
+
max_seqlen_q: int,
|
| 414 |
+
max_seqlen_k: int,
|
| 415 |
+
dropout_p: float,
|
| 416 |
+
softmax_scale: float,
|
| 417 |
+
causal: bool,
|
| 418 |
+
window_size_left: int,
|
| 419 |
+
window_size_right: int,
|
| 420 |
+
softcap: float,
|
| 421 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 422 |
+
deterministic: bool,
|
| 423 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 424 |
+
zero_tensors: bool = False,
|
| 425 |
+
) -> torch.Tensor:
|
| 426 |
+
# dq, dk, dv are allocated by us so they should already be contiguous
|
| 427 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 428 |
+
(
|
| 429 |
+
dq,
|
| 430 |
+
dk,
|
| 431 |
+
dv,
|
| 432 |
+
softmax_d,
|
| 433 |
+
) = flash_attn.varlen_bwd(
|
| 434 |
+
dout,
|
| 435 |
+
q,
|
| 436 |
+
k,
|
| 437 |
+
v,
|
| 438 |
+
out,
|
| 439 |
+
softmax_lse,
|
| 440 |
+
dq,
|
| 441 |
+
dk,
|
| 442 |
+
dv,
|
| 443 |
+
cu_seqlens_q,
|
| 444 |
+
cu_seqlens_k,
|
| 445 |
+
alibi_slopes,
|
| 446 |
+
max_seqlen_q,
|
| 447 |
+
max_seqlen_k,
|
| 448 |
+
dropout_p,
|
| 449 |
+
softmax_scale,
|
| 450 |
+
zero_tensors,
|
| 451 |
+
causal,
|
| 452 |
+
window_size_left,
|
| 453 |
+
window_size_right,
|
| 454 |
+
softcap,
|
| 455 |
+
deterministic,
|
| 456 |
+
None,
|
| 457 |
+
rng_state,
|
| 458 |
+
)
|
| 459 |
+
# if dk.isnan().any() or dk.isnan().any() or dv.isnan().any() or softmax_d.isnan().any():
|
| 460 |
+
# breakpoint()
|
| 461 |
+
return softmax_d
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_varlen_backward"))
|
| 465 |
+
def _flash_attn_varlen_backward_fake(
|
| 466 |
+
dout: torch.Tensor,
|
| 467 |
+
q: torch.Tensor,
|
| 468 |
+
k: torch.Tensor,
|
| 469 |
+
v: torch.Tensor,
|
| 470 |
+
out: torch.Tensor,
|
| 471 |
+
softmax_lse: torch.Tensor,
|
| 472 |
+
dq: Optional[torch.Tensor],
|
| 473 |
+
dk: Optional[torch.Tensor],
|
| 474 |
+
dv: Optional[torch.Tensor],
|
| 475 |
+
cu_seqlens_q: torch.Tensor,
|
| 476 |
+
cu_seqlens_k: torch.Tensor,
|
| 477 |
+
max_seqlen_q: int,
|
| 478 |
+
max_seqlen_k: int,
|
| 479 |
+
dropout_p: float,
|
| 480 |
+
softmax_scale: float,
|
| 481 |
+
causal: bool,
|
| 482 |
+
window_size_left: int,
|
| 483 |
+
window_size_right: int,
|
| 484 |
+
softcap: float,
|
| 485 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 486 |
+
deterministic: bool,
|
| 487 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 488 |
+
zero_tensors: bool = False,
|
| 489 |
+
) -> torch.Tensor:
|
| 490 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 491 |
+
batch_size = cu_seqlens_q.numel() - 1
|
| 492 |
+
total_q, num_heads, _ = q.shape
|
| 493 |
+
|
| 494 |
+
if dq is None:
|
| 495 |
+
dq = torch.empty_like(q)
|
| 496 |
+
if dk is None:
|
| 497 |
+
dk = torch.empty_like(k)
|
| 498 |
+
if dv is None:
|
| 499 |
+
dv = torch.empty_like(v)
|
| 500 |
+
softmax_d = torch.empty(
|
| 501 |
+
(num_heads, total_q + 128 * batch_size), device=q.device, dtype=torch.float32
|
| 502 |
+
)
|
| 503 |
+
|
| 504 |
+
return softmax_d
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
_wrapped_flash_attn_varlen_backward = flash_attn._flash_attn_varlen_backward # upstream alias, see CARD.md
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
class FlashAttnQKVPackedFunc(torch.autograd.Function):
|
| 511 |
+
@staticmethod
|
| 512 |
+
def forward(
|
| 513 |
+
ctx,
|
| 514 |
+
qkv,
|
| 515 |
+
dropout_p,
|
| 516 |
+
softmax_scale,
|
| 517 |
+
causal,
|
| 518 |
+
window_size,
|
| 519 |
+
softcap,
|
| 520 |
+
alibi_slopes,
|
| 521 |
+
deterministic,
|
| 522 |
+
return_softmax,
|
| 523 |
+
is_grad_enabled,
|
| 524 |
+
):
|
| 525 |
+
is_grad = is_grad_enabled and qkv.requires_grad
|
| 526 |
+
if softmax_scale is None:
|
| 527 |
+
softmax_scale = qkv.shape[-1] ** (-0.5)
|
| 528 |
+
q, k, v = qkv[:, :, 0].detach(), qkv[:, :, 1].detach(), qkv[:, :, 2].detach()
|
| 529 |
+
head_size_og = q.size(3)
|
| 530 |
+
if head_size_og % 8 != 0:
|
| 531 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 532 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 533 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 534 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_forward(
|
| 535 |
+
q,
|
| 536 |
+
k,
|
| 537 |
+
v,
|
| 538 |
+
dropout_p,
|
| 539 |
+
softmax_scale,
|
| 540 |
+
causal=causal,
|
| 541 |
+
window_size_left=window_size[0],
|
| 542 |
+
window_size_right=window_size[1],
|
| 543 |
+
softcap=softcap,
|
| 544 |
+
alibi_slopes=alibi_slopes,
|
| 545 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 546 |
+
)
|
| 547 |
+
if is_grad:
|
| 548 |
+
ctx.save_for_backward(q, k, v, out_padded, softmax_lse, rng_state)
|
| 549 |
+
ctx.dropout_p = dropout_p
|
| 550 |
+
ctx.softmax_scale = softmax_scale
|
| 551 |
+
ctx.causal = causal
|
| 552 |
+
ctx.window_size = window_size
|
| 553 |
+
ctx.softcap = softcap
|
| 554 |
+
ctx.alibi_slopes = alibi_slopes
|
| 555 |
+
ctx.deterministic = deterministic
|
| 556 |
+
out = out_padded[..., :head_size_og]
|
| 557 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 558 |
+
|
| 559 |
+
@staticmethod
|
| 560 |
+
def backward(ctx, dout, *args):
|
| 561 |
+
q, k, v, out, softmax_lse, rng_state = ctx.saved_tensors
|
| 562 |
+
qkv_shape = q.shape[:-2] + (3, *q.shape[-2:])
|
| 563 |
+
dqkv = torch.empty(qkv_shape, dtype=q.dtype, device=q.device)
|
| 564 |
+
head_size_og = dout.size(3)
|
| 565 |
+
dout_padded = dout
|
| 566 |
+
if head_size_og % 8 != 0:
|
| 567 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 568 |
+
_flash_attn_backward(
|
| 569 |
+
dout_padded,
|
| 570 |
+
q,
|
| 571 |
+
k,
|
| 572 |
+
v,
|
| 573 |
+
out,
|
| 574 |
+
softmax_lse,
|
| 575 |
+
dqkv[:, :, 0],
|
| 576 |
+
dqkv[:, :, 1],
|
| 577 |
+
dqkv[:, :, 2],
|
| 578 |
+
ctx.dropout_p,
|
| 579 |
+
ctx.softmax_scale,
|
| 580 |
+
ctx.causal,
|
| 581 |
+
ctx.window_size[0],
|
| 582 |
+
ctx.window_size[1],
|
| 583 |
+
ctx.softcap,
|
| 584 |
+
ctx.alibi_slopes,
|
| 585 |
+
ctx.deterministic,
|
| 586 |
+
rng_state=rng_state,
|
| 587 |
+
)
|
| 588 |
+
dqkv = dqkv[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 589 |
+
return dqkv, None, None, None, None, None, None, None, None, None
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
class FlashAttnVarlenQKVPackedFunc(torch.autograd.Function):
|
| 593 |
+
@staticmethod
|
| 594 |
+
def forward(
|
| 595 |
+
ctx,
|
| 596 |
+
qkv,
|
| 597 |
+
cu_seqlens,
|
| 598 |
+
max_seqlen,
|
| 599 |
+
dropout_p,
|
| 600 |
+
softmax_scale,
|
| 601 |
+
causal,
|
| 602 |
+
window_size,
|
| 603 |
+
softcap,
|
| 604 |
+
alibi_slopes,
|
| 605 |
+
deterministic,
|
| 606 |
+
return_softmax,
|
| 607 |
+
is_grad_enabled,
|
| 608 |
+
):
|
| 609 |
+
is_grad = is_grad_enabled and qkv.requires_grad
|
| 610 |
+
if softmax_scale is None:
|
| 611 |
+
softmax_scale = qkv.shape[-1] ** (-0.5)
|
| 612 |
+
q, k, v = qkv[:, 0].detach(), qkv[:, 1].detach(), qkv[:, 2].detach()
|
| 613 |
+
head_size_og = q.size(2)
|
| 614 |
+
if head_size_og % 8 != 0:
|
| 615 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 616 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 617 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 618 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_varlen_forward(
|
| 619 |
+
q,
|
| 620 |
+
k,
|
| 621 |
+
v,
|
| 622 |
+
cu_seqlens,
|
| 623 |
+
cu_seqlens,
|
| 624 |
+
max_seqlen,
|
| 625 |
+
max_seqlen,
|
| 626 |
+
dropout_p,
|
| 627 |
+
softmax_scale,
|
| 628 |
+
causal=causal,
|
| 629 |
+
window_size_left=window_size[0],
|
| 630 |
+
window_size_right=window_size[1],
|
| 631 |
+
softcap=softcap,
|
| 632 |
+
alibi_slopes=alibi_slopes,
|
| 633 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 634 |
+
block_table=None,
|
| 635 |
+
)
|
| 636 |
+
if is_grad:
|
| 637 |
+
ctx.save_for_backward(
|
| 638 |
+
q, k, v, out_padded, softmax_lse, cu_seqlens, rng_state
|
| 639 |
+
)
|
| 640 |
+
ctx.dropout_p = dropout_p
|
| 641 |
+
ctx.max_seqlen = max_seqlen
|
| 642 |
+
ctx.softmax_scale = softmax_scale
|
| 643 |
+
ctx.causal = causal
|
| 644 |
+
ctx.window_size = window_size
|
| 645 |
+
ctx.softcap = softcap
|
| 646 |
+
ctx.alibi_slopes = alibi_slopes
|
| 647 |
+
ctx.deterministic = deterministic
|
| 648 |
+
out = out_padded[..., :head_size_og]
|
| 649 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 650 |
+
|
| 651 |
+
@staticmethod
|
| 652 |
+
def backward(ctx, dout, *args):
|
| 653 |
+
q, k, v, out, softmax_lse, cu_seqlens, rng_state = ctx.saved_tensors
|
| 654 |
+
qkv_shape = q.shape[:-2] + (3, *q.shape[-2:])
|
| 655 |
+
dqkv = torch.empty(qkv_shape, dtype=q.dtype, device=q.device)
|
| 656 |
+
head_size_og = dout.size(2)
|
| 657 |
+
dout_padded = dout
|
| 658 |
+
if head_size_og % 8 != 0:
|
| 659 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 660 |
+
_flash_attn_varlen_backward(
|
| 661 |
+
dout_padded,
|
| 662 |
+
q,
|
| 663 |
+
k,
|
| 664 |
+
v,
|
| 665 |
+
out,
|
| 666 |
+
softmax_lse,
|
| 667 |
+
dqkv[:, 0],
|
| 668 |
+
dqkv[:, 1],
|
| 669 |
+
dqkv[:, 2],
|
| 670 |
+
cu_seqlens,
|
| 671 |
+
cu_seqlens,
|
| 672 |
+
ctx.max_seqlen,
|
| 673 |
+
ctx.max_seqlen,
|
| 674 |
+
ctx.dropout_p,
|
| 675 |
+
ctx.softmax_scale,
|
| 676 |
+
ctx.causal,
|
| 677 |
+
ctx.window_size[0],
|
| 678 |
+
ctx.window_size[1],
|
| 679 |
+
ctx.softcap,
|
| 680 |
+
ctx.alibi_slopes,
|
| 681 |
+
ctx.deterministic,
|
| 682 |
+
rng_state=rng_state,
|
| 683 |
+
)
|
| 684 |
+
dqkv = dqkv[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 685 |
+
return dqkv, None, None, None, None, None, None, None, None, None, None, None
|
| 686 |
+
|
| 687 |
+
|
| 688 |
+
class FlashAttnKVPackedFunc(torch.autograd.Function):
|
| 689 |
+
@staticmethod
|
| 690 |
+
def forward(
|
| 691 |
+
ctx,
|
| 692 |
+
q,
|
| 693 |
+
kv,
|
| 694 |
+
dropout_p,
|
| 695 |
+
softmax_scale,
|
| 696 |
+
causal,
|
| 697 |
+
window_size,
|
| 698 |
+
softcap,
|
| 699 |
+
alibi_slopes,
|
| 700 |
+
deterministic,
|
| 701 |
+
return_softmax,
|
| 702 |
+
is_grad_enabled,
|
| 703 |
+
):
|
| 704 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, kv])
|
| 705 |
+
if softmax_scale is None:
|
| 706 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 707 |
+
k, v = kv[:, :, 0].detach(), kv[:, :, 1].detach()
|
| 708 |
+
head_size_og = q.size(3)
|
| 709 |
+
if head_size_og % 8 != 0:
|
| 710 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 711 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 712 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 713 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_forward(
|
| 714 |
+
q,
|
| 715 |
+
k,
|
| 716 |
+
v,
|
| 717 |
+
dropout_p,
|
| 718 |
+
softmax_scale,
|
| 719 |
+
causal=causal,
|
| 720 |
+
window_size_left=window_size[0],
|
| 721 |
+
window_size_right=window_size[1],
|
| 722 |
+
softcap=softcap,
|
| 723 |
+
alibi_slopes=alibi_slopes,
|
| 724 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 725 |
+
)
|
| 726 |
+
if is_grad:
|
| 727 |
+
ctx.save_for_backward(q, k, v, out_padded, softmax_lse, rng_state)
|
| 728 |
+
ctx.dropout_p = dropout_p
|
| 729 |
+
ctx.softmax_scale = softmax_scale
|
| 730 |
+
ctx.causal = causal
|
| 731 |
+
ctx.window_size = window_size
|
| 732 |
+
ctx.softcap = softcap
|
| 733 |
+
ctx.alibi_slopes = alibi_slopes
|
| 734 |
+
ctx.deterministic = deterministic
|
| 735 |
+
out = out_padded[..., :head_size_og]
|
| 736 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 737 |
+
|
| 738 |
+
@staticmethod
|
| 739 |
+
def backward(ctx, dout, *args):
|
| 740 |
+
q, k, v, out, softmax_lse, rng_state = ctx.saved_tensors
|
| 741 |
+
dq = torch.empty_like(q)
|
| 742 |
+
kv_shape = k.shape[:-2] + (2, *k.shape[-2:])
|
| 743 |
+
dkv = torch.empty(kv_shape, dtype=k.dtype, device=k.device)
|
| 744 |
+
head_size_og = dout.size(3)
|
| 745 |
+
dout_padded = dout
|
| 746 |
+
if head_size_og % 8 != 0:
|
| 747 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 748 |
+
_flash_attn_backward(
|
| 749 |
+
dout_padded,
|
| 750 |
+
q,
|
| 751 |
+
k,
|
| 752 |
+
v,
|
| 753 |
+
out,
|
| 754 |
+
softmax_lse,
|
| 755 |
+
dq,
|
| 756 |
+
dkv[:, :, 0],
|
| 757 |
+
dkv[:, :, 1],
|
| 758 |
+
ctx.dropout_p,
|
| 759 |
+
ctx.softmax_scale,
|
| 760 |
+
ctx.causal,
|
| 761 |
+
ctx.window_size[0],
|
| 762 |
+
ctx.window_size[1],
|
| 763 |
+
ctx.softcap,
|
| 764 |
+
ctx.alibi_slopes,
|
| 765 |
+
ctx.deterministic,
|
| 766 |
+
rng_state=rng_state,
|
| 767 |
+
)
|
| 768 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 769 |
+
dkv = dkv[..., : dout.shape[-1]]
|
| 770 |
+
return dq, dkv, None, None, None, None, None, None, None, None, None
|
| 771 |
+
|
| 772 |
+
|
| 773 |
+
class FlashAttnVarlenKVPackedFunc(torch.autograd.Function):
|
| 774 |
+
@staticmethod
|
| 775 |
+
def forward(
|
| 776 |
+
ctx,
|
| 777 |
+
q,
|
| 778 |
+
kv,
|
| 779 |
+
cu_seqlens_q,
|
| 780 |
+
cu_seqlens_k,
|
| 781 |
+
max_seqlen_q,
|
| 782 |
+
max_seqlen_k,
|
| 783 |
+
dropout_p,
|
| 784 |
+
softmax_scale,
|
| 785 |
+
causal,
|
| 786 |
+
window_size,
|
| 787 |
+
softcap,
|
| 788 |
+
alibi_slopes,
|
| 789 |
+
deterministic,
|
| 790 |
+
return_softmax,
|
| 791 |
+
is_grad_enabled,
|
| 792 |
+
):
|
| 793 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, kv])
|
| 794 |
+
if softmax_scale is None:
|
| 795 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 796 |
+
k, v = kv[:, 0].detach(), kv[:, 1].detach()
|
| 797 |
+
head_size_og = q.size(2)
|
| 798 |
+
if head_size_og % 8 != 0:
|
| 799 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 800 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 801 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 802 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_varlen_forward(
|
| 803 |
+
q,
|
| 804 |
+
k,
|
| 805 |
+
v,
|
| 806 |
+
cu_seqlens_q,
|
| 807 |
+
cu_seqlens_k,
|
| 808 |
+
max_seqlen_q,
|
| 809 |
+
max_seqlen_k,
|
| 810 |
+
dropout_p,
|
| 811 |
+
softmax_scale,
|
| 812 |
+
causal=causal,
|
| 813 |
+
window_size_left=window_size[0],
|
| 814 |
+
window_size_right=window_size[1],
|
| 815 |
+
softcap=softcap,
|
| 816 |
+
alibi_slopes=alibi_slopes,
|
| 817 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 818 |
+
block_table=None,
|
| 819 |
+
)
|
| 820 |
+
if is_grad:
|
| 821 |
+
ctx.save_for_backward(
|
| 822 |
+
q, k, v, out_padded, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state
|
| 823 |
+
)
|
| 824 |
+
ctx.dropout_p = dropout_p
|
| 825 |
+
ctx.max_seqlen_q = max_seqlen_q
|
| 826 |
+
ctx.max_seqlen_k = max_seqlen_k
|
| 827 |
+
ctx.softmax_scale = softmax_scale
|
| 828 |
+
ctx.causal = causal
|
| 829 |
+
ctx.window_size = window_size
|
| 830 |
+
ctx.softcap = softcap
|
| 831 |
+
ctx.alibi_slopes = alibi_slopes
|
| 832 |
+
ctx.deterministic = deterministic
|
| 833 |
+
out = out_padded[..., :head_size_og]
|
| 834 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 835 |
+
|
| 836 |
+
@staticmethod
|
| 837 |
+
def backward(ctx, dout, *args):
|
| 838 |
+
q, k, v, out, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state = (
|
| 839 |
+
ctx.saved_tensors
|
| 840 |
+
)
|
| 841 |
+
dq = torch.empty_like(q)
|
| 842 |
+
kv_shape = k.shape[:-2] + (2, *k.shape[-2:])
|
| 843 |
+
dkv = torch.empty(kv_shape, dtype=k.dtype, device=k.device)
|
| 844 |
+
head_size_og = dout.size(2)
|
| 845 |
+
dout_padded = dout
|
| 846 |
+
if head_size_og % 8 != 0:
|
| 847 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 848 |
+
_flash_attn_varlen_backward(
|
| 849 |
+
dout_padded,
|
| 850 |
+
q,
|
| 851 |
+
k,
|
| 852 |
+
v,
|
| 853 |
+
out,
|
| 854 |
+
softmax_lse,
|
| 855 |
+
dq,
|
| 856 |
+
dkv[:, 0],
|
| 857 |
+
dkv[:, 1],
|
| 858 |
+
cu_seqlens_q,
|
| 859 |
+
cu_seqlens_k,
|
| 860 |
+
ctx.max_seqlen_q,
|
| 861 |
+
ctx.max_seqlen_k,
|
| 862 |
+
ctx.dropout_p,
|
| 863 |
+
ctx.softmax_scale,
|
| 864 |
+
ctx.causal,
|
| 865 |
+
ctx.window_size[0],
|
| 866 |
+
ctx.window_size[1],
|
| 867 |
+
ctx.softcap,
|
| 868 |
+
ctx.alibi_slopes,
|
| 869 |
+
ctx.deterministic,
|
| 870 |
+
rng_state=rng_state,
|
| 871 |
+
)
|
| 872 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 873 |
+
dkv = dkv[..., : dout.shape[-1]]
|
| 874 |
+
return (
|
| 875 |
+
dq,
|
| 876 |
+
dkv,
|
| 877 |
+
None,
|
| 878 |
+
None,
|
| 879 |
+
None,
|
| 880 |
+
None,
|
| 881 |
+
None,
|
| 882 |
+
None,
|
| 883 |
+
None,
|
| 884 |
+
None,
|
| 885 |
+
None,
|
| 886 |
+
None,
|
| 887 |
+
None,
|
| 888 |
+
None,
|
| 889 |
+
None,
|
| 890 |
+
)
|
| 891 |
+
|
| 892 |
+
|
| 893 |
+
class FlashAttnFunc(torch.autograd.Function):
|
| 894 |
+
@staticmethod
|
| 895 |
+
def forward(
|
| 896 |
+
ctx,
|
| 897 |
+
q,
|
| 898 |
+
k,
|
| 899 |
+
v,
|
| 900 |
+
dropout_p,
|
| 901 |
+
softmax_scale,
|
| 902 |
+
causal,
|
| 903 |
+
window_size,
|
| 904 |
+
softcap,
|
| 905 |
+
alibi_slopes,
|
| 906 |
+
deterministic,
|
| 907 |
+
return_softmax,
|
| 908 |
+
is_grad_enabled,
|
| 909 |
+
):
|
| 910 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, k, v])
|
| 911 |
+
if softmax_scale is None:
|
| 912 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 913 |
+
head_size_og = q.size(3)
|
| 914 |
+
if head_size_og % 8 != 0:
|
| 915 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 916 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 917 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 918 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_forward(
|
| 919 |
+
q,
|
| 920 |
+
k,
|
| 921 |
+
v,
|
| 922 |
+
dropout_p,
|
| 923 |
+
softmax_scale,
|
| 924 |
+
causal=causal,
|
| 925 |
+
window_size_left=window_size[0],
|
| 926 |
+
window_size_right=window_size[1],
|
| 927 |
+
softcap=softcap,
|
| 928 |
+
alibi_slopes=alibi_slopes,
|
| 929 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 930 |
+
)
|
| 931 |
+
if is_grad:
|
| 932 |
+
ctx.save_for_backward(q, k, v, out_padded, softmax_lse, rng_state)
|
| 933 |
+
ctx.dropout_p = dropout_p
|
| 934 |
+
ctx.softmax_scale = softmax_scale
|
| 935 |
+
ctx.causal = causal
|
| 936 |
+
ctx.window_size = window_size
|
| 937 |
+
ctx.softcap = softcap
|
| 938 |
+
ctx.alibi_slopes = alibi_slopes
|
| 939 |
+
ctx.deterministic = deterministic
|
| 940 |
+
out = out_padded[..., :head_size_og]
|
| 941 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 942 |
+
|
| 943 |
+
@staticmethod
|
| 944 |
+
def backward(ctx, dout, *args):
|
| 945 |
+
q, k, v, out, softmax_lse, rng_state = ctx.saved_tensors
|
| 946 |
+
dq, dk, dv = torch.empty_like(q), torch.empty_like(k), torch.empty_like(v)
|
| 947 |
+
head_size_og = dout.size(3)
|
| 948 |
+
dout_padded = dout
|
| 949 |
+
if head_size_og % 8 != 0:
|
| 950 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 951 |
+
_flash_attn_backward(
|
| 952 |
+
dout_padded,
|
| 953 |
+
q,
|
| 954 |
+
k,
|
| 955 |
+
v,
|
| 956 |
+
out,
|
| 957 |
+
softmax_lse,
|
| 958 |
+
dq,
|
| 959 |
+
dk,
|
| 960 |
+
dv,
|
| 961 |
+
ctx.dropout_p,
|
| 962 |
+
ctx.softmax_scale,
|
| 963 |
+
ctx.causal,
|
| 964 |
+
ctx.window_size[0],
|
| 965 |
+
ctx.window_size[1],
|
| 966 |
+
ctx.softcap,
|
| 967 |
+
ctx.alibi_slopes,
|
| 968 |
+
ctx.deterministic,
|
| 969 |
+
rng_state=rng_state,
|
| 970 |
+
)
|
| 971 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 972 |
+
dk = dk[..., : dout.shape[-1]]
|
| 973 |
+
dv = dv[..., : dout.shape[-1]]
|
| 974 |
+
return dq, dk, dv, None, None, None, None, None, None, None, None, None
|
| 975 |
+
|
| 976 |
+
|
| 977 |
+
class FlashAttnVarlenFunc(torch.autograd.Function):
|
| 978 |
+
@staticmethod
|
| 979 |
+
def forward(
|
| 980 |
+
ctx,
|
| 981 |
+
q,
|
| 982 |
+
k,
|
| 983 |
+
v,
|
| 984 |
+
cu_seqlens_q,
|
| 985 |
+
cu_seqlens_k,
|
| 986 |
+
max_seqlen_q,
|
| 987 |
+
max_seqlen_k,
|
| 988 |
+
dropout_p,
|
| 989 |
+
softmax_scale,
|
| 990 |
+
causal,
|
| 991 |
+
window_size,
|
| 992 |
+
softcap,
|
| 993 |
+
alibi_slopes,
|
| 994 |
+
deterministic,
|
| 995 |
+
return_softmax,
|
| 996 |
+
block_table,
|
| 997 |
+
is_grad_enabled,
|
| 998 |
+
):
|
| 999 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, k, v])
|
| 1000 |
+
if softmax_scale is None:
|
| 1001 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 1002 |
+
head_size_og = q.size(2)
|
| 1003 |
+
if head_size_og % 8 != 0:
|
| 1004 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 1005 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 1006 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 1007 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_varlen_forward(
|
| 1008 |
+
q,
|
| 1009 |
+
k,
|
| 1010 |
+
v,
|
| 1011 |
+
cu_seqlens_q,
|
| 1012 |
+
cu_seqlens_k,
|
| 1013 |
+
max_seqlen_q,
|
| 1014 |
+
max_seqlen_k,
|
| 1015 |
+
dropout_p,
|
| 1016 |
+
softmax_scale,
|
| 1017 |
+
causal=causal,
|
| 1018 |
+
window_size_left=window_size[0],
|
| 1019 |
+
window_size_right=window_size[1],
|
| 1020 |
+
softcap=softcap,
|
| 1021 |
+
alibi_slopes=alibi_slopes,
|
| 1022 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 1023 |
+
block_table=block_table,
|
| 1024 |
+
)
|
| 1025 |
+
if is_grad:
|
| 1026 |
+
ctx.save_for_backward(
|
| 1027 |
+
q, k, v, out_padded, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state
|
| 1028 |
+
)
|
| 1029 |
+
ctx.dropout_p = dropout_p
|
| 1030 |
+
ctx.max_seqlen_q = max_seqlen_q
|
| 1031 |
+
ctx.max_seqlen_k = max_seqlen_k
|
| 1032 |
+
ctx.softmax_scale = softmax_scale
|
| 1033 |
+
ctx.causal = causal
|
| 1034 |
+
ctx.window_size = window_size
|
| 1035 |
+
ctx.softcap = softcap
|
| 1036 |
+
ctx.alibi_slopes = alibi_slopes
|
| 1037 |
+
ctx.deterministic = deterministic
|
| 1038 |
+
|
| 1039 |
+
out = out_padded[..., :head_size_og]
|
| 1040 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 1041 |
+
|
| 1042 |
+
@staticmethod
|
| 1043 |
+
def backward(ctx, dout, *args):
|
| 1044 |
+
q, k, v, out, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state = (
|
| 1045 |
+
ctx.saved_tensors
|
| 1046 |
+
)
|
| 1047 |
+
dq, dk, dv = torch.empty_like(q), torch.empty_like(k), torch.empty_like(v)
|
| 1048 |
+
head_size_og = dout.size(2)
|
| 1049 |
+
dout_padded = dout
|
| 1050 |
+
if head_size_og % 8 != 0:
|
| 1051 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 1052 |
+
_flash_attn_varlen_backward(
|
| 1053 |
+
dout_padded,
|
| 1054 |
+
q,
|
| 1055 |
+
k,
|
| 1056 |
+
v,
|
| 1057 |
+
out,
|
| 1058 |
+
softmax_lse,
|
| 1059 |
+
dq,
|
| 1060 |
+
dk,
|
| 1061 |
+
dv,
|
| 1062 |
+
cu_seqlens_q,
|
| 1063 |
+
cu_seqlens_k,
|
| 1064 |
+
ctx.max_seqlen_q,
|
| 1065 |
+
ctx.max_seqlen_k,
|
| 1066 |
+
ctx.dropout_p,
|
| 1067 |
+
ctx.softmax_scale,
|
| 1068 |
+
ctx.causal,
|
| 1069 |
+
ctx.window_size[0],
|
| 1070 |
+
ctx.window_size[1],
|
| 1071 |
+
ctx.softcap,
|
| 1072 |
+
ctx.alibi_slopes,
|
| 1073 |
+
ctx.deterministic,
|
| 1074 |
+
rng_state=rng_state,
|
| 1075 |
+
)
|
| 1076 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 1077 |
+
dk = dk[..., : dout.shape[-1]]
|
| 1078 |
+
dv = dv[..., : dout.shape[-1]]
|
| 1079 |
+
return (
|
| 1080 |
+
dq,
|
| 1081 |
+
dk,
|
| 1082 |
+
dv,
|
| 1083 |
+
None,
|
| 1084 |
+
None,
|
| 1085 |
+
None,
|
| 1086 |
+
None,
|
| 1087 |
+
None,
|
| 1088 |
+
None,
|
| 1089 |
+
None,
|
| 1090 |
+
None,
|
| 1091 |
+
None,
|
| 1092 |
+
None,
|
| 1093 |
+
None,
|
| 1094 |
+
None,
|
| 1095 |
+
None,
|
| 1096 |
+
None,
|
| 1097 |
+
)
|
| 1098 |
+
|
| 1099 |
+
|
| 1100 |
+
def flash_attn_qkvpacked_func(
|
| 1101 |
+
qkv,
|
| 1102 |
+
dropout_p=0.0,
|
| 1103 |
+
softmax_scale=None,
|
| 1104 |
+
causal=False,
|
| 1105 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1106 |
+
softcap=0.0, # <=0.0 means deactivate
|
| 1107 |
+
alibi_slopes=None,
|
| 1108 |
+
deterministic=False,
|
| 1109 |
+
return_attn_probs=False,
|
| 1110 |
+
):
|
| 1111 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1112 |
+
If Q, K, V are already stacked into 1 tensor, this function will be faster than
|
| 1113 |
+
calling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1114 |
+
of the gradients of Q, K, V.
|
| 1115 |
+
For multi-query and grouped-query attention (MQA/GQA), please see
|
| 1116 |
+
flash_attn_kvpacked_func and flash_attn_func.
|
| 1117 |
+
|
| 1118 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1119 |
+
will only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.
|
| 1120 |
+
|
| 1121 |
+
Arguments:
|
| 1122 |
+
qkv: (batch_size, seqlen, 3, nheads, headdim)
|
| 1123 |
+
dropout_p: float. Dropout probability.
|
| 1124 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1125 |
+
Default to 1 / sqrt(headdim).
|
| 1126 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1127 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1128 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1129 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|) is added to
|
| 1130 |
+
the attention score of query i and key j.
|
| 1131 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1132 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1133 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1134 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1135 |
+
(they might not have the right scaling).
|
| 1136 |
+
Return:
|
| 1137 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1138 |
+
softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The
|
| 1139 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1140 |
+
normalization factor).
|
| 1141 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1142 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1143 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1144 |
+
"""
|
| 1145 |
+
return FlashAttnQKVPackedFunc.apply(
|
| 1146 |
+
qkv,
|
| 1147 |
+
dropout_p,
|
| 1148 |
+
softmax_scale,
|
| 1149 |
+
causal,
|
| 1150 |
+
window_size,
|
| 1151 |
+
softcap,
|
| 1152 |
+
alibi_slopes,
|
| 1153 |
+
deterministic,
|
| 1154 |
+
return_attn_probs,
|
| 1155 |
+
torch.is_grad_enabled(),
|
| 1156 |
+
)
|
| 1157 |
+
|
| 1158 |
+
|
| 1159 |
+
def flash_attn_kvpacked_func(
|
| 1160 |
+
q,
|
| 1161 |
+
kv,
|
| 1162 |
+
dropout_p=0.0,
|
| 1163 |
+
softmax_scale=None,
|
| 1164 |
+
causal=False,
|
| 1165 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1166 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1167 |
+
alibi_slopes=None,
|
| 1168 |
+
deterministic=False,
|
| 1169 |
+
return_attn_probs=False,
|
| 1170 |
+
):
|
| 1171 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1172 |
+
If K, V are already stacked into 1 tensor, this function will be faster than
|
| 1173 |
+
calling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1174 |
+
of the gradients of K, V.
|
| 1175 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1176 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1177 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1178 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1179 |
+
|
| 1180 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1181 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1182 |
+
1 1 1 1 0
|
| 1183 |
+
1 1 1 1 1
|
| 1184 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1185 |
+
0 0
|
| 1186 |
+
0 0
|
| 1187 |
+
0 0
|
| 1188 |
+
1 0
|
| 1189 |
+
1 1
|
| 1190 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1191 |
+
|
| 1192 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1193 |
+
will only attend to keys between
|
| 1194 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1195 |
+
|
| 1196 |
+
Arguments:
|
| 1197 |
+
q: (batch_size, seqlen, nheads, headdim)
|
| 1198 |
+
kv: (batch_size, seqlen, 2, nheads_k, headdim)
|
| 1199 |
+
dropout_p: float. Dropout probability.
|
| 1200 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1201 |
+
Default to 1 / sqrt(headdim).
|
| 1202 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1203 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1204 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1205 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1206 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1207 |
+
is added to the attention score of query i and key j.
|
| 1208 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1209 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1210 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1211 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1212 |
+
(they might not have the right scaling).
|
| 1213 |
+
Return:
|
| 1214 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1215 |
+
softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The
|
| 1216 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1217 |
+
normalization factor).
|
| 1218 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1219 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1220 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1221 |
+
"""
|
| 1222 |
+
return FlashAttnKVPackedFunc.apply(
|
| 1223 |
+
q,
|
| 1224 |
+
kv,
|
| 1225 |
+
dropout_p,
|
| 1226 |
+
softmax_scale,
|
| 1227 |
+
causal,
|
| 1228 |
+
window_size,
|
| 1229 |
+
softcap,
|
| 1230 |
+
alibi_slopes,
|
| 1231 |
+
deterministic,
|
| 1232 |
+
return_attn_probs,
|
| 1233 |
+
torch.is_grad_enabled(),
|
| 1234 |
+
)
|
| 1235 |
+
|
| 1236 |
+
|
| 1237 |
+
def flash_attn_func(
|
| 1238 |
+
q,
|
| 1239 |
+
k,
|
| 1240 |
+
v,
|
| 1241 |
+
dropout_p=0.0,
|
| 1242 |
+
softmax_scale=None,
|
| 1243 |
+
causal=False,
|
| 1244 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1245 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1246 |
+
alibi_slopes=None,
|
| 1247 |
+
deterministic=False,
|
| 1248 |
+
return_attn_probs=False,
|
| 1249 |
+
):
|
| 1250 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1251 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1252 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1253 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1254 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1255 |
+
|
| 1256 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1257 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1258 |
+
1 1 1 1 0
|
| 1259 |
+
1 1 1 1 1
|
| 1260 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1261 |
+
0 0
|
| 1262 |
+
0 0
|
| 1263 |
+
0 0
|
| 1264 |
+
1 0
|
| 1265 |
+
1 1
|
| 1266 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1267 |
+
|
| 1268 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1269 |
+
will only attend to keys between
|
| 1270 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1271 |
+
|
| 1272 |
+
Arguments:
|
| 1273 |
+
q: (batch_size, seqlen, nheads, headdim)
|
| 1274 |
+
k: (batch_size, seqlen, nheads_k, headdim)
|
| 1275 |
+
v: (batch_size, seqlen, nheads_k, headdim)
|
| 1276 |
+
dropout_p: float. Dropout probability.
|
| 1277 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1278 |
+
Default to 1 / sqrt(headdim).
|
| 1279 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1280 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1281 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1282 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1283 |
+
is added to the attention score of query i and key j.
|
| 1284 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1285 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1286 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1287 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1288 |
+
(they might not have the right scaling).
|
| 1289 |
+
Return:
|
| 1290 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1291 |
+
softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The
|
| 1292 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1293 |
+
normalization factor).
|
| 1294 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1295 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1296 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1297 |
+
"""
|
| 1298 |
+
return FlashAttnFunc.apply(
|
| 1299 |
+
q,
|
| 1300 |
+
k,
|
| 1301 |
+
v,
|
| 1302 |
+
dropout_p,
|
| 1303 |
+
softmax_scale,
|
| 1304 |
+
causal,
|
| 1305 |
+
window_size,
|
| 1306 |
+
softcap,
|
| 1307 |
+
alibi_slopes,
|
| 1308 |
+
deterministic,
|
| 1309 |
+
return_attn_probs,
|
| 1310 |
+
torch.is_grad_enabled(),
|
| 1311 |
+
)
|
| 1312 |
+
|
| 1313 |
+
|
| 1314 |
+
def flash_attn_varlen_qkvpacked_func(
|
| 1315 |
+
qkv,
|
| 1316 |
+
cu_seqlens,
|
| 1317 |
+
max_seqlen,
|
| 1318 |
+
dropout_p=0.0,
|
| 1319 |
+
softmax_scale=None,
|
| 1320 |
+
causal=False,
|
| 1321 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1322 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1323 |
+
alibi_slopes=None,
|
| 1324 |
+
deterministic=False,
|
| 1325 |
+
return_attn_probs=False,
|
| 1326 |
+
):
|
| 1327 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1328 |
+
If Q, K, V are already stacked into 1 tensor, this function will be faster than
|
| 1329 |
+
calling flash_attn_varlen_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1330 |
+
of the gradients of Q, K, V.
|
| 1331 |
+
For multi-query and grouped-query attention (MQA/GQA), please see
|
| 1332 |
+
flash_attn_varlen_kvpacked_func and flash_attn_varlen_func.
|
| 1333 |
+
|
| 1334 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1335 |
+
will only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.
|
| 1336 |
+
|
| 1337 |
+
Arguments:
|
| 1338 |
+
qkv: (total, 3, nheads, headdim), where total = total number of tokens in the batch.
|
| 1339 |
+
cu_seqlens: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1340 |
+
of the sequences in the batch, used to index into qkv.
|
| 1341 |
+
max_seqlen: int. Maximum sequence length in the batch.
|
| 1342 |
+
dropout_p: float. Dropout probability.
|
| 1343 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1344 |
+
Default to 1 / sqrt(headdim).
|
| 1345 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1346 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1347 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1348 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|)
|
| 1349 |
+
is added to the attention score of query i and key j.
|
| 1350 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1351 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1352 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1353 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1354 |
+
(they might not have the right scaling).
|
| 1355 |
+
Return:
|
| 1356 |
+
out: (total, nheads, headdim).
|
| 1357 |
+
softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The
|
| 1358 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1359 |
+
normalization factor).
|
| 1360 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1361 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1362 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1363 |
+
"""
|
| 1364 |
+
return FlashAttnVarlenQKVPackedFunc.apply(
|
| 1365 |
+
qkv,
|
| 1366 |
+
cu_seqlens,
|
| 1367 |
+
max_seqlen,
|
| 1368 |
+
dropout_p,
|
| 1369 |
+
softmax_scale,
|
| 1370 |
+
causal,
|
| 1371 |
+
window_size,
|
| 1372 |
+
softcap,
|
| 1373 |
+
alibi_slopes,
|
| 1374 |
+
deterministic,
|
| 1375 |
+
return_attn_probs,
|
| 1376 |
+
torch.is_grad_enabled(),
|
| 1377 |
+
)
|
| 1378 |
+
|
| 1379 |
+
|
| 1380 |
+
def flash_attn_varlen_kvpacked_func(
|
| 1381 |
+
q,
|
| 1382 |
+
kv,
|
| 1383 |
+
cu_seqlens_q,
|
| 1384 |
+
cu_seqlens_k,
|
| 1385 |
+
max_seqlen_q,
|
| 1386 |
+
max_seqlen_k,
|
| 1387 |
+
dropout_p=0.0,
|
| 1388 |
+
softmax_scale=None,
|
| 1389 |
+
causal=False,
|
| 1390 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1391 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1392 |
+
alibi_slopes=None,
|
| 1393 |
+
deterministic=False,
|
| 1394 |
+
return_attn_probs=False,
|
| 1395 |
+
):
|
| 1396 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1397 |
+
If K, V are already stacked into 1 tensor, this function will be faster than
|
| 1398 |
+
calling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1399 |
+
of the gradients of K, V.
|
| 1400 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1401 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1402 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1403 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1404 |
+
|
| 1405 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1406 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1407 |
+
1 1 1 1 0
|
| 1408 |
+
1 1 1 1 1
|
| 1409 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1410 |
+
0 0
|
| 1411 |
+
0 0
|
| 1412 |
+
0 0
|
| 1413 |
+
1 0
|
| 1414 |
+
1 1
|
| 1415 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1416 |
+
|
| 1417 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1418 |
+
will only attend to keys between
|
| 1419 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1420 |
+
|
| 1421 |
+
Arguments:
|
| 1422 |
+
q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.
|
| 1423 |
+
kv: (total_k, 2, nheads_k, headdim), where total_k = total number of key tokens in the batch.
|
| 1424 |
+
cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1425 |
+
of the sequences in the batch, used to index into q.
|
| 1426 |
+
cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1427 |
+
of the sequences in the batch, used to index into kv.
|
| 1428 |
+
max_seqlen_q: int. Maximum query sequence length in the batch.
|
| 1429 |
+
max_seqlen_k: int. Maximum key sequence length in the batch.
|
| 1430 |
+
dropout_p: float. Dropout probability.
|
| 1431 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1432 |
+
Default to 1 / sqrt(headdim).
|
| 1433 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1434 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1435 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1436 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1437 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1438 |
+
is added to the attention score of query i and key j.
|
| 1439 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1440 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1441 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1442 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1443 |
+
(they might not have the right scaling).
|
| 1444 |
+
Return:
|
| 1445 |
+
out: (total, nheads, headdim).
|
| 1446 |
+
softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The
|
| 1447 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1448 |
+
normalization factor).
|
| 1449 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1450 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1451 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1452 |
+
"""
|
| 1453 |
+
return FlashAttnVarlenKVPackedFunc.apply(
|
| 1454 |
+
q,
|
| 1455 |
+
kv,
|
| 1456 |
+
cu_seqlens_q,
|
| 1457 |
+
cu_seqlens_k,
|
| 1458 |
+
max_seqlen_q,
|
| 1459 |
+
max_seqlen_k,
|
| 1460 |
+
dropout_p,
|
| 1461 |
+
softmax_scale,
|
| 1462 |
+
causal,
|
| 1463 |
+
window_size,
|
| 1464 |
+
softcap,
|
| 1465 |
+
alibi_slopes,
|
| 1466 |
+
deterministic,
|
| 1467 |
+
return_attn_probs,
|
| 1468 |
+
torch.is_grad_enabled(),
|
| 1469 |
+
)
|
| 1470 |
+
|
| 1471 |
+
|
| 1472 |
+
def flash_attn_varlen_func(
|
| 1473 |
+
q,
|
| 1474 |
+
k,
|
| 1475 |
+
v,
|
| 1476 |
+
cu_seqlens_q,
|
| 1477 |
+
cu_seqlens_k,
|
| 1478 |
+
max_seqlen_q,
|
| 1479 |
+
max_seqlen_k,
|
| 1480 |
+
dropout_p=0.0,
|
| 1481 |
+
softmax_scale=None,
|
| 1482 |
+
causal=False,
|
| 1483 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1484 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1485 |
+
alibi_slopes=None,
|
| 1486 |
+
deterministic=False,
|
| 1487 |
+
return_attn_probs=False,
|
| 1488 |
+
block_table=None,
|
| 1489 |
+
):
|
| 1490 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1491 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in K, V with fewer heads
|
| 1492 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1493 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1494 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1495 |
+
|
| 1496 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1497 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1498 |
+
1 1 1 1 0
|
| 1499 |
+
1 1 1 1 1
|
| 1500 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1501 |
+
0 0
|
| 1502 |
+
0 0
|
| 1503 |
+
0 0
|
| 1504 |
+
1 0
|
| 1505 |
+
1 1
|
| 1506 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1507 |
+
|
| 1508 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1509 |
+
will only attend to keys between
|
| 1510 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1511 |
+
|
| 1512 |
+
Arguments:
|
| 1513 |
+
q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.
|
| 1514 |
+
k: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.
|
| 1515 |
+
v: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.
|
| 1516 |
+
cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1517 |
+
of the sequences in the batch, used to index into q.
|
| 1518 |
+
cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1519 |
+
of the sequences in the batch, used to index into kv.
|
| 1520 |
+
max_seqlen_q: int. Maximum query sequence length in the batch.
|
| 1521 |
+
max_seqlen_k: int. Maximum key sequence length in the batch.
|
| 1522 |
+
dropout_p: float. Dropout probability.
|
| 1523 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1524 |
+
Default to 1 / sqrt(headdim).
|
| 1525 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1526 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1527 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1528 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1529 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1530 |
+
is added to the attention score of query i and key j.
|
| 1531 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1532 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1533 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1534 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1535 |
+
(they might not have the right scaling).
|
| 1536 |
+
Return:
|
| 1537 |
+
out: (total, nheads, headdim).
|
| 1538 |
+
softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The
|
| 1539 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1540 |
+
normalization factor).
|
| 1541 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1542 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1543 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1544 |
+
"""
|
| 1545 |
+
return FlashAttnVarlenFunc.apply(
|
| 1546 |
+
q,
|
| 1547 |
+
k,
|
| 1548 |
+
v,
|
| 1549 |
+
cu_seqlens_q,
|
| 1550 |
+
cu_seqlens_k,
|
| 1551 |
+
max_seqlen_q,
|
| 1552 |
+
max_seqlen_k,
|
| 1553 |
+
dropout_p,
|
| 1554 |
+
softmax_scale,
|
| 1555 |
+
causal,
|
| 1556 |
+
window_size,
|
| 1557 |
+
softcap,
|
| 1558 |
+
alibi_slopes,
|
| 1559 |
+
deterministic,
|
| 1560 |
+
return_attn_probs,
|
| 1561 |
+
block_table,
|
| 1562 |
+
False if q.device.type == "cpu" else torch.is_grad_enabled(),
|
| 1563 |
+
)
|
| 1564 |
+
|
| 1565 |
+
|
| 1566 |
+
def flash_attn_with_kvcache(
|
| 1567 |
+
q,
|
| 1568 |
+
k_cache,
|
| 1569 |
+
v_cache,
|
| 1570 |
+
k=None,
|
| 1571 |
+
v=None,
|
| 1572 |
+
rotary_cos=None,
|
| 1573 |
+
rotary_sin=None,
|
| 1574 |
+
cache_seqlens: Optional[Union[(int, torch.Tensor)]] = None,
|
| 1575 |
+
cache_batch_idx: Optional[torch.Tensor] = None,
|
| 1576 |
+
cache_leftpad: Optional[torch.Tensor] = None,
|
| 1577 |
+
block_table: Optional[torch.Tensor] = None,
|
| 1578 |
+
softmax_scale=None,
|
| 1579 |
+
causal=False,
|
| 1580 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1581 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1582 |
+
rotary_interleaved=True,
|
| 1583 |
+
alibi_slopes=None,
|
| 1584 |
+
num_splits=0,
|
| 1585 |
+
return_softmax_lse=False,
|
| 1586 |
+
):
|
| 1587 |
+
"""
|
| 1588 |
+
If k and v are not None, k_cache and v_cache will be updated *inplace* with the new values from
|
| 1589 |
+
k and v. This is useful for incremental decoding: you can pass in the cached keys/values from
|
| 1590 |
+
the previous step, and update them with the new keys/values from the current step, and do
|
| 1591 |
+
attention with the updated cache, all in 1 kernel.
|
| 1592 |
+
|
| 1593 |
+
If you pass in k / v, you must make sure that the cache is large enough to hold the new values.
|
| 1594 |
+
For example, the KV cache could be pre-allocated with the max sequence length, and you can use
|
| 1595 |
+
cache_seqlens to keep track of the current sequence lengths of each sequence in the batch.
|
| 1596 |
+
|
| 1597 |
+
Also apply rotary embedding if rotary_cos and rotary_sin are passed in. The key @k will be
|
| 1598 |
+
rotated by rotary_cos and rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.
|
| 1599 |
+
If causal or local (i.e., window_size != (-1, -1)), the query @q will be rotated by rotary_cos
|
| 1600 |
+
and rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.
|
| 1601 |
+
If not causal and not local, the query @q will be rotated by rotary_cos and rotary_sin at
|
| 1602 |
+
indices cache_seqlens only (i.e. we consider all tokens in @q to be at position cache_seqlens).
|
| 1603 |
+
|
| 1604 |
+
See tests/test_flash_attn.py::test_flash_attn_kvcache for examples of how to use this function.
|
| 1605 |
+
|
| 1606 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1607 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1608 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1609 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1610 |
+
|
| 1611 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1612 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1613 |
+
1 1 1 1 0
|
| 1614 |
+
1 1 1 1 1
|
| 1615 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1616 |
+
0 0
|
| 1617 |
+
0 0
|
| 1618 |
+
0 0
|
| 1619 |
+
1 0
|
| 1620 |
+
1 1
|
| 1621 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1622 |
+
|
| 1623 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1624 |
+
will only attend to keys between
|
| 1625 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1626 |
+
|
| 1627 |
+
Note: Does not support backward pass.
|
| 1628 |
+
|
| 1629 |
+
Arguments:
|
| 1630 |
+
q: (batch_size, seqlen, nheads, headdim)
|
| 1631 |
+
k_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,
|
| 1632 |
+
or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)
|
| 1633 |
+
page_block_size must be a multiple of 256.
|
| 1634 |
+
v_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,
|
| 1635 |
+
or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)
|
| 1636 |
+
k [optional]: (batch_size, seqlen_new, nheads_k, headdim). If not None, we concatenate
|
| 1637 |
+
k with k_cache, starting at the indices specified by cache_seqlens.
|
| 1638 |
+
v [optional]: (batch_size, seqlen_new, nheads_k, headdim). Similar to k.
|
| 1639 |
+
rotary_cos [optional]: (seqlen_ro, rotary_dim / 2). If not None, we apply rotary embedding
|
| 1640 |
+
to k and q. Only applicable if k and v are passed in. rotary_dim must be divisible by 16.
|
| 1641 |
+
rotary_sin [optional]: (seqlen_ro, rotary_dim / 2). Similar to rotary_cos.
|
| 1642 |
+
cache_seqlens: int, or (batch_size,), dtype torch.int32. The sequence lengths of the
|
| 1643 |
+
KV cache.
|
| 1644 |
+
cache_batch_idx: (batch_size,), dtype torch.int32. The indices used to index into the KV cache.
|
| 1645 |
+
If None, we assume that the batch indices are [0, 1, 2, ..., batch_size - 1].
|
| 1646 |
+
If the indices are not distinct, and k and v are provided, the values updated in the cache
|
| 1647 |
+
might come from any of the duplicate indices.
|
| 1648 |
+
cache_leftpad: (batch_size,), dtype torch.int32. The index that the KV cache starts. If None, assume 0.
|
| 1649 |
+
block_table [optional]: (batch_size, max_num_blocks_per_seq), dtype torch.int32.
|
| 1650 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1651 |
+
Default to 1 / sqrt(headdim).
|
| 1652 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1653 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1654 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1655 |
+
rotary_interleaved: bool. Only applicable if rotary_cos and rotary_sin are passed in.
|
| 1656 |
+
If True, rotary embedding will combine dimensions 0 & 1, 2 & 3, etc. If False,
|
| 1657 |
+
rotary embedding will combine dimensions 0 & rotary_dim / 2, 1 & rotary_dim / 2 + 1
|
| 1658 |
+
(i.e. GPT-NeoX style).
|
| 1659 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1660 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1661 |
+
is added to the attention score of query i and key j.
|
| 1662 |
+
num_splits: int. If > 1, split the key/value into this many chunks along the sequence.
|
| 1663 |
+
If num_splits == 1, we don't split the key/value. If num_splits == 0, we use a heuristic
|
| 1664 |
+
to automatically determine the number of splits.
|
| 1665 |
+
Don't change this unless you know what you are doing.
|
| 1666 |
+
return_softmax_lse: bool. Whether to return the logsumexp of the attention scores.
|
| 1667 |
+
|
| 1668 |
+
Return:
|
| 1669 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1670 |
+
softmax_lse [optional, if return_softmax_lse=True]: (batch_size, nheads, seqlen). The
|
| 1671 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1672 |
+
normalization factor).
|
| 1673 |
+
"""
|
| 1674 |
+
assert k_cache.stride(-1) == 1, "k_cache must have contiguous last dimension"
|
| 1675 |
+
assert v_cache.stride(-1) == 1, "v_cache must have contiguous last dimension"
|
| 1676 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 1677 |
+
if softmax_scale is None:
|
| 1678 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 1679 |
+
if cache_seqlens is not None and isinstance(cache_seqlens, int):
|
| 1680 |
+
cache_seqlens = torch.full(
|
| 1681 |
+
(k_cache.shape[0],), cache_seqlens, dtype=torch.int32, device=k_cache.device
|
| 1682 |
+
)
|
| 1683 |
+
cache_seqlens = maybe_contiguous(cache_seqlens)
|
| 1684 |
+
cache_batch_idx = maybe_contiguous(cache_batch_idx)
|
| 1685 |
+
block_table = maybe_contiguous(block_table)
|
| 1686 |
+
out, softmax_lse = flash_attn.fwd_kvcache(
|
| 1687 |
+
q,
|
| 1688 |
+
k_cache,
|
| 1689 |
+
v_cache,
|
| 1690 |
+
k,
|
| 1691 |
+
v,
|
| 1692 |
+
cache_seqlens,
|
| 1693 |
+
rotary_cos,
|
| 1694 |
+
rotary_sin,
|
| 1695 |
+
cache_batch_idx,
|
| 1696 |
+
cache_leftpad,
|
| 1697 |
+
block_table,
|
| 1698 |
+
alibi_slopes,
|
| 1699 |
+
None,
|
| 1700 |
+
softmax_scale,
|
| 1701 |
+
causal,
|
| 1702 |
+
window_size[0],
|
| 1703 |
+
window_size[1],
|
| 1704 |
+
softcap,
|
| 1705 |
+
rotary_interleaved,
|
| 1706 |
+
num_splits,
|
| 1707 |
+
)
|
| 1708 |
+
return (out, softmax_lse) if return_softmax_lse else out
|
build/torch-stable-abi210-cu126-aarch64-linux/metadata.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "flash-attn2",
|
| 3 |
+
"id": "_flash_attn2_cuda_460047c",
|
| 4 |
+
"version": 4,
|
| 5 |
+
"kernels-minver": "0.14.0",
|
| 6 |
+
"license": "BSD-3-Clause",
|
| 7 |
+
"python-depends": [],
|
| 8 |
+
"kernel-depends": [],
|
| 9 |
+
"backend": {
|
| 10 |
+
"type": "cuda",
|
| 11 |
+
"archs": [
|
| 12 |
+
"8.0",
|
| 13 |
+
"9.0"
|
| 14 |
+
]
|
| 15 |
+
},
|
| 16 |
+
"digest": {
|
| 17 |
+
"algorithm": "sha256",
|
| 18 |
+
"files": {
|
| 19 |
+
"__init__.py": "Nz8hqrusjoUHQqszpxfF2USMwUXn1VfpvcmtAAvutSM=",
|
| 20 |
+
"_flash_attn2_cuda_460047c.abi3.so": "3kHgiHr9cfyiLMCy91oPoTJGHumJQ1KfsHP2dnozBWs=",
|
| 21 |
+
"_ops.py": "DV4Eo4+s3aaNmDsfXoZiYKNLnRUJqlsdDGlMsdKFgk4=",
|
| 22 |
+
"flash_attn_interface.py": "6UYUhfUax4+yOUygyS7K8dVjrIjU5GQr1AJ2gSp8rPo=",
|
| 23 |
+
"symbols.json": "uvC+87tHUhtHv7L/Nl53T/Ms7ceX317/jwQBoqHY14A="
|
| 24 |
+
}
|
| 25 |
+
},
|
| 26 |
+
"provenance": {
|
| 27 |
+
"kernel-builder": {
|
| 28 |
+
"version": "0.18.0-dev0",
|
| 29 |
+
"commit": "d054906a13710b811b96697b4635f03020842733",
|
| 30 |
+
"dirty": false
|
| 31 |
+
},
|
| 32 |
+
"kernel": {
|
| 33 |
+
"commit": "460047c291fc7f0b3dbd4239b46bd5e1281b1806",
|
| 34 |
+
"dirty": false
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
}
|
build/torch-stable-abi210-cu126-aarch64-linux/metadata.json.sigstore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"mediaType":"application/vnd.dev.sigstore.bundle.v0.3+json","verificationMaterial":{"certificate":{"rawBytes":"MIIHLDCCBrGgAwIBAgIUBo1ks8d30sjWI29uW4tvs06Uni0wCgYIKoZIzj0EAwMwNzEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MR4wHAYDVQQDExVzaWdzdG9yZS1pbnRlcm1lZGlhdGUwHhcNMjYxMDI0MDAwNzQ2WhcNMjYxMDI0MDAxNzQ2WjAAMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEEzA99VPpsYDB2mkOR8D8Ny5mxwdRyzlpQV+P+bE8CoxdCpWd09IH013MGaePr13ZWqTY7DEQ8+3bJoM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ZvpFBP4P9Q=="},"tlogEntries":[{"logIndex":"3430230245","logId":{"keyId":"wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="},"kindVersion":{"kind":"hashedrekord","version":"0.0.1"},"integratedTime":"1792800466","inclusionPromise":{"signedEntryTimestamp":"MEQCICEYIjYMuYPLk7awtJYUASuf8XztXLMTPs4X+7Lpm3SDAiBQ2efj7gnDF/2NSMrJ86bJTfQ7rYpmYzchaNwDe1o2Jg=="},"inclusionProof":{"logIndex":"3308325983","rootHash":"9RhrJeVdTN1XWyq96fL3jjoOsc1nFsM/HES3FIUszPY=","treeSize":"3308326223","hashes":["ZZUqFo+YHPeC5R2p2SNck7J01R9ENmB4BWVMlc/slXA=","w1p4nI+R9aogwUiO35DVWRpok9RtvnHgMp91m1i7zoQ=","+kPgoLboWgPIQiwgl1SZtK3PTOu2+ACMpj/nlyywJEQ=","Asr5xdoDBoe5g4/E1xBri09H+TR7Hg8RYo8YPR50xUo=","s/j4WllkZVu4yLXws1v72aG8K1grAGGvb8ScmOZRxos=","JJNA2oVUYuX1sAXI7HnJAGnj/FjXacYPyZRxdAttFwg=","TjxCovIPh2dORfx6kgB6177znXUUsc7rfrk5J/CY1Ig=","UJUvB1WAmOcG2neywwATlbUwjcr87A3PcVOC1+jgJC4=","pUGUimNXW8f8DrPF31Qf+xxBakJshScZqbbDtWrHgkA=","PuwdRME/93l6s2BMRjCojmjsVC29KnBqdtPSPE1l6cQ=","tWdxtMrYqmZ0zKHnOCAERPP7SvuDvubtw3jwj7rH4uA=","8x0N/oAmvpY+6DQUGTU+i6a1Cuqphro2WbV5WZ/RHL8=","DMchGrSAeKV9qHo75XJV3UFZ/CHF8zofPRu+NgVRwA4=","V6dXjeDcwYxBG/9gVSBM8rYdPrAqGpZsf1e7v6l67GA=","iDfImp65w8dirRfYGNgFA34JTUYDWbcJwNBBU/Ok+X4=","YYCr61A8azar3dfO8Ct+pri7LqDxkUlUkfs7fiqYErU=","1DaDKzrCNNB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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema_version": 1,
|
| 3 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 4 |
+
"functions": [
|
| 5 |
+
{
|
| 6 |
+
"name": "flash_attn_func",
|
| 7 |
+
"qualname": "flash_attn_func",
|
| 8 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 9 |
+
"kind": "function",
|
| 10 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (batch_size, seqlen, nheads, headdim)\n k: (batch_size, seqlen, nheads_k, headdim)\n v: (batch_size, seqlen, nheads_k, headdim)\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 11 |
+
"signature": {
|
| 12 |
+
"parameters": [
|
| 13 |
+
{
|
| 14 |
+
"name": "q",
|
| 15 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 16 |
+
"default": null,
|
| 17 |
+
"annotation": null
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"name": "k",
|
| 21 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 22 |
+
"default": null,
|
| 23 |
+
"annotation": null
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"name": "v",
|
| 27 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 28 |
+
"default": null,
|
| 29 |
+
"annotation": null
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"name": "dropout_p",
|
| 33 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 34 |
+
"default": "0.0",
|
| 35 |
+
"annotation": null
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"name": "softmax_scale",
|
| 39 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 40 |
+
"default": "None",
|
| 41 |
+
"annotation": null
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"name": "causal",
|
| 45 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 46 |
+
"default": "False",
|
| 47 |
+
"annotation": null
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"name": "window_size",
|
| 51 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 52 |
+
"default": "(-1, -1)",
|
| 53 |
+
"annotation": null
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"name": "softcap",
|
| 57 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 58 |
+
"default": "0.0",
|
| 59 |
+
"annotation": null
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"name": "alibi_slopes",
|
| 63 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 64 |
+
"default": "None",
|
| 65 |
+
"annotation": null
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"name": "deterministic",
|
| 69 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 70 |
+
"default": "False",
|
| 71 |
+
"annotation": null
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"name": "return_attn_probs",
|
| 75 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 76 |
+
"default": "False",
|
| 77 |
+
"annotation": null
|
| 78 |
+
}
|
| 79 |
+
],
|
| 80 |
+
"return_annotation": null
|
| 81 |
+
}
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
"name": "flash_attn_kvpacked_func",
|
| 85 |
+
"qualname": "flash_attn_kvpacked_func",
|
| 86 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 87 |
+
"kind": "function",
|
| 88 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of K, V.\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (batch_size, seqlen, nheads, headdim)\n kv: (batch_size, seqlen, 2, nheads_k, headdim)\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 89 |
+
"signature": {
|
| 90 |
+
"parameters": [
|
| 91 |
+
{
|
| 92 |
+
"name": "q",
|
| 93 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 94 |
+
"default": null,
|
| 95 |
+
"annotation": null
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"name": "kv",
|
| 99 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 100 |
+
"default": null,
|
| 101 |
+
"annotation": null
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"name": "dropout_p",
|
| 105 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 106 |
+
"default": "0.0",
|
| 107 |
+
"annotation": null
|
| 108 |
+
},
|
| 109 |
+
{
|
| 110 |
+
"name": "softmax_scale",
|
| 111 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 112 |
+
"default": "None",
|
| 113 |
+
"annotation": null
|
| 114 |
+
},
|
| 115 |
+
{
|
| 116 |
+
"name": "causal",
|
| 117 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 118 |
+
"default": "False",
|
| 119 |
+
"annotation": null
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"name": "window_size",
|
| 123 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 124 |
+
"default": "(-1, -1)",
|
| 125 |
+
"annotation": null
|
| 126 |
+
},
|
| 127 |
+
{
|
| 128 |
+
"name": "softcap",
|
| 129 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 130 |
+
"default": "0.0",
|
| 131 |
+
"annotation": null
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
"name": "alibi_slopes",
|
| 135 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 136 |
+
"default": "None",
|
| 137 |
+
"annotation": null
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"name": "deterministic",
|
| 141 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 142 |
+
"default": "False",
|
| 143 |
+
"annotation": null
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"name": "return_attn_probs",
|
| 147 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 148 |
+
"default": "False",
|
| 149 |
+
"annotation": null
|
| 150 |
+
}
|
| 151 |
+
],
|
| 152 |
+
"return_annotation": null
|
| 153 |
+
}
|
| 154 |
+
},
|
| 155 |
+
{
|
| 156 |
+
"name": "flash_attn_qkvpacked_func",
|
| 157 |
+
"qualname": "flash_attn_qkvpacked_func",
|
| 158 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 159 |
+
"kind": "function",
|
| 160 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf Q, K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of Q, K, V.\nFor multi-query and grouped-query attention (MQA/GQA), please see\nflash_attn_kvpacked_func and flash_attn_func.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.\n\nArguments:\n qkv: (batch_size, seqlen, 3, nheads, headdim)\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|) is added to\n the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 161 |
+
"signature": {
|
| 162 |
+
"parameters": [
|
| 163 |
+
{
|
| 164 |
+
"name": "qkv",
|
| 165 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 166 |
+
"default": null,
|
| 167 |
+
"annotation": null
|
| 168 |
+
},
|
| 169 |
+
{
|
| 170 |
+
"name": "dropout_p",
|
| 171 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 172 |
+
"default": "0.0",
|
| 173 |
+
"annotation": null
|
| 174 |
+
},
|
| 175 |
+
{
|
| 176 |
+
"name": "softmax_scale",
|
| 177 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 178 |
+
"default": "None",
|
| 179 |
+
"annotation": null
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
"name": "causal",
|
| 183 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 184 |
+
"default": "False",
|
| 185 |
+
"annotation": null
|
| 186 |
+
},
|
| 187 |
+
{
|
| 188 |
+
"name": "window_size",
|
| 189 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 190 |
+
"default": "(-1, -1)",
|
| 191 |
+
"annotation": null
|
| 192 |
+
},
|
| 193 |
+
{
|
| 194 |
+
"name": "softcap",
|
| 195 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 196 |
+
"default": "0.0",
|
| 197 |
+
"annotation": null
|
| 198 |
+
},
|
| 199 |
+
{
|
| 200 |
+
"name": "alibi_slopes",
|
| 201 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 202 |
+
"default": "None",
|
| 203 |
+
"annotation": null
|
| 204 |
+
},
|
| 205 |
+
{
|
| 206 |
+
"name": "deterministic",
|
| 207 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 208 |
+
"default": "False",
|
| 209 |
+
"annotation": null
|
| 210 |
+
},
|
| 211 |
+
{
|
| 212 |
+
"name": "return_attn_probs",
|
| 213 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 214 |
+
"default": "False",
|
| 215 |
+
"annotation": null
|
| 216 |
+
}
|
| 217 |
+
],
|
| 218 |
+
"return_annotation": null
|
| 219 |
+
}
|
| 220 |
+
},
|
| 221 |
+
{
|
| 222 |
+
"name": "flash_attn_varlen_func",
|
| 223 |
+
"qualname": "flash_attn_varlen_func",
|
| 224 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 225 |
+
"kind": "function",
|
| 226 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in K, V with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.\n k: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.\n v: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.\n cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into q.\n cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into kv.\n max_seqlen_q: int. Maximum query sequence length in the batch.\n max_seqlen_k: int. Maximum key sequence length in the batch.\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (total, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 227 |
+
"signature": {
|
| 228 |
+
"parameters": [
|
| 229 |
+
{
|
| 230 |
+
"name": "q",
|
| 231 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 232 |
+
"default": null,
|
| 233 |
+
"annotation": null
|
| 234 |
+
},
|
| 235 |
+
{
|
| 236 |
+
"name": "k",
|
| 237 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 238 |
+
"default": null,
|
| 239 |
+
"annotation": null
|
| 240 |
+
},
|
| 241 |
+
{
|
| 242 |
+
"name": "v",
|
| 243 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 244 |
+
"default": null,
|
| 245 |
+
"annotation": null
|
| 246 |
+
},
|
| 247 |
+
{
|
| 248 |
+
"name": "cu_seqlens_q",
|
| 249 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 250 |
+
"default": null,
|
| 251 |
+
"annotation": null
|
| 252 |
+
},
|
| 253 |
+
{
|
| 254 |
+
"name": "cu_seqlens_k",
|
| 255 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 256 |
+
"default": null,
|
| 257 |
+
"annotation": null
|
| 258 |
+
},
|
| 259 |
+
{
|
| 260 |
+
"name": "max_seqlen_q",
|
| 261 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 262 |
+
"default": null,
|
| 263 |
+
"annotation": null
|
| 264 |
+
},
|
| 265 |
+
{
|
| 266 |
+
"name": "max_seqlen_k",
|
| 267 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 268 |
+
"default": null,
|
| 269 |
+
"annotation": null
|
| 270 |
+
},
|
| 271 |
+
{
|
| 272 |
+
"name": "dropout_p",
|
| 273 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 274 |
+
"default": "0.0",
|
| 275 |
+
"annotation": null
|
| 276 |
+
},
|
| 277 |
+
{
|
| 278 |
+
"name": "softmax_scale",
|
| 279 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 280 |
+
"default": "None",
|
| 281 |
+
"annotation": null
|
| 282 |
+
},
|
| 283 |
+
{
|
| 284 |
+
"name": "causal",
|
| 285 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 286 |
+
"default": "False",
|
| 287 |
+
"annotation": null
|
| 288 |
+
},
|
| 289 |
+
{
|
| 290 |
+
"name": "window_size",
|
| 291 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 292 |
+
"default": "(-1, -1)",
|
| 293 |
+
"annotation": null
|
| 294 |
+
},
|
| 295 |
+
{
|
| 296 |
+
"name": "softcap",
|
| 297 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 298 |
+
"default": "0.0",
|
| 299 |
+
"annotation": null
|
| 300 |
+
},
|
| 301 |
+
{
|
| 302 |
+
"name": "alibi_slopes",
|
| 303 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 304 |
+
"default": "None",
|
| 305 |
+
"annotation": null
|
| 306 |
+
},
|
| 307 |
+
{
|
| 308 |
+
"name": "deterministic",
|
| 309 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 310 |
+
"default": "False",
|
| 311 |
+
"annotation": null
|
| 312 |
+
},
|
| 313 |
+
{
|
| 314 |
+
"name": "return_attn_probs",
|
| 315 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 316 |
+
"default": "False",
|
| 317 |
+
"annotation": null
|
| 318 |
+
},
|
| 319 |
+
{
|
| 320 |
+
"name": "block_table",
|
| 321 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 322 |
+
"default": "None",
|
| 323 |
+
"annotation": null
|
| 324 |
+
}
|
| 325 |
+
],
|
| 326 |
+
"return_annotation": null
|
| 327 |
+
}
|
| 328 |
+
},
|
| 329 |
+
{
|
| 330 |
+
"name": "flash_attn_varlen_kvpacked_func",
|
| 331 |
+
"qualname": "flash_attn_varlen_kvpacked_func",
|
| 332 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 333 |
+
"kind": "function",
|
| 334 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of K, V.\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.\n kv: (total_k, 2, nheads_k, headdim), where total_k = total number of key tokens in the batch.\n cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into q.\n cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into kv.\n max_seqlen_q: int. Maximum query sequence length in the batch.\n max_seqlen_k: int. Maximum key sequence length in the batch.\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (total, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 335 |
+
"signature": {
|
| 336 |
+
"parameters": [
|
| 337 |
+
{
|
| 338 |
+
"name": "q",
|
| 339 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 340 |
+
"default": null,
|
| 341 |
+
"annotation": null
|
| 342 |
+
},
|
| 343 |
+
{
|
| 344 |
+
"name": "kv",
|
| 345 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 346 |
+
"default": null,
|
| 347 |
+
"annotation": null
|
| 348 |
+
},
|
| 349 |
+
{
|
| 350 |
+
"name": "cu_seqlens_q",
|
| 351 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 352 |
+
"default": null,
|
| 353 |
+
"annotation": null
|
| 354 |
+
},
|
| 355 |
+
{
|
| 356 |
+
"name": "cu_seqlens_k",
|
| 357 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 358 |
+
"default": null,
|
| 359 |
+
"annotation": null
|
| 360 |
+
},
|
| 361 |
+
{
|
| 362 |
+
"name": "max_seqlen_q",
|
| 363 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 364 |
+
"default": null,
|
| 365 |
+
"annotation": null
|
| 366 |
+
},
|
| 367 |
+
{
|
| 368 |
+
"name": "max_seqlen_k",
|
| 369 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 370 |
+
"default": null,
|
| 371 |
+
"annotation": null
|
| 372 |
+
},
|
| 373 |
+
{
|
| 374 |
+
"name": "dropout_p",
|
| 375 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 376 |
+
"default": "0.0",
|
| 377 |
+
"annotation": null
|
| 378 |
+
},
|
| 379 |
+
{
|
| 380 |
+
"name": "softmax_scale",
|
| 381 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 382 |
+
"default": "None",
|
| 383 |
+
"annotation": null
|
| 384 |
+
},
|
| 385 |
+
{
|
| 386 |
+
"name": "causal",
|
| 387 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 388 |
+
"default": "False",
|
| 389 |
+
"annotation": null
|
| 390 |
+
},
|
| 391 |
+
{
|
| 392 |
+
"name": "window_size",
|
| 393 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 394 |
+
"default": "(-1, -1)",
|
| 395 |
+
"annotation": null
|
| 396 |
+
},
|
| 397 |
+
{
|
| 398 |
+
"name": "softcap",
|
| 399 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 400 |
+
"default": "0.0",
|
| 401 |
+
"annotation": null
|
| 402 |
+
},
|
| 403 |
+
{
|
| 404 |
+
"name": "alibi_slopes",
|
| 405 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 406 |
+
"default": "None",
|
| 407 |
+
"annotation": null
|
| 408 |
+
},
|
| 409 |
+
{
|
| 410 |
+
"name": "deterministic",
|
| 411 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 412 |
+
"default": "False",
|
| 413 |
+
"annotation": null
|
| 414 |
+
},
|
| 415 |
+
{
|
| 416 |
+
"name": "return_attn_probs",
|
| 417 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 418 |
+
"default": "False",
|
| 419 |
+
"annotation": null
|
| 420 |
+
}
|
| 421 |
+
],
|
| 422 |
+
"return_annotation": null
|
| 423 |
+
}
|
| 424 |
+
},
|
| 425 |
+
{
|
| 426 |
+
"name": "flash_attn_varlen_qkvpacked_func",
|
| 427 |
+
"qualname": "flash_attn_varlen_qkvpacked_func",
|
| 428 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 429 |
+
"kind": "function",
|
| 430 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf Q, K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_varlen_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of Q, K, V.\nFor multi-query and grouped-query attention (MQA/GQA), please see\nflash_attn_varlen_kvpacked_func and flash_attn_varlen_func.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.\n\nArguments:\n qkv: (total, 3, nheads, headdim), where total = total number of tokens in the batch.\n cu_seqlens: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into qkv.\n max_seqlen: int. Maximum sequence length in the batch.\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (total, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 431 |
+
"signature": {
|
| 432 |
+
"parameters": [
|
| 433 |
+
{
|
| 434 |
+
"name": "qkv",
|
| 435 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 436 |
+
"default": null,
|
| 437 |
+
"annotation": null
|
| 438 |
+
},
|
| 439 |
+
{
|
| 440 |
+
"name": "cu_seqlens",
|
| 441 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 442 |
+
"default": null,
|
| 443 |
+
"annotation": null
|
| 444 |
+
},
|
| 445 |
+
{
|
| 446 |
+
"name": "max_seqlen",
|
| 447 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 448 |
+
"default": null,
|
| 449 |
+
"annotation": null
|
| 450 |
+
},
|
| 451 |
+
{
|
| 452 |
+
"name": "dropout_p",
|
| 453 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 454 |
+
"default": "0.0",
|
| 455 |
+
"annotation": null
|
| 456 |
+
},
|
| 457 |
+
{
|
| 458 |
+
"name": "softmax_scale",
|
| 459 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 460 |
+
"default": "None",
|
| 461 |
+
"annotation": null
|
| 462 |
+
},
|
| 463 |
+
{
|
| 464 |
+
"name": "causal",
|
| 465 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 466 |
+
"default": "False",
|
| 467 |
+
"annotation": null
|
| 468 |
+
},
|
| 469 |
+
{
|
| 470 |
+
"name": "window_size",
|
| 471 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 472 |
+
"default": "(-1, -1)",
|
| 473 |
+
"annotation": null
|
| 474 |
+
},
|
| 475 |
+
{
|
| 476 |
+
"name": "softcap",
|
| 477 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 478 |
+
"default": "0.0",
|
| 479 |
+
"annotation": null
|
| 480 |
+
},
|
| 481 |
+
{
|
| 482 |
+
"name": "alibi_slopes",
|
| 483 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 484 |
+
"default": "None",
|
| 485 |
+
"annotation": null
|
| 486 |
+
},
|
| 487 |
+
{
|
| 488 |
+
"name": "deterministic",
|
| 489 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 490 |
+
"default": "False",
|
| 491 |
+
"annotation": null
|
| 492 |
+
},
|
| 493 |
+
{
|
| 494 |
+
"name": "return_attn_probs",
|
| 495 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 496 |
+
"default": "False",
|
| 497 |
+
"annotation": null
|
| 498 |
+
}
|
| 499 |
+
],
|
| 500 |
+
"return_annotation": null
|
| 501 |
+
}
|
| 502 |
+
},
|
| 503 |
+
{
|
| 504 |
+
"name": "flash_attn_with_kvcache",
|
| 505 |
+
"qualname": "flash_attn_with_kvcache",
|
| 506 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 507 |
+
"kind": "function",
|
| 508 |
+
"doc": "If k and v are not None, k_cache and v_cache will be updated *inplace* with the new values from\nk and v. This is useful for incremental decoding: you can pass in the cached keys/values from\nthe previous step, and update them with the new keys/values from the current step, and do\nattention with the updated cache, all in 1 kernel.\n\nIf you pass in k / v, you must make sure that the cache is large enough to hold the new values.\nFor example, the KV cache could be pre-allocated with the max sequence length, and you can use\ncache_seqlens to keep track of the current sequence lengths of each sequence in the batch.\n\nAlso apply rotary embedding if rotary_cos and rotary_sin are passed in. The key @k will be\nrotated by rotary_cos and rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.\nIf causal or local (i.e., window_size != (-1, -1)), the query @q will be rotated by rotary_cos\nand rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.\nIf not causal and not local, the query @q will be rotated by rotary_cos and rotary_sin at\nindices cache_seqlens only (i.e. we consider all tokens in @q to be at position cache_seqlens).\n\nSee tests/test_flash_attn.py::test_flash_attn_kvcache for examples of how to use this function.\n\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nNote: Does not support backward pass.\n\nArguments:\n q: (batch_size, seqlen, nheads, headdim)\n k_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,\n or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)\n page_block_size must be a multiple of 256.\n v_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,\n or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)\n k [optional]: (batch_size, seqlen_new, nheads_k, headdim). If not None, we concatenate\n k with k_cache, starting at the indices specified by cache_seqlens.\n v [optional]: (batch_size, seqlen_new, nheads_k, headdim). Similar to k.\n rotary_cos [optional]: (seqlen_ro, rotary_dim / 2). If not None, we apply rotary embedding\n to k and q. Only applicable if k and v are passed in. rotary_dim must be divisible by 16.\n rotary_sin [optional]: (seqlen_ro, rotary_dim / 2). Similar to rotary_cos.\n cache_seqlens: int, or (batch_size,), dtype torch.int32. The sequence lengths of the\n KV cache.\n cache_batch_idx: (batch_size,), dtype torch.int32. The indices used to index into the KV cache.\n If None, we assume that the batch indices are [0, 1, 2, ..., batch_size - 1].\n If the indices are not distinct, and k and v are provided, the values updated in the cache\n might come from any of the duplicate indices.\n cache_leftpad: (batch_size,), dtype torch.int32. The index that the KV cache starts. If None, assume 0.\n block_table [optional]: (batch_size, max_num_blocks_per_seq), dtype torch.int32.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n rotary_interleaved: bool. Only applicable if rotary_cos and rotary_sin are passed in.\n If True, rotary embedding will combine dimensions 0 & 1, 2 & 3, etc. If False,\n rotary embedding will combine dimensions 0 & rotary_dim / 2, 1 & rotary_dim / 2 + 1\n (i.e. GPT-NeoX style).\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n num_splits: int. If > 1, split the key/value into this many chunks along the sequence.\n If num_splits == 1, we don't split the key/value. If num_splits == 0, we use a heuristic\n to automatically determine the number of splits.\n Don't change this unless you know what you are doing.\n return_softmax_lse: bool. Whether to return the logsumexp of the attention scores.\n\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_softmax_lse=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).",
|
| 509 |
+
"signature": {
|
| 510 |
+
"parameters": [
|
| 511 |
+
{
|
| 512 |
+
"name": "q",
|
| 513 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 514 |
+
"default": null,
|
| 515 |
+
"annotation": null
|
| 516 |
+
},
|
| 517 |
+
{
|
| 518 |
+
"name": "k_cache",
|
| 519 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 520 |
+
"default": null,
|
| 521 |
+
"annotation": null
|
| 522 |
+
},
|
| 523 |
+
{
|
| 524 |
+
"name": "v_cache",
|
| 525 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 526 |
+
"default": null,
|
| 527 |
+
"annotation": null
|
| 528 |
+
},
|
| 529 |
+
{
|
| 530 |
+
"name": "k",
|
| 531 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 532 |
+
"default": "None",
|
| 533 |
+
"annotation": null
|
| 534 |
+
},
|
| 535 |
+
{
|
| 536 |
+
"name": "v",
|
| 537 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 538 |
+
"default": "None",
|
| 539 |
+
"annotation": null
|
| 540 |
+
},
|
| 541 |
+
{
|
| 542 |
+
"name": "rotary_cos",
|
| 543 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 544 |
+
"default": "None",
|
| 545 |
+
"annotation": null
|
| 546 |
+
},
|
| 547 |
+
{
|
| 548 |
+
"name": "rotary_sin",
|
| 549 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 550 |
+
"default": "None",
|
| 551 |
+
"annotation": null
|
| 552 |
+
},
|
| 553 |
+
{
|
| 554 |
+
"name": "cache_seqlens",
|
| 555 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 556 |
+
"default": "None",
|
| 557 |
+
"annotation": "int | torch.Tensor | None"
|
| 558 |
+
},
|
| 559 |
+
{
|
| 560 |
+
"name": "cache_batch_idx",
|
| 561 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 562 |
+
"default": "None",
|
| 563 |
+
"annotation": "torch.Tensor | None"
|
| 564 |
+
},
|
| 565 |
+
{
|
| 566 |
+
"name": "cache_leftpad",
|
| 567 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 568 |
+
"default": "None",
|
| 569 |
+
"annotation": "torch.Tensor | None"
|
| 570 |
+
},
|
| 571 |
+
{
|
| 572 |
+
"name": "block_table",
|
| 573 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 574 |
+
"default": "None",
|
| 575 |
+
"annotation": "torch.Tensor | None"
|
| 576 |
+
},
|
| 577 |
+
{
|
| 578 |
+
"name": "softmax_scale",
|
| 579 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 580 |
+
"default": "None",
|
| 581 |
+
"annotation": null
|
| 582 |
+
},
|
| 583 |
+
{
|
| 584 |
+
"name": "causal",
|
| 585 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 586 |
+
"default": "False",
|
| 587 |
+
"annotation": null
|
| 588 |
+
},
|
| 589 |
+
{
|
| 590 |
+
"name": "window_size",
|
| 591 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 592 |
+
"default": "(-1, -1)",
|
| 593 |
+
"annotation": null
|
| 594 |
+
},
|
| 595 |
+
{
|
| 596 |
+
"name": "softcap",
|
| 597 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 598 |
+
"default": "0.0",
|
| 599 |
+
"annotation": null
|
| 600 |
+
},
|
| 601 |
+
{
|
| 602 |
+
"name": "rotary_interleaved",
|
| 603 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 604 |
+
"default": "True",
|
| 605 |
+
"annotation": null
|
| 606 |
+
},
|
| 607 |
+
{
|
| 608 |
+
"name": "alibi_slopes",
|
| 609 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 610 |
+
"default": "None",
|
| 611 |
+
"annotation": null
|
| 612 |
+
},
|
| 613 |
+
{
|
| 614 |
+
"name": "num_splits",
|
| 615 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 616 |
+
"default": "0",
|
| 617 |
+
"annotation": null
|
| 618 |
+
},
|
| 619 |
+
{
|
| 620 |
+
"name": "return_softmax_lse",
|
| 621 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 622 |
+
"default": "False",
|
| 623 |
+
"annotation": null
|
| 624 |
+
}
|
| 625 |
+
],
|
| 626 |
+
"return_annotation": null
|
| 627 |
+
}
|
| 628 |
+
},
|
| 629 |
+
{
|
| 630 |
+
"name": "fwd",
|
| 631 |
+
"qualname": "fwd",
|
| 632 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 633 |
+
"kind": "function",
|
| 634 |
+
"doc": "Forward pass for multi-head attention.\n\nArgs:\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n out: Optional output tensor, same shape as q\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n return_softmax: Whether to return softmax weights\n gen: Optional random number generator\n\nReturns:\n List of tensors: [output, softmax_lse, (softmax if return_softmax)]",
|
| 635 |
+
"signature": {
|
| 636 |
+
"parameters": [
|
| 637 |
+
{
|
| 638 |
+
"name": "q",
|
| 639 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 640 |
+
"default": null,
|
| 641 |
+
"annotation": "torch.Tensor"
|
| 642 |
+
},
|
| 643 |
+
{
|
| 644 |
+
"name": "k",
|
| 645 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 646 |
+
"default": null,
|
| 647 |
+
"annotation": "torch.Tensor"
|
| 648 |
+
},
|
| 649 |
+
{
|
| 650 |
+
"name": "v",
|
| 651 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 652 |
+
"default": null,
|
| 653 |
+
"annotation": "torch.Tensor"
|
| 654 |
+
},
|
| 655 |
+
{
|
| 656 |
+
"name": "out",
|
| 657 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 658 |
+
"default": "None",
|
| 659 |
+
"annotation": "torch.Tensor | None"
|
| 660 |
+
},
|
| 661 |
+
{
|
| 662 |
+
"name": "alibi_slopes",
|
| 663 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 664 |
+
"default": "None",
|
| 665 |
+
"annotation": "torch.Tensor | None"
|
| 666 |
+
},
|
| 667 |
+
{
|
| 668 |
+
"name": "p_dropout",
|
| 669 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 670 |
+
"default": "0.0",
|
| 671 |
+
"annotation": "float"
|
| 672 |
+
},
|
| 673 |
+
{
|
| 674 |
+
"name": "softmax_scale",
|
| 675 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 676 |
+
"default": "None",
|
| 677 |
+
"annotation": "float | None"
|
| 678 |
+
},
|
| 679 |
+
{
|
| 680 |
+
"name": "is_causal",
|
| 681 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 682 |
+
"default": "False",
|
| 683 |
+
"annotation": "bool"
|
| 684 |
+
},
|
| 685 |
+
{
|
| 686 |
+
"name": "window_size_left",
|
| 687 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 688 |
+
"default": "-1",
|
| 689 |
+
"annotation": "int"
|
| 690 |
+
},
|
| 691 |
+
{
|
| 692 |
+
"name": "window_size_right",
|
| 693 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 694 |
+
"default": "-1",
|
| 695 |
+
"annotation": "int"
|
| 696 |
+
},
|
| 697 |
+
{
|
| 698 |
+
"name": "softcap",
|
| 699 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 700 |
+
"default": "0.0",
|
| 701 |
+
"annotation": "float"
|
| 702 |
+
},
|
| 703 |
+
{
|
| 704 |
+
"name": "return_softmax",
|
| 705 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 706 |
+
"default": "False",
|
| 707 |
+
"annotation": "bool"
|
| 708 |
+
},
|
| 709 |
+
{
|
| 710 |
+
"name": "gen",
|
| 711 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 712 |
+
"default": "None",
|
| 713 |
+
"annotation": "torch._C.Generator | None"
|
| 714 |
+
}
|
| 715 |
+
],
|
| 716 |
+
"return_annotation": "List[torch.Tensor]"
|
| 717 |
+
}
|
| 718 |
+
},
|
| 719 |
+
{
|
| 720 |
+
"name": "varlen_fwd",
|
| 721 |
+
"qualname": "varlen_fwd",
|
| 722 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 723 |
+
"kind": "function",
|
| 724 |
+
"doc": "Forward pass for multi-head attention with variable sequence lengths.\n\nArgs:\n q: Query tensor of shape [total_q, num_heads, head_size]\n k: Key tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n v: Value tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]\n cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]\n out: Optional output tensor of shape [total_q, num_heads, head_size]\n seqused_k: Optional tensor specifying how many keys to use per batch element [batch_size]\n leftpad_k: Optional left padding for keys of shape [batch_size]\n block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n max_seqlen_q: Maximum sequence length for queries\n max_seqlen_k: Maximum sequence length for keys\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n zero_tensors: Whether to zero tensors before computation\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n return_softmax: Whether to return softmax weights\n gen: Optional random number generator\n\nReturns:\n List of tensors: [output, softmax_lse, (softmax if return_softmax)]",
|
| 725 |
+
"signature": {
|
| 726 |
+
"parameters": [
|
| 727 |
+
{
|
| 728 |
+
"name": "q",
|
| 729 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 730 |
+
"default": null,
|
| 731 |
+
"annotation": "torch.Tensor"
|
| 732 |
+
},
|
| 733 |
+
{
|
| 734 |
+
"name": "k",
|
| 735 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 736 |
+
"default": null,
|
| 737 |
+
"annotation": "torch.Tensor"
|
| 738 |
+
},
|
| 739 |
+
{
|
| 740 |
+
"name": "v",
|
| 741 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 742 |
+
"default": null,
|
| 743 |
+
"annotation": "torch.Tensor"
|
| 744 |
+
},
|
| 745 |
+
{
|
| 746 |
+
"name": "cu_seqlens_q",
|
| 747 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 748 |
+
"default": null,
|
| 749 |
+
"annotation": "torch.Tensor"
|
| 750 |
+
},
|
| 751 |
+
{
|
| 752 |
+
"name": "cu_seqlens_k",
|
| 753 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 754 |
+
"default": null,
|
| 755 |
+
"annotation": "torch.Tensor"
|
| 756 |
+
},
|
| 757 |
+
{
|
| 758 |
+
"name": "out",
|
| 759 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 760 |
+
"default": "None",
|
| 761 |
+
"annotation": "torch.Tensor | None"
|
| 762 |
+
},
|
| 763 |
+
{
|
| 764 |
+
"name": "seqused_k",
|
| 765 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 766 |
+
"default": "None",
|
| 767 |
+
"annotation": "torch.Tensor | None"
|
| 768 |
+
},
|
| 769 |
+
{
|
| 770 |
+
"name": "leftpad_k",
|
| 771 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 772 |
+
"default": "None",
|
| 773 |
+
"annotation": "torch.Tensor | None"
|
| 774 |
+
},
|
| 775 |
+
{
|
| 776 |
+
"name": "block_table",
|
| 777 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 778 |
+
"default": "None",
|
| 779 |
+
"annotation": "torch.Tensor | None"
|
| 780 |
+
},
|
| 781 |
+
{
|
| 782 |
+
"name": "alibi_slopes",
|
| 783 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 784 |
+
"default": "None",
|
| 785 |
+
"annotation": "torch.Tensor | None"
|
| 786 |
+
},
|
| 787 |
+
{
|
| 788 |
+
"name": "max_seqlen_q",
|
| 789 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 790 |
+
"default": "0",
|
| 791 |
+
"annotation": "int"
|
| 792 |
+
},
|
| 793 |
+
{
|
| 794 |
+
"name": "max_seqlen_k",
|
| 795 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 796 |
+
"default": "0",
|
| 797 |
+
"annotation": "int"
|
| 798 |
+
},
|
| 799 |
+
{
|
| 800 |
+
"name": "p_dropout",
|
| 801 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 802 |
+
"default": "0.0",
|
| 803 |
+
"annotation": "float"
|
| 804 |
+
},
|
| 805 |
+
{
|
| 806 |
+
"name": "softmax_scale",
|
| 807 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 808 |
+
"default": "None",
|
| 809 |
+
"annotation": "float | None"
|
| 810 |
+
},
|
| 811 |
+
{
|
| 812 |
+
"name": "zero_tensors",
|
| 813 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 814 |
+
"default": "False",
|
| 815 |
+
"annotation": "bool"
|
| 816 |
+
},
|
| 817 |
+
{
|
| 818 |
+
"name": "is_causal",
|
| 819 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 820 |
+
"default": "False",
|
| 821 |
+
"annotation": "bool"
|
| 822 |
+
},
|
| 823 |
+
{
|
| 824 |
+
"name": "window_size_left",
|
| 825 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 826 |
+
"default": "-1",
|
| 827 |
+
"annotation": "int"
|
| 828 |
+
},
|
| 829 |
+
{
|
| 830 |
+
"name": "window_size_right",
|
| 831 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 832 |
+
"default": "-1",
|
| 833 |
+
"annotation": "int"
|
| 834 |
+
},
|
| 835 |
+
{
|
| 836 |
+
"name": "softcap",
|
| 837 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 838 |
+
"default": "0.0",
|
| 839 |
+
"annotation": "float"
|
| 840 |
+
},
|
| 841 |
+
{
|
| 842 |
+
"name": "return_softmax",
|
| 843 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 844 |
+
"default": "False",
|
| 845 |
+
"annotation": "bool"
|
| 846 |
+
},
|
| 847 |
+
{
|
| 848 |
+
"name": "gen",
|
| 849 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 850 |
+
"default": "None",
|
| 851 |
+
"annotation": "torch._C.Generator | None"
|
| 852 |
+
}
|
| 853 |
+
],
|
| 854 |
+
"return_annotation": "List[torch.Tensor]"
|
| 855 |
+
}
|
| 856 |
+
},
|
| 857 |
+
{
|
| 858 |
+
"name": "bwd",
|
| 859 |
+
"qualname": "bwd",
|
| 860 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 861 |
+
"kind": "function",
|
| 862 |
+
"doc": "Backward pass for multi-head attention.\n\nArgs:\n dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]\n softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]\n dq: Optional gradient tensor for queries, same shape as q\n dk: Optional gradient tensor for keys, same shape as k\n dv: Optional gradient tensor for values, same shape as v\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n deterministic: Whether to use deterministic algorithms\n gen: Optional random number generator\n rng_state: Optional RNG state from forward pass\n\nReturns:\n List of tensors: [dq, dk, dv]",
|
| 863 |
+
"signature": {
|
| 864 |
+
"parameters": [
|
| 865 |
+
{
|
| 866 |
+
"name": "dout",
|
| 867 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 868 |
+
"default": null,
|
| 869 |
+
"annotation": "torch.Tensor"
|
| 870 |
+
},
|
| 871 |
+
{
|
| 872 |
+
"name": "q",
|
| 873 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 874 |
+
"default": null,
|
| 875 |
+
"annotation": "torch.Tensor"
|
| 876 |
+
},
|
| 877 |
+
{
|
| 878 |
+
"name": "k",
|
| 879 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 880 |
+
"default": null,
|
| 881 |
+
"annotation": "torch.Tensor"
|
| 882 |
+
},
|
| 883 |
+
{
|
| 884 |
+
"name": "v",
|
| 885 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 886 |
+
"default": null,
|
| 887 |
+
"annotation": "torch.Tensor"
|
| 888 |
+
},
|
| 889 |
+
{
|
| 890 |
+
"name": "out",
|
| 891 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 892 |
+
"default": null,
|
| 893 |
+
"annotation": "torch.Tensor"
|
| 894 |
+
},
|
| 895 |
+
{
|
| 896 |
+
"name": "softmax_lse",
|
| 897 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 898 |
+
"default": null,
|
| 899 |
+
"annotation": "torch.Tensor"
|
| 900 |
+
},
|
| 901 |
+
{
|
| 902 |
+
"name": "dq",
|
| 903 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 904 |
+
"default": "None",
|
| 905 |
+
"annotation": "torch.Tensor | None"
|
| 906 |
+
},
|
| 907 |
+
{
|
| 908 |
+
"name": "dk",
|
| 909 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 910 |
+
"default": "None",
|
| 911 |
+
"annotation": "torch.Tensor | None"
|
| 912 |
+
},
|
| 913 |
+
{
|
| 914 |
+
"name": "dv",
|
| 915 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 916 |
+
"default": "None",
|
| 917 |
+
"annotation": "torch.Tensor | None"
|
| 918 |
+
},
|
| 919 |
+
{
|
| 920 |
+
"name": "alibi_slopes",
|
| 921 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 922 |
+
"default": "None",
|
| 923 |
+
"annotation": "torch.Tensor | None"
|
| 924 |
+
},
|
| 925 |
+
{
|
| 926 |
+
"name": "p_dropout",
|
| 927 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 928 |
+
"default": "0.0",
|
| 929 |
+
"annotation": "float"
|
| 930 |
+
},
|
| 931 |
+
{
|
| 932 |
+
"name": "softmax_scale",
|
| 933 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 934 |
+
"default": "None",
|
| 935 |
+
"annotation": "float | None"
|
| 936 |
+
},
|
| 937 |
+
{
|
| 938 |
+
"name": "is_causal",
|
| 939 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 940 |
+
"default": "False",
|
| 941 |
+
"annotation": "bool"
|
| 942 |
+
},
|
| 943 |
+
{
|
| 944 |
+
"name": "window_size_left",
|
| 945 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 946 |
+
"default": "-1",
|
| 947 |
+
"annotation": "int"
|
| 948 |
+
},
|
| 949 |
+
{
|
| 950 |
+
"name": "window_size_right",
|
| 951 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 952 |
+
"default": "-1",
|
| 953 |
+
"annotation": "int"
|
| 954 |
+
},
|
| 955 |
+
{
|
| 956 |
+
"name": "softcap",
|
| 957 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 958 |
+
"default": "0.0",
|
| 959 |
+
"annotation": "float"
|
| 960 |
+
},
|
| 961 |
+
{
|
| 962 |
+
"name": "deterministic",
|
| 963 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 964 |
+
"default": "False",
|
| 965 |
+
"annotation": "bool"
|
| 966 |
+
},
|
| 967 |
+
{
|
| 968 |
+
"name": "gen",
|
| 969 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 970 |
+
"default": "None",
|
| 971 |
+
"annotation": "torch._C.Generator | None"
|
| 972 |
+
},
|
| 973 |
+
{
|
| 974 |
+
"name": "rng_state",
|
| 975 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 976 |
+
"default": "None",
|
| 977 |
+
"annotation": "torch.Tensor | None"
|
| 978 |
+
}
|
| 979 |
+
],
|
| 980 |
+
"return_annotation": "List[torch.Tensor]"
|
| 981 |
+
}
|
| 982 |
+
},
|
| 983 |
+
{
|
| 984 |
+
"name": "varlen_bwd",
|
| 985 |
+
"qualname": "varlen_bwd",
|
| 986 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 987 |
+
"kind": "function",
|
| 988 |
+
"doc": "Backward pass for multi-head attention with variable sequence lengths.\n\nArgs:\n dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]\n softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]\n cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]\n cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]\n dq: Optional gradient tensor for queries, same shape as q\n dk: Optional gradient tensor for keys, same shape as k\n dv: Optional gradient tensor for values, same shape as v\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n max_seqlen_q: Maximum sequence length for queries\n max_seqlen_k: Maximum sequence length for keys\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n zero_tensors: Whether to zero tensors before computation\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n deterministic: Whether to use deterministic algorithms\n gen: Optional random number generator\n rng_state: Optional RNG state from forward pass\n\nReturns:\n List of tensors: [dq, dk, dv]",
|
| 989 |
+
"signature": {
|
| 990 |
+
"parameters": [
|
| 991 |
+
{
|
| 992 |
+
"name": "dout",
|
| 993 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 994 |
+
"default": null,
|
| 995 |
+
"annotation": "torch.Tensor"
|
| 996 |
+
},
|
| 997 |
+
{
|
| 998 |
+
"name": "q",
|
| 999 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1000 |
+
"default": null,
|
| 1001 |
+
"annotation": "torch.Tensor"
|
| 1002 |
+
},
|
| 1003 |
+
{
|
| 1004 |
+
"name": "k",
|
| 1005 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1006 |
+
"default": null,
|
| 1007 |
+
"annotation": "torch.Tensor"
|
| 1008 |
+
},
|
| 1009 |
+
{
|
| 1010 |
+
"name": "v",
|
| 1011 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1012 |
+
"default": null,
|
| 1013 |
+
"annotation": "torch.Tensor"
|
| 1014 |
+
},
|
| 1015 |
+
{
|
| 1016 |
+
"name": "out",
|
| 1017 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1018 |
+
"default": null,
|
| 1019 |
+
"annotation": "torch.Tensor"
|
| 1020 |
+
},
|
| 1021 |
+
{
|
| 1022 |
+
"name": "softmax_lse",
|
| 1023 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1024 |
+
"default": null,
|
| 1025 |
+
"annotation": "torch.Tensor"
|
| 1026 |
+
},
|
| 1027 |
+
{
|
| 1028 |
+
"name": "cu_seqlens_q",
|
| 1029 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1030 |
+
"default": null,
|
| 1031 |
+
"annotation": "torch.Tensor"
|
| 1032 |
+
},
|
| 1033 |
+
{
|
| 1034 |
+
"name": "cu_seqlens_k",
|
| 1035 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1036 |
+
"default": null,
|
| 1037 |
+
"annotation": "torch.Tensor"
|
| 1038 |
+
},
|
| 1039 |
+
{
|
| 1040 |
+
"name": "dq",
|
| 1041 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1042 |
+
"default": "None",
|
| 1043 |
+
"annotation": "torch.Tensor | None"
|
| 1044 |
+
},
|
| 1045 |
+
{
|
| 1046 |
+
"name": "dk",
|
| 1047 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1048 |
+
"default": "None",
|
| 1049 |
+
"annotation": "torch.Tensor | None"
|
| 1050 |
+
},
|
| 1051 |
+
{
|
| 1052 |
+
"name": "dv",
|
| 1053 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1054 |
+
"default": "None",
|
| 1055 |
+
"annotation": "torch.Tensor | None"
|
| 1056 |
+
},
|
| 1057 |
+
{
|
| 1058 |
+
"name": "alibi_slopes",
|
| 1059 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1060 |
+
"default": "None",
|
| 1061 |
+
"annotation": "torch.Tensor | None"
|
| 1062 |
+
},
|
| 1063 |
+
{
|
| 1064 |
+
"name": "max_seqlen_q",
|
| 1065 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1066 |
+
"default": "0",
|
| 1067 |
+
"annotation": "int"
|
| 1068 |
+
},
|
| 1069 |
+
{
|
| 1070 |
+
"name": "max_seqlen_k",
|
| 1071 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1072 |
+
"default": "0",
|
| 1073 |
+
"annotation": "int"
|
| 1074 |
+
},
|
| 1075 |
+
{
|
| 1076 |
+
"name": "p_dropout",
|
| 1077 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1078 |
+
"default": "0.0",
|
| 1079 |
+
"annotation": "float"
|
| 1080 |
+
},
|
| 1081 |
+
{
|
| 1082 |
+
"name": "softmax_scale",
|
| 1083 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1084 |
+
"default": "None",
|
| 1085 |
+
"annotation": "float | None"
|
| 1086 |
+
},
|
| 1087 |
+
{
|
| 1088 |
+
"name": "zero_tensors",
|
| 1089 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1090 |
+
"default": "False",
|
| 1091 |
+
"annotation": "bool"
|
| 1092 |
+
},
|
| 1093 |
+
{
|
| 1094 |
+
"name": "is_causal",
|
| 1095 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1096 |
+
"default": "False",
|
| 1097 |
+
"annotation": "bool"
|
| 1098 |
+
},
|
| 1099 |
+
{
|
| 1100 |
+
"name": "window_size_left",
|
| 1101 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1102 |
+
"default": "-1",
|
| 1103 |
+
"annotation": "int"
|
| 1104 |
+
},
|
| 1105 |
+
{
|
| 1106 |
+
"name": "window_size_right",
|
| 1107 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1108 |
+
"default": "-1",
|
| 1109 |
+
"annotation": "int"
|
| 1110 |
+
},
|
| 1111 |
+
{
|
| 1112 |
+
"name": "softcap",
|
| 1113 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1114 |
+
"default": "0.0",
|
| 1115 |
+
"annotation": "float"
|
| 1116 |
+
},
|
| 1117 |
+
{
|
| 1118 |
+
"name": "deterministic",
|
| 1119 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1120 |
+
"default": "False",
|
| 1121 |
+
"annotation": "bool"
|
| 1122 |
+
},
|
| 1123 |
+
{
|
| 1124 |
+
"name": "gen",
|
| 1125 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1126 |
+
"default": "None",
|
| 1127 |
+
"annotation": "torch._C.Generator | None"
|
| 1128 |
+
},
|
| 1129 |
+
{
|
| 1130 |
+
"name": "rng_state",
|
| 1131 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1132 |
+
"default": "None",
|
| 1133 |
+
"annotation": "torch.Tensor | None"
|
| 1134 |
+
}
|
| 1135 |
+
],
|
| 1136 |
+
"return_annotation": "List[torch.Tensor]"
|
| 1137 |
+
}
|
| 1138 |
+
},
|
| 1139 |
+
{
|
| 1140 |
+
"name": "fwd_kvcache",
|
| 1141 |
+
"qualname": "fwd_kvcache",
|
| 1142 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 1143 |
+
"kind": "function",
|
| 1144 |
+
"doc": "Forward pass for multi-head attention with KV cache.\n\nArgs:\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n kcache: Key cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n vcache: Value cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n k: Optional new keys tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]\n v: Optional new values tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]\n seqlens_k: Optional sequence lengths for keys of shape [batch_size]\n rotary_cos: Optional rotary cosine tensor of shape [seqlen_ro, rotary_dim/2]\n rotary_sin: Optional rotary sine tensor of shape [seqlen_ro, rotary_dim/2]\n cache_batch_idx: Optional indices to index into the KV cache\n leftpad_k: Optional left padding for keys of shape [batch_size]\n block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n out: Optional output tensor, same shape as q\n softmax_scale: Scale factor for softmax\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n is_rotary_interleaved: Whether rotary embeddings are interleaved\n num_splits: Number of splits for computation\n\nReturns:\n List of tensors: [output, softmax_lse]",
|
| 1145 |
+
"signature": {
|
| 1146 |
+
"parameters": [
|
| 1147 |
+
{
|
| 1148 |
+
"name": "q",
|
| 1149 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1150 |
+
"default": null,
|
| 1151 |
+
"annotation": "torch.Tensor"
|
| 1152 |
+
},
|
| 1153 |
+
{
|
| 1154 |
+
"name": "kcache",
|
| 1155 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1156 |
+
"default": null,
|
| 1157 |
+
"annotation": "torch.Tensor"
|
| 1158 |
+
},
|
| 1159 |
+
{
|
| 1160 |
+
"name": "vcache",
|
| 1161 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1162 |
+
"default": null,
|
| 1163 |
+
"annotation": "torch.Tensor"
|
| 1164 |
+
},
|
| 1165 |
+
{
|
| 1166 |
+
"name": "k",
|
| 1167 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1168 |
+
"default": "None",
|
| 1169 |
+
"annotation": "torch.Tensor | None"
|
| 1170 |
+
},
|
| 1171 |
+
{
|
| 1172 |
+
"name": "v",
|
| 1173 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1174 |
+
"default": "None",
|
| 1175 |
+
"annotation": "torch.Tensor | None"
|
| 1176 |
+
},
|
| 1177 |
+
{
|
| 1178 |
+
"name": "seqlens_k",
|
| 1179 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1180 |
+
"default": "None",
|
| 1181 |
+
"annotation": "torch.Tensor | None"
|
| 1182 |
+
},
|
| 1183 |
+
{
|
| 1184 |
+
"name": "rotary_cos",
|
| 1185 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1186 |
+
"default": "None",
|
| 1187 |
+
"annotation": "torch.Tensor | None"
|
| 1188 |
+
},
|
| 1189 |
+
{
|
| 1190 |
+
"name": "rotary_sin",
|
| 1191 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1192 |
+
"default": "None",
|
| 1193 |
+
"annotation": "torch.Tensor | None"
|
| 1194 |
+
},
|
| 1195 |
+
{
|
| 1196 |
+
"name": "cache_batch_idx",
|
| 1197 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1198 |
+
"default": "None",
|
| 1199 |
+
"annotation": "torch.Tensor | None"
|
| 1200 |
+
},
|
| 1201 |
+
{
|
| 1202 |
+
"name": "leftpad_k",
|
| 1203 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1204 |
+
"default": "None",
|
| 1205 |
+
"annotation": "torch.Tensor | None"
|
| 1206 |
+
},
|
| 1207 |
+
{
|
| 1208 |
+
"name": "block_table",
|
| 1209 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1210 |
+
"default": "None",
|
| 1211 |
+
"annotation": "torch.Tensor | None"
|
| 1212 |
+
},
|
| 1213 |
+
{
|
| 1214 |
+
"name": "alibi_slopes",
|
| 1215 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1216 |
+
"default": "None",
|
| 1217 |
+
"annotation": "torch.Tensor | None"
|
| 1218 |
+
},
|
| 1219 |
+
{
|
| 1220 |
+
"name": "out",
|
| 1221 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1222 |
+
"default": "None",
|
| 1223 |
+
"annotation": "torch.Tensor | None"
|
| 1224 |
+
},
|
| 1225 |
+
{
|
| 1226 |
+
"name": "softmax_scale",
|
| 1227 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1228 |
+
"default": "None",
|
| 1229 |
+
"annotation": "float | None"
|
| 1230 |
+
},
|
| 1231 |
+
{
|
| 1232 |
+
"name": "is_causal",
|
| 1233 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1234 |
+
"default": "False",
|
| 1235 |
+
"annotation": "bool"
|
| 1236 |
+
},
|
| 1237 |
+
{
|
| 1238 |
+
"name": "window_size_left",
|
| 1239 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1240 |
+
"default": "-1",
|
| 1241 |
+
"annotation": "int"
|
| 1242 |
+
},
|
| 1243 |
+
{
|
| 1244 |
+
"name": "window_size_right",
|
| 1245 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1246 |
+
"default": "-1",
|
| 1247 |
+
"annotation": "int"
|
| 1248 |
+
},
|
| 1249 |
+
{
|
| 1250 |
+
"name": "softcap",
|
| 1251 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1252 |
+
"default": "0.0",
|
| 1253 |
+
"annotation": "float"
|
| 1254 |
+
},
|
| 1255 |
+
{
|
| 1256 |
+
"name": "is_rotary_interleaved",
|
| 1257 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1258 |
+
"default": "False",
|
| 1259 |
+
"annotation": "bool"
|
| 1260 |
+
},
|
| 1261 |
+
{
|
| 1262 |
+
"name": "num_splits",
|
| 1263 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1264 |
+
"default": "1",
|
| 1265 |
+
"annotation": "int"
|
| 1266 |
+
}
|
| 1267 |
+
],
|
| 1268 |
+
"return_annotation": "List[torch.Tensor]"
|
| 1269 |
+
}
|
| 1270 |
+
}
|
| 1271 |
+
],
|
| 1272 |
+
"layers": []
|
| 1273 |
+
}
|
build/torch-stable-abi210-cu128-aarch64-linux/__init__.py
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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+
from . import flash_attn_interface
|
| 6 |
+
from ._ops import ops as flash_attn_ops
|
| 7 |
+
from .flash_attn_interface import (
|
| 8 |
+
# helper to set up the Philox random number generator for dropout
|
| 9 |
+
_philox_generator,
|
| 10 |
+
# reexported for convenience to be used in the high-level API functions
|
| 11 |
+
flash_attn_func,
|
| 12 |
+
flash_attn_kvpacked_func,
|
| 13 |
+
flash_attn_qkvpacked_func,
|
| 14 |
+
flash_attn_varlen_func,
|
| 15 |
+
flash_attn_varlen_kvpacked_func,
|
| 16 |
+
flash_attn_varlen_qkvpacked_func,
|
| 17 |
+
flash_attn_with_kvcache,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
__all__ = [
|
| 21 |
+
# High-level API (with autograd support)
|
| 22 |
+
"flash_attn_func",
|
| 23 |
+
"flash_attn_kvpacked_func",
|
| 24 |
+
"flash_attn_qkvpacked_func",
|
| 25 |
+
"flash_attn_varlen_func",
|
| 26 |
+
"flash_attn_varlen_kvpacked_func",
|
| 27 |
+
"flash_attn_varlen_qkvpacked_func",
|
| 28 |
+
"flash_attn_with_kvcache",
|
| 29 |
+
# Upstream interface module. Its `_flash_attn_forward`, `_flash_attn_backward`,
|
| 30 |
+
# `_flash_attn_varlen_forward` and `_flash_attn_varlen_backward` are supported
|
| 31 |
+
# low-level entry points with upstream's signatures: Torch custom ops without
|
| 32 |
+
# autograd that return the LSE and are traceable by torch.compile. The autograd
|
| 33 |
+
# Functions above are built on top of them.
|
| 34 |
+
"flash_attn_interface",
|
| 35 |
+
# Low-level ops (no autograd)
|
| 36 |
+
"fwd",
|
| 37 |
+
"varlen_fwd",
|
| 38 |
+
"bwd",
|
| 39 |
+
"varlen_bwd",
|
| 40 |
+
"fwd_kvcache",
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def fwd(
|
| 45 |
+
q: torch.Tensor,
|
| 46 |
+
k: torch.Tensor,
|
| 47 |
+
v: torch.Tensor,
|
| 48 |
+
out: Optional[torch.Tensor] = None,
|
| 49 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 50 |
+
p_dropout: float = 0.0,
|
| 51 |
+
softmax_scale: Optional[float] = None,
|
| 52 |
+
is_causal: bool = False,
|
| 53 |
+
window_size_left: int = -1,
|
| 54 |
+
window_size_right: int = -1,
|
| 55 |
+
softcap: float = 0.0,
|
| 56 |
+
return_softmax: bool = False,
|
| 57 |
+
gen: Optional[torch.Generator] = None,
|
| 58 |
+
) -> List[torch.Tensor]:
|
| 59 |
+
"""
|
| 60 |
+
Forward pass for multi-head attention.
|
| 61 |
+
|
| 62 |
+
Args:
|
| 63 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 64 |
+
k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 65 |
+
v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 66 |
+
out: Optional output tensor, same shape as q
|
| 67 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 68 |
+
p_dropout: Dropout probability
|
| 69 |
+
softmax_scale: Scale factor for softmax
|
| 70 |
+
is_causal: Whether to use causal attention
|
| 71 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 72 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 73 |
+
softcap: Soft cap for attention weights
|
| 74 |
+
return_softmax: Whether to return softmax weights
|
| 75 |
+
gen: Optional random number generator
|
| 76 |
+
|
| 77 |
+
Returns:
|
| 78 |
+
List of tensors: [output, softmax_lse, (softmax if return_softmax)]
|
| 79 |
+
"""
|
| 80 |
+
if softmax_scale is None:
|
| 81 |
+
attention_head_dim = q.shape[-1]
|
| 82 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 83 |
+
|
| 84 |
+
gen = _philox_generator(q, p_dropout, gen)
|
| 85 |
+
return flash_attn_ops.fwd(
|
| 86 |
+
q,
|
| 87 |
+
k,
|
| 88 |
+
v,
|
| 89 |
+
out,
|
| 90 |
+
alibi_slopes,
|
| 91 |
+
p_dropout,
|
| 92 |
+
softmax_scale,
|
| 93 |
+
is_causal,
|
| 94 |
+
window_size_left,
|
| 95 |
+
window_size_right,
|
| 96 |
+
softcap,
|
| 97 |
+
return_softmax,
|
| 98 |
+
gen,
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def varlen_fwd(
|
| 103 |
+
q: torch.Tensor,
|
| 104 |
+
k: torch.Tensor,
|
| 105 |
+
v: torch.Tensor,
|
| 106 |
+
cu_seqlens_q: torch.Tensor,
|
| 107 |
+
cu_seqlens_k: torch.Tensor,
|
| 108 |
+
out: Optional[torch.Tensor] = None,
|
| 109 |
+
seqused_k: Optional[torch.Tensor] = None,
|
| 110 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 111 |
+
block_table: Optional[torch.Tensor] = None,
|
| 112 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 113 |
+
max_seqlen_q: int = 0,
|
| 114 |
+
max_seqlen_k: int = 0,
|
| 115 |
+
p_dropout: float = 0.0,
|
| 116 |
+
softmax_scale: Optional[float] = None,
|
| 117 |
+
zero_tensors: bool = False,
|
| 118 |
+
is_causal: bool = False,
|
| 119 |
+
window_size_left: int = -1,
|
| 120 |
+
window_size_right: int = -1,
|
| 121 |
+
softcap: float = 0.0,
|
| 122 |
+
return_softmax: bool = False,
|
| 123 |
+
gen: Optional[torch.Generator] = None,
|
| 124 |
+
) -> List[torch.Tensor]:
|
| 125 |
+
"""
|
| 126 |
+
Forward pass for multi-head attention with variable sequence lengths.
|
| 127 |
+
|
| 128 |
+
Args:
|
| 129 |
+
q: Query tensor of shape [total_q, num_heads, head_size]
|
| 130 |
+
k: Key tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 131 |
+
v: Value tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 132 |
+
cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]
|
| 133 |
+
cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]
|
| 134 |
+
out: Optional output tensor of shape [total_q, num_heads, head_size]
|
| 135 |
+
seqused_k: Optional tensor specifying how many keys to use per batch element [batch_size]
|
| 136 |
+
leftpad_k: Optional left padding for keys of shape [batch_size]
|
| 137 |
+
block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]
|
| 138 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 139 |
+
max_seqlen_q: Maximum sequence length for queries
|
| 140 |
+
max_seqlen_k: Maximum sequence length for keys
|
| 141 |
+
p_dropout: Dropout probability
|
| 142 |
+
softmax_scale: Scale factor for softmax
|
| 143 |
+
zero_tensors: Whether to zero tensors before computation
|
| 144 |
+
is_causal: Whether to use causal attention
|
| 145 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 146 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 147 |
+
softcap: Soft cap for attention weights
|
| 148 |
+
return_softmax: Whether to return softmax weights
|
| 149 |
+
gen: Optional random number generator
|
| 150 |
+
|
| 151 |
+
Returns:
|
| 152 |
+
List of tensors: [output, softmax_lse, (softmax if return_softmax)]
|
| 153 |
+
"""
|
| 154 |
+
if softmax_scale is None:
|
| 155 |
+
attention_head_dim = q.shape[-1]
|
| 156 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 157 |
+
|
| 158 |
+
gen = _philox_generator(q, p_dropout, gen)
|
| 159 |
+
return flash_attn_ops.varlen_fwd(
|
| 160 |
+
q,
|
| 161 |
+
k,
|
| 162 |
+
v,
|
| 163 |
+
out,
|
| 164 |
+
cu_seqlens_q,
|
| 165 |
+
cu_seqlens_k,
|
| 166 |
+
seqused_k,
|
| 167 |
+
leftpad_k,
|
| 168 |
+
block_table,
|
| 169 |
+
alibi_slopes,
|
| 170 |
+
max_seqlen_q,
|
| 171 |
+
max_seqlen_k,
|
| 172 |
+
p_dropout,
|
| 173 |
+
softmax_scale,
|
| 174 |
+
zero_tensors,
|
| 175 |
+
is_causal,
|
| 176 |
+
window_size_left,
|
| 177 |
+
window_size_right,
|
| 178 |
+
softcap,
|
| 179 |
+
return_softmax,
|
| 180 |
+
gen,
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def bwd(
|
| 185 |
+
dout: torch.Tensor,
|
| 186 |
+
q: torch.Tensor,
|
| 187 |
+
k: torch.Tensor,
|
| 188 |
+
v: torch.Tensor,
|
| 189 |
+
out: torch.Tensor,
|
| 190 |
+
softmax_lse: torch.Tensor,
|
| 191 |
+
dq: Optional[torch.Tensor] = None,
|
| 192 |
+
dk: Optional[torch.Tensor] = None,
|
| 193 |
+
dv: Optional[torch.Tensor] = None,
|
| 194 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 195 |
+
p_dropout: float = 0.0,
|
| 196 |
+
softmax_scale: Optional[float] = None,
|
| 197 |
+
is_causal: bool = False,
|
| 198 |
+
window_size_left: int = -1,
|
| 199 |
+
window_size_right: int = -1,
|
| 200 |
+
softcap: float = 0.0,
|
| 201 |
+
deterministic: bool = False,
|
| 202 |
+
gen: Optional[torch.Generator] = None,
|
| 203 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 204 |
+
) -> List[torch.Tensor]:
|
| 205 |
+
"""
|
| 206 |
+
Backward pass for multi-head attention.
|
| 207 |
+
|
| 208 |
+
Args:
|
| 209 |
+
dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 210 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 211 |
+
k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 212 |
+
v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 213 |
+
out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 214 |
+
softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]
|
| 215 |
+
dq: Optional gradient tensor for queries, same shape as q
|
| 216 |
+
dk: Optional gradient tensor for keys, same shape as k
|
| 217 |
+
dv: Optional gradient tensor for values, same shape as v
|
| 218 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 219 |
+
p_dropout: Dropout probability
|
| 220 |
+
softmax_scale: Scale factor for softmax
|
| 221 |
+
is_causal: Whether to use causal attention
|
| 222 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 223 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 224 |
+
softcap: Soft cap for attention weights
|
| 225 |
+
deterministic: Whether to use deterministic algorithms
|
| 226 |
+
gen: Optional random number generator
|
| 227 |
+
rng_state: Optional RNG state from forward pass
|
| 228 |
+
|
| 229 |
+
Returns:
|
| 230 |
+
List of tensors: [dq, dk, dv]
|
| 231 |
+
"""
|
| 232 |
+
if softmax_scale is None:
|
| 233 |
+
attention_head_dim = q.shape[-1]
|
| 234 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 235 |
+
|
| 236 |
+
return flash_attn_ops.bwd(
|
| 237 |
+
dout,
|
| 238 |
+
q,
|
| 239 |
+
k,
|
| 240 |
+
v,
|
| 241 |
+
out,
|
| 242 |
+
softmax_lse,
|
| 243 |
+
dq,
|
| 244 |
+
dk,
|
| 245 |
+
dv,
|
| 246 |
+
alibi_slopes,
|
| 247 |
+
p_dropout,
|
| 248 |
+
softmax_scale,
|
| 249 |
+
is_causal,
|
| 250 |
+
window_size_left,
|
| 251 |
+
window_size_right,
|
| 252 |
+
softcap,
|
| 253 |
+
deterministic,
|
| 254 |
+
gen,
|
| 255 |
+
rng_state,
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def varlen_bwd(
|
| 260 |
+
dout: torch.Tensor,
|
| 261 |
+
q: torch.Tensor,
|
| 262 |
+
k: torch.Tensor,
|
| 263 |
+
v: torch.Tensor,
|
| 264 |
+
out: torch.Tensor,
|
| 265 |
+
softmax_lse: torch.Tensor,
|
| 266 |
+
cu_seqlens_q: torch.Tensor,
|
| 267 |
+
cu_seqlens_k: torch.Tensor,
|
| 268 |
+
dq: Optional[torch.Tensor] = None,
|
| 269 |
+
dk: Optional[torch.Tensor] = None,
|
| 270 |
+
dv: Optional[torch.Tensor] = None,
|
| 271 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 272 |
+
max_seqlen_q: int = 0,
|
| 273 |
+
max_seqlen_k: int = 0,
|
| 274 |
+
p_dropout: float = 0.0,
|
| 275 |
+
softmax_scale: Optional[float] = None,
|
| 276 |
+
zero_tensors: bool = False,
|
| 277 |
+
is_causal: bool = False,
|
| 278 |
+
window_size_left: int = -1,
|
| 279 |
+
window_size_right: int = -1,
|
| 280 |
+
softcap: float = 0.0,
|
| 281 |
+
deterministic: bool = False,
|
| 282 |
+
gen: Optional[torch.Generator] = None,
|
| 283 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 284 |
+
) -> List[torch.Tensor]:
|
| 285 |
+
"""
|
| 286 |
+
Backward pass for multi-head attention with variable sequence lengths.
|
| 287 |
+
|
| 288 |
+
Args:
|
| 289 |
+
dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 290 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 291 |
+
k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 292 |
+
v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 293 |
+
out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 294 |
+
softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]
|
| 295 |
+
cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]
|
| 296 |
+
cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]
|
| 297 |
+
dq: Optional gradient tensor for queries, same shape as q
|
| 298 |
+
dk: Optional gradient tensor for keys, same shape as k
|
| 299 |
+
dv: Optional gradient tensor for values, same shape as v
|
| 300 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 301 |
+
max_seqlen_q: Maximum sequence length for queries
|
| 302 |
+
max_seqlen_k: Maximum sequence length for keys
|
| 303 |
+
p_dropout: Dropout probability
|
| 304 |
+
softmax_scale: Scale factor for softmax
|
| 305 |
+
zero_tensors: Whether to zero tensors before computation
|
| 306 |
+
is_causal: Whether to use causal attention
|
| 307 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 308 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 309 |
+
softcap: Soft cap for attention weights
|
| 310 |
+
deterministic: Whether to use deterministic algorithms
|
| 311 |
+
gen: Optional random number generator
|
| 312 |
+
rng_state: Optional RNG state from forward pass
|
| 313 |
+
|
| 314 |
+
Returns:
|
| 315 |
+
List of tensors: [dq, dk, dv]
|
| 316 |
+
"""
|
| 317 |
+
if softmax_scale is None:
|
| 318 |
+
attention_head_dim = q.shape[-1]
|
| 319 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 320 |
+
|
| 321 |
+
return flash_attn_ops.varlen_bwd(
|
| 322 |
+
dout,
|
| 323 |
+
q,
|
| 324 |
+
k,
|
| 325 |
+
v,
|
| 326 |
+
out,
|
| 327 |
+
softmax_lse,
|
| 328 |
+
dq,
|
| 329 |
+
dk,
|
| 330 |
+
dv,
|
| 331 |
+
cu_seqlens_q,
|
| 332 |
+
cu_seqlens_k,
|
| 333 |
+
alibi_slopes,
|
| 334 |
+
max_seqlen_q,
|
| 335 |
+
max_seqlen_k,
|
| 336 |
+
p_dropout,
|
| 337 |
+
softmax_scale,
|
| 338 |
+
zero_tensors,
|
| 339 |
+
is_causal,
|
| 340 |
+
window_size_left,
|
| 341 |
+
window_size_right,
|
| 342 |
+
softcap,
|
| 343 |
+
deterministic,
|
| 344 |
+
gen,
|
| 345 |
+
rng_state,
|
| 346 |
+
)
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
def fwd_kvcache(
|
| 350 |
+
q: torch.Tensor,
|
| 351 |
+
kcache: torch.Tensor,
|
| 352 |
+
vcache: torch.Tensor,
|
| 353 |
+
k: Optional[torch.Tensor] = None,
|
| 354 |
+
v: Optional[torch.Tensor] = None,
|
| 355 |
+
seqlens_k: Optional[torch.Tensor] = None,
|
| 356 |
+
rotary_cos: Optional[torch.Tensor] = None,
|
| 357 |
+
rotary_sin: Optional[torch.Tensor] = None,
|
| 358 |
+
cache_batch_idx: Optional[torch.Tensor] = None,
|
| 359 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 360 |
+
block_table: Optional[torch.Tensor] = None,
|
| 361 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 362 |
+
out: Optional[torch.Tensor] = None,
|
| 363 |
+
softmax_scale: Optional[float] = None,
|
| 364 |
+
is_causal: bool = False,
|
| 365 |
+
window_size_left: int = -1,
|
| 366 |
+
window_size_right: int = -1,
|
| 367 |
+
softcap: float = 0.0,
|
| 368 |
+
is_rotary_interleaved: bool = False,
|
| 369 |
+
num_splits: int = 1,
|
| 370 |
+
) -> List[torch.Tensor]:
|
| 371 |
+
"""
|
| 372 |
+
Forward pass for multi-head attention with KV cache.
|
| 373 |
+
|
| 374 |
+
Args:
|
| 375 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 376 |
+
kcache: Key cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 377 |
+
vcache: Value cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 378 |
+
k: Optional new keys tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]
|
| 379 |
+
v: Optional new values tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]
|
| 380 |
+
seqlens_k: Optional sequence lengths for keys of shape [batch_size]
|
| 381 |
+
rotary_cos: Optional rotary cosine tensor of shape [seqlen_ro, rotary_dim/2]
|
| 382 |
+
rotary_sin: Optional rotary sine tensor of shape [seqlen_ro, rotary_dim/2]
|
| 383 |
+
cache_batch_idx: Optional indices to index into the KV cache
|
| 384 |
+
leftpad_k: Optional left padding for keys of shape [batch_size]
|
| 385 |
+
block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]
|
| 386 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 387 |
+
out: Optional output tensor, same shape as q
|
| 388 |
+
softmax_scale: Scale factor for softmax
|
| 389 |
+
is_causal: Whether to use causal attention
|
| 390 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 391 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 392 |
+
softcap: Soft cap for attention weights
|
| 393 |
+
is_rotary_interleaved: Whether rotary embeddings are interleaved
|
| 394 |
+
num_splits: Number of splits for computation
|
| 395 |
+
|
| 396 |
+
Returns:
|
| 397 |
+
List of tensors: [output, softmax_lse]
|
| 398 |
+
"""
|
| 399 |
+
if softmax_scale is None:
|
| 400 |
+
attention_head_dim = q.shape[-1]
|
| 401 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 402 |
+
|
| 403 |
+
return flash_attn_ops.fwd_kvcache(
|
| 404 |
+
q,
|
| 405 |
+
kcache,
|
| 406 |
+
vcache,
|
| 407 |
+
k,
|
| 408 |
+
v,
|
| 409 |
+
seqlens_k,
|
| 410 |
+
rotary_cos,
|
| 411 |
+
rotary_sin,
|
| 412 |
+
cache_batch_idx,
|
| 413 |
+
leftpad_k,
|
| 414 |
+
block_table,
|
| 415 |
+
alibi_slopes,
|
| 416 |
+
out,
|
| 417 |
+
softmax_scale,
|
| 418 |
+
is_causal,
|
| 419 |
+
window_size_left,
|
| 420 |
+
window_size_right,
|
| 421 |
+
softcap,
|
| 422 |
+
is_rotary_interleaved,
|
| 423 |
+
num_splits,
|
| 424 |
+
)
|
build/torch-stable-abi210-cu128-aarch64-linux/_flash_attn2_cuda_460047c.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cb60d33341a0f1262fa11d919c0776398651e327cdfeb7d21fad3c2aeaf8513b
|
| 3 |
+
size 1036209976
|
build/torch-stable-abi210-cu128-aarch64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _flash_attn2_cuda_460047c
|
| 3 |
+
ops = torch.ops._flash_attn2_cuda_460047c
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_flash_attn2_cuda_460047c::{op_name}"
|
build/torch-stable-abi210-cu128-aarch64-linux/flash_attn_interface.py
ADDED
|
@@ -0,0 +1,1708 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2023, Tri Dao.
|
| 2 |
+
|
| 3 |
+
from typing import Optional, Sequence, Tuple, Union
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
import torch.nn as nn
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
# # isort: off
|
| 10 |
+
# # We need to import the CUDA kernels after importing torch
|
| 11 |
+
# USE_TRITON_ROCM = os.getenv("FLASH_ATTENTION_TRITON_AMD_ENABLE", "FALSE") == "TRUE"
|
| 12 |
+
# if USE_TRITON_ROCM:
|
| 13 |
+
# from .flash_attn_triton_amd import interface_fa as flash_attn
|
| 14 |
+
# else:
|
| 15 |
+
# import flash_attn_2_cuda as flash_attn
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
from ._ops import ops as flash_attn
|
| 19 |
+
from ._ops import add_op_namespace_prefix
|
| 20 |
+
|
| 21 |
+
# # isort: on
|
| 22 |
+
|
| 23 |
+
# Torch >= 2.13 can pass a Generator through the stable ABI. Older versions reject the argument
|
| 24 |
+
# before the kernel runs, so there the CUDA op has to draw its Philox seed and offset itself.
|
| 25 |
+
_STABLE_ABI_GENERATOR = torch.__version__ >= "2.13"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def maybe_contiguous(x):
|
| 29 |
+
return x.contiguous() if x is not None and x.stride(-1) != 1 else x
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def _get_device():
|
| 33 |
+
if torch.xpu.is_available():
|
| 34 |
+
return "xpu"
|
| 35 |
+
elif torch.cuda.is_available():
|
| 36 |
+
return "cuda"
|
| 37 |
+
else:
|
| 38 |
+
return "cpu"
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def _get_block_size_n(device, head_dim, is_dropout, is_causal):
|
| 42 |
+
assert head_dim <= 256
|
| 43 |
+
|
| 44 |
+
if device.type == "xpu":
|
| 45 |
+
if head_dim <= 96:
|
| 46 |
+
return 64
|
| 47 |
+
elif head_dim <= 128:
|
| 48 |
+
return 32
|
| 49 |
+
elif head_dim <= 256:
|
| 50 |
+
return 64
|
| 51 |
+
else:
|
| 52 |
+
return 32
|
| 53 |
+
|
| 54 |
+
# This should match the block sizes in the CUDA kernel
|
| 55 |
+
major, minor = torch.cuda.get_device_capability(device)
|
| 56 |
+
is_sm8x = (
|
| 57 |
+
major == 8 and minor > 0
|
| 58 |
+
) # Only include sm86 and sm89, exclude sm80 (A100)
|
| 59 |
+
is_sm80 = major == 8 and minor == 0
|
| 60 |
+
is_sm90 = major == 9 and minor == 0
|
| 61 |
+
if head_dim <= 32:
|
| 62 |
+
return 128
|
| 63 |
+
if head_dim <= 64:
|
| 64 |
+
return 128 if not is_dropout else 64
|
| 65 |
+
elif head_dim <= 96:
|
| 66 |
+
return 64
|
| 67 |
+
elif head_dim <= 128:
|
| 68 |
+
if is_sm8x:
|
| 69 |
+
return 64 if (not is_dropout and is_causal) else 32
|
| 70 |
+
else:
|
| 71 |
+
return 64 if not is_dropout else 32
|
| 72 |
+
elif head_dim <= 192:
|
| 73 |
+
return 64
|
| 74 |
+
elif head_dim <= 224:
|
| 75 |
+
return 64
|
| 76 |
+
elif head_dim <= 256:
|
| 77 |
+
return 64
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def round_multiple(x, m):
|
| 81 |
+
return (x + m - 1) // m * m
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def _philox_generator(
|
| 85 |
+
q: torch.Tensor, dropout_p: float, generator: Optional[torch.Generator] = None
|
| 86 |
+
) -> Optional[torch.Generator]:
|
| 87 |
+
"""The generator to hand to `fwd` / `varlen_fwd`.
|
| 88 |
+
|
| 89 |
+
With dropout on CUDA this is the default generator unless one is given, so the kernel reserves
|
| 90 |
+
its seed and offset exactly like the non-stable build (see set_params_philox in flash_api.cpp).
|
| 91 |
+
"""
|
| 92 |
+
if not q.is_cuda:
|
| 93 |
+
return generator
|
| 94 |
+
if dropout_p <= 0:
|
| 95 |
+
return None
|
| 96 |
+
if not _STABLE_ABI_GENERATOR:
|
| 97 |
+
if generator is not None:
|
| 98 |
+
raise ValueError(
|
| 99 |
+
"flash_attn2: passing a generator to the CUDA kernel requires torch >= 2.13; "
|
| 100 |
+
"seed the default generator with torch.manual_seed instead"
|
| 101 |
+
)
|
| 102 |
+
return None
|
| 103 |
+
if generator is None:
|
| 104 |
+
generator = torch.cuda.default_generators[q.device.index]
|
| 105 |
+
return generator
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
@torch.library.custom_op(
|
| 109 |
+
add_op_namespace_prefix("_flash_attn_forward"),
|
| 110 |
+
mutates_args=(),
|
| 111 |
+
device_types=_get_device(),
|
| 112 |
+
# Tells torch.compile the forward draws random numbers, so it is never deduplicated or
|
| 113 |
+
# recomputed (e.g. under activation checkpointing).
|
| 114 |
+
tags=(torch.Tag.nondeterministic_seeded,),
|
| 115 |
+
)
|
| 116 |
+
def _flash_attn_forward(
|
| 117 |
+
q: torch.Tensor,
|
| 118 |
+
k: torch.Tensor,
|
| 119 |
+
v: torch.Tensor,
|
| 120 |
+
dropout_p: float,
|
| 121 |
+
softmax_scale: float,
|
| 122 |
+
causal: bool,
|
| 123 |
+
window_size_left: int,
|
| 124 |
+
window_size_right: int,
|
| 125 |
+
softcap: float,
|
| 126 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 127 |
+
return_softmax: bool,
|
| 128 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 129 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 130 |
+
gen = _philox_generator(q, dropout_p)
|
| 131 |
+
out, softmax_lse, S_dmask, rng_state = flash_attn.fwd(
|
| 132 |
+
q,
|
| 133 |
+
k,
|
| 134 |
+
v,
|
| 135 |
+
None,
|
| 136 |
+
alibi_slopes,
|
| 137 |
+
dropout_p,
|
| 138 |
+
softmax_scale,
|
| 139 |
+
causal,
|
| 140 |
+
window_size_left,
|
| 141 |
+
window_size_right,
|
| 142 |
+
softcap,
|
| 143 |
+
return_softmax,
|
| 144 |
+
gen,
|
| 145 |
+
)
|
| 146 |
+
return out, softmax_lse, S_dmask, rng_state
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_forward"))
|
| 150 |
+
def _flash_attn_forward_fake(
|
| 151 |
+
q: torch.Tensor,
|
| 152 |
+
k: torch.Tensor,
|
| 153 |
+
v: torch.Tensor,
|
| 154 |
+
dropout_p: float,
|
| 155 |
+
softmax_scale: float,
|
| 156 |
+
causal: bool,
|
| 157 |
+
window_size_left: int,
|
| 158 |
+
window_size_right: int,
|
| 159 |
+
softcap: float,
|
| 160 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 161 |
+
return_softmax: bool,
|
| 162 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 163 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 164 |
+
batch_size, seqlen_q, num_heads, head_size = q.shape
|
| 165 |
+
seqlen_k = k.shape[1]
|
| 166 |
+
out = torch.empty_like(q)
|
| 167 |
+
softmax_lse = torch.empty(
|
| 168 |
+
(batch_size, num_heads, seqlen_q),
|
| 169 |
+
dtype=torch.float32,
|
| 170 |
+
device=q.device,
|
| 171 |
+
layout=q.layout,
|
| 172 |
+
)
|
| 173 |
+
p = torch.empty((0,), dtype=q.dtype, device=q.device, layout=q.layout)
|
| 174 |
+
if return_softmax:
|
| 175 |
+
p = torch.empty(
|
| 176 |
+
(
|
| 177 |
+
batch_size,
|
| 178 |
+
num_heads,
|
| 179 |
+
round_multiple(seqlen_q, 128),
|
| 180 |
+
round_multiple(seqlen_k, 128),
|
| 181 |
+
),
|
| 182 |
+
dtype=q.dtype,
|
| 183 |
+
device=q.device,
|
| 184 |
+
layout=q.layout,
|
| 185 |
+
)
|
| 186 |
+
rng_state = torch.empty((2,), dtype=torch.int64, device=q.device)
|
| 187 |
+
|
| 188 |
+
return out, softmax_lse, p, rng_state
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
_wrapped_flash_attn_forward = flash_attn._flash_attn_forward # upstream alias, see CARD.md
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
@torch.library.custom_op(
|
| 195 |
+
add_op_namespace_prefix("_flash_attn_varlen_forward"),
|
| 196 |
+
mutates_args=(),
|
| 197 |
+
device_types=_get_device(),
|
| 198 |
+
tags=(torch.Tag.nondeterministic_seeded,),
|
| 199 |
+
)
|
| 200 |
+
def _flash_attn_varlen_forward(
|
| 201 |
+
q: torch.Tensor,
|
| 202 |
+
k: torch.Tensor,
|
| 203 |
+
v: torch.Tensor,
|
| 204 |
+
cu_seqlens_q: torch.Tensor,
|
| 205 |
+
cu_seqlens_k: torch.Tensor,
|
| 206 |
+
max_seqlen_q: int,
|
| 207 |
+
max_seqlen_k: int,
|
| 208 |
+
dropout_p: float,
|
| 209 |
+
softmax_scale: float,
|
| 210 |
+
causal: bool,
|
| 211 |
+
window_size_left: int = -1,
|
| 212 |
+
window_size_right: int = -1,
|
| 213 |
+
softcap: float = 0.0,
|
| 214 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 215 |
+
return_softmax: bool = False,
|
| 216 |
+
block_table: Optional[torch.Tensor] = None,
|
| 217 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 218 |
+
seqused_k: Optional[torch.Tensor] = None,
|
| 219 |
+
zero_tensors: bool = False,
|
| 220 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 221 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 222 |
+
gen = _philox_generator(q, dropout_p)
|
| 223 |
+
out, softmax_lse, S_dmask, rng_state = flash_attn.varlen_fwd(
|
| 224 |
+
q,
|
| 225 |
+
k,
|
| 226 |
+
v,
|
| 227 |
+
None,
|
| 228 |
+
cu_seqlens_q,
|
| 229 |
+
cu_seqlens_k,
|
| 230 |
+
seqused_k,
|
| 231 |
+
leftpad_k,
|
| 232 |
+
block_table,
|
| 233 |
+
alibi_slopes,
|
| 234 |
+
max_seqlen_q,
|
| 235 |
+
max_seqlen_k,
|
| 236 |
+
dropout_p,
|
| 237 |
+
softmax_scale,
|
| 238 |
+
zero_tensors,
|
| 239 |
+
causal,
|
| 240 |
+
window_size_left,
|
| 241 |
+
window_size_right,
|
| 242 |
+
softcap,
|
| 243 |
+
return_softmax,
|
| 244 |
+
gen,
|
| 245 |
+
)
|
| 246 |
+
# if out.isnan().any() or softmax_lse.isnan().any():
|
| 247 |
+
# breakpoint()
|
| 248 |
+
return out, softmax_lse, S_dmask, rng_state
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_varlen_forward"))
|
| 252 |
+
def _flash_attn_varlen_forward_fake(
|
| 253 |
+
q: torch.Tensor,
|
| 254 |
+
k: torch.Tensor,
|
| 255 |
+
v: torch.Tensor,
|
| 256 |
+
cu_seqlens_q: torch.Tensor,
|
| 257 |
+
cu_seqlens_k: torch.Tensor,
|
| 258 |
+
max_seqlen_q: int,
|
| 259 |
+
max_seqlen_k: int,
|
| 260 |
+
dropout_p: float,
|
| 261 |
+
softmax_scale: float,
|
| 262 |
+
causal: bool,
|
| 263 |
+
window_size_left: int = -1,
|
| 264 |
+
window_size_right: int = -1,
|
| 265 |
+
softcap: float = 0.0,
|
| 266 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 267 |
+
return_softmax: bool = False,
|
| 268 |
+
block_table: Optional[torch.Tensor] = None,
|
| 269 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 270 |
+
seqused_k: Optional[torch.Tensor] = None,
|
| 271 |
+
zero_tensors: bool = False,
|
| 272 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 273 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 274 |
+
paged_kv = block_table is not None
|
| 275 |
+
batch_size = cu_seqlens_q.numel() - 1
|
| 276 |
+
total_q, num_heads, _ = q.shape
|
| 277 |
+
|
| 278 |
+
out = torch.empty_like(q)
|
| 279 |
+
softmax_lse = torch.empty(
|
| 280 |
+
(num_heads, total_q), dtype=torch.float32, device=q.device, layout=q.layout
|
| 281 |
+
)
|
| 282 |
+
p = torch.empty((0,), dtype=q.dtype, device=q.device, layout=q.layout)
|
| 283 |
+
seqlen_q_rounded = round_multiple(max_seqlen_q, 128)
|
| 284 |
+
seqlen_k_rounded = round_multiple(max_seqlen_k, 128)
|
| 285 |
+
if return_softmax:
|
| 286 |
+
p = torch.empty(
|
| 287 |
+
(batch_size, num_heads, seqlen_q_rounded, seqlen_k_rounded),
|
| 288 |
+
dtype=q.dtype,
|
| 289 |
+
device=q.device,
|
| 290 |
+
layout=q.layout,
|
| 291 |
+
)
|
| 292 |
+
rng_state = torch.empty((2,), dtype=torch.int64, device=q.device)
|
| 293 |
+
return out, softmax_lse, p, rng_state
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
_wrapped_flash_attn_varlen_forward = flash_attn._flash_attn_varlen_forward # upstream alias, see CARD.md
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
@torch.library.custom_op(
|
| 300 |
+
add_op_namespace_prefix("_flash_attn_backward"),
|
| 301 |
+
mutates_args=("dq", "dk", "dv"),
|
| 302 |
+
device_types=_get_device(),
|
| 303 |
+
)
|
| 304 |
+
def _flash_attn_backward(
|
| 305 |
+
dout: torch.Tensor,
|
| 306 |
+
q: torch.Tensor,
|
| 307 |
+
k: torch.Tensor,
|
| 308 |
+
v: torch.Tensor,
|
| 309 |
+
out: torch.Tensor,
|
| 310 |
+
softmax_lse: torch.Tensor,
|
| 311 |
+
dq: Optional[torch.Tensor],
|
| 312 |
+
dk: Optional[torch.Tensor],
|
| 313 |
+
dv: Optional[torch.Tensor],
|
| 314 |
+
dropout_p: float,
|
| 315 |
+
softmax_scale: float,
|
| 316 |
+
causal: bool,
|
| 317 |
+
window_size_left: int,
|
| 318 |
+
window_size_right: int,
|
| 319 |
+
softcap: float,
|
| 320 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 321 |
+
deterministic: bool,
|
| 322 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 323 |
+
) -> torch.Tensor:
|
| 324 |
+
# dq, dk, dv are allocated by us so they should already be contiguous
|
| 325 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 326 |
+
(
|
| 327 |
+
dq,
|
| 328 |
+
dk,
|
| 329 |
+
dv,
|
| 330 |
+
softmax_d,
|
| 331 |
+
) = flash_attn.bwd(
|
| 332 |
+
dout,
|
| 333 |
+
q,
|
| 334 |
+
k,
|
| 335 |
+
v,
|
| 336 |
+
out,
|
| 337 |
+
softmax_lse,
|
| 338 |
+
dq,
|
| 339 |
+
dk,
|
| 340 |
+
dv,
|
| 341 |
+
alibi_slopes,
|
| 342 |
+
dropout_p,
|
| 343 |
+
softmax_scale,
|
| 344 |
+
causal,
|
| 345 |
+
window_size_left,
|
| 346 |
+
window_size_right,
|
| 347 |
+
softcap,
|
| 348 |
+
deterministic,
|
| 349 |
+
None,
|
| 350 |
+
rng_state,
|
| 351 |
+
)
|
| 352 |
+
return softmax_d
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_backward"))
|
| 356 |
+
def _flash_attn_backward_fake(
|
| 357 |
+
dout: torch.Tensor,
|
| 358 |
+
q: torch.Tensor,
|
| 359 |
+
k: torch.Tensor,
|
| 360 |
+
v: torch.Tensor,
|
| 361 |
+
out: torch.Tensor,
|
| 362 |
+
softmax_lse: torch.Tensor,
|
| 363 |
+
dq: Optional[torch.Tensor],
|
| 364 |
+
dk: Optional[torch.Tensor],
|
| 365 |
+
dv: Optional[torch.Tensor],
|
| 366 |
+
dropout_p: float,
|
| 367 |
+
softmax_scale: float,
|
| 368 |
+
causal: bool,
|
| 369 |
+
window_size_left: int,
|
| 370 |
+
window_size_right: int,
|
| 371 |
+
softcap: float,
|
| 372 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 373 |
+
deterministic: bool,
|
| 374 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 375 |
+
) -> torch.Tensor:
|
| 376 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 377 |
+
if dq is None:
|
| 378 |
+
dq = torch.empty_like(q)
|
| 379 |
+
if dk is None:
|
| 380 |
+
dk = torch.empty_like(k)
|
| 381 |
+
if dv is None:
|
| 382 |
+
dv = torch.empty_like(v)
|
| 383 |
+
batch_size, seqlen_q, num_heads, _ = q.shape
|
| 384 |
+
softmax_d = torch.empty(
|
| 385 |
+
(batch_size, num_heads, round_multiple(seqlen_q, 128)),
|
| 386 |
+
device=q.device,
|
| 387 |
+
dtype=torch.float32,
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
return softmax_d
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
_wrapped_flash_attn_backward = flash_attn._flash_attn_backward # upstream alias, see CARD.md
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
@torch.library.custom_op(
|
| 397 |
+
add_op_namespace_prefix("_flash_attn_varlen_backward"),
|
| 398 |
+
mutates_args=("dq", "dk", "dv"),
|
| 399 |
+
device_types=_get_device(),
|
| 400 |
+
)
|
| 401 |
+
def _flash_attn_varlen_backward(
|
| 402 |
+
dout: torch.Tensor,
|
| 403 |
+
q: torch.Tensor,
|
| 404 |
+
k: torch.Tensor,
|
| 405 |
+
v: torch.Tensor,
|
| 406 |
+
out: torch.Tensor,
|
| 407 |
+
softmax_lse: torch.Tensor,
|
| 408 |
+
dq: Optional[torch.Tensor],
|
| 409 |
+
dk: Optional[torch.Tensor],
|
| 410 |
+
dv: Optional[torch.Tensor],
|
| 411 |
+
cu_seqlens_q: torch.Tensor,
|
| 412 |
+
cu_seqlens_k: torch.Tensor,
|
| 413 |
+
max_seqlen_q: int,
|
| 414 |
+
max_seqlen_k: int,
|
| 415 |
+
dropout_p: float,
|
| 416 |
+
softmax_scale: float,
|
| 417 |
+
causal: bool,
|
| 418 |
+
window_size_left: int,
|
| 419 |
+
window_size_right: int,
|
| 420 |
+
softcap: float,
|
| 421 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 422 |
+
deterministic: bool,
|
| 423 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 424 |
+
zero_tensors: bool = False,
|
| 425 |
+
) -> torch.Tensor:
|
| 426 |
+
# dq, dk, dv are allocated by us so they should already be contiguous
|
| 427 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 428 |
+
(
|
| 429 |
+
dq,
|
| 430 |
+
dk,
|
| 431 |
+
dv,
|
| 432 |
+
softmax_d,
|
| 433 |
+
) = flash_attn.varlen_bwd(
|
| 434 |
+
dout,
|
| 435 |
+
q,
|
| 436 |
+
k,
|
| 437 |
+
v,
|
| 438 |
+
out,
|
| 439 |
+
softmax_lse,
|
| 440 |
+
dq,
|
| 441 |
+
dk,
|
| 442 |
+
dv,
|
| 443 |
+
cu_seqlens_q,
|
| 444 |
+
cu_seqlens_k,
|
| 445 |
+
alibi_slopes,
|
| 446 |
+
max_seqlen_q,
|
| 447 |
+
max_seqlen_k,
|
| 448 |
+
dropout_p,
|
| 449 |
+
softmax_scale,
|
| 450 |
+
zero_tensors,
|
| 451 |
+
causal,
|
| 452 |
+
window_size_left,
|
| 453 |
+
window_size_right,
|
| 454 |
+
softcap,
|
| 455 |
+
deterministic,
|
| 456 |
+
None,
|
| 457 |
+
rng_state,
|
| 458 |
+
)
|
| 459 |
+
# if dk.isnan().any() or dk.isnan().any() or dv.isnan().any() or softmax_d.isnan().any():
|
| 460 |
+
# breakpoint()
|
| 461 |
+
return softmax_d
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_varlen_backward"))
|
| 465 |
+
def _flash_attn_varlen_backward_fake(
|
| 466 |
+
dout: torch.Tensor,
|
| 467 |
+
q: torch.Tensor,
|
| 468 |
+
k: torch.Tensor,
|
| 469 |
+
v: torch.Tensor,
|
| 470 |
+
out: torch.Tensor,
|
| 471 |
+
softmax_lse: torch.Tensor,
|
| 472 |
+
dq: Optional[torch.Tensor],
|
| 473 |
+
dk: Optional[torch.Tensor],
|
| 474 |
+
dv: Optional[torch.Tensor],
|
| 475 |
+
cu_seqlens_q: torch.Tensor,
|
| 476 |
+
cu_seqlens_k: torch.Tensor,
|
| 477 |
+
max_seqlen_q: int,
|
| 478 |
+
max_seqlen_k: int,
|
| 479 |
+
dropout_p: float,
|
| 480 |
+
softmax_scale: float,
|
| 481 |
+
causal: bool,
|
| 482 |
+
window_size_left: int,
|
| 483 |
+
window_size_right: int,
|
| 484 |
+
softcap: float,
|
| 485 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 486 |
+
deterministic: bool,
|
| 487 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 488 |
+
zero_tensors: bool = False,
|
| 489 |
+
) -> torch.Tensor:
|
| 490 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 491 |
+
batch_size = cu_seqlens_q.numel() - 1
|
| 492 |
+
total_q, num_heads, _ = q.shape
|
| 493 |
+
|
| 494 |
+
if dq is None:
|
| 495 |
+
dq = torch.empty_like(q)
|
| 496 |
+
if dk is None:
|
| 497 |
+
dk = torch.empty_like(k)
|
| 498 |
+
if dv is None:
|
| 499 |
+
dv = torch.empty_like(v)
|
| 500 |
+
softmax_d = torch.empty(
|
| 501 |
+
(num_heads, total_q + 128 * batch_size), device=q.device, dtype=torch.float32
|
| 502 |
+
)
|
| 503 |
+
|
| 504 |
+
return softmax_d
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
_wrapped_flash_attn_varlen_backward = flash_attn._flash_attn_varlen_backward # upstream alias, see CARD.md
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
class FlashAttnQKVPackedFunc(torch.autograd.Function):
|
| 511 |
+
@staticmethod
|
| 512 |
+
def forward(
|
| 513 |
+
ctx,
|
| 514 |
+
qkv,
|
| 515 |
+
dropout_p,
|
| 516 |
+
softmax_scale,
|
| 517 |
+
causal,
|
| 518 |
+
window_size,
|
| 519 |
+
softcap,
|
| 520 |
+
alibi_slopes,
|
| 521 |
+
deterministic,
|
| 522 |
+
return_softmax,
|
| 523 |
+
is_grad_enabled,
|
| 524 |
+
):
|
| 525 |
+
is_grad = is_grad_enabled and qkv.requires_grad
|
| 526 |
+
if softmax_scale is None:
|
| 527 |
+
softmax_scale = qkv.shape[-1] ** (-0.5)
|
| 528 |
+
q, k, v = qkv[:, :, 0].detach(), qkv[:, :, 1].detach(), qkv[:, :, 2].detach()
|
| 529 |
+
head_size_og = q.size(3)
|
| 530 |
+
if head_size_og % 8 != 0:
|
| 531 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 532 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 533 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 534 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_forward(
|
| 535 |
+
q,
|
| 536 |
+
k,
|
| 537 |
+
v,
|
| 538 |
+
dropout_p,
|
| 539 |
+
softmax_scale,
|
| 540 |
+
causal=causal,
|
| 541 |
+
window_size_left=window_size[0],
|
| 542 |
+
window_size_right=window_size[1],
|
| 543 |
+
softcap=softcap,
|
| 544 |
+
alibi_slopes=alibi_slopes,
|
| 545 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 546 |
+
)
|
| 547 |
+
if is_grad:
|
| 548 |
+
ctx.save_for_backward(q, k, v, out_padded, softmax_lse, rng_state)
|
| 549 |
+
ctx.dropout_p = dropout_p
|
| 550 |
+
ctx.softmax_scale = softmax_scale
|
| 551 |
+
ctx.causal = causal
|
| 552 |
+
ctx.window_size = window_size
|
| 553 |
+
ctx.softcap = softcap
|
| 554 |
+
ctx.alibi_slopes = alibi_slopes
|
| 555 |
+
ctx.deterministic = deterministic
|
| 556 |
+
out = out_padded[..., :head_size_og]
|
| 557 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 558 |
+
|
| 559 |
+
@staticmethod
|
| 560 |
+
def backward(ctx, dout, *args):
|
| 561 |
+
q, k, v, out, softmax_lse, rng_state = ctx.saved_tensors
|
| 562 |
+
qkv_shape = q.shape[:-2] + (3, *q.shape[-2:])
|
| 563 |
+
dqkv = torch.empty(qkv_shape, dtype=q.dtype, device=q.device)
|
| 564 |
+
head_size_og = dout.size(3)
|
| 565 |
+
dout_padded = dout
|
| 566 |
+
if head_size_og % 8 != 0:
|
| 567 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 568 |
+
_flash_attn_backward(
|
| 569 |
+
dout_padded,
|
| 570 |
+
q,
|
| 571 |
+
k,
|
| 572 |
+
v,
|
| 573 |
+
out,
|
| 574 |
+
softmax_lse,
|
| 575 |
+
dqkv[:, :, 0],
|
| 576 |
+
dqkv[:, :, 1],
|
| 577 |
+
dqkv[:, :, 2],
|
| 578 |
+
ctx.dropout_p,
|
| 579 |
+
ctx.softmax_scale,
|
| 580 |
+
ctx.causal,
|
| 581 |
+
ctx.window_size[0],
|
| 582 |
+
ctx.window_size[1],
|
| 583 |
+
ctx.softcap,
|
| 584 |
+
ctx.alibi_slopes,
|
| 585 |
+
ctx.deterministic,
|
| 586 |
+
rng_state=rng_state,
|
| 587 |
+
)
|
| 588 |
+
dqkv = dqkv[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 589 |
+
return dqkv, None, None, None, None, None, None, None, None, None
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
class FlashAttnVarlenQKVPackedFunc(torch.autograd.Function):
|
| 593 |
+
@staticmethod
|
| 594 |
+
def forward(
|
| 595 |
+
ctx,
|
| 596 |
+
qkv,
|
| 597 |
+
cu_seqlens,
|
| 598 |
+
max_seqlen,
|
| 599 |
+
dropout_p,
|
| 600 |
+
softmax_scale,
|
| 601 |
+
causal,
|
| 602 |
+
window_size,
|
| 603 |
+
softcap,
|
| 604 |
+
alibi_slopes,
|
| 605 |
+
deterministic,
|
| 606 |
+
return_softmax,
|
| 607 |
+
is_grad_enabled,
|
| 608 |
+
):
|
| 609 |
+
is_grad = is_grad_enabled and qkv.requires_grad
|
| 610 |
+
if softmax_scale is None:
|
| 611 |
+
softmax_scale = qkv.shape[-1] ** (-0.5)
|
| 612 |
+
q, k, v = qkv[:, 0].detach(), qkv[:, 1].detach(), qkv[:, 2].detach()
|
| 613 |
+
head_size_og = q.size(2)
|
| 614 |
+
if head_size_og % 8 != 0:
|
| 615 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 616 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 617 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 618 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_varlen_forward(
|
| 619 |
+
q,
|
| 620 |
+
k,
|
| 621 |
+
v,
|
| 622 |
+
cu_seqlens,
|
| 623 |
+
cu_seqlens,
|
| 624 |
+
max_seqlen,
|
| 625 |
+
max_seqlen,
|
| 626 |
+
dropout_p,
|
| 627 |
+
softmax_scale,
|
| 628 |
+
causal=causal,
|
| 629 |
+
window_size_left=window_size[0],
|
| 630 |
+
window_size_right=window_size[1],
|
| 631 |
+
softcap=softcap,
|
| 632 |
+
alibi_slopes=alibi_slopes,
|
| 633 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 634 |
+
block_table=None,
|
| 635 |
+
)
|
| 636 |
+
if is_grad:
|
| 637 |
+
ctx.save_for_backward(
|
| 638 |
+
q, k, v, out_padded, softmax_lse, cu_seqlens, rng_state
|
| 639 |
+
)
|
| 640 |
+
ctx.dropout_p = dropout_p
|
| 641 |
+
ctx.max_seqlen = max_seqlen
|
| 642 |
+
ctx.softmax_scale = softmax_scale
|
| 643 |
+
ctx.causal = causal
|
| 644 |
+
ctx.window_size = window_size
|
| 645 |
+
ctx.softcap = softcap
|
| 646 |
+
ctx.alibi_slopes = alibi_slopes
|
| 647 |
+
ctx.deterministic = deterministic
|
| 648 |
+
out = out_padded[..., :head_size_og]
|
| 649 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 650 |
+
|
| 651 |
+
@staticmethod
|
| 652 |
+
def backward(ctx, dout, *args):
|
| 653 |
+
q, k, v, out, softmax_lse, cu_seqlens, rng_state = ctx.saved_tensors
|
| 654 |
+
qkv_shape = q.shape[:-2] + (3, *q.shape[-2:])
|
| 655 |
+
dqkv = torch.empty(qkv_shape, dtype=q.dtype, device=q.device)
|
| 656 |
+
head_size_og = dout.size(2)
|
| 657 |
+
dout_padded = dout
|
| 658 |
+
if head_size_og % 8 != 0:
|
| 659 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 660 |
+
_flash_attn_varlen_backward(
|
| 661 |
+
dout_padded,
|
| 662 |
+
q,
|
| 663 |
+
k,
|
| 664 |
+
v,
|
| 665 |
+
out,
|
| 666 |
+
softmax_lse,
|
| 667 |
+
dqkv[:, 0],
|
| 668 |
+
dqkv[:, 1],
|
| 669 |
+
dqkv[:, 2],
|
| 670 |
+
cu_seqlens,
|
| 671 |
+
cu_seqlens,
|
| 672 |
+
ctx.max_seqlen,
|
| 673 |
+
ctx.max_seqlen,
|
| 674 |
+
ctx.dropout_p,
|
| 675 |
+
ctx.softmax_scale,
|
| 676 |
+
ctx.causal,
|
| 677 |
+
ctx.window_size[0],
|
| 678 |
+
ctx.window_size[1],
|
| 679 |
+
ctx.softcap,
|
| 680 |
+
ctx.alibi_slopes,
|
| 681 |
+
ctx.deterministic,
|
| 682 |
+
rng_state=rng_state,
|
| 683 |
+
)
|
| 684 |
+
dqkv = dqkv[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 685 |
+
return dqkv, None, None, None, None, None, None, None, None, None, None, None
|
| 686 |
+
|
| 687 |
+
|
| 688 |
+
class FlashAttnKVPackedFunc(torch.autograd.Function):
|
| 689 |
+
@staticmethod
|
| 690 |
+
def forward(
|
| 691 |
+
ctx,
|
| 692 |
+
q,
|
| 693 |
+
kv,
|
| 694 |
+
dropout_p,
|
| 695 |
+
softmax_scale,
|
| 696 |
+
causal,
|
| 697 |
+
window_size,
|
| 698 |
+
softcap,
|
| 699 |
+
alibi_slopes,
|
| 700 |
+
deterministic,
|
| 701 |
+
return_softmax,
|
| 702 |
+
is_grad_enabled,
|
| 703 |
+
):
|
| 704 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, kv])
|
| 705 |
+
if softmax_scale is None:
|
| 706 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 707 |
+
k, v = kv[:, :, 0].detach(), kv[:, :, 1].detach()
|
| 708 |
+
head_size_og = q.size(3)
|
| 709 |
+
if head_size_og % 8 != 0:
|
| 710 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 711 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 712 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 713 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_forward(
|
| 714 |
+
q,
|
| 715 |
+
k,
|
| 716 |
+
v,
|
| 717 |
+
dropout_p,
|
| 718 |
+
softmax_scale,
|
| 719 |
+
causal=causal,
|
| 720 |
+
window_size_left=window_size[0],
|
| 721 |
+
window_size_right=window_size[1],
|
| 722 |
+
softcap=softcap,
|
| 723 |
+
alibi_slopes=alibi_slopes,
|
| 724 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 725 |
+
)
|
| 726 |
+
if is_grad:
|
| 727 |
+
ctx.save_for_backward(q, k, v, out_padded, softmax_lse, rng_state)
|
| 728 |
+
ctx.dropout_p = dropout_p
|
| 729 |
+
ctx.softmax_scale = softmax_scale
|
| 730 |
+
ctx.causal = causal
|
| 731 |
+
ctx.window_size = window_size
|
| 732 |
+
ctx.softcap = softcap
|
| 733 |
+
ctx.alibi_slopes = alibi_slopes
|
| 734 |
+
ctx.deterministic = deterministic
|
| 735 |
+
out = out_padded[..., :head_size_og]
|
| 736 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 737 |
+
|
| 738 |
+
@staticmethod
|
| 739 |
+
def backward(ctx, dout, *args):
|
| 740 |
+
q, k, v, out, softmax_lse, rng_state = ctx.saved_tensors
|
| 741 |
+
dq = torch.empty_like(q)
|
| 742 |
+
kv_shape = k.shape[:-2] + (2, *k.shape[-2:])
|
| 743 |
+
dkv = torch.empty(kv_shape, dtype=k.dtype, device=k.device)
|
| 744 |
+
head_size_og = dout.size(3)
|
| 745 |
+
dout_padded = dout
|
| 746 |
+
if head_size_og % 8 != 0:
|
| 747 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 748 |
+
_flash_attn_backward(
|
| 749 |
+
dout_padded,
|
| 750 |
+
q,
|
| 751 |
+
k,
|
| 752 |
+
v,
|
| 753 |
+
out,
|
| 754 |
+
softmax_lse,
|
| 755 |
+
dq,
|
| 756 |
+
dkv[:, :, 0],
|
| 757 |
+
dkv[:, :, 1],
|
| 758 |
+
ctx.dropout_p,
|
| 759 |
+
ctx.softmax_scale,
|
| 760 |
+
ctx.causal,
|
| 761 |
+
ctx.window_size[0],
|
| 762 |
+
ctx.window_size[1],
|
| 763 |
+
ctx.softcap,
|
| 764 |
+
ctx.alibi_slopes,
|
| 765 |
+
ctx.deterministic,
|
| 766 |
+
rng_state=rng_state,
|
| 767 |
+
)
|
| 768 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 769 |
+
dkv = dkv[..., : dout.shape[-1]]
|
| 770 |
+
return dq, dkv, None, None, None, None, None, None, None, None, None
|
| 771 |
+
|
| 772 |
+
|
| 773 |
+
class FlashAttnVarlenKVPackedFunc(torch.autograd.Function):
|
| 774 |
+
@staticmethod
|
| 775 |
+
def forward(
|
| 776 |
+
ctx,
|
| 777 |
+
q,
|
| 778 |
+
kv,
|
| 779 |
+
cu_seqlens_q,
|
| 780 |
+
cu_seqlens_k,
|
| 781 |
+
max_seqlen_q,
|
| 782 |
+
max_seqlen_k,
|
| 783 |
+
dropout_p,
|
| 784 |
+
softmax_scale,
|
| 785 |
+
causal,
|
| 786 |
+
window_size,
|
| 787 |
+
softcap,
|
| 788 |
+
alibi_slopes,
|
| 789 |
+
deterministic,
|
| 790 |
+
return_softmax,
|
| 791 |
+
is_grad_enabled,
|
| 792 |
+
):
|
| 793 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, kv])
|
| 794 |
+
if softmax_scale is None:
|
| 795 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 796 |
+
k, v = kv[:, 0].detach(), kv[:, 1].detach()
|
| 797 |
+
head_size_og = q.size(2)
|
| 798 |
+
if head_size_og % 8 != 0:
|
| 799 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 800 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 801 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 802 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_varlen_forward(
|
| 803 |
+
q,
|
| 804 |
+
k,
|
| 805 |
+
v,
|
| 806 |
+
cu_seqlens_q,
|
| 807 |
+
cu_seqlens_k,
|
| 808 |
+
max_seqlen_q,
|
| 809 |
+
max_seqlen_k,
|
| 810 |
+
dropout_p,
|
| 811 |
+
softmax_scale,
|
| 812 |
+
causal=causal,
|
| 813 |
+
window_size_left=window_size[0],
|
| 814 |
+
window_size_right=window_size[1],
|
| 815 |
+
softcap=softcap,
|
| 816 |
+
alibi_slopes=alibi_slopes,
|
| 817 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 818 |
+
block_table=None,
|
| 819 |
+
)
|
| 820 |
+
if is_grad:
|
| 821 |
+
ctx.save_for_backward(
|
| 822 |
+
q, k, v, out_padded, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state
|
| 823 |
+
)
|
| 824 |
+
ctx.dropout_p = dropout_p
|
| 825 |
+
ctx.max_seqlen_q = max_seqlen_q
|
| 826 |
+
ctx.max_seqlen_k = max_seqlen_k
|
| 827 |
+
ctx.softmax_scale = softmax_scale
|
| 828 |
+
ctx.causal = causal
|
| 829 |
+
ctx.window_size = window_size
|
| 830 |
+
ctx.softcap = softcap
|
| 831 |
+
ctx.alibi_slopes = alibi_slopes
|
| 832 |
+
ctx.deterministic = deterministic
|
| 833 |
+
out = out_padded[..., :head_size_og]
|
| 834 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 835 |
+
|
| 836 |
+
@staticmethod
|
| 837 |
+
def backward(ctx, dout, *args):
|
| 838 |
+
q, k, v, out, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state = (
|
| 839 |
+
ctx.saved_tensors
|
| 840 |
+
)
|
| 841 |
+
dq = torch.empty_like(q)
|
| 842 |
+
kv_shape = k.shape[:-2] + (2, *k.shape[-2:])
|
| 843 |
+
dkv = torch.empty(kv_shape, dtype=k.dtype, device=k.device)
|
| 844 |
+
head_size_og = dout.size(2)
|
| 845 |
+
dout_padded = dout
|
| 846 |
+
if head_size_og % 8 != 0:
|
| 847 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 848 |
+
_flash_attn_varlen_backward(
|
| 849 |
+
dout_padded,
|
| 850 |
+
q,
|
| 851 |
+
k,
|
| 852 |
+
v,
|
| 853 |
+
out,
|
| 854 |
+
softmax_lse,
|
| 855 |
+
dq,
|
| 856 |
+
dkv[:, 0],
|
| 857 |
+
dkv[:, 1],
|
| 858 |
+
cu_seqlens_q,
|
| 859 |
+
cu_seqlens_k,
|
| 860 |
+
ctx.max_seqlen_q,
|
| 861 |
+
ctx.max_seqlen_k,
|
| 862 |
+
ctx.dropout_p,
|
| 863 |
+
ctx.softmax_scale,
|
| 864 |
+
ctx.causal,
|
| 865 |
+
ctx.window_size[0],
|
| 866 |
+
ctx.window_size[1],
|
| 867 |
+
ctx.softcap,
|
| 868 |
+
ctx.alibi_slopes,
|
| 869 |
+
ctx.deterministic,
|
| 870 |
+
rng_state=rng_state,
|
| 871 |
+
)
|
| 872 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 873 |
+
dkv = dkv[..., : dout.shape[-1]]
|
| 874 |
+
return (
|
| 875 |
+
dq,
|
| 876 |
+
dkv,
|
| 877 |
+
None,
|
| 878 |
+
None,
|
| 879 |
+
None,
|
| 880 |
+
None,
|
| 881 |
+
None,
|
| 882 |
+
None,
|
| 883 |
+
None,
|
| 884 |
+
None,
|
| 885 |
+
None,
|
| 886 |
+
None,
|
| 887 |
+
None,
|
| 888 |
+
None,
|
| 889 |
+
None,
|
| 890 |
+
)
|
| 891 |
+
|
| 892 |
+
|
| 893 |
+
class FlashAttnFunc(torch.autograd.Function):
|
| 894 |
+
@staticmethod
|
| 895 |
+
def forward(
|
| 896 |
+
ctx,
|
| 897 |
+
q,
|
| 898 |
+
k,
|
| 899 |
+
v,
|
| 900 |
+
dropout_p,
|
| 901 |
+
softmax_scale,
|
| 902 |
+
causal,
|
| 903 |
+
window_size,
|
| 904 |
+
softcap,
|
| 905 |
+
alibi_slopes,
|
| 906 |
+
deterministic,
|
| 907 |
+
return_softmax,
|
| 908 |
+
is_grad_enabled,
|
| 909 |
+
):
|
| 910 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, k, v])
|
| 911 |
+
if softmax_scale is None:
|
| 912 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 913 |
+
head_size_og = q.size(3)
|
| 914 |
+
if head_size_og % 8 != 0:
|
| 915 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 916 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 917 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 918 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_forward(
|
| 919 |
+
q,
|
| 920 |
+
k,
|
| 921 |
+
v,
|
| 922 |
+
dropout_p,
|
| 923 |
+
softmax_scale,
|
| 924 |
+
causal=causal,
|
| 925 |
+
window_size_left=window_size[0],
|
| 926 |
+
window_size_right=window_size[1],
|
| 927 |
+
softcap=softcap,
|
| 928 |
+
alibi_slopes=alibi_slopes,
|
| 929 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 930 |
+
)
|
| 931 |
+
if is_grad:
|
| 932 |
+
ctx.save_for_backward(q, k, v, out_padded, softmax_lse, rng_state)
|
| 933 |
+
ctx.dropout_p = dropout_p
|
| 934 |
+
ctx.softmax_scale = softmax_scale
|
| 935 |
+
ctx.causal = causal
|
| 936 |
+
ctx.window_size = window_size
|
| 937 |
+
ctx.softcap = softcap
|
| 938 |
+
ctx.alibi_slopes = alibi_slopes
|
| 939 |
+
ctx.deterministic = deterministic
|
| 940 |
+
out = out_padded[..., :head_size_og]
|
| 941 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 942 |
+
|
| 943 |
+
@staticmethod
|
| 944 |
+
def backward(ctx, dout, *args):
|
| 945 |
+
q, k, v, out, softmax_lse, rng_state = ctx.saved_tensors
|
| 946 |
+
dq, dk, dv = torch.empty_like(q), torch.empty_like(k), torch.empty_like(v)
|
| 947 |
+
head_size_og = dout.size(3)
|
| 948 |
+
dout_padded = dout
|
| 949 |
+
if head_size_og % 8 != 0:
|
| 950 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 951 |
+
_flash_attn_backward(
|
| 952 |
+
dout_padded,
|
| 953 |
+
q,
|
| 954 |
+
k,
|
| 955 |
+
v,
|
| 956 |
+
out,
|
| 957 |
+
softmax_lse,
|
| 958 |
+
dq,
|
| 959 |
+
dk,
|
| 960 |
+
dv,
|
| 961 |
+
ctx.dropout_p,
|
| 962 |
+
ctx.softmax_scale,
|
| 963 |
+
ctx.causal,
|
| 964 |
+
ctx.window_size[0],
|
| 965 |
+
ctx.window_size[1],
|
| 966 |
+
ctx.softcap,
|
| 967 |
+
ctx.alibi_slopes,
|
| 968 |
+
ctx.deterministic,
|
| 969 |
+
rng_state=rng_state,
|
| 970 |
+
)
|
| 971 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 972 |
+
dk = dk[..., : dout.shape[-1]]
|
| 973 |
+
dv = dv[..., : dout.shape[-1]]
|
| 974 |
+
return dq, dk, dv, None, None, None, None, None, None, None, None, None
|
| 975 |
+
|
| 976 |
+
|
| 977 |
+
class FlashAttnVarlenFunc(torch.autograd.Function):
|
| 978 |
+
@staticmethod
|
| 979 |
+
def forward(
|
| 980 |
+
ctx,
|
| 981 |
+
q,
|
| 982 |
+
k,
|
| 983 |
+
v,
|
| 984 |
+
cu_seqlens_q,
|
| 985 |
+
cu_seqlens_k,
|
| 986 |
+
max_seqlen_q,
|
| 987 |
+
max_seqlen_k,
|
| 988 |
+
dropout_p,
|
| 989 |
+
softmax_scale,
|
| 990 |
+
causal,
|
| 991 |
+
window_size,
|
| 992 |
+
softcap,
|
| 993 |
+
alibi_slopes,
|
| 994 |
+
deterministic,
|
| 995 |
+
return_softmax,
|
| 996 |
+
block_table,
|
| 997 |
+
is_grad_enabled,
|
| 998 |
+
):
|
| 999 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, k, v])
|
| 1000 |
+
if softmax_scale is None:
|
| 1001 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 1002 |
+
head_size_og = q.size(2)
|
| 1003 |
+
if head_size_og % 8 != 0:
|
| 1004 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 1005 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 1006 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 1007 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_varlen_forward(
|
| 1008 |
+
q,
|
| 1009 |
+
k,
|
| 1010 |
+
v,
|
| 1011 |
+
cu_seqlens_q,
|
| 1012 |
+
cu_seqlens_k,
|
| 1013 |
+
max_seqlen_q,
|
| 1014 |
+
max_seqlen_k,
|
| 1015 |
+
dropout_p,
|
| 1016 |
+
softmax_scale,
|
| 1017 |
+
causal=causal,
|
| 1018 |
+
window_size_left=window_size[0],
|
| 1019 |
+
window_size_right=window_size[1],
|
| 1020 |
+
softcap=softcap,
|
| 1021 |
+
alibi_slopes=alibi_slopes,
|
| 1022 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 1023 |
+
block_table=block_table,
|
| 1024 |
+
)
|
| 1025 |
+
if is_grad:
|
| 1026 |
+
ctx.save_for_backward(
|
| 1027 |
+
q, k, v, out_padded, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state
|
| 1028 |
+
)
|
| 1029 |
+
ctx.dropout_p = dropout_p
|
| 1030 |
+
ctx.max_seqlen_q = max_seqlen_q
|
| 1031 |
+
ctx.max_seqlen_k = max_seqlen_k
|
| 1032 |
+
ctx.softmax_scale = softmax_scale
|
| 1033 |
+
ctx.causal = causal
|
| 1034 |
+
ctx.window_size = window_size
|
| 1035 |
+
ctx.softcap = softcap
|
| 1036 |
+
ctx.alibi_slopes = alibi_slopes
|
| 1037 |
+
ctx.deterministic = deterministic
|
| 1038 |
+
|
| 1039 |
+
out = out_padded[..., :head_size_og]
|
| 1040 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 1041 |
+
|
| 1042 |
+
@staticmethod
|
| 1043 |
+
def backward(ctx, dout, *args):
|
| 1044 |
+
q, k, v, out, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state = (
|
| 1045 |
+
ctx.saved_tensors
|
| 1046 |
+
)
|
| 1047 |
+
dq, dk, dv = torch.empty_like(q), torch.empty_like(k), torch.empty_like(v)
|
| 1048 |
+
head_size_og = dout.size(2)
|
| 1049 |
+
dout_padded = dout
|
| 1050 |
+
if head_size_og % 8 != 0:
|
| 1051 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 1052 |
+
_flash_attn_varlen_backward(
|
| 1053 |
+
dout_padded,
|
| 1054 |
+
q,
|
| 1055 |
+
k,
|
| 1056 |
+
v,
|
| 1057 |
+
out,
|
| 1058 |
+
softmax_lse,
|
| 1059 |
+
dq,
|
| 1060 |
+
dk,
|
| 1061 |
+
dv,
|
| 1062 |
+
cu_seqlens_q,
|
| 1063 |
+
cu_seqlens_k,
|
| 1064 |
+
ctx.max_seqlen_q,
|
| 1065 |
+
ctx.max_seqlen_k,
|
| 1066 |
+
ctx.dropout_p,
|
| 1067 |
+
ctx.softmax_scale,
|
| 1068 |
+
ctx.causal,
|
| 1069 |
+
ctx.window_size[0],
|
| 1070 |
+
ctx.window_size[1],
|
| 1071 |
+
ctx.softcap,
|
| 1072 |
+
ctx.alibi_slopes,
|
| 1073 |
+
ctx.deterministic,
|
| 1074 |
+
rng_state=rng_state,
|
| 1075 |
+
)
|
| 1076 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 1077 |
+
dk = dk[..., : dout.shape[-1]]
|
| 1078 |
+
dv = dv[..., : dout.shape[-1]]
|
| 1079 |
+
return (
|
| 1080 |
+
dq,
|
| 1081 |
+
dk,
|
| 1082 |
+
dv,
|
| 1083 |
+
None,
|
| 1084 |
+
None,
|
| 1085 |
+
None,
|
| 1086 |
+
None,
|
| 1087 |
+
None,
|
| 1088 |
+
None,
|
| 1089 |
+
None,
|
| 1090 |
+
None,
|
| 1091 |
+
None,
|
| 1092 |
+
None,
|
| 1093 |
+
None,
|
| 1094 |
+
None,
|
| 1095 |
+
None,
|
| 1096 |
+
None,
|
| 1097 |
+
)
|
| 1098 |
+
|
| 1099 |
+
|
| 1100 |
+
def flash_attn_qkvpacked_func(
|
| 1101 |
+
qkv,
|
| 1102 |
+
dropout_p=0.0,
|
| 1103 |
+
softmax_scale=None,
|
| 1104 |
+
causal=False,
|
| 1105 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1106 |
+
softcap=0.0, # <=0.0 means deactivate
|
| 1107 |
+
alibi_slopes=None,
|
| 1108 |
+
deterministic=False,
|
| 1109 |
+
return_attn_probs=False,
|
| 1110 |
+
):
|
| 1111 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1112 |
+
If Q, K, V are already stacked into 1 tensor, this function will be faster than
|
| 1113 |
+
calling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1114 |
+
of the gradients of Q, K, V.
|
| 1115 |
+
For multi-query and grouped-query attention (MQA/GQA), please see
|
| 1116 |
+
flash_attn_kvpacked_func and flash_attn_func.
|
| 1117 |
+
|
| 1118 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1119 |
+
will only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.
|
| 1120 |
+
|
| 1121 |
+
Arguments:
|
| 1122 |
+
qkv: (batch_size, seqlen, 3, nheads, headdim)
|
| 1123 |
+
dropout_p: float. Dropout probability.
|
| 1124 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1125 |
+
Default to 1 / sqrt(headdim).
|
| 1126 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1127 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1128 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1129 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|) is added to
|
| 1130 |
+
the attention score of query i and key j.
|
| 1131 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1132 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1133 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1134 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1135 |
+
(they might not have the right scaling).
|
| 1136 |
+
Return:
|
| 1137 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1138 |
+
softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The
|
| 1139 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1140 |
+
normalization factor).
|
| 1141 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1142 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1143 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1144 |
+
"""
|
| 1145 |
+
return FlashAttnQKVPackedFunc.apply(
|
| 1146 |
+
qkv,
|
| 1147 |
+
dropout_p,
|
| 1148 |
+
softmax_scale,
|
| 1149 |
+
causal,
|
| 1150 |
+
window_size,
|
| 1151 |
+
softcap,
|
| 1152 |
+
alibi_slopes,
|
| 1153 |
+
deterministic,
|
| 1154 |
+
return_attn_probs,
|
| 1155 |
+
torch.is_grad_enabled(),
|
| 1156 |
+
)
|
| 1157 |
+
|
| 1158 |
+
|
| 1159 |
+
def flash_attn_kvpacked_func(
|
| 1160 |
+
q,
|
| 1161 |
+
kv,
|
| 1162 |
+
dropout_p=0.0,
|
| 1163 |
+
softmax_scale=None,
|
| 1164 |
+
causal=False,
|
| 1165 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1166 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1167 |
+
alibi_slopes=None,
|
| 1168 |
+
deterministic=False,
|
| 1169 |
+
return_attn_probs=False,
|
| 1170 |
+
):
|
| 1171 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1172 |
+
If K, V are already stacked into 1 tensor, this function will be faster than
|
| 1173 |
+
calling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1174 |
+
of the gradients of K, V.
|
| 1175 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1176 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1177 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1178 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1179 |
+
|
| 1180 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1181 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1182 |
+
1 1 1 1 0
|
| 1183 |
+
1 1 1 1 1
|
| 1184 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1185 |
+
0 0
|
| 1186 |
+
0 0
|
| 1187 |
+
0 0
|
| 1188 |
+
1 0
|
| 1189 |
+
1 1
|
| 1190 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1191 |
+
|
| 1192 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1193 |
+
will only attend to keys between
|
| 1194 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1195 |
+
|
| 1196 |
+
Arguments:
|
| 1197 |
+
q: (batch_size, seqlen, nheads, headdim)
|
| 1198 |
+
kv: (batch_size, seqlen, 2, nheads_k, headdim)
|
| 1199 |
+
dropout_p: float. Dropout probability.
|
| 1200 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1201 |
+
Default to 1 / sqrt(headdim).
|
| 1202 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1203 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1204 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1205 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1206 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1207 |
+
is added to the attention score of query i and key j.
|
| 1208 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1209 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1210 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1211 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1212 |
+
(they might not have the right scaling).
|
| 1213 |
+
Return:
|
| 1214 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1215 |
+
softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The
|
| 1216 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1217 |
+
normalization factor).
|
| 1218 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1219 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1220 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1221 |
+
"""
|
| 1222 |
+
return FlashAttnKVPackedFunc.apply(
|
| 1223 |
+
q,
|
| 1224 |
+
kv,
|
| 1225 |
+
dropout_p,
|
| 1226 |
+
softmax_scale,
|
| 1227 |
+
causal,
|
| 1228 |
+
window_size,
|
| 1229 |
+
softcap,
|
| 1230 |
+
alibi_slopes,
|
| 1231 |
+
deterministic,
|
| 1232 |
+
return_attn_probs,
|
| 1233 |
+
torch.is_grad_enabled(),
|
| 1234 |
+
)
|
| 1235 |
+
|
| 1236 |
+
|
| 1237 |
+
def flash_attn_func(
|
| 1238 |
+
q,
|
| 1239 |
+
k,
|
| 1240 |
+
v,
|
| 1241 |
+
dropout_p=0.0,
|
| 1242 |
+
softmax_scale=None,
|
| 1243 |
+
causal=False,
|
| 1244 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1245 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1246 |
+
alibi_slopes=None,
|
| 1247 |
+
deterministic=False,
|
| 1248 |
+
return_attn_probs=False,
|
| 1249 |
+
):
|
| 1250 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1251 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1252 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1253 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1254 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1255 |
+
|
| 1256 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1257 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1258 |
+
1 1 1 1 0
|
| 1259 |
+
1 1 1 1 1
|
| 1260 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1261 |
+
0 0
|
| 1262 |
+
0 0
|
| 1263 |
+
0 0
|
| 1264 |
+
1 0
|
| 1265 |
+
1 1
|
| 1266 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1267 |
+
|
| 1268 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1269 |
+
will only attend to keys between
|
| 1270 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1271 |
+
|
| 1272 |
+
Arguments:
|
| 1273 |
+
q: (batch_size, seqlen, nheads, headdim)
|
| 1274 |
+
k: (batch_size, seqlen, nheads_k, headdim)
|
| 1275 |
+
v: (batch_size, seqlen, nheads_k, headdim)
|
| 1276 |
+
dropout_p: float. Dropout probability.
|
| 1277 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1278 |
+
Default to 1 / sqrt(headdim).
|
| 1279 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1280 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1281 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1282 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1283 |
+
is added to the attention score of query i and key j.
|
| 1284 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1285 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1286 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1287 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1288 |
+
(they might not have the right scaling).
|
| 1289 |
+
Return:
|
| 1290 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1291 |
+
softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The
|
| 1292 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1293 |
+
normalization factor).
|
| 1294 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1295 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1296 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1297 |
+
"""
|
| 1298 |
+
return FlashAttnFunc.apply(
|
| 1299 |
+
q,
|
| 1300 |
+
k,
|
| 1301 |
+
v,
|
| 1302 |
+
dropout_p,
|
| 1303 |
+
softmax_scale,
|
| 1304 |
+
causal,
|
| 1305 |
+
window_size,
|
| 1306 |
+
softcap,
|
| 1307 |
+
alibi_slopes,
|
| 1308 |
+
deterministic,
|
| 1309 |
+
return_attn_probs,
|
| 1310 |
+
torch.is_grad_enabled(),
|
| 1311 |
+
)
|
| 1312 |
+
|
| 1313 |
+
|
| 1314 |
+
def flash_attn_varlen_qkvpacked_func(
|
| 1315 |
+
qkv,
|
| 1316 |
+
cu_seqlens,
|
| 1317 |
+
max_seqlen,
|
| 1318 |
+
dropout_p=0.0,
|
| 1319 |
+
softmax_scale=None,
|
| 1320 |
+
causal=False,
|
| 1321 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1322 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1323 |
+
alibi_slopes=None,
|
| 1324 |
+
deterministic=False,
|
| 1325 |
+
return_attn_probs=False,
|
| 1326 |
+
):
|
| 1327 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1328 |
+
If Q, K, V are already stacked into 1 tensor, this function will be faster than
|
| 1329 |
+
calling flash_attn_varlen_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1330 |
+
of the gradients of Q, K, V.
|
| 1331 |
+
For multi-query and grouped-query attention (MQA/GQA), please see
|
| 1332 |
+
flash_attn_varlen_kvpacked_func and flash_attn_varlen_func.
|
| 1333 |
+
|
| 1334 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1335 |
+
will only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.
|
| 1336 |
+
|
| 1337 |
+
Arguments:
|
| 1338 |
+
qkv: (total, 3, nheads, headdim), where total = total number of tokens in the batch.
|
| 1339 |
+
cu_seqlens: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1340 |
+
of the sequences in the batch, used to index into qkv.
|
| 1341 |
+
max_seqlen: int. Maximum sequence length in the batch.
|
| 1342 |
+
dropout_p: float. Dropout probability.
|
| 1343 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1344 |
+
Default to 1 / sqrt(headdim).
|
| 1345 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1346 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1347 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1348 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|)
|
| 1349 |
+
is added to the attention score of query i and key j.
|
| 1350 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1351 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1352 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1353 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1354 |
+
(they might not have the right scaling).
|
| 1355 |
+
Return:
|
| 1356 |
+
out: (total, nheads, headdim).
|
| 1357 |
+
softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The
|
| 1358 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1359 |
+
normalization factor).
|
| 1360 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1361 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1362 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1363 |
+
"""
|
| 1364 |
+
return FlashAttnVarlenQKVPackedFunc.apply(
|
| 1365 |
+
qkv,
|
| 1366 |
+
cu_seqlens,
|
| 1367 |
+
max_seqlen,
|
| 1368 |
+
dropout_p,
|
| 1369 |
+
softmax_scale,
|
| 1370 |
+
causal,
|
| 1371 |
+
window_size,
|
| 1372 |
+
softcap,
|
| 1373 |
+
alibi_slopes,
|
| 1374 |
+
deterministic,
|
| 1375 |
+
return_attn_probs,
|
| 1376 |
+
torch.is_grad_enabled(),
|
| 1377 |
+
)
|
| 1378 |
+
|
| 1379 |
+
|
| 1380 |
+
def flash_attn_varlen_kvpacked_func(
|
| 1381 |
+
q,
|
| 1382 |
+
kv,
|
| 1383 |
+
cu_seqlens_q,
|
| 1384 |
+
cu_seqlens_k,
|
| 1385 |
+
max_seqlen_q,
|
| 1386 |
+
max_seqlen_k,
|
| 1387 |
+
dropout_p=0.0,
|
| 1388 |
+
softmax_scale=None,
|
| 1389 |
+
causal=False,
|
| 1390 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1391 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1392 |
+
alibi_slopes=None,
|
| 1393 |
+
deterministic=False,
|
| 1394 |
+
return_attn_probs=False,
|
| 1395 |
+
):
|
| 1396 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1397 |
+
If K, V are already stacked into 1 tensor, this function will be faster than
|
| 1398 |
+
calling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1399 |
+
of the gradients of K, V.
|
| 1400 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1401 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1402 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1403 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1404 |
+
|
| 1405 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1406 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1407 |
+
1 1 1 1 0
|
| 1408 |
+
1 1 1 1 1
|
| 1409 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1410 |
+
0 0
|
| 1411 |
+
0 0
|
| 1412 |
+
0 0
|
| 1413 |
+
1 0
|
| 1414 |
+
1 1
|
| 1415 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1416 |
+
|
| 1417 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1418 |
+
will only attend to keys between
|
| 1419 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1420 |
+
|
| 1421 |
+
Arguments:
|
| 1422 |
+
q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.
|
| 1423 |
+
kv: (total_k, 2, nheads_k, headdim), where total_k = total number of key tokens in the batch.
|
| 1424 |
+
cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1425 |
+
of the sequences in the batch, used to index into q.
|
| 1426 |
+
cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1427 |
+
of the sequences in the batch, used to index into kv.
|
| 1428 |
+
max_seqlen_q: int. Maximum query sequence length in the batch.
|
| 1429 |
+
max_seqlen_k: int. Maximum key sequence length in the batch.
|
| 1430 |
+
dropout_p: float. Dropout probability.
|
| 1431 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1432 |
+
Default to 1 / sqrt(headdim).
|
| 1433 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1434 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1435 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1436 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1437 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1438 |
+
is added to the attention score of query i and key j.
|
| 1439 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1440 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1441 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1442 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1443 |
+
(they might not have the right scaling).
|
| 1444 |
+
Return:
|
| 1445 |
+
out: (total, nheads, headdim).
|
| 1446 |
+
softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The
|
| 1447 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1448 |
+
normalization factor).
|
| 1449 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1450 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1451 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1452 |
+
"""
|
| 1453 |
+
return FlashAttnVarlenKVPackedFunc.apply(
|
| 1454 |
+
q,
|
| 1455 |
+
kv,
|
| 1456 |
+
cu_seqlens_q,
|
| 1457 |
+
cu_seqlens_k,
|
| 1458 |
+
max_seqlen_q,
|
| 1459 |
+
max_seqlen_k,
|
| 1460 |
+
dropout_p,
|
| 1461 |
+
softmax_scale,
|
| 1462 |
+
causal,
|
| 1463 |
+
window_size,
|
| 1464 |
+
softcap,
|
| 1465 |
+
alibi_slopes,
|
| 1466 |
+
deterministic,
|
| 1467 |
+
return_attn_probs,
|
| 1468 |
+
torch.is_grad_enabled(),
|
| 1469 |
+
)
|
| 1470 |
+
|
| 1471 |
+
|
| 1472 |
+
def flash_attn_varlen_func(
|
| 1473 |
+
q,
|
| 1474 |
+
k,
|
| 1475 |
+
v,
|
| 1476 |
+
cu_seqlens_q,
|
| 1477 |
+
cu_seqlens_k,
|
| 1478 |
+
max_seqlen_q,
|
| 1479 |
+
max_seqlen_k,
|
| 1480 |
+
dropout_p=0.0,
|
| 1481 |
+
softmax_scale=None,
|
| 1482 |
+
causal=False,
|
| 1483 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1484 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1485 |
+
alibi_slopes=None,
|
| 1486 |
+
deterministic=False,
|
| 1487 |
+
return_attn_probs=False,
|
| 1488 |
+
block_table=None,
|
| 1489 |
+
):
|
| 1490 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1491 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in K, V with fewer heads
|
| 1492 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1493 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1494 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1495 |
+
|
| 1496 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1497 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1498 |
+
1 1 1 1 0
|
| 1499 |
+
1 1 1 1 1
|
| 1500 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1501 |
+
0 0
|
| 1502 |
+
0 0
|
| 1503 |
+
0 0
|
| 1504 |
+
1 0
|
| 1505 |
+
1 1
|
| 1506 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1507 |
+
|
| 1508 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1509 |
+
will only attend to keys between
|
| 1510 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1511 |
+
|
| 1512 |
+
Arguments:
|
| 1513 |
+
q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.
|
| 1514 |
+
k: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.
|
| 1515 |
+
v: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.
|
| 1516 |
+
cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1517 |
+
of the sequences in the batch, used to index into q.
|
| 1518 |
+
cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1519 |
+
of the sequences in the batch, used to index into kv.
|
| 1520 |
+
max_seqlen_q: int. Maximum query sequence length in the batch.
|
| 1521 |
+
max_seqlen_k: int. Maximum key sequence length in the batch.
|
| 1522 |
+
dropout_p: float. Dropout probability.
|
| 1523 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1524 |
+
Default to 1 / sqrt(headdim).
|
| 1525 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1526 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1527 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1528 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1529 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1530 |
+
is added to the attention score of query i and key j.
|
| 1531 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1532 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1533 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1534 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1535 |
+
(they might not have the right scaling).
|
| 1536 |
+
Return:
|
| 1537 |
+
out: (total, nheads, headdim).
|
| 1538 |
+
softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The
|
| 1539 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1540 |
+
normalization factor).
|
| 1541 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1542 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1543 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1544 |
+
"""
|
| 1545 |
+
return FlashAttnVarlenFunc.apply(
|
| 1546 |
+
q,
|
| 1547 |
+
k,
|
| 1548 |
+
v,
|
| 1549 |
+
cu_seqlens_q,
|
| 1550 |
+
cu_seqlens_k,
|
| 1551 |
+
max_seqlen_q,
|
| 1552 |
+
max_seqlen_k,
|
| 1553 |
+
dropout_p,
|
| 1554 |
+
softmax_scale,
|
| 1555 |
+
causal,
|
| 1556 |
+
window_size,
|
| 1557 |
+
softcap,
|
| 1558 |
+
alibi_slopes,
|
| 1559 |
+
deterministic,
|
| 1560 |
+
return_attn_probs,
|
| 1561 |
+
block_table,
|
| 1562 |
+
False if q.device.type == "cpu" else torch.is_grad_enabled(),
|
| 1563 |
+
)
|
| 1564 |
+
|
| 1565 |
+
|
| 1566 |
+
def flash_attn_with_kvcache(
|
| 1567 |
+
q,
|
| 1568 |
+
k_cache,
|
| 1569 |
+
v_cache,
|
| 1570 |
+
k=None,
|
| 1571 |
+
v=None,
|
| 1572 |
+
rotary_cos=None,
|
| 1573 |
+
rotary_sin=None,
|
| 1574 |
+
cache_seqlens: Optional[Union[(int, torch.Tensor)]] = None,
|
| 1575 |
+
cache_batch_idx: Optional[torch.Tensor] = None,
|
| 1576 |
+
cache_leftpad: Optional[torch.Tensor] = None,
|
| 1577 |
+
block_table: Optional[torch.Tensor] = None,
|
| 1578 |
+
softmax_scale=None,
|
| 1579 |
+
causal=False,
|
| 1580 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1581 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1582 |
+
rotary_interleaved=True,
|
| 1583 |
+
alibi_slopes=None,
|
| 1584 |
+
num_splits=0,
|
| 1585 |
+
return_softmax_lse=False,
|
| 1586 |
+
):
|
| 1587 |
+
"""
|
| 1588 |
+
If k and v are not None, k_cache and v_cache will be updated *inplace* with the new values from
|
| 1589 |
+
k and v. This is useful for incremental decoding: you can pass in the cached keys/values from
|
| 1590 |
+
the previous step, and update them with the new keys/values from the current step, and do
|
| 1591 |
+
attention with the updated cache, all in 1 kernel.
|
| 1592 |
+
|
| 1593 |
+
If you pass in k / v, you must make sure that the cache is large enough to hold the new values.
|
| 1594 |
+
For example, the KV cache could be pre-allocated with the max sequence length, and you can use
|
| 1595 |
+
cache_seqlens to keep track of the current sequence lengths of each sequence in the batch.
|
| 1596 |
+
|
| 1597 |
+
Also apply rotary embedding if rotary_cos and rotary_sin are passed in. The key @k will be
|
| 1598 |
+
rotated by rotary_cos and rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.
|
| 1599 |
+
If causal or local (i.e., window_size != (-1, -1)), the query @q will be rotated by rotary_cos
|
| 1600 |
+
and rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.
|
| 1601 |
+
If not causal and not local, the query @q will be rotated by rotary_cos and rotary_sin at
|
| 1602 |
+
indices cache_seqlens only (i.e. we consider all tokens in @q to be at position cache_seqlens).
|
| 1603 |
+
|
| 1604 |
+
See tests/test_flash_attn.py::test_flash_attn_kvcache for examples of how to use this function.
|
| 1605 |
+
|
| 1606 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1607 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1608 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1609 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1610 |
+
|
| 1611 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1612 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1613 |
+
1 1 1 1 0
|
| 1614 |
+
1 1 1 1 1
|
| 1615 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1616 |
+
0 0
|
| 1617 |
+
0 0
|
| 1618 |
+
0 0
|
| 1619 |
+
1 0
|
| 1620 |
+
1 1
|
| 1621 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1622 |
+
|
| 1623 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1624 |
+
will only attend to keys between
|
| 1625 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1626 |
+
|
| 1627 |
+
Note: Does not support backward pass.
|
| 1628 |
+
|
| 1629 |
+
Arguments:
|
| 1630 |
+
q: (batch_size, seqlen, nheads, headdim)
|
| 1631 |
+
k_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,
|
| 1632 |
+
or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)
|
| 1633 |
+
page_block_size must be a multiple of 256.
|
| 1634 |
+
v_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,
|
| 1635 |
+
or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)
|
| 1636 |
+
k [optional]: (batch_size, seqlen_new, nheads_k, headdim). If not None, we concatenate
|
| 1637 |
+
k with k_cache, starting at the indices specified by cache_seqlens.
|
| 1638 |
+
v [optional]: (batch_size, seqlen_new, nheads_k, headdim). Similar to k.
|
| 1639 |
+
rotary_cos [optional]: (seqlen_ro, rotary_dim / 2). If not None, we apply rotary embedding
|
| 1640 |
+
to k and q. Only applicable if k and v are passed in. rotary_dim must be divisible by 16.
|
| 1641 |
+
rotary_sin [optional]: (seqlen_ro, rotary_dim / 2). Similar to rotary_cos.
|
| 1642 |
+
cache_seqlens: int, or (batch_size,), dtype torch.int32. The sequence lengths of the
|
| 1643 |
+
KV cache.
|
| 1644 |
+
cache_batch_idx: (batch_size,), dtype torch.int32. The indices used to index into the KV cache.
|
| 1645 |
+
If None, we assume that the batch indices are [0, 1, 2, ..., batch_size - 1].
|
| 1646 |
+
If the indices are not distinct, and k and v are provided, the values updated in the cache
|
| 1647 |
+
might come from any of the duplicate indices.
|
| 1648 |
+
cache_leftpad: (batch_size,), dtype torch.int32. The index that the KV cache starts. If None, assume 0.
|
| 1649 |
+
block_table [optional]: (batch_size, max_num_blocks_per_seq), dtype torch.int32.
|
| 1650 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1651 |
+
Default to 1 / sqrt(headdim).
|
| 1652 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1653 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1654 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1655 |
+
rotary_interleaved: bool. Only applicable if rotary_cos and rotary_sin are passed in.
|
| 1656 |
+
If True, rotary embedding will combine dimensions 0 & 1, 2 & 3, etc. If False,
|
| 1657 |
+
rotary embedding will combine dimensions 0 & rotary_dim / 2, 1 & rotary_dim / 2 + 1
|
| 1658 |
+
(i.e. GPT-NeoX style).
|
| 1659 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1660 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1661 |
+
is added to the attention score of query i and key j.
|
| 1662 |
+
num_splits: int. If > 1, split the key/value into this many chunks along the sequence.
|
| 1663 |
+
If num_splits == 1, we don't split the key/value. If num_splits == 0, we use a heuristic
|
| 1664 |
+
to automatically determine the number of splits.
|
| 1665 |
+
Don't change this unless you know what you are doing.
|
| 1666 |
+
return_softmax_lse: bool. Whether to return the logsumexp of the attention scores.
|
| 1667 |
+
|
| 1668 |
+
Return:
|
| 1669 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1670 |
+
softmax_lse [optional, if return_softmax_lse=True]: (batch_size, nheads, seqlen). The
|
| 1671 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1672 |
+
normalization factor).
|
| 1673 |
+
"""
|
| 1674 |
+
assert k_cache.stride(-1) == 1, "k_cache must have contiguous last dimension"
|
| 1675 |
+
assert v_cache.stride(-1) == 1, "v_cache must have contiguous last dimension"
|
| 1676 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 1677 |
+
if softmax_scale is None:
|
| 1678 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 1679 |
+
if cache_seqlens is not None and isinstance(cache_seqlens, int):
|
| 1680 |
+
cache_seqlens = torch.full(
|
| 1681 |
+
(k_cache.shape[0],), cache_seqlens, dtype=torch.int32, device=k_cache.device
|
| 1682 |
+
)
|
| 1683 |
+
cache_seqlens = maybe_contiguous(cache_seqlens)
|
| 1684 |
+
cache_batch_idx = maybe_contiguous(cache_batch_idx)
|
| 1685 |
+
block_table = maybe_contiguous(block_table)
|
| 1686 |
+
out, softmax_lse = flash_attn.fwd_kvcache(
|
| 1687 |
+
q,
|
| 1688 |
+
k_cache,
|
| 1689 |
+
v_cache,
|
| 1690 |
+
k,
|
| 1691 |
+
v,
|
| 1692 |
+
cache_seqlens,
|
| 1693 |
+
rotary_cos,
|
| 1694 |
+
rotary_sin,
|
| 1695 |
+
cache_batch_idx,
|
| 1696 |
+
cache_leftpad,
|
| 1697 |
+
block_table,
|
| 1698 |
+
alibi_slopes,
|
| 1699 |
+
None,
|
| 1700 |
+
softmax_scale,
|
| 1701 |
+
causal,
|
| 1702 |
+
window_size[0],
|
| 1703 |
+
window_size[1],
|
| 1704 |
+
softcap,
|
| 1705 |
+
rotary_interleaved,
|
| 1706 |
+
num_splits,
|
| 1707 |
+
)
|
| 1708 |
+
return (out, softmax_lse) if return_softmax_lse else out
|
build/torch-stable-abi210-cu128-aarch64-linux/metadata.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "flash-attn2",
|
| 3 |
+
"id": "_flash_attn2_cuda_460047c",
|
| 4 |
+
"version": 4,
|
| 5 |
+
"kernels-minver": "0.14.0",
|
| 6 |
+
"license": "BSD-3-Clause",
|
| 7 |
+
"python-depends": [],
|
| 8 |
+
"kernel-depends": [],
|
| 9 |
+
"backend": {
|
| 10 |
+
"type": "cuda",
|
| 11 |
+
"archs": [
|
| 12 |
+
"10.0",
|
| 13 |
+
"12.0",
|
| 14 |
+
"8.0",
|
| 15 |
+
"9.0"
|
| 16 |
+
]
|
| 17 |
+
},
|
| 18 |
+
"digest": {
|
| 19 |
+
"algorithm": "sha256",
|
| 20 |
+
"files": {
|
| 21 |
+
"__init__.py": "Nz8hqrusjoUHQqszpxfF2USMwUXn1VfpvcmtAAvutSM=",
|
| 22 |
+
"_flash_attn2_cuda_460047c.abi3.so": "y2DTM0Gg8SYvoR2RnAd2OYZR4yfN/rfSH608Kur4UTs=",
|
| 23 |
+
"_ops.py": "DV4Eo4+s3aaNmDsfXoZiYKNLnRUJqlsdDGlMsdKFgk4=",
|
| 24 |
+
"flash_attn_interface.py": "6UYUhfUax4+yOUygyS7K8dVjrIjU5GQr1AJ2gSp8rPo=",
|
| 25 |
+
"symbols.json": "uvC+87tHUhtHv7L/Nl53T/Ms7ceX317/jwQBoqHY14A="
|
| 26 |
+
}
|
| 27 |
+
},
|
| 28 |
+
"provenance": {
|
| 29 |
+
"kernel-builder": {
|
| 30 |
+
"version": "0.18.0-dev0",
|
| 31 |
+
"commit": "d054906a13710b811b96697b4635f03020842733",
|
| 32 |
+
"dirty": false
|
| 33 |
+
},
|
| 34 |
+
"kernel": {
|
| 35 |
+
"commit": "460047c291fc7f0b3dbd4239b46bd5e1281b1806",
|
| 36 |
+
"dirty": false
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
}
|
build/torch-stable-abi210-cu128-aarch64-linux/metadata.json.sigstore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"mediaType":"application/vnd.dev.sigstore.bundle.v0.3+json","verificationMaterial":{"certificate":{"rawBytes":"MIIHKzCCBrGgAwIBAgIUGbk1nmy8ZtAxTYtkF97vt1SsF5wwCgYIKoZIzj0EAwMwNzEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MR4wHAYDVQQDExVzaWdzdG9yZS1pbnRlcm1lZGlhdGUwHhcNMjYxMDI0MDAwNzQ4WhcNMjYxMDI0MDAxNzQ4WjAAMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE4WV6kHnDLUJYxjhxaSnJwr6NG2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7zOdkI0fVHPXEw19zksIee8Evng7rIfy8H48SPQboIo0hpmOnEhD"},"tlogEntries":[{"logIndex":"3430231150","logId":{"keyId":"wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="},"kindVersion":{"kind":"hashedrekord","version":"0.0.1"},"integratedTime":"1792800468","inclusionPromise":{"signedEntryTimestamp":"MEQCIGZLwd3J3l3V5DJXhWg+9EGadjCvaCWzPMsUG93F6kNJAiAP+kvJFeyEBb1JoFaYPSRaVko7A3De8lLTG9MmgfItug=="},"inclusionProof":{"logIndex":"3308326888","rootHash":"0dxDHKHJJNB18GUn1mFkbYi+mmMHAiKBJZiSnPoSq0M=","treeSize":"3308327082","hashes":["tEmdr9KY4X4wGUqr7YjGpLBDSzBdktM+iTNHlN/KVnI=","28a1JPd0NfARI9ataGIjKR2HImyILikAgZQlo9g3gR0=","HPdmEIkQK6TAzqM3AhOjMT2pV8lJmiBdHB4ecJvoH3c=","1oNpBskEERK7M/2IelxCy6dVBEIOAlrvMrekGwOEIhQ=","4ihQi/htRBQaP0gx9I9zFdpjlhs98HBFIi6y7MxxGEs=","fhi0wkcZ9wIt9C3ZoYSTiwPoztVF0FoG/M0C7cRQIjs=","/NfyecAkSIGEAZki6MTEL1vFqGHHJqwpejFj36u/6W8=","rIuKGGpr2xHVfYpBBBRmjjC1BSLVSY7CUZBWo+YwVe4=","D4KiQ6dLka04xW5SItSpf6u70l4OLIJY9TGL3Vgb7J4=","JHbO9SM0uiPdIUJoCFWlrHv/QNK/f6UMlwBq/6914+w=","PuwdRME/93l6s2BMRjCojmjsVC29KnBqdtPSPE1l6cQ=","tWdxtMrYqmZ0zKHnOCAERPP7SvuDvubtw3jwj7rH4uA=","kM+kX6uNUuDAQM/IB5IDAgZEYbCs+QGUBYxh34/qyC4=","8x0N/oAmvpY+6DQUGTU+i6a1Cuqphro2WbV5WZ/RHL8=","DMchGrSAeKV9qHo75XJV3UFZ/CHF8zofPRu+NgVRwA4=","V6dXjeDcwYxBG/9gVSBM8rYdPrAqGpZsf1e7v6l67GA=","iDfImp65w8dirRfYGNgFA34JTUYDWbcJwNBBU/Ok+X4=","YYCr61A8azar3dfO8Ct+pri7LqDxkUlUkfs7fiqYErU=","1DaDKzrCNNBhmSdY5vFjz+NpAmxmYfYEgBCdPLrMP1A=","xH/DCseLHr9eKoYT8qsORZK7zVdEGYWHuVtsVrD95wY="],"checkpoint":{"envelope":"rekor.sigstore.dev - 1193050959916656506\n3308327082\n0dxDHKHJJNB18GUn1mFkbYi+mmMHAiKBJZiSnPoSq0M=\n\n— rekor.sigstore.dev wNI9ajBFAiBW2C60YRvrM9xE+1c/VFt32boXOn4+Am6CokqDb2PTJAIhALsoOhB00Myr6SMsAdAtJZkX1K3OPOb9DU6y/28bhshI\n"}},"canonicalizedBody":"eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoiaGFzaGVkcmVrb3JkIiwic3BlYyI6eyJkYXRhIjp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiJjNjRiNmQxNWQ4NWNkZTQ5YzJmMjQ1NTJiMmNiN2MyY2QyNWE3MTE5ZDlkOTRjOTg5OTQzMWNkOTQxNWRlNzFjIn19LCJzaWduYXR1cmUiOnsiY29udGVudCI6Ik1FVUNJUUQ4aGFKZnFUSXkrSVVuRWxaK3NiM0tNWFRkUUF0OVF3K3grNENTOXI0MklBSWdFbXZlalF2dXBEVjd1UzFsYjNhUWxkcE9HNG5VeElmMmFIc0F6MlZOd0NVPSIsInB1YmxpY0tleSI6eyJjb250ZW50IjoiTFMwdExTMUNSVWRKVGlCRFJWSlVTVVpKUTBGVVJTMHRMUzB0Q2sxSlNVaExla05EUW5KSFowRjNTVUpCWjBsVlIySnJNVzV0ZVRoYWRFRjRWRmwwYTBZNU4zWjBNVk56UmpWM2QwTm5XVWxMYjFwSmVtb3dSVUYzVFhjS1RucEZWazFDVFVkQk1WVkZRMmhOVFdNeWJHNWpNMUoyWTIxV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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema_version": 1,
|
| 3 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 4 |
+
"functions": [
|
| 5 |
+
{
|
| 6 |
+
"name": "flash_attn_func",
|
| 7 |
+
"qualname": "flash_attn_func",
|
| 8 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 9 |
+
"kind": "function",
|
| 10 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (batch_size, seqlen, nheads, headdim)\n k: (batch_size, seqlen, nheads_k, headdim)\n v: (batch_size, seqlen, nheads_k, headdim)\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 11 |
+
"signature": {
|
| 12 |
+
"parameters": [
|
| 13 |
+
{
|
| 14 |
+
"name": "q",
|
| 15 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 16 |
+
"default": null,
|
| 17 |
+
"annotation": null
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"name": "k",
|
| 21 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 22 |
+
"default": null,
|
| 23 |
+
"annotation": null
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"name": "v",
|
| 27 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 28 |
+
"default": null,
|
| 29 |
+
"annotation": null
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"name": "dropout_p",
|
| 33 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 34 |
+
"default": "0.0",
|
| 35 |
+
"annotation": null
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"name": "softmax_scale",
|
| 39 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 40 |
+
"default": "None",
|
| 41 |
+
"annotation": null
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"name": "causal",
|
| 45 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 46 |
+
"default": "False",
|
| 47 |
+
"annotation": null
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"name": "window_size",
|
| 51 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 52 |
+
"default": "(-1, -1)",
|
| 53 |
+
"annotation": null
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"name": "softcap",
|
| 57 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 58 |
+
"default": "0.0",
|
| 59 |
+
"annotation": null
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"name": "alibi_slopes",
|
| 63 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 64 |
+
"default": "None",
|
| 65 |
+
"annotation": null
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"name": "deterministic",
|
| 69 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 70 |
+
"default": "False",
|
| 71 |
+
"annotation": null
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"name": "return_attn_probs",
|
| 75 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 76 |
+
"default": "False",
|
| 77 |
+
"annotation": null
|
| 78 |
+
}
|
| 79 |
+
],
|
| 80 |
+
"return_annotation": null
|
| 81 |
+
}
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
"name": "flash_attn_kvpacked_func",
|
| 85 |
+
"qualname": "flash_attn_kvpacked_func",
|
| 86 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 87 |
+
"kind": "function",
|
| 88 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of K, V.\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (batch_size, seqlen, nheads, headdim)\n kv: (batch_size, seqlen, 2, nheads_k, headdim)\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 89 |
+
"signature": {
|
| 90 |
+
"parameters": [
|
| 91 |
+
{
|
| 92 |
+
"name": "q",
|
| 93 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 94 |
+
"default": null,
|
| 95 |
+
"annotation": null
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"name": "kv",
|
| 99 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 100 |
+
"default": null,
|
| 101 |
+
"annotation": null
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"name": "dropout_p",
|
| 105 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 106 |
+
"default": "0.0",
|
| 107 |
+
"annotation": null
|
| 108 |
+
},
|
| 109 |
+
{
|
| 110 |
+
"name": "softmax_scale",
|
| 111 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 112 |
+
"default": "None",
|
| 113 |
+
"annotation": null
|
| 114 |
+
},
|
| 115 |
+
{
|
| 116 |
+
"name": "causal",
|
| 117 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 118 |
+
"default": "False",
|
| 119 |
+
"annotation": null
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"name": "window_size",
|
| 123 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 124 |
+
"default": "(-1, -1)",
|
| 125 |
+
"annotation": null
|
| 126 |
+
},
|
| 127 |
+
{
|
| 128 |
+
"name": "softcap",
|
| 129 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 130 |
+
"default": "0.0",
|
| 131 |
+
"annotation": null
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
"name": "alibi_slopes",
|
| 135 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 136 |
+
"default": "None",
|
| 137 |
+
"annotation": null
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"name": "deterministic",
|
| 141 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 142 |
+
"default": "False",
|
| 143 |
+
"annotation": null
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"name": "return_attn_probs",
|
| 147 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 148 |
+
"default": "False",
|
| 149 |
+
"annotation": null
|
| 150 |
+
}
|
| 151 |
+
],
|
| 152 |
+
"return_annotation": null
|
| 153 |
+
}
|
| 154 |
+
},
|
| 155 |
+
{
|
| 156 |
+
"name": "flash_attn_qkvpacked_func",
|
| 157 |
+
"qualname": "flash_attn_qkvpacked_func",
|
| 158 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 159 |
+
"kind": "function",
|
| 160 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf Q, K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of Q, K, V.\nFor multi-query and grouped-query attention (MQA/GQA), please see\nflash_attn_kvpacked_func and flash_attn_func.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.\n\nArguments:\n qkv: (batch_size, seqlen, 3, nheads, headdim)\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|) is added to\n the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 161 |
+
"signature": {
|
| 162 |
+
"parameters": [
|
| 163 |
+
{
|
| 164 |
+
"name": "qkv",
|
| 165 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 166 |
+
"default": null,
|
| 167 |
+
"annotation": null
|
| 168 |
+
},
|
| 169 |
+
{
|
| 170 |
+
"name": "dropout_p",
|
| 171 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 172 |
+
"default": "0.0",
|
| 173 |
+
"annotation": null
|
| 174 |
+
},
|
| 175 |
+
{
|
| 176 |
+
"name": "softmax_scale",
|
| 177 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 178 |
+
"default": "None",
|
| 179 |
+
"annotation": null
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
"name": "causal",
|
| 183 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 184 |
+
"default": "False",
|
| 185 |
+
"annotation": null
|
| 186 |
+
},
|
| 187 |
+
{
|
| 188 |
+
"name": "window_size",
|
| 189 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 190 |
+
"default": "(-1, -1)",
|
| 191 |
+
"annotation": null
|
| 192 |
+
},
|
| 193 |
+
{
|
| 194 |
+
"name": "softcap",
|
| 195 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 196 |
+
"default": "0.0",
|
| 197 |
+
"annotation": null
|
| 198 |
+
},
|
| 199 |
+
{
|
| 200 |
+
"name": "alibi_slopes",
|
| 201 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 202 |
+
"default": "None",
|
| 203 |
+
"annotation": null
|
| 204 |
+
},
|
| 205 |
+
{
|
| 206 |
+
"name": "deterministic",
|
| 207 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 208 |
+
"default": "False",
|
| 209 |
+
"annotation": null
|
| 210 |
+
},
|
| 211 |
+
{
|
| 212 |
+
"name": "return_attn_probs",
|
| 213 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 214 |
+
"default": "False",
|
| 215 |
+
"annotation": null
|
| 216 |
+
}
|
| 217 |
+
],
|
| 218 |
+
"return_annotation": null
|
| 219 |
+
}
|
| 220 |
+
},
|
| 221 |
+
{
|
| 222 |
+
"name": "flash_attn_varlen_func",
|
| 223 |
+
"qualname": "flash_attn_varlen_func",
|
| 224 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 225 |
+
"kind": "function",
|
| 226 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in K, V with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.\n k: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.\n v: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.\n cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into q.\n cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into kv.\n max_seqlen_q: int. Maximum query sequence length in the batch.\n max_seqlen_k: int. Maximum key sequence length in the batch.\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (total, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 227 |
+
"signature": {
|
| 228 |
+
"parameters": [
|
| 229 |
+
{
|
| 230 |
+
"name": "q",
|
| 231 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 232 |
+
"default": null,
|
| 233 |
+
"annotation": null
|
| 234 |
+
},
|
| 235 |
+
{
|
| 236 |
+
"name": "k",
|
| 237 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 238 |
+
"default": null,
|
| 239 |
+
"annotation": null
|
| 240 |
+
},
|
| 241 |
+
{
|
| 242 |
+
"name": "v",
|
| 243 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 244 |
+
"default": null,
|
| 245 |
+
"annotation": null
|
| 246 |
+
},
|
| 247 |
+
{
|
| 248 |
+
"name": "cu_seqlens_q",
|
| 249 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 250 |
+
"default": null,
|
| 251 |
+
"annotation": null
|
| 252 |
+
},
|
| 253 |
+
{
|
| 254 |
+
"name": "cu_seqlens_k",
|
| 255 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 256 |
+
"default": null,
|
| 257 |
+
"annotation": null
|
| 258 |
+
},
|
| 259 |
+
{
|
| 260 |
+
"name": "max_seqlen_q",
|
| 261 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 262 |
+
"default": null,
|
| 263 |
+
"annotation": null
|
| 264 |
+
},
|
| 265 |
+
{
|
| 266 |
+
"name": "max_seqlen_k",
|
| 267 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 268 |
+
"default": null,
|
| 269 |
+
"annotation": null
|
| 270 |
+
},
|
| 271 |
+
{
|
| 272 |
+
"name": "dropout_p",
|
| 273 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 274 |
+
"default": "0.0",
|
| 275 |
+
"annotation": null
|
| 276 |
+
},
|
| 277 |
+
{
|
| 278 |
+
"name": "softmax_scale",
|
| 279 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 280 |
+
"default": "None",
|
| 281 |
+
"annotation": null
|
| 282 |
+
},
|
| 283 |
+
{
|
| 284 |
+
"name": "causal",
|
| 285 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 286 |
+
"default": "False",
|
| 287 |
+
"annotation": null
|
| 288 |
+
},
|
| 289 |
+
{
|
| 290 |
+
"name": "window_size",
|
| 291 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 292 |
+
"default": "(-1, -1)",
|
| 293 |
+
"annotation": null
|
| 294 |
+
},
|
| 295 |
+
{
|
| 296 |
+
"name": "softcap",
|
| 297 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 298 |
+
"default": "0.0",
|
| 299 |
+
"annotation": null
|
| 300 |
+
},
|
| 301 |
+
{
|
| 302 |
+
"name": "alibi_slopes",
|
| 303 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 304 |
+
"default": "None",
|
| 305 |
+
"annotation": null
|
| 306 |
+
},
|
| 307 |
+
{
|
| 308 |
+
"name": "deterministic",
|
| 309 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 310 |
+
"default": "False",
|
| 311 |
+
"annotation": null
|
| 312 |
+
},
|
| 313 |
+
{
|
| 314 |
+
"name": "return_attn_probs",
|
| 315 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 316 |
+
"default": "False",
|
| 317 |
+
"annotation": null
|
| 318 |
+
},
|
| 319 |
+
{
|
| 320 |
+
"name": "block_table",
|
| 321 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 322 |
+
"default": "None",
|
| 323 |
+
"annotation": null
|
| 324 |
+
}
|
| 325 |
+
],
|
| 326 |
+
"return_annotation": null
|
| 327 |
+
}
|
| 328 |
+
},
|
| 329 |
+
{
|
| 330 |
+
"name": "flash_attn_varlen_kvpacked_func",
|
| 331 |
+
"qualname": "flash_attn_varlen_kvpacked_func",
|
| 332 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 333 |
+
"kind": "function",
|
| 334 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of K, V.\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.\n kv: (total_k, 2, nheads_k, headdim), where total_k = total number of key tokens in the batch.\n cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into q.\n cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into kv.\n max_seqlen_q: int. Maximum query sequence length in the batch.\n max_seqlen_k: int. Maximum key sequence length in the batch.\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (total, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 335 |
+
"signature": {
|
| 336 |
+
"parameters": [
|
| 337 |
+
{
|
| 338 |
+
"name": "q",
|
| 339 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 340 |
+
"default": null,
|
| 341 |
+
"annotation": null
|
| 342 |
+
},
|
| 343 |
+
{
|
| 344 |
+
"name": "kv",
|
| 345 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 346 |
+
"default": null,
|
| 347 |
+
"annotation": null
|
| 348 |
+
},
|
| 349 |
+
{
|
| 350 |
+
"name": "cu_seqlens_q",
|
| 351 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 352 |
+
"default": null,
|
| 353 |
+
"annotation": null
|
| 354 |
+
},
|
| 355 |
+
{
|
| 356 |
+
"name": "cu_seqlens_k",
|
| 357 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 358 |
+
"default": null,
|
| 359 |
+
"annotation": null
|
| 360 |
+
},
|
| 361 |
+
{
|
| 362 |
+
"name": "max_seqlen_q",
|
| 363 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 364 |
+
"default": null,
|
| 365 |
+
"annotation": null
|
| 366 |
+
},
|
| 367 |
+
{
|
| 368 |
+
"name": "max_seqlen_k",
|
| 369 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 370 |
+
"default": null,
|
| 371 |
+
"annotation": null
|
| 372 |
+
},
|
| 373 |
+
{
|
| 374 |
+
"name": "dropout_p",
|
| 375 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 376 |
+
"default": "0.0",
|
| 377 |
+
"annotation": null
|
| 378 |
+
},
|
| 379 |
+
{
|
| 380 |
+
"name": "softmax_scale",
|
| 381 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 382 |
+
"default": "None",
|
| 383 |
+
"annotation": null
|
| 384 |
+
},
|
| 385 |
+
{
|
| 386 |
+
"name": "causal",
|
| 387 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 388 |
+
"default": "False",
|
| 389 |
+
"annotation": null
|
| 390 |
+
},
|
| 391 |
+
{
|
| 392 |
+
"name": "window_size",
|
| 393 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 394 |
+
"default": "(-1, -1)",
|
| 395 |
+
"annotation": null
|
| 396 |
+
},
|
| 397 |
+
{
|
| 398 |
+
"name": "softcap",
|
| 399 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 400 |
+
"default": "0.0",
|
| 401 |
+
"annotation": null
|
| 402 |
+
},
|
| 403 |
+
{
|
| 404 |
+
"name": "alibi_slopes",
|
| 405 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 406 |
+
"default": "None",
|
| 407 |
+
"annotation": null
|
| 408 |
+
},
|
| 409 |
+
{
|
| 410 |
+
"name": "deterministic",
|
| 411 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 412 |
+
"default": "False",
|
| 413 |
+
"annotation": null
|
| 414 |
+
},
|
| 415 |
+
{
|
| 416 |
+
"name": "return_attn_probs",
|
| 417 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 418 |
+
"default": "False",
|
| 419 |
+
"annotation": null
|
| 420 |
+
}
|
| 421 |
+
],
|
| 422 |
+
"return_annotation": null
|
| 423 |
+
}
|
| 424 |
+
},
|
| 425 |
+
{
|
| 426 |
+
"name": "flash_attn_varlen_qkvpacked_func",
|
| 427 |
+
"qualname": "flash_attn_varlen_qkvpacked_func",
|
| 428 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 429 |
+
"kind": "function",
|
| 430 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf Q, K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_varlen_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of Q, K, V.\nFor multi-query and grouped-query attention (MQA/GQA), please see\nflash_attn_varlen_kvpacked_func and flash_attn_varlen_func.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.\n\nArguments:\n qkv: (total, 3, nheads, headdim), where total = total number of tokens in the batch.\n cu_seqlens: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into qkv.\n max_seqlen: int. Maximum sequence length in the batch.\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (total, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 431 |
+
"signature": {
|
| 432 |
+
"parameters": [
|
| 433 |
+
{
|
| 434 |
+
"name": "qkv",
|
| 435 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 436 |
+
"default": null,
|
| 437 |
+
"annotation": null
|
| 438 |
+
},
|
| 439 |
+
{
|
| 440 |
+
"name": "cu_seqlens",
|
| 441 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 442 |
+
"default": null,
|
| 443 |
+
"annotation": null
|
| 444 |
+
},
|
| 445 |
+
{
|
| 446 |
+
"name": "max_seqlen",
|
| 447 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 448 |
+
"default": null,
|
| 449 |
+
"annotation": null
|
| 450 |
+
},
|
| 451 |
+
{
|
| 452 |
+
"name": "dropout_p",
|
| 453 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 454 |
+
"default": "0.0",
|
| 455 |
+
"annotation": null
|
| 456 |
+
},
|
| 457 |
+
{
|
| 458 |
+
"name": "softmax_scale",
|
| 459 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 460 |
+
"default": "None",
|
| 461 |
+
"annotation": null
|
| 462 |
+
},
|
| 463 |
+
{
|
| 464 |
+
"name": "causal",
|
| 465 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 466 |
+
"default": "False",
|
| 467 |
+
"annotation": null
|
| 468 |
+
},
|
| 469 |
+
{
|
| 470 |
+
"name": "window_size",
|
| 471 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 472 |
+
"default": "(-1, -1)",
|
| 473 |
+
"annotation": null
|
| 474 |
+
},
|
| 475 |
+
{
|
| 476 |
+
"name": "softcap",
|
| 477 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 478 |
+
"default": "0.0",
|
| 479 |
+
"annotation": null
|
| 480 |
+
},
|
| 481 |
+
{
|
| 482 |
+
"name": "alibi_slopes",
|
| 483 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 484 |
+
"default": "None",
|
| 485 |
+
"annotation": null
|
| 486 |
+
},
|
| 487 |
+
{
|
| 488 |
+
"name": "deterministic",
|
| 489 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 490 |
+
"default": "False",
|
| 491 |
+
"annotation": null
|
| 492 |
+
},
|
| 493 |
+
{
|
| 494 |
+
"name": "return_attn_probs",
|
| 495 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 496 |
+
"default": "False",
|
| 497 |
+
"annotation": null
|
| 498 |
+
}
|
| 499 |
+
],
|
| 500 |
+
"return_annotation": null
|
| 501 |
+
}
|
| 502 |
+
},
|
| 503 |
+
{
|
| 504 |
+
"name": "flash_attn_with_kvcache",
|
| 505 |
+
"qualname": "flash_attn_with_kvcache",
|
| 506 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 507 |
+
"kind": "function",
|
| 508 |
+
"doc": "If k and v are not None, k_cache and v_cache will be updated *inplace* with the new values from\nk and v. This is useful for incremental decoding: you can pass in the cached keys/values from\nthe previous step, and update them with the new keys/values from the current step, and do\nattention with the updated cache, all in 1 kernel.\n\nIf you pass in k / v, you must make sure that the cache is large enough to hold the new values.\nFor example, the KV cache could be pre-allocated with the max sequence length, and you can use\ncache_seqlens to keep track of the current sequence lengths of each sequence in the batch.\n\nAlso apply rotary embedding if rotary_cos and rotary_sin are passed in. The key @k will be\nrotated by rotary_cos and rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.\nIf causal or local (i.e., window_size != (-1, -1)), the query @q will be rotated by rotary_cos\nand rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.\nIf not causal and not local, the query @q will be rotated by rotary_cos and rotary_sin at\nindices cache_seqlens only (i.e. we consider all tokens in @q to be at position cache_seqlens).\n\nSee tests/test_flash_attn.py::test_flash_attn_kvcache for examples of how to use this function.\n\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nNote: Does not support backward pass.\n\nArguments:\n q: (batch_size, seqlen, nheads, headdim)\n k_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,\n or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)\n page_block_size must be a multiple of 256.\n v_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,\n or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)\n k [optional]: (batch_size, seqlen_new, nheads_k, headdim). If not None, we concatenate\n k with k_cache, starting at the indices specified by cache_seqlens.\n v [optional]: (batch_size, seqlen_new, nheads_k, headdim). Similar to k.\n rotary_cos [optional]: (seqlen_ro, rotary_dim / 2). If not None, we apply rotary embedding\n to k and q. Only applicable if k and v are passed in. rotary_dim must be divisible by 16.\n rotary_sin [optional]: (seqlen_ro, rotary_dim / 2). Similar to rotary_cos.\n cache_seqlens: int, or (batch_size,), dtype torch.int32. The sequence lengths of the\n KV cache.\n cache_batch_idx: (batch_size,), dtype torch.int32. The indices used to index into the KV cache.\n If None, we assume that the batch indices are [0, 1, 2, ..., batch_size - 1].\n If the indices are not distinct, and k and v are provided, the values updated in the cache\n might come from any of the duplicate indices.\n cache_leftpad: (batch_size,), dtype torch.int32. The index that the KV cache starts. If None, assume 0.\n block_table [optional]: (batch_size, max_num_blocks_per_seq), dtype torch.int32.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n rotary_interleaved: bool. Only applicable if rotary_cos and rotary_sin are passed in.\n If True, rotary embedding will combine dimensions 0 & 1, 2 & 3, etc. If False,\n rotary embedding will combine dimensions 0 & rotary_dim / 2, 1 & rotary_dim / 2 + 1\n (i.e. GPT-NeoX style).\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n num_splits: int. If > 1, split the key/value into this many chunks along the sequence.\n If num_splits == 1, we don't split the key/value. If num_splits == 0, we use a heuristic\n to automatically determine the number of splits.\n Don't change this unless you know what you are doing.\n return_softmax_lse: bool. Whether to return the logsumexp of the attention scores.\n\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_softmax_lse=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).",
|
| 509 |
+
"signature": {
|
| 510 |
+
"parameters": [
|
| 511 |
+
{
|
| 512 |
+
"name": "q",
|
| 513 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 514 |
+
"default": null,
|
| 515 |
+
"annotation": null
|
| 516 |
+
},
|
| 517 |
+
{
|
| 518 |
+
"name": "k_cache",
|
| 519 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 520 |
+
"default": null,
|
| 521 |
+
"annotation": null
|
| 522 |
+
},
|
| 523 |
+
{
|
| 524 |
+
"name": "v_cache",
|
| 525 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 526 |
+
"default": null,
|
| 527 |
+
"annotation": null
|
| 528 |
+
},
|
| 529 |
+
{
|
| 530 |
+
"name": "k",
|
| 531 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 532 |
+
"default": "None",
|
| 533 |
+
"annotation": null
|
| 534 |
+
},
|
| 535 |
+
{
|
| 536 |
+
"name": "v",
|
| 537 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 538 |
+
"default": "None",
|
| 539 |
+
"annotation": null
|
| 540 |
+
},
|
| 541 |
+
{
|
| 542 |
+
"name": "rotary_cos",
|
| 543 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 544 |
+
"default": "None",
|
| 545 |
+
"annotation": null
|
| 546 |
+
},
|
| 547 |
+
{
|
| 548 |
+
"name": "rotary_sin",
|
| 549 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 550 |
+
"default": "None",
|
| 551 |
+
"annotation": null
|
| 552 |
+
},
|
| 553 |
+
{
|
| 554 |
+
"name": "cache_seqlens",
|
| 555 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 556 |
+
"default": "None",
|
| 557 |
+
"annotation": "int | torch.Tensor | None"
|
| 558 |
+
},
|
| 559 |
+
{
|
| 560 |
+
"name": "cache_batch_idx",
|
| 561 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 562 |
+
"default": "None",
|
| 563 |
+
"annotation": "torch.Tensor | None"
|
| 564 |
+
},
|
| 565 |
+
{
|
| 566 |
+
"name": "cache_leftpad",
|
| 567 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 568 |
+
"default": "None",
|
| 569 |
+
"annotation": "torch.Tensor | None"
|
| 570 |
+
},
|
| 571 |
+
{
|
| 572 |
+
"name": "block_table",
|
| 573 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 574 |
+
"default": "None",
|
| 575 |
+
"annotation": "torch.Tensor | None"
|
| 576 |
+
},
|
| 577 |
+
{
|
| 578 |
+
"name": "softmax_scale",
|
| 579 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 580 |
+
"default": "None",
|
| 581 |
+
"annotation": null
|
| 582 |
+
},
|
| 583 |
+
{
|
| 584 |
+
"name": "causal",
|
| 585 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 586 |
+
"default": "False",
|
| 587 |
+
"annotation": null
|
| 588 |
+
},
|
| 589 |
+
{
|
| 590 |
+
"name": "window_size",
|
| 591 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 592 |
+
"default": "(-1, -1)",
|
| 593 |
+
"annotation": null
|
| 594 |
+
},
|
| 595 |
+
{
|
| 596 |
+
"name": "softcap",
|
| 597 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 598 |
+
"default": "0.0",
|
| 599 |
+
"annotation": null
|
| 600 |
+
},
|
| 601 |
+
{
|
| 602 |
+
"name": "rotary_interleaved",
|
| 603 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 604 |
+
"default": "True",
|
| 605 |
+
"annotation": null
|
| 606 |
+
},
|
| 607 |
+
{
|
| 608 |
+
"name": "alibi_slopes",
|
| 609 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 610 |
+
"default": "None",
|
| 611 |
+
"annotation": null
|
| 612 |
+
},
|
| 613 |
+
{
|
| 614 |
+
"name": "num_splits",
|
| 615 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 616 |
+
"default": "0",
|
| 617 |
+
"annotation": null
|
| 618 |
+
},
|
| 619 |
+
{
|
| 620 |
+
"name": "return_softmax_lse",
|
| 621 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 622 |
+
"default": "False",
|
| 623 |
+
"annotation": null
|
| 624 |
+
}
|
| 625 |
+
],
|
| 626 |
+
"return_annotation": null
|
| 627 |
+
}
|
| 628 |
+
},
|
| 629 |
+
{
|
| 630 |
+
"name": "fwd",
|
| 631 |
+
"qualname": "fwd",
|
| 632 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 633 |
+
"kind": "function",
|
| 634 |
+
"doc": "Forward pass for multi-head attention.\n\nArgs:\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n out: Optional output tensor, same shape as q\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n return_softmax: Whether to return softmax weights\n gen: Optional random number generator\n\nReturns:\n List of tensors: [output, softmax_lse, (softmax if return_softmax)]",
|
| 635 |
+
"signature": {
|
| 636 |
+
"parameters": [
|
| 637 |
+
{
|
| 638 |
+
"name": "q",
|
| 639 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 640 |
+
"default": null,
|
| 641 |
+
"annotation": "torch.Tensor"
|
| 642 |
+
},
|
| 643 |
+
{
|
| 644 |
+
"name": "k",
|
| 645 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 646 |
+
"default": null,
|
| 647 |
+
"annotation": "torch.Tensor"
|
| 648 |
+
},
|
| 649 |
+
{
|
| 650 |
+
"name": "v",
|
| 651 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 652 |
+
"default": null,
|
| 653 |
+
"annotation": "torch.Tensor"
|
| 654 |
+
},
|
| 655 |
+
{
|
| 656 |
+
"name": "out",
|
| 657 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 658 |
+
"default": "None",
|
| 659 |
+
"annotation": "torch.Tensor | None"
|
| 660 |
+
},
|
| 661 |
+
{
|
| 662 |
+
"name": "alibi_slopes",
|
| 663 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 664 |
+
"default": "None",
|
| 665 |
+
"annotation": "torch.Tensor | None"
|
| 666 |
+
},
|
| 667 |
+
{
|
| 668 |
+
"name": "p_dropout",
|
| 669 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 670 |
+
"default": "0.0",
|
| 671 |
+
"annotation": "float"
|
| 672 |
+
},
|
| 673 |
+
{
|
| 674 |
+
"name": "softmax_scale",
|
| 675 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 676 |
+
"default": "None",
|
| 677 |
+
"annotation": "float | None"
|
| 678 |
+
},
|
| 679 |
+
{
|
| 680 |
+
"name": "is_causal",
|
| 681 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 682 |
+
"default": "False",
|
| 683 |
+
"annotation": "bool"
|
| 684 |
+
},
|
| 685 |
+
{
|
| 686 |
+
"name": "window_size_left",
|
| 687 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 688 |
+
"default": "-1",
|
| 689 |
+
"annotation": "int"
|
| 690 |
+
},
|
| 691 |
+
{
|
| 692 |
+
"name": "window_size_right",
|
| 693 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 694 |
+
"default": "-1",
|
| 695 |
+
"annotation": "int"
|
| 696 |
+
},
|
| 697 |
+
{
|
| 698 |
+
"name": "softcap",
|
| 699 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 700 |
+
"default": "0.0",
|
| 701 |
+
"annotation": "float"
|
| 702 |
+
},
|
| 703 |
+
{
|
| 704 |
+
"name": "return_softmax",
|
| 705 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 706 |
+
"default": "False",
|
| 707 |
+
"annotation": "bool"
|
| 708 |
+
},
|
| 709 |
+
{
|
| 710 |
+
"name": "gen",
|
| 711 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 712 |
+
"default": "None",
|
| 713 |
+
"annotation": "torch._C.Generator | None"
|
| 714 |
+
}
|
| 715 |
+
],
|
| 716 |
+
"return_annotation": "List[torch.Tensor]"
|
| 717 |
+
}
|
| 718 |
+
},
|
| 719 |
+
{
|
| 720 |
+
"name": "varlen_fwd",
|
| 721 |
+
"qualname": "varlen_fwd",
|
| 722 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 723 |
+
"kind": "function",
|
| 724 |
+
"doc": "Forward pass for multi-head attention with variable sequence lengths.\n\nArgs:\n q: Query tensor of shape [total_q, num_heads, head_size]\n k: Key tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n v: Value tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]\n cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]\n out: Optional output tensor of shape [total_q, num_heads, head_size]\n seqused_k: Optional tensor specifying how many keys to use per batch element [batch_size]\n leftpad_k: Optional left padding for keys of shape [batch_size]\n block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n max_seqlen_q: Maximum sequence length for queries\n max_seqlen_k: Maximum sequence length for keys\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n zero_tensors: Whether to zero tensors before computation\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n return_softmax: Whether to return softmax weights\n gen: Optional random number generator\n\nReturns:\n List of tensors: [output, softmax_lse, (softmax if return_softmax)]",
|
| 725 |
+
"signature": {
|
| 726 |
+
"parameters": [
|
| 727 |
+
{
|
| 728 |
+
"name": "q",
|
| 729 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 730 |
+
"default": null,
|
| 731 |
+
"annotation": "torch.Tensor"
|
| 732 |
+
},
|
| 733 |
+
{
|
| 734 |
+
"name": "k",
|
| 735 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 736 |
+
"default": null,
|
| 737 |
+
"annotation": "torch.Tensor"
|
| 738 |
+
},
|
| 739 |
+
{
|
| 740 |
+
"name": "v",
|
| 741 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 742 |
+
"default": null,
|
| 743 |
+
"annotation": "torch.Tensor"
|
| 744 |
+
},
|
| 745 |
+
{
|
| 746 |
+
"name": "cu_seqlens_q",
|
| 747 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 748 |
+
"default": null,
|
| 749 |
+
"annotation": "torch.Tensor"
|
| 750 |
+
},
|
| 751 |
+
{
|
| 752 |
+
"name": "cu_seqlens_k",
|
| 753 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 754 |
+
"default": null,
|
| 755 |
+
"annotation": "torch.Tensor"
|
| 756 |
+
},
|
| 757 |
+
{
|
| 758 |
+
"name": "out",
|
| 759 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 760 |
+
"default": "None",
|
| 761 |
+
"annotation": "torch.Tensor | None"
|
| 762 |
+
},
|
| 763 |
+
{
|
| 764 |
+
"name": "seqused_k",
|
| 765 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 766 |
+
"default": "None",
|
| 767 |
+
"annotation": "torch.Tensor | None"
|
| 768 |
+
},
|
| 769 |
+
{
|
| 770 |
+
"name": "leftpad_k",
|
| 771 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 772 |
+
"default": "None",
|
| 773 |
+
"annotation": "torch.Tensor | None"
|
| 774 |
+
},
|
| 775 |
+
{
|
| 776 |
+
"name": "block_table",
|
| 777 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 778 |
+
"default": "None",
|
| 779 |
+
"annotation": "torch.Tensor | None"
|
| 780 |
+
},
|
| 781 |
+
{
|
| 782 |
+
"name": "alibi_slopes",
|
| 783 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 784 |
+
"default": "None",
|
| 785 |
+
"annotation": "torch.Tensor | None"
|
| 786 |
+
},
|
| 787 |
+
{
|
| 788 |
+
"name": "max_seqlen_q",
|
| 789 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 790 |
+
"default": "0",
|
| 791 |
+
"annotation": "int"
|
| 792 |
+
},
|
| 793 |
+
{
|
| 794 |
+
"name": "max_seqlen_k",
|
| 795 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 796 |
+
"default": "0",
|
| 797 |
+
"annotation": "int"
|
| 798 |
+
},
|
| 799 |
+
{
|
| 800 |
+
"name": "p_dropout",
|
| 801 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 802 |
+
"default": "0.0",
|
| 803 |
+
"annotation": "float"
|
| 804 |
+
},
|
| 805 |
+
{
|
| 806 |
+
"name": "softmax_scale",
|
| 807 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 808 |
+
"default": "None",
|
| 809 |
+
"annotation": "float | None"
|
| 810 |
+
},
|
| 811 |
+
{
|
| 812 |
+
"name": "zero_tensors",
|
| 813 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 814 |
+
"default": "False",
|
| 815 |
+
"annotation": "bool"
|
| 816 |
+
},
|
| 817 |
+
{
|
| 818 |
+
"name": "is_causal",
|
| 819 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 820 |
+
"default": "False",
|
| 821 |
+
"annotation": "bool"
|
| 822 |
+
},
|
| 823 |
+
{
|
| 824 |
+
"name": "window_size_left",
|
| 825 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 826 |
+
"default": "-1",
|
| 827 |
+
"annotation": "int"
|
| 828 |
+
},
|
| 829 |
+
{
|
| 830 |
+
"name": "window_size_right",
|
| 831 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 832 |
+
"default": "-1",
|
| 833 |
+
"annotation": "int"
|
| 834 |
+
},
|
| 835 |
+
{
|
| 836 |
+
"name": "softcap",
|
| 837 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 838 |
+
"default": "0.0",
|
| 839 |
+
"annotation": "float"
|
| 840 |
+
},
|
| 841 |
+
{
|
| 842 |
+
"name": "return_softmax",
|
| 843 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 844 |
+
"default": "False",
|
| 845 |
+
"annotation": "bool"
|
| 846 |
+
},
|
| 847 |
+
{
|
| 848 |
+
"name": "gen",
|
| 849 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 850 |
+
"default": "None",
|
| 851 |
+
"annotation": "torch._C.Generator | None"
|
| 852 |
+
}
|
| 853 |
+
],
|
| 854 |
+
"return_annotation": "List[torch.Tensor]"
|
| 855 |
+
}
|
| 856 |
+
},
|
| 857 |
+
{
|
| 858 |
+
"name": "bwd",
|
| 859 |
+
"qualname": "bwd",
|
| 860 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 861 |
+
"kind": "function",
|
| 862 |
+
"doc": "Backward pass for multi-head attention.\n\nArgs:\n dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]\n softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]\n dq: Optional gradient tensor for queries, same shape as q\n dk: Optional gradient tensor for keys, same shape as k\n dv: Optional gradient tensor for values, same shape as v\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n deterministic: Whether to use deterministic algorithms\n gen: Optional random number generator\n rng_state: Optional RNG state from forward pass\n\nReturns:\n List of tensors: [dq, dk, dv]",
|
| 863 |
+
"signature": {
|
| 864 |
+
"parameters": [
|
| 865 |
+
{
|
| 866 |
+
"name": "dout",
|
| 867 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 868 |
+
"default": null,
|
| 869 |
+
"annotation": "torch.Tensor"
|
| 870 |
+
},
|
| 871 |
+
{
|
| 872 |
+
"name": "q",
|
| 873 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 874 |
+
"default": null,
|
| 875 |
+
"annotation": "torch.Tensor"
|
| 876 |
+
},
|
| 877 |
+
{
|
| 878 |
+
"name": "k",
|
| 879 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 880 |
+
"default": null,
|
| 881 |
+
"annotation": "torch.Tensor"
|
| 882 |
+
},
|
| 883 |
+
{
|
| 884 |
+
"name": "v",
|
| 885 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 886 |
+
"default": null,
|
| 887 |
+
"annotation": "torch.Tensor"
|
| 888 |
+
},
|
| 889 |
+
{
|
| 890 |
+
"name": "out",
|
| 891 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 892 |
+
"default": null,
|
| 893 |
+
"annotation": "torch.Tensor"
|
| 894 |
+
},
|
| 895 |
+
{
|
| 896 |
+
"name": "softmax_lse",
|
| 897 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 898 |
+
"default": null,
|
| 899 |
+
"annotation": "torch.Tensor"
|
| 900 |
+
},
|
| 901 |
+
{
|
| 902 |
+
"name": "dq",
|
| 903 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 904 |
+
"default": "None",
|
| 905 |
+
"annotation": "torch.Tensor | None"
|
| 906 |
+
},
|
| 907 |
+
{
|
| 908 |
+
"name": "dk",
|
| 909 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 910 |
+
"default": "None",
|
| 911 |
+
"annotation": "torch.Tensor | None"
|
| 912 |
+
},
|
| 913 |
+
{
|
| 914 |
+
"name": "dv",
|
| 915 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 916 |
+
"default": "None",
|
| 917 |
+
"annotation": "torch.Tensor | None"
|
| 918 |
+
},
|
| 919 |
+
{
|
| 920 |
+
"name": "alibi_slopes",
|
| 921 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 922 |
+
"default": "None",
|
| 923 |
+
"annotation": "torch.Tensor | None"
|
| 924 |
+
},
|
| 925 |
+
{
|
| 926 |
+
"name": "p_dropout",
|
| 927 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 928 |
+
"default": "0.0",
|
| 929 |
+
"annotation": "float"
|
| 930 |
+
},
|
| 931 |
+
{
|
| 932 |
+
"name": "softmax_scale",
|
| 933 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 934 |
+
"default": "None",
|
| 935 |
+
"annotation": "float | None"
|
| 936 |
+
},
|
| 937 |
+
{
|
| 938 |
+
"name": "is_causal",
|
| 939 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 940 |
+
"default": "False",
|
| 941 |
+
"annotation": "bool"
|
| 942 |
+
},
|
| 943 |
+
{
|
| 944 |
+
"name": "window_size_left",
|
| 945 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 946 |
+
"default": "-1",
|
| 947 |
+
"annotation": "int"
|
| 948 |
+
},
|
| 949 |
+
{
|
| 950 |
+
"name": "window_size_right",
|
| 951 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 952 |
+
"default": "-1",
|
| 953 |
+
"annotation": "int"
|
| 954 |
+
},
|
| 955 |
+
{
|
| 956 |
+
"name": "softcap",
|
| 957 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 958 |
+
"default": "0.0",
|
| 959 |
+
"annotation": "float"
|
| 960 |
+
},
|
| 961 |
+
{
|
| 962 |
+
"name": "deterministic",
|
| 963 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 964 |
+
"default": "False",
|
| 965 |
+
"annotation": "bool"
|
| 966 |
+
},
|
| 967 |
+
{
|
| 968 |
+
"name": "gen",
|
| 969 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 970 |
+
"default": "None",
|
| 971 |
+
"annotation": "torch._C.Generator | None"
|
| 972 |
+
},
|
| 973 |
+
{
|
| 974 |
+
"name": "rng_state",
|
| 975 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 976 |
+
"default": "None",
|
| 977 |
+
"annotation": "torch.Tensor | None"
|
| 978 |
+
}
|
| 979 |
+
],
|
| 980 |
+
"return_annotation": "List[torch.Tensor]"
|
| 981 |
+
}
|
| 982 |
+
},
|
| 983 |
+
{
|
| 984 |
+
"name": "varlen_bwd",
|
| 985 |
+
"qualname": "varlen_bwd",
|
| 986 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 987 |
+
"kind": "function",
|
| 988 |
+
"doc": "Backward pass for multi-head attention with variable sequence lengths.\n\nArgs:\n dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]\n softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]\n cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]\n cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]\n dq: Optional gradient tensor for queries, same shape as q\n dk: Optional gradient tensor for keys, same shape as k\n dv: Optional gradient tensor for values, same shape as v\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n max_seqlen_q: Maximum sequence length for queries\n max_seqlen_k: Maximum sequence length for keys\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n zero_tensors: Whether to zero tensors before computation\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n deterministic: Whether to use deterministic algorithms\n gen: Optional random number generator\n rng_state: Optional RNG state from forward pass\n\nReturns:\n List of tensors: [dq, dk, dv]",
|
| 989 |
+
"signature": {
|
| 990 |
+
"parameters": [
|
| 991 |
+
{
|
| 992 |
+
"name": "dout",
|
| 993 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 994 |
+
"default": null,
|
| 995 |
+
"annotation": "torch.Tensor"
|
| 996 |
+
},
|
| 997 |
+
{
|
| 998 |
+
"name": "q",
|
| 999 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1000 |
+
"default": null,
|
| 1001 |
+
"annotation": "torch.Tensor"
|
| 1002 |
+
},
|
| 1003 |
+
{
|
| 1004 |
+
"name": "k",
|
| 1005 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1006 |
+
"default": null,
|
| 1007 |
+
"annotation": "torch.Tensor"
|
| 1008 |
+
},
|
| 1009 |
+
{
|
| 1010 |
+
"name": "v",
|
| 1011 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1012 |
+
"default": null,
|
| 1013 |
+
"annotation": "torch.Tensor"
|
| 1014 |
+
},
|
| 1015 |
+
{
|
| 1016 |
+
"name": "out",
|
| 1017 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1018 |
+
"default": null,
|
| 1019 |
+
"annotation": "torch.Tensor"
|
| 1020 |
+
},
|
| 1021 |
+
{
|
| 1022 |
+
"name": "softmax_lse",
|
| 1023 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1024 |
+
"default": null,
|
| 1025 |
+
"annotation": "torch.Tensor"
|
| 1026 |
+
},
|
| 1027 |
+
{
|
| 1028 |
+
"name": "cu_seqlens_q",
|
| 1029 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1030 |
+
"default": null,
|
| 1031 |
+
"annotation": "torch.Tensor"
|
| 1032 |
+
},
|
| 1033 |
+
{
|
| 1034 |
+
"name": "cu_seqlens_k",
|
| 1035 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1036 |
+
"default": null,
|
| 1037 |
+
"annotation": "torch.Tensor"
|
| 1038 |
+
},
|
| 1039 |
+
{
|
| 1040 |
+
"name": "dq",
|
| 1041 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1042 |
+
"default": "None",
|
| 1043 |
+
"annotation": "torch.Tensor | None"
|
| 1044 |
+
},
|
| 1045 |
+
{
|
| 1046 |
+
"name": "dk",
|
| 1047 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1048 |
+
"default": "None",
|
| 1049 |
+
"annotation": "torch.Tensor | None"
|
| 1050 |
+
},
|
| 1051 |
+
{
|
| 1052 |
+
"name": "dv",
|
| 1053 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1054 |
+
"default": "None",
|
| 1055 |
+
"annotation": "torch.Tensor | None"
|
| 1056 |
+
},
|
| 1057 |
+
{
|
| 1058 |
+
"name": "alibi_slopes",
|
| 1059 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1060 |
+
"default": "None",
|
| 1061 |
+
"annotation": "torch.Tensor | None"
|
| 1062 |
+
},
|
| 1063 |
+
{
|
| 1064 |
+
"name": "max_seqlen_q",
|
| 1065 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1066 |
+
"default": "0",
|
| 1067 |
+
"annotation": "int"
|
| 1068 |
+
},
|
| 1069 |
+
{
|
| 1070 |
+
"name": "max_seqlen_k",
|
| 1071 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1072 |
+
"default": "0",
|
| 1073 |
+
"annotation": "int"
|
| 1074 |
+
},
|
| 1075 |
+
{
|
| 1076 |
+
"name": "p_dropout",
|
| 1077 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1078 |
+
"default": "0.0",
|
| 1079 |
+
"annotation": "float"
|
| 1080 |
+
},
|
| 1081 |
+
{
|
| 1082 |
+
"name": "softmax_scale",
|
| 1083 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1084 |
+
"default": "None",
|
| 1085 |
+
"annotation": "float | None"
|
| 1086 |
+
},
|
| 1087 |
+
{
|
| 1088 |
+
"name": "zero_tensors",
|
| 1089 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1090 |
+
"default": "False",
|
| 1091 |
+
"annotation": "bool"
|
| 1092 |
+
},
|
| 1093 |
+
{
|
| 1094 |
+
"name": "is_causal",
|
| 1095 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1096 |
+
"default": "False",
|
| 1097 |
+
"annotation": "bool"
|
| 1098 |
+
},
|
| 1099 |
+
{
|
| 1100 |
+
"name": "window_size_left",
|
| 1101 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1102 |
+
"default": "-1",
|
| 1103 |
+
"annotation": "int"
|
| 1104 |
+
},
|
| 1105 |
+
{
|
| 1106 |
+
"name": "window_size_right",
|
| 1107 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1108 |
+
"default": "-1",
|
| 1109 |
+
"annotation": "int"
|
| 1110 |
+
},
|
| 1111 |
+
{
|
| 1112 |
+
"name": "softcap",
|
| 1113 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1114 |
+
"default": "0.0",
|
| 1115 |
+
"annotation": "float"
|
| 1116 |
+
},
|
| 1117 |
+
{
|
| 1118 |
+
"name": "deterministic",
|
| 1119 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1120 |
+
"default": "False",
|
| 1121 |
+
"annotation": "bool"
|
| 1122 |
+
},
|
| 1123 |
+
{
|
| 1124 |
+
"name": "gen",
|
| 1125 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1126 |
+
"default": "None",
|
| 1127 |
+
"annotation": "torch._C.Generator | None"
|
| 1128 |
+
},
|
| 1129 |
+
{
|
| 1130 |
+
"name": "rng_state",
|
| 1131 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1132 |
+
"default": "None",
|
| 1133 |
+
"annotation": "torch.Tensor | None"
|
| 1134 |
+
}
|
| 1135 |
+
],
|
| 1136 |
+
"return_annotation": "List[torch.Tensor]"
|
| 1137 |
+
}
|
| 1138 |
+
},
|
| 1139 |
+
{
|
| 1140 |
+
"name": "fwd_kvcache",
|
| 1141 |
+
"qualname": "fwd_kvcache",
|
| 1142 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 1143 |
+
"kind": "function",
|
| 1144 |
+
"doc": "Forward pass for multi-head attention with KV cache.\n\nArgs:\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n kcache: Key cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n vcache: Value cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n k: Optional new keys tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]\n v: Optional new values tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]\n seqlens_k: Optional sequence lengths for keys of shape [batch_size]\n rotary_cos: Optional rotary cosine tensor of shape [seqlen_ro, rotary_dim/2]\n rotary_sin: Optional rotary sine tensor of shape [seqlen_ro, rotary_dim/2]\n cache_batch_idx: Optional indices to index into the KV cache\n leftpad_k: Optional left padding for keys of shape [batch_size]\n block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n out: Optional output tensor, same shape as q\n softmax_scale: Scale factor for softmax\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n is_rotary_interleaved: Whether rotary embeddings are interleaved\n num_splits: Number of splits for computation\n\nReturns:\n List of tensors: [output, softmax_lse]",
|
| 1145 |
+
"signature": {
|
| 1146 |
+
"parameters": [
|
| 1147 |
+
{
|
| 1148 |
+
"name": "q",
|
| 1149 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1150 |
+
"default": null,
|
| 1151 |
+
"annotation": "torch.Tensor"
|
| 1152 |
+
},
|
| 1153 |
+
{
|
| 1154 |
+
"name": "kcache",
|
| 1155 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1156 |
+
"default": null,
|
| 1157 |
+
"annotation": "torch.Tensor"
|
| 1158 |
+
},
|
| 1159 |
+
{
|
| 1160 |
+
"name": "vcache",
|
| 1161 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1162 |
+
"default": null,
|
| 1163 |
+
"annotation": "torch.Tensor"
|
| 1164 |
+
},
|
| 1165 |
+
{
|
| 1166 |
+
"name": "k",
|
| 1167 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1168 |
+
"default": "None",
|
| 1169 |
+
"annotation": "torch.Tensor | None"
|
| 1170 |
+
},
|
| 1171 |
+
{
|
| 1172 |
+
"name": "v",
|
| 1173 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1174 |
+
"default": "None",
|
| 1175 |
+
"annotation": "torch.Tensor | None"
|
| 1176 |
+
},
|
| 1177 |
+
{
|
| 1178 |
+
"name": "seqlens_k",
|
| 1179 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1180 |
+
"default": "None",
|
| 1181 |
+
"annotation": "torch.Tensor | None"
|
| 1182 |
+
},
|
| 1183 |
+
{
|
| 1184 |
+
"name": "rotary_cos",
|
| 1185 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1186 |
+
"default": "None",
|
| 1187 |
+
"annotation": "torch.Tensor | None"
|
| 1188 |
+
},
|
| 1189 |
+
{
|
| 1190 |
+
"name": "rotary_sin",
|
| 1191 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1192 |
+
"default": "None",
|
| 1193 |
+
"annotation": "torch.Tensor | None"
|
| 1194 |
+
},
|
| 1195 |
+
{
|
| 1196 |
+
"name": "cache_batch_idx",
|
| 1197 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1198 |
+
"default": "None",
|
| 1199 |
+
"annotation": "torch.Tensor | None"
|
| 1200 |
+
},
|
| 1201 |
+
{
|
| 1202 |
+
"name": "leftpad_k",
|
| 1203 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1204 |
+
"default": "None",
|
| 1205 |
+
"annotation": "torch.Tensor | None"
|
| 1206 |
+
},
|
| 1207 |
+
{
|
| 1208 |
+
"name": "block_table",
|
| 1209 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1210 |
+
"default": "None",
|
| 1211 |
+
"annotation": "torch.Tensor | None"
|
| 1212 |
+
},
|
| 1213 |
+
{
|
| 1214 |
+
"name": "alibi_slopes",
|
| 1215 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1216 |
+
"default": "None",
|
| 1217 |
+
"annotation": "torch.Tensor | None"
|
| 1218 |
+
},
|
| 1219 |
+
{
|
| 1220 |
+
"name": "out",
|
| 1221 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1222 |
+
"default": "None",
|
| 1223 |
+
"annotation": "torch.Tensor | None"
|
| 1224 |
+
},
|
| 1225 |
+
{
|
| 1226 |
+
"name": "softmax_scale",
|
| 1227 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1228 |
+
"default": "None",
|
| 1229 |
+
"annotation": "float | None"
|
| 1230 |
+
},
|
| 1231 |
+
{
|
| 1232 |
+
"name": "is_causal",
|
| 1233 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1234 |
+
"default": "False",
|
| 1235 |
+
"annotation": "bool"
|
| 1236 |
+
},
|
| 1237 |
+
{
|
| 1238 |
+
"name": "window_size_left",
|
| 1239 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1240 |
+
"default": "-1",
|
| 1241 |
+
"annotation": "int"
|
| 1242 |
+
},
|
| 1243 |
+
{
|
| 1244 |
+
"name": "window_size_right",
|
| 1245 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1246 |
+
"default": "-1",
|
| 1247 |
+
"annotation": "int"
|
| 1248 |
+
},
|
| 1249 |
+
{
|
| 1250 |
+
"name": "softcap",
|
| 1251 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1252 |
+
"default": "0.0",
|
| 1253 |
+
"annotation": "float"
|
| 1254 |
+
},
|
| 1255 |
+
{
|
| 1256 |
+
"name": "is_rotary_interleaved",
|
| 1257 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1258 |
+
"default": "False",
|
| 1259 |
+
"annotation": "bool"
|
| 1260 |
+
},
|
| 1261 |
+
{
|
| 1262 |
+
"name": "num_splits",
|
| 1263 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1264 |
+
"default": "1",
|
| 1265 |
+
"annotation": "int"
|
| 1266 |
+
}
|
| 1267 |
+
],
|
| 1268 |
+
"return_annotation": "List[torch.Tensor]"
|
| 1269 |
+
}
|
| 1270 |
+
}
|
| 1271 |
+
],
|
| 1272 |
+
"layers": []
|
| 1273 |
+
}
|
build/torch-stable-abi210-cu130-aarch64-linux/__init__.py
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List, Optional
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
from . import flash_attn_interface
|
| 6 |
+
from ._ops import ops as flash_attn_ops
|
| 7 |
+
from .flash_attn_interface import (
|
| 8 |
+
# helper to set up the Philox random number generator for dropout
|
| 9 |
+
_philox_generator,
|
| 10 |
+
# reexported for convenience to be used in the high-level API functions
|
| 11 |
+
flash_attn_func,
|
| 12 |
+
flash_attn_kvpacked_func,
|
| 13 |
+
flash_attn_qkvpacked_func,
|
| 14 |
+
flash_attn_varlen_func,
|
| 15 |
+
flash_attn_varlen_kvpacked_func,
|
| 16 |
+
flash_attn_varlen_qkvpacked_func,
|
| 17 |
+
flash_attn_with_kvcache,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
__all__ = [
|
| 21 |
+
# High-level API (with autograd support)
|
| 22 |
+
"flash_attn_func",
|
| 23 |
+
"flash_attn_kvpacked_func",
|
| 24 |
+
"flash_attn_qkvpacked_func",
|
| 25 |
+
"flash_attn_varlen_func",
|
| 26 |
+
"flash_attn_varlen_kvpacked_func",
|
| 27 |
+
"flash_attn_varlen_qkvpacked_func",
|
| 28 |
+
"flash_attn_with_kvcache",
|
| 29 |
+
# Upstream interface module. Its `_flash_attn_forward`, `_flash_attn_backward`,
|
| 30 |
+
# `_flash_attn_varlen_forward` and `_flash_attn_varlen_backward` are supported
|
| 31 |
+
# low-level entry points with upstream's signatures: Torch custom ops without
|
| 32 |
+
# autograd that return the LSE and are traceable by torch.compile. The autograd
|
| 33 |
+
# Functions above are built on top of them.
|
| 34 |
+
"flash_attn_interface",
|
| 35 |
+
# Low-level ops (no autograd)
|
| 36 |
+
"fwd",
|
| 37 |
+
"varlen_fwd",
|
| 38 |
+
"bwd",
|
| 39 |
+
"varlen_bwd",
|
| 40 |
+
"fwd_kvcache",
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def fwd(
|
| 45 |
+
q: torch.Tensor,
|
| 46 |
+
k: torch.Tensor,
|
| 47 |
+
v: torch.Tensor,
|
| 48 |
+
out: Optional[torch.Tensor] = None,
|
| 49 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 50 |
+
p_dropout: float = 0.0,
|
| 51 |
+
softmax_scale: Optional[float] = None,
|
| 52 |
+
is_causal: bool = False,
|
| 53 |
+
window_size_left: int = -1,
|
| 54 |
+
window_size_right: int = -1,
|
| 55 |
+
softcap: float = 0.0,
|
| 56 |
+
return_softmax: bool = False,
|
| 57 |
+
gen: Optional[torch.Generator] = None,
|
| 58 |
+
) -> List[torch.Tensor]:
|
| 59 |
+
"""
|
| 60 |
+
Forward pass for multi-head attention.
|
| 61 |
+
|
| 62 |
+
Args:
|
| 63 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 64 |
+
k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 65 |
+
v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 66 |
+
out: Optional output tensor, same shape as q
|
| 67 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 68 |
+
p_dropout: Dropout probability
|
| 69 |
+
softmax_scale: Scale factor for softmax
|
| 70 |
+
is_causal: Whether to use causal attention
|
| 71 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 72 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 73 |
+
softcap: Soft cap for attention weights
|
| 74 |
+
return_softmax: Whether to return softmax weights
|
| 75 |
+
gen: Optional random number generator
|
| 76 |
+
|
| 77 |
+
Returns:
|
| 78 |
+
List of tensors: [output, softmax_lse, (softmax if return_softmax)]
|
| 79 |
+
"""
|
| 80 |
+
if softmax_scale is None:
|
| 81 |
+
attention_head_dim = q.shape[-1]
|
| 82 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 83 |
+
|
| 84 |
+
gen = _philox_generator(q, p_dropout, gen)
|
| 85 |
+
return flash_attn_ops.fwd(
|
| 86 |
+
q,
|
| 87 |
+
k,
|
| 88 |
+
v,
|
| 89 |
+
out,
|
| 90 |
+
alibi_slopes,
|
| 91 |
+
p_dropout,
|
| 92 |
+
softmax_scale,
|
| 93 |
+
is_causal,
|
| 94 |
+
window_size_left,
|
| 95 |
+
window_size_right,
|
| 96 |
+
softcap,
|
| 97 |
+
return_softmax,
|
| 98 |
+
gen,
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def varlen_fwd(
|
| 103 |
+
q: torch.Tensor,
|
| 104 |
+
k: torch.Tensor,
|
| 105 |
+
v: torch.Tensor,
|
| 106 |
+
cu_seqlens_q: torch.Tensor,
|
| 107 |
+
cu_seqlens_k: torch.Tensor,
|
| 108 |
+
out: Optional[torch.Tensor] = None,
|
| 109 |
+
seqused_k: Optional[torch.Tensor] = None,
|
| 110 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 111 |
+
block_table: Optional[torch.Tensor] = None,
|
| 112 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 113 |
+
max_seqlen_q: int = 0,
|
| 114 |
+
max_seqlen_k: int = 0,
|
| 115 |
+
p_dropout: float = 0.0,
|
| 116 |
+
softmax_scale: Optional[float] = None,
|
| 117 |
+
zero_tensors: bool = False,
|
| 118 |
+
is_causal: bool = False,
|
| 119 |
+
window_size_left: int = -1,
|
| 120 |
+
window_size_right: int = -1,
|
| 121 |
+
softcap: float = 0.0,
|
| 122 |
+
return_softmax: bool = False,
|
| 123 |
+
gen: Optional[torch.Generator] = None,
|
| 124 |
+
) -> List[torch.Tensor]:
|
| 125 |
+
"""
|
| 126 |
+
Forward pass for multi-head attention with variable sequence lengths.
|
| 127 |
+
|
| 128 |
+
Args:
|
| 129 |
+
q: Query tensor of shape [total_q, num_heads, head_size]
|
| 130 |
+
k: Key tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 131 |
+
v: Value tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 132 |
+
cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]
|
| 133 |
+
cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]
|
| 134 |
+
out: Optional output tensor of shape [total_q, num_heads, head_size]
|
| 135 |
+
seqused_k: Optional tensor specifying how many keys to use per batch element [batch_size]
|
| 136 |
+
leftpad_k: Optional left padding for keys of shape [batch_size]
|
| 137 |
+
block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]
|
| 138 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 139 |
+
max_seqlen_q: Maximum sequence length for queries
|
| 140 |
+
max_seqlen_k: Maximum sequence length for keys
|
| 141 |
+
p_dropout: Dropout probability
|
| 142 |
+
softmax_scale: Scale factor for softmax
|
| 143 |
+
zero_tensors: Whether to zero tensors before computation
|
| 144 |
+
is_causal: Whether to use causal attention
|
| 145 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 146 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 147 |
+
softcap: Soft cap for attention weights
|
| 148 |
+
return_softmax: Whether to return softmax weights
|
| 149 |
+
gen: Optional random number generator
|
| 150 |
+
|
| 151 |
+
Returns:
|
| 152 |
+
List of tensors: [output, softmax_lse, (softmax if return_softmax)]
|
| 153 |
+
"""
|
| 154 |
+
if softmax_scale is None:
|
| 155 |
+
attention_head_dim = q.shape[-1]
|
| 156 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 157 |
+
|
| 158 |
+
gen = _philox_generator(q, p_dropout, gen)
|
| 159 |
+
return flash_attn_ops.varlen_fwd(
|
| 160 |
+
q,
|
| 161 |
+
k,
|
| 162 |
+
v,
|
| 163 |
+
out,
|
| 164 |
+
cu_seqlens_q,
|
| 165 |
+
cu_seqlens_k,
|
| 166 |
+
seqused_k,
|
| 167 |
+
leftpad_k,
|
| 168 |
+
block_table,
|
| 169 |
+
alibi_slopes,
|
| 170 |
+
max_seqlen_q,
|
| 171 |
+
max_seqlen_k,
|
| 172 |
+
p_dropout,
|
| 173 |
+
softmax_scale,
|
| 174 |
+
zero_tensors,
|
| 175 |
+
is_causal,
|
| 176 |
+
window_size_left,
|
| 177 |
+
window_size_right,
|
| 178 |
+
softcap,
|
| 179 |
+
return_softmax,
|
| 180 |
+
gen,
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def bwd(
|
| 185 |
+
dout: torch.Tensor,
|
| 186 |
+
q: torch.Tensor,
|
| 187 |
+
k: torch.Tensor,
|
| 188 |
+
v: torch.Tensor,
|
| 189 |
+
out: torch.Tensor,
|
| 190 |
+
softmax_lse: torch.Tensor,
|
| 191 |
+
dq: Optional[torch.Tensor] = None,
|
| 192 |
+
dk: Optional[torch.Tensor] = None,
|
| 193 |
+
dv: Optional[torch.Tensor] = None,
|
| 194 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 195 |
+
p_dropout: float = 0.0,
|
| 196 |
+
softmax_scale: Optional[float] = None,
|
| 197 |
+
is_causal: bool = False,
|
| 198 |
+
window_size_left: int = -1,
|
| 199 |
+
window_size_right: int = -1,
|
| 200 |
+
softcap: float = 0.0,
|
| 201 |
+
deterministic: bool = False,
|
| 202 |
+
gen: Optional[torch.Generator] = None,
|
| 203 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 204 |
+
) -> List[torch.Tensor]:
|
| 205 |
+
"""
|
| 206 |
+
Backward pass for multi-head attention.
|
| 207 |
+
|
| 208 |
+
Args:
|
| 209 |
+
dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 210 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 211 |
+
k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 212 |
+
v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 213 |
+
out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 214 |
+
softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]
|
| 215 |
+
dq: Optional gradient tensor for queries, same shape as q
|
| 216 |
+
dk: Optional gradient tensor for keys, same shape as k
|
| 217 |
+
dv: Optional gradient tensor for values, same shape as v
|
| 218 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 219 |
+
p_dropout: Dropout probability
|
| 220 |
+
softmax_scale: Scale factor for softmax
|
| 221 |
+
is_causal: Whether to use causal attention
|
| 222 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 223 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 224 |
+
softcap: Soft cap for attention weights
|
| 225 |
+
deterministic: Whether to use deterministic algorithms
|
| 226 |
+
gen: Optional random number generator
|
| 227 |
+
rng_state: Optional RNG state from forward pass
|
| 228 |
+
|
| 229 |
+
Returns:
|
| 230 |
+
List of tensors: [dq, dk, dv]
|
| 231 |
+
"""
|
| 232 |
+
if softmax_scale is None:
|
| 233 |
+
attention_head_dim = q.shape[-1]
|
| 234 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 235 |
+
|
| 236 |
+
return flash_attn_ops.bwd(
|
| 237 |
+
dout,
|
| 238 |
+
q,
|
| 239 |
+
k,
|
| 240 |
+
v,
|
| 241 |
+
out,
|
| 242 |
+
softmax_lse,
|
| 243 |
+
dq,
|
| 244 |
+
dk,
|
| 245 |
+
dv,
|
| 246 |
+
alibi_slopes,
|
| 247 |
+
p_dropout,
|
| 248 |
+
softmax_scale,
|
| 249 |
+
is_causal,
|
| 250 |
+
window_size_left,
|
| 251 |
+
window_size_right,
|
| 252 |
+
softcap,
|
| 253 |
+
deterministic,
|
| 254 |
+
gen,
|
| 255 |
+
rng_state,
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def varlen_bwd(
|
| 260 |
+
dout: torch.Tensor,
|
| 261 |
+
q: torch.Tensor,
|
| 262 |
+
k: torch.Tensor,
|
| 263 |
+
v: torch.Tensor,
|
| 264 |
+
out: torch.Tensor,
|
| 265 |
+
softmax_lse: torch.Tensor,
|
| 266 |
+
cu_seqlens_q: torch.Tensor,
|
| 267 |
+
cu_seqlens_k: torch.Tensor,
|
| 268 |
+
dq: Optional[torch.Tensor] = None,
|
| 269 |
+
dk: Optional[torch.Tensor] = None,
|
| 270 |
+
dv: Optional[torch.Tensor] = None,
|
| 271 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 272 |
+
max_seqlen_q: int = 0,
|
| 273 |
+
max_seqlen_k: int = 0,
|
| 274 |
+
p_dropout: float = 0.0,
|
| 275 |
+
softmax_scale: Optional[float] = None,
|
| 276 |
+
zero_tensors: bool = False,
|
| 277 |
+
is_causal: bool = False,
|
| 278 |
+
window_size_left: int = -1,
|
| 279 |
+
window_size_right: int = -1,
|
| 280 |
+
softcap: float = 0.0,
|
| 281 |
+
deterministic: bool = False,
|
| 282 |
+
gen: Optional[torch.Generator] = None,
|
| 283 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 284 |
+
) -> List[torch.Tensor]:
|
| 285 |
+
"""
|
| 286 |
+
Backward pass for multi-head attention with variable sequence lengths.
|
| 287 |
+
|
| 288 |
+
Args:
|
| 289 |
+
dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 290 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 291 |
+
k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 292 |
+
v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 293 |
+
out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 294 |
+
softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]
|
| 295 |
+
cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]
|
| 296 |
+
cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]
|
| 297 |
+
dq: Optional gradient tensor for queries, same shape as q
|
| 298 |
+
dk: Optional gradient tensor for keys, same shape as k
|
| 299 |
+
dv: Optional gradient tensor for values, same shape as v
|
| 300 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 301 |
+
max_seqlen_q: Maximum sequence length for queries
|
| 302 |
+
max_seqlen_k: Maximum sequence length for keys
|
| 303 |
+
p_dropout: Dropout probability
|
| 304 |
+
softmax_scale: Scale factor for softmax
|
| 305 |
+
zero_tensors: Whether to zero tensors before computation
|
| 306 |
+
is_causal: Whether to use causal attention
|
| 307 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 308 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 309 |
+
softcap: Soft cap for attention weights
|
| 310 |
+
deterministic: Whether to use deterministic algorithms
|
| 311 |
+
gen: Optional random number generator
|
| 312 |
+
rng_state: Optional RNG state from forward pass
|
| 313 |
+
|
| 314 |
+
Returns:
|
| 315 |
+
List of tensors: [dq, dk, dv]
|
| 316 |
+
"""
|
| 317 |
+
if softmax_scale is None:
|
| 318 |
+
attention_head_dim = q.shape[-1]
|
| 319 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 320 |
+
|
| 321 |
+
return flash_attn_ops.varlen_bwd(
|
| 322 |
+
dout,
|
| 323 |
+
q,
|
| 324 |
+
k,
|
| 325 |
+
v,
|
| 326 |
+
out,
|
| 327 |
+
softmax_lse,
|
| 328 |
+
dq,
|
| 329 |
+
dk,
|
| 330 |
+
dv,
|
| 331 |
+
cu_seqlens_q,
|
| 332 |
+
cu_seqlens_k,
|
| 333 |
+
alibi_slopes,
|
| 334 |
+
max_seqlen_q,
|
| 335 |
+
max_seqlen_k,
|
| 336 |
+
p_dropout,
|
| 337 |
+
softmax_scale,
|
| 338 |
+
zero_tensors,
|
| 339 |
+
is_causal,
|
| 340 |
+
window_size_left,
|
| 341 |
+
window_size_right,
|
| 342 |
+
softcap,
|
| 343 |
+
deterministic,
|
| 344 |
+
gen,
|
| 345 |
+
rng_state,
|
| 346 |
+
)
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
def fwd_kvcache(
|
| 350 |
+
q: torch.Tensor,
|
| 351 |
+
kcache: torch.Tensor,
|
| 352 |
+
vcache: torch.Tensor,
|
| 353 |
+
k: Optional[torch.Tensor] = None,
|
| 354 |
+
v: Optional[torch.Tensor] = None,
|
| 355 |
+
seqlens_k: Optional[torch.Tensor] = None,
|
| 356 |
+
rotary_cos: Optional[torch.Tensor] = None,
|
| 357 |
+
rotary_sin: Optional[torch.Tensor] = None,
|
| 358 |
+
cache_batch_idx: Optional[torch.Tensor] = None,
|
| 359 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 360 |
+
block_table: Optional[torch.Tensor] = None,
|
| 361 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 362 |
+
out: Optional[torch.Tensor] = None,
|
| 363 |
+
softmax_scale: Optional[float] = None,
|
| 364 |
+
is_causal: bool = False,
|
| 365 |
+
window_size_left: int = -1,
|
| 366 |
+
window_size_right: int = -1,
|
| 367 |
+
softcap: float = 0.0,
|
| 368 |
+
is_rotary_interleaved: bool = False,
|
| 369 |
+
num_splits: int = 1,
|
| 370 |
+
) -> List[torch.Tensor]:
|
| 371 |
+
"""
|
| 372 |
+
Forward pass for multi-head attention with KV cache.
|
| 373 |
+
|
| 374 |
+
Args:
|
| 375 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 376 |
+
kcache: Key cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 377 |
+
vcache: Value cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 378 |
+
k: Optional new keys tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]
|
| 379 |
+
v: Optional new values tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]
|
| 380 |
+
seqlens_k: Optional sequence lengths for keys of shape [batch_size]
|
| 381 |
+
rotary_cos: Optional rotary cosine tensor of shape [seqlen_ro, rotary_dim/2]
|
| 382 |
+
rotary_sin: Optional rotary sine tensor of shape [seqlen_ro, rotary_dim/2]
|
| 383 |
+
cache_batch_idx: Optional indices to index into the KV cache
|
| 384 |
+
leftpad_k: Optional left padding for keys of shape [batch_size]
|
| 385 |
+
block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]
|
| 386 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 387 |
+
out: Optional output tensor, same shape as q
|
| 388 |
+
softmax_scale: Scale factor for softmax
|
| 389 |
+
is_causal: Whether to use causal attention
|
| 390 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 391 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 392 |
+
softcap: Soft cap for attention weights
|
| 393 |
+
is_rotary_interleaved: Whether rotary embeddings are interleaved
|
| 394 |
+
num_splits: Number of splits for computation
|
| 395 |
+
|
| 396 |
+
Returns:
|
| 397 |
+
List of tensors: [output, softmax_lse]
|
| 398 |
+
"""
|
| 399 |
+
if softmax_scale is None:
|
| 400 |
+
attention_head_dim = q.shape[-1]
|
| 401 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 402 |
+
|
| 403 |
+
return flash_attn_ops.fwd_kvcache(
|
| 404 |
+
q,
|
| 405 |
+
kcache,
|
| 406 |
+
vcache,
|
| 407 |
+
k,
|
| 408 |
+
v,
|
| 409 |
+
seqlens_k,
|
| 410 |
+
rotary_cos,
|
| 411 |
+
rotary_sin,
|
| 412 |
+
cache_batch_idx,
|
| 413 |
+
leftpad_k,
|
| 414 |
+
block_table,
|
| 415 |
+
alibi_slopes,
|
| 416 |
+
out,
|
| 417 |
+
softmax_scale,
|
| 418 |
+
is_causal,
|
| 419 |
+
window_size_left,
|
| 420 |
+
window_size_right,
|
| 421 |
+
softcap,
|
| 422 |
+
is_rotary_interleaved,
|
| 423 |
+
num_splits,
|
| 424 |
+
)
|
build/torch-stable-abi210-cu130-aarch64-linux/_flash_attn2_cuda_460047c.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5d3349b4e099095c41123643df2cbff49c7065bf03fb5ae0d88f598cd721e413
|
| 3 |
+
size 1005585784
|
build/torch-stable-abi210-cu130-aarch64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _flash_attn2_cuda_460047c
|
| 3 |
+
ops = torch.ops._flash_attn2_cuda_460047c
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_flash_attn2_cuda_460047c::{op_name}"
|
build/torch-stable-abi210-cu130-aarch64-linux/flash_attn_interface.py
ADDED
|
@@ -0,0 +1,1708 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2023, Tri Dao.
|
| 2 |
+
|
| 3 |
+
from typing import Optional, Sequence, Tuple, Union
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
import torch.nn as nn
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
# # isort: off
|
| 10 |
+
# # We need to import the CUDA kernels after importing torch
|
| 11 |
+
# USE_TRITON_ROCM = os.getenv("FLASH_ATTENTION_TRITON_AMD_ENABLE", "FALSE") == "TRUE"
|
| 12 |
+
# if USE_TRITON_ROCM:
|
| 13 |
+
# from .flash_attn_triton_amd import interface_fa as flash_attn
|
| 14 |
+
# else:
|
| 15 |
+
# import flash_attn_2_cuda as flash_attn
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
from ._ops import ops as flash_attn
|
| 19 |
+
from ._ops import add_op_namespace_prefix
|
| 20 |
+
|
| 21 |
+
# # isort: on
|
| 22 |
+
|
| 23 |
+
# Torch >= 2.13 can pass a Generator through the stable ABI. Older versions reject the argument
|
| 24 |
+
# before the kernel runs, so there the CUDA op has to draw its Philox seed and offset itself.
|
| 25 |
+
_STABLE_ABI_GENERATOR = torch.__version__ >= "2.13"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def maybe_contiguous(x):
|
| 29 |
+
return x.contiguous() if x is not None and x.stride(-1) != 1 else x
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def _get_device():
|
| 33 |
+
if torch.xpu.is_available():
|
| 34 |
+
return "xpu"
|
| 35 |
+
elif torch.cuda.is_available():
|
| 36 |
+
return "cuda"
|
| 37 |
+
else:
|
| 38 |
+
return "cpu"
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def _get_block_size_n(device, head_dim, is_dropout, is_causal):
|
| 42 |
+
assert head_dim <= 256
|
| 43 |
+
|
| 44 |
+
if device.type == "xpu":
|
| 45 |
+
if head_dim <= 96:
|
| 46 |
+
return 64
|
| 47 |
+
elif head_dim <= 128:
|
| 48 |
+
return 32
|
| 49 |
+
elif head_dim <= 256:
|
| 50 |
+
return 64
|
| 51 |
+
else:
|
| 52 |
+
return 32
|
| 53 |
+
|
| 54 |
+
# This should match the block sizes in the CUDA kernel
|
| 55 |
+
major, minor = torch.cuda.get_device_capability(device)
|
| 56 |
+
is_sm8x = (
|
| 57 |
+
major == 8 and minor > 0
|
| 58 |
+
) # Only include sm86 and sm89, exclude sm80 (A100)
|
| 59 |
+
is_sm80 = major == 8 and minor == 0
|
| 60 |
+
is_sm90 = major == 9 and minor == 0
|
| 61 |
+
if head_dim <= 32:
|
| 62 |
+
return 128
|
| 63 |
+
if head_dim <= 64:
|
| 64 |
+
return 128 if not is_dropout else 64
|
| 65 |
+
elif head_dim <= 96:
|
| 66 |
+
return 64
|
| 67 |
+
elif head_dim <= 128:
|
| 68 |
+
if is_sm8x:
|
| 69 |
+
return 64 if (not is_dropout and is_causal) else 32
|
| 70 |
+
else:
|
| 71 |
+
return 64 if not is_dropout else 32
|
| 72 |
+
elif head_dim <= 192:
|
| 73 |
+
return 64
|
| 74 |
+
elif head_dim <= 224:
|
| 75 |
+
return 64
|
| 76 |
+
elif head_dim <= 256:
|
| 77 |
+
return 64
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def round_multiple(x, m):
|
| 81 |
+
return (x + m - 1) // m * m
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def _philox_generator(
|
| 85 |
+
q: torch.Tensor, dropout_p: float, generator: Optional[torch.Generator] = None
|
| 86 |
+
) -> Optional[torch.Generator]:
|
| 87 |
+
"""The generator to hand to `fwd` / `varlen_fwd`.
|
| 88 |
+
|
| 89 |
+
With dropout on CUDA this is the default generator unless one is given, so the kernel reserves
|
| 90 |
+
its seed and offset exactly like the non-stable build (see set_params_philox in flash_api.cpp).
|
| 91 |
+
"""
|
| 92 |
+
if not q.is_cuda:
|
| 93 |
+
return generator
|
| 94 |
+
if dropout_p <= 0:
|
| 95 |
+
return None
|
| 96 |
+
if not _STABLE_ABI_GENERATOR:
|
| 97 |
+
if generator is not None:
|
| 98 |
+
raise ValueError(
|
| 99 |
+
"flash_attn2: passing a generator to the CUDA kernel requires torch >= 2.13; "
|
| 100 |
+
"seed the default generator with torch.manual_seed instead"
|
| 101 |
+
)
|
| 102 |
+
return None
|
| 103 |
+
if generator is None:
|
| 104 |
+
generator = torch.cuda.default_generators[q.device.index]
|
| 105 |
+
return generator
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
@torch.library.custom_op(
|
| 109 |
+
add_op_namespace_prefix("_flash_attn_forward"),
|
| 110 |
+
mutates_args=(),
|
| 111 |
+
device_types=_get_device(),
|
| 112 |
+
# Tells torch.compile the forward draws random numbers, so it is never deduplicated or
|
| 113 |
+
# recomputed (e.g. under activation checkpointing).
|
| 114 |
+
tags=(torch.Tag.nondeterministic_seeded,),
|
| 115 |
+
)
|
| 116 |
+
def _flash_attn_forward(
|
| 117 |
+
q: torch.Tensor,
|
| 118 |
+
k: torch.Tensor,
|
| 119 |
+
v: torch.Tensor,
|
| 120 |
+
dropout_p: float,
|
| 121 |
+
softmax_scale: float,
|
| 122 |
+
causal: bool,
|
| 123 |
+
window_size_left: int,
|
| 124 |
+
window_size_right: int,
|
| 125 |
+
softcap: float,
|
| 126 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 127 |
+
return_softmax: bool,
|
| 128 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 129 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 130 |
+
gen = _philox_generator(q, dropout_p)
|
| 131 |
+
out, softmax_lse, S_dmask, rng_state = flash_attn.fwd(
|
| 132 |
+
q,
|
| 133 |
+
k,
|
| 134 |
+
v,
|
| 135 |
+
None,
|
| 136 |
+
alibi_slopes,
|
| 137 |
+
dropout_p,
|
| 138 |
+
softmax_scale,
|
| 139 |
+
causal,
|
| 140 |
+
window_size_left,
|
| 141 |
+
window_size_right,
|
| 142 |
+
softcap,
|
| 143 |
+
return_softmax,
|
| 144 |
+
gen,
|
| 145 |
+
)
|
| 146 |
+
return out, softmax_lse, S_dmask, rng_state
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_forward"))
|
| 150 |
+
def _flash_attn_forward_fake(
|
| 151 |
+
q: torch.Tensor,
|
| 152 |
+
k: torch.Tensor,
|
| 153 |
+
v: torch.Tensor,
|
| 154 |
+
dropout_p: float,
|
| 155 |
+
softmax_scale: float,
|
| 156 |
+
causal: bool,
|
| 157 |
+
window_size_left: int,
|
| 158 |
+
window_size_right: int,
|
| 159 |
+
softcap: float,
|
| 160 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 161 |
+
return_softmax: bool,
|
| 162 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 163 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 164 |
+
batch_size, seqlen_q, num_heads, head_size = q.shape
|
| 165 |
+
seqlen_k = k.shape[1]
|
| 166 |
+
out = torch.empty_like(q)
|
| 167 |
+
softmax_lse = torch.empty(
|
| 168 |
+
(batch_size, num_heads, seqlen_q),
|
| 169 |
+
dtype=torch.float32,
|
| 170 |
+
device=q.device,
|
| 171 |
+
layout=q.layout,
|
| 172 |
+
)
|
| 173 |
+
p = torch.empty((0,), dtype=q.dtype, device=q.device, layout=q.layout)
|
| 174 |
+
if return_softmax:
|
| 175 |
+
p = torch.empty(
|
| 176 |
+
(
|
| 177 |
+
batch_size,
|
| 178 |
+
num_heads,
|
| 179 |
+
round_multiple(seqlen_q, 128),
|
| 180 |
+
round_multiple(seqlen_k, 128),
|
| 181 |
+
),
|
| 182 |
+
dtype=q.dtype,
|
| 183 |
+
device=q.device,
|
| 184 |
+
layout=q.layout,
|
| 185 |
+
)
|
| 186 |
+
rng_state = torch.empty((2,), dtype=torch.int64, device=q.device)
|
| 187 |
+
|
| 188 |
+
return out, softmax_lse, p, rng_state
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
_wrapped_flash_attn_forward = flash_attn._flash_attn_forward # upstream alias, see CARD.md
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
@torch.library.custom_op(
|
| 195 |
+
add_op_namespace_prefix("_flash_attn_varlen_forward"),
|
| 196 |
+
mutates_args=(),
|
| 197 |
+
device_types=_get_device(),
|
| 198 |
+
tags=(torch.Tag.nondeterministic_seeded,),
|
| 199 |
+
)
|
| 200 |
+
def _flash_attn_varlen_forward(
|
| 201 |
+
q: torch.Tensor,
|
| 202 |
+
k: torch.Tensor,
|
| 203 |
+
v: torch.Tensor,
|
| 204 |
+
cu_seqlens_q: torch.Tensor,
|
| 205 |
+
cu_seqlens_k: torch.Tensor,
|
| 206 |
+
max_seqlen_q: int,
|
| 207 |
+
max_seqlen_k: int,
|
| 208 |
+
dropout_p: float,
|
| 209 |
+
softmax_scale: float,
|
| 210 |
+
causal: bool,
|
| 211 |
+
window_size_left: int = -1,
|
| 212 |
+
window_size_right: int = -1,
|
| 213 |
+
softcap: float = 0.0,
|
| 214 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 215 |
+
return_softmax: bool = False,
|
| 216 |
+
block_table: Optional[torch.Tensor] = None,
|
| 217 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 218 |
+
seqused_k: Optional[torch.Tensor] = None,
|
| 219 |
+
zero_tensors: bool = False,
|
| 220 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 221 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 222 |
+
gen = _philox_generator(q, dropout_p)
|
| 223 |
+
out, softmax_lse, S_dmask, rng_state = flash_attn.varlen_fwd(
|
| 224 |
+
q,
|
| 225 |
+
k,
|
| 226 |
+
v,
|
| 227 |
+
None,
|
| 228 |
+
cu_seqlens_q,
|
| 229 |
+
cu_seqlens_k,
|
| 230 |
+
seqused_k,
|
| 231 |
+
leftpad_k,
|
| 232 |
+
block_table,
|
| 233 |
+
alibi_slopes,
|
| 234 |
+
max_seqlen_q,
|
| 235 |
+
max_seqlen_k,
|
| 236 |
+
dropout_p,
|
| 237 |
+
softmax_scale,
|
| 238 |
+
zero_tensors,
|
| 239 |
+
causal,
|
| 240 |
+
window_size_left,
|
| 241 |
+
window_size_right,
|
| 242 |
+
softcap,
|
| 243 |
+
return_softmax,
|
| 244 |
+
gen,
|
| 245 |
+
)
|
| 246 |
+
# if out.isnan().any() or softmax_lse.isnan().any():
|
| 247 |
+
# breakpoint()
|
| 248 |
+
return out, softmax_lse, S_dmask, rng_state
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_varlen_forward"))
|
| 252 |
+
def _flash_attn_varlen_forward_fake(
|
| 253 |
+
q: torch.Tensor,
|
| 254 |
+
k: torch.Tensor,
|
| 255 |
+
v: torch.Tensor,
|
| 256 |
+
cu_seqlens_q: torch.Tensor,
|
| 257 |
+
cu_seqlens_k: torch.Tensor,
|
| 258 |
+
max_seqlen_q: int,
|
| 259 |
+
max_seqlen_k: int,
|
| 260 |
+
dropout_p: float,
|
| 261 |
+
softmax_scale: float,
|
| 262 |
+
causal: bool,
|
| 263 |
+
window_size_left: int = -1,
|
| 264 |
+
window_size_right: int = -1,
|
| 265 |
+
softcap: float = 0.0,
|
| 266 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 267 |
+
return_softmax: bool = False,
|
| 268 |
+
block_table: Optional[torch.Tensor] = None,
|
| 269 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 270 |
+
seqused_k: Optional[torch.Tensor] = None,
|
| 271 |
+
zero_tensors: bool = False,
|
| 272 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 273 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 274 |
+
paged_kv = block_table is not None
|
| 275 |
+
batch_size = cu_seqlens_q.numel() - 1
|
| 276 |
+
total_q, num_heads, _ = q.shape
|
| 277 |
+
|
| 278 |
+
out = torch.empty_like(q)
|
| 279 |
+
softmax_lse = torch.empty(
|
| 280 |
+
(num_heads, total_q), dtype=torch.float32, device=q.device, layout=q.layout
|
| 281 |
+
)
|
| 282 |
+
p = torch.empty((0,), dtype=q.dtype, device=q.device, layout=q.layout)
|
| 283 |
+
seqlen_q_rounded = round_multiple(max_seqlen_q, 128)
|
| 284 |
+
seqlen_k_rounded = round_multiple(max_seqlen_k, 128)
|
| 285 |
+
if return_softmax:
|
| 286 |
+
p = torch.empty(
|
| 287 |
+
(batch_size, num_heads, seqlen_q_rounded, seqlen_k_rounded),
|
| 288 |
+
dtype=q.dtype,
|
| 289 |
+
device=q.device,
|
| 290 |
+
layout=q.layout,
|
| 291 |
+
)
|
| 292 |
+
rng_state = torch.empty((2,), dtype=torch.int64, device=q.device)
|
| 293 |
+
return out, softmax_lse, p, rng_state
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
_wrapped_flash_attn_varlen_forward = flash_attn._flash_attn_varlen_forward # upstream alias, see CARD.md
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
@torch.library.custom_op(
|
| 300 |
+
add_op_namespace_prefix("_flash_attn_backward"),
|
| 301 |
+
mutates_args=("dq", "dk", "dv"),
|
| 302 |
+
device_types=_get_device(),
|
| 303 |
+
)
|
| 304 |
+
def _flash_attn_backward(
|
| 305 |
+
dout: torch.Tensor,
|
| 306 |
+
q: torch.Tensor,
|
| 307 |
+
k: torch.Tensor,
|
| 308 |
+
v: torch.Tensor,
|
| 309 |
+
out: torch.Tensor,
|
| 310 |
+
softmax_lse: torch.Tensor,
|
| 311 |
+
dq: Optional[torch.Tensor],
|
| 312 |
+
dk: Optional[torch.Tensor],
|
| 313 |
+
dv: Optional[torch.Tensor],
|
| 314 |
+
dropout_p: float,
|
| 315 |
+
softmax_scale: float,
|
| 316 |
+
causal: bool,
|
| 317 |
+
window_size_left: int,
|
| 318 |
+
window_size_right: int,
|
| 319 |
+
softcap: float,
|
| 320 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 321 |
+
deterministic: bool,
|
| 322 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 323 |
+
) -> torch.Tensor:
|
| 324 |
+
# dq, dk, dv are allocated by us so they should already be contiguous
|
| 325 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 326 |
+
(
|
| 327 |
+
dq,
|
| 328 |
+
dk,
|
| 329 |
+
dv,
|
| 330 |
+
softmax_d,
|
| 331 |
+
) = flash_attn.bwd(
|
| 332 |
+
dout,
|
| 333 |
+
q,
|
| 334 |
+
k,
|
| 335 |
+
v,
|
| 336 |
+
out,
|
| 337 |
+
softmax_lse,
|
| 338 |
+
dq,
|
| 339 |
+
dk,
|
| 340 |
+
dv,
|
| 341 |
+
alibi_slopes,
|
| 342 |
+
dropout_p,
|
| 343 |
+
softmax_scale,
|
| 344 |
+
causal,
|
| 345 |
+
window_size_left,
|
| 346 |
+
window_size_right,
|
| 347 |
+
softcap,
|
| 348 |
+
deterministic,
|
| 349 |
+
None,
|
| 350 |
+
rng_state,
|
| 351 |
+
)
|
| 352 |
+
return softmax_d
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_backward"))
|
| 356 |
+
def _flash_attn_backward_fake(
|
| 357 |
+
dout: torch.Tensor,
|
| 358 |
+
q: torch.Tensor,
|
| 359 |
+
k: torch.Tensor,
|
| 360 |
+
v: torch.Tensor,
|
| 361 |
+
out: torch.Tensor,
|
| 362 |
+
softmax_lse: torch.Tensor,
|
| 363 |
+
dq: Optional[torch.Tensor],
|
| 364 |
+
dk: Optional[torch.Tensor],
|
| 365 |
+
dv: Optional[torch.Tensor],
|
| 366 |
+
dropout_p: float,
|
| 367 |
+
softmax_scale: float,
|
| 368 |
+
causal: bool,
|
| 369 |
+
window_size_left: int,
|
| 370 |
+
window_size_right: int,
|
| 371 |
+
softcap: float,
|
| 372 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 373 |
+
deterministic: bool,
|
| 374 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 375 |
+
) -> torch.Tensor:
|
| 376 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 377 |
+
if dq is None:
|
| 378 |
+
dq = torch.empty_like(q)
|
| 379 |
+
if dk is None:
|
| 380 |
+
dk = torch.empty_like(k)
|
| 381 |
+
if dv is None:
|
| 382 |
+
dv = torch.empty_like(v)
|
| 383 |
+
batch_size, seqlen_q, num_heads, _ = q.shape
|
| 384 |
+
softmax_d = torch.empty(
|
| 385 |
+
(batch_size, num_heads, round_multiple(seqlen_q, 128)),
|
| 386 |
+
device=q.device,
|
| 387 |
+
dtype=torch.float32,
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
return softmax_d
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
_wrapped_flash_attn_backward = flash_attn._flash_attn_backward # upstream alias, see CARD.md
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
@torch.library.custom_op(
|
| 397 |
+
add_op_namespace_prefix("_flash_attn_varlen_backward"),
|
| 398 |
+
mutates_args=("dq", "dk", "dv"),
|
| 399 |
+
device_types=_get_device(),
|
| 400 |
+
)
|
| 401 |
+
def _flash_attn_varlen_backward(
|
| 402 |
+
dout: torch.Tensor,
|
| 403 |
+
q: torch.Tensor,
|
| 404 |
+
k: torch.Tensor,
|
| 405 |
+
v: torch.Tensor,
|
| 406 |
+
out: torch.Tensor,
|
| 407 |
+
softmax_lse: torch.Tensor,
|
| 408 |
+
dq: Optional[torch.Tensor],
|
| 409 |
+
dk: Optional[torch.Tensor],
|
| 410 |
+
dv: Optional[torch.Tensor],
|
| 411 |
+
cu_seqlens_q: torch.Tensor,
|
| 412 |
+
cu_seqlens_k: torch.Tensor,
|
| 413 |
+
max_seqlen_q: int,
|
| 414 |
+
max_seqlen_k: int,
|
| 415 |
+
dropout_p: float,
|
| 416 |
+
softmax_scale: float,
|
| 417 |
+
causal: bool,
|
| 418 |
+
window_size_left: int,
|
| 419 |
+
window_size_right: int,
|
| 420 |
+
softcap: float,
|
| 421 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 422 |
+
deterministic: bool,
|
| 423 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 424 |
+
zero_tensors: bool = False,
|
| 425 |
+
) -> torch.Tensor:
|
| 426 |
+
# dq, dk, dv are allocated by us so they should already be contiguous
|
| 427 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 428 |
+
(
|
| 429 |
+
dq,
|
| 430 |
+
dk,
|
| 431 |
+
dv,
|
| 432 |
+
softmax_d,
|
| 433 |
+
) = flash_attn.varlen_bwd(
|
| 434 |
+
dout,
|
| 435 |
+
q,
|
| 436 |
+
k,
|
| 437 |
+
v,
|
| 438 |
+
out,
|
| 439 |
+
softmax_lse,
|
| 440 |
+
dq,
|
| 441 |
+
dk,
|
| 442 |
+
dv,
|
| 443 |
+
cu_seqlens_q,
|
| 444 |
+
cu_seqlens_k,
|
| 445 |
+
alibi_slopes,
|
| 446 |
+
max_seqlen_q,
|
| 447 |
+
max_seqlen_k,
|
| 448 |
+
dropout_p,
|
| 449 |
+
softmax_scale,
|
| 450 |
+
zero_tensors,
|
| 451 |
+
causal,
|
| 452 |
+
window_size_left,
|
| 453 |
+
window_size_right,
|
| 454 |
+
softcap,
|
| 455 |
+
deterministic,
|
| 456 |
+
None,
|
| 457 |
+
rng_state,
|
| 458 |
+
)
|
| 459 |
+
# if dk.isnan().any() or dk.isnan().any() or dv.isnan().any() or softmax_d.isnan().any():
|
| 460 |
+
# breakpoint()
|
| 461 |
+
return softmax_d
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_varlen_backward"))
|
| 465 |
+
def _flash_attn_varlen_backward_fake(
|
| 466 |
+
dout: torch.Tensor,
|
| 467 |
+
q: torch.Tensor,
|
| 468 |
+
k: torch.Tensor,
|
| 469 |
+
v: torch.Tensor,
|
| 470 |
+
out: torch.Tensor,
|
| 471 |
+
softmax_lse: torch.Tensor,
|
| 472 |
+
dq: Optional[torch.Tensor],
|
| 473 |
+
dk: Optional[torch.Tensor],
|
| 474 |
+
dv: Optional[torch.Tensor],
|
| 475 |
+
cu_seqlens_q: torch.Tensor,
|
| 476 |
+
cu_seqlens_k: torch.Tensor,
|
| 477 |
+
max_seqlen_q: int,
|
| 478 |
+
max_seqlen_k: int,
|
| 479 |
+
dropout_p: float,
|
| 480 |
+
softmax_scale: float,
|
| 481 |
+
causal: bool,
|
| 482 |
+
window_size_left: int,
|
| 483 |
+
window_size_right: int,
|
| 484 |
+
softcap: float,
|
| 485 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 486 |
+
deterministic: bool,
|
| 487 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 488 |
+
zero_tensors: bool = False,
|
| 489 |
+
) -> torch.Tensor:
|
| 490 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 491 |
+
batch_size = cu_seqlens_q.numel() - 1
|
| 492 |
+
total_q, num_heads, _ = q.shape
|
| 493 |
+
|
| 494 |
+
if dq is None:
|
| 495 |
+
dq = torch.empty_like(q)
|
| 496 |
+
if dk is None:
|
| 497 |
+
dk = torch.empty_like(k)
|
| 498 |
+
if dv is None:
|
| 499 |
+
dv = torch.empty_like(v)
|
| 500 |
+
softmax_d = torch.empty(
|
| 501 |
+
(num_heads, total_q + 128 * batch_size), device=q.device, dtype=torch.float32
|
| 502 |
+
)
|
| 503 |
+
|
| 504 |
+
return softmax_d
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
_wrapped_flash_attn_varlen_backward = flash_attn._flash_attn_varlen_backward # upstream alias, see CARD.md
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
class FlashAttnQKVPackedFunc(torch.autograd.Function):
|
| 511 |
+
@staticmethod
|
| 512 |
+
def forward(
|
| 513 |
+
ctx,
|
| 514 |
+
qkv,
|
| 515 |
+
dropout_p,
|
| 516 |
+
softmax_scale,
|
| 517 |
+
causal,
|
| 518 |
+
window_size,
|
| 519 |
+
softcap,
|
| 520 |
+
alibi_slopes,
|
| 521 |
+
deterministic,
|
| 522 |
+
return_softmax,
|
| 523 |
+
is_grad_enabled,
|
| 524 |
+
):
|
| 525 |
+
is_grad = is_grad_enabled and qkv.requires_grad
|
| 526 |
+
if softmax_scale is None:
|
| 527 |
+
softmax_scale = qkv.shape[-1] ** (-0.5)
|
| 528 |
+
q, k, v = qkv[:, :, 0].detach(), qkv[:, :, 1].detach(), qkv[:, :, 2].detach()
|
| 529 |
+
head_size_og = q.size(3)
|
| 530 |
+
if head_size_og % 8 != 0:
|
| 531 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 532 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 533 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 534 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_forward(
|
| 535 |
+
q,
|
| 536 |
+
k,
|
| 537 |
+
v,
|
| 538 |
+
dropout_p,
|
| 539 |
+
softmax_scale,
|
| 540 |
+
causal=causal,
|
| 541 |
+
window_size_left=window_size[0],
|
| 542 |
+
window_size_right=window_size[1],
|
| 543 |
+
softcap=softcap,
|
| 544 |
+
alibi_slopes=alibi_slopes,
|
| 545 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 546 |
+
)
|
| 547 |
+
if is_grad:
|
| 548 |
+
ctx.save_for_backward(q, k, v, out_padded, softmax_lse, rng_state)
|
| 549 |
+
ctx.dropout_p = dropout_p
|
| 550 |
+
ctx.softmax_scale = softmax_scale
|
| 551 |
+
ctx.causal = causal
|
| 552 |
+
ctx.window_size = window_size
|
| 553 |
+
ctx.softcap = softcap
|
| 554 |
+
ctx.alibi_slopes = alibi_slopes
|
| 555 |
+
ctx.deterministic = deterministic
|
| 556 |
+
out = out_padded[..., :head_size_og]
|
| 557 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 558 |
+
|
| 559 |
+
@staticmethod
|
| 560 |
+
def backward(ctx, dout, *args):
|
| 561 |
+
q, k, v, out, softmax_lse, rng_state = ctx.saved_tensors
|
| 562 |
+
qkv_shape = q.shape[:-2] + (3, *q.shape[-2:])
|
| 563 |
+
dqkv = torch.empty(qkv_shape, dtype=q.dtype, device=q.device)
|
| 564 |
+
head_size_og = dout.size(3)
|
| 565 |
+
dout_padded = dout
|
| 566 |
+
if head_size_og % 8 != 0:
|
| 567 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 568 |
+
_flash_attn_backward(
|
| 569 |
+
dout_padded,
|
| 570 |
+
q,
|
| 571 |
+
k,
|
| 572 |
+
v,
|
| 573 |
+
out,
|
| 574 |
+
softmax_lse,
|
| 575 |
+
dqkv[:, :, 0],
|
| 576 |
+
dqkv[:, :, 1],
|
| 577 |
+
dqkv[:, :, 2],
|
| 578 |
+
ctx.dropout_p,
|
| 579 |
+
ctx.softmax_scale,
|
| 580 |
+
ctx.causal,
|
| 581 |
+
ctx.window_size[0],
|
| 582 |
+
ctx.window_size[1],
|
| 583 |
+
ctx.softcap,
|
| 584 |
+
ctx.alibi_slopes,
|
| 585 |
+
ctx.deterministic,
|
| 586 |
+
rng_state=rng_state,
|
| 587 |
+
)
|
| 588 |
+
dqkv = dqkv[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 589 |
+
return dqkv, None, None, None, None, None, None, None, None, None
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
class FlashAttnVarlenQKVPackedFunc(torch.autograd.Function):
|
| 593 |
+
@staticmethod
|
| 594 |
+
def forward(
|
| 595 |
+
ctx,
|
| 596 |
+
qkv,
|
| 597 |
+
cu_seqlens,
|
| 598 |
+
max_seqlen,
|
| 599 |
+
dropout_p,
|
| 600 |
+
softmax_scale,
|
| 601 |
+
causal,
|
| 602 |
+
window_size,
|
| 603 |
+
softcap,
|
| 604 |
+
alibi_slopes,
|
| 605 |
+
deterministic,
|
| 606 |
+
return_softmax,
|
| 607 |
+
is_grad_enabled,
|
| 608 |
+
):
|
| 609 |
+
is_grad = is_grad_enabled and qkv.requires_grad
|
| 610 |
+
if softmax_scale is None:
|
| 611 |
+
softmax_scale = qkv.shape[-1] ** (-0.5)
|
| 612 |
+
q, k, v = qkv[:, 0].detach(), qkv[:, 1].detach(), qkv[:, 2].detach()
|
| 613 |
+
head_size_og = q.size(2)
|
| 614 |
+
if head_size_og % 8 != 0:
|
| 615 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 616 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 617 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 618 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_varlen_forward(
|
| 619 |
+
q,
|
| 620 |
+
k,
|
| 621 |
+
v,
|
| 622 |
+
cu_seqlens,
|
| 623 |
+
cu_seqlens,
|
| 624 |
+
max_seqlen,
|
| 625 |
+
max_seqlen,
|
| 626 |
+
dropout_p,
|
| 627 |
+
softmax_scale,
|
| 628 |
+
causal=causal,
|
| 629 |
+
window_size_left=window_size[0],
|
| 630 |
+
window_size_right=window_size[1],
|
| 631 |
+
softcap=softcap,
|
| 632 |
+
alibi_slopes=alibi_slopes,
|
| 633 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 634 |
+
block_table=None,
|
| 635 |
+
)
|
| 636 |
+
if is_grad:
|
| 637 |
+
ctx.save_for_backward(
|
| 638 |
+
q, k, v, out_padded, softmax_lse, cu_seqlens, rng_state
|
| 639 |
+
)
|
| 640 |
+
ctx.dropout_p = dropout_p
|
| 641 |
+
ctx.max_seqlen = max_seqlen
|
| 642 |
+
ctx.softmax_scale = softmax_scale
|
| 643 |
+
ctx.causal = causal
|
| 644 |
+
ctx.window_size = window_size
|
| 645 |
+
ctx.softcap = softcap
|
| 646 |
+
ctx.alibi_slopes = alibi_slopes
|
| 647 |
+
ctx.deterministic = deterministic
|
| 648 |
+
out = out_padded[..., :head_size_og]
|
| 649 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 650 |
+
|
| 651 |
+
@staticmethod
|
| 652 |
+
def backward(ctx, dout, *args):
|
| 653 |
+
q, k, v, out, softmax_lse, cu_seqlens, rng_state = ctx.saved_tensors
|
| 654 |
+
qkv_shape = q.shape[:-2] + (3, *q.shape[-2:])
|
| 655 |
+
dqkv = torch.empty(qkv_shape, dtype=q.dtype, device=q.device)
|
| 656 |
+
head_size_og = dout.size(2)
|
| 657 |
+
dout_padded = dout
|
| 658 |
+
if head_size_og % 8 != 0:
|
| 659 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 660 |
+
_flash_attn_varlen_backward(
|
| 661 |
+
dout_padded,
|
| 662 |
+
q,
|
| 663 |
+
k,
|
| 664 |
+
v,
|
| 665 |
+
out,
|
| 666 |
+
softmax_lse,
|
| 667 |
+
dqkv[:, 0],
|
| 668 |
+
dqkv[:, 1],
|
| 669 |
+
dqkv[:, 2],
|
| 670 |
+
cu_seqlens,
|
| 671 |
+
cu_seqlens,
|
| 672 |
+
ctx.max_seqlen,
|
| 673 |
+
ctx.max_seqlen,
|
| 674 |
+
ctx.dropout_p,
|
| 675 |
+
ctx.softmax_scale,
|
| 676 |
+
ctx.causal,
|
| 677 |
+
ctx.window_size[0],
|
| 678 |
+
ctx.window_size[1],
|
| 679 |
+
ctx.softcap,
|
| 680 |
+
ctx.alibi_slopes,
|
| 681 |
+
ctx.deterministic,
|
| 682 |
+
rng_state=rng_state,
|
| 683 |
+
)
|
| 684 |
+
dqkv = dqkv[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 685 |
+
return dqkv, None, None, None, None, None, None, None, None, None, None, None
|
| 686 |
+
|
| 687 |
+
|
| 688 |
+
class FlashAttnKVPackedFunc(torch.autograd.Function):
|
| 689 |
+
@staticmethod
|
| 690 |
+
def forward(
|
| 691 |
+
ctx,
|
| 692 |
+
q,
|
| 693 |
+
kv,
|
| 694 |
+
dropout_p,
|
| 695 |
+
softmax_scale,
|
| 696 |
+
causal,
|
| 697 |
+
window_size,
|
| 698 |
+
softcap,
|
| 699 |
+
alibi_slopes,
|
| 700 |
+
deterministic,
|
| 701 |
+
return_softmax,
|
| 702 |
+
is_grad_enabled,
|
| 703 |
+
):
|
| 704 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, kv])
|
| 705 |
+
if softmax_scale is None:
|
| 706 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 707 |
+
k, v = kv[:, :, 0].detach(), kv[:, :, 1].detach()
|
| 708 |
+
head_size_og = q.size(3)
|
| 709 |
+
if head_size_og % 8 != 0:
|
| 710 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 711 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 712 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 713 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_forward(
|
| 714 |
+
q,
|
| 715 |
+
k,
|
| 716 |
+
v,
|
| 717 |
+
dropout_p,
|
| 718 |
+
softmax_scale,
|
| 719 |
+
causal=causal,
|
| 720 |
+
window_size_left=window_size[0],
|
| 721 |
+
window_size_right=window_size[1],
|
| 722 |
+
softcap=softcap,
|
| 723 |
+
alibi_slopes=alibi_slopes,
|
| 724 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 725 |
+
)
|
| 726 |
+
if is_grad:
|
| 727 |
+
ctx.save_for_backward(q, k, v, out_padded, softmax_lse, rng_state)
|
| 728 |
+
ctx.dropout_p = dropout_p
|
| 729 |
+
ctx.softmax_scale = softmax_scale
|
| 730 |
+
ctx.causal = causal
|
| 731 |
+
ctx.window_size = window_size
|
| 732 |
+
ctx.softcap = softcap
|
| 733 |
+
ctx.alibi_slopes = alibi_slopes
|
| 734 |
+
ctx.deterministic = deterministic
|
| 735 |
+
out = out_padded[..., :head_size_og]
|
| 736 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 737 |
+
|
| 738 |
+
@staticmethod
|
| 739 |
+
def backward(ctx, dout, *args):
|
| 740 |
+
q, k, v, out, softmax_lse, rng_state = ctx.saved_tensors
|
| 741 |
+
dq = torch.empty_like(q)
|
| 742 |
+
kv_shape = k.shape[:-2] + (2, *k.shape[-2:])
|
| 743 |
+
dkv = torch.empty(kv_shape, dtype=k.dtype, device=k.device)
|
| 744 |
+
head_size_og = dout.size(3)
|
| 745 |
+
dout_padded = dout
|
| 746 |
+
if head_size_og % 8 != 0:
|
| 747 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 748 |
+
_flash_attn_backward(
|
| 749 |
+
dout_padded,
|
| 750 |
+
q,
|
| 751 |
+
k,
|
| 752 |
+
v,
|
| 753 |
+
out,
|
| 754 |
+
softmax_lse,
|
| 755 |
+
dq,
|
| 756 |
+
dkv[:, :, 0],
|
| 757 |
+
dkv[:, :, 1],
|
| 758 |
+
ctx.dropout_p,
|
| 759 |
+
ctx.softmax_scale,
|
| 760 |
+
ctx.causal,
|
| 761 |
+
ctx.window_size[0],
|
| 762 |
+
ctx.window_size[1],
|
| 763 |
+
ctx.softcap,
|
| 764 |
+
ctx.alibi_slopes,
|
| 765 |
+
ctx.deterministic,
|
| 766 |
+
rng_state=rng_state,
|
| 767 |
+
)
|
| 768 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 769 |
+
dkv = dkv[..., : dout.shape[-1]]
|
| 770 |
+
return dq, dkv, None, None, None, None, None, None, None, None, None
|
| 771 |
+
|
| 772 |
+
|
| 773 |
+
class FlashAttnVarlenKVPackedFunc(torch.autograd.Function):
|
| 774 |
+
@staticmethod
|
| 775 |
+
def forward(
|
| 776 |
+
ctx,
|
| 777 |
+
q,
|
| 778 |
+
kv,
|
| 779 |
+
cu_seqlens_q,
|
| 780 |
+
cu_seqlens_k,
|
| 781 |
+
max_seqlen_q,
|
| 782 |
+
max_seqlen_k,
|
| 783 |
+
dropout_p,
|
| 784 |
+
softmax_scale,
|
| 785 |
+
causal,
|
| 786 |
+
window_size,
|
| 787 |
+
softcap,
|
| 788 |
+
alibi_slopes,
|
| 789 |
+
deterministic,
|
| 790 |
+
return_softmax,
|
| 791 |
+
is_grad_enabled,
|
| 792 |
+
):
|
| 793 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, kv])
|
| 794 |
+
if softmax_scale is None:
|
| 795 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 796 |
+
k, v = kv[:, 0].detach(), kv[:, 1].detach()
|
| 797 |
+
head_size_og = q.size(2)
|
| 798 |
+
if head_size_og % 8 != 0:
|
| 799 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 800 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 801 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 802 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_varlen_forward(
|
| 803 |
+
q,
|
| 804 |
+
k,
|
| 805 |
+
v,
|
| 806 |
+
cu_seqlens_q,
|
| 807 |
+
cu_seqlens_k,
|
| 808 |
+
max_seqlen_q,
|
| 809 |
+
max_seqlen_k,
|
| 810 |
+
dropout_p,
|
| 811 |
+
softmax_scale,
|
| 812 |
+
causal=causal,
|
| 813 |
+
window_size_left=window_size[0],
|
| 814 |
+
window_size_right=window_size[1],
|
| 815 |
+
softcap=softcap,
|
| 816 |
+
alibi_slopes=alibi_slopes,
|
| 817 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 818 |
+
block_table=None,
|
| 819 |
+
)
|
| 820 |
+
if is_grad:
|
| 821 |
+
ctx.save_for_backward(
|
| 822 |
+
q, k, v, out_padded, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state
|
| 823 |
+
)
|
| 824 |
+
ctx.dropout_p = dropout_p
|
| 825 |
+
ctx.max_seqlen_q = max_seqlen_q
|
| 826 |
+
ctx.max_seqlen_k = max_seqlen_k
|
| 827 |
+
ctx.softmax_scale = softmax_scale
|
| 828 |
+
ctx.causal = causal
|
| 829 |
+
ctx.window_size = window_size
|
| 830 |
+
ctx.softcap = softcap
|
| 831 |
+
ctx.alibi_slopes = alibi_slopes
|
| 832 |
+
ctx.deterministic = deterministic
|
| 833 |
+
out = out_padded[..., :head_size_og]
|
| 834 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 835 |
+
|
| 836 |
+
@staticmethod
|
| 837 |
+
def backward(ctx, dout, *args):
|
| 838 |
+
q, k, v, out, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state = (
|
| 839 |
+
ctx.saved_tensors
|
| 840 |
+
)
|
| 841 |
+
dq = torch.empty_like(q)
|
| 842 |
+
kv_shape = k.shape[:-2] + (2, *k.shape[-2:])
|
| 843 |
+
dkv = torch.empty(kv_shape, dtype=k.dtype, device=k.device)
|
| 844 |
+
head_size_og = dout.size(2)
|
| 845 |
+
dout_padded = dout
|
| 846 |
+
if head_size_og % 8 != 0:
|
| 847 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 848 |
+
_flash_attn_varlen_backward(
|
| 849 |
+
dout_padded,
|
| 850 |
+
q,
|
| 851 |
+
k,
|
| 852 |
+
v,
|
| 853 |
+
out,
|
| 854 |
+
softmax_lse,
|
| 855 |
+
dq,
|
| 856 |
+
dkv[:, 0],
|
| 857 |
+
dkv[:, 1],
|
| 858 |
+
cu_seqlens_q,
|
| 859 |
+
cu_seqlens_k,
|
| 860 |
+
ctx.max_seqlen_q,
|
| 861 |
+
ctx.max_seqlen_k,
|
| 862 |
+
ctx.dropout_p,
|
| 863 |
+
ctx.softmax_scale,
|
| 864 |
+
ctx.causal,
|
| 865 |
+
ctx.window_size[0],
|
| 866 |
+
ctx.window_size[1],
|
| 867 |
+
ctx.softcap,
|
| 868 |
+
ctx.alibi_slopes,
|
| 869 |
+
ctx.deterministic,
|
| 870 |
+
rng_state=rng_state,
|
| 871 |
+
)
|
| 872 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 873 |
+
dkv = dkv[..., : dout.shape[-1]]
|
| 874 |
+
return (
|
| 875 |
+
dq,
|
| 876 |
+
dkv,
|
| 877 |
+
None,
|
| 878 |
+
None,
|
| 879 |
+
None,
|
| 880 |
+
None,
|
| 881 |
+
None,
|
| 882 |
+
None,
|
| 883 |
+
None,
|
| 884 |
+
None,
|
| 885 |
+
None,
|
| 886 |
+
None,
|
| 887 |
+
None,
|
| 888 |
+
None,
|
| 889 |
+
None,
|
| 890 |
+
)
|
| 891 |
+
|
| 892 |
+
|
| 893 |
+
class FlashAttnFunc(torch.autograd.Function):
|
| 894 |
+
@staticmethod
|
| 895 |
+
def forward(
|
| 896 |
+
ctx,
|
| 897 |
+
q,
|
| 898 |
+
k,
|
| 899 |
+
v,
|
| 900 |
+
dropout_p,
|
| 901 |
+
softmax_scale,
|
| 902 |
+
causal,
|
| 903 |
+
window_size,
|
| 904 |
+
softcap,
|
| 905 |
+
alibi_slopes,
|
| 906 |
+
deterministic,
|
| 907 |
+
return_softmax,
|
| 908 |
+
is_grad_enabled,
|
| 909 |
+
):
|
| 910 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, k, v])
|
| 911 |
+
if softmax_scale is None:
|
| 912 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 913 |
+
head_size_og = q.size(3)
|
| 914 |
+
if head_size_og % 8 != 0:
|
| 915 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 916 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 917 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 918 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_forward(
|
| 919 |
+
q,
|
| 920 |
+
k,
|
| 921 |
+
v,
|
| 922 |
+
dropout_p,
|
| 923 |
+
softmax_scale,
|
| 924 |
+
causal=causal,
|
| 925 |
+
window_size_left=window_size[0],
|
| 926 |
+
window_size_right=window_size[1],
|
| 927 |
+
softcap=softcap,
|
| 928 |
+
alibi_slopes=alibi_slopes,
|
| 929 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 930 |
+
)
|
| 931 |
+
if is_grad:
|
| 932 |
+
ctx.save_for_backward(q, k, v, out_padded, softmax_lse, rng_state)
|
| 933 |
+
ctx.dropout_p = dropout_p
|
| 934 |
+
ctx.softmax_scale = softmax_scale
|
| 935 |
+
ctx.causal = causal
|
| 936 |
+
ctx.window_size = window_size
|
| 937 |
+
ctx.softcap = softcap
|
| 938 |
+
ctx.alibi_slopes = alibi_slopes
|
| 939 |
+
ctx.deterministic = deterministic
|
| 940 |
+
out = out_padded[..., :head_size_og]
|
| 941 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 942 |
+
|
| 943 |
+
@staticmethod
|
| 944 |
+
def backward(ctx, dout, *args):
|
| 945 |
+
q, k, v, out, softmax_lse, rng_state = ctx.saved_tensors
|
| 946 |
+
dq, dk, dv = torch.empty_like(q), torch.empty_like(k), torch.empty_like(v)
|
| 947 |
+
head_size_og = dout.size(3)
|
| 948 |
+
dout_padded = dout
|
| 949 |
+
if head_size_og % 8 != 0:
|
| 950 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 951 |
+
_flash_attn_backward(
|
| 952 |
+
dout_padded,
|
| 953 |
+
q,
|
| 954 |
+
k,
|
| 955 |
+
v,
|
| 956 |
+
out,
|
| 957 |
+
softmax_lse,
|
| 958 |
+
dq,
|
| 959 |
+
dk,
|
| 960 |
+
dv,
|
| 961 |
+
ctx.dropout_p,
|
| 962 |
+
ctx.softmax_scale,
|
| 963 |
+
ctx.causal,
|
| 964 |
+
ctx.window_size[0],
|
| 965 |
+
ctx.window_size[1],
|
| 966 |
+
ctx.softcap,
|
| 967 |
+
ctx.alibi_slopes,
|
| 968 |
+
ctx.deterministic,
|
| 969 |
+
rng_state=rng_state,
|
| 970 |
+
)
|
| 971 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 972 |
+
dk = dk[..., : dout.shape[-1]]
|
| 973 |
+
dv = dv[..., : dout.shape[-1]]
|
| 974 |
+
return dq, dk, dv, None, None, None, None, None, None, None, None, None
|
| 975 |
+
|
| 976 |
+
|
| 977 |
+
class FlashAttnVarlenFunc(torch.autograd.Function):
|
| 978 |
+
@staticmethod
|
| 979 |
+
def forward(
|
| 980 |
+
ctx,
|
| 981 |
+
q,
|
| 982 |
+
k,
|
| 983 |
+
v,
|
| 984 |
+
cu_seqlens_q,
|
| 985 |
+
cu_seqlens_k,
|
| 986 |
+
max_seqlen_q,
|
| 987 |
+
max_seqlen_k,
|
| 988 |
+
dropout_p,
|
| 989 |
+
softmax_scale,
|
| 990 |
+
causal,
|
| 991 |
+
window_size,
|
| 992 |
+
softcap,
|
| 993 |
+
alibi_slopes,
|
| 994 |
+
deterministic,
|
| 995 |
+
return_softmax,
|
| 996 |
+
block_table,
|
| 997 |
+
is_grad_enabled,
|
| 998 |
+
):
|
| 999 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, k, v])
|
| 1000 |
+
if softmax_scale is None:
|
| 1001 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 1002 |
+
head_size_og = q.size(2)
|
| 1003 |
+
if head_size_og % 8 != 0:
|
| 1004 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 1005 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 1006 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 1007 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_varlen_forward(
|
| 1008 |
+
q,
|
| 1009 |
+
k,
|
| 1010 |
+
v,
|
| 1011 |
+
cu_seqlens_q,
|
| 1012 |
+
cu_seqlens_k,
|
| 1013 |
+
max_seqlen_q,
|
| 1014 |
+
max_seqlen_k,
|
| 1015 |
+
dropout_p,
|
| 1016 |
+
softmax_scale,
|
| 1017 |
+
causal=causal,
|
| 1018 |
+
window_size_left=window_size[0],
|
| 1019 |
+
window_size_right=window_size[1],
|
| 1020 |
+
softcap=softcap,
|
| 1021 |
+
alibi_slopes=alibi_slopes,
|
| 1022 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 1023 |
+
block_table=block_table,
|
| 1024 |
+
)
|
| 1025 |
+
if is_grad:
|
| 1026 |
+
ctx.save_for_backward(
|
| 1027 |
+
q, k, v, out_padded, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state
|
| 1028 |
+
)
|
| 1029 |
+
ctx.dropout_p = dropout_p
|
| 1030 |
+
ctx.max_seqlen_q = max_seqlen_q
|
| 1031 |
+
ctx.max_seqlen_k = max_seqlen_k
|
| 1032 |
+
ctx.softmax_scale = softmax_scale
|
| 1033 |
+
ctx.causal = causal
|
| 1034 |
+
ctx.window_size = window_size
|
| 1035 |
+
ctx.softcap = softcap
|
| 1036 |
+
ctx.alibi_slopes = alibi_slopes
|
| 1037 |
+
ctx.deterministic = deterministic
|
| 1038 |
+
|
| 1039 |
+
out = out_padded[..., :head_size_og]
|
| 1040 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 1041 |
+
|
| 1042 |
+
@staticmethod
|
| 1043 |
+
def backward(ctx, dout, *args):
|
| 1044 |
+
q, k, v, out, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state = (
|
| 1045 |
+
ctx.saved_tensors
|
| 1046 |
+
)
|
| 1047 |
+
dq, dk, dv = torch.empty_like(q), torch.empty_like(k), torch.empty_like(v)
|
| 1048 |
+
head_size_og = dout.size(2)
|
| 1049 |
+
dout_padded = dout
|
| 1050 |
+
if head_size_og % 8 != 0:
|
| 1051 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 1052 |
+
_flash_attn_varlen_backward(
|
| 1053 |
+
dout_padded,
|
| 1054 |
+
q,
|
| 1055 |
+
k,
|
| 1056 |
+
v,
|
| 1057 |
+
out,
|
| 1058 |
+
softmax_lse,
|
| 1059 |
+
dq,
|
| 1060 |
+
dk,
|
| 1061 |
+
dv,
|
| 1062 |
+
cu_seqlens_q,
|
| 1063 |
+
cu_seqlens_k,
|
| 1064 |
+
ctx.max_seqlen_q,
|
| 1065 |
+
ctx.max_seqlen_k,
|
| 1066 |
+
ctx.dropout_p,
|
| 1067 |
+
ctx.softmax_scale,
|
| 1068 |
+
ctx.causal,
|
| 1069 |
+
ctx.window_size[0],
|
| 1070 |
+
ctx.window_size[1],
|
| 1071 |
+
ctx.softcap,
|
| 1072 |
+
ctx.alibi_slopes,
|
| 1073 |
+
ctx.deterministic,
|
| 1074 |
+
rng_state=rng_state,
|
| 1075 |
+
)
|
| 1076 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 1077 |
+
dk = dk[..., : dout.shape[-1]]
|
| 1078 |
+
dv = dv[..., : dout.shape[-1]]
|
| 1079 |
+
return (
|
| 1080 |
+
dq,
|
| 1081 |
+
dk,
|
| 1082 |
+
dv,
|
| 1083 |
+
None,
|
| 1084 |
+
None,
|
| 1085 |
+
None,
|
| 1086 |
+
None,
|
| 1087 |
+
None,
|
| 1088 |
+
None,
|
| 1089 |
+
None,
|
| 1090 |
+
None,
|
| 1091 |
+
None,
|
| 1092 |
+
None,
|
| 1093 |
+
None,
|
| 1094 |
+
None,
|
| 1095 |
+
None,
|
| 1096 |
+
None,
|
| 1097 |
+
)
|
| 1098 |
+
|
| 1099 |
+
|
| 1100 |
+
def flash_attn_qkvpacked_func(
|
| 1101 |
+
qkv,
|
| 1102 |
+
dropout_p=0.0,
|
| 1103 |
+
softmax_scale=None,
|
| 1104 |
+
causal=False,
|
| 1105 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1106 |
+
softcap=0.0, # <=0.0 means deactivate
|
| 1107 |
+
alibi_slopes=None,
|
| 1108 |
+
deterministic=False,
|
| 1109 |
+
return_attn_probs=False,
|
| 1110 |
+
):
|
| 1111 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1112 |
+
If Q, K, V are already stacked into 1 tensor, this function will be faster than
|
| 1113 |
+
calling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1114 |
+
of the gradients of Q, K, V.
|
| 1115 |
+
For multi-query and grouped-query attention (MQA/GQA), please see
|
| 1116 |
+
flash_attn_kvpacked_func and flash_attn_func.
|
| 1117 |
+
|
| 1118 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1119 |
+
will only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.
|
| 1120 |
+
|
| 1121 |
+
Arguments:
|
| 1122 |
+
qkv: (batch_size, seqlen, 3, nheads, headdim)
|
| 1123 |
+
dropout_p: float. Dropout probability.
|
| 1124 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1125 |
+
Default to 1 / sqrt(headdim).
|
| 1126 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1127 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1128 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1129 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|) is added to
|
| 1130 |
+
the attention score of query i and key j.
|
| 1131 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1132 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1133 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1134 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1135 |
+
(they might not have the right scaling).
|
| 1136 |
+
Return:
|
| 1137 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1138 |
+
softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The
|
| 1139 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1140 |
+
normalization factor).
|
| 1141 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1142 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1143 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1144 |
+
"""
|
| 1145 |
+
return FlashAttnQKVPackedFunc.apply(
|
| 1146 |
+
qkv,
|
| 1147 |
+
dropout_p,
|
| 1148 |
+
softmax_scale,
|
| 1149 |
+
causal,
|
| 1150 |
+
window_size,
|
| 1151 |
+
softcap,
|
| 1152 |
+
alibi_slopes,
|
| 1153 |
+
deterministic,
|
| 1154 |
+
return_attn_probs,
|
| 1155 |
+
torch.is_grad_enabled(),
|
| 1156 |
+
)
|
| 1157 |
+
|
| 1158 |
+
|
| 1159 |
+
def flash_attn_kvpacked_func(
|
| 1160 |
+
q,
|
| 1161 |
+
kv,
|
| 1162 |
+
dropout_p=0.0,
|
| 1163 |
+
softmax_scale=None,
|
| 1164 |
+
causal=False,
|
| 1165 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1166 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1167 |
+
alibi_slopes=None,
|
| 1168 |
+
deterministic=False,
|
| 1169 |
+
return_attn_probs=False,
|
| 1170 |
+
):
|
| 1171 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1172 |
+
If K, V are already stacked into 1 tensor, this function will be faster than
|
| 1173 |
+
calling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1174 |
+
of the gradients of K, V.
|
| 1175 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1176 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1177 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1178 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1179 |
+
|
| 1180 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1181 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1182 |
+
1 1 1 1 0
|
| 1183 |
+
1 1 1 1 1
|
| 1184 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1185 |
+
0 0
|
| 1186 |
+
0 0
|
| 1187 |
+
0 0
|
| 1188 |
+
1 0
|
| 1189 |
+
1 1
|
| 1190 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1191 |
+
|
| 1192 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1193 |
+
will only attend to keys between
|
| 1194 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1195 |
+
|
| 1196 |
+
Arguments:
|
| 1197 |
+
q: (batch_size, seqlen, nheads, headdim)
|
| 1198 |
+
kv: (batch_size, seqlen, 2, nheads_k, headdim)
|
| 1199 |
+
dropout_p: float. Dropout probability.
|
| 1200 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1201 |
+
Default to 1 / sqrt(headdim).
|
| 1202 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1203 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1204 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1205 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1206 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1207 |
+
is added to the attention score of query i and key j.
|
| 1208 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1209 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1210 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1211 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1212 |
+
(they might not have the right scaling).
|
| 1213 |
+
Return:
|
| 1214 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1215 |
+
softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The
|
| 1216 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1217 |
+
normalization factor).
|
| 1218 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1219 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1220 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1221 |
+
"""
|
| 1222 |
+
return FlashAttnKVPackedFunc.apply(
|
| 1223 |
+
q,
|
| 1224 |
+
kv,
|
| 1225 |
+
dropout_p,
|
| 1226 |
+
softmax_scale,
|
| 1227 |
+
causal,
|
| 1228 |
+
window_size,
|
| 1229 |
+
softcap,
|
| 1230 |
+
alibi_slopes,
|
| 1231 |
+
deterministic,
|
| 1232 |
+
return_attn_probs,
|
| 1233 |
+
torch.is_grad_enabled(),
|
| 1234 |
+
)
|
| 1235 |
+
|
| 1236 |
+
|
| 1237 |
+
def flash_attn_func(
|
| 1238 |
+
q,
|
| 1239 |
+
k,
|
| 1240 |
+
v,
|
| 1241 |
+
dropout_p=0.0,
|
| 1242 |
+
softmax_scale=None,
|
| 1243 |
+
causal=False,
|
| 1244 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1245 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1246 |
+
alibi_slopes=None,
|
| 1247 |
+
deterministic=False,
|
| 1248 |
+
return_attn_probs=False,
|
| 1249 |
+
):
|
| 1250 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1251 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1252 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1253 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1254 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1255 |
+
|
| 1256 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1257 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1258 |
+
1 1 1 1 0
|
| 1259 |
+
1 1 1 1 1
|
| 1260 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1261 |
+
0 0
|
| 1262 |
+
0 0
|
| 1263 |
+
0 0
|
| 1264 |
+
1 0
|
| 1265 |
+
1 1
|
| 1266 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1267 |
+
|
| 1268 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1269 |
+
will only attend to keys between
|
| 1270 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1271 |
+
|
| 1272 |
+
Arguments:
|
| 1273 |
+
q: (batch_size, seqlen, nheads, headdim)
|
| 1274 |
+
k: (batch_size, seqlen, nheads_k, headdim)
|
| 1275 |
+
v: (batch_size, seqlen, nheads_k, headdim)
|
| 1276 |
+
dropout_p: float. Dropout probability.
|
| 1277 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1278 |
+
Default to 1 / sqrt(headdim).
|
| 1279 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1280 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1281 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1282 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1283 |
+
is added to the attention score of query i and key j.
|
| 1284 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1285 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1286 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1287 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1288 |
+
(they might not have the right scaling).
|
| 1289 |
+
Return:
|
| 1290 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1291 |
+
softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The
|
| 1292 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1293 |
+
normalization factor).
|
| 1294 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1295 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1296 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1297 |
+
"""
|
| 1298 |
+
return FlashAttnFunc.apply(
|
| 1299 |
+
q,
|
| 1300 |
+
k,
|
| 1301 |
+
v,
|
| 1302 |
+
dropout_p,
|
| 1303 |
+
softmax_scale,
|
| 1304 |
+
causal,
|
| 1305 |
+
window_size,
|
| 1306 |
+
softcap,
|
| 1307 |
+
alibi_slopes,
|
| 1308 |
+
deterministic,
|
| 1309 |
+
return_attn_probs,
|
| 1310 |
+
torch.is_grad_enabled(),
|
| 1311 |
+
)
|
| 1312 |
+
|
| 1313 |
+
|
| 1314 |
+
def flash_attn_varlen_qkvpacked_func(
|
| 1315 |
+
qkv,
|
| 1316 |
+
cu_seqlens,
|
| 1317 |
+
max_seqlen,
|
| 1318 |
+
dropout_p=0.0,
|
| 1319 |
+
softmax_scale=None,
|
| 1320 |
+
causal=False,
|
| 1321 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1322 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1323 |
+
alibi_slopes=None,
|
| 1324 |
+
deterministic=False,
|
| 1325 |
+
return_attn_probs=False,
|
| 1326 |
+
):
|
| 1327 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1328 |
+
If Q, K, V are already stacked into 1 tensor, this function will be faster than
|
| 1329 |
+
calling flash_attn_varlen_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1330 |
+
of the gradients of Q, K, V.
|
| 1331 |
+
For multi-query and grouped-query attention (MQA/GQA), please see
|
| 1332 |
+
flash_attn_varlen_kvpacked_func and flash_attn_varlen_func.
|
| 1333 |
+
|
| 1334 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1335 |
+
will only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.
|
| 1336 |
+
|
| 1337 |
+
Arguments:
|
| 1338 |
+
qkv: (total, 3, nheads, headdim), where total = total number of tokens in the batch.
|
| 1339 |
+
cu_seqlens: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1340 |
+
of the sequences in the batch, used to index into qkv.
|
| 1341 |
+
max_seqlen: int. Maximum sequence length in the batch.
|
| 1342 |
+
dropout_p: float. Dropout probability.
|
| 1343 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1344 |
+
Default to 1 / sqrt(headdim).
|
| 1345 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1346 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1347 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1348 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|)
|
| 1349 |
+
is added to the attention score of query i and key j.
|
| 1350 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1351 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1352 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1353 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1354 |
+
(they might not have the right scaling).
|
| 1355 |
+
Return:
|
| 1356 |
+
out: (total, nheads, headdim).
|
| 1357 |
+
softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The
|
| 1358 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1359 |
+
normalization factor).
|
| 1360 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1361 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1362 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1363 |
+
"""
|
| 1364 |
+
return FlashAttnVarlenQKVPackedFunc.apply(
|
| 1365 |
+
qkv,
|
| 1366 |
+
cu_seqlens,
|
| 1367 |
+
max_seqlen,
|
| 1368 |
+
dropout_p,
|
| 1369 |
+
softmax_scale,
|
| 1370 |
+
causal,
|
| 1371 |
+
window_size,
|
| 1372 |
+
softcap,
|
| 1373 |
+
alibi_slopes,
|
| 1374 |
+
deterministic,
|
| 1375 |
+
return_attn_probs,
|
| 1376 |
+
torch.is_grad_enabled(),
|
| 1377 |
+
)
|
| 1378 |
+
|
| 1379 |
+
|
| 1380 |
+
def flash_attn_varlen_kvpacked_func(
|
| 1381 |
+
q,
|
| 1382 |
+
kv,
|
| 1383 |
+
cu_seqlens_q,
|
| 1384 |
+
cu_seqlens_k,
|
| 1385 |
+
max_seqlen_q,
|
| 1386 |
+
max_seqlen_k,
|
| 1387 |
+
dropout_p=0.0,
|
| 1388 |
+
softmax_scale=None,
|
| 1389 |
+
causal=False,
|
| 1390 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1391 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1392 |
+
alibi_slopes=None,
|
| 1393 |
+
deterministic=False,
|
| 1394 |
+
return_attn_probs=False,
|
| 1395 |
+
):
|
| 1396 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1397 |
+
If K, V are already stacked into 1 tensor, this function will be faster than
|
| 1398 |
+
calling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1399 |
+
of the gradients of K, V.
|
| 1400 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1401 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1402 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1403 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1404 |
+
|
| 1405 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1406 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1407 |
+
1 1 1 1 0
|
| 1408 |
+
1 1 1 1 1
|
| 1409 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1410 |
+
0 0
|
| 1411 |
+
0 0
|
| 1412 |
+
0 0
|
| 1413 |
+
1 0
|
| 1414 |
+
1 1
|
| 1415 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1416 |
+
|
| 1417 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1418 |
+
will only attend to keys between
|
| 1419 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1420 |
+
|
| 1421 |
+
Arguments:
|
| 1422 |
+
q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.
|
| 1423 |
+
kv: (total_k, 2, nheads_k, headdim), where total_k = total number of key tokens in the batch.
|
| 1424 |
+
cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1425 |
+
of the sequences in the batch, used to index into q.
|
| 1426 |
+
cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1427 |
+
of the sequences in the batch, used to index into kv.
|
| 1428 |
+
max_seqlen_q: int. Maximum query sequence length in the batch.
|
| 1429 |
+
max_seqlen_k: int. Maximum key sequence length in the batch.
|
| 1430 |
+
dropout_p: float. Dropout probability.
|
| 1431 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1432 |
+
Default to 1 / sqrt(headdim).
|
| 1433 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1434 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1435 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1436 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1437 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1438 |
+
is added to the attention score of query i and key j.
|
| 1439 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1440 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1441 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1442 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1443 |
+
(they might not have the right scaling).
|
| 1444 |
+
Return:
|
| 1445 |
+
out: (total, nheads, headdim).
|
| 1446 |
+
softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The
|
| 1447 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1448 |
+
normalization factor).
|
| 1449 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1450 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1451 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1452 |
+
"""
|
| 1453 |
+
return FlashAttnVarlenKVPackedFunc.apply(
|
| 1454 |
+
q,
|
| 1455 |
+
kv,
|
| 1456 |
+
cu_seqlens_q,
|
| 1457 |
+
cu_seqlens_k,
|
| 1458 |
+
max_seqlen_q,
|
| 1459 |
+
max_seqlen_k,
|
| 1460 |
+
dropout_p,
|
| 1461 |
+
softmax_scale,
|
| 1462 |
+
causal,
|
| 1463 |
+
window_size,
|
| 1464 |
+
softcap,
|
| 1465 |
+
alibi_slopes,
|
| 1466 |
+
deterministic,
|
| 1467 |
+
return_attn_probs,
|
| 1468 |
+
torch.is_grad_enabled(),
|
| 1469 |
+
)
|
| 1470 |
+
|
| 1471 |
+
|
| 1472 |
+
def flash_attn_varlen_func(
|
| 1473 |
+
q,
|
| 1474 |
+
k,
|
| 1475 |
+
v,
|
| 1476 |
+
cu_seqlens_q,
|
| 1477 |
+
cu_seqlens_k,
|
| 1478 |
+
max_seqlen_q,
|
| 1479 |
+
max_seqlen_k,
|
| 1480 |
+
dropout_p=0.0,
|
| 1481 |
+
softmax_scale=None,
|
| 1482 |
+
causal=False,
|
| 1483 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1484 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1485 |
+
alibi_slopes=None,
|
| 1486 |
+
deterministic=False,
|
| 1487 |
+
return_attn_probs=False,
|
| 1488 |
+
block_table=None,
|
| 1489 |
+
):
|
| 1490 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1491 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in K, V with fewer heads
|
| 1492 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1493 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1494 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1495 |
+
|
| 1496 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1497 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1498 |
+
1 1 1 1 0
|
| 1499 |
+
1 1 1 1 1
|
| 1500 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1501 |
+
0 0
|
| 1502 |
+
0 0
|
| 1503 |
+
0 0
|
| 1504 |
+
1 0
|
| 1505 |
+
1 1
|
| 1506 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1507 |
+
|
| 1508 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1509 |
+
will only attend to keys between
|
| 1510 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1511 |
+
|
| 1512 |
+
Arguments:
|
| 1513 |
+
q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.
|
| 1514 |
+
k: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.
|
| 1515 |
+
v: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.
|
| 1516 |
+
cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1517 |
+
of the sequences in the batch, used to index into q.
|
| 1518 |
+
cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1519 |
+
of the sequences in the batch, used to index into kv.
|
| 1520 |
+
max_seqlen_q: int. Maximum query sequence length in the batch.
|
| 1521 |
+
max_seqlen_k: int. Maximum key sequence length in the batch.
|
| 1522 |
+
dropout_p: float. Dropout probability.
|
| 1523 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1524 |
+
Default to 1 / sqrt(headdim).
|
| 1525 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1526 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1527 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1528 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1529 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1530 |
+
is added to the attention score of query i and key j.
|
| 1531 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1532 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1533 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1534 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1535 |
+
(they might not have the right scaling).
|
| 1536 |
+
Return:
|
| 1537 |
+
out: (total, nheads, headdim).
|
| 1538 |
+
softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The
|
| 1539 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1540 |
+
normalization factor).
|
| 1541 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1542 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1543 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1544 |
+
"""
|
| 1545 |
+
return FlashAttnVarlenFunc.apply(
|
| 1546 |
+
q,
|
| 1547 |
+
k,
|
| 1548 |
+
v,
|
| 1549 |
+
cu_seqlens_q,
|
| 1550 |
+
cu_seqlens_k,
|
| 1551 |
+
max_seqlen_q,
|
| 1552 |
+
max_seqlen_k,
|
| 1553 |
+
dropout_p,
|
| 1554 |
+
softmax_scale,
|
| 1555 |
+
causal,
|
| 1556 |
+
window_size,
|
| 1557 |
+
softcap,
|
| 1558 |
+
alibi_slopes,
|
| 1559 |
+
deterministic,
|
| 1560 |
+
return_attn_probs,
|
| 1561 |
+
block_table,
|
| 1562 |
+
False if q.device.type == "cpu" else torch.is_grad_enabled(),
|
| 1563 |
+
)
|
| 1564 |
+
|
| 1565 |
+
|
| 1566 |
+
def flash_attn_with_kvcache(
|
| 1567 |
+
q,
|
| 1568 |
+
k_cache,
|
| 1569 |
+
v_cache,
|
| 1570 |
+
k=None,
|
| 1571 |
+
v=None,
|
| 1572 |
+
rotary_cos=None,
|
| 1573 |
+
rotary_sin=None,
|
| 1574 |
+
cache_seqlens: Optional[Union[(int, torch.Tensor)]] = None,
|
| 1575 |
+
cache_batch_idx: Optional[torch.Tensor] = None,
|
| 1576 |
+
cache_leftpad: Optional[torch.Tensor] = None,
|
| 1577 |
+
block_table: Optional[torch.Tensor] = None,
|
| 1578 |
+
softmax_scale=None,
|
| 1579 |
+
causal=False,
|
| 1580 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1581 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1582 |
+
rotary_interleaved=True,
|
| 1583 |
+
alibi_slopes=None,
|
| 1584 |
+
num_splits=0,
|
| 1585 |
+
return_softmax_lse=False,
|
| 1586 |
+
):
|
| 1587 |
+
"""
|
| 1588 |
+
If k and v are not None, k_cache and v_cache will be updated *inplace* with the new values from
|
| 1589 |
+
k and v. This is useful for incremental decoding: you can pass in the cached keys/values from
|
| 1590 |
+
the previous step, and update them with the new keys/values from the current step, and do
|
| 1591 |
+
attention with the updated cache, all in 1 kernel.
|
| 1592 |
+
|
| 1593 |
+
If you pass in k / v, you must make sure that the cache is large enough to hold the new values.
|
| 1594 |
+
For example, the KV cache could be pre-allocated with the max sequence length, and you can use
|
| 1595 |
+
cache_seqlens to keep track of the current sequence lengths of each sequence in the batch.
|
| 1596 |
+
|
| 1597 |
+
Also apply rotary embedding if rotary_cos and rotary_sin are passed in. The key @k will be
|
| 1598 |
+
rotated by rotary_cos and rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.
|
| 1599 |
+
If causal or local (i.e., window_size != (-1, -1)), the query @q will be rotated by rotary_cos
|
| 1600 |
+
and rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.
|
| 1601 |
+
If not causal and not local, the query @q will be rotated by rotary_cos and rotary_sin at
|
| 1602 |
+
indices cache_seqlens only (i.e. we consider all tokens in @q to be at position cache_seqlens).
|
| 1603 |
+
|
| 1604 |
+
See tests/test_flash_attn.py::test_flash_attn_kvcache for examples of how to use this function.
|
| 1605 |
+
|
| 1606 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1607 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1608 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1609 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1610 |
+
|
| 1611 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1612 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1613 |
+
1 1 1 1 0
|
| 1614 |
+
1 1 1 1 1
|
| 1615 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1616 |
+
0 0
|
| 1617 |
+
0 0
|
| 1618 |
+
0 0
|
| 1619 |
+
1 0
|
| 1620 |
+
1 1
|
| 1621 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1622 |
+
|
| 1623 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1624 |
+
will only attend to keys between
|
| 1625 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1626 |
+
|
| 1627 |
+
Note: Does not support backward pass.
|
| 1628 |
+
|
| 1629 |
+
Arguments:
|
| 1630 |
+
q: (batch_size, seqlen, nheads, headdim)
|
| 1631 |
+
k_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,
|
| 1632 |
+
or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)
|
| 1633 |
+
page_block_size must be a multiple of 256.
|
| 1634 |
+
v_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,
|
| 1635 |
+
or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)
|
| 1636 |
+
k [optional]: (batch_size, seqlen_new, nheads_k, headdim). If not None, we concatenate
|
| 1637 |
+
k with k_cache, starting at the indices specified by cache_seqlens.
|
| 1638 |
+
v [optional]: (batch_size, seqlen_new, nheads_k, headdim). Similar to k.
|
| 1639 |
+
rotary_cos [optional]: (seqlen_ro, rotary_dim / 2). If not None, we apply rotary embedding
|
| 1640 |
+
to k and q. Only applicable if k and v are passed in. rotary_dim must be divisible by 16.
|
| 1641 |
+
rotary_sin [optional]: (seqlen_ro, rotary_dim / 2). Similar to rotary_cos.
|
| 1642 |
+
cache_seqlens: int, or (batch_size,), dtype torch.int32. The sequence lengths of the
|
| 1643 |
+
KV cache.
|
| 1644 |
+
cache_batch_idx: (batch_size,), dtype torch.int32. The indices used to index into the KV cache.
|
| 1645 |
+
If None, we assume that the batch indices are [0, 1, 2, ..., batch_size - 1].
|
| 1646 |
+
If the indices are not distinct, and k and v are provided, the values updated in the cache
|
| 1647 |
+
might come from any of the duplicate indices.
|
| 1648 |
+
cache_leftpad: (batch_size,), dtype torch.int32. The index that the KV cache starts. If None, assume 0.
|
| 1649 |
+
block_table [optional]: (batch_size, max_num_blocks_per_seq), dtype torch.int32.
|
| 1650 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1651 |
+
Default to 1 / sqrt(headdim).
|
| 1652 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1653 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1654 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1655 |
+
rotary_interleaved: bool. Only applicable if rotary_cos and rotary_sin are passed in.
|
| 1656 |
+
If True, rotary embedding will combine dimensions 0 & 1, 2 & 3, etc. If False,
|
| 1657 |
+
rotary embedding will combine dimensions 0 & rotary_dim / 2, 1 & rotary_dim / 2 + 1
|
| 1658 |
+
(i.e. GPT-NeoX style).
|
| 1659 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1660 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1661 |
+
is added to the attention score of query i and key j.
|
| 1662 |
+
num_splits: int. If > 1, split the key/value into this many chunks along the sequence.
|
| 1663 |
+
If num_splits == 1, we don't split the key/value. If num_splits == 0, we use a heuristic
|
| 1664 |
+
to automatically determine the number of splits.
|
| 1665 |
+
Don't change this unless you know what you are doing.
|
| 1666 |
+
return_softmax_lse: bool. Whether to return the logsumexp of the attention scores.
|
| 1667 |
+
|
| 1668 |
+
Return:
|
| 1669 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1670 |
+
softmax_lse [optional, if return_softmax_lse=True]: (batch_size, nheads, seqlen). The
|
| 1671 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1672 |
+
normalization factor).
|
| 1673 |
+
"""
|
| 1674 |
+
assert k_cache.stride(-1) == 1, "k_cache must have contiguous last dimension"
|
| 1675 |
+
assert v_cache.stride(-1) == 1, "v_cache must have contiguous last dimension"
|
| 1676 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 1677 |
+
if softmax_scale is None:
|
| 1678 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 1679 |
+
if cache_seqlens is not None and isinstance(cache_seqlens, int):
|
| 1680 |
+
cache_seqlens = torch.full(
|
| 1681 |
+
(k_cache.shape[0],), cache_seqlens, dtype=torch.int32, device=k_cache.device
|
| 1682 |
+
)
|
| 1683 |
+
cache_seqlens = maybe_contiguous(cache_seqlens)
|
| 1684 |
+
cache_batch_idx = maybe_contiguous(cache_batch_idx)
|
| 1685 |
+
block_table = maybe_contiguous(block_table)
|
| 1686 |
+
out, softmax_lse = flash_attn.fwd_kvcache(
|
| 1687 |
+
q,
|
| 1688 |
+
k_cache,
|
| 1689 |
+
v_cache,
|
| 1690 |
+
k,
|
| 1691 |
+
v,
|
| 1692 |
+
cache_seqlens,
|
| 1693 |
+
rotary_cos,
|
| 1694 |
+
rotary_sin,
|
| 1695 |
+
cache_batch_idx,
|
| 1696 |
+
cache_leftpad,
|
| 1697 |
+
block_table,
|
| 1698 |
+
alibi_slopes,
|
| 1699 |
+
None,
|
| 1700 |
+
softmax_scale,
|
| 1701 |
+
causal,
|
| 1702 |
+
window_size[0],
|
| 1703 |
+
window_size[1],
|
| 1704 |
+
softcap,
|
| 1705 |
+
rotary_interleaved,
|
| 1706 |
+
num_splits,
|
| 1707 |
+
)
|
| 1708 |
+
return (out, softmax_lse) if return_softmax_lse else out
|
build/torch-stable-abi210-cu130-aarch64-linux/metadata.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "flash-attn2",
|
| 3 |
+
"id": "_flash_attn2_cuda_460047c",
|
| 4 |
+
"version": 4,
|
| 5 |
+
"kernels-minver": "0.14.0",
|
| 6 |
+
"license": "BSD-3-Clause",
|
| 7 |
+
"python-depends": [],
|
| 8 |
+
"kernel-depends": [],
|
| 9 |
+
"backend": {
|
| 10 |
+
"type": "cuda",
|
| 11 |
+
"archs": [
|
| 12 |
+
"10.0",
|
| 13 |
+
"12.0",
|
| 14 |
+
"8.0",
|
| 15 |
+
"9.0"
|
| 16 |
+
]
|
| 17 |
+
},
|
| 18 |
+
"digest": {
|
| 19 |
+
"algorithm": "sha256",
|
| 20 |
+
"files": {
|
| 21 |
+
"__init__.py": "Nz8hqrusjoUHQqszpxfF2USMwUXn1VfpvcmtAAvutSM=",
|
| 22 |
+
"_flash_attn2_cuda_460047c.abi3.so": "XTNJtOCZCVxBEjZD3yy/9JxwZb8D+1rg2I9ZjNch5BM=",
|
| 23 |
+
"_ops.py": "DV4Eo4+s3aaNmDsfXoZiYKNLnRUJqlsdDGlMsdKFgk4=",
|
| 24 |
+
"flash_attn_interface.py": "6UYUhfUax4+yOUygyS7K8dVjrIjU5GQr1AJ2gSp8rPo=",
|
| 25 |
+
"symbols.json": "uvC+87tHUhtHv7L/Nl53T/Ms7ceX317/jwQBoqHY14A="
|
| 26 |
+
}
|
| 27 |
+
},
|
| 28 |
+
"provenance": {
|
| 29 |
+
"kernel-builder": {
|
| 30 |
+
"version": "0.18.0-dev0",
|
| 31 |
+
"commit": "d054906a13710b811b96697b4635f03020842733",
|
| 32 |
+
"dirty": false
|
| 33 |
+
},
|
| 34 |
+
"kernel": {
|
| 35 |
+
"commit": "460047c291fc7f0b3dbd4239b46bd5e1281b1806",
|
| 36 |
+
"dirty": false
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
}
|
build/torch-stable-abi210-cu130-aarch64-linux/metadata.json.sigstore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"mediaType":"application/vnd.dev.sigstore.bundle.v0.3+json","verificationMaterial":{"certificate":{"rawBytes":"MIIHLDCCBrOgAwIBAgIUV5dC/QsMY1gdXh+pxvVOTFf2nxQwCgYIKoZIzj0EAwMwNzEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MR4wHAYDVQQDExVzaWdzdG9yZS1pbnRlcm1lZGlhdG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DO6DNPFLkhEBDAKBggqhkjOPQQDAwNnADBkAjBPzCJZB4fe4+gup4iAsdCMJDS2r6ytH3dy6FMauWIXJUdzHh4tIY1jmNIy0wOMsDkCMA7GDNNIS0J/4woDrEUlbZmH035vUjLltFZuK+IQsbv7a91yAUhQxRM3Zk/hUId3ZA=="},"tlogEntries":[{"logIndex":"3430231988","logId":{"keyId":"wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="},"kindVersion":{"kind":"hashedrekord","version":"0.0.1"},"integratedTime":"1792800470","inclusionPromise":{"signedEntryTimestamp":"MEYCIQCmHkPxEo6UA56CtGAvcd7tuGSq+BTh09PAdp32SFBZLgIhAPToHBO342Kcu8F0o+BGUR+W22R/ILnHLl73H3vqP8Lj"},"inclusionProof":{"logIndex":"3308327726","rootHash":"9j+WvjjLBQ6Dg17XvdJ7GaT9NstggA0SjQdvQa4SJls=","treeSize":"3308328149","hashes":["NMP7eOc8EnoNjTnvyncEDeeDSn30GrZLCo/z/YmE8Lw=","ICRVwZIV8m9NxN75D8+IxvBmuVn1gqs5Xh10I4RFKY0=","WBxEYgVoTGEhcWfbUQduXtRHERE8IK0oWSPwDHRLT/U=","MnnalYww5Z3KevmaBMHkF5DOiCuZDATeV5EhjKf50LM=","Tc0I1OuGp5qzxaeLQEWZyOeCB8SHUPvP0eNG/K38o2c=","YwDNh7SwtIh/zqCVP1jL0CyyakPPls+pxGBrL4UWnKU=","qg3u2EeN52cnvOm+KIKO7RMKmtx8rYCMwXusD5VORnc=","+9D72OvJMqE7pujmt6xkkyNsnwEo55yUuDk9sn3o+eY=","XjdWy49UvJFoNoQxicEvigURdRnav3eX5vfaEMQxdR0=","C4d/JSc723ScaFwqOj7Rp4UyeZlWzqzRqTehzamGn7Y=","hM/G+D/5k6TXc6r9PyzYqE/YqDRL1txJXgyl5W+peYg=","gdS39fsn5MOVlKluUgGY2sdKF3H5oauxkHMa7DSSNcg=","8x0N/oAmvpY+6DQUGTU+i6a1Cuqphro2WbV5WZ/RHL8=","DMchGrSAeKV9qHo75XJV3UFZ/CHF8zofPRu+NgVRwA4=","V6dXjeDcwYxBG/9gVSBM8rYdPrAqGpZsf1e7v6l67GA=","iDfImp65w8dirRfYGNgFA34JTUYDWbcJwNBBU/Ok+X4=","YYCr61A8azar3dfO8Ct+pri7LqDxkUlUkfs7fiqYErU=","1DaDKzrCNNBhmSdY5vFjz+NpAmxmYfYEgBCdPLrMP1A=","xH/DCseLHr9eKoYT8qsORZK7zVdEGYWHuVtsVrD95wY="],"checkpoint":{"envelope":"rekor.sigstore.dev - 1193050959916656506\n3308328149\n9j+WvjjLBQ6Dg17XvdJ7GaT9NstggA0SjQdvQa4SJls=\n\n— rekor.sigstore.dev wNI9ajBEAiBZmvNl49SFK82hdRPtmAHH84wBRtvOKW++tQp9p62duwIga+rvFXCpKRulXzsOALA3vQv+xB+oJAiUe5ehKu+mpn4=\n"}},"canonicalizedBody":"eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoiaGFzaGVkcmVrb3JkIiwic3BlYyI6eyJkYXRhIjp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiI3NjFhZjcxMTBkYjY5OThiODVhZGViYWYwMjdhZTA5MDI4ZDA5ZmNmNWUzYWI5MzMyM2VmMDU3NjA3MzFjODEzIn19LCJzaWduYXR1cmUiOnsiY29udGVudCI6Ik1FUUNJSGZsUUlkZlh6dHVFM2V5VzFiQUdidkZGR1RsajZ2L3VsYlFCN3JHRVhvT0FpQWswRUs4aDc0NzluVUI3KzVvMVhleCtraTFmMUtCNlJhaUJ2TXBJOVVSdXc9PSIsInB1YmxpY0tleSI6eyJjb250ZW50IjoiTFMwdExTMUNSVWRKVGlCRFJWSlVTVVpKUTBGVVJTMHRMUzB0Q2sxSlNVaE1SRU5EUW5KUFowRjNTVUpCWjBsVlZqVmtReTlSYzAxWk1XZGtXR2dyY0hoMlZrOVVSbVl5Ym5oUmQwTm5XVWxMYjF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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema_version": 1,
|
| 3 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 4 |
+
"functions": [
|
| 5 |
+
{
|
| 6 |
+
"name": "flash_attn_func",
|
| 7 |
+
"qualname": "flash_attn_func",
|
| 8 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 9 |
+
"kind": "function",
|
| 10 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (batch_size, seqlen, nheads, headdim)\n k: (batch_size, seqlen, nheads_k, headdim)\n v: (batch_size, seqlen, nheads_k, headdim)\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 11 |
+
"signature": {
|
| 12 |
+
"parameters": [
|
| 13 |
+
{
|
| 14 |
+
"name": "q",
|
| 15 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 16 |
+
"default": null,
|
| 17 |
+
"annotation": null
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"name": "k",
|
| 21 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 22 |
+
"default": null,
|
| 23 |
+
"annotation": null
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"name": "v",
|
| 27 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 28 |
+
"default": null,
|
| 29 |
+
"annotation": null
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"name": "dropout_p",
|
| 33 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 34 |
+
"default": "0.0",
|
| 35 |
+
"annotation": null
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"name": "softmax_scale",
|
| 39 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 40 |
+
"default": "None",
|
| 41 |
+
"annotation": null
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"name": "causal",
|
| 45 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 46 |
+
"default": "False",
|
| 47 |
+
"annotation": null
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"name": "window_size",
|
| 51 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 52 |
+
"default": "(-1, -1)",
|
| 53 |
+
"annotation": null
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"name": "softcap",
|
| 57 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 58 |
+
"default": "0.0",
|
| 59 |
+
"annotation": null
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"name": "alibi_slopes",
|
| 63 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 64 |
+
"default": "None",
|
| 65 |
+
"annotation": null
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"name": "deterministic",
|
| 69 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 70 |
+
"default": "False",
|
| 71 |
+
"annotation": null
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"name": "return_attn_probs",
|
| 75 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 76 |
+
"default": "False",
|
| 77 |
+
"annotation": null
|
| 78 |
+
}
|
| 79 |
+
],
|
| 80 |
+
"return_annotation": null
|
| 81 |
+
}
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
"name": "flash_attn_kvpacked_func",
|
| 85 |
+
"qualname": "flash_attn_kvpacked_func",
|
| 86 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 87 |
+
"kind": "function",
|
| 88 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of K, V.\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (batch_size, seqlen, nheads, headdim)\n kv: (batch_size, seqlen, 2, nheads_k, headdim)\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 89 |
+
"signature": {
|
| 90 |
+
"parameters": [
|
| 91 |
+
{
|
| 92 |
+
"name": "q",
|
| 93 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 94 |
+
"default": null,
|
| 95 |
+
"annotation": null
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"name": "kv",
|
| 99 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 100 |
+
"default": null,
|
| 101 |
+
"annotation": null
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"name": "dropout_p",
|
| 105 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 106 |
+
"default": "0.0",
|
| 107 |
+
"annotation": null
|
| 108 |
+
},
|
| 109 |
+
{
|
| 110 |
+
"name": "softmax_scale",
|
| 111 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 112 |
+
"default": "None",
|
| 113 |
+
"annotation": null
|
| 114 |
+
},
|
| 115 |
+
{
|
| 116 |
+
"name": "causal",
|
| 117 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 118 |
+
"default": "False",
|
| 119 |
+
"annotation": null
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"name": "window_size",
|
| 123 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 124 |
+
"default": "(-1, -1)",
|
| 125 |
+
"annotation": null
|
| 126 |
+
},
|
| 127 |
+
{
|
| 128 |
+
"name": "softcap",
|
| 129 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 130 |
+
"default": "0.0",
|
| 131 |
+
"annotation": null
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
"name": "alibi_slopes",
|
| 135 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 136 |
+
"default": "None",
|
| 137 |
+
"annotation": null
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"name": "deterministic",
|
| 141 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 142 |
+
"default": "False",
|
| 143 |
+
"annotation": null
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"name": "return_attn_probs",
|
| 147 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 148 |
+
"default": "False",
|
| 149 |
+
"annotation": null
|
| 150 |
+
}
|
| 151 |
+
],
|
| 152 |
+
"return_annotation": null
|
| 153 |
+
}
|
| 154 |
+
},
|
| 155 |
+
{
|
| 156 |
+
"name": "flash_attn_qkvpacked_func",
|
| 157 |
+
"qualname": "flash_attn_qkvpacked_func",
|
| 158 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 159 |
+
"kind": "function",
|
| 160 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf Q, K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of Q, K, V.\nFor multi-query and grouped-query attention (MQA/GQA), please see\nflash_attn_kvpacked_func and flash_attn_func.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.\n\nArguments:\n qkv: (batch_size, seqlen, 3, nheads, headdim)\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|) is added to\n the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 161 |
+
"signature": {
|
| 162 |
+
"parameters": [
|
| 163 |
+
{
|
| 164 |
+
"name": "qkv",
|
| 165 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 166 |
+
"default": null,
|
| 167 |
+
"annotation": null
|
| 168 |
+
},
|
| 169 |
+
{
|
| 170 |
+
"name": "dropout_p",
|
| 171 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 172 |
+
"default": "0.0",
|
| 173 |
+
"annotation": null
|
| 174 |
+
},
|
| 175 |
+
{
|
| 176 |
+
"name": "softmax_scale",
|
| 177 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 178 |
+
"default": "None",
|
| 179 |
+
"annotation": null
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
"name": "causal",
|
| 183 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 184 |
+
"default": "False",
|
| 185 |
+
"annotation": null
|
| 186 |
+
},
|
| 187 |
+
{
|
| 188 |
+
"name": "window_size",
|
| 189 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 190 |
+
"default": "(-1, -1)",
|
| 191 |
+
"annotation": null
|
| 192 |
+
},
|
| 193 |
+
{
|
| 194 |
+
"name": "softcap",
|
| 195 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 196 |
+
"default": "0.0",
|
| 197 |
+
"annotation": null
|
| 198 |
+
},
|
| 199 |
+
{
|
| 200 |
+
"name": "alibi_slopes",
|
| 201 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 202 |
+
"default": "None",
|
| 203 |
+
"annotation": null
|
| 204 |
+
},
|
| 205 |
+
{
|
| 206 |
+
"name": "deterministic",
|
| 207 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 208 |
+
"default": "False",
|
| 209 |
+
"annotation": null
|
| 210 |
+
},
|
| 211 |
+
{
|
| 212 |
+
"name": "return_attn_probs",
|
| 213 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 214 |
+
"default": "False",
|
| 215 |
+
"annotation": null
|
| 216 |
+
}
|
| 217 |
+
],
|
| 218 |
+
"return_annotation": null
|
| 219 |
+
}
|
| 220 |
+
},
|
| 221 |
+
{
|
| 222 |
+
"name": "flash_attn_varlen_func",
|
| 223 |
+
"qualname": "flash_attn_varlen_func",
|
| 224 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 225 |
+
"kind": "function",
|
| 226 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in K, V with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.\n k: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.\n v: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.\n cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into q.\n cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into kv.\n max_seqlen_q: int. Maximum query sequence length in the batch.\n max_seqlen_k: int. Maximum key sequence length in the batch.\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (total, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 227 |
+
"signature": {
|
| 228 |
+
"parameters": [
|
| 229 |
+
{
|
| 230 |
+
"name": "q",
|
| 231 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 232 |
+
"default": null,
|
| 233 |
+
"annotation": null
|
| 234 |
+
},
|
| 235 |
+
{
|
| 236 |
+
"name": "k",
|
| 237 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 238 |
+
"default": null,
|
| 239 |
+
"annotation": null
|
| 240 |
+
},
|
| 241 |
+
{
|
| 242 |
+
"name": "v",
|
| 243 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 244 |
+
"default": null,
|
| 245 |
+
"annotation": null
|
| 246 |
+
},
|
| 247 |
+
{
|
| 248 |
+
"name": "cu_seqlens_q",
|
| 249 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 250 |
+
"default": null,
|
| 251 |
+
"annotation": null
|
| 252 |
+
},
|
| 253 |
+
{
|
| 254 |
+
"name": "cu_seqlens_k",
|
| 255 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 256 |
+
"default": null,
|
| 257 |
+
"annotation": null
|
| 258 |
+
},
|
| 259 |
+
{
|
| 260 |
+
"name": "max_seqlen_q",
|
| 261 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 262 |
+
"default": null,
|
| 263 |
+
"annotation": null
|
| 264 |
+
},
|
| 265 |
+
{
|
| 266 |
+
"name": "max_seqlen_k",
|
| 267 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 268 |
+
"default": null,
|
| 269 |
+
"annotation": null
|
| 270 |
+
},
|
| 271 |
+
{
|
| 272 |
+
"name": "dropout_p",
|
| 273 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 274 |
+
"default": "0.0",
|
| 275 |
+
"annotation": null
|
| 276 |
+
},
|
| 277 |
+
{
|
| 278 |
+
"name": "softmax_scale",
|
| 279 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 280 |
+
"default": "None",
|
| 281 |
+
"annotation": null
|
| 282 |
+
},
|
| 283 |
+
{
|
| 284 |
+
"name": "causal",
|
| 285 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 286 |
+
"default": "False",
|
| 287 |
+
"annotation": null
|
| 288 |
+
},
|
| 289 |
+
{
|
| 290 |
+
"name": "window_size",
|
| 291 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 292 |
+
"default": "(-1, -1)",
|
| 293 |
+
"annotation": null
|
| 294 |
+
},
|
| 295 |
+
{
|
| 296 |
+
"name": "softcap",
|
| 297 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 298 |
+
"default": "0.0",
|
| 299 |
+
"annotation": null
|
| 300 |
+
},
|
| 301 |
+
{
|
| 302 |
+
"name": "alibi_slopes",
|
| 303 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 304 |
+
"default": "None",
|
| 305 |
+
"annotation": null
|
| 306 |
+
},
|
| 307 |
+
{
|
| 308 |
+
"name": "deterministic",
|
| 309 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 310 |
+
"default": "False",
|
| 311 |
+
"annotation": null
|
| 312 |
+
},
|
| 313 |
+
{
|
| 314 |
+
"name": "return_attn_probs",
|
| 315 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 316 |
+
"default": "False",
|
| 317 |
+
"annotation": null
|
| 318 |
+
},
|
| 319 |
+
{
|
| 320 |
+
"name": "block_table",
|
| 321 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 322 |
+
"default": "None",
|
| 323 |
+
"annotation": null
|
| 324 |
+
}
|
| 325 |
+
],
|
| 326 |
+
"return_annotation": null
|
| 327 |
+
}
|
| 328 |
+
},
|
| 329 |
+
{
|
| 330 |
+
"name": "flash_attn_varlen_kvpacked_func",
|
| 331 |
+
"qualname": "flash_attn_varlen_kvpacked_func",
|
| 332 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 333 |
+
"kind": "function",
|
| 334 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of K, V.\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.\n kv: (total_k, 2, nheads_k, headdim), where total_k = total number of key tokens in the batch.\n cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into q.\n cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into kv.\n max_seqlen_q: int. Maximum query sequence length in the batch.\n max_seqlen_k: int. Maximum key sequence length in the batch.\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (total, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 335 |
+
"signature": {
|
| 336 |
+
"parameters": [
|
| 337 |
+
{
|
| 338 |
+
"name": "q",
|
| 339 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 340 |
+
"default": null,
|
| 341 |
+
"annotation": null
|
| 342 |
+
},
|
| 343 |
+
{
|
| 344 |
+
"name": "kv",
|
| 345 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 346 |
+
"default": null,
|
| 347 |
+
"annotation": null
|
| 348 |
+
},
|
| 349 |
+
{
|
| 350 |
+
"name": "cu_seqlens_q",
|
| 351 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 352 |
+
"default": null,
|
| 353 |
+
"annotation": null
|
| 354 |
+
},
|
| 355 |
+
{
|
| 356 |
+
"name": "cu_seqlens_k",
|
| 357 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 358 |
+
"default": null,
|
| 359 |
+
"annotation": null
|
| 360 |
+
},
|
| 361 |
+
{
|
| 362 |
+
"name": "max_seqlen_q",
|
| 363 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 364 |
+
"default": null,
|
| 365 |
+
"annotation": null
|
| 366 |
+
},
|
| 367 |
+
{
|
| 368 |
+
"name": "max_seqlen_k",
|
| 369 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 370 |
+
"default": null,
|
| 371 |
+
"annotation": null
|
| 372 |
+
},
|
| 373 |
+
{
|
| 374 |
+
"name": "dropout_p",
|
| 375 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 376 |
+
"default": "0.0",
|
| 377 |
+
"annotation": null
|
| 378 |
+
},
|
| 379 |
+
{
|
| 380 |
+
"name": "softmax_scale",
|
| 381 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 382 |
+
"default": "None",
|
| 383 |
+
"annotation": null
|
| 384 |
+
},
|
| 385 |
+
{
|
| 386 |
+
"name": "causal",
|
| 387 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 388 |
+
"default": "False",
|
| 389 |
+
"annotation": null
|
| 390 |
+
},
|
| 391 |
+
{
|
| 392 |
+
"name": "window_size",
|
| 393 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 394 |
+
"default": "(-1, -1)",
|
| 395 |
+
"annotation": null
|
| 396 |
+
},
|
| 397 |
+
{
|
| 398 |
+
"name": "softcap",
|
| 399 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 400 |
+
"default": "0.0",
|
| 401 |
+
"annotation": null
|
| 402 |
+
},
|
| 403 |
+
{
|
| 404 |
+
"name": "alibi_slopes",
|
| 405 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 406 |
+
"default": "None",
|
| 407 |
+
"annotation": null
|
| 408 |
+
},
|
| 409 |
+
{
|
| 410 |
+
"name": "deterministic",
|
| 411 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 412 |
+
"default": "False",
|
| 413 |
+
"annotation": null
|
| 414 |
+
},
|
| 415 |
+
{
|
| 416 |
+
"name": "return_attn_probs",
|
| 417 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 418 |
+
"default": "False",
|
| 419 |
+
"annotation": null
|
| 420 |
+
}
|
| 421 |
+
],
|
| 422 |
+
"return_annotation": null
|
| 423 |
+
}
|
| 424 |
+
},
|
| 425 |
+
{
|
| 426 |
+
"name": "flash_attn_varlen_qkvpacked_func",
|
| 427 |
+
"qualname": "flash_attn_varlen_qkvpacked_func",
|
| 428 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 429 |
+
"kind": "function",
|
| 430 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf Q, K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_varlen_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of Q, K, V.\nFor multi-query and grouped-query attention (MQA/GQA), please see\nflash_attn_varlen_kvpacked_func and flash_attn_varlen_func.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.\n\nArguments:\n qkv: (total, 3, nheads, headdim), where total = total number of tokens in the batch.\n cu_seqlens: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into qkv.\n max_seqlen: int. Maximum sequence length in the batch.\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (total, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 431 |
+
"signature": {
|
| 432 |
+
"parameters": [
|
| 433 |
+
{
|
| 434 |
+
"name": "qkv",
|
| 435 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 436 |
+
"default": null,
|
| 437 |
+
"annotation": null
|
| 438 |
+
},
|
| 439 |
+
{
|
| 440 |
+
"name": "cu_seqlens",
|
| 441 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 442 |
+
"default": null,
|
| 443 |
+
"annotation": null
|
| 444 |
+
},
|
| 445 |
+
{
|
| 446 |
+
"name": "max_seqlen",
|
| 447 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 448 |
+
"default": null,
|
| 449 |
+
"annotation": null
|
| 450 |
+
},
|
| 451 |
+
{
|
| 452 |
+
"name": "dropout_p",
|
| 453 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 454 |
+
"default": "0.0",
|
| 455 |
+
"annotation": null
|
| 456 |
+
},
|
| 457 |
+
{
|
| 458 |
+
"name": "softmax_scale",
|
| 459 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 460 |
+
"default": "None",
|
| 461 |
+
"annotation": null
|
| 462 |
+
},
|
| 463 |
+
{
|
| 464 |
+
"name": "causal",
|
| 465 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 466 |
+
"default": "False",
|
| 467 |
+
"annotation": null
|
| 468 |
+
},
|
| 469 |
+
{
|
| 470 |
+
"name": "window_size",
|
| 471 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 472 |
+
"default": "(-1, -1)",
|
| 473 |
+
"annotation": null
|
| 474 |
+
},
|
| 475 |
+
{
|
| 476 |
+
"name": "softcap",
|
| 477 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 478 |
+
"default": "0.0",
|
| 479 |
+
"annotation": null
|
| 480 |
+
},
|
| 481 |
+
{
|
| 482 |
+
"name": "alibi_slopes",
|
| 483 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 484 |
+
"default": "None",
|
| 485 |
+
"annotation": null
|
| 486 |
+
},
|
| 487 |
+
{
|
| 488 |
+
"name": "deterministic",
|
| 489 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 490 |
+
"default": "False",
|
| 491 |
+
"annotation": null
|
| 492 |
+
},
|
| 493 |
+
{
|
| 494 |
+
"name": "return_attn_probs",
|
| 495 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 496 |
+
"default": "False",
|
| 497 |
+
"annotation": null
|
| 498 |
+
}
|
| 499 |
+
],
|
| 500 |
+
"return_annotation": null
|
| 501 |
+
}
|
| 502 |
+
},
|
| 503 |
+
{
|
| 504 |
+
"name": "flash_attn_with_kvcache",
|
| 505 |
+
"qualname": "flash_attn_with_kvcache",
|
| 506 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 507 |
+
"kind": "function",
|
| 508 |
+
"doc": "If k and v are not None, k_cache and v_cache will be updated *inplace* with the new values from\nk and v. This is useful for incremental decoding: you can pass in the cached keys/values from\nthe previous step, and update them with the new keys/values from the current step, and do\nattention with the updated cache, all in 1 kernel.\n\nIf you pass in k / v, you must make sure that the cache is large enough to hold the new values.\nFor example, the KV cache could be pre-allocated with the max sequence length, and you can use\ncache_seqlens to keep track of the current sequence lengths of each sequence in the batch.\n\nAlso apply rotary embedding if rotary_cos and rotary_sin are passed in. The key @k will be\nrotated by rotary_cos and rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.\nIf causal or local (i.e., window_size != (-1, -1)), the query @q will be rotated by rotary_cos\nand rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.\nIf not causal and not local, the query @q will be rotated by rotary_cos and rotary_sin at\nindices cache_seqlens only (i.e. we consider all tokens in @q to be at position cache_seqlens).\n\nSee tests/test_flash_attn.py::test_flash_attn_kvcache for examples of how to use this function.\n\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nNote: Does not support backward pass.\n\nArguments:\n q: (batch_size, seqlen, nheads, headdim)\n k_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,\n or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)\n page_block_size must be a multiple of 256.\n v_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,\n or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)\n k [optional]: (batch_size, seqlen_new, nheads_k, headdim). If not None, we concatenate\n k with k_cache, starting at the indices specified by cache_seqlens.\n v [optional]: (batch_size, seqlen_new, nheads_k, headdim). Similar to k.\n rotary_cos [optional]: (seqlen_ro, rotary_dim / 2). If not None, we apply rotary embedding\n to k and q. Only applicable if k and v are passed in. rotary_dim must be divisible by 16.\n rotary_sin [optional]: (seqlen_ro, rotary_dim / 2). Similar to rotary_cos.\n cache_seqlens: int, or (batch_size,), dtype torch.int32. The sequence lengths of the\n KV cache.\n cache_batch_idx: (batch_size,), dtype torch.int32. The indices used to index into the KV cache.\n If None, we assume that the batch indices are [0, 1, 2, ..., batch_size - 1].\n If the indices are not distinct, and k and v are provided, the values updated in the cache\n might come from any of the duplicate indices.\n cache_leftpad: (batch_size,), dtype torch.int32. The index that the KV cache starts. If None, assume 0.\n block_table [optional]: (batch_size, max_num_blocks_per_seq), dtype torch.int32.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n rotary_interleaved: bool. Only applicable if rotary_cos and rotary_sin are passed in.\n If True, rotary embedding will combine dimensions 0 & 1, 2 & 3, etc. If False,\n rotary embedding will combine dimensions 0 & rotary_dim / 2, 1 & rotary_dim / 2 + 1\n (i.e. GPT-NeoX style).\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n num_splits: int. If > 1, split the key/value into this many chunks along the sequence.\n If num_splits == 1, we don't split the key/value. If num_splits == 0, we use a heuristic\n to automatically determine the number of splits.\n Don't change this unless you know what you are doing.\n return_softmax_lse: bool. Whether to return the logsumexp of the attention scores.\n\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_softmax_lse=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).",
|
| 509 |
+
"signature": {
|
| 510 |
+
"parameters": [
|
| 511 |
+
{
|
| 512 |
+
"name": "q",
|
| 513 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 514 |
+
"default": null,
|
| 515 |
+
"annotation": null
|
| 516 |
+
},
|
| 517 |
+
{
|
| 518 |
+
"name": "k_cache",
|
| 519 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 520 |
+
"default": null,
|
| 521 |
+
"annotation": null
|
| 522 |
+
},
|
| 523 |
+
{
|
| 524 |
+
"name": "v_cache",
|
| 525 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 526 |
+
"default": null,
|
| 527 |
+
"annotation": null
|
| 528 |
+
},
|
| 529 |
+
{
|
| 530 |
+
"name": "k",
|
| 531 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 532 |
+
"default": "None",
|
| 533 |
+
"annotation": null
|
| 534 |
+
},
|
| 535 |
+
{
|
| 536 |
+
"name": "v",
|
| 537 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 538 |
+
"default": "None",
|
| 539 |
+
"annotation": null
|
| 540 |
+
},
|
| 541 |
+
{
|
| 542 |
+
"name": "rotary_cos",
|
| 543 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 544 |
+
"default": "None",
|
| 545 |
+
"annotation": null
|
| 546 |
+
},
|
| 547 |
+
{
|
| 548 |
+
"name": "rotary_sin",
|
| 549 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 550 |
+
"default": "None",
|
| 551 |
+
"annotation": null
|
| 552 |
+
},
|
| 553 |
+
{
|
| 554 |
+
"name": "cache_seqlens",
|
| 555 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 556 |
+
"default": "None",
|
| 557 |
+
"annotation": "int | torch.Tensor | None"
|
| 558 |
+
},
|
| 559 |
+
{
|
| 560 |
+
"name": "cache_batch_idx",
|
| 561 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 562 |
+
"default": "None",
|
| 563 |
+
"annotation": "torch.Tensor | None"
|
| 564 |
+
},
|
| 565 |
+
{
|
| 566 |
+
"name": "cache_leftpad",
|
| 567 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 568 |
+
"default": "None",
|
| 569 |
+
"annotation": "torch.Tensor | None"
|
| 570 |
+
},
|
| 571 |
+
{
|
| 572 |
+
"name": "block_table",
|
| 573 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 574 |
+
"default": "None",
|
| 575 |
+
"annotation": "torch.Tensor | None"
|
| 576 |
+
},
|
| 577 |
+
{
|
| 578 |
+
"name": "softmax_scale",
|
| 579 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 580 |
+
"default": "None",
|
| 581 |
+
"annotation": null
|
| 582 |
+
},
|
| 583 |
+
{
|
| 584 |
+
"name": "causal",
|
| 585 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 586 |
+
"default": "False",
|
| 587 |
+
"annotation": null
|
| 588 |
+
},
|
| 589 |
+
{
|
| 590 |
+
"name": "window_size",
|
| 591 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 592 |
+
"default": "(-1, -1)",
|
| 593 |
+
"annotation": null
|
| 594 |
+
},
|
| 595 |
+
{
|
| 596 |
+
"name": "softcap",
|
| 597 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 598 |
+
"default": "0.0",
|
| 599 |
+
"annotation": null
|
| 600 |
+
},
|
| 601 |
+
{
|
| 602 |
+
"name": "rotary_interleaved",
|
| 603 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 604 |
+
"default": "True",
|
| 605 |
+
"annotation": null
|
| 606 |
+
},
|
| 607 |
+
{
|
| 608 |
+
"name": "alibi_slopes",
|
| 609 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 610 |
+
"default": "None",
|
| 611 |
+
"annotation": null
|
| 612 |
+
},
|
| 613 |
+
{
|
| 614 |
+
"name": "num_splits",
|
| 615 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 616 |
+
"default": "0",
|
| 617 |
+
"annotation": null
|
| 618 |
+
},
|
| 619 |
+
{
|
| 620 |
+
"name": "return_softmax_lse",
|
| 621 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 622 |
+
"default": "False",
|
| 623 |
+
"annotation": null
|
| 624 |
+
}
|
| 625 |
+
],
|
| 626 |
+
"return_annotation": null
|
| 627 |
+
}
|
| 628 |
+
},
|
| 629 |
+
{
|
| 630 |
+
"name": "fwd",
|
| 631 |
+
"qualname": "fwd",
|
| 632 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 633 |
+
"kind": "function",
|
| 634 |
+
"doc": "Forward pass for multi-head attention.\n\nArgs:\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n out: Optional output tensor, same shape as q\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n return_softmax: Whether to return softmax weights\n gen: Optional random number generator\n\nReturns:\n List of tensors: [output, softmax_lse, (softmax if return_softmax)]",
|
| 635 |
+
"signature": {
|
| 636 |
+
"parameters": [
|
| 637 |
+
{
|
| 638 |
+
"name": "q",
|
| 639 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 640 |
+
"default": null,
|
| 641 |
+
"annotation": "torch.Tensor"
|
| 642 |
+
},
|
| 643 |
+
{
|
| 644 |
+
"name": "k",
|
| 645 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 646 |
+
"default": null,
|
| 647 |
+
"annotation": "torch.Tensor"
|
| 648 |
+
},
|
| 649 |
+
{
|
| 650 |
+
"name": "v",
|
| 651 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 652 |
+
"default": null,
|
| 653 |
+
"annotation": "torch.Tensor"
|
| 654 |
+
},
|
| 655 |
+
{
|
| 656 |
+
"name": "out",
|
| 657 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 658 |
+
"default": "None",
|
| 659 |
+
"annotation": "torch.Tensor | None"
|
| 660 |
+
},
|
| 661 |
+
{
|
| 662 |
+
"name": "alibi_slopes",
|
| 663 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 664 |
+
"default": "None",
|
| 665 |
+
"annotation": "torch.Tensor | None"
|
| 666 |
+
},
|
| 667 |
+
{
|
| 668 |
+
"name": "p_dropout",
|
| 669 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 670 |
+
"default": "0.0",
|
| 671 |
+
"annotation": "float"
|
| 672 |
+
},
|
| 673 |
+
{
|
| 674 |
+
"name": "softmax_scale",
|
| 675 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 676 |
+
"default": "None",
|
| 677 |
+
"annotation": "float | None"
|
| 678 |
+
},
|
| 679 |
+
{
|
| 680 |
+
"name": "is_causal",
|
| 681 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 682 |
+
"default": "False",
|
| 683 |
+
"annotation": "bool"
|
| 684 |
+
},
|
| 685 |
+
{
|
| 686 |
+
"name": "window_size_left",
|
| 687 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 688 |
+
"default": "-1",
|
| 689 |
+
"annotation": "int"
|
| 690 |
+
},
|
| 691 |
+
{
|
| 692 |
+
"name": "window_size_right",
|
| 693 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 694 |
+
"default": "-1",
|
| 695 |
+
"annotation": "int"
|
| 696 |
+
},
|
| 697 |
+
{
|
| 698 |
+
"name": "softcap",
|
| 699 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 700 |
+
"default": "0.0",
|
| 701 |
+
"annotation": "float"
|
| 702 |
+
},
|
| 703 |
+
{
|
| 704 |
+
"name": "return_softmax",
|
| 705 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 706 |
+
"default": "False",
|
| 707 |
+
"annotation": "bool"
|
| 708 |
+
},
|
| 709 |
+
{
|
| 710 |
+
"name": "gen",
|
| 711 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 712 |
+
"default": "None",
|
| 713 |
+
"annotation": "torch._C.Generator | None"
|
| 714 |
+
}
|
| 715 |
+
],
|
| 716 |
+
"return_annotation": "List[torch.Tensor]"
|
| 717 |
+
}
|
| 718 |
+
},
|
| 719 |
+
{
|
| 720 |
+
"name": "varlen_fwd",
|
| 721 |
+
"qualname": "varlen_fwd",
|
| 722 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 723 |
+
"kind": "function",
|
| 724 |
+
"doc": "Forward pass for multi-head attention with variable sequence lengths.\n\nArgs:\n q: Query tensor of shape [total_q, num_heads, head_size]\n k: Key tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n v: Value tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]\n cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]\n out: Optional output tensor of shape [total_q, num_heads, head_size]\n seqused_k: Optional tensor specifying how many keys to use per batch element [batch_size]\n leftpad_k: Optional left padding for keys of shape [batch_size]\n block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n max_seqlen_q: Maximum sequence length for queries\n max_seqlen_k: Maximum sequence length for keys\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n zero_tensors: Whether to zero tensors before computation\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n return_softmax: Whether to return softmax weights\n gen: Optional random number generator\n\nReturns:\n List of tensors: [output, softmax_lse, (softmax if return_softmax)]",
|
| 725 |
+
"signature": {
|
| 726 |
+
"parameters": [
|
| 727 |
+
{
|
| 728 |
+
"name": "q",
|
| 729 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 730 |
+
"default": null,
|
| 731 |
+
"annotation": "torch.Tensor"
|
| 732 |
+
},
|
| 733 |
+
{
|
| 734 |
+
"name": "k",
|
| 735 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 736 |
+
"default": null,
|
| 737 |
+
"annotation": "torch.Tensor"
|
| 738 |
+
},
|
| 739 |
+
{
|
| 740 |
+
"name": "v",
|
| 741 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 742 |
+
"default": null,
|
| 743 |
+
"annotation": "torch.Tensor"
|
| 744 |
+
},
|
| 745 |
+
{
|
| 746 |
+
"name": "cu_seqlens_q",
|
| 747 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 748 |
+
"default": null,
|
| 749 |
+
"annotation": "torch.Tensor"
|
| 750 |
+
},
|
| 751 |
+
{
|
| 752 |
+
"name": "cu_seqlens_k",
|
| 753 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 754 |
+
"default": null,
|
| 755 |
+
"annotation": "torch.Tensor"
|
| 756 |
+
},
|
| 757 |
+
{
|
| 758 |
+
"name": "out",
|
| 759 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 760 |
+
"default": "None",
|
| 761 |
+
"annotation": "torch.Tensor | None"
|
| 762 |
+
},
|
| 763 |
+
{
|
| 764 |
+
"name": "seqused_k",
|
| 765 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 766 |
+
"default": "None",
|
| 767 |
+
"annotation": "torch.Tensor | None"
|
| 768 |
+
},
|
| 769 |
+
{
|
| 770 |
+
"name": "leftpad_k",
|
| 771 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 772 |
+
"default": "None",
|
| 773 |
+
"annotation": "torch.Tensor | None"
|
| 774 |
+
},
|
| 775 |
+
{
|
| 776 |
+
"name": "block_table",
|
| 777 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 778 |
+
"default": "None",
|
| 779 |
+
"annotation": "torch.Tensor | None"
|
| 780 |
+
},
|
| 781 |
+
{
|
| 782 |
+
"name": "alibi_slopes",
|
| 783 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 784 |
+
"default": "None",
|
| 785 |
+
"annotation": "torch.Tensor | None"
|
| 786 |
+
},
|
| 787 |
+
{
|
| 788 |
+
"name": "max_seqlen_q",
|
| 789 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 790 |
+
"default": "0",
|
| 791 |
+
"annotation": "int"
|
| 792 |
+
},
|
| 793 |
+
{
|
| 794 |
+
"name": "max_seqlen_k",
|
| 795 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 796 |
+
"default": "0",
|
| 797 |
+
"annotation": "int"
|
| 798 |
+
},
|
| 799 |
+
{
|
| 800 |
+
"name": "p_dropout",
|
| 801 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 802 |
+
"default": "0.0",
|
| 803 |
+
"annotation": "float"
|
| 804 |
+
},
|
| 805 |
+
{
|
| 806 |
+
"name": "softmax_scale",
|
| 807 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 808 |
+
"default": "None",
|
| 809 |
+
"annotation": "float | None"
|
| 810 |
+
},
|
| 811 |
+
{
|
| 812 |
+
"name": "zero_tensors",
|
| 813 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 814 |
+
"default": "False",
|
| 815 |
+
"annotation": "bool"
|
| 816 |
+
},
|
| 817 |
+
{
|
| 818 |
+
"name": "is_causal",
|
| 819 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 820 |
+
"default": "False",
|
| 821 |
+
"annotation": "bool"
|
| 822 |
+
},
|
| 823 |
+
{
|
| 824 |
+
"name": "window_size_left",
|
| 825 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 826 |
+
"default": "-1",
|
| 827 |
+
"annotation": "int"
|
| 828 |
+
},
|
| 829 |
+
{
|
| 830 |
+
"name": "window_size_right",
|
| 831 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 832 |
+
"default": "-1",
|
| 833 |
+
"annotation": "int"
|
| 834 |
+
},
|
| 835 |
+
{
|
| 836 |
+
"name": "softcap",
|
| 837 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 838 |
+
"default": "0.0",
|
| 839 |
+
"annotation": "float"
|
| 840 |
+
},
|
| 841 |
+
{
|
| 842 |
+
"name": "return_softmax",
|
| 843 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 844 |
+
"default": "False",
|
| 845 |
+
"annotation": "bool"
|
| 846 |
+
},
|
| 847 |
+
{
|
| 848 |
+
"name": "gen",
|
| 849 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 850 |
+
"default": "None",
|
| 851 |
+
"annotation": "torch._C.Generator | None"
|
| 852 |
+
}
|
| 853 |
+
],
|
| 854 |
+
"return_annotation": "List[torch.Tensor]"
|
| 855 |
+
}
|
| 856 |
+
},
|
| 857 |
+
{
|
| 858 |
+
"name": "bwd",
|
| 859 |
+
"qualname": "bwd",
|
| 860 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 861 |
+
"kind": "function",
|
| 862 |
+
"doc": "Backward pass for multi-head attention.\n\nArgs:\n dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]\n softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]\n dq: Optional gradient tensor for queries, same shape as q\n dk: Optional gradient tensor for keys, same shape as k\n dv: Optional gradient tensor for values, same shape as v\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n deterministic: Whether to use deterministic algorithms\n gen: Optional random number generator\n rng_state: Optional RNG state from forward pass\n\nReturns:\n List of tensors: [dq, dk, dv]",
|
| 863 |
+
"signature": {
|
| 864 |
+
"parameters": [
|
| 865 |
+
{
|
| 866 |
+
"name": "dout",
|
| 867 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 868 |
+
"default": null,
|
| 869 |
+
"annotation": "torch.Tensor"
|
| 870 |
+
},
|
| 871 |
+
{
|
| 872 |
+
"name": "q",
|
| 873 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 874 |
+
"default": null,
|
| 875 |
+
"annotation": "torch.Tensor"
|
| 876 |
+
},
|
| 877 |
+
{
|
| 878 |
+
"name": "k",
|
| 879 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 880 |
+
"default": null,
|
| 881 |
+
"annotation": "torch.Tensor"
|
| 882 |
+
},
|
| 883 |
+
{
|
| 884 |
+
"name": "v",
|
| 885 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 886 |
+
"default": null,
|
| 887 |
+
"annotation": "torch.Tensor"
|
| 888 |
+
},
|
| 889 |
+
{
|
| 890 |
+
"name": "out",
|
| 891 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 892 |
+
"default": null,
|
| 893 |
+
"annotation": "torch.Tensor"
|
| 894 |
+
},
|
| 895 |
+
{
|
| 896 |
+
"name": "softmax_lse",
|
| 897 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 898 |
+
"default": null,
|
| 899 |
+
"annotation": "torch.Tensor"
|
| 900 |
+
},
|
| 901 |
+
{
|
| 902 |
+
"name": "dq",
|
| 903 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 904 |
+
"default": "None",
|
| 905 |
+
"annotation": "torch.Tensor | None"
|
| 906 |
+
},
|
| 907 |
+
{
|
| 908 |
+
"name": "dk",
|
| 909 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 910 |
+
"default": "None",
|
| 911 |
+
"annotation": "torch.Tensor | None"
|
| 912 |
+
},
|
| 913 |
+
{
|
| 914 |
+
"name": "dv",
|
| 915 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 916 |
+
"default": "None",
|
| 917 |
+
"annotation": "torch.Tensor | None"
|
| 918 |
+
},
|
| 919 |
+
{
|
| 920 |
+
"name": "alibi_slopes",
|
| 921 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 922 |
+
"default": "None",
|
| 923 |
+
"annotation": "torch.Tensor | None"
|
| 924 |
+
},
|
| 925 |
+
{
|
| 926 |
+
"name": "p_dropout",
|
| 927 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 928 |
+
"default": "0.0",
|
| 929 |
+
"annotation": "float"
|
| 930 |
+
},
|
| 931 |
+
{
|
| 932 |
+
"name": "softmax_scale",
|
| 933 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 934 |
+
"default": "None",
|
| 935 |
+
"annotation": "float | None"
|
| 936 |
+
},
|
| 937 |
+
{
|
| 938 |
+
"name": "is_causal",
|
| 939 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 940 |
+
"default": "False",
|
| 941 |
+
"annotation": "bool"
|
| 942 |
+
},
|
| 943 |
+
{
|
| 944 |
+
"name": "window_size_left",
|
| 945 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 946 |
+
"default": "-1",
|
| 947 |
+
"annotation": "int"
|
| 948 |
+
},
|
| 949 |
+
{
|
| 950 |
+
"name": "window_size_right",
|
| 951 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 952 |
+
"default": "-1",
|
| 953 |
+
"annotation": "int"
|
| 954 |
+
},
|
| 955 |
+
{
|
| 956 |
+
"name": "softcap",
|
| 957 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 958 |
+
"default": "0.0",
|
| 959 |
+
"annotation": "float"
|
| 960 |
+
},
|
| 961 |
+
{
|
| 962 |
+
"name": "deterministic",
|
| 963 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 964 |
+
"default": "False",
|
| 965 |
+
"annotation": "bool"
|
| 966 |
+
},
|
| 967 |
+
{
|
| 968 |
+
"name": "gen",
|
| 969 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 970 |
+
"default": "None",
|
| 971 |
+
"annotation": "torch._C.Generator | None"
|
| 972 |
+
},
|
| 973 |
+
{
|
| 974 |
+
"name": "rng_state",
|
| 975 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 976 |
+
"default": "None",
|
| 977 |
+
"annotation": "torch.Tensor | None"
|
| 978 |
+
}
|
| 979 |
+
],
|
| 980 |
+
"return_annotation": "List[torch.Tensor]"
|
| 981 |
+
}
|
| 982 |
+
},
|
| 983 |
+
{
|
| 984 |
+
"name": "varlen_bwd",
|
| 985 |
+
"qualname": "varlen_bwd",
|
| 986 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 987 |
+
"kind": "function",
|
| 988 |
+
"doc": "Backward pass for multi-head attention with variable sequence lengths.\n\nArgs:\n dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]\n softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]\n cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]\n cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]\n dq: Optional gradient tensor for queries, same shape as q\n dk: Optional gradient tensor for keys, same shape as k\n dv: Optional gradient tensor for values, same shape as v\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n max_seqlen_q: Maximum sequence length for queries\n max_seqlen_k: Maximum sequence length for keys\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n zero_tensors: Whether to zero tensors before computation\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n deterministic: Whether to use deterministic algorithms\n gen: Optional random number generator\n rng_state: Optional RNG state from forward pass\n\nReturns:\n List of tensors: [dq, dk, dv]",
|
| 989 |
+
"signature": {
|
| 990 |
+
"parameters": [
|
| 991 |
+
{
|
| 992 |
+
"name": "dout",
|
| 993 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 994 |
+
"default": null,
|
| 995 |
+
"annotation": "torch.Tensor"
|
| 996 |
+
},
|
| 997 |
+
{
|
| 998 |
+
"name": "q",
|
| 999 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1000 |
+
"default": null,
|
| 1001 |
+
"annotation": "torch.Tensor"
|
| 1002 |
+
},
|
| 1003 |
+
{
|
| 1004 |
+
"name": "k",
|
| 1005 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1006 |
+
"default": null,
|
| 1007 |
+
"annotation": "torch.Tensor"
|
| 1008 |
+
},
|
| 1009 |
+
{
|
| 1010 |
+
"name": "v",
|
| 1011 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1012 |
+
"default": null,
|
| 1013 |
+
"annotation": "torch.Tensor"
|
| 1014 |
+
},
|
| 1015 |
+
{
|
| 1016 |
+
"name": "out",
|
| 1017 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1018 |
+
"default": null,
|
| 1019 |
+
"annotation": "torch.Tensor"
|
| 1020 |
+
},
|
| 1021 |
+
{
|
| 1022 |
+
"name": "softmax_lse",
|
| 1023 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1024 |
+
"default": null,
|
| 1025 |
+
"annotation": "torch.Tensor"
|
| 1026 |
+
},
|
| 1027 |
+
{
|
| 1028 |
+
"name": "cu_seqlens_q",
|
| 1029 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1030 |
+
"default": null,
|
| 1031 |
+
"annotation": "torch.Tensor"
|
| 1032 |
+
},
|
| 1033 |
+
{
|
| 1034 |
+
"name": "cu_seqlens_k",
|
| 1035 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1036 |
+
"default": null,
|
| 1037 |
+
"annotation": "torch.Tensor"
|
| 1038 |
+
},
|
| 1039 |
+
{
|
| 1040 |
+
"name": "dq",
|
| 1041 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1042 |
+
"default": "None",
|
| 1043 |
+
"annotation": "torch.Tensor | None"
|
| 1044 |
+
},
|
| 1045 |
+
{
|
| 1046 |
+
"name": "dk",
|
| 1047 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1048 |
+
"default": "None",
|
| 1049 |
+
"annotation": "torch.Tensor | None"
|
| 1050 |
+
},
|
| 1051 |
+
{
|
| 1052 |
+
"name": "dv",
|
| 1053 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1054 |
+
"default": "None",
|
| 1055 |
+
"annotation": "torch.Tensor | None"
|
| 1056 |
+
},
|
| 1057 |
+
{
|
| 1058 |
+
"name": "alibi_slopes",
|
| 1059 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1060 |
+
"default": "None",
|
| 1061 |
+
"annotation": "torch.Tensor | None"
|
| 1062 |
+
},
|
| 1063 |
+
{
|
| 1064 |
+
"name": "max_seqlen_q",
|
| 1065 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1066 |
+
"default": "0",
|
| 1067 |
+
"annotation": "int"
|
| 1068 |
+
},
|
| 1069 |
+
{
|
| 1070 |
+
"name": "max_seqlen_k",
|
| 1071 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1072 |
+
"default": "0",
|
| 1073 |
+
"annotation": "int"
|
| 1074 |
+
},
|
| 1075 |
+
{
|
| 1076 |
+
"name": "p_dropout",
|
| 1077 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1078 |
+
"default": "0.0",
|
| 1079 |
+
"annotation": "float"
|
| 1080 |
+
},
|
| 1081 |
+
{
|
| 1082 |
+
"name": "softmax_scale",
|
| 1083 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1084 |
+
"default": "None",
|
| 1085 |
+
"annotation": "float | None"
|
| 1086 |
+
},
|
| 1087 |
+
{
|
| 1088 |
+
"name": "zero_tensors",
|
| 1089 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1090 |
+
"default": "False",
|
| 1091 |
+
"annotation": "bool"
|
| 1092 |
+
},
|
| 1093 |
+
{
|
| 1094 |
+
"name": "is_causal",
|
| 1095 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1096 |
+
"default": "False",
|
| 1097 |
+
"annotation": "bool"
|
| 1098 |
+
},
|
| 1099 |
+
{
|
| 1100 |
+
"name": "window_size_left",
|
| 1101 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1102 |
+
"default": "-1",
|
| 1103 |
+
"annotation": "int"
|
| 1104 |
+
},
|
| 1105 |
+
{
|
| 1106 |
+
"name": "window_size_right",
|
| 1107 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1108 |
+
"default": "-1",
|
| 1109 |
+
"annotation": "int"
|
| 1110 |
+
},
|
| 1111 |
+
{
|
| 1112 |
+
"name": "softcap",
|
| 1113 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1114 |
+
"default": "0.0",
|
| 1115 |
+
"annotation": "float"
|
| 1116 |
+
},
|
| 1117 |
+
{
|
| 1118 |
+
"name": "deterministic",
|
| 1119 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1120 |
+
"default": "False",
|
| 1121 |
+
"annotation": "bool"
|
| 1122 |
+
},
|
| 1123 |
+
{
|
| 1124 |
+
"name": "gen",
|
| 1125 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1126 |
+
"default": "None",
|
| 1127 |
+
"annotation": "torch._C.Generator | None"
|
| 1128 |
+
},
|
| 1129 |
+
{
|
| 1130 |
+
"name": "rng_state",
|
| 1131 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1132 |
+
"default": "None",
|
| 1133 |
+
"annotation": "torch.Tensor | None"
|
| 1134 |
+
}
|
| 1135 |
+
],
|
| 1136 |
+
"return_annotation": "List[torch.Tensor]"
|
| 1137 |
+
}
|
| 1138 |
+
},
|
| 1139 |
+
{
|
| 1140 |
+
"name": "fwd_kvcache",
|
| 1141 |
+
"qualname": "fwd_kvcache",
|
| 1142 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 1143 |
+
"kind": "function",
|
| 1144 |
+
"doc": "Forward pass for multi-head attention with KV cache.\n\nArgs:\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n kcache: Key cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n vcache: Value cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n k: Optional new keys tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]\n v: Optional new values tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]\n seqlens_k: Optional sequence lengths for keys of shape [batch_size]\n rotary_cos: Optional rotary cosine tensor of shape [seqlen_ro, rotary_dim/2]\n rotary_sin: Optional rotary sine tensor of shape [seqlen_ro, rotary_dim/2]\n cache_batch_idx: Optional indices to index into the KV cache\n leftpad_k: Optional left padding for keys of shape [batch_size]\n block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n out: Optional output tensor, same shape as q\n softmax_scale: Scale factor for softmax\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n is_rotary_interleaved: Whether rotary embeddings are interleaved\n num_splits: Number of splits for computation\n\nReturns:\n List of tensors: [output, softmax_lse]",
|
| 1145 |
+
"signature": {
|
| 1146 |
+
"parameters": [
|
| 1147 |
+
{
|
| 1148 |
+
"name": "q",
|
| 1149 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1150 |
+
"default": null,
|
| 1151 |
+
"annotation": "torch.Tensor"
|
| 1152 |
+
},
|
| 1153 |
+
{
|
| 1154 |
+
"name": "kcache",
|
| 1155 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1156 |
+
"default": null,
|
| 1157 |
+
"annotation": "torch.Tensor"
|
| 1158 |
+
},
|
| 1159 |
+
{
|
| 1160 |
+
"name": "vcache",
|
| 1161 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1162 |
+
"default": null,
|
| 1163 |
+
"annotation": "torch.Tensor"
|
| 1164 |
+
},
|
| 1165 |
+
{
|
| 1166 |
+
"name": "k",
|
| 1167 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1168 |
+
"default": "None",
|
| 1169 |
+
"annotation": "torch.Tensor | None"
|
| 1170 |
+
},
|
| 1171 |
+
{
|
| 1172 |
+
"name": "v",
|
| 1173 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1174 |
+
"default": "None",
|
| 1175 |
+
"annotation": "torch.Tensor | None"
|
| 1176 |
+
},
|
| 1177 |
+
{
|
| 1178 |
+
"name": "seqlens_k",
|
| 1179 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1180 |
+
"default": "None",
|
| 1181 |
+
"annotation": "torch.Tensor | None"
|
| 1182 |
+
},
|
| 1183 |
+
{
|
| 1184 |
+
"name": "rotary_cos",
|
| 1185 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1186 |
+
"default": "None",
|
| 1187 |
+
"annotation": "torch.Tensor | None"
|
| 1188 |
+
},
|
| 1189 |
+
{
|
| 1190 |
+
"name": "rotary_sin",
|
| 1191 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1192 |
+
"default": "None",
|
| 1193 |
+
"annotation": "torch.Tensor | None"
|
| 1194 |
+
},
|
| 1195 |
+
{
|
| 1196 |
+
"name": "cache_batch_idx",
|
| 1197 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1198 |
+
"default": "None",
|
| 1199 |
+
"annotation": "torch.Tensor | None"
|
| 1200 |
+
},
|
| 1201 |
+
{
|
| 1202 |
+
"name": "leftpad_k",
|
| 1203 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1204 |
+
"default": "None",
|
| 1205 |
+
"annotation": "torch.Tensor | None"
|
| 1206 |
+
},
|
| 1207 |
+
{
|
| 1208 |
+
"name": "block_table",
|
| 1209 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1210 |
+
"default": "None",
|
| 1211 |
+
"annotation": "torch.Tensor | None"
|
| 1212 |
+
},
|
| 1213 |
+
{
|
| 1214 |
+
"name": "alibi_slopes",
|
| 1215 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1216 |
+
"default": "None",
|
| 1217 |
+
"annotation": "torch.Tensor | None"
|
| 1218 |
+
},
|
| 1219 |
+
{
|
| 1220 |
+
"name": "out",
|
| 1221 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1222 |
+
"default": "None",
|
| 1223 |
+
"annotation": "torch.Tensor | None"
|
| 1224 |
+
},
|
| 1225 |
+
{
|
| 1226 |
+
"name": "softmax_scale",
|
| 1227 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1228 |
+
"default": "None",
|
| 1229 |
+
"annotation": "float | None"
|
| 1230 |
+
},
|
| 1231 |
+
{
|
| 1232 |
+
"name": "is_causal",
|
| 1233 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1234 |
+
"default": "False",
|
| 1235 |
+
"annotation": "bool"
|
| 1236 |
+
},
|
| 1237 |
+
{
|
| 1238 |
+
"name": "window_size_left",
|
| 1239 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1240 |
+
"default": "-1",
|
| 1241 |
+
"annotation": "int"
|
| 1242 |
+
},
|
| 1243 |
+
{
|
| 1244 |
+
"name": "window_size_right",
|
| 1245 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1246 |
+
"default": "-1",
|
| 1247 |
+
"annotation": "int"
|
| 1248 |
+
},
|
| 1249 |
+
{
|
| 1250 |
+
"name": "softcap",
|
| 1251 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1252 |
+
"default": "0.0",
|
| 1253 |
+
"annotation": "float"
|
| 1254 |
+
},
|
| 1255 |
+
{
|
| 1256 |
+
"name": "is_rotary_interleaved",
|
| 1257 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1258 |
+
"default": "False",
|
| 1259 |
+
"annotation": "bool"
|
| 1260 |
+
},
|
| 1261 |
+
{
|
| 1262 |
+
"name": "num_splits",
|
| 1263 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1264 |
+
"default": "1",
|
| 1265 |
+
"annotation": "int"
|
| 1266 |
+
}
|
| 1267 |
+
],
|
| 1268 |
+
"return_annotation": "List[torch.Tensor]"
|
| 1269 |
+
}
|
| 1270 |
+
}
|
| 1271 |
+
],
|
| 1272 |
+
"layers": []
|
| 1273 |
+
}
|
build/torch-stable-abi210-cu132-aarch64-linux/__init__.py
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List, Optional
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
from . import flash_attn_interface
|
| 6 |
+
from ._ops import ops as flash_attn_ops
|
| 7 |
+
from .flash_attn_interface import (
|
| 8 |
+
# helper to set up the Philox random number generator for dropout
|
| 9 |
+
_philox_generator,
|
| 10 |
+
# reexported for convenience to be used in the high-level API functions
|
| 11 |
+
flash_attn_func,
|
| 12 |
+
flash_attn_kvpacked_func,
|
| 13 |
+
flash_attn_qkvpacked_func,
|
| 14 |
+
flash_attn_varlen_func,
|
| 15 |
+
flash_attn_varlen_kvpacked_func,
|
| 16 |
+
flash_attn_varlen_qkvpacked_func,
|
| 17 |
+
flash_attn_with_kvcache,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
__all__ = [
|
| 21 |
+
# High-level API (with autograd support)
|
| 22 |
+
"flash_attn_func",
|
| 23 |
+
"flash_attn_kvpacked_func",
|
| 24 |
+
"flash_attn_qkvpacked_func",
|
| 25 |
+
"flash_attn_varlen_func",
|
| 26 |
+
"flash_attn_varlen_kvpacked_func",
|
| 27 |
+
"flash_attn_varlen_qkvpacked_func",
|
| 28 |
+
"flash_attn_with_kvcache",
|
| 29 |
+
# Upstream interface module. Its `_flash_attn_forward`, `_flash_attn_backward`,
|
| 30 |
+
# `_flash_attn_varlen_forward` and `_flash_attn_varlen_backward` are supported
|
| 31 |
+
# low-level entry points with upstream's signatures: Torch custom ops without
|
| 32 |
+
# autograd that return the LSE and are traceable by torch.compile. The autograd
|
| 33 |
+
# Functions above are built on top of them.
|
| 34 |
+
"flash_attn_interface",
|
| 35 |
+
# Low-level ops (no autograd)
|
| 36 |
+
"fwd",
|
| 37 |
+
"varlen_fwd",
|
| 38 |
+
"bwd",
|
| 39 |
+
"varlen_bwd",
|
| 40 |
+
"fwd_kvcache",
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def fwd(
|
| 45 |
+
q: torch.Tensor,
|
| 46 |
+
k: torch.Tensor,
|
| 47 |
+
v: torch.Tensor,
|
| 48 |
+
out: Optional[torch.Tensor] = None,
|
| 49 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 50 |
+
p_dropout: float = 0.0,
|
| 51 |
+
softmax_scale: Optional[float] = None,
|
| 52 |
+
is_causal: bool = False,
|
| 53 |
+
window_size_left: int = -1,
|
| 54 |
+
window_size_right: int = -1,
|
| 55 |
+
softcap: float = 0.0,
|
| 56 |
+
return_softmax: bool = False,
|
| 57 |
+
gen: Optional[torch.Generator] = None,
|
| 58 |
+
) -> List[torch.Tensor]:
|
| 59 |
+
"""
|
| 60 |
+
Forward pass for multi-head attention.
|
| 61 |
+
|
| 62 |
+
Args:
|
| 63 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 64 |
+
k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 65 |
+
v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 66 |
+
out: Optional output tensor, same shape as q
|
| 67 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 68 |
+
p_dropout: Dropout probability
|
| 69 |
+
softmax_scale: Scale factor for softmax
|
| 70 |
+
is_causal: Whether to use causal attention
|
| 71 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 72 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 73 |
+
softcap: Soft cap for attention weights
|
| 74 |
+
return_softmax: Whether to return softmax weights
|
| 75 |
+
gen: Optional random number generator
|
| 76 |
+
|
| 77 |
+
Returns:
|
| 78 |
+
List of tensors: [output, softmax_lse, (softmax if return_softmax)]
|
| 79 |
+
"""
|
| 80 |
+
if softmax_scale is None:
|
| 81 |
+
attention_head_dim = q.shape[-1]
|
| 82 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 83 |
+
|
| 84 |
+
gen = _philox_generator(q, p_dropout, gen)
|
| 85 |
+
return flash_attn_ops.fwd(
|
| 86 |
+
q,
|
| 87 |
+
k,
|
| 88 |
+
v,
|
| 89 |
+
out,
|
| 90 |
+
alibi_slopes,
|
| 91 |
+
p_dropout,
|
| 92 |
+
softmax_scale,
|
| 93 |
+
is_causal,
|
| 94 |
+
window_size_left,
|
| 95 |
+
window_size_right,
|
| 96 |
+
softcap,
|
| 97 |
+
return_softmax,
|
| 98 |
+
gen,
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def varlen_fwd(
|
| 103 |
+
q: torch.Tensor,
|
| 104 |
+
k: torch.Tensor,
|
| 105 |
+
v: torch.Tensor,
|
| 106 |
+
cu_seqlens_q: torch.Tensor,
|
| 107 |
+
cu_seqlens_k: torch.Tensor,
|
| 108 |
+
out: Optional[torch.Tensor] = None,
|
| 109 |
+
seqused_k: Optional[torch.Tensor] = None,
|
| 110 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 111 |
+
block_table: Optional[torch.Tensor] = None,
|
| 112 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 113 |
+
max_seqlen_q: int = 0,
|
| 114 |
+
max_seqlen_k: int = 0,
|
| 115 |
+
p_dropout: float = 0.0,
|
| 116 |
+
softmax_scale: Optional[float] = None,
|
| 117 |
+
zero_tensors: bool = False,
|
| 118 |
+
is_causal: bool = False,
|
| 119 |
+
window_size_left: int = -1,
|
| 120 |
+
window_size_right: int = -1,
|
| 121 |
+
softcap: float = 0.0,
|
| 122 |
+
return_softmax: bool = False,
|
| 123 |
+
gen: Optional[torch.Generator] = None,
|
| 124 |
+
) -> List[torch.Tensor]:
|
| 125 |
+
"""
|
| 126 |
+
Forward pass for multi-head attention with variable sequence lengths.
|
| 127 |
+
|
| 128 |
+
Args:
|
| 129 |
+
q: Query tensor of shape [total_q, num_heads, head_size]
|
| 130 |
+
k: Key tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 131 |
+
v: Value tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 132 |
+
cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]
|
| 133 |
+
cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]
|
| 134 |
+
out: Optional output tensor of shape [total_q, num_heads, head_size]
|
| 135 |
+
seqused_k: Optional tensor specifying how many keys to use per batch element [batch_size]
|
| 136 |
+
leftpad_k: Optional left padding for keys of shape [batch_size]
|
| 137 |
+
block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]
|
| 138 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 139 |
+
max_seqlen_q: Maximum sequence length for queries
|
| 140 |
+
max_seqlen_k: Maximum sequence length for keys
|
| 141 |
+
p_dropout: Dropout probability
|
| 142 |
+
softmax_scale: Scale factor for softmax
|
| 143 |
+
zero_tensors: Whether to zero tensors before computation
|
| 144 |
+
is_causal: Whether to use causal attention
|
| 145 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 146 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 147 |
+
softcap: Soft cap for attention weights
|
| 148 |
+
return_softmax: Whether to return softmax weights
|
| 149 |
+
gen: Optional random number generator
|
| 150 |
+
|
| 151 |
+
Returns:
|
| 152 |
+
List of tensors: [output, softmax_lse, (softmax if return_softmax)]
|
| 153 |
+
"""
|
| 154 |
+
if softmax_scale is None:
|
| 155 |
+
attention_head_dim = q.shape[-1]
|
| 156 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 157 |
+
|
| 158 |
+
gen = _philox_generator(q, p_dropout, gen)
|
| 159 |
+
return flash_attn_ops.varlen_fwd(
|
| 160 |
+
q,
|
| 161 |
+
k,
|
| 162 |
+
v,
|
| 163 |
+
out,
|
| 164 |
+
cu_seqlens_q,
|
| 165 |
+
cu_seqlens_k,
|
| 166 |
+
seqused_k,
|
| 167 |
+
leftpad_k,
|
| 168 |
+
block_table,
|
| 169 |
+
alibi_slopes,
|
| 170 |
+
max_seqlen_q,
|
| 171 |
+
max_seqlen_k,
|
| 172 |
+
p_dropout,
|
| 173 |
+
softmax_scale,
|
| 174 |
+
zero_tensors,
|
| 175 |
+
is_causal,
|
| 176 |
+
window_size_left,
|
| 177 |
+
window_size_right,
|
| 178 |
+
softcap,
|
| 179 |
+
return_softmax,
|
| 180 |
+
gen,
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def bwd(
|
| 185 |
+
dout: torch.Tensor,
|
| 186 |
+
q: torch.Tensor,
|
| 187 |
+
k: torch.Tensor,
|
| 188 |
+
v: torch.Tensor,
|
| 189 |
+
out: torch.Tensor,
|
| 190 |
+
softmax_lse: torch.Tensor,
|
| 191 |
+
dq: Optional[torch.Tensor] = None,
|
| 192 |
+
dk: Optional[torch.Tensor] = None,
|
| 193 |
+
dv: Optional[torch.Tensor] = None,
|
| 194 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 195 |
+
p_dropout: float = 0.0,
|
| 196 |
+
softmax_scale: Optional[float] = None,
|
| 197 |
+
is_causal: bool = False,
|
| 198 |
+
window_size_left: int = -1,
|
| 199 |
+
window_size_right: int = -1,
|
| 200 |
+
softcap: float = 0.0,
|
| 201 |
+
deterministic: bool = False,
|
| 202 |
+
gen: Optional[torch.Generator] = None,
|
| 203 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 204 |
+
) -> List[torch.Tensor]:
|
| 205 |
+
"""
|
| 206 |
+
Backward pass for multi-head attention.
|
| 207 |
+
|
| 208 |
+
Args:
|
| 209 |
+
dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 210 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 211 |
+
k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 212 |
+
v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 213 |
+
out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 214 |
+
softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]
|
| 215 |
+
dq: Optional gradient tensor for queries, same shape as q
|
| 216 |
+
dk: Optional gradient tensor for keys, same shape as k
|
| 217 |
+
dv: Optional gradient tensor for values, same shape as v
|
| 218 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 219 |
+
p_dropout: Dropout probability
|
| 220 |
+
softmax_scale: Scale factor for softmax
|
| 221 |
+
is_causal: Whether to use causal attention
|
| 222 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 223 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 224 |
+
softcap: Soft cap for attention weights
|
| 225 |
+
deterministic: Whether to use deterministic algorithms
|
| 226 |
+
gen: Optional random number generator
|
| 227 |
+
rng_state: Optional RNG state from forward pass
|
| 228 |
+
|
| 229 |
+
Returns:
|
| 230 |
+
List of tensors: [dq, dk, dv]
|
| 231 |
+
"""
|
| 232 |
+
if softmax_scale is None:
|
| 233 |
+
attention_head_dim = q.shape[-1]
|
| 234 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 235 |
+
|
| 236 |
+
return flash_attn_ops.bwd(
|
| 237 |
+
dout,
|
| 238 |
+
q,
|
| 239 |
+
k,
|
| 240 |
+
v,
|
| 241 |
+
out,
|
| 242 |
+
softmax_lse,
|
| 243 |
+
dq,
|
| 244 |
+
dk,
|
| 245 |
+
dv,
|
| 246 |
+
alibi_slopes,
|
| 247 |
+
p_dropout,
|
| 248 |
+
softmax_scale,
|
| 249 |
+
is_causal,
|
| 250 |
+
window_size_left,
|
| 251 |
+
window_size_right,
|
| 252 |
+
softcap,
|
| 253 |
+
deterministic,
|
| 254 |
+
gen,
|
| 255 |
+
rng_state,
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def varlen_bwd(
|
| 260 |
+
dout: torch.Tensor,
|
| 261 |
+
q: torch.Tensor,
|
| 262 |
+
k: torch.Tensor,
|
| 263 |
+
v: torch.Tensor,
|
| 264 |
+
out: torch.Tensor,
|
| 265 |
+
softmax_lse: torch.Tensor,
|
| 266 |
+
cu_seqlens_q: torch.Tensor,
|
| 267 |
+
cu_seqlens_k: torch.Tensor,
|
| 268 |
+
dq: Optional[torch.Tensor] = None,
|
| 269 |
+
dk: Optional[torch.Tensor] = None,
|
| 270 |
+
dv: Optional[torch.Tensor] = None,
|
| 271 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 272 |
+
max_seqlen_q: int = 0,
|
| 273 |
+
max_seqlen_k: int = 0,
|
| 274 |
+
p_dropout: float = 0.0,
|
| 275 |
+
softmax_scale: Optional[float] = None,
|
| 276 |
+
zero_tensors: bool = False,
|
| 277 |
+
is_causal: bool = False,
|
| 278 |
+
window_size_left: int = -1,
|
| 279 |
+
window_size_right: int = -1,
|
| 280 |
+
softcap: float = 0.0,
|
| 281 |
+
deterministic: bool = False,
|
| 282 |
+
gen: Optional[torch.Generator] = None,
|
| 283 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 284 |
+
) -> List[torch.Tensor]:
|
| 285 |
+
"""
|
| 286 |
+
Backward pass for multi-head attention with variable sequence lengths.
|
| 287 |
+
|
| 288 |
+
Args:
|
| 289 |
+
dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 290 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 291 |
+
k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 292 |
+
v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 293 |
+
out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 294 |
+
softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]
|
| 295 |
+
cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]
|
| 296 |
+
cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]
|
| 297 |
+
dq: Optional gradient tensor for queries, same shape as q
|
| 298 |
+
dk: Optional gradient tensor for keys, same shape as k
|
| 299 |
+
dv: Optional gradient tensor for values, same shape as v
|
| 300 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 301 |
+
max_seqlen_q: Maximum sequence length for queries
|
| 302 |
+
max_seqlen_k: Maximum sequence length for keys
|
| 303 |
+
p_dropout: Dropout probability
|
| 304 |
+
softmax_scale: Scale factor for softmax
|
| 305 |
+
zero_tensors: Whether to zero tensors before computation
|
| 306 |
+
is_causal: Whether to use causal attention
|
| 307 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 308 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 309 |
+
softcap: Soft cap for attention weights
|
| 310 |
+
deterministic: Whether to use deterministic algorithms
|
| 311 |
+
gen: Optional random number generator
|
| 312 |
+
rng_state: Optional RNG state from forward pass
|
| 313 |
+
|
| 314 |
+
Returns:
|
| 315 |
+
List of tensors: [dq, dk, dv]
|
| 316 |
+
"""
|
| 317 |
+
if softmax_scale is None:
|
| 318 |
+
attention_head_dim = q.shape[-1]
|
| 319 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 320 |
+
|
| 321 |
+
return flash_attn_ops.varlen_bwd(
|
| 322 |
+
dout,
|
| 323 |
+
q,
|
| 324 |
+
k,
|
| 325 |
+
v,
|
| 326 |
+
out,
|
| 327 |
+
softmax_lse,
|
| 328 |
+
dq,
|
| 329 |
+
dk,
|
| 330 |
+
dv,
|
| 331 |
+
cu_seqlens_q,
|
| 332 |
+
cu_seqlens_k,
|
| 333 |
+
alibi_slopes,
|
| 334 |
+
max_seqlen_q,
|
| 335 |
+
max_seqlen_k,
|
| 336 |
+
p_dropout,
|
| 337 |
+
softmax_scale,
|
| 338 |
+
zero_tensors,
|
| 339 |
+
is_causal,
|
| 340 |
+
window_size_left,
|
| 341 |
+
window_size_right,
|
| 342 |
+
softcap,
|
| 343 |
+
deterministic,
|
| 344 |
+
gen,
|
| 345 |
+
rng_state,
|
| 346 |
+
)
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
def fwd_kvcache(
|
| 350 |
+
q: torch.Tensor,
|
| 351 |
+
kcache: torch.Tensor,
|
| 352 |
+
vcache: torch.Tensor,
|
| 353 |
+
k: Optional[torch.Tensor] = None,
|
| 354 |
+
v: Optional[torch.Tensor] = None,
|
| 355 |
+
seqlens_k: Optional[torch.Tensor] = None,
|
| 356 |
+
rotary_cos: Optional[torch.Tensor] = None,
|
| 357 |
+
rotary_sin: Optional[torch.Tensor] = None,
|
| 358 |
+
cache_batch_idx: Optional[torch.Tensor] = None,
|
| 359 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 360 |
+
block_table: Optional[torch.Tensor] = None,
|
| 361 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 362 |
+
out: Optional[torch.Tensor] = None,
|
| 363 |
+
softmax_scale: Optional[float] = None,
|
| 364 |
+
is_causal: bool = False,
|
| 365 |
+
window_size_left: int = -1,
|
| 366 |
+
window_size_right: int = -1,
|
| 367 |
+
softcap: float = 0.0,
|
| 368 |
+
is_rotary_interleaved: bool = False,
|
| 369 |
+
num_splits: int = 1,
|
| 370 |
+
) -> List[torch.Tensor]:
|
| 371 |
+
"""
|
| 372 |
+
Forward pass for multi-head attention with KV cache.
|
| 373 |
+
|
| 374 |
+
Args:
|
| 375 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 376 |
+
kcache: Key cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 377 |
+
vcache: Value cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 378 |
+
k: Optional new keys tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]
|
| 379 |
+
v: Optional new values tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]
|
| 380 |
+
seqlens_k: Optional sequence lengths for keys of shape [batch_size]
|
| 381 |
+
rotary_cos: Optional rotary cosine tensor of shape [seqlen_ro, rotary_dim/2]
|
| 382 |
+
rotary_sin: Optional rotary sine tensor of shape [seqlen_ro, rotary_dim/2]
|
| 383 |
+
cache_batch_idx: Optional indices to index into the KV cache
|
| 384 |
+
leftpad_k: Optional left padding for keys of shape [batch_size]
|
| 385 |
+
block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]
|
| 386 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 387 |
+
out: Optional output tensor, same shape as q
|
| 388 |
+
softmax_scale: Scale factor for softmax
|
| 389 |
+
is_causal: Whether to use causal attention
|
| 390 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 391 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 392 |
+
softcap: Soft cap for attention weights
|
| 393 |
+
is_rotary_interleaved: Whether rotary embeddings are interleaved
|
| 394 |
+
num_splits: Number of splits for computation
|
| 395 |
+
|
| 396 |
+
Returns:
|
| 397 |
+
List of tensors: [output, softmax_lse]
|
| 398 |
+
"""
|
| 399 |
+
if softmax_scale is None:
|
| 400 |
+
attention_head_dim = q.shape[-1]
|
| 401 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 402 |
+
|
| 403 |
+
return flash_attn_ops.fwd_kvcache(
|
| 404 |
+
q,
|
| 405 |
+
kcache,
|
| 406 |
+
vcache,
|
| 407 |
+
k,
|
| 408 |
+
v,
|
| 409 |
+
seqlens_k,
|
| 410 |
+
rotary_cos,
|
| 411 |
+
rotary_sin,
|
| 412 |
+
cache_batch_idx,
|
| 413 |
+
leftpad_k,
|
| 414 |
+
block_table,
|
| 415 |
+
alibi_slopes,
|
| 416 |
+
out,
|
| 417 |
+
softmax_scale,
|
| 418 |
+
is_causal,
|
| 419 |
+
window_size_left,
|
| 420 |
+
window_size_right,
|
| 421 |
+
softcap,
|
| 422 |
+
is_rotary_interleaved,
|
| 423 |
+
num_splits,
|
| 424 |
+
)
|
build/torch-stable-abi210-cu132-aarch64-linux/_flash_attn2_cuda_460047c.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a3829f9e740fcc72ea67cd5334a6917943be836f86bd652957fd62f1e3aea3b9
|
| 3 |
+
size 1021117888
|
build/torch-stable-abi210-cu132-aarch64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _flash_attn2_cuda_460047c
|
| 3 |
+
ops = torch.ops._flash_attn2_cuda_460047c
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_flash_attn2_cuda_460047c::{op_name}"
|
build/torch-stable-abi210-cu132-aarch64-linux/flash_attn_interface.py
ADDED
|
@@ -0,0 +1,1708 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2023, Tri Dao.
|
| 2 |
+
|
| 3 |
+
from typing import Optional, Sequence, Tuple, Union
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
import torch.nn as nn
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
# # isort: off
|
| 10 |
+
# # We need to import the CUDA kernels after importing torch
|
| 11 |
+
# USE_TRITON_ROCM = os.getenv("FLASH_ATTENTION_TRITON_AMD_ENABLE", "FALSE") == "TRUE"
|
| 12 |
+
# if USE_TRITON_ROCM:
|
| 13 |
+
# from .flash_attn_triton_amd import interface_fa as flash_attn
|
| 14 |
+
# else:
|
| 15 |
+
# import flash_attn_2_cuda as flash_attn
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
from ._ops import ops as flash_attn
|
| 19 |
+
from ._ops import add_op_namespace_prefix
|
| 20 |
+
|
| 21 |
+
# # isort: on
|
| 22 |
+
|
| 23 |
+
# Torch >= 2.13 can pass a Generator through the stable ABI. Older versions reject the argument
|
| 24 |
+
# before the kernel runs, so there the CUDA op has to draw its Philox seed and offset itself.
|
| 25 |
+
_STABLE_ABI_GENERATOR = torch.__version__ >= "2.13"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def maybe_contiguous(x):
|
| 29 |
+
return x.contiguous() if x is not None and x.stride(-1) != 1 else x
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def _get_device():
|
| 33 |
+
if torch.xpu.is_available():
|
| 34 |
+
return "xpu"
|
| 35 |
+
elif torch.cuda.is_available():
|
| 36 |
+
return "cuda"
|
| 37 |
+
else:
|
| 38 |
+
return "cpu"
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def _get_block_size_n(device, head_dim, is_dropout, is_causal):
|
| 42 |
+
assert head_dim <= 256
|
| 43 |
+
|
| 44 |
+
if device.type == "xpu":
|
| 45 |
+
if head_dim <= 96:
|
| 46 |
+
return 64
|
| 47 |
+
elif head_dim <= 128:
|
| 48 |
+
return 32
|
| 49 |
+
elif head_dim <= 256:
|
| 50 |
+
return 64
|
| 51 |
+
else:
|
| 52 |
+
return 32
|
| 53 |
+
|
| 54 |
+
# This should match the block sizes in the CUDA kernel
|
| 55 |
+
major, minor = torch.cuda.get_device_capability(device)
|
| 56 |
+
is_sm8x = (
|
| 57 |
+
major == 8 and minor > 0
|
| 58 |
+
) # Only include sm86 and sm89, exclude sm80 (A100)
|
| 59 |
+
is_sm80 = major == 8 and minor == 0
|
| 60 |
+
is_sm90 = major == 9 and minor == 0
|
| 61 |
+
if head_dim <= 32:
|
| 62 |
+
return 128
|
| 63 |
+
if head_dim <= 64:
|
| 64 |
+
return 128 if not is_dropout else 64
|
| 65 |
+
elif head_dim <= 96:
|
| 66 |
+
return 64
|
| 67 |
+
elif head_dim <= 128:
|
| 68 |
+
if is_sm8x:
|
| 69 |
+
return 64 if (not is_dropout and is_causal) else 32
|
| 70 |
+
else:
|
| 71 |
+
return 64 if not is_dropout else 32
|
| 72 |
+
elif head_dim <= 192:
|
| 73 |
+
return 64
|
| 74 |
+
elif head_dim <= 224:
|
| 75 |
+
return 64
|
| 76 |
+
elif head_dim <= 256:
|
| 77 |
+
return 64
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def round_multiple(x, m):
|
| 81 |
+
return (x + m - 1) // m * m
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def _philox_generator(
|
| 85 |
+
q: torch.Tensor, dropout_p: float, generator: Optional[torch.Generator] = None
|
| 86 |
+
) -> Optional[torch.Generator]:
|
| 87 |
+
"""The generator to hand to `fwd` / `varlen_fwd`.
|
| 88 |
+
|
| 89 |
+
With dropout on CUDA this is the default generator unless one is given, so the kernel reserves
|
| 90 |
+
its seed and offset exactly like the non-stable build (see set_params_philox in flash_api.cpp).
|
| 91 |
+
"""
|
| 92 |
+
if not q.is_cuda:
|
| 93 |
+
return generator
|
| 94 |
+
if dropout_p <= 0:
|
| 95 |
+
return None
|
| 96 |
+
if not _STABLE_ABI_GENERATOR:
|
| 97 |
+
if generator is not None:
|
| 98 |
+
raise ValueError(
|
| 99 |
+
"flash_attn2: passing a generator to the CUDA kernel requires torch >= 2.13; "
|
| 100 |
+
"seed the default generator with torch.manual_seed instead"
|
| 101 |
+
)
|
| 102 |
+
return None
|
| 103 |
+
if generator is None:
|
| 104 |
+
generator = torch.cuda.default_generators[q.device.index]
|
| 105 |
+
return generator
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
@torch.library.custom_op(
|
| 109 |
+
add_op_namespace_prefix("_flash_attn_forward"),
|
| 110 |
+
mutates_args=(),
|
| 111 |
+
device_types=_get_device(),
|
| 112 |
+
# Tells torch.compile the forward draws random numbers, so it is never deduplicated or
|
| 113 |
+
# recomputed (e.g. under activation checkpointing).
|
| 114 |
+
tags=(torch.Tag.nondeterministic_seeded,),
|
| 115 |
+
)
|
| 116 |
+
def _flash_attn_forward(
|
| 117 |
+
q: torch.Tensor,
|
| 118 |
+
k: torch.Tensor,
|
| 119 |
+
v: torch.Tensor,
|
| 120 |
+
dropout_p: float,
|
| 121 |
+
softmax_scale: float,
|
| 122 |
+
causal: bool,
|
| 123 |
+
window_size_left: int,
|
| 124 |
+
window_size_right: int,
|
| 125 |
+
softcap: float,
|
| 126 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 127 |
+
return_softmax: bool,
|
| 128 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 129 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 130 |
+
gen = _philox_generator(q, dropout_p)
|
| 131 |
+
out, softmax_lse, S_dmask, rng_state = flash_attn.fwd(
|
| 132 |
+
q,
|
| 133 |
+
k,
|
| 134 |
+
v,
|
| 135 |
+
None,
|
| 136 |
+
alibi_slopes,
|
| 137 |
+
dropout_p,
|
| 138 |
+
softmax_scale,
|
| 139 |
+
causal,
|
| 140 |
+
window_size_left,
|
| 141 |
+
window_size_right,
|
| 142 |
+
softcap,
|
| 143 |
+
return_softmax,
|
| 144 |
+
gen,
|
| 145 |
+
)
|
| 146 |
+
return out, softmax_lse, S_dmask, rng_state
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_forward"))
|
| 150 |
+
def _flash_attn_forward_fake(
|
| 151 |
+
q: torch.Tensor,
|
| 152 |
+
k: torch.Tensor,
|
| 153 |
+
v: torch.Tensor,
|
| 154 |
+
dropout_p: float,
|
| 155 |
+
softmax_scale: float,
|
| 156 |
+
causal: bool,
|
| 157 |
+
window_size_left: int,
|
| 158 |
+
window_size_right: int,
|
| 159 |
+
softcap: float,
|
| 160 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 161 |
+
return_softmax: bool,
|
| 162 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 163 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 164 |
+
batch_size, seqlen_q, num_heads, head_size = q.shape
|
| 165 |
+
seqlen_k = k.shape[1]
|
| 166 |
+
out = torch.empty_like(q)
|
| 167 |
+
softmax_lse = torch.empty(
|
| 168 |
+
(batch_size, num_heads, seqlen_q),
|
| 169 |
+
dtype=torch.float32,
|
| 170 |
+
device=q.device,
|
| 171 |
+
layout=q.layout,
|
| 172 |
+
)
|
| 173 |
+
p = torch.empty((0,), dtype=q.dtype, device=q.device, layout=q.layout)
|
| 174 |
+
if return_softmax:
|
| 175 |
+
p = torch.empty(
|
| 176 |
+
(
|
| 177 |
+
batch_size,
|
| 178 |
+
num_heads,
|
| 179 |
+
round_multiple(seqlen_q, 128),
|
| 180 |
+
round_multiple(seqlen_k, 128),
|
| 181 |
+
),
|
| 182 |
+
dtype=q.dtype,
|
| 183 |
+
device=q.device,
|
| 184 |
+
layout=q.layout,
|
| 185 |
+
)
|
| 186 |
+
rng_state = torch.empty((2,), dtype=torch.int64, device=q.device)
|
| 187 |
+
|
| 188 |
+
return out, softmax_lse, p, rng_state
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
_wrapped_flash_attn_forward = flash_attn._flash_attn_forward # upstream alias, see CARD.md
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
@torch.library.custom_op(
|
| 195 |
+
add_op_namespace_prefix("_flash_attn_varlen_forward"),
|
| 196 |
+
mutates_args=(),
|
| 197 |
+
device_types=_get_device(),
|
| 198 |
+
tags=(torch.Tag.nondeterministic_seeded,),
|
| 199 |
+
)
|
| 200 |
+
def _flash_attn_varlen_forward(
|
| 201 |
+
q: torch.Tensor,
|
| 202 |
+
k: torch.Tensor,
|
| 203 |
+
v: torch.Tensor,
|
| 204 |
+
cu_seqlens_q: torch.Tensor,
|
| 205 |
+
cu_seqlens_k: torch.Tensor,
|
| 206 |
+
max_seqlen_q: int,
|
| 207 |
+
max_seqlen_k: int,
|
| 208 |
+
dropout_p: float,
|
| 209 |
+
softmax_scale: float,
|
| 210 |
+
causal: bool,
|
| 211 |
+
window_size_left: int = -1,
|
| 212 |
+
window_size_right: int = -1,
|
| 213 |
+
softcap: float = 0.0,
|
| 214 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 215 |
+
return_softmax: bool = False,
|
| 216 |
+
block_table: Optional[torch.Tensor] = None,
|
| 217 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 218 |
+
seqused_k: Optional[torch.Tensor] = None,
|
| 219 |
+
zero_tensors: bool = False,
|
| 220 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 221 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 222 |
+
gen = _philox_generator(q, dropout_p)
|
| 223 |
+
out, softmax_lse, S_dmask, rng_state = flash_attn.varlen_fwd(
|
| 224 |
+
q,
|
| 225 |
+
k,
|
| 226 |
+
v,
|
| 227 |
+
None,
|
| 228 |
+
cu_seqlens_q,
|
| 229 |
+
cu_seqlens_k,
|
| 230 |
+
seqused_k,
|
| 231 |
+
leftpad_k,
|
| 232 |
+
block_table,
|
| 233 |
+
alibi_slopes,
|
| 234 |
+
max_seqlen_q,
|
| 235 |
+
max_seqlen_k,
|
| 236 |
+
dropout_p,
|
| 237 |
+
softmax_scale,
|
| 238 |
+
zero_tensors,
|
| 239 |
+
causal,
|
| 240 |
+
window_size_left,
|
| 241 |
+
window_size_right,
|
| 242 |
+
softcap,
|
| 243 |
+
return_softmax,
|
| 244 |
+
gen,
|
| 245 |
+
)
|
| 246 |
+
# if out.isnan().any() or softmax_lse.isnan().any():
|
| 247 |
+
# breakpoint()
|
| 248 |
+
return out, softmax_lse, S_dmask, rng_state
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_varlen_forward"))
|
| 252 |
+
def _flash_attn_varlen_forward_fake(
|
| 253 |
+
q: torch.Tensor,
|
| 254 |
+
k: torch.Tensor,
|
| 255 |
+
v: torch.Tensor,
|
| 256 |
+
cu_seqlens_q: torch.Tensor,
|
| 257 |
+
cu_seqlens_k: torch.Tensor,
|
| 258 |
+
max_seqlen_q: int,
|
| 259 |
+
max_seqlen_k: int,
|
| 260 |
+
dropout_p: float,
|
| 261 |
+
softmax_scale: float,
|
| 262 |
+
causal: bool,
|
| 263 |
+
window_size_left: int = -1,
|
| 264 |
+
window_size_right: int = -1,
|
| 265 |
+
softcap: float = 0.0,
|
| 266 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 267 |
+
return_softmax: bool = False,
|
| 268 |
+
block_table: Optional[torch.Tensor] = None,
|
| 269 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 270 |
+
seqused_k: Optional[torch.Tensor] = None,
|
| 271 |
+
zero_tensors: bool = False,
|
| 272 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 273 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 274 |
+
paged_kv = block_table is not None
|
| 275 |
+
batch_size = cu_seqlens_q.numel() - 1
|
| 276 |
+
total_q, num_heads, _ = q.shape
|
| 277 |
+
|
| 278 |
+
out = torch.empty_like(q)
|
| 279 |
+
softmax_lse = torch.empty(
|
| 280 |
+
(num_heads, total_q), dtype=torch.float32, device=q.device, layout=q.layout
|
| 281 |
+
)
|
| 282 |
+
p = torch.empty((0,), dtype=q.dtype, device=q.device, layout=q.layout)
|
| 283 |
+
seqlen_q_rounded = round_multiple(max_seqlen_q, 128)
|
| 284 |
+
seqlen_k_rounded = round_multiple(max_seqlen_k, 128)
|
| 285 |
+
if return_softmax:
|
| 286 |
+
p = torch.empty(
|
| 287 |
+
(batch_size, num_heads, seqlen_q_rounded, seqlen_k_rounded),
|
| 288 |
+
dtype=q.dtype,
|
| 289 |
+
device=q.device,
|
| 290 |
+
layout=q.layout,
|
| 291 |
+
)
|
| 292 |
+
rng_state = torch.empty((2,), dtype=torch.int64, device=q.device)
|
| 293 |
+
return out, softmax_lse, p, rng_state
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
_wrapped_flash_attn_varlen_forward = flash_attn._flash_attn_varlen_forward # upstream alias, see CARD.md
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
@torch.library.custom_op(
|
| 300 |
+
add_op_namespace_prefix("_flash_attn_backward"),
|
| 301 |
+
mutates_args=("dq", "dk", "dv"),
|
| 302 |
+
device_types=_get_device(),
|
| 303 |
+
)
|
| 304 |
+
def _flash_attn_backward(
|
| 305 |
+
dout: torch.Tensor,
|
| 306 |
+
q: torch.Tensor,
|
| 307 |
+
k: torch.Tensor,
|
| 308 |
+
v: torch.Tensor,
|
| 309 |
+
out: torch.Tensor,
|
| 310 |
+
softmax_lse: torch.Tensor,
|
| 311 |
+
dq: Optional[torch.Tensor],
|
| 312 |
+
dk: Optional[torch.Tensor],
|
| 313 |
+
dv: Optional[torch.Tensor],
|
| 314 |
+
dropout_p: float,
|
| 315 |
+
softmax_scale: float,
|
| 316 |
+
causal: bool,
|
| 317 |
+
window_size_left: int,
|
| 318 |
+
window_size_right: int,
|
| 319 |
+
softcap: float,
|
| 320 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 321 |
+
deterministic: bool,
|
| 322 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 323 |
+
) -> torch.Tensor:
|
| 324 |
+
# dq, dk, dv are allocated by us so they should already be contiguous
|
| 325 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 326 |
+
(
|
| 327 |
+
dq,
|
| 328 |
+
dk,
|
| 329 |
+
dv,
|
| 330 |
+
softmax_d,
|
| 331 |
+
) = flash_attn.bwd(
|
| 332 |
+
dout,
|
| 333 |
+
q,
|
| 334 |
+
k,
|
| 335 |
+
v,
|
| 336 |
+
out,
|
| 337 |
+
softmax_lse,
|
| 338 |
+
dq,
|
| 339 |
+
dk,
|
| 340 |
+
dv,
|
| 341 |
+
alibi_slopes,
|
| 342 |
+
dropout_p,
|
| 343 |
+
softmax_scale,
|
| 344 |
+
causal,
|
| 345 |
+
window_size_left,
|
| 346 |
+
window_size_right,
|
| 347 |
+
softcap,
|
| 348 |
+
deterministic,
|
| 349 |
+
None,
|
| 350 |
+
rng_state,
|
| 351 |
+
)
|
| 352 |
+
return softmax_d
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_backward"))
|
| 356 |
+
def _flash_attn_backward_fake(
|
| 357 |
+
dout: torch.Tensor,
|
| 358 |
+
q: torch.Tensor,
|
| 359 |
+
k: torch.Tensor,
|
| 360 |
+
v: torch.Tensor,
|
| 361 |
+
out: torch.Tensor,
|
| 362 |
+
softmax_lse: torch.Tensor,
|
| 363 |
+
dq: Optional[torch.Tensor],
|
| 364 |
+
dk: Optional[torch.Tensor],
|
| 365 |
+
dv: Optional[torch.Tensor],
|
| 366 |
+
dropout_p: float,
|
| 367 |
+
softmax_scale: float,
|
| 368 |
+
causal: bool,
|
| 369 |
+
window_size_left: int,
|
| 370 |
+
window_size_right: int,
|
| 371 |
+
softcap: float,
|
| 372 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 373 |
+
deterministic: bool,
|
| 374 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 375 |
+
) -> torch.Tensor:
|
| 376 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 377 |
+
if dq is None:
|
| 378 |
+
dq = torch.empty_like(q)
|
| 379 |
+
if dk is None:
|
| 380 |
+
dk = torch.empty_like(k)
|
| 381 |
+
if dv is None:
|
| 382 |
+
dv = torch.empty_like(v)
|
| 383 |
+
batch_size, seqlen_q, num_heads, _ = q.shape
|
| 384 |
+
softmax_d = torch.empty(
|
| 385 |
+
(batch_size, num_heads, round_multiple(seqlen_q, 128)),
|
| 386 |
+
device=q.device,
|
| 387 |
+
dtype=torch.float32,
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
return softmax_d
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
_wrapped_flash_attn_backward = flash_attn._flash_attn_backward # upstream alias, see CARD.md
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
@torch.library.custom_op(
|
| 397 |
+
add_op_namespace_prefix("_flash_attn_varlen_backward"),
|
| 398 |
+
mutates_args=("dq", "dk", "dv"),
|
| 399 |
+
device_types=_get_device(),
|
| 400 |
+
)
|
| 401 |
+
def _flash_attn_varlen_backward(
|
| 402 |
+
dout: torch.Tensor,
|
| 403 |
+
q: torch.Tensor,
|
| 404 |
+
k: torch.Tensor,
|
| 405 |
+
v: torch.Tensor,
|
| 406 |
+
out: torch.Tensor,
|
| 407 |
+
softmax_lse: torch.Tensor,
|
| 408 |
+
dq: Optional[torch.Tensor],
|
| 409 |
+
dk: Optional[torch.Tensor],
|
| 410 |
+
dv: Optional[torch.Tensor],
|
| 411 |
+
cu_seqlens_q: torch.Tensor,
|
| 412 |
+
cu_seqlens_k: torch.Tensor,
|
| 413 |
+
max_seqlen_q: int,
|
| 414 |
+
max_seqlen_k: int,
|
| 415 |
+
dropout_p: float,
|
| 416 |
+
softmax_scale: float,
|
| 417 |
+
causal: bool,
|
| 418 |
+
window_size_left: int,
|
| 419 |
+
window_size_right: int,
|
| 420 |
+
softcap: float,
|
| 421 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 422 |
+
deterministic: bool,
|
| 423 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 424 |
+
zero_tensors: bool = False,
|
| 425 |
+
) -> torch.Tensor:
|
| 426 |
+
# dq, dk, dv are allocated by us so they should already be contiguous
|
| 427 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 428 |
+
(
|
| 429 |
+
dq,
|
| 430 |
+
dk,
|
| 431 |
+
dv,
|
| 432 |
+
softmax_d,
|
| 433 |
+
) = flash_attn.varlen_bwd(
|
| 434 |
+
dout,
|
| 435 |
+
q,
|
| 436 |
+
k,
|
| 437 |
+
v,
|
| 438 |
+
out,
|
| 439 |
+
softmax_lse,
|
| 440 |
+
dq,
|
| 441 |
+
dk,
|
| 442 |
+
dv,
|
| 443 |
+
cu_seqlens_q,
|
| 444 |
+
cu_seqlens_k,
|
| 445 |
+
alibi_slopes,
|
| 446 |
+
max_seqlen_q,
|
| 447 |
+
max_seqlen_k,
|
| 448 |
+
dropout_p,
|
| 449 |
+
softmax_scale,
|
| 450 |
+
zero_tensors,
|
| 451 |
+
causal,
|
| 452 |
+
window_size_left,
|
| 453 |
+
window_size_right,
|
| 454 |
+
softcap,
|
| 455 |
+
deterministic,
|
| 456 |
+
None,
|
| 457 |
+
rng_state,
|
| 458 |
+
)
|
| 459 |
+
# if dk.isnan().any() or dk.isnan().any() or dv.isnan().any() or softmax_d.isnan().any():
|
| 460 |
+
# breakpoint()
|
| 461 |
+
return softmax_d
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_varlen_backward"))
|
| 465 |
+
def _flash_attn_varlen_backward_fake(
|
| 466 |
+
dout: torch.Tensor,
|
| 467 |
+
q: torch.Tensor,
|
| 468 |
+
k: torch.Tensor,
|
| 469 |
+
v: torch.Tensor,
|
| 470 |
+
out: torch.Tensor,
|
| 471 |
+
softmax_lse: torch.Tensor,
|
| 472 |
+
dq: Optional[torch.Tensor],
|
| 473 |
+
dk: Optional[torch.Tensor],
|
| 474 |
+
dv: Optional[torch.Tensor],
|
| 475 |
+
cu_seqlens_q: torch.Tensor,
|
| 476 |
+
cu_seqlens_k: torch.Tensor,
|
| 477 |
+
max_seqlen_q: int,
|
| 478 |
+
max_seqlen_k: int,
|
| 479 |
+
dropout_p: float,
|
| 480 |
+
softmax_scale: float,
|
| 481 |
+
causal: bool,
|
| 482 |
+
window_size_left: int,
|
| 483 |
+
window_size_right: int,
|
| 484 |
+
softcap: float,
|
| 485 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 486 |
+
deterministic: bool,
|
| 487 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 488 |
+
zero_tensors: bool = False,
|
| 489 |
+
) -> torch.Tensor:
|
| 490 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 491 |
+
batch_size = cu_seqlens_q.numel() - 1
|
| 492 |
+
total_q, num_heads, _ = q.shape
|
| 493 |
+
|
| 494 |
+
if dq is None:
|
| 495 |
+
dq = torch.empty_like(q)
|
| 496 |
+
if dk is None:
|
| 497 |
+
dk = torch.empty_like(k)
|
| 498 |
+
if dv is None:
|
| 499 |
+
dv = torch.empty_like(v)
|
| 500 |
+
softmax_d = torch.empty(
|
| 501 |
+
(num_heads, total_q + 128 * batch_size), device=q.device, dtype=torch.float32
|
| 502 |
+
)
|
| 503 |
+
|
| 504 |
+
return softmax_d
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
_wrapped_flash_attn_varlen_backward = flash_attn._flash_attn_varlen_backward # upstream alias, see CARD.md
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
class FlashAttnQKVPackedFunc(torch.autograd.Function):
|
| 511 |
+
@staticmethod
|
| 512 |
+
def forward(
|
| 513 |
+
ctx,
|
| 514 |
+
qkv,
|
| 515 |
+
dropout_p,
|
| 516 |
+
softmax_scale,
|
| 517 |
+
causal,
|
| 518 |
+
window_size,
|
| 519 |
+
softcap,
|
| 520 |
+
alibi_slopes,
|
| 521 |
+
deterministic,
|
| 522 |
+
return_softmax,
|
| 523 |
+
is_grad_enabled,
|
| 524 |
+
):
|
| 525 |
+
is_grad = is_grad_enabled and qkv.requires_grad
|
| 526 |
+
if softmax_scale is None:
|
| 527 |
+
softmax_scale = qkv.shape[-1] ** (-0.5)
|
| 528 |
+
q, k, v = qkv[:, :, 0].detach(), qkv[:, :, 1].detach(), qkv[:, :, 2].detach()
|
| 529 |
+
head_size_og = q.size(3)
|
| 530 |
+
if head_size_og % 8 != 0:
|
| 531 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 532 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 533 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 534 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_forward(
|
| 535 |
+
q,
|
| 536 |
+
k,
|
| 537 |
+
v,
|
| 538 |
+
dropout_p,
|
| 539 |
+
softmax_scale,
|
| 540 |
+
causal=causal,
|
| 541 |
+
window_size_left=window_size[0],
|
| 542 |
+
window_size_right=window_size[1],
|
| 543 |
+
softcap=softcap,
|
| 544 |
+
alibi_slopes=alibi_slopes,
|
| 545 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 546 |
+
)
|
| 547 |
+
if is_grad:
|
| 548 |
+
ctx.save_for_backward(q, k, v, out_padded, softmax_lse, rng_state)
|
| 549 |
+
ctx.dropout_p = dropout_p
|
| 550 |
+
ctx.softmax_scale = softmax_scale
|
| 551 |
+
ctx.causal = causal
|
| 552 |
+
ctx.window_size = window_size
|
| 553 |
+
ctx.softcap = softcap
|
| 554 |
+
ctx.alibi_slopes = alibi_slopes
|
| 555 |
+
ctx.deterministic = deterministic
|
| 556 |
+
out = out_padded[..., :head_size_og]
|
| 557 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 558 |
+
|
| 559 |
+
@staticmethod
|
| 560 |
+
def backward(ctx, dout, *args):
|
| 561 |
+
q, k, v, out, softmax_lse, rng_state = ctx.saved_tensors
|
| 562 |
+
qkv_shape = q.shape[:-2] + (3, *q.shape[-2:])
|
| 563 |
+
dqkv = torch.empty(qkv_shape, dtype=q.dtype, device=q.device)
|
| 564 |
+
head_size_og = dout.size(3)
|
| 565 |
+
dout_padded = dout
|
| 566 |
+
if head_size_og % 8 != 0:
|
| 567 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 568 |
+
_flash_attn_backward(
|
| 569 |
+
dout_padded,
|
| 570 |
+
q,
|
| 571 |
+
k,
|
| 572 |
+
v,
|
| 573 |
+
out,
|
| 574 |
+
softmax_lse,
|
| 575 |
+
dqkv[:, :, 0],
|
| 576 |
+
dqkv[:, :, 1],
|
| 577 |
+
dqkv[:, :, 2],
|
| 578 |
+
ctx.dropout_p,
|
| 579 |
+
ctx.softmax_scale,
|
| 580 |
+
ctx.causal,
|
| 581 |
+
ctx.window_size[0],
|
| 582 |
+
ctx.window_size[1],
|
| 583 |
+
ctx.softcap,
|
| 584 |
+
ctx.alibi_slopes,
|
| 585 |
+
ctx.deterministic,
|
| 586 |
+
rng_state=rng_state,
|
| 587 |
+
)
|
| 588 |
+
dqkv = dqkv[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 589 |
+
return dqkv, None, None, None, None, None, None, None, None, None
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
class FlashAttnVarlenQKVPackedFunc(torch.autograd.Function):
|
| 593 |
+
@staticmethod
|
| 594 |
+
def forward(
|
| 595 |
+
ctx,
|
| 596 |
+
qkv,
|
| 597 |
+
cu_seqlens,
|
| 598 |
+
max_seqlen,
|
| 599 |
+
dropout_p,
|
| 600 |
+
softmax_scale,
|
| 601 |
+
causal,
|
| 602 |
+
window_size,
|
| 603 |
+
softcap,
|
| 604 |
+
alibi_slopes,
|
| 605 |
+
deterministic,
|
| 606 |
+
return_softmax,
|
| 607 |
+
is_grad_enabled,
|
| 608 |
+
):
|
| 609 |
+
is_grad = is_grad_enabled and qkv.requires_grad
|
| 610 |
+
if softmax_scale is None:
|
| 611 |
+
softmax_scale = qkv.shape[-1] ** (-0.5)
|
| 612 |
+
q, k, v = qkv[:, 0].detach(), qkv[:, 1].detach(), qkv[:, 2].detach()
|
| 613 |
+
head_size_og = q.size(2)
|
| 614 |
+
if head_size_og % 8 != 0:
|
| 615 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 616 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 617 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 618 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_varlen_forward(
|
| 619 |
+
q,
|
| 620 |
+
k,
|
| 621 |
+
v,
|
| 622 |
+
cu_seqlens,
|
| 623 |
+
cu_seqlens,
|
| 624 |
+
max_seqlen,
|
| 625 |
+
max_seqlen,
|
| 626 |
+
dropout_p,
|
| 627 |
+
softmax_scale,
|
| 628 |
+
causal=causal,
|
| 629 |
+
window_size_left=window_size[0],
|
| 630 |
+
window_size_right=window_size[1],
|
| 631 |
+
softcap=softcap,
|
| 632 |
+
alibi_slopes=alibi_slopes,
|
| 633 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 634 |
+
block_table=None,
|
| 635 |
+
)
|
| 636 |
+
if is_grad:
|
| 637 |
+
ctx.save_for_backward(
|
| 638 |
+
q, k, v, out_padded, softmax_lse, cu_seqlens, rng_state
|
| 639 |
+
)
|
| 640 |
+
ctx.dropout_p = dropout_p
|
| 641 |
+
ctx.max_seqlen = max_seqlen
|
| 642 |
+
ctx.softmax_scale = softmax_scale
|
| 643 |
+
ctx.causal = causal
|
| 644 |
+
ctx.window_size = window_size
|
| 645 |
+
ctx.softcap = softcap
|
| 646 |
+
ctx.alibi_slopes = alibi_slopes
|
| 647 |
+
ctx.deterministic = deterministic
|
| 648 |
+
out = out_padded[..., :head_size_og]
|
| 649 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 650 |
+
|
| 651 |
+
@staticmethod
|
| 652 |
+
def backward(ctx, dout, *args):
|
| 653 |
+
q, k, v, out, softmax_lse, cu_seqlens, rng_state = ctx.saved_tensors
|
| 654 |
+
qkv_shape = q.shape[:-2] + (3, *q.shape[-2:])
|
| 655 |
+
dqkv = torch.empty(qkv_shape, dtype=q.dtype, device=q.device)
|
| 656 |
+
head_size_og = dout.size(2)
|
| 657 |
+
dout_padded = dout
|
| 658 |
+
if head_size_og % 8 != 0:
|
| 659 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 660 |
+
_flash_attn_varlen_backward(
|
| 661 |
+
dout_padded,
|
| 662 |
+
q,
|
| 663 |
+
k,
|
| 664 |
+
v,
|
| 665 |
+
out,
|
| 666 |
+
softmax_lse,
|
| 667 |
+
dqkv[:, 0],
|
| 668 |
+
dqkv[:, 1],
|
| 669 |
+
dqkv[:, 2],
|
| 670 |
+
cu_seqlens,
|
| 671 |
+
cu_seqlens,
|
| 672 |
+
ctx.max_seqlen,
|
| 673 |
+
ctx.max_seqlen,
|
| 674 |
+
ctx.dropout_p,
|
| 675 |
+
ctx.softmax_scale,
|
| 676 |
+
ctx.causal,
|
| 677 |
+
ctx.window_size[0],
|
| 678 |
+
ctx.window_size[1],
|
| 679 |
+
ctx.softcap,
|
| 680 |
+
ctx.alibi_slopes,
|
| 681 |
+
ctx.deterministic,
|
| 682 |
+
rng_state=rng_state,
|
| 683 |
+
)
|
| 684 |
+
dqkv = dqkv[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 685 |
+
return dqkv, None, None, None, None, None, None, None, None, None, None, None
|
| 686 |
+
|
| 687 |
+
|
| 688 |
+
class FlashAttnKVPackedFunc(torch.autograd.Function):
|
| 689 |
+
@staticmethod
|
| 690 |
+
def forward(
|
| 691 |
+
ctx,
|
| 692 |
+
q,
|
| 693 |
+
kv,
|
| 694 |
+
dropout_p,
|
| 695 |
+
softmax_scale,
|
| 696 |
+
causal,
|
| 697 |
+
window_size,
|
| 698 |
+
softcap,
|
| 699 |
+
alibi_slopes,
|
| 700 |
+
deterministic,
|
| 701 |
+
return_softmax,
|
| 702 |
+
is_grad_enabled,
|
| 703 |
+
):
|
| 704 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, kv])
|
| 705 |
+
if softmax_scale is None:
|
| 706 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 707 |
+
k, v = kv[:, :, 0].detach(), kv[:, :, 1].detach()
|
| 708 |
+
head_size_og = q.size(3)
|
| 709 |
+
if head_size_og % 8 != 0:
|
| 710 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 711 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 712 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 713 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_forward(
|
| 714 |
+
q,
|
| 715 |
+
k,
|
| 716 |
+
v,
|
| 717 |
+
dropout_p,
|
| 718 |
+
softmax_scale,
|
| 719 |
+
causal=causal,
|
| 720 |
+
window_size_left=window_size[0],
|
| 721 |
+
window_size_right=window_size[1],
|
| 722 |
+
softcap=softcap,
|
| 723 |
+
alibi_slopes=alibi_slopes,
|
| 724 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 725 |
+
)
|
| 726 |
+
if is_grad:
|
| 727 |
+
ctx.save_for_backward(q, k, v, out_padded, softmax_lse, rng_state)
|
| 728 |
+
ctx.dropout_p = dropout_p
|
| 729 |
+
ctx.softmax_scale = softmax_scale
|
| 730 |
+
ctx.causal = causal
|
| 731 |
+
ctx.window_size = window_size
|
| 732 |
+
ctx.softcap = softcap
|
| 733 |
+
ctx.alibi_slopes = alibi_slopes
|
| 734 |
+
ctx.deterministic = deterministic
|
| 735 |
+
out = out_padded[..., :head_size_og]
|
| 736 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 737 |
+
|
| 738 |
+
@staticmethod
|
| 739 |
+
def backward(ctx, dout, *args):
|
| 740 |
+
q, k, v, out, softmax_lse, rng_state = ctx.saved_tensors
|
| 741 |
+
dq = torch.empty_like(q)
|
| 742 |
+
kv_shape = k.shape[:-2] + (2, *k.shape[-2:])
|
| 743 |
+
dkv = torch.empty(kv_shape, dtype=k.dtype, device=k.device)
|
| 744 |
+
head_size_og = dout.size(3)
|
| 745 |
+
dout_padded = dout
|
| 746 |
+
if head_size_og % 8 != 0:
|
| 747 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 748 |
+
_flash_attn_backward(
|
| 749 |
+
dout_padded,
|
| 750 |
+
q,
|
| 751 |
+
k,
|
| 752 |
+
v,
|
| 753 |
+
out,
|
| 754 |
+
softmax_lse,
|
| 755 |
+
dq,
|
| 756 |
+
dkv[:, :, 0],
|
| 757 |
+
dkv[:, :, 1],
|
| 758 |
+
ctx.dropout_p,
|
| 759 |
+
ctx.softmax_scale,
|
| 760 |
+
ctx.causal,
|
| 761 |
+
ctx.window_size[0],
|
| 762 |
+
ctx.window_size[1],
|
| 763 |
+
ctx.softcap,
|
| 764 |
+
ctx.alibi_slopes,
|
| 765 |
+
ctx.deterministic,
|
| 766 |
+
rng_state=rng_state,
|
| 767 |
+
)
|
| 768 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 769 |
+
dkv = dkv[..., : dout.shape[-1]]
|
| 770 |
+
return dq, dkv, None, None, None, None, None, None, None, None, None
|
| 771 |
+
|
| 772 |
+
|
| 773 |
+
class FlashAttnVarlenKVPackedFunc(torch.autograd.Function):
|
| 774 |
+
@staticmethod
|
| 775 |
+
def forward(
|
| 776 |
+
ctx,
|
| 777 |
+
q,
|
| 778 |
+
kv,
|
| 779 |
+
cu_seqlens_q,
|
| 780 |
+
cu_seqlens_k,
|
| 781 |
+
max_seqlen_q,
|
| 782 |
+
max_seqlen_k,
|
| 783 |
+
dropout_p,
|
| 784 |
+
softmax_scale,
|
| 785 |
+
causal,
|
| 786 |
+
window_size,
|
| 787 |
+
softcap,
|
| 788 |
+
alibi_slopes,
|
| 789 |
+
deterministic,
|
| 790 |
+
return_softmax,
|
| 791 |
+
is_grad_enabled,
|
| 792 |
+
):
|
| 793 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, kv])
|
| 794 |
+
if softmax_scale is None:
|
| 795 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 796 |
+
k, v = kv[:, 0].detach(), kv[:, 1].detach()
|
| 797 |
+
head_size_og = q.size(2)
|
| 798 |
+
if head_size_og % 8 != 0:
|
| 799 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 800 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 801 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 802 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_varlen_forward(
|
| 803 |
+
q,
|
| 804 |
+
k,
|
| 805 |
+
v,
|
| 806 |
+
cu_seqlens_q,
|
| 807 |
+
cu_seqlens_k,
|
| 808 |
+
max_seqlen_q,
|
| 809 |
+
max_seqlen_k,
|
| 810 |
+
dropout_p,
|
| 811 |
+
softmax_scale,
|
| 812 |
+
causal=causal,
|
| 813 |
+
window_size_left=window_size[0],
|
| 814 |
+
window_size_right=window_size[1],
|
| 815 |
+
softcap=softcap,
|
| 816 |
+
alibi_slopes=alibi_slopes,
|
| 817 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 818 |
+
block_table=None,
|
| 819 |
+
)
|
| 820 |
+
if is_grad:
|
| 821 |
+
ctx.save_for_backward(
|
| 822 |
+
q, k, v, out_padded, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state
|
| 823 |
+
)
|
| 824 |
+
ctx.dropout_p = dropout_p
|
| 825 |
+
ctx.max_seqlen_q = max_seqlen_q
|
| 826 |
+
ctx.max_seqlen_k = max_seqlen_k
|
| 827 |
+
ctx.softmax_scale = softmax_scale
|
| 828 |
+
ctx.causal = causal
|
| 829 |
+
ctx.window_size = window_size
|
| 830 |
+
ctx.softcap = softcap
|
| 831 |
+
ctx.alibi_slopes = alibi_slopes
|
| 832 |
+
ctx.deterministic = deterministic
|
| 833 |
+
out = out_padded[..., :head_size_og]
|
| 834 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 835 |
+
|
| 836 |
+
@staticmethod
|
| 837 |
+
def backward(ctx, dout, *args):
|
| 838 |
+
q, k, v, out, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state = (
|
| 839 |
+
ctx.saved_tensors
|
| 840 |
+
)
|
| 841 |
+
dq = torch.empty_like(q)
|
| 842 |
+
kv_shape = k.shape[:-2] + (2, *k.shape[-2:])
|
| 843 |
+
dkv = torch.empty(kv_shape, dtype=k.dtype, device=k.device)
|
| 844 |
+
head_size_og = dout.size(2)
|
| 845 |
+
dout_padded = dout
|
| 846 |
+
if head_size_og % 8 != 0:
|
| 847 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 848 |
+
_flash_attn_varlen_backward(
|
| 849 |
+
dout_padded,
|
| 850 |
+
q,
|
| 851 |
+
k,
|
| 852 |
+
v,
|
| 853 |
+
out,
|
| 854 |
+
softmax_lse,
|
| 855 |
+
dq,
|
| 856 |
+
dkv[:, 0],
|
| 857 |
+
dkv[:, 1],
|
| 858 |
+
cu_seqlens_q,
|
| 859 |
+
cu_seqlens_k,
|
| 860 |
+
ctx.max_seqlen_q,
|
| 861 |
+
ctx.max_seqlen_k,
|
| 862 |
+
ctx.dropout_p,
|
| 863 |
+
ctx.softmax_scale,
|
| 864 |
+
ctx.causal,
|
| 865 |
+
ctx.window_size[0],
|
| 866 |
+
ctx.window_size[1],
|
| 867 |
+
ctx.softcap,
|
| 868 |
+
ctx.alibi_slopes,
|
| 869 |
+
ctx.deterministic,
|
| 870 |
+
rng_state=rng_state,
|
| 871 |
+
)
|
| 872 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 873 |
+
dkv = dkv[..., : dout.shape[-1]]
|
| 874 |
+
return (
|
| 875 |
+
dq,
|
| 876 |
+
dkv,
|
| 877 |
+
None,
|
| 878 |
+
None,
|
| 879 |
+
None,
|
| 880 |
+
None,
|
| 881 |
+
None,
|
| 882 |
+
None,
|
| 883 |
+
None,
|
| 884 |
+
None,
|
| 885 |
+
None,
|
| 886 |
+
None,
|
| 887 |
+
None,
|
| 888 |
+
None,
|
| 889 |
+
None,
|
| 890 |
+
)
|
| 891 |
+
|
| 892 |
+
|
| 893 |
+
class FlashAttnFunc(torch.autograd.Function):
|
| 894 |
+
@staticmethod
|
| 895 |
+
def forward(
|
| 896 |
+
ctx,
|
| 897 |
+
q,
|
| 898 |
+
k,
|
| 899 |
+
v,
|
| 900 |
+
dropout_p,
|
| 901 |
+
softmax_scale,
|
| 902 |
+
causal,
|
| 903 |
+
window_size,
|
| 904 |
+
softcap,
|
| 905 |
+
alibi_slopes,
|
| 906 |
+
deterministic,
|
| 907 |
+
return_softmax,
|
| 908 |
+
is_grad_enabled,
|
| 909 |
+
):
|
| 910 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, k, v])
|
| 911 |
+
if softmax_scale is None:
|
| 912 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 913 |
+
head_size_og = q.size(3)
|
| 914 |
+
if head_size_og % 8 != 0:
|
| 915 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 916 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 917 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 918 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_forward(
|
| 919 |
+
q,
|
| 920 |
+
k,
|
| 921 |
+
v,
|
| 922 |
+
dropout_p,
|
| 923 |
+
softmax_scale,
|
| 924 |
+
causal=causal,
|
| 925 |
+
window_size_left=window_size[0],
|
| 926 |
+
window_size_right=window_size[1],
|
| 927 |
+
softcap=softcap,
|
| 928 |
+
alibi_slopes=alibi_slopes,
|
| 929 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 930 |
+
)
|
| 931 |
+
if is_grad:
|
| 932 |
+
ctx.save_for_backward(q, k, v, out_padded, softmax_lse, rng_state)
|
| 933 |
+
ctx.dropout_p = dropout_p
|
| 934 |
+
ctx.softmax_scale = softmax_scale
|
| 935 |
+
ctx.causal = causal
|
| 936 |
+
ctx.window_size = window_size
|
| 937 |
+
ctx.softcap = softcap
|
| 938 |
+
ctx.alibi_slopes = alibi_slopes
|
| 939 |
+
ctx.deterministic = deterministic
|
| 940 |
+
out = out_padded[..., :head_size_og]
|
| 941 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 942 |
+
|
| 943 |
+
@staticmethod
|
| 944 |
+
def backward(ctx, dout, *args):
|
| 945 |
+
q, k, v, out, softmax_lse, rng_state = ctx.saved_tensors
|
| 946 |
+
dq, dk, dv = torch.empty_like(q), torch.empty_like(k), torch.empty_like(v)
|
| 947 |
+
head_size_og = dout.size(3)
|
| 948 |
+
dout_padded = dout
|
| 949 |
+
if head_size_og % 8 != 0:
|
| 950 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 951 |
+
_flash_attn_backward(
|
| 952 |
+
dout_padded,
|
| 953 |
+
q,
|
| 954 |
+
k,
|
| 955 |
+
v,
|
| 956 |
+
out,
|
| 957 |
+
softmax_lse,
|
| 958 |
+
dq,
|
| 959 |
+
dk,
|
| 960 |
+
dv,
|
| 961 |
+
ctx.dropout_p,
|
| 962 |
+
ctx.softmax_scale,
|
| 963 |
+
ctx.causal,
|
| 964 |
+
ctx.window_size[0],
|
| 965 |
+
ctx.window_size[1],
|
| 966 |
+
ctx.softcap,
|
| 967 |
+
ctx.alibi_slopes,
|
| 968 |
+
ctx.deterministic,
|
| 969 |
+
rng_state=rng_state,
|
| 970 |
+
)
|
| 971 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 972 |
+
dk = dk[..., : dout.shape[-1]]
|
| 973 |
+
dv = dv[..., : dout.shape[-1]]
|
| 974 |
+
return dq, dk, dv, None, None, None, None, None, None, None, None, None
|
| 975 |
+
|
| 976 |
+
|
| 977 |
+
class FlashAttnVarlenFunc(torch.autograd.Function):
|
| 978 |
+
@staticmethod
|
| 979 |
+
def forward(
|
| 980 |
+
ctx,
|
| 981 |
+
q,
|
| 982 |
+
k,
|
| 983 |
+
v,
|
| 984 |
+
cu_seqlens_q,
|
| 985 |
+
cu_seqlens_k,
|
| 986 |
+
max_seqlen_q,
|
| 987 |
+
max_seqlen_k,
|
| 988 |
+
dropout_p,
|
| 989 |
+
softmax_scale,
|
| 990 |
+
causal,
|
| 991 |
+
window_size,
|
| 992 |
+
softcap,
|
| 993 |
+
alibi_slopes,
|
| 994 |
+
deterministic,
|
| 995 |
+
return_softmax,
|
| 996 |
+
block_table,
|
| 997 |
+
is_grad_enabled,
|
| 998 |
+
):
|
| 999 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, k, v])
|
| 1000 |
+
if softmax_scale is None:
|
| 1001 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 1002 |
+
head_size_og = q.size(2)
|
| 1003 |
+
if head_size_og % 8 != 0:
|
| 1004 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 1005 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 1006 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 1007 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_varlen_forward(
|
| 1008 |
+
q,
|
| 1009 |
+
k,
|
| 1010 |
+
v,
|
| 1011 |
+
cu_seqlens_q,
|
| 1012 |
+
cu_seqlens_k,
|
| 1013 |
+
max_seqlen_q,
|
| 1014 |
+
max_seqlen_k,
|
| 1015 |
+
dropout_p,
|
| 1016 |
+
softmax_scale,
|
| 1017 |
+
causal=causal,
|
| 1018 |
+
window_size_left=window_size[0],
|
| 1019 |
+
window_size_right=window_size[1],
|
| 1020 |
+
softcap=softcap,
|
| 1021 |
+
alibi_slopes=alibi_slopes,
|
| 1022 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 1023 |
+
block_table=block_table,
|
| 1024 |
+
)
|
| 1025 |
+
if is_grad:
|
| 1026 |
+
ctx.save_for_backward(
|
| 1027 |
+
q, k, v, out_padded, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state
|
| 1028 |
+
)
|
| 1029 |
+
ctx.dropout_p = dropout_p
|
| 1030 |
+
ctx.max_seqlen_q = max_seqlen_q
|
| 1031 |
+
ctx.max_seqlen_k = max_seqlen_k
|
| 1032 |
+
ctx.softmax_scale = softmax_scale
|
| 1033 |
+
ctx.causal = causal
|
| 1034 |
+
ctx.window_size = window_size
|
| 1035 |
+
ctx.softcap = softcap
|
| 1036 |
+
ctx.alibi_slopes = alibi_slopes
|
| 1037 |
+
ctx.deterministic = deterministic
|
| 1038 |
+
|
| 1039 |
+
out = out_padded[..., :head_size_og]
|
| 1040 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 1041 |
+
|
| 1042 |
+
@staticmethod
|
| 1043 |
+
def backward(ctx, dout, *args):
|
| 1044 |
+
q, k, v, out, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state = (
|
| 1045 |
+
ctx.saved_tensors
|
| 1046 |
+
)
|
| 1047 |
+
dq, dk, dv = torch.empty_like(q), torch.empty_like(k), torch.empty_like(v)
|
| 1048 |
+
head_size_og = dout.size(2)
|
| 1049 |
+
dout_padded = dout
|
| 1050 |
+
if head_size_og % 8 != 0:
|
| 1051 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 1052 |
+
_flash_attn_varlen_backward(
|
| 1053 |
+
dout_padded,
|
| 1054 |
+
q,
|
| 1055 |
+
k,
|
| 1056 |
+
v,
|
| 1057 |
+
out,
|
| 1058 |
+
softmax_lse,
|
| 1059 |
+
dq,
|
| 1060 |
+
dk,
|
| 1061 |
+
dv,
|
| 1062 |
+
cu_seqlens_q,
|
| 1063 |
+
cu_seqlens_k,
|
| 1064 |
+
ctx.max_seqlen_q,
|
| 1065 |
+
ctx.max_seqlen_k,
|
| 1066 |
+
ctx.dropout_p,
|
| 1067 |
+
ctx.softmax_scale,
|
| 1068 |
+
ctx.causal,
|
| 1069 |
+
ctx.window_size[0],
|
| 1070 |
+
ctx.window_size[1],
|
| 1071 |
+
ctx.softcap,
|
| 1072 |
+
ctx.alibi_slopes,
|
| 1073 |
+
ctx.deterministic,
|
| 1074 |
+
rng_state=rng_state,
|
| 1075 |
+
)
|
| 1076 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 1077 |
+
dk = dk[..., : dout.shape[-1]]
|
| 1078 |
+
dv = dv[..., : dout.shape[-1]]
|
| 1079 |
+
return (
|
| 1080 |
+
dq,
|
| 1081 |
+
dk,
|
| 1082 |
+
dv,
|
| 1083 |
+
None,
|
| 1084 |
+
None,
|
| 1085 |
+
None,
|
| 1086 |
+
None,
|
| 1087 |
+
None,
|
| 1088 |
+
None,
|
| 1089 |
+
None,
|
| 1090 |
+
None,
|
| 1091 |
+
None,
|
| 1092 |
+
None,
|
| 1093 |
+
None,
|
| 1094 |
+
None,
|
| 1095 |
+
None,
|
| 1096 |
+
None,
|
| 1097 |
+
)
|
| 1098 |
+
|
| 1099 |
+
|
| 1100 |
+
def flash_attn_qkvpacked_func(
|
| 1101 |
+
qkv,
|
| 1102 |
+
dropout_p=0.0,
|
| 1103 |
+
softmax_scale=None,
|
| 1104 |
+
causal=False,
|
| 1105 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1106 |
+
softcap=0.0, # <=0.0 means deactivate
|
| 1107 |
+
alibi_slopes=None,
|
| 1108 |
+
deterministic=False,
|
| 1109 |
+
return_attn_probs=False,
|
| 1110 |
+
):
|
| 1111 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1112 |
+
If Q, K, V are already stacked into 1 tensor, this function will be faster than
|
| 1113 |
+
calling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1114 |
+
of the gradients of Q, K, V.
|
| 1115 |
+
For multi-query and grouped-query attention (MQA/GQA), please see
|
| 1116 |
+
flash_attn_kvpacked_func and flash_attn_func.
|
| 1117 |
+
|
| 1118 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1119 |
+
will only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.
|
| 1120 |
+
|
| 1121 |
+
Arguments:
|
| 1122 |
+
qkv: (batch_size, seqlen, 3, nheads, headdim)
|
| 1123 |
+
dropout_p: float. Dropout probability.
|
| 1124 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1125 |
+
Default to 1 / sqrt(headdim).
|
| 1126 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1127 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1128 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1129 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|) is added to
|
| 1130 |
+
the attention score of query i and key j.
|
| 1131 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1132 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1133 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1134 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1135 |
+
(they might not have the right scaling).
|
| 1136 |
+
Return:
|
| 1137 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1138 |
+
softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The
|
| 1139 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1140 |
+
normalization factor).
|
| 1141 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1142 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1143 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1144 |
+
"""
|
| 1145 |
+
return FlashAttnQKVPackedFunc.apply(
|
| 1146 |
+
qkv,
|
| 1147 |
+
dropout_p,
|
| 1148 |
+
softmax_scale,
|
| 1149 |
+
causal,
|
| 1150 |
+
window_size,
|
| 1151 |
+
softcap,
|
| 1152 |
+
alibi_slopes,
|
| 1153 |
+
deterministic,
|
| 1154 |
+
return_attn_probs,
|
| 1155 |
+
torch.is_grad_enabled(),
|
| 1156 |
+
)
|
| 1157 |
+
|
| 1158 |
+
|
| 1159 |
+
def flash_attn_kvpacked_func(
|
| 1160 |
+
q,
|
| 1161 |
+
kv,
|
| 1162 |
+
dropout_p=0.0,
|
| 1163 |
+
softmax_scale=None,
|
| 1164 |
+
causal=False,
|
| 1165 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1166 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1167 |
+
alibi_slopes=None,
|
| 1168 |
+
deterministic=False,
|
| 1169 |
+
return_attn_probs=False,
|
| 1170 |
+
):
|
| 1171 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1172 |
+
If K, V are already stacked into 1 tensor, this function will be faster than
|
| 1173 |
+
calling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1174 |
+
of the gradients of K, V.
|
| 1175 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1176 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1177 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1178 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1179 |
+
|
| 1180 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1181 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1182 |
+
1 1 1 1 0
|
| 1183 |
+
1 1 1 1 1
|
| 1184 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1185 |
+
0 0
|
| 1186 |
+
0 0
|
| 1187 |
+
0 0
|
| 1188 |
+
1 0
|
| 1189 |
+
1 1
|
| 1190 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1191 |
+
|
| 1192 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1193 |
+
will only attend to keys between
|
| 1194 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1195 |
+
|
| 1196 |
+
Arguments:
|
| 1197 |
+
q: (batch_size, seqlen, nheads, headdim)
|
| 1198 |
+
kv: (batch_size, seqlen, 2, nheads_k, headdim)
|
| 1199 |
+
dropout_p: float. Dropout probability.
|
| 1200 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1201 |
+
Default to 1 / sqrt(headdim).
|
| 1202 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1203 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1204 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1205 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1206 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1207 |
+
is added to the attention score of query i and key j.
|
| 1208 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1209 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1210 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1211 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1212 |
+
(they might not have the right scaling).
|
| 1213 |
+
Return:
|
| 1214 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1215 |
+
softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The
|
| 1216 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1217 |
+
normalization factor).
|
| 1218 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1219 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1220 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1221 |
+
"""
|
| 1222 |
+
return FlashAttnKVPackedFunc.apply(
|
| 1223 |
+
q,
|
| 1224 |
+
kv,
|
| 1225 |
+
dropout_p,
|
| 1226 |
+
softmax_scale,
|
| 1227 |
+
causal,
|
| 1228 |
+
window_size,
|
| 1229 |
+
softcap,
|
| 1230 |
+
alibi_slopes,
|
| 1231 |
+
deterministic,
|
| 1232 |
+
return_attn_probs,
|
| 1233 |
+
torch.is_grad_enabled(),
|
| 1234 |
+
)
|
| 1235 |
+
|
| 1236 |
+
|
| 1237 |
+
def flash_attn_func(
|
| 1238 |
+
q,
|
| 1239 |
+
k,
|
| 1240 |
+
v,
|
| 1241 |
+
dropout_p=0.0,
|
| 1242 |
+
softmax_scale=None,
|
| 1243 |
+
causal=False,
|
| 1244 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1245 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1246 |
+
alibi_slopes=None,
|
| 1247 |
+
deterministic=False,
|
| 1248 |
+
return_attn_probs=False,
|
| 1249 |
+
):
|
| 1250 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1251 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1252 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1253 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1254 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1255 |
+
|
| 1256 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1257 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1258 |
+
1 1 1 1 0
|
| 1259 |
+
1 1 1 1 1
|
| 1260 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1261 |
+
0 0
|
| 1262 |
+
0 0
|
| 1263 |
+
0 0
|
| 1264 |
+
1 0
|
| 1265 |
+
1 1
|
| 1266 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1267 |
+
|
| 1268 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1269 |
+
will only attend to keys between
|
| 1270 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1271 |
+
|
| 1272 |
+
Arguments:
|
| 1273 |
+
q: (batch_size, seqlen, nheads, headdim)
|
| 1274 |
+
k: (batch_size, seqlen, nheads_k, headdim)
|
| 1275 |
+
v: (batch_size, seqlen, nheads_k, headdim)
|
| 1276 |
+
dropout_p: float. Dropout probability.
|
| 1277 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1278 |
+
Default to 1 / sqrt(headdim).
|
| 1279 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1280 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1281 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1282 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1283 |
+
is added to the attention score of query i and key j.
|
| 1284 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1285 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1286 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1287 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1288 |
+
(they might not have the right scaling).
|
| 1289 |
+
Return:
|
| 1290 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1291 |
+
softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The
|
| 1292 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1293 |
+
normalization factor).
|
| 1294 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1295 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1296 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1297 |
+
"""
|
| 1298 |
+
return FlashAttnFunc.apply(
|
| 1299 |
+
q,
|
| 1300 |
+
k,
|
| 1301 |
+
v,
|
| 1302 |
+
dropout_p,
|
| 1303 |
+
softmax_scale,
|
| 1304 |
+
causal,
|
| 1305 |
+
window_size,
|
| 1306 |
+
softcap,
|
| 1307 |
+
alibi_slopes,
|
| 1308 |
+
deterministic,
|
| 1309 |
+
return_attn_probs,
|
| 1310 |
+
torch.is_grad_enabled(),
|
| 1311 |
+
)
|
| 1312 |
+
|
| 1313 |
+
|
| 1314 |
+
def flash_attn_varlen_qkvpacked_func(
|
| 1315 |
+
qkv,
|
| 1316 |
+
cu_seqlens,
|
| 1317 |
+
max_seqlen,
|
| 1318 |
+
dropout_p=0.0,
|
| 1319 |
+
softmax_scale=None,
|
| 1320 |
+
causal=False,
|
| 1321 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1322 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1323 |
+
alibi_slopes=None,
|
| 1324 |
+
deterministic=False,
|
| 1325 |
+
return_attn_probs=False,
|
| 1326 |
+
):
|
| 1327 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1328 |
+
If Q, K, V are already stacked into 1 tensor, this function will be faster than
|
| 1329 |
+
calling flash_attn_varlen_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1330 |
+
of the gradients of Q, K, V.
|
| 1331 |
+
For multi-query and grouped-query attention (MQA/GQA), please see
|
| 1332 |
+
flash_attn_varlen_kvpacked_func and flash_attn_varlen_func.
|
| 1333 |
+
|
| 1334 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1335 |
+
will only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.
|
| 1336 |
+
|
| 1337 |
+
Arguments:
|
| 1338 |
+
qkv: (total, 3, nheads, headdim), where total = total number of tokens in the batch.
|
| 1339 |
+
cu_seqlens: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1340 |
+
of the sequences in the batch, used to index into qkv.
|
| 1341 |
+
max_seqlen: int. Maximum sequence length in the batch.
|
| 1342 |
+
dropout_p: float. Dropout probability.
|
| 1343 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1344 |
+
Default to 1 / sqrt(headdim).
|
| 1345 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1346 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1347 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1348 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|)
|
| 1349 |
+
is added to the attention score of query i and key j.
|
| 1350 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1351 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1352 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1353 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1354 |
+
(they might not have the right scaling).
|
| 1355 |
+
Return:
|
| 1356 |
+
out: (total, nheads, headdim).
|
| 1357 |
+
softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The
|
| 1358 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1359 |
+
normalization factor).
|
| 1360 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1361 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1362 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1363 |
+
"""
|
| 1364 |
+
return FlashAttnVarlenQKVPackedFunc.apply(
|
| 1365 |
+
qkv,
|
| 1366 |
+
cu_seqlens,
|
| 1367 |
+
max_seqlen,
|
| 1368 |
+
dropout_p,
|
| 1369 |
+
softmax_scale,
|
| 1370 |
+
causal,
|
| 1371 |
+
window_size,
|
| 1372 |
+
softcap,
|
| 1373 |
+
alibi_slopes,
|
| 1374 |
+
deterministic,
|
| 1375 |
+
return_attn_probs,
|
| 1376 |
+
torch.is_grad_enabled(),
|
| 1377 |
+
)
|
| 1378 |
+
|
| 1379 |
+
|
| 1380 |
+
def flash_attn_varlen_kvpacked_func(
|
| 1381 |
+
q,
|
| 1382 |
+
kv,
|
| 1383 |
+
cu_seqlens_q,
|
| 1384 |
+
cu_seqlens_k,
|
| 1385 |
+
max_seqlen_q,
|
| 1386 |
+
max_seqlen_k,
|
| 1387 |
+
dropout_p=0.0,
|
| 1388 |
+
softmax_scale=None,
|
| 1389 |
+
causal=False,
|
| 1390 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1391 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1392 |
+
alibi_slopes=None,
|
| 1393 |
+
deterministic=False,
|
| 1394 |
+
return_attn_probs=False,
|
| 1395 |
+
):
|
| 1396 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1397 |
+
If K, V are already stacked into 1 tensor, this function will be faster than
|
| 1398 |
+
calling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1399 |
+
of the gradients of K, V.
|
| 1400 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1401 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1402 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1403 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1404 |
+
|
| 1405 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1406 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1407 |
+
1 1 1 1 0
|
| 1408 |
+
1 1 1 1 1
|
| 1409 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1410 |
+
0 0
|
| 1411 |
+
0 0
|
| 1412 |
+
0 0
|
| 1413 |
+
1 0
|
| 1414 |
+
1 1
|
| 1415 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1416 |
+
|
| 1417 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1418 |
+
will only attend to keys between
|
| 1419 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1420 |
+
|
| 1421 |
+
Arguments:
|
| 1422 |
+
q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.
|
| 1423 |
+
kv: (total_k, 2, nheads_k, headdim), where total_k = total number of key tokens in the batch.
|
| 1424 |
+
cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1425 |
+
of the sequences in the batch, used to index into q.
|
| 1426 |
+
cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1427 |
+
of the sequences in the batch, used to index into kv.
|
| 1428 |
+
max_seqlen_q: int. Maximum query sequence length in the batch.
|
| 1429 |
+
max_seqlen_k: int. Maximum key sequence length in the batch.
|
| 1430 |
+
dropout_p: float. Dropout probability.
|
| 1431 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1432 |
+
Default to 1 / sqrt(headdim).
|
| 1433 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1434 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1435 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1436 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1437 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1438 |
+
is added to the attention score of query i and key j.
|
| 1439 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1440 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1441 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1442 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1443 |
+
(they might not have the right scaling).
|
| 1444 |
+
Return:
|
| 1445 |
+
out: (total, nheads, headdim).
|
| 1446 |
+
softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The
|
| 1447 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1448 |
+
normalization factor).
|
| 1449 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1450 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1451 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1452 |
+
"""
|
| 1453 |
+
return FlashAttnVarlenKVPackedFunc.apply(
|
| 1454 |
+
q,
|
| 1455 |
+
kv,
|
| 1456 |
+
cu_seqlens_q,
|
| 1457 |
+
cu_seqlens_k,
|
| 1458 |
+
max_seqlen_q,
|
| 1459 |
+
max_seqlen_k,
|
| 1460 |
+
dropout_p,
|
| 1461 |
+
softmax_scale,
|
| 1462 |
+
causal,
|
| 1463 |
+
window_size,
|
| 1464 |
+
softcap,
|
| 1465 |
+
alibi_slopes,
|
| 1466 |
+
deterministic,
|
| 1467 |
+
return_attn_probs,
|
| 1468 |
+
torch.is_grad_enabled(),
|
| 1469 |
+
)
|
| 1470 |
+
|
| 1471 |
+
|
| 1472 |
+
def flash_attn_varlen_func(
|
| 1473 |
+
q,
|
| 1474 |
+
k,
|
| 1475 |
+
v,
|
| 1476 |
+
cu_seqlens_q,
|
| 1477 |
+
cu_seqlens_k,
|
| 1478 |
+
max_seqlen_q,
|
| 1479 |
+
max_seqlen_k,
|
| 1480 |
+
dropout_p=0.0,
|
| 1481 |
+
softmax_scale=None,
|
| 1482 |
+
causal=False,
|
| 1483 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1484 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1485 |
+
alibi_slopes=None,
|
| 1486 |
+
deterministic=False,
|
| 1487 |
+
return_attn_probs=False,
|
| 1488 |
+
block_table=None,
|
| 1489 |
+
):
|
| 1490 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1491 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in K, V with fewer heads
|
| 1492 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1493 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1494 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1495 |
+
|
| 1496 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1497 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1498 |
+
1 1 1 1 0
|
| 1499 |
+
1 1 1 1 1
|
| 1500 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1501 |
+
0 0
|
| 1502 |
+
0 0
|
| 1503 |
+
0 0
|
| 1504 |
+
1 0
|
| 1505 |
+
1 1
|
| 1506 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1507 |
+
|
| 1508 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1509 |
+
will only attend to keys between
|
| 1510 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1511 |
+
|
| 1512 |
+
Arguments:
|
| 1513 |
+
q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.
|
| 1514 |
+
k: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.
|
| 1515 |
+
v: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.
|
| 1516 |
+
cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1517 |
+
of the sequences in the batch, used to index into q.
|
| 1518 |
+
cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1519 |
+
of the sequences in the batch, used to index into kv.
|
| 1520 |
+
max_seqlen_q: int. Maximum query sequence length in the batch.
|
| 1521 |
+
max_seqlen_k: int. Maximum key sequence length in the batch.
|
| 1522 |
+
dropout_p: float. Dropout probability.
|
| 1523 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1524 |
+
Default to 1 / sqrt(headdim).
|
| 1525 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1526 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1527 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1528 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1529 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1530 |
+
is added to the attention score of query i and key j.
|
| 1531 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1532 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1533 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1534 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1535 |
+
(they might not have the right scaling).
|
| 1536 |
+
Return:
|
| 1537 |
+
out: (total, nheads, headdim).
|
| 1538 |
+
softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The
|
| 1539 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1540 |
+
normalization factor).
|
| 1541 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1542 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1543 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1544 |
+
"""
|
| 1545 |
+
return FlashAttnVarlenFunc.apply(
|
| 1546 |
+
q,
|
| 1547 |
+
k,
|
| 1548 |
+
v,
|
| 1549 |
+
cu_seqlens_q,
|
| 1550 |
+
cu_seqlens_k,
|
| 1551 |
+
max_seqlen_q,
|
| 1552 |
+
max_seqlen_k,
|
| 1553 |
+
dropout_p,
|
| 1554 |
+
softmax_scale,
|
| 1555 |
+
causal,
|
| 1556 |
+
window_size,
|
| 1557 |
+
softcap,
|
| 1558 |
+
alibi_slopes,
|
| 1559 |
+
deterministic,
|
| 1560 |
+
return_attn_probs,
|
| 1561 |
+
block_table,
|
| 1562 |
+
False if q.device.type == "cpu" else torch.is_grad_enabled(),
|
| 1563 |
+
)
|
| 1564 |
+
|
| 1565 |
+
|
| 1566 |
+
def flash_attn_with_kvcache(
|
| 1567 |
+
q,
|
| 1568 |
+
k_cache,
|
| 1569 |
+
v_cache,
|
| 1570 |
+
k=None,
|
| 1571 |
+
v=None,
|
| 1572 |
+
rotary_cos=None,
|
| 1573 |
+
rotary_sin=None,
|
| 1574 |
+
cache_seqlens: Optional[Union[(int, torch.Tensor)]] = None,
|
| 1575 |
+
cache_batch_idx: Optional[torch.Tensor] = None,
|
| 1576 |
+
cache_leftpad: Optional[torch.Tensor] = None,
|
| 1577 |
+
block_table: Optional[torch.Tensor] = None,
|
| 1578 |
+
softmax_scale=None,
|
| 1579 |
+
causal=False,
|
| 1580 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1581 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1582 |
+
rotary_interleaved=True,
|
| 1583 |
+
alibi_slopes=None,
|
| 1584 |
+
num_splits=0,
|
| 1585 |
+
return_softmax_lse=False,
|
| 1586 |
+
):
|
| 1587 |
+
"""
|
| 1588 |
+
If k and v are not None, k_cache and v_cache will be updated *inplace* with the new values from
|
| 1589 |
+
k and v. This is useful for incremental decoding: you can pass in the cached keys/values from
|
| 1590 |
+
the previous step, and update them with the new keys/values from the current step, and do
|
| 1591 |
+
attention with the updated cache, all in 1 kernel.
|
| 1592 |
+
|
| 1593 |
+
If you pass in k / v, you must make sure that the cache is large enough to hold the new values.
|
| 1594 |
+
For example, the KV cache could be pre-allocated with the max sequence length, and you can use
|
| 1595 |
+
cache_seqlens to keep track of the current sequence lengths of each sequence in the batch.
|
| 1596 |
+
|
| 1597 |
+
Also apply rotary embedding if rotary_cos and rotary_sin are passed in. The key @k will be
|
| 1598 |
+
rotated by rotary_cos and rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.
|
| 1599 |
+
If causal or local (i.e., window_size != (-1, -1)), the query @q will be rotated by rotary_cos
|
| 1600 |
+
and rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.
|
| 1601 |
+
If not causal and not local, the query @q will be rotated by rotary_cos and rotary_sin at
|
| 1602 |
+
indices cache_seqlens only (i.e. we consider all tokens in @q to be at position cache_seqlens).
|
| 1603 |
+
|
| 1604 |
+
See tests/test_flash_attn.py::test_flash_attn_kvcache for examples of how to use this function.
|
| 1605 |
+
|
| 1606 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1607 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1608 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1609 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1610 |
+
|
| 1611 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1612 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1613 |
+
1 1 1 1 0
|
| 1614 |
+
1 1 1 1 1
|
| 1615 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1616 |
+
0 0
|
| 1617 |
+
0 0
|
| 1618 |
+
0 0
|
| 1619 |
+
1 0
|
| 1620 |
+
1 1
|
| 1621 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1622 |
+
|
| 1623 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1624 |
+
will only attend to keys between
|
| 1625 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1626 |
+
|
| 1627 |
+
Note: Does not support backward pass.
|
| 1628 |
+
|
| 1629 |
+
Arguments:
|
| 1630 |
+
q: (batch_size, seqlen, nheads, headdim)
|
| 1631 |
+
k_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,
|
| 1632 |
+
or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)
|
| 1633 |
+
page_block_size must be a multiple of 256.
|
| 1634 |
+
v_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,
|
| 1635 |
+
or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)
|
| 1636 |
+
k [optional]: (batch_size, seqlen_new, nheads_k, headdim). If not None, we concatenate
|
| 1637 |
+
k with k_cache, starting at the indices specified by cache_seqlens.
|
| 1638 |
+
v [optional]: (batch_size, seqlen_new, nheads_k, headdim). Similar to k.
|
| 1639 |
+
rotary_cos [optional]: (seqlen_ro, rotary_dim / 2). If not None, we apply rotary embedding
|
| 1640 |
+
to k and q. Only applicable if k and v are passed in. rotary_dim must be divisible by 16.
|
| 1641 |
+
rotary_sin [optional]: (seqlen_ro, rotary_dim / 2). Similar to rotary_cos.
|
| 1642 |
+
cache_seqlens: int, or (batch_size,), dtype torch.int32. The sequence lengths of the
|
| 1643 |
+
KV cache.
|
| 1644 |
+
cache_batch_idx: (batch_size,), dtype torch.int32. The indices used to index into the KV cache.
|
| 1645 |
+
If None, we assume that the batch indices are [0, 1, 2, ..., batch_size - 1].
|
| 1646 |
+
If the indices are not distinct, and k and v are provided, the values updated in the cache
|
| 1647 |
+
might come from any of the duplicate indices.
|
| 1648 |
+
cache_leftpad: (batch_size,), dtype torch.int32. The index that the KV cache starts. If None, assume 0.
|
| 1649 |
+
block_table [optional]: (batch_size, max_num_blocks_per_seq), dtype torch.int32.
|
| 1650 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1651 |
+
Default to 1 / sqrt(headdim).
|
| 1652 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1653 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1654 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1655 |
+
rotary_interleaved: bool. Only applicable if rotary_cos and rotary_sin are passed in.
|
| 1656 |
+
If True, rotary embedding will combine dimensions 0 & 1, 2 & 3, etc. If False,
|
| 1657 |
+
rotary embedding will combine dimensions 0 & rotary_dim / 2, 1 & rotary_dim / 2 + 1
|
| 1658 |
+
(i.e. GPT-NeoX style).
|
| 1659 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1660 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1661 |
+
is added to the attention score of query i and key j.
|
| 1662 |
+
num_splits: int. If > 1, split the key/value into this many chunks along the sequence.
|
| 1663 |
+
If num_splits == 1, we don't split the key/value. If num_splits == 0, we use a heuristic
|
| 1664 |
+
to automatically determine the number of splits.
|
| 1665 |
+
Don't change this unless you know what you are doing.
|
| 1666 |
+
return_softmax_lse: bool. Whether to return the logsumexp of the attention scores.
|
| 1667 |
+
|
| 1668 |
+
Return:
|
| 1669 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1670 |
+
softmax_lse [optional, if return_softmax_lse=True]: (batch_size, nheads, seqlen). The
|
| 1671 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1672 |
+
normalization factor).
|
| 1673 |
+
"""
|
| 1674 |
+
assert k_cache.stride(-1) == 1, "k_cache must have contiguous last dimension"
|
| 1675 |
+
assert v_cache.stride(-1) == 1, "v_cache must have contiguous last dimension"
|
| 1676 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 1677 |
+
if softmax_scale is None:
|
| 1678 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 1679 |
+
if cache_seqlens is not None and isinstance(cache_seqlens, int):
|
| 1680 |
+
cache_seqlens = torch.full(
|
| 1681 |
+
(k_cache.shape[0],), cache_seqlens, dtype=torch.int32, device=k_cache.device
|
| 1682 |
+
)
|
| 1683 |
+
cache_seqlens = maybe_contiguous(cache_seqlens)
|
| 1684 |
+
cache_batch_idx = maybe_contiguous(cache_batch_idx)
|
| 1685 |
+
block_table = maybe_contiguous(block_table)
|
| 1686 |
+
out, softmax_lse = flash_attn.fwd_kvcache(
|
| 1687 |
+
q,
|
| 1688 |
+
k_cache,
|
| 1689 |
+
v_cache,
|
| 1690 |
+
k,
|
| 1691 |
+
v,
|
| 1692 |
+
cache_seqlens,
|
| 1693 |
+
rotary_cos,
|
| 1694 |
+
rotary_sin,
|
| 1695 |
+
cache_batch_idx,
|
| 1696 |
+
cache_leftpad,
|
| 1697 |
+
block_table,
|
| 1698 |
+
alibi_slopes,
|
| 1699 |
+
None,
|
| 1700 |
+
softmax_scale,
|
| 1701 |
+
causal,
|
| 1702 |
+
window_size[0],
|
| 1703 |
+
window_size[1],
|
| 1704 |
+
softcap,
|
| 1705 |
+
rotary_interleaved,
|
| 1706 |
+
num_splits,
|
| 1707 |
+
)
|
| 1708 |
+
return (out, softmax_lse) if return_softmax_lse else out
|
build/torch-stable-abi210-cu132-aarch64-linux/metadata.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "flash-attn2",
|
| 3 |
+
"id": "_flash_attn2_cuda_460047c",
|
| 4 |
+
"version": 4,
|
| 5 |
+
"kernels-minver": "0.14.0",
|
| 6 |
+
"license": "BSD-3-Clause",
|
| 7 |
+
"python-depends": [],
|
| 8 |
+
"kernel-depends": [],
|
| 9 |
+
"backend": {
|
| 10 |
+
"type": "cuda",
|
| 11 |
+
"archs": [
|
| 12 |
+
"10.0",
|
| 13 |
+
"12.0",
|
| 14 |
+
"8.0",
|
| 15 |
+
"9.0"
|
| 16 |
+
]
|
| 17 |
+
},
|
| 18 |
+
"digest": {
|
| 19 |
+
"algorithm": "sha256",
|
| 20 |
+
"files": {
|
| 21 |
+
"__init__.py": "Nz8hqrusjoUHQqszpxfF2USMwUXn1VfpvcmtAAvutSM=",
|
| 22 |
+
"_flash_attn2_cuda_460047c.abi3.so": "o4KfnnQPzHLqZ81TNKaReUO+g2+GvWUpV/1i8eOuo7k=",
|
| 23 |
+
"_ops.py": "DV4Eo4+s3aaNmDsfXoZiYKNLnRUJqlsdDGlMsdKFgk4=",
|
| 24 |
+
"flash_attn_interface.py": "6UYUhfUax4+yOUygyS7K8dVjrIjU5GQr1AJ2gSp8rPo=",
|
| 25 |
+
"symbols.json": "uvC+87tHUhtHv7L/Nl53T/Ms7ceX317/jwQBoqHY14A="
|
| 26 |
+
}
|
| 27 |
+
},
|
| 28 |
+
"provenance": {
|
| 29 |
+
"kernel-builder": {
|
| 30 |
+
"version": "0.18.0-dev0",
|
| 31 |
+
"commit": "d054906a13710b811b96697b4635f03020842733",
|
| 32 |
+
"dirty": false
|
| 33 |
+
},
|
| 34 |
+
"kernel": {
|
| 35 |
+
"commit": "460047c291fc7f0b3dbd4239b46bd5e1281b1806",
|
| 36 |
+
"dirty": false
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
}
|
build/torch-stable-abi210-cu132-aarch64-linux/metadata.json.sigstore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"mediaType":"application/vnd.dev.sigstore.bundle.v0.3+json","verificationMaterial":{"certificate":{"rawBytes":"MIIHKzCCBrGgAwIBAgIUN7yA9ogS+KkeDYuoPcAUr6hsD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hazw+FwAABAMARjBEAiBhXXca/RPxAQD6x2U/fkkQs2Qb8xhB3Ocbtk8EAL85GwIgFLfhJk5UBvp5BCpQy306uX7zrE0ceQ6zVJ6sLk64CJ8wCgYIKoZIzj0EAwMDaAAwZQIwSu3h0shlf5zMVbi2esJOvdB3yo1tjfdSU3p0BnUQqTQGDcIbzFRw4daoStzhwG6sAjEAhZifr0fUQ3tKF7NYXYHSqfURaRZef+oxxMOp2on1bYztf6njLa8bQ5ofvAYRRyDu"},"tlogEntries":[{"logIndex":"3430232829","logId":{"keyId":"wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="},"kindVersion":{"kind":"hashedrekord","version":"0.0.1"},"integratedTime":"1792800472","inclusionPromise":{"signedEntryTimestamp":"MEUCIQDapAVpzW9ZMQuTUJ39O7fTsatpIEek0pompEwTH4wvswIgRVThrMi15G2rOZgieSQkQYoUfgxwA9jQoW3N99QqtOU="},"inclusionProof":{"logIndex":"3308328567","rootHash":"8d7Q7d3LmggWU8eU5xZvu5mR+vnArSvWFl8O3w51kQ4=","treeSize":"3308328619","hashes":["ZeSraJnEOIg5RprEttxTPyJoHEIpK2DU9f+GgF7gKUU=","cTgqACgBgsyVC/yK4IGTbMOaCKHRO6569hXM02AYU7Q=","mlwEM8vnsselj+orQh+ahYjAcQRH/p00zGXam6wJfpg=","Ky499GSNP9wO5tKXqV1xgq2eVFaO9tYJrSgCADxcRvY=","C/FFp0p++7+e4msx8G01Pjp5EsyyHe7ThgIj+TssXXQ=","/ubypAm95ilTKdYwhtn6ndwUwRpZ3ICLmEdRdWZB5c8=","gWAOr6FsG8QrENGVRNoJq5UmkHkoGgTYikl74JYz6mg=","eiXoi0AkFmtS6KaPVPsLZdJkcMd6L/c9gNFiiUO7E+g=","K/8DiKTfabbp+AGoyQMoqW/REHMadjMC9YuSpdz5/Cs=","8jJv+xlIJWDTCEJK91Tx1dYXJK/tgcxFsykheeCSw3U=","gdS39fsn5MOVlKluUgGY2sdKF3H5oauxkHMa7DSSNcg=","8x0N/oAmvpY+6DQUGTU+i6a1Cuqphro2WbV5WZ/RHL8=","DMchGrSAeKV9qHo75XJV3UFZ/CHF8zofPRu+NgVRwA4=","V6dXjeDcwYxBG/9gVSBM8rYdPrAqGpZsf1e7v6l67GA=","iDfImp65w8dirRfYGNgFA34JTUYDWbcJwNBBU/Ok+X4=","YYCr61A8azar3dfO8Ct+pri7LqDxkUlUkfs7fiqYErU=","1DaDKzrCNNBhmSdY5vFjz+NpAmxmYfYEgBCdPLrMP1A=","xH/DCseLHr9eKoYT8qsORZK7zVdEGYWHuVtsVrD95wY="],"checkpoint":{"envelope":"rekor.sigstore.dev - 1193050959916656506\n3308328619\n8d7Q7d3LmggWU8eU5xZvu5mR+vnArSvWFl8O3w51kQ4=\n\n— rekor.sigstore.dev wNI9ajBFAiEAl3psN46GEcjBpud4+y/WZ4F3HtMSO1IV8ZardGaTWcACIEjD4ZIUStqCf5b+jEh+/EbgTp70rKCnzpq9mNBPkHLQ\n"}},"canonicalizedBody":"eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoiaGFzaGVkcmVrb3JkIiwic3BlYyI6eyJkYXRhIjp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiIyNWMyZDk2MDQwNzkxYTJhNmMxZjE4ZDg0MjkwNDQxOTJlY2JjZTMzZTNiMjg4YjM1MDUyYWYxNDRjNGVlM2QzIn19LCJzaWduYXR1cmUiOnsiY29udGVudCI6Ik1FVUNJRkJXa2hMNDl4V09YY3Vwdmh3VlBFZk14RWxPR0tvVmp1azlxZjF6OW1GMUFpRUF5Q0VaLzVTNmhENGNEajcwOUszUXl3elRmSUo1UkF6S1MrbjFNZ3RLTGtvPSIsInB1YmxpY0tleSI6eyJjb250ZW50IjoiTFMwdExTMUNSVWRKVGlCRFJWSlVTVVpKUTBGVVJTMHRMUzB0Q2sxSlNVaExla05EUW5KSFowRjNTVUpCWjBsVlRqZDVRVGx2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S6v8KAhsXgaLHLxLtLXkMEuVxlrkSey5PYJmitundFbhChOAUAn5UQIvVczNzLLzW54p+k/liiht08kDHlfLylc4CehlBIyOx4XANNwmxu4LW0fhJxYKjNI="}]}},"messageSignature":{"messageDigest":{"algorithm":"SHA2_256","digest":"JcLZYEB5GipsHxjYQpBEGS7LzjPjsoizUFKvFExO49M="},"signature":"MEUCIFBWkhL49xWOXcupvhwVPEfMxElOGKoVjuk9qf1z9mF1AiEAyCEZ/5S6hD4cDj709K3QywzTfIJ5RAzKS+n1MgtKLko="}}
|
build/torch-stable-abi210-cu132-aarch64-linux/symbols.json
ADDED
|
@@ -0,0 +1,1273 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema_version": 1,
|
| 3 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 4 |
+
"functions": [
|
| 5 |
+
{
|
| 6 |
+
"name": "flash_attn_func",
|
| 7 |
+
"qualname": "flash_attn_func",
|
| 8 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 9 |
+
"kind": "function",
|
| 10 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (batch_size, seqlen, nheads, headdim)\n k: (batch_size, seqlen, nheads_k, headdim)\n v: (batch_size, seqlen, nheads_k, headdim)\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 11 |
+
"signature": {
|
| 12 |
+
"parameters": [
|
| 13 |
+
{
|
| 14 |
+
"name": "q",
|
| 15 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 16 |
+
"default": null,
|
| 17 |
+
"annotation": null
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"name": "k",
|
| 21 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 22 |
+
"default": null,
|
| 23 |
+
"annotation": null
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"name": "v",
|
| 27 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 28 |
+
"default": null,
|
| 29 |
+
"annotation": null
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"name": "dropout_p",
|
| 33 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 34 |
+
"default": "0.0",
|
| 35 |
+
"annotation": null
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"name": "softmax_scale",
|
| 39 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 40 |
+
"default": "None",
|
| 41 |
+
"annotation": null
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"name": "causal",
|
| 45 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 46 |
+
"default": "False",
|
| 47 |
+
"annotation": null
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"name": "window_size",
|
| 51 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 52 |
+
"default": "(-1, -1)",
|
| 53 |
+
"annotation": null
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"name": "softcap",
|
| 57 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 58 |
+
"default": "0.0",
|
| 59 |
+
"annotation": null
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"name": "alibi_slopes",
|
| 63 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 64 |
+
"default": "None",
|
| 65 |
+
"annotation": null
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"name": "deterministic",
|
| 69 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 70 |
+
"default": "False",
|
| 71 |
+
"annotation": null
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"name": "return_attn_probs",
|
| 75 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 76 |
+
"default": "False",
|
| 77 |
+
"annotation": null
|
| 78 |
+
}
|
| 79 |
+
],
|
| 80 |
+
"return_annotation": null
|
| 81 |
+
}
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
"name": "flash_attn_kvpacked_func",
|
| 85 |
+
"qualname": "flash_attn_kvpacked_func",
|
| 86 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 87 |
+
"kind": "function",
|
| 88 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of K, V.\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (batch_size, seqlen, nheads, headdim)\n kv: (batch_size, seqlen, 2, nheads_k, headdim)\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 89 |
+
"signature": {
|
| 90 |
+
"parameters": [
|
| 91 |
+
{
|
| 92 |
+
"name": "q",
|
| 93 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 94 |
+
"default": null,
|
| 95 |
+
"annotation": null
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"name": "kv",
|
| 99 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 100 |
+
"default": null,
|
| 101 |
+
"annotation": null
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"name": "dropout_p",
|
| 105 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 106 |
+
"default": "0.0",
|
| 107 |
+
"annotation": null
|
| 108 |
+
},
|
| 109 |
+
{
|
| 110 |
+
"name": "softmax_scale",
|
| 111 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 112 |
+
"default": "None",
|
| 113 |
+
"annotation": null
|
| 114 |
+
},
|
| 115 |
+
{
|
| 116 |
+
"name": "causal",
|
| 117 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 118 |
+
"default": "False",
|
| 119 |
+
"annotation": null
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"name": "window_size",
|
| 123 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 124 |
+
"default": "(-1, -1)",
|
| 125 |
+
"annotation": null
|
| 126 |
+
},
|
| 127 |
+
{
|
| 128 |
+
"name": "softcap",
|
| 129 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 130 |
+
"default": "0.0",
|
| 131 |
+
"annotation": null
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
"name": "alibi_slopes",
|
| 135 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 136 |
+
"default": "None",
|
| 137 |
+
"annotation": null
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"name": "deterministic",
|
| 141 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 142 |
+
"default": "False",
|
| 143 |
+
"annotation": null
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"name": "return_attn_probs",
|
| 147 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 148 |
+
"default": "False",
|
| 149 |
+
"annotation": null
|
| 150 |
+
}
|
| 151 |
+
],
|
| 152 |
+
"return_annotation": null
|
| 153 |
+
}
|
| 154 |
+
},
|
| 155 |
+
{
|
| 156 |
+
"name": "flash_attn_qkvpacked_func",
|
| 157 |
+
"qualname": "flash_attn_qkvpacked_func",
|
| 158 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 159 |
+
"kind": "function",
|
| 160 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf Q, K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of Q, K, V.\nFor multi-query and grouped-query attention (MQA/GQA), please see\nflash_attn_kvpacked_func and flash_attn_func.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.\n\nArguments:\n qkv: (batch_size, seqlen, 3, nheads, headdim)\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|) is added to\n the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 161 |
+
"signature": {
|
| 162 |
+
"parameters": [
|
| 163 |
+
{
|
| 164 |
+
"name": "qkv",
|
| 165 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 166 |
+
"default": null,
|
| 167 |
+
"annotation": null
|
| 168 |
+
},
|
| 169 |
+
{
|
| 170 |
+
"name": "dropout_p",
|
| 171 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 172 |
+
"default": "0.0",
|
| 173 |
+
"annotation": null
|
| 174 |
+
},
|
| 175 |
+
{
|
| 176 |
+
"name": "softmax_scale",
|
| 177 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 178 |
+
"default": "None",
|
| 179 |
+
"annotation": null
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
"name": "causal",
|
| 183 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 184 |
+
"default": "False",
|
| 185 |
+
"annotation": null
|
| 186 |
+
},
|
| 187 |
+
{
|
| 188 |
+
"name": "window_size",
|
| 189 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 190 |
+
"default": "(-1, -1)",
|
| 191 |
+
"annotation": null
|
| 192 |
+
},
|
| 193 |
+
{
|
| 194 |
+
"name": "softcap",
|
| 195 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 196 |
+
"default": "0.0",
|
| 197 |
+
"annotation": null
|
| 198 |
+
},
|
| 199 |
+
{
|
| 200 |
+
"name": "alibi_slopes",
|
| 201 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 202 |
+
"default": "None",
|
| 203 |
+
"annotation": null
|
| 204 |
+
},
|
| 205 |
+
{
|
| 206 |
+
"name": "deterministic",
|
| 207 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 208 |
+
"default": "False",
|
| 209 |
+
"annotation": null
|
| 210 |
+
},
|
| 211 |
+
{
|
| 212 |
+
"name": "return_attn_probs",
|
| 213 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 214 |
+
"default": "False",
|
| 215 |
+
"annotation": null
|
| 216 |
+
}
|
| 217 |
+
],
|
| 218 |
+
"return_annotation": null
|
| 219 |
+
}
|
| 220 |
+
},
|
| 221 |
+
{
|
| 222 |
+
"name": "flash_attn_varlen_func",
|
| 223 |
+
"qualname": "flash_attn_varlen_func",
|
| 224 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 225 |
+
"kind": "function",
|
| 226 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in K, V with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.\n k: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.\n v: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.\n cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into q.\n cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into kv.\n max_seqlen_q: int. Maximum query sequence length in the batch.\n max_seqlen_k: int. Maximum key sequence length in the batch.\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (total, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 227 |
+
"signature": {
|
| 228 |
+
"parameters": [
|
| 229 |
+
{
|
| 230 |
+
"name": "q",
|
| 231 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 232 |
+
"default": null,
|
| 233 |
+
"annotation": null
|
| 234 |
+
},
|
| 235 |
+
{
|
| 236 |
+
"name": "k",
|
| 237 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 238 |
+
"default": null,
|
| 239 |
+
"annotation": null
|
| 240 |
+
},
|
| 241 |
+
{
|
| 242 |
+
"name": "v",
|
| 243 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 244 |
+
"default": null,
|
| 245 |
+
"annotation": null
|
| 246 |
+
},
|
| 247 |
+
{
|
| 248 |
+
"name": "cu_seqlens_q",
|
| 249 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 250 |
+
"default": null,
|
| 251 |
+
"annotation": null
|
| 252 |
+
},
|
| 253 |
+
{
|
| 254 |
+
"name": "cu_seqlens_k",
|
| 255 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 256 |
+
"default": null,
|
| 257 |
+
"annotation": null
|
| 258 |
+
},
|
| 259 |
+
{
|
| 260 |
+
"name": "max_seqlen_q",
|
| 261 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 262 |
+
"default": null,
|
| 263 |
+
"annotation": null
|
| 264 |
+
},
|
| 265 |
+
{
|
| 266 |
+
"name": "max_seqlen_k",
|
| 267 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 268 |
+
"default": null,
|
| 269 |
+
"annotation": null
|
| 270 |
+
},
|
| 271 |
+
{
|
| 272 |
+
"name": "dropout_p",
|
| 273 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 274 |
+
"default": "0.0",
|
| 275 |
+
"annotation": null
|
| 276 |
+
},
|
| 277 |
+
{
|
| 278 |
+
"name": "softmax_scale",
|
| 279 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 280 |
+
"default": "None",
|
| 281 |
+
"annotation": null
|
| 282 |
+
},
|
| 283 |
+
{
|
| 284 |
+
"name": "causal",
|
| 285 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 286 |
+
"default": "False",
|
| 287 |
+
"annotation": null
|
| 288 |
+
},
|
| 289 |
+
{
|
| 290 |
+
"name": "window_size",
|
| 291 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 292 |
+
"default": "(-1, -1)",
|
| 293 |
+
"annotation": null
|
| 294 |
+
},
|
| 295 |
+
{
|
| 296 |
+
"name": "softcap",
|
| 297 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 298 |
+
"default": "0.0",
|
| 299 |
+
"annotation": null
|
| 300 |
+
},
|
| 301 |
+
{
|
| 302 |
+
"name": "alibi_slopes",
|
| 303 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 304 |
+
"default": "None",
|
| 305 |
+
"annotation": null
|
| 306 |
+
},
|
| 307 |
+
{
|
| 308 |
+
"name": "deterministic",
|
| 309 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 310 |
+
"default": "False",
|
| 311 |
+
"annotation": null
|
| 312 |
+
},
|
| 313 |
+
{
|
| 314 |
+
"name": "return_attn_probs",
|
| 315 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 316 |
+
"default": "False",
|
| 317 |
+
"annotation": null
|
| 318 |
+
},
|
| 319 |
+
{
|
| 320 |
+
"name": "block_table",
|
| 321 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 322 |
+
"default": "None",
|
| 323 |
+
"annotation": null
|
| 324 |
+
}
|
| 325 |
+
],
|
| 326 |
+
"return_annotation": null
|
| 327 |
+
}
|
| 328 |
+
},
|
| 329 |
+
{
|
| 330 |
+
"name": "flash_attn_varlen_kvpacked_func",
|
| 331 |
+
"qualname": "flash_attn_varlen_kvpacked_func",
|
| 332 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 333 |
+
"kind": "function",
|
| 334 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of K, V.\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.\n kv: (total_k, 2, nheads_k, headdim), where total_k = total number of key tokens in the batch.\n cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into q.\n cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into kv.\n max_seqlen_q: int. Maximum query sequence length in the batch.\n max_seqlen_k: int. Maximum key sequence length in the batch.\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (total, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 335 |
+
"signature": {
|
| 336 |
+
"parameters": [
|
| 337 |
+
{
|
| 338 |
+
"name": "q",
|
| 339 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 340 |
+
"default": null,
|
| 341 |
+
"annotation": null
|
| 342 |
+
},
|
| 343 |
+
{
|
| 344 |
+
"name": "kv",
|
| 345 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 346 |
+
"default": null,
|
| 347 |
+
"annotation": null
|
| 348 |
+
},
|
| 349 |
+
{
|
| 350 |
+
"name": "cu_seqlens_q",
|
| 351 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 352 |
+
"default": null,
|
| 353 |
+
"annotation": null
|
| 354 |
+
},
|
| 355 |
+
{
|
| 356 |
+
"name": "cu_seqlens_k",
|
| 357 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 358 |
+
"default": null,
|
| 359 |
+
"annotation": null
|
| 360 |
+
},
|
| 361 |
+
{
|
| 362 |
+
"name": "max_seqlen_q",
|
| 363 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 364 |
+
"default": null,
|
| 365 |
+
"annotation": null
|
| 366 |
+
},
|
| 367 |
+
{
|
| 368 |
+
"name": "max_seqlen_k",
|
| 369 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 370 |
+
"default": null,
|
| 371 |
+
"annotation": null
|
| 372 |
+
},
|
| 373 |
+
{
|
| 374 |
+
"name": "dropout_p",
|
| 375 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 376 |
+
"default": "0.0",
|
| 377 |
+
"annotation": null
|
| 378 |
+
},
|
| 379 |
+
{
|
| 380 |
+
"name": "softmax_scale",
|
| 381 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 382 |
+
"default": "None",
|
| 383 |
+
"annotation": null
|
| 384 |
+
},
|
| 385 |
+
{
|
| 386 |
+
"name": "causal",
|
| 387 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 388 |
+
"default": "False",
|
| 389 |
+
"annotation": null
|
| 390 |
+
},
|
| 391 |
+
{
|
| 392 |
+
"name": "window_size",
|
| 393 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 394 |
+
"default": "(-1, -1)",
|
| 395 |
+
"annotation": null
|
| 396 |
+
},
|
| 397 |
+
{
|
| 398 |
+
"name": "softcap",
|
| 399 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 400 |
+
"default": "0.0",
|
| 401 |
+
"annotation": null
|
| 402 |
+
},
|
| 403 |
+
{
|
| 404 |
+
"name": "alibi_slopes",
|
| 405 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 406 |
+
"default": "None",
|
| 407 |
+
"annotation": null
|
| 408 |
+
},
|
| 409 |
+
{
|
| 410 |
+
"name": "deterministic",
|
| 411 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 412 |
+
"default": "False",
|
| 413 |
+
"annotation": null
|
| 414 |
+
},
|
| 415 |
+
{
|
| 416 |
+
"name": "return_attn_probs",
|
| 417 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 418 |
+
"default": "False",
|
| 419 |
+
"annotation": null
|
| 420 |
+
}
|
| 421 |
+
],
|
| 422 |
+
"return_annotation": null
|
| 423 |
+
}
|
| 424 |
+
},
|
| 425 |
+
{
|
| 426 |
+
"name": "flash_attn_varlen_qkvpacked_func",
|
| 427 |
+
"qualname": "flash_attn_varlen_qkvpacked_func",
|
| 428 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 429 |
+
"kind": "function",
|
| 430 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf Q, K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_varlen_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of Q, K, V.\nFor multi-query and grouped-query attention (MQA/GQA), please see\nflash_attn_varlen_kvpacked_func and flash_attn_varlen_func.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.\n\nArguments:\n qkv: (total, 3, nheads, headdim), where total = total number of tokens in the batch.\n cu_seqlens: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into qkv.\n max_seqlen: int. Maximum sequence length in the batch.\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (total, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 431 |
+
"signature": {
|
| 432 |
+
"parameters": [
|
| 433 |
+
{
|
| 434 |
+
"name": "qkv",
|
| 435 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 436 |
+
"default": null,
|
| 437 |
+
"annotation": null
|
| 438 |
+
},
|
| 439 |
+
{
|
| 440 |
+
"name": "cu_seqlens",
|
| 441 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 442 |
+
"default": null,
|
| 443 |
+
"annotation": null
|
| 444 |
+
},
|
| 445 |
+
{
|
| 446 |
+
"name": "max_seqlen",
|
| 447 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 448 |
+
"default": null,
|
| 449 |
+
"annotation": null
|
| 450 |
+
},
|
| 451 |
+
{
|
| 452 |
+
"name": "dropout_p",
|
| 453 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 454 |
+
"default": "0.0",
|
| 455 |
+
"annotation": null
|
| 456 |
+
},
|
| 457 |
+
{
|
| 458 |
+
"name": "softmax_scale",
|
| 459 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 460 |
+
"default": "None",
|
| 461 |
+
"annotation": null
|
| 462 |
+
},
|
| 463 |
+
{
|
| 464 |
+
"name": "causal",
|
| 465 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 466 |
+
"default": "False",
|
| 467 |
+
"annotation": null
|
| 468 |
+
},
|
| 469 |
+
{
|
| 470 |
+
"name": "window_size",
|
| 471 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 472 |
+
"default": "(-1, -1)",
|
| 473 |
+
"annotation": null
|
| 474 |
+
},
|
| 475 |
+
{
|
| 476 |
+
"name": "softcap",
|
| 477 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 478 |
+
"default": "0.0",
|
| 479 |
+
"annotation": null
|
| 480 |
+
},
|
| 481 |
+
{
|
| 482 |
+
"name": "alibi_slopes",
|
| 483 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 484 |
+
"default": "None",
|
| 485 |
+
"annotation": null
|
| 486 |
+
},
|
| 487 |
+
{
|
| 488 |
+
"name": "deterministic",
|
| 489 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 490 |
+
"default": "False",
|
| 491 |
+
"annotation": null
|
| 492 |
+
},
|
| 493 |
+
{
|
| 494 |
+
"name": "return_attn_probs",
|
| 495 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 496 |
+
"default": "False",
|
| 497 |
+
"annotation": null
|
| 498 |
+
}
|
| 499 |
+
],
|
| 500 |
+
"return_annotation": null
|
| 501 |
+
}
|
| 502 |
+
},
|
| 503 |
+
{
|
| 504 |
+
"name": "flash_attn_with_kvcache",
|
| 505 |
+
"qualname": "flash_attn_with_kvcache",
|
| 506 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 507 |
+
"kind": "function",
|
| 508 |
+
"doc": "If k and v are not None, k_cache and v_cache will be updated *inplace* with the new values from\nk and v. This is useful for incremental decoding: you can pass in the cached keys/values from\nthe previous step, and update them with the new keys/values from the current step, and do\nattention with the updated cache, all in 1 kernel.\n\nIf you pass in k / v, you must make sure that the cache is large enough to hold the new values.\nFor example, the KV cache could be pre-allocated with the max sequence length, and you can use\ncache_seqlens to keep track of the current sequence lengths of each sequence in the batch.\n\nAlso apply rotary embedding if rotary_cos and rotary_sin are passed in. The key @k will be\nrotated by rotary_cos and rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.\nIf causal or local (i.e., window_size != (-1, -1)), the query @q will be rotated by rotary_cos\nand rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.\nIf not causal and not local, the query @q will be rotated by rotary_cos and rotary_sin at\nindices cache_seqlens only (i.e. we consider all tokens in @q to be at position cache_seqlens).\n\nSee tests/test_flash_attn.py::test_flash_attn_kvcache for examples of how to use this function.\n\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nNote: Does not support backward pass.\n\nArguments:\n q: (batch_size, seqlen, nheads, headdim)\n k_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,\n or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)\n page_block_size must be a multiple of 256.\n v_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,\n or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)\n k [optional]: (batch_size, seqlen_new, nheads_k, headdim). If not None, we concatenate\n k with k_cache, starting at the indices specified by cache_seqlens.\n v [optional]: (batch_size, seqlen_new, nheads_k, headdim). Similar to k.\n rotary_cos [optional]: (seqlen_ro, rotary_dim / 2). If not None, we apply rotary embedding\n to k and q. Only applicable if k and v are passed in. rotary_dim must be divisible by 16.\n rotary_sin [optional]: (seqlen_ro, rotary_dim / 2). Similar to rotary_cos.\n cache_seqlens: int, or (batch_size,), dtype torch.int32. The sequence lengths of the\n KV cache.\n cache_batch_idx: (batch_size,), dtype torch.int32. The indices used to index into the KV cache.\n If None, we assume that the batch indices are [0, 1, 2, ..., batch_size - 1].\n If the indices are not distinct, and k and v are provided, the values updated in the cache\n might come from any of the duplicate indices.\n cache_leftpad: (batch_size,), dtype torch.int32. The index that the KV cache starts. If None, assume 0.\n block_table [optional]: (batch_size, max_num_blocks_per_seq), dtype torch.int32.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n rotary_interleaved: bool. Only applicable if rotary_cos and rotary_sin are passed in.\n If True, rotary embedding will combine dimensions 0 & 1, 2 & 3, etc. If False,\n rotary embedding will combine dimensions 0 & rotary_dim / 2, 1 & rotary_dim / 2 + 1\n (i.e. GPT-NeoX style).\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n num_splits: int. If > 1, split the key/value into this many chunks along the sequence.\n If num_splits == 1, we don't split the key/value. If num_splits == 0, we use a heuristic\n to automatically determine the number of splits.\n Don't change this unless you know what you are doing.\n return_softmax_lse: bool. Whether to return the logsumexp of the attention scores.\n\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_softmax_lse=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).",
|
| 509 |
+
"signature": {
|
| 510 |
+
"parameters": [
|
| 511 |
+
{
|
| 512 |
+
"name": "q",
|
| 513 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 514 |
+
"default": null,
|
| 515 |
+
"annotation": null
|
| 516 |
+
},
|
| 517 |
+
{
|
| 518 |
+
"name": "k_cache",
|
| 519 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 520 |
+
"default": null,
|
| 521 |
+
"annotation": null
|
| 522 |
+
},
|
| 523 |
+
{
|
| 524 |
+
"name": "v_cache",
|
| 525 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 526 |
+
"default": null,
|
| 527 |
+
"annotation": null
|
| 528 |
+
},
|
| 529 |
+
{
|
| 530 |
+
"name": "k",
|
| 531 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 532 |
+
"default": "None",
|
| 533 |
+
"annotation": null
|
| 534 |
+
},
|
| 535 |
+
{
|
| 536 |
+
"name": "v",
|
| 537 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 538 |
+
"default": "None",
|
| 539 |
+
"annotation": null
|
| 540 |
+
},
|
| 541 |
+
{
|
| 542 |
+
"name": "rotary_cos",
|
| 543 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 544 |
+
"default": "None",
|
| 545 |
+
"annotation": null
|
| 546 |
+
},
|
| 547 |
+
{
|
| 548 |
+
"name": "rotary_sin",
|
| 549 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 550 |
+
"default": "None",
|
| 551 |
+
"annotation": null
|
| 552 |
+
},
|
| 553 |
+
{
|
| 554 |
+
"name": "cache_seqlens",
|
| 555 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 556 |
+
"default": "None",
|
| 557 |
+
"annotation": "int | torch.Tensor | None"
|
| 558 |
+
},
|
| 559 |
+
{
|
| 560 |
+
"name": "cache_batch_idx",
|
| 561 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 562 |
+
"default": "None",
|
| 563 |
+
"annotation": "torch.Tensor | None"
|
| 564 |
+
},
|
| 565 |
+
{
|
| 566 |
+
"name": "cache_leftpad",
|
| 567 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 568 |
+
"default": "None",
|
| 569 |
+
"annotation": "torch.Tensor | None"
|
| 570 |
+
},
|
| 571 |
+
{
|
| 572 |
+
"name": "block_table",
|
| 573 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 574 |
+
"default": "None",
|
| 575 |
+
"annotation": "torch.Tensor | None"
|
| 576 |
+
},
|
| 577 |
+
{
|
| 578 |
+
"name": "softmax_scale",
|
| 579 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 580 |
+
"default": "None",
|
| 581 |
+
"annotation": null
|
| 582 |
+
},
|
| 583 |
+
{
|
| 584 |
+
"name": "causal",
|
| 585 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 586 |
+
"default": "False",
|
| 587 |
+
"annotation": null
|
| 588 |
+
},
|
| 589 |
+
{
|
| 590 |
+
"name": "window_size",
|
| 591 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 592 |
+
"default": "(-1, -1)",
|
| 593 |
+
"annotation": null
|
| 594 |
+
},
|
| 595 |
+
{
|
| 596 |
+
"name": "softcap",
|
| 597 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 598 |
+
"default": "0.0",
|
| 599 |
+
"annotation": null
|
| 600 |
+
},
|
| 601 |
+
{
|
| 602 |
+
"name": "rotary_interleaved",
|
| 603 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 604 |
+
"default": "True",
|
| 605 |
+
"annotation": null
|
| 606 |
+
},
|
| 607 |
+
{
|
| 608 |
+
"name": "alibi_slopes",
|
| 609 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 610 |
+
"default": "None",
|
| 611 |
+
"annotation": null
|
| 612 |
+
},
|
| 613 |
+
{
|
| 614 |
+
"name": "num_splits",
|
| 615 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 616 |
+
"default": "0",
|
| 617 |
+
"annotation": null
|
| 618 |
+
},
|
| 619 |
+
{
|
| 620 |
+
"name": "return_softmax_lse",
|
| 621 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 622 |
+
"default": "False",
|
| 623 |
+
"annotation": null
|
| 624 |
+
}
|
| 625 |
+
],
|
| 626 |
+
"return_annotation": null
|
| 627 |
+
}
|
| 628 |
+
},
|
| 629 |
+
{
|
| 630 |
+
"name": "fwd",
|
| 631 |
+
"qualname": "fwd",
|
| 632 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 633 |
+
"kind": "function",
|
| 634 |
+
"doc": "Forward pass for multi-head attention.\n\nArgs:\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n out: Optional output tensor, same shape as q\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n return_softmax: Whether to return softmax weights\n gen: Optional random number generator\n\nReturns:\n List of tensors: [output, softmax_lse, (softmax if return_softmax)]",
|
| 635 |
+
"signature": {
|
| 636 |
+
"parameters": [
|
| 637 |
+
{
|
| 638 |
+
"name": "q",
|
| 639 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 640 |
+
"default": null,
|
| 641 |
+
"annotation": "torch.Tensor"
|
| 642 |
+
},
|
| 643 |
+
{
|
| 644 |
+
"name": "k",
|
| 645 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 646 |
+
"default": null,
|
| 647 |
+
"annotation": "torch.Tensor"
|
| 648 |
+
},
|
| 649 |
+
{
|
| 650 |
+
"name": "v",
|
| 651 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 652 |
+
"default": null,
|
| 653 |
+
"annotation": "torch.Tensor"
|
| 654 |
+
},
|
| 655 |
+
{
|
| 656 |
+
"name": "out",
|
| 657 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 658 |
+
"default": "None",
|
| 659 |
+
"annotation": "torch.Tensor | None"
|
| 660 |
+
},
|
| 661 |
+
{
|
| 662 |
+
"name": "alibi_slopes",
|
| 663 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 664 |
+
"default": "None",
|
| 665 |
+
"annotation": "torch.Tensor | None"
|
| 666 |
+
},
|
| 667 |
+
{
|
| 668 |
+
"name": "p_dropout",
|
| 669 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 670 |
+
"default": "0.0",
|
| 671 |
+
"annotation": "float"
|
| 672 |
+
},
|
| 673 |
+
{
|
| 674 |
+
"name": "softmax_scale",
|
| 675 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 676 |
+
"default": "None",
|
| 677 |
+
"annotation": "float | None"
|
| 678 |
+
},
|
| 679 |
+
{
|
| 680 |
+
"name": "is_causal",
|
| 681 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 682 |
+
"default": "False",
|
| 683 |
+
"annotation": "bool"
|
| 684 |
+
},
|
| 685 |
+
{
|
| 686 |
+
"name": "window_size_left",
|
| 687 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 688 |
+
"default": "-1",
|
| 689 |
+
"annotation": "int"
|
| 690 |
+
},
|
| 691 |
+
{
|
| 692 |
+
"name": "window_size_right",
|
| 693 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 694 |
+
"default": "-1",
|
| 695 |
+
"annotation": "int"
|
| 696 |
+
},
|
| 697 |
+
{
|
| 698 |
+
"name": "softcap",
|
| 699 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 700 |
+
"default": "0.0",
|
| 701 |
+
"annotation": "float"
|
| 702 |
+
},
|
| 703 |
+
{
|
| 704 |
+
"name": "return_softmax",
|
| 705 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 706 |
+
"default": "False",
|
| 707 |
+
"annotation": "bool"
|
| 708 |
+
},
|
| 709 |
+
{
|
| 710 |
+
"name": "gen",
|
| 711 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 712 |
+
"default": "None",
|
| 713 |
+
"annotation": "torch._C.Generator | None"
|
| 714 |
+
}
|
| 715 |
+
],
|
| 716 |
+
"return_annotation": "List[torch.Tensor]"
|
| 717 |
+
}
|
| 718 |
+
},
|
| 719 |
+
{
|
| 720 |
+
"name": "varlen_fwd",
|
| 721 |
+
"qualname": "varlen_fwd",
|
| 722 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 723 |
+
"kind": "function",
|
| 724 |
+
"doc": "Forward pass for multi-head attention with variable sequence lengths.\n\nArgs:\n q: Query tensor of shape [total_q, num_heads, head_size]\n k: Key tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n v: Value tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]\n cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]\n out: Optional output tensor of shape [total_q, num_heads, head_size]\n seqused_k: Optional tensor specifying how many keys to use per batch element [batch_size]\n leftpad_k: Optional left padding for keys of shape [batch_size]\n block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n max_seqlen_q: Maximum sequence length for queries\n max_seqlen_k: Maximum sequence length for keys\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n zero_tensors: Whether to zero tensors before computation\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n return_softmax: Whether to return softmax weights\n gen: Optional random number generator\n\nReturns:\n List of tensors: [output, softmax_lse, (softmax if return_softmax)]",
|
| 725 |
+
"signature": {
|
| 726 |
+
"parameters": [
|
| 727 |
+
{
|
| 728 |
+
"name": "q",
|
| 729 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 730 |
+
"default": null,
|
| 731 |
+
"annotation": "torch.Tensor"
|
| 732 |
+
},
|
| 733 |
+
{
|
| 734 |
+
"name": "k",
|
| 735 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 736 |
+
"default": null,
|
| 737 |
+
"annotation": "torch.Tensor"
|
| 738 |
+
},
|
| 739 |
+
{
|
| 740 |
+
"name": "v",
|
| 741 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 742 |
+
"default": null,
|
| 743 |
+
"annotation": "torch.Tensor"
|
| 744 |
+
},
|
| 745 |
+
{
|
| 746 |
+
"name": "cu_seqlens_q",
|
| 747 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 748 |
+
"default": null,
|
| 749 |
+
"annotation": "torch.Tensor"
|
| 750 |
+
},
|
| 751 |
+
{
|
| 752 |
+
"name": "cu_seqlens_k",
|
| 753 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 754 |
+
"default": null,
|
| 755 |
+
"annotation": "torch.Tensor"
|
| 756 |
+
},
|
| 757 |
+
{
|
| 758 |
+
"name": "out",
|
| 759 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 760 |
+
"default": "None",
|
| 761 |
+
"annotation": "torch.Tensor | None"
|
| 762 |
+
},
|
| 763 |
+
{
|
| 764 |
+
"name": "seqused_k",
|
| 765 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 766 |
+
"default": "None",
|
| 767 |
+
"annotation": "torch.Tensor | None"
|
| 768 |
+
},
|
| 769 |
+
{
|
| 770 |
+
"name": "leftpad_k",
|
| 771 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 772 |
+
"default": "None",
|
| 773 |
+
"annotation": "torch.Tensor | None"
|
| 774 |
+
},
|
| 775 |
+
{
|
| 776 |
+
"name": "block_table",
|
| 777 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 778 |
+
"default": "None",
|
| 779 |
+
"annotation": "torch.Tensor | None"
|
| 780 |
+
},
|
| 781 |
+
{
|
| 782 |
+
"name": "alibi_slopes",
|
| 783 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 784 |
+
"default": "None",
|
| 785 |
+
"annotation": "torch.Tensor | None"
|
| 786 |
+
},
|
| 787 |
+
{
|
| 788 |
+
"name": "max_seqlen_q",
|
| 789 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 790 |
+
"default": "0",
|
| 791 |
+
"annotation": "int"
|
| 792 |
+
},
|
| 793 |
+
{
|
| 794 |
+
"name": "max_seqlen_k",
|
| 795 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 796 |
+
"default": "0",
|
| 797 |
+
"annotation": "int"
|
| 798 |
+
},
|
| 799 |
+
{
|
| 800 |
+
"name": "p_dropout",
|
| 801 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 802 |
+
"default": "0.0",
|
| 803 |
+
"annotation": "float"
|
| 804 |
+
},
|
| 805 |
+
{
|
| 806 |
+
"name": "softmax_scale",
|
| 807 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 808 |
+
"default": "None",
|
| 809 |
+
"annotation": "float | None"
|
| 810 |
+
},
|
| 811 |
+
{
|
| 812 |
+
"name": "zero_tensors",
|
| 813 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 814 |
+
"default": "False",
|
| 815 |
+
"annotation": "bool"
|
| 816 |
+
},
|
| 817 |
+
{
|
| 818 |
+
"name": "is_causal",
|
| 819 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 820 |
+
"default": "False",
|
| 821 |
+
"annotation": "bool"
|
| 822 |
+
},
|
| 823 |
+
{
|
| 824 |
+
"name": "window_size_left",
|
| 825 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 826 |
+
"default": "-1",
|
| 827 |
+
"annotation": "int"
|
| 828 |
+
},
|
| 829 |
+
{
|
| 830 |
+
"name": "window_size_right",
|
| 831 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 832 |
+
"default": "-1",
|
| 833 |
+
"annotation": "int"
|
| 834 |
+
},
|
| 835 |
+
{
|
| 836 |
+
"name": "softcap",
|
| 837 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 838 |
+
"default": "0.0",
|
| 839 |
+
"annotation": "float"
|
| 840 |
+
},
|
| 841 |
+
{
|
| 842 |
+
"name": "return_softmax",
|
| 843 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 844 |
+
"default": "False",
|
| 845 |
+
"annotation": "bool"
|
| 846 |
+
},
|
| 847 |
+
{
|
| 848 |
+
"name": "gen",
|
| 849 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 850 |
+
"default": "None",
|
| 851 |
+
"annotation": "torch._C.Generator | None"
|
| 852 |
+
}
|
| 853 |
+
],
|
| 854 |
+
"return_annotation": "List[torch.Tensor]"
|
| 855 |
+
}
|
| 856 |
+
},
|
| 857 |
+
{
|
| 858 |
+
"name": "bwd",
|
| 859 |
+
"qualname": "bwd",
|
| 860 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 861 |
+
"kind": "function",
|
| 862 |
+
"doc": "Backward pass for multi-head attention.\n\nArgs:\n dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]\n softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]\n dq: Optional gradient tensor for queries, same shape as q\n dk: Optional gradient tensor for keys, same shape as k\n dv: Optional gradient tensor for values, same shape as v\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n deterministic: Whether to use deterministic algorithms\n gen: Optional random number generator\n rng_state: Optional RNG state from forward pass\n\nReturns:\n List of tensors: [dq, dk, dv]",
|
| 863 |
+
"signature": {
|
| 864 |
+
"parameters": [
|
| 865 |
+
{
|
| 866 |
+
"name": "dout",
|
| 867 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 868 |
+
"default": null,
|
| 869 |
+
"annotation": "torch.Tensor"
|
| 870 |
+
},
|
| 871 |
+
{
|
| 872 |
+
"name": "q",
|
| 873 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 874 |
+
"default": null,
|
| 875 |
+
"annotation": "torch.Tensor"
|
| 876 |
+
},
|
| 877 |
+
{
|
| 878 |
+
"name": "k",
|
| 879 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 880 |
+
"default": null,
|
| 881 |
+
"annotation": "torch.Tensor"
|
| 882 |
+
},
|
| 883 |
+
{
|
| 884 |
+
"name": "v",
|
| 885 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 886 |
+
"default": null,
|
| 887 |
+
"annotation": "torch.Tensor"
|
| 888 |
+
},
|
| 889 |
+
{
|
| 890 |
+
"name": "out",
|
| 891 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 892 |
+
"default": null,
|
| 893 |
+
"annotation": "torch.Tensor"
|
| 894 |
+
},
|
| 895 |
+
{
|
| 896 |
+
"name": "softmax_lse",
|
| 897 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 898 |
+
"default": null,
|
| 899 |
+
"annotation": "torch.Tensor"
|
| 900 |
+
},
|
| 901 |
+
{
|
| 902 |
+
"name": "dq",
|
| 903 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 904 |
+
"default": "None",
|
| 905 |
+
"annotation": "torch.Tensor | None"
|
| 906 |
+
},
|
| 907 |
+
{
|
| 908 |
+
"name": "dk",
|
| 909 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 910 |
+
"default": "None",
|
| 911 |
+
"annotation": "torch.Tensor | None"
|
| 912 |
+
},
|
| 913 |
+
{
|
| 914 |
+
"name": "dv",
|
| 915 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 916 |
+
"default": "None",
|
| 917 |
+
"annotation": "torch.Tensor | None"
|
| 918 |
+
},
|
| 919 |
+
{
|
| 920 |
+
"name": "alibi_slopes",
|
| 921 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 922 |
+
"default": "None",
|
| 923 |
+
"annotation": "torch.Tensor | None"
|
| 924 |
+
},
|
| 925 |
+
{
|
| 926 |
+
"name": "p_dropout",
|
| 927 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 928 |
+
"default": "0.0",
|
| 929 |
+
"annotation": "float"
|
| 930 |
+
},
|
| 931 |
+
{
|
| 932 |
+
"name": "softmax_scale",
|
| 933 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 934 |
+
"default": "None",
|
| 935 |
+
"annotation": "float | None"
|
| 936 |
+
},
|
| 937 |
+
{
|
| 938 |
+
"name": "is_causal",
|
| 939 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 940 |
+
"default": "False",
|
| 941 |
+
"annotation": "bool"
|
| 942 |
+
},
|
| 943 |
+
{
|
| 944 |
+
"name": "window_size_left",
|
| 945 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 946 |
+
"default": "-1",
|
| 947 |
+
"annotation": "int"
|
| 948 |
+
},
|
| 949 |
+
{
|
| 950 |
+
"name": "window_size_right",
|
| 951 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 952 |
+
"default": "-1",
|
| 953 |
+
"annotation": "int"
|
| 954 |
+
},
|
| 955 |
+
{
|
| 956 |
+
"name": "softcap",
|
| 957 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 958 |
+
"default": "0.0",
|
| 959 |
+
"annotation": "float"
|
| 960 |
+
},
|
| 961 |
+
{
|
| 962 |
+
"name": "deterministic",
|
| 963 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 964 |
+
"default": "False",
|
| 965 |
+
"annotation": "bool"
|
| 966 |
+
},
|
| 967 |
+
{
|
| 968 |
+
"name": "gen",
|
| 969 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 970 |
+
"default": "None",
|
| 971 |
+
"annotation": "torch._C.Generator | None"
|
| 972 |
+
},
|
| 973 |
+
{
|
| 974 |
+
"name": "rng_state",
|
| 975 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 976 |
+
"default": "None",
|
| 977 |
+
"annotation": "torch.Tensor | None"
|
| 978 |
+
}
|
| 979 |
+
],
|
| 980 |
+
"return_annotation": "List[torch.Tensor]"
|
| 981 |
+
}
|
| 982 |
+
},
|
| 983 |
+
{
|
| 984 |
+
"name": "varlen_bwd",
|
| 985 |
+
"qualname": "varlen_bwd",
|
| 986 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 987 |
+
"kind": "function",
|
| 988 |
+
"doc": "Backward pass for multi-head attention with variable sequence lengths.\n\nArgs:\n dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]\n softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]\n cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]\n cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]\n dq: Optional gradient tensor for queries, same shape as q\n dk: Optional gradient tensor for keys, same shape as k\n dv: Optional gradient tensor for values, same shape as v\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n max_seqlen_q: Maximum sequence length for queries\n max_seqlen_k: Maximum sequence length for keys\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n zero_tensors: Whether to zero tensors before computation\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n deterministic: Whether to use deterministic algorithms\n gen: Optional random number generator\n rng_state: Optional RNG state from forward pass\n\nReturns:\n List of tensors: [dq, dk, dv]",
|
| 989 |
+
"signature": {
|
| 990 |
+
"parameters": [
|
| 991 |
+
{
|
| 992 |
+
"name": "dout",
|
| 993 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 994 |
+
"default": null,
|
| 995 |
+
"annotation": "torch.Tensor"
|
| 996 |
+
},
|
| 997 |
+
{
|
| 998 |
+
"name": "q",
|
| 999 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1000 |
+
"default": null,
|
| 1001 |
+
"annotation": "torch.Tensor"
|
| 1002 |
+
},
|
| 1003 |
+
{
|
| 1004 |
+
"name": "k",
|
| 1005 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1006 |
+
"default": null,
|
| 1007 |
+
"annotation": "torch.Tensor"
|
| 1008 |
+
},
|
| 1009 |
+
{
|
| 1010 |
+
"name": "v",
|
| 1011 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1012 |
+
"default": null,
|
| 1013 |
+
"annotation": "torch.Tensor"
|
| 1014 |
+
},
|
| 1015 |
+
{
|
| 1016 |
+
"name": "out",
|
| 1017 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1018 |
+
"default": null,
|
| 1019 |
+
"annotation": "torch.Tensor"
|
| 1020 |
+
},
|
| 1021 |
+
{
|
| 1022 |
+
"name": "softmax_lse",
|
| 1023 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1024 |
+
"default": null,
|
| 1025 |
+
"annotation": "torch.Tensor"
|
| 1026 |
+
},
|
| 1027 |
+
{
|
| 1028 |
+
"name": "cu_seqlens_q",
|
| 1029 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1030 |
+
"default": null,
|
| 1031 |
+
"annotation": "torch.Tensor"
|
| 1032 |
+
},
|
| 1033 |
+
{
|
| 1034 |
+
"name": "cu_seqlens_k",
|
| 1035 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1036 |
+
"default": null,
|
| 1037 |
+
"annotation": "torch.Tensor"
|
| 1038 |
+
},
|
| 1039 |
+
{
|
| 1040 |
+
"name": "dq",
|
| 1041 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1042 |
+
"default": "None",
|
| 1043 |
+
"annotation": "torch.Tensor | None"
|
| 1044 |
+
},
|
| 1045 |
+
{
|
| 1046 |
+
"name": "dk",
|
| 1047 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1048 |
+
"default": "None",
|
| 1049 |
+
"annotation": "torch.Tensor | None"
|
| 1050 |
+
},
|
| 1051 |
+
{
|
| 1052 |
+
"name": "dv",
|
| 1053 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1054 |
+
"default": "None",
|
| 1055 |
+
"annotation": "torch.Tensor | None"
|
| 1056 |
+
},
|
| 1057 |
+
{
|
| 1058 |
+
"name": "alibi_slopes",
|
| 1059 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1060 |
+
"default": "None",
|
| 1061 |
+
"annotation": "torch.Tensor | None"
|
| 1062 |
+
},
|
| 1063 |
+
{
|
| 1064 |
+
"name": "max_seqlen_q",
|
| 1065 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1066 |
+
"default": "0",
|
| 1067 |
+
"annotation": "int"
|
| 1068 |
+
},
|
| 1069 |
+
{
|
| 1070 |
+
"name": "max_seqlen_k",
|
| 1071 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1072 |
+
"default": "0",
|
| 1073 |
+
"annotation": "int"
|
| 1074 |
+
},
|
| 1075 |
+
{
|
| 1076 |
+
"name": "p_dropout",
|
| 1077 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1078 |
+
"default": "0.0",
|
| 1079 |
+
"annotation": "float"
|
| 1080 |
+
},
|
| 1081 |
+
{
|
| 1082 |
+
"name": "softmax_scale",
|
| 1083 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1084 |
+
"default": "None",
|
| 1085 |
+
"annotation": "float | None"
|
| 1086 |
+
},
|
| 1087 |
+
{
|
| 1088 |
+
"name": "zero_tensors",
|
| 1089 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1090 |
+
"default": "False",
|
| 1091 |
+
"annotation": "bool"
|
| 1092 |
+
},
|
| 1093 |
+
{
|
| 1094 |
+
"name": "is_causal",
|
| 1095 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1096 |
+
"default": "False",
|
| 1097 |
+
"annotation": "bool"
|
| 1098 |
+
},
|
| 1099 |
+
{
|
| 1100 |
+
"name": "window_size_left",
|
| 1101 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1102 |
+
"default": "-1",
|
| 1103 |
+
"annotation": "int"
|
| 1104 |
+
},
|
| 1105 |
+
{
|
| 1106 |
+
"name": "window_size_right",
|
| 1107 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1108 |
+
"default": "-1",
|
| 1109 |
+
"annotation": "int"
|
| 1110 |
+
},
|
| 1111 |
+
{
|
| 1112 |
+
"name": "softcap",
|
| 1113 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1114 |
+
"default": "0.0",
|
| 1115 |
+
"annotation": "float"
|
| 1116 |
+
},
|
| 1117 |
+
{
|
| 1118 |
+
"name": "deterministic",
|
| 1119 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1120 |
+
"default": "False",
|
| 1121 |
+
"annotation": "bool"
|
| 1122 |
+
},
|
| 1123 |
+
{
|
| 1124 |
+
"name": "gen",
|
| 1125 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1126 |
+
"default": "None",
|
| 1127 |
+
"annotation": "torch._C.Generator | None"
|
| 1128 |
+
},
|
| 1129 |
+
{
|
| 1130 |
+
"name": "rng_state",
|
| 1131 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1132 |
+
"default": "None",
|
| 1133 |
+
"annotation": "torch.Tensor | None"
|
| 1134 |
+
}
|
| 1135 |
+
],
|
| 1136 |
+
"return_annotation": "List[torch.Tensor]"
|
| 1137 |
+
}
|
| 1138 |
+
},
|
| 1139 |
+
{
|
| 1140 |
+
"name": "fwd_kvcache",
|
| 1141 |
+
"qualname": "fwd_kvcache",
|
| 1142 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 1143 |
+
"kind": "function",
|
| 1144 |
+
"doc": "Forward pass for multi-head attention with KV cache.\n\nArgs:\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n kcache: Key cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n vcache: Value cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n k: Optional new keys tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]\n v: Optional new values tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]\n seqlens_k: Optional sequence lengths for keys of shape [batch_size]\n rotary_cos: Optional rotary cosine tensor of shape [seqlen_ro, rotary_dim/2]\n rotary_sin: Optional rotary sine tensor of shape [seqlen_ro, rotary_dim/2]\n cache_batch_idx: Optional indices to index into the KV cache\n leftpad_k: Optional left padding for keys of shape [batch_size]\n block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n out: Optional output tensor, same shape as q\n softmax_scale: Scale factor for softmax\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n is_rotary_interleaved: Whether rotary embeddings are interleaved\n num_splits: Number of splits for computation\n\nReturns:\n List of tensors: [output, softmax_lse]",
|
| 1145 |
+
"signature": {
|
| 1146 |
+
"parameters": [
|
| 1147 |
+
{
|
| 1148 |
+
"name": "q",
|
| 1149 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1150 |
+
"default": null,
|
| 1151 |
+
"annotation": "torch.Tensor"
|
| 1152 |
+
},
|
| 1153 |
+
{
|
| 1154 |
+
"name": "kcache",
|
| 1155 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1156 |
+
"default": null,
|
| 1157 |
+
"annotation": "torch.Tensor"
|
| 1158 |
+
},
|
| 1159 |
+
{
|
| 1160 |
+
"name": "vcache",
|
| 1161 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1162 |
+
"default": null,
|
| 1163 |
+
"annotation": "torch.Tensor"
|
| 1164 |
+
},
|
| 1165 |
+
{
|
| 1166 |
+
"name": "k",
|
| 1167 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1168 |
+
"default": "None",
|
| 1169 |
+
"annotation": "torch.Tensor | None"
|
| 1170 |
+
},
|
| 1171 |
+
{
|
| 1172 |
+
"name": "v",
|
| 1173 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1174 |
+
"default": "None",
|
| 1175 |
+
"annotation": "torch.Tensor | None"
|
| 1176 |
+
},
|
| 1177 |
+
{
|
| 1178 |
+
"name": "seqlens_k",
|
| 1179 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1180 |
+
"default": "None",
|
| 1181 |
+
"annotation": "torch.Tensor | None"
|
| 1182 |
+
},
|
| 1183 |
+
{
|
| 1184 |
+
"name": "rotary_cos",
|
| 1185 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1186 |
+
"default": "None",
|
| 1187 |
+
"annotation": "torch.Tensor | None"
|
| 1188 |
+
},
|
| 1189 |
+
{
|
| 1190 |
+
"name": "rotary_sin",
|
| 1191 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1192 |
+
"default": "None",
|
| 1193 |
+
"annotation": "torch.Tensor | None"
|
| 1194 |
+
},
|
| 1195 |
+
{
|
| 1196 |
+
"name": "cache_batch_idx",
|
| 1197 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1198 |
+
"default": "None",
|
| 1199 |
+
"annotation": "torch.Tensor | None"
|
| 1200 |
+
},
|
| 1201 |
+
{
|
| 1202 |
+
"name": "leftpad_k",
|
| 1203 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1204 |
+
"default": "None",
|
| 1205 |
+
"annotation": "torch.Tensor | None"
|
| 1206 |
+
},
|
| 1207 |
+
{
|
| 1208 |
+
"name": "block_table",
|
| 1209 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1210 |
+
"default": "None",
|
| 1211 |
+
"annotation": "torch.Tensor | None"
|
| 1212 |
+
},
|
| 1213 |
+
{
|
| 1214 |
+
"name": "alibi_slopes",
|
| 1215 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1216 |
+
"default": "None",
|
| 1217 |
+
"annotation": "torch.Tensor | None"
|
| 1218 |
+
},
|
| 1219 |
+
{
|
| 1220 |
+
"name": "out",
|
| 1221 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1222 |
+
"default": "None",
|
| 1223 |
+
"annotation": "torch.Tensor | None"
|
| 1224 |
+
},
|
| 1225 |
+
{
|
| 1226 |
+
"name": "softmax_scale",
|
| 1227 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1228 |
+
"default": "None",
|
| 1229 |
+
"annotation": "float | None"
|
| 1230 |
+
},
|
| 1231 |
+
{
|
| 1232 |
+
"name": "is_causal",
|
| 1233 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1234 |
+
"default": "False",
|
| 1235 |
+
"annotation": "bool"
|
| 1236 |
+
},
|
| 1237 |
+
{
|
| 1238 |
+
"name": "window_size_left",
|
| 1239 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1240 |
+
"default": "-1",
|
| 1241 |
+
"annotation": "int"
|
| 1242 |
+
},
|
| 1243 |
+
{
|
| 1244 |
+
"name": "window_size_right",
|
| 1245 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1246 |
+
"default": "-1",
|
| 1247 |
+
"annotation": "int"
|
| 1248 |
+
},
|
| 1249 |
+
{
|
| 1250 |
+
"name": "softcap",
|
| 1251 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1252 |
+
"default": "0.0",
|
| 1253 |
+
"annotation": "float"
|
| 1254 |
+
},
|
| 1255 |
+
{
|
| 1256 |
+
"name": "is_rotary_interleaved",
|
| 1257 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1258 |
+
"default": "False",
|
| 1259 |
+
"annotation": "bool"
|
| 1260 |
+
},
|
| 1261 |
+
{
|
| 1262 |
+
"name": "num_splits",
|
| 1263 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1264 |
+
"default": "1",
|
| 1265 |
+
"annotation": "int"
|
| 1266 |
+
}
|
| 1267 |
+
],
|
| 1268 |
+
"return_annotation": "List[torch.Tensor]"
|
| 1269 |
+
}
|
| 1270 |
+
}
|
| 1271 |
+
],
|
| 1272 |
+
"layers": []
|
| 1273 |
+
}
|
build/torch-stable-abi210-cu134-aarch64-linux/__init__.py
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List, Optional
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
from . import flash_attn_interface
|
| 6 |
+
from ._ops import ops as flash_attn_ops
|
| 7 |
+
from .flash_attn_interface import (
|
| 8 |
+
# helper to set up the Philox random number generator for dropout
|
| 9 |
+
_philox_generator,
|
| 10 |
+
# reexported for convenience to be used in the high-level API functions
|
| 11 |
+
flash_attn_func,
|
| 12 |
+
flash_attn_kvpacked_func,
|
| 13 |
+
flash_attn_qkvpacked_func,
|
| 14 |
+
flash_attn_varlen_func,
|
| 15 |
+
flash_attn_varlen_kvpacked_func,
|
| 16 |
+
flash_attn_varlen_qkvpacked_func,
|
| 17 |
+
flash_attn_with_kvcache,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
__all__ = [
|
| 21 |
+
# High-level API (with autograd support)
|
| 22 |
+
"flash_attn_func",
|
| 23 |
+
"flash_attn_kvpacked_func",
|
| 24 |
+
"flash_attn_qkvpacked_func",
|
| 25 |
+
"flash_attn_varlen_func",
|
| 26 |
+
"flash_attn_varlen_kvpacked_func",
|
| 27 |
+
"flash_attn_varlen_qkvpacked_func",
|
| 28 |
+
"flash_attn_with_kvcache",
|
| 29 |
+
# Upstream interface module. Its `_flash_attn_forward`, `_flash_attn_backward`,
|
| 30 |
+
# `_flash_attn_varlen_forward` and `_flash_attn_varlen_backward` are supported
|
| 31 |
+
# low-level entry points with upstream's signatures: Torch custom ops without
|
| 32 |
+
# autograd that return the LSE and are traceable by torch.compile. The autograd
|
| 33 |
+
# Functions above are built on top of them.
|
| 34 |
+
"flash_attn_interface",
|
| 35 |
+
# Low-level ops (no autograd)
|
| 36 |
+
"fwd",
|
| 37 |
+
"varlen_fwd",
|
| 38 |
+
"bwd",
|
| 39 |
+
"varlen_bwd",
|
| 40 |
+
"fwd_kvcache",
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def fwd(
|
| 45 |
+
q: torch.Tensor,
|
| 46 |
+
k: torch.Tensor,
|
| 47 |
+
v: torch.Tensor,
|
| 48 |
+
out: Optional[torch.Tensor] = None,
|
| 49 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 50 |
+
p_dropout: float = 0.0,
|
| 51 |
+
softmax_scale: Optional[float] = None,
|
| 52 |
+
is_causal: bool = False,
|
| 53 |
+
window_size_left: int = -1,
|
| 54 |
+
window_size_right: int = -1,
|
| 55 |
+
softcap: float = 0.0,
|
| 56 |
+
return_softmax: bool = False,
|
| 57 |
+
gen: Optional[torch.Generator] = None,
|
| 58 |
+
) -> List[torch.Tensor]:
|
| 59 |
+
"""
|
| 60 |
+
Forward pass for multi-head attention.
|
| 61 |
+
|
| 62 |
+
Args:
|
| 63 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 64 |
+
k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 65 |
+
v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 66 |
+
out: Optional output tensor, same shape as q
|
| 67 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 68 |
+
p_dropout: Dropout probability
|
| 69 |
+
softmax_scale: Scale factor for softmax
|
| 70 |
+
is_causal: Whether to use causal attention
|
| 71 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 72 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 73 |
+
softcap: Soft cap for attention weights
|
| 74 |
+
return_softmax: Whether to return softmax weights
|
| 75 |
+
gen: Optional random number generator
|
| 76 |
+
|
| 77 |
+
Returns:
|
| 78 |
+
List of tensors: [output, softmax_lse, (softmax if return_softmax)]
|
| 79 |
+
"""
|
| 80 |
+
if softmax_scale is None:
|
| 81 |
+
attention_head_dim = q.shape[-1]
|
| 82 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 83 |
+
|
| 84 |
+
gen = _philox_generator(q, p_dropout, gen)
|
| 85 |
+
return flash_attn_ops.fwd(
|
| 86 |
+
q,
|
| 87 |
+
k,
|
| 88 |
+
v,
|
| 89 |
+
out,
|
| 90 |
+
alibi_slopes,
|
| 91 |
+
p_dropout,
|
| 92 |
+
softmax_scale,
|
| 93 |
+
is_causal,
|
| 94 |
+
window_size_left,
|
| 95 |
+
window_size_right,
|
| 96 |
+
softcap,
|
| 97 |
+
return_softmax,
|
| 98 |
+
gen,
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def varlen_fwd(
|
| 103 |
+
q: torch.Tensor,
|
| 104 |
+
k: torch.Tensor,
|
| 105 |
+
v: torch.Tensor,
|
| 106 |
+
cu_seqlens_q: torch.Tensor,
|
| 107 |
+
cu_seqlens_k: torch.Tensor,
|
| 108 |
+
out: Optional[torch.Tensor] = None,
|
| 109 |
+
seqused_k: Optional[torch.Tensor] = None,
|
| 110 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 111 |
+
block_table: Optional[torch.Tensor] = None,
|
| 112 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 113 |
+
max_seqlen_q: int = 0,
|
| 114 |
+
max_seqlen_k: int = 0,
|
| 115 |
+
p_dropout: float = 0.0,
|
| 116 |
+
softmax_scale: Optional[float] = None,
|
| 117 |
+
zero_tensors: bool = False,
|
| 118 |
+
is_causal: bool = False,
|
| 119 |
+
window_size_left: int = -1,
|
| 120 |
+
window_size_right: int = -1,
|
| 121 |
+
softcap: float = 0.0,
|
| 122 |
+
return_softmax: bool = False,
|
| 123 |
+
gen: Optional[torch.Generator] = None,
|
| 124 |
+
) -> List[torch.Tensor]:
|
| 125 |
+
"""
|
| 126 |
+
Forward pass for multi-head attention with variable sequence lengths.
|
| 127 |
+
|
| 128 |
+
Args:
|
| 129 |
+
q: Query tensor of shape [total_q, num_heads, head_size]
|
| 130 |
+
k: Key tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 131 |
+
v: Value tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 132 |
+
cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]
|
| 133 |
+
cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]
|
| 134 |
+
out: Optional output tensor of shape [total_q, num_heads, head_size]
|
| 135 |
+
seqused_k: Optional tensor specifying how many keys to use per batch element [batch_size]
|
| 136 |
+
leftpad_k: Optional left padding for keys of shape [batch_size]
|
| 137 |
+
block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]
|
| 138 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 139 |
+
max_seqlen_q: Maximum sequence length for queries
|
| 140 |
+
max_seqlen_k: Maximum sequence length for keys
|
| 141 |
+
p_dropout: Dropout probability
|
| 142 |
+
softmax_scale: Scale factor for softmax
|
| 143 |
+
zero_tensors: Whether to zero tensors before computation
|
| 144 |
+
is_causal: Whether to use causal attention
|
| 145 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 146 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 147 |
+
softcap: Soft cap for attention weights
|
| 148 |
+
return_softmax: Whether to return softmax weights
|
| 149 |
+
gen: Optional random number generator
|
| 150 |
+
|
| 151 |
+
Returns:
|
| 152 |
+
List of tensors: [output, softmax_lse, (softmax if return_softmax)]
|
| 153 |
+
"""
|
| 154 |
+
if softmax_scale is None:
|
| 155 |
+
attention_head_dim = q.shape[-1]
|
| 156 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 157 |
+
|
| 158 |
+
gen = _philox_generator(q, p_dropout, gen)
|
| 159 |
+
return flash_attn_ops.varlen_fwd(
|
| 160 |
+
q,
|
| 161 |
+
k,
|
| 162 |
+
v,
|
| 163 |
+
out,
|
| 164 |
+
cu_seqlens_q,
|
| 165 |
+
cu_seqlens_k,
|
| 166 |
+
seqused_k,
|
| 167 |
+
leftpad_k,
|
| 168 |
+
block_table,
|
| 169 |
+
alibi_slopes,
|
| 170 |
+
max_seqlen_q,
|
| 171 |
+
max_seqlen_k,
|
| 172 |
+
p_dropout,
|
| 173 |
+
softmax_scale,
|
| 174 |
+
zero_tensors,
|
| 175 |
+
is_causal,
|
| 176 |
+
window_size_left,
|
| 177 |
+
window_size_right,
|
| 178 |
+
softcap,
|
| 179 |
+
return_softmax,
|
| 180 |
+
gen,
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def bwd(
|
| 185 |
+
dout: torch.Tensor,
|
| 186 |
+
q: torch.Tensor,
|
| 187 |
+
k: torch.Tensor,
|
| 188 |
+
v: torch.Tensor,
|
| 189 |
+
out: torch.Tensor,
|
| 190 |
+
softmax_lse: torch.Tensor,
|
| 191 |
+
dq: Optional[torch.Tensor] = None,
|
| 192 |
+
dk: Optional[torch.Tensor] = None,
|
| 193 |
+
dv: Optional[torch.Tensor] = None,
|
| 194 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 195 |
+
p_dropout: float = 0.0,
|
| 196 |
+
softmax_scale: Optional[float] = None,
|
| 197 |
+
is_causal: bool = False,
|
| 198 |
+
window_size_left: int = -1,
|
| 199 |
+
window_size_right: int = -1,
|
| 200 |
+
softcap: float = 0.0,
|
| 201 |
+
deterministic: bool = False,
|
| 202 |
+
gen: Optional[torch.Generator] = None,
|
| 203 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 204 |
+
) -> List[torch.Tensor]:
|
| 205 |
+
"""
|
| 206 |
+
Backward pass for multi-head attention.
|
| 207 |
+
|
| 208 |
+
Args:
|
| 209 |
+
dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 210 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 211 |
+
k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 212 |
+
v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 213 |
+
out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 214 |
+
softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]
|
| 215 |
+
dq: Optional gradient tensor for queries, same shape as q
|
| 216 |
+
dk: Optional gradient tensor for keys, same shape as k
|
| 217 |
+
dv: Optional gradient tensor for values, same shape as v
|
| 218 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 219 |
+
p_dropout: Dropout probability
|
| 220 |
+
softmax_scale: Scale factor for softmax
|
| 221 |
+
is_causal: Whether to use causal attention
|
| 222 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 223 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 224 |
+
softcap: Soft cap for attention weights
|
| 225 |
+
deterministic: Whether to use deterministic algorithms
|
| 226 |
+
gen: Optional random number generator
|
| 227 |
+
rng_state: Optional RNG state from forward pass
|
| 228 |
+
|
| 229 |
+
Returns:
|
| 230 |
+
List of tensors: [dq, dk, dv]
|
| 231 |
+
"""
|
| 232 |
+
if softmax_scale is None:
|
| 233 |
+
attention_head_dim = q.shape[-1]
|
| 234 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 235 |
+
|
| 236 |
+
return flash_attn_ops.bwd(
|
| 237 |
+
dout,
|
| 238 |
+
q,
|
| 239 |
+
k,
|
| 240 |
+
v,
|
| 241 |
+
out,
|
| 242 |
+
softmax_lse,
|
| 243 |
+
dq,
|
| 244 |
+
dk,
|
| 245 |
+
dv,
|
| 246 |
+
alibi_slopes,
|
| 247 |
+
p_dropout,
|
| 248 |
+
softmax_scale,
|
| 249 |
+
is_causal,
|
| 250 |
+
window_size_left,
|
| 251 |
+
window_size_right,
|
| 252 |
+
softcap,
|
| 253 |
+
deterministic,
|
| 254 |
+
gen,
|
| 255 |
+
rng_state,
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def varlen_bwd(
|
| 260 |
+
dout: torch.Tensor,
|
| 261 |
+
q: torch.Tensor,
|
| 262 |
+
k: torch.Tensor,
|
| 263 |
+
v: torch.Tensor,
|
| 264 |
+
out: torch.Tensor,
|
| 265 |
+
softmax_lse: torch.Tensor,
|
| 266 |
+
cu_seqlens_q: torch.Tensor,
|
| 267 |
+
cu_seqlens_k: torch.Tensor,
|
| 268 |
+
dq: Optional[torch.Tensor] = None,
|
| 269 |
+
dk: Optional[torch.Tensor] = None,
|
| 270 |
+
dv: Optional[torch.Tensor] = None,
|
| 271 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 272 |
+
max_seqlen_q: int = 0,
|
| 273 |
+
max_seqlen_k: int = 0,
|
| 274 |
+
p_dropout: float = 0.0,
|
| 275 |
+
softmax_scale: Optional[float] = None,
|
| 276 |
+
zero_tensors: bool = False,
|
| 277 |
+
is_causal: bool = False,
|
| 278 |
+
window_size_left: int = -1,
|
| 279 |
+
window_size_right: int = -1,
|
| 280 |
+
softcap: float = 0.0,
|
| 281 |
+
deterministic: bool = False,
|
| 282 |
+
gen: Optional[torch.Generator] = None,
|
| 283 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 284 |
+
) -> List[torch.Tensor]:
|
| 285 |
+
"""
|
| 286 |
+
Backward pass for multi-head attention with variable sequence lengths.
|
| 287 |
+
|
| 288 |
+
Args:
|
| 289 |
+
dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 290 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 291 |
+
k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 292 |
+
v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]
|
| 293 |
+
out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 294 |
+
softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]
|
| 295 |
+
cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]
|
| 296 |
+
cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]
|
| 297 |
+
dq: Optional gradient tensor for queries, same shape as q
|
| 298 |
+
dk: Optional gradient tensor for keys, same shape as k
|
| 299 |
+
dv: Optional gradient tensor for values, same shape as v
|
| 300 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 301 |
+
max_seqlen_q: Maximum sequence length for queries
|
| 302 |
+
max_seqlen_k: Maximum sequence length for keys
|
| 303 |
+
p_dropout: Dropout probability
|
| 304 |
+
softmax_scale: Scale factor for softmax
|
| 305 |
+
zero_tensors: Whether to zero tensors before computation
|
| 306 |
+
is_causal: Whether to use causal attention
|
| 307 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 308 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 309 |
+
softcap: Soft cap for attention weights
|
| 310 |
+
deterministic: Whether to use deterministic algorithms
|
| 311 |
+
gen: Optional random number generator
|
| 312 |
+
rng_state: Optional RNG state from forward pass
|
| 313 |
+
|
| 314 |
+
Returns:
|
| 315 |
+
List of tensors: [dq, dk, dv]
|
| 316 |
+
"""
|
| 317 |
+
if softmax_scale is None:
|
| 318 |
+
attention_head_dim = q.shape[-1]
|
| 319 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 320 |
+
|
| 321 |
+
return flash_attn_ops.varlen_bwd(
|
| 322 |
+
dout,
|
| 323 |
+
q,
|
| 324 |
+
k,
|
| 325 |
+
v,
|
| 326 |
+
out,
|
| 327 |
+
softmax_lse,
|
| 328 |
+
dq,
|
| 329 |
+
dk,
|
| 330 |
+
dv,
|
| 331 |
+
cu_seqlens_q,
|
| 332 |
+
cu_seqlens_k,
|
| 333 |
+
alibi_slopes,
|
| 334 |
+
max_seqlen_q,
|
| 335 |
+
max_seqlen_k,
|
| 336 |
+
p_dropout,
|
| 337 |
+
softmax_scale,
|
| 338 |
+
zero_tensors,
|
| 339 |
+
is_causal,
|
| 340 |
+
window_size_left,
|
| 341 |
+
window_size_right,
|
| 342 |
+
softcap,
|
| 343 |
+
deterministic,
|
| 344 |
+
gen,
|
| 345 |
+
rng_state,
|
| 346 |
+
)
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
def fwd_kvcache(
|
| 350 |
+
q: torch.Tensor,
|
| 351 |
+
kcache: torch.Tensor,
|
| 352 |
+
vcache: torch.Tensor,
|
| 353 |
+
k: Optional[torch.Tensor] = None,
|
| 354 |
+
v: Optional[torch.Tensor] = None,
|
| 355 |
+
seqlens_k: Optional[torch.Tensor] = None,
|
| 356 |
+
rotary_cos: Optional[torch.Tensor] = None,
|
| 357 |
+
rotary_sin: Optional[torch.Tensor] = None,
|
| 358 |
+
cache_batch_idx: Optional[torch.Tensor] = None,
|
| 359 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 360 |
+
block_table: Optional[torch.Tensor] = None,
|
| 361 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 362 |
+
out: Optional[torch.Tensor] = None,
|
| 363 |
+
softmax_scale: Optional[float] = None,
|
| 364 |
+
is_causal: bool = False,
|
| 365 |
+
window_size_left: int = -1,
|
| 366 |
+
window_size_right: int = -1,
|
| 367 |
+
softcap: float = 0.0,
|
| 368 |
+
is_rotary_interleaved: bool = False,
|
| 369 |
+
num_splits: int = 1,
|
| 370 |
+
) -> List[torch.Tensor]:
|
| 371 |
+
"""
|
| 372 |
+
Forward pass for multi-head attention with KV cache.
|
| 373 |
+
|
| 374 |
+
Args:
|
| 375 |
+
q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]
|
| 376 |
+
kcache: Key cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 377 |
+
vcache: Value cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]
|
| 378 |
+
k: Optional new keys tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]
|
| 379 |
+
v: Optional new values tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]
|
| 380 |
+
seqlens_k: Optional sequence lengths for keys of shape [batch_size]
|
| 381 |
+
rotary_cos: Optional rotary cosine tensor of shape [seqlen_ro, rotary_dim/2]
|
| 382 |
+
rotary_sin: Optional rotary sine tensor of shape [seqlen_ro, rotary_dim/2]
|
| 383 |
+
cache_batch_idx: Optional indices to index into the KV cache
|
| 384 |
+
leftpad_k: Optional left padding for keys of shape [batch_size]
|
| 385 |
+
block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]
|
| 386 |
+
alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]
|
| 387 |
+
out: Optional output tensor, same shape as q
|
| 388 |
+
softmax_scale: Scale factor for softmax
|
| 389 |
+
is_causal: Whether to use causal attention
|
| 390 |
+
window_size_left: Window size for left context (-1 for unlimited)
|
| 391 |
+
window_size_right: Window size for right context (-1 for unlimited)
|
| 392 |
+
softcap: Soft cap for attention weights
|
| 393 |
+
is_rotary_interleaved: Whether rotary embeddings are interleaved
|
| 394 |
+
num_splits: Number of splits for computation
|
| 395 |
+
|
| 396 |
+
Returns:
|
| 397 |
+
List of tensors: [output, softmax_lse]
|
| 398 |
+
"""
|
| 399 |
+
if softmax_scale is None:
|
| 400 |
+
attention_head_dim = q.shape[-1]
|
| 401 |
+
softmax_scale = 1.0 / (attention_head_dim**0.5)
|
| 402 |
+
|
| 403 |
+
return flash_attn_ops.fwd_kvcache(
|
| 404 |
+
q,
|
| 405 |
+
kcache,
|
| 406 |
+
vcache,
|
| 407 |
+
k,
|
| 408 |
+
v,
|
| 409 |
+
seqlens_k,
|
| 410 |
+
rotary_cos,
|
| 411 |
+
rotary_sin,
|
| 412 |
+
cache_batch_idx,
|
| 413 |
+
leftpad_k,
|
| 414 |
+
block_table,
|
| 415 |
+
alibi_slopes,
|
| 416 |
+
out,
|
| 417 |
+
softmax_scale,
|
| 418 |
+
is_causal,
|
| 419 |
+
window_size_left,
|
| 420 |
+
window_size_right,
|
| 421 |
+
softcap,
|
| 422 |
+
is_rotary_interleaved,
|
| 423 |
+
num_splits,
|
| 424 |
+
)
|
build/torch-stable-abi210-cu134-aarch64-linux/_flash_attn2_cuda_460047c.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:923bd50971a3d94f45b9a5fabc2223a7fdca1d40d8ccff4848907eb850e99b4c
|
| 3 |
+
size 1011746240
|
build/torch-stable-abi210-cu134-aarch64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _flash_attn2_cuda_460047c
|
| 3 |
+
ops = torch.ops._flash_attn2_cuda_460047c
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_flash_attn2_cuda_460047c::{op_name}"
|
build/torch-stable-abi210-cu134-aarch64-linux/flash_attn_interface.py
ADDED
|
@@ -0,0 +1,1708 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2023, Tri Dao.
|
| 2 |
+
|
| 3 |
+
from typing import Optional, Sequence, Tuple, Union
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
import torch.nn as nn
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
# # isort: off
|
| 10 |
+
# # We need to import the CUDA kernels after importing torch
|
| 11 |
+
# USE_TRITON_ROCM = os.getenv("FLASH_ATTENTION_TRITON_AMD_ENABLE", "FALSE") == "TRUE"
|
| 12 |
+
# if USE_TRITON_ROCM:
|
| 13 |
+
# from .flash_attn_triton_amd import interface_fa as flash_attn
|
| 14 |
+
# else:
|
| 15 |
+
# import flash_attn_2_cuda as flash_attn
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
from ._ops import ops as flash_attn
|
| 19 |
+
from ._ops import add_op_namespace_prefix
|
| 20 |
+
|
| 21 |
+
# # isort: on
|
| 22 |
+
|
| 23 |
+
# Torch >= 2.13 can pass a Generator through the stable ABI. Older versions reject the argument
|
| 24 |
+
# before the kernel runs, so there the CUDA op has to draw its Philox seed and offset itself.
|
| 25 |
+
_STABLE_ABI_GENERATOR = torch.__version__ >= "2.13"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def maybe_contiguous(x):
|
| 29 |
+
return x.contiguous() if x is not None and x.stride(-1) != 1 else x
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def _get_device():
|
| 33 |
+
if torch.xpu.is_available():
|
| 34 |
+
return "xpu"
|
| 35 |
+
elif torch.cuda.is_available():
|
| 36 |
+
return "cuda"
|
| 37 |
+
else:
|
| 38 |
+
return "cpu"
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def _get_block_size_n(device, head_dim, is_dropout, is_causal):
|
| 42 |
+
assert head_dim <= 256
|
| 43 |
+
|
| 44 |
+
if device.type == "xpu":
|
| 45 |
+
if head_dim <= 96:
|
| 46 |
+
return 64
|
| 47 |
+
elif head_dim <= 128:
|
| 48 |
+
return 32
|
| 49 |
+
elif head_dim <= 256:
|
| 50 |
+
return 64
|
| 51 |
+
else:
|
| 52 |
+
return 32
|
| 53 |
+
|
| 54 |
+
# This should match the block sizes in the CUDA kernel
|
| 55 |
+
major, minor = torch.cuda.get_device_capability(device)
|
| 56 |
+
is_sm8x = (
|
| 57 |
+
major == 8 and minor > 0
|
| 58 |
+
) # Only include sm86 and sm89, exclude sm80 (A100)
|
| 59 |
+
is_sm80 = major == 8 and minor == 0
|
| 60 |
+
is_sm90 = major == 9 and minor == 0
|
| 61 |
+
if head_dim <= 32:
|
| 62 |
+
return 128
|
| 63 |
+
if head_dim <= 64:
|
| 64 |
+
return 128 if not is_dropout else 64
|
| 65 |
+
elif head_dim <= 96:
|
| 66 |
+
return 64
|
| 67 |
+
elif head_dim <= 128:
|
| 68 |
+
if is_sm8x:
|
| 69 |
+
return 64 if (not is_dropout and is_causal) else 32
|
| 70 |
+
else:
|
| 71 |
+
return 64 if not is_dropout else 32
|
| 72 |
+
elif head_dim <= 192:
|
| 73 |
+
return 64
|
| 74 |
+
elif head_dim <= 224:
|
| 75 |
+
return 64
|
| 76 |
+
elif head_dim <= 256:
|
| 77 |
+
return 64
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def round_multiple(x, m):
|
| 81 |
+
return (x + m - 1) // m * m
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def _philox_generator(
|
| 85 |
+
q: torch.Tensor, dropout_p: float, generator: Optional[torch.Generator] = None
|
| 86 |
+
) -> Optional[torch.Generator]:
|
| 87 |
+
"""The generator to hand to `fwd` / `varlen_fwd`.
|
| 88 |
+
|
| 89 |
+
With dropout on CUDA this is the default generator unless one is given, so the kernel reserves
|
| 90 |
+
its seed and offset exactly like the non-stable build (see set_params_philox in flash_api.cpp).
|
| 91 |
+
"""
|
| 92 |
+
if not q.is_cuda:
|
| 93 |
+
return generator
|
| 94 |
+
if dropout_p <= 0:
|
| 95 |
+
return None
|
| 96 |
+
if not _STABLE_ABI_GENERATOR:
|
| 97 |
+
if generator is not None:
|
| 98 |
+
raise ValueError(
|
| 99 |
+
"flash_attn2: passing a generator to the CUDA kernel requires torch >= 2.13; "
|
| 100 |
+
"seed the default generator with torch.manual_seed instead"
|
| 101 |
+
)
|
| 102 |
+
return None
|
| 103 |
+
if generator is None:
|
| 104 |
+
generator = torch.cuda.default_generators[q.device.index]
|
| 105 |
+
return generator
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
@torch.library.custom_op(
|
| 109 |
+
add_op_namespace_prefix("_flash_attn_forward"),
|
| 110 |
+
mutates_args=(),
|
| 111 |
+
device_types=_get_device(),
|
| 112 |
+
# Tells torch.compile the forward draws random numbers, so it is never deduplicated or
|
| 113 |
+
# recomputed (e.g. under activation checkpointing).
|
| 114 |
+
tags=(torch.Tag.nondeterministic_seeded,),
|
| 115 |
+
)
|
| 116 |
+
def _flash_attn_forward(
|
| 117 |
+
q: torch.Tensor,
|
| 118 |
+
k: torch.Tensor,
|
| 119 |
+
v: torch.Tensor,
|
| 120 |
+
dropout_p: float,
|
| 121 |
+
softmax_scale: float,
|
| 122 |
+
causal: bool,
|
| 123 |
+
window_size_left: int,
|
| 124 |
+
window_size_right: int,
|
| 125 |
+
softcap: float,
|
| 126 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 127 |
+
return_softmax: bool,
|
| 128 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 129 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 130 |
+
gen = _philox_generator(q, dropout_p)
|
| 131 |
+
out, softmax_lse, S_dmask, rng_state = flash_attn.fwd(
|
| 132 |
+
q,
|
| 133 |
+
k,
|
| 134 |
+
v,
|
| 135 |
+
None,
|
| 136 |
+
alibi_slopes,
|
| 137 |
+
dropout_p,
|
| 138 |
+
softmax_scale,
|
| 139 |
+
causal,
|
| 140 |
+
window_size_left,
|
| 141 |
+
window_size_right,
|
| 142 |
+
softcap,
|
| 143 |
+
return_softmax,
|
| 144 |
+
gen,
|
| 145 |
+
)
|
| 146 |
+
return out, softmax_lse, S_dmask, rng_state
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_forward"))
|
| 150 |
+
def _flash_attn_forward_fake(
|
| 151 |
+
q: torch.Tensor,
|
| 152 |
+
k: torch.Tensor,
|
| 153 |
+
v: torch.Tensor,
|
| 154 |
+
dropout_p: float,
|
| 155 |
+
softmax_scale: float,
|
| 156 |
+
causal: bool,
|
| 157 |
+
window_size_left: int,
|
| 158 |
+
window_size_right: int,
|
| 159 |
+
softcap: float,
|
| 160 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 161 |
+
return_softmax: bool,
|
| 162 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 163 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 164 |
+
batch_size, seqlen_q, num_heads, head_size = q.shape
|
| 165 |
+
seqlen_k = k.shape[1]
|
| 166 |
+
out = torch.empty_like(q)
|
| 167 |
+
softmax_lse = torch.empty(
|
| 168 |
+
(batch_size, num_heads, seqlen_q),
|
| 169 |
+
dtype=torch.float32,
|
| 170 |
+
device=q.device,
|
| 171 |
+
layout=q.layout,
|
| 172 |
+
)
|
| 173 |
+
p = torch.empty((0,), dtype=q.dtype, device=q.device, layout=q.layout)
|
| 174 |
+
if return_softmax:
|
| 175 |
+
p = torch.empty(
|
| 176 |
+
(
|
| 177 |
+
batch_size,
|
| 178 |
+
num_heads,
|
| 179 |
+
round_multiple(seqlen_q, 128),
|
| 180 |
+
round_multiple(seqlen_k, 128),
|
| 181 |
+
),
|
| 182 |
+
dtype=q.dtype,
|
| 183 |
+
device=q.device,
|
| 184 |
+
layout=q.layout,
|
| 185 |
+
)
|
| 186 |
+
rng_state = torch.empty((2,), dtype=torch.int64, device=q.device)
|
| 187 |
+
|
| 188 |
+
return out, softmax_lse, p, rng_state
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
_wrapped_flash_attn_forward = flash_attn._flash_attn_forward # upstream alias, see CARD.md
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
@torch.library.custom_op(
|
| 195 |
+
add_op_namespace_prefix("_flash_attn_varlen_forward"),
|
| 196 |
+
mutates_args=(),
|
| 197 |
+
device_types=_get_device(),
|
| 198 |
+
tags=(torch.Tag.nondeterministic_seeded,),
|
| 199 |
+
)
|
| 200 |
+
def _flash_attn_varlen_forward(
|
| 201 |
+
q: torch.Tensor,
|
| 202 |
+
k: torch.Tensor,
|
| 203 |
+
v: torch.Tensor,
|
| 204 |
+
cu_seqlens_q: torch.Tensor,
|
| 205 |
+
cu_seqlens_k: torch.Tensor,
|
| 206 |
+
max_seqlen_q: int,
|
| 207 |
+
max_seqlen_k: int,
|
| 208 |
+
dropout_p: float,
|
| 209 |
+
softmax_scale: float,
|
| 210 |
+
causal: bool,
|
| 211 |
+
window_size_left: int = -1,
|
| 212 |
+
window_size_right: int = -1,
|
| 213 |
+
softcap: float = 0.0,
|
| 214 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 215 |
+
return_softmax: bool = False,
|
| 216 |
+
block_table: Optional[torch.Tensor] = None,
|
| 217 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 218 |
+
seqused_k: Optional[torch.Tensor] = None,
|
| 219 |
+
zero_tensors: bool = False,
|
| 220 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 221 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 222 |
+
gen = _philox_generator(q, dropout_p)
|
| 223 |
+
out, softmax_lse, S_dmask, rng_state = flash_attn.varlen_fwd(
|
| 224 |
+
q,
|
| 225 |
+
k,
|
| 226 |
+
v,
|
| 227 |
+
None,
|
| 228 |
+
cu_seqlens_q,
|
| 229 |
+
cu_seqlens_k,
|
| 230 |
+
seqused_k,
|
| 231 |
+
leftpad_k,
|
| 232 |
+
block_table,
|
| 233 |
+
alibi_slopes,
|
| 234 |
+
max_seqlen_q,
|
| 235 |
+
max_seqlen_k,
|
| 236 |
+
dropout_p,
|
| 237 |
+
softmax_scale,
|
| 238 |
+
zero_tensors,
|
| 239 |
+
causal,
|
| 240 |
+
window_size_left,
|
| 241 |
+
window_size_right,
|
| 242 |
+
softcap,
|
| 243 |
+
return_softmax,
|
| 244 |
+
gen,
|
| 245 |
+
)
|
| 246 |
+
# if out.isnan().any() or softmax_lse.isnan().any():
|
| 247 |
+
# breakpoint()
|
| 248 |
+
return out, softmax_lse, S_dmask, rng_state
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_varlen_forward"))
|
| 252 |
+
def _flash_attn_varlen_forward_fake(
|
| 253 |
+
q: torch.Tensor,
|
| 254 |
+
k: torch.Tensor,
|
| 255 |
+
v: torch.Tensor,
|
| 256 |
+
cu_seqlens_q: torch.Tensor,
|
| 257 |
+
cu_seqlens_k: torch.Tensor,
|
| 258 |
+
max_seqlen_q: int,
|
| 259 |
+
max_seqlen_k: int,
|
| 260 |
+
dropout_p: float,
|
| 261 |
+
softmax_scale: float,
|
| 262 |
+
causal: bool,
|
| 263 |
+
window_size_left: int = -1,
|
| 264 |
+
window_size_right: int = -1,
|
| 265 |
+
softcap: float = 0.0,
|
| 266 |
+
alibi_slopes: Optional[torch.Tensor] = None,
|
| 267 |
+
return_softmax: bool = False,
|
| 268 |
+
block_table: Optional[torch.Tensor] = None,
|
| 269 |
+
leftpad_k: Optional[torch.Tensor] = None,
|
| 270 |
+
seqused_k: Optional[torch.Tensor] = None,
|
| 271 |
+
zero_tensors: bool = False,
|
| 272 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 273 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 274 |
+
paged_kv = block_table is not None
|
| 275 |
+
batch_size = cu_seqlens_q.numel() - 1
|
| 276 |
+
total_q, num_heads, _ = q.shape
|
| 277 |
+
|
| 278 |
+
out = torch.empty_like(q)
|
| 279 |
+
softmax_lse = torch.empty(
|
| 280 |
+
(num_heads, total_q), dtype=torch.float32, device=q.device, layout=q.layout
|
| 281 |
+
)
|
| 282 |
+
p = torch.empty((0,), dtype=q.dtype, device=q.device, layout=q.layout)
|
| 283 |
+
seqlen_q_rounded = round_multiple(max_seqlen_q, 128)
|
| 284 |
+
seqlen_k_rounded = round_multiple(max_seqlen_k, 128)
|
| 285 |
+
if return_softmax:
|
| 286 |
+
p = torch.empty(
|
| 287 |
+
(batch_size, num_heads, seqlen_q_rounded, seqlen_k_rounded),
|
| 288 |
+
dtype=q.dtype,
|
| 289 |
+
device=q.device,
|
| 290 |
+
layout=q.layout,
|
| 291 |
+
)
|
| 292 |
+
rng_state = torch.empty((2,), dtype=torch.int64, device=q.device)
|
| 293 |
+
return out, softmax_lse, p, rng_state
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
_wrapped_flash_attn_varlen_forward = flash_attn._flash_attn_varlen_forward # upstream alias, see CARD.md
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
@torch.library.custom_op(
|
| 300 |
+
add_op_namespace_prefix("_flash_attn_backward"),
|
| 301 |
+
mutates_args=("dq", "dk", "dv"),
|
| 302 |
+
device_types=_get_device(),
|
| 303 |
+
)
|
| 304 |
+
def _flash_attn_backward(
|
| 305 |
+
dout: torch.Tensor,
|
| 306 |
+
q: torch.Tensor,
|
| 307 |
+
k: torch.Tensor,
|
| 308 |
+
v: torch.Tensor,
|
| 309 |
+
out: torch.Tensor,
|
| 310 |
+
softmax_lse: torch.Tensor,
|
| 311 |
+
dq: Optional[torch.Tensor],
|
| 312 |
+
dk: Optional[torch.Tensor],
|
| 313 |
+
dv: Optional[torch.Tensor],
|
| 314 |
+
dropout_p: float,
|
| 315 |
+
softmax_scale: float,
|
| 316 |
+
causal: bool,
|
| 317 |
+
window_size_left: int,
|
| 318 |
+
window_size_right: int,
|
| 319 |
+
softcap: float,
|
| 320 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 321 |
+
deterministic: bool,
|
| 322 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 323 |
+
) -> torch.Tensor:
|
| 324 |
+
# dq, dk, dv are allocated by us so they should already be contiguous
|
| 325 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 326 |
+
(
|
| 327 |
+
dq,
|
| 328 |
+
dk,
|
| 329 |
+
dv,
|
| 330 |
+
softmax_d,
|
| 331 |
+
) = flash_attn.bwd(
|
| 332 |
+
dout,
|
| 333 |
+
q,
|
| 334 |
+
k,
|
| 335 |
+
v,
|
| 336 |
+
out,
|
| 337 |
+
softmax_lse,
|
| 338 |
+
dq,
|
| 339 |
+
dk,
|
| 340 |
+
dv,
|
| 341 |
+
alibi_slopes,
|
| 342 |
+
dropout_p,
|
| 343 |
+
softmax_scale,
|
| 344 |
+
causal,
|
| 345 |
+
window_size_left,
|
| 346 |
+
window_size_right,
|
| 347 |
+
softcap,
|
| 348 |
+
deterministic,
|
| 349 |
+
None,
|
| 350 |
+
rng_state,
|
| 351 |
+
)
|
| 352 |
+
return softmax_d
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_backward"))
|
| 356 |
+
def _flash_attn_backward_fake(
|
| 357 |
+
dout: torch.Tensor,
|
| 358 |
+
q: torch.Tensor,
|
| 359 |
+
k: torch.Tensor,
|
| 360 |
+
v: torch.Tensor,
|
| 361 |
+
out: torch.Tensor,
|
| 362 |
+
softmax_lse: torch.Tensor,
|
| 363 |
+
dq: Optional[torch.Tensor],
|
| 364 |
+
dk: Optional[torch.Tensor],
|
| 365 |
+
dv: Optional[torch.Tensor],
|
| 366 |
+
dropout_p: float,
|
| 367 |
+
softmax_scale: float,
|
| 368 |
+
causal: bool,
|
| 369 |
+
window_size_left: int,
|
| 370 |
+
window_size_right: int,
|
| 371 |
+
softcap: float,
|
| 372 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 373 |
+
deterministic: bool,
|
| 374 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 375 |
+
) -> torch.Tensor:
|
| 376 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 377 |
+
if dq is None:
|
| 378 |
+
dq = torch.empty_like(q)
|
| 379 |
+
if dk is None:
|
| 380 |
+
dk = torch.empty_like(k)
|
| 381 |
+
if dv is None:
|
| 382 |
+
dv = torch.empty_like(v)
|
| 383 |
+
batch_size, seqlen_q, num_heads, _ = q.shape
|
| 384 |
+
softmax_d = torch.empty(
|
| 385 |
+
(batch_size, num_heads, round_multiple(seqlen_q, 128)),
|
| 386 |
+
device=q.device,
|
| 387 |
+
dtype=torch.float32,
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
return softmax_d
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
_wrapped_flash_attn_backward = flash_attn._flash_attn_backward # upstream alias, see CARD.md
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
@torch.library.custom_op(
|
| 397 |
+
add_op_namespace_prefix("_flash_attn_varlen_backward"),
|
| 398 |
+
mutates_args=("dq", "dk", "dv"),
|
| 399 |
+
device_types=_get_device(),
|
| 400 |
+
)
|
| 401 |
+
def _flash_attn_varlen_backward(
|
| 402 |
+
dout: torch.Tensor,
|
| 403 |
+
q: torch.Tensor,
|
| 404 |
+
k: torch.Tensor,
|
| 405 |
+
v: torch.Tensor,
|
| 406 |
+
out: torch.Tensor,
|
| 407 |
+
softmax_lse: torch.Tensor,
|
| 408 |
+
dq: Optional[torch.Tensor],
|
| 409 |
+
dk: Optional[torch.Tensor],
|
| 410 |
+
dv: Optional[torch.Tensor],
|
| 411 |
+
cu_seqlens_q: torch.Tensor,
|
| 412 |
+
cu_seqlens_k: torch.Tensor,
|
| 413 |
+
max_seqlen_q: int,
|
| 414 |
+
max_seqlen_k: int,
|
| 415 |
+
dropout_p: float,
|
| 416 |
+
softmax_scale: float,
|
| 417 |
+
causal: bool,
|
| 418 |
+
window_size_left: int,
|
| 419 |
+
window_size_right: int,
|
| 420 |
+
softcap: float,
|
| 421 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 422 |
+
deterministic: bool,
|
| 423 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 424 |
+
zero_tensors: bool = False,
|
| 425 |
+
) -> torch.Tensor:
|
| 426 |
+
# dq, dk, dv are allocated by us so they should already be contiguous
|
| 427 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 428 |
+
(
|
| 429 |
+
dq,
|
| 430 |
+
dk,
|
| 431 |
+
dv,
|
| 432 |
+
softmax_d,
|
| 433 |
+
) = flash_attn.varlen_bwd(
|
| 434 |
+
dout,
|
| 435 |
+
q,
|
| 436 |
+
k,
|
| 437 |
+
v,
|
| 438 |
+
out,
|
| 439 |
+
softmax_lse,
|
| 440 |
+
dq,
|
| 441 |
+
dk,
|
| 442 |
+
dv,
|
| 443 |
+
cu_seqlens_q,
|
| 444 |
+
cu_seqlens_k,
|
| 445 |
+
alibi_slopes,
|
| 446 |
+
max_seqlen_q,
|
| 447 |
+
max_seqlen_k,
|
| 448 |
+
dropout_p,
|
| 449 |
+
softmax_scale,
|
| 450 |
+
zero_tensors,
|
| 451 |
+
causal,
|
| 452 |
+
window_size_left,
|
| 453 |
+
window_size_right,
|
| 454 |
+
softcap,
|
| 455 |
+
deterministic,
|
| 456 |
+
None,
|
| 457 |
+
rng_state,
|
| 458 |
+
)
|
| 459 |
+
# if dk.isnan().any() or dk.isnan().any() or dv.isnan().any() or softmax_d.isnan().any():
|
| 460 |
+
# breakpoint()
|
| 461 |
+
return softmax_d
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
@torch.library.register_fake(add_op_namespace_prefix("_flash_attn_varlen_backward"))
|
| 465 |
+
def _flash_attn_varlen_backward_fake(
|
| 466 |
+
dout: torch.Tensor,
|
| 467 |
+
q: torch.Tensor,
|
| 468 |
+
k: torch.Tensor,
|
| 469 |
+
v: torch.Tensor,
|
| 470 |
+
out: torch.Tensor,
|
| 471 |
+
softmax_lse: torch.Tensor,
|
| 472 |
+
dq: Optional[torch.Tensor],
|
| 473 |
+
dk: Optional[torch.Tensor],
|
| 474 |
+
dv: Optional[torch.Tensor],
|
| 475 |
+
cu_seqlens_q: torch.Tensor,
|
| 476 |
+
cu_seqlens_k: torch.Tensor,
|
| 477 |
+
max_seqlen_q: int,
|
| 478 |
+
max_seqlen_k: int,
|
| 479 |
+
dropout_p: float,
|
| 480 |
+
softmax_scale: float,
|
| 481 |
+
causal: bool,
|
| 482 |
+
window_size_left: int,
|
| 483 |
+
window_size_right: int,
|
| 484 |
+
softcap: float,
|
| 485 |
+
alibi_slopes: Optional[torch.Tensor],
|
| 486 |
+
deterministic: bool,
|
| 487 |
+
rng_state: Optional[torch.Tensor] = None,
|
| 488 |
+
zero_tensors: bool = False,
|
| 489 |
+
) -> torch.Tensor:
|
| 490 |
+
dout, q, k, v, out = [maybe_contiguous(x) for x in (dout, q, k, v, out)]
|
| 491 |
+
batch_size = cu_seqlens_q.numel() - 1
|
| 492 |
+
total_q, num_heads, _ = q.shape
|
| 493 |
+
|
| 494 |
+
if dq is None:
|
| 495 |
+
dq = torch.empty_like(q)
|
| 496 |
+
if dk is None:
|
| 497 |
+
dk = torch.empty_like(k)
|
| 498 |
+
if dv is None:
|
| 499 |
+
dv = torch.empty_like(v)
|
| 500 |
+
softmax_d = torch.empty(
|
| 501 |
+
(num_heads, total_q + 128 * batch_size), device=q.device, dtype=torch.float32
|
| 502 |
+
)
|
| 503 |
+
|
| 504 |
+
return softmax_d
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
_wrapped_flash_attn_varlen_backward = flash_attn._flash_attn_varlen_backward # upstream alias, see CARD.md
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
class FlashAttnQKVPackedFunc(torch.autograd.Function):
|
| 511 |
+
@staticmethod
|
| 512 |
+
def forward(
|
| 513 |
+
ctx,
|
| 514 |
+
qkv,
|
| 515 |
+
dropout_p,
|
| 516 |
+
softmax_scale,
|
| 517 |
+
causal,
|
| 518 |
+
window_size,
|
| 519 |
+
softcap,
|
| 520 |
+
alibi_slopes,
|
| 521 |
+
deterministic,
|
| 522 |
+
return_softmax,
|
| 523 |
+
is_grad_enabled,
|
| 524 |
+
):
|
| 525 |
+
is_grad = is_grad_enabled and qkv.requires_grad
|
| 526 |
+
if softmax_scale is None:
|
| 527 |
+
softmax_scale = qkv.shape[-1] ** (-0.5)
|
| 528 |
+
q, k, v = qkv[:, :, 0].detach(), qkv[:, :, 1].detach(), qkv[:, :, 2].detach()
|
| 529 |
+
head_size_og = q.size(3)
|
| 530 |
+
if head_size_og % 8 != 0:
|
| 531 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 532 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 533 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 534 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_forward(
|
| 535 |
+
q,
|
| 536 |
+
k,
|
| 537 |
+
v,
|
| 538 |
+
dropout_p,
|
| 539 |
+
softmax_scale,
|
| 540 |
+
causal=causal,
|
| 541 |
+
window_size_left=window_size[0],
|
| 542 |
+
window_size_right=window_size[1],
|
| 543 |
+
softcap=softcap,
|
| 544 |
+
alibi_slopes=alibi_slopes,
|
| 545 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 546 |
+
)
|
| 547 |
+
if is_grad:
|
| 548 |
+
ctx.save_for_backward(q, k, v, out_padded, softmax_lse, rng_state)
|
| 549 |
+
ctx.dropout_p = dropout_p
|
| 550 |
+
ctx.softmax_scale = softmax_scale
|
| 551 |
+
ctx.causal = causal
|
| 552 |
+
ctx.window_size = window_size
|
| 553 |
+
ctx.softcap = softcap
|
| 554 |
+
ctx.alibi_slopes = alibi_slopes
|
| 555 |
+
ctx.deterministic = deterministic
|
| 556 |
+
out = out_padded[..., :head_size_og]
|
| 557 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 558 |
+
|
| 559 |
+
@staticmethod
|
| 560 |
+
def backward(ctx, dout, *args):
|
| 561 |
+
q, k, v, out, softmax_lse, rng_state = ctx.saved_tensors
|
| 562 |
+
qkv_shape = q.shape[:-2] + (3, *q.shape[-2:])
|
| 563 |
+
dqkv = torch.empty(qkv_shape, dtype=q.dtype, device=q.device)
|
| 564 |
+
head_size_og = dout.size(3)
|
| 565 |
+
dout_padded = dout
|
| 566 |
+
if head_size_og % 8 != 0:
|
| 567 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 568 |
+
_flash_attn_backward(
|
| 569 |
+
dout_padded,
|
| 570 |
+
q,
|
| 571 |
+
k,
|
| 572 |
+
v,
|
| 573 |
+
out,
|
| 574 |
+
softmax_lse,
|
| 575 |
+
dqkv[:, :, 0],
|
| 576 |
+
dqkv[:, :, 1],
|
| 577 |
+
dqkv[:, :, 2],
|
| 578 |
+
ctx.dropout_p,
|
| 579 |
+
ctx.softmax_scale,
|
| 580 |
+
ctx.causal,
|
| 581 |
+
ctx.window_size[0],
|
| 582 |
+
ctx.window_size[1],
|
| 583 |
+
ctx.softcap,
|
| 584 |
+
ctx.alibi_slopes,
|
| 585 |
+
ctx.deterministic,
|
| 586 |
+
rng_state=rng_state,
|
| 587 |
+
)
|
| 588 |
+
dqkv = dqkv[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 589 |
+
return dqkv, None, None, None, None, None, None, None, None, None
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
class FlashAttnVarlenQKVPackedFunc(torch.autograd.Function):
|
| 593 |
+
@staticmethod
|
| 594 |
+
def forward(
|
| 595 |
+
ctx,
|
| 596 |
+
qkv,
|
| 597 |
+
cu_seqlens,
|
| 598 |
+
max_seqlen,
|
| 599 |
+
dropout_p,
|
| 600 |
+
softmax_scale,
|
| 601 |
+
causal,
|
| 602 |
+
window_size,
|
| 603 |
+
softcap,
|
| 604 |
+
alibi_slopes,
|
| 605 |
+
deterministic,
|
| 606 |
+
return_softmax,
|
| 607 |
+
is_grad_enabled,
|
| 608 |
+
):
|
| 609 |
+
is_grad = is_grad_enabled and qkv.requires_grad
|
| 610 |
+
if softmax_scale is None:
|
| 611 |
+
softmax_scale = qkv.shape[-1] ** (-0.5)
|
| 612 |
+
q, k, v = qkv[:, 0].detach(), qkv[:, 1].detach(), qkv[:, 2].detach()
|
| 613 |
+
head_size_og = q.size(2)
|
| 614 |
+
if head_size_og % 8 != 0:
|
| 615 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 616 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 617 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 618 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_varlen_forward(
|
| 619 |
+
q,
|
| 620 |
+
k,
|
| 621 |
+
v,
|
| 622 |
+
cu_seqlens,
|
| 623 |
+
cu_seqlens,
|
| 624 |
+
max_seqlen,
|
| 625 |
+
max_seqlen,
|
| 626 |
+
dropout_p,
|
| 627 |
+
softmax_scale,
|
| 628 |
+
causal=causal,
|
| 629 |
+
window_size_left=window_size[0],
|
| 630 |
+
window_size_right=window_size[1],
|
| 631 |
+
softcap=softcap,
|
| 632 |
+
alibi_slopes=alibi_slopes,
|
| 633 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 634 |
+
block_table=None,
|
| 635 |
+
)
|
| 636 |
+
if is_grad:
|
| 637 |
+
ctx.save_for_backward(
|
| 638 |
+
q, k, v, out_padded, softmax_lse, cu_seqlens, rng_state
|
| 639 |
+
)
|
| 640 |
+
ctx.dropout_p = dropout_p
|
| 641 |
+
ctx.max_seqlen = max_seqlen
|
| 642 |
+
ctx.softmax_scale = softmax_scale
|
| 643 |
+
ctx.causal = causal
|
| 644 |
+
ctx.window_size = window_size
|
| 645 |
+
ctx.softcap = softcap
|
| 646 |
+
ctx.alibi_slopes = alibi_slopes
|
| 647 |
+
ctx.deterministic = deterministic
|
| 648 |
+
out = out_padded[..., :head_size_og]
|
| 649 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 650 |
+
|
| 651 |
+
@staticmethod
|
| 652 |
+
def backward(ctx, dout, *args):
|
| 653 |
+
q, k, v, out, softmax_lse, cu_seqlens, rng_state = ctx.saved_tensors
|
| 654 |
+
qkv_shape = q.shape[:-2] + (3, *q.shape[-2:])
|
| 655 |
+
dqkv = torch.empty(qkv_shape, dtype=q.dtype, device=q.device)
|
| 656 |
+
head_size_og = dout.size(2)
|
| 657 |
+
dout_padded = dout
|
| 658 |
+
if head_size_og % 8 != 0:
|
| 659 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 660 |
+
_flash_attn_varlen_backward(
|
| 661 |
+
dout_padded,
|
| 662 |
+
q,
|
| 663 |
+
k,
|
| 664 |
+
v,
|
| 665 |
+
out,
|
| 666 |
+
softmax_lse,
|
| 667 |
+
dqkv[:, 0],
|
| 668 |
+
dqkv[:, 1],
|
| 669 |
+
dqkv[:, 2],
|
| 670 |
+
cu_seqlens,
|
| 671 |
+
cu_seqlens,
|
| 672 |
+
ctx.max_seqlen,
|
| 673 |
+
ctx.max_seqlen,
|
| 674 |
+
ctx.dropout_p,
|
| 675 |
+
ctx.softmax_scale,
|
| 676 |
+
ctx.causal,
|
| 677 |
+
ctx.window_size[0],
|
| 678 |
+
ctx.window_size[1],
|
| 679 |
+
ctx.softcap,
|
| 680 |
+
ctx.alibi_slopes,
|
| 681 |
+
ctx.deterministic,
|
| 682 |
+
rng_state=rng_state,
|
| 683 |
+
)
|
| 684 |
+
dqkv = dqkv[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 685 |
+
return dqkv, None, None, None, None, None, None, None, None, None, None, None
|
| 686 |
+
|
| 687 |
+
|
| 688 |
+
class FlashAttnKVPackedFunc(torch.autograd.Function):
|
| 689 |
+
@staticmethod
|
| 690 |
+
def forward(
|
| 691 |
+
ctx,
|
| 692 |
+
q,
|
| 693 |
+
kv,
|
| 694 |
+
dropout_p,
|
| 695 |
+
softmax_scale,
|
| 696 |
+
causal,
|
| 697 |
+
window_size,
|
| 698 |
+
softcap,
|
| 699 |
+
alibi_slopes,
|
| 700 |
+
deterministic,
|
| 701 |
+
return_softmax,
|
| 702 |
+
is_grad_enabled,
|
| 703 |
+
):
|
| 704 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, kv])
|
| 705 |
+
if softmax_scale is None:
|
| 706 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 707 |
+
k, v = kv[:, :, 0].detach(), kv[:, :, 1].detach()
|
| 708 |
+
head_size_og = q.size(3)
|
| 709 |
+
if head_size_og % 8 != 0:
|
| 710 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 711 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 712 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 713 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_forward(
|
| 714 |
+
q,
|
| 715 |
+
k,
|
| 716 |
+
v,
|
| 717 |
+
dropout_p,
|
| 718 |
+
softmax_scale,
|
| 719 |
+
causal=causal,
|
| 720 |
+
window_size_left=window_size[0],
|
| 721 |
+
window_size_right=window_size[1],
|
| 722 |
+
softcap=softcap,
|
| 723 |
+
alibi_slopes=alibi_slopes,
|
| 724 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 725 |
+
)
|
| 726 |
+
if is_grad:
|
| 727 |
+
ctx.save_for_backward(q, k, v, out_padded, softmax_lse, rng_state)
|
| 728 |
+
ctx.dropout_p = dropout_p
|
| 729 |
+
ctx.softmax_scale = softmax_scale
|
| 730 |
+
ctx.causal = causal
|
| 731 |
+
ctx.window_size = window_size
|
| 732 |
+
ctx.softcap = softcap
|
| 733 |
+
ctx.alibi_slopes = alibi_slopes
|
| 734 |
+
ctx.deterministic = deterministic
|
| 735 |
+
out = out_padded[..., :head_size_og]
|
| 736 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 737 |
+
|
| 738 |
+
@staticmethod
|
| 739 |
+
def backward(ctx, dout, *args):
|
| 740 |
+
q, k, v, out, softmax_lse, rng_state = ctx.saved_tensors
|
| 741 |
+
dq = torch.empty_like(q)
|
| 742 |
+
kv_shape = k.shape[:-2] + (2, *k.shape[-2:])
|
| 743 |
+
dkv = torch.empty(kv_shape, dtype=k.dtype, device=k.device)
|
| 744 |
+
head_size_og = dout.size(3)
|
| 745 |
+
dout_padded = dout
|
| 746 |
+
if head_size_og % 8 != 0:
|
| 747 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 748 |
+
_flash_attn_backward(
|
| 749 |
+
dout_padded,
|
| 750 |
+
q,
|
| 751 |
+
k,
|
| 752 |
+
v,
|
| 753 |
+
out,
|
| 754 |
+
softmax_lse,
|
| 755 |
+
dq,
|
| 756 |
+
dkv[:, :, 0],
|
| 757 |
+
dkv[:, :, 1],
|
| 758 |
+
ctx.dropout_p,
|
| 759 |
+
ctx.softmax_scale,
|
| 760 |
+
ctx.causal,
|
| 761 |
+
ctx.window_size[0],
|
| 762 |
+
ctx.window_size[1],
|
| 763 |
+
ctx.softcap,
|
| 764 |
+
ctx.alibi_slopes,
|
| 765 |
+
ctx.deterministic,
|
| 766 |
+
rng_state=rng_state,
|
| 767 |
+
)
|
| 768 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 769 |
+
dkv = dkv[..., : dout.shape[-1]]
|
| 770 |
+
return dq, dkv, None, None, None, None, None, None, None, None, None
|
| 771 |
+
|
| 772 |
+
|
| 773 |
+
class FlashAttnVarlenKVPackedFunc(torch.autograd.Function):
|
| 774 |
+
@staticmethod
|
| 775 |
+
def forward(
|
| 776 |
+
ctx,
|
| 777 |
+
q,
|
| 778 |
+
kv,
|
| 779 |
+
cu_seqlens_q,
|
| 780 |
+
cu_seqlens_k,
|
| 781 |
+
max_seqlen_q,
|
| 782 |
+
max_seqlen_k,
|
| 783 |
+
dropout_p,
|
| 784 |
+
softmax_scale,
|
| 785 |
+
causal,
|
| 786 |
+
window_size,
|
| 787 |
+
softcap,
|
| 788 |
+
alibi_slopes,
|
| 789 |
+
deterministic,
|
| 790 |
+
return_softmax,
|
| 791 |
+
is_grad_enabled,
|
| 792 |
+
):
|
| 793 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, kv])
|
| 794 |
+
if softmax_scale is None:
|
| 795 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 796 |
+
k, v = kv[:, 0].detach(), kv[:, 1].detach()
|
| 797 |
+
head_size_og = q.size(2)
|
| 798 |
+
if head_size_og % 8 != 0:
|
| 799 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 800 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 801 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 802 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_varlen_forward(
|
| 803 |
+
q,
|
| 804 |
+
k,
|
| 805 |
+
v,
|
| 806 |
+
cu_seqlens_q,
|
| 807 |
+
cu_seqlens_k,
|
| 808 |
+
max_seqlen_q,
|
| 809 |
+
max_seqlen_k,
|
| 810 |
+
dropout_p,
|
| 811 |
+
softmax_scale,
|
| 812 |
+
causal=causal,
|
| 813 |
+
window_size_left=window_size[0],
|
| 814 |
+
window_size_right=window_size[1],
|
| 815 |
+
softcap=softcap,
|
| 816 |
+
alibi_slopes=alibi_slopes,
|
| 817 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 818 |
+
block_table=None,
|
| 819 |
+
)
|
| 820 |
+
if is_grad:
|
| 821 |
+
ctx.save_for_backward(
|
| 822 |
+
q, k, v, out_padded, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state
|
| 823 |
+
)
|
| 824 |
+
ctx.dropout_p = dropout_p
|
| 825 |
+
ctx.max_seqlen_q = max_seqlen_q
|
| 826 |
+
ctx.max_seqlen_k = max_seqlen_k
|
| 827 |
+
ctx.softmax_scale = softmax_scale
|
| 828 |
+
ctx.causal = causal
|
| 829 |
+
ctx.window_size = window_size
|
| 830 |
+
ctx.softcap = softcap
|
| 831 |
+
ctx.alibi_slopes = alibi_slopes
|
| 832 |
+
ctx.deterministic = deterministic
|
| 833 |
+
out = out_padded[..., :head_size_og]
|
| 834 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 835 |
+
|
| 836 |
+
@staticmethod
|
| 837 |
+
def backward(ctx, dout, *args):
|
| 838 |
+
q, k, v, out, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state = (
|
| 839 |
+
ctx.saved_tensors
|
| 840 |
+
)
|
| 841 |
+
dq = torch.empty_like(q)
|
| 842 |
+
kv_shape = k.shape[:-2] + (2, *k.shape[-2:])
|
| 843 |
+
dkv = torch.empty(kv_shape, dtype=k.dtype, device=k.device)
|
| 844 |
+
head_size_og = dout.size(2)
|
| 845 |
+
dout_padded = dout
|
| 846 |
+
if head_size_og % 8 != 0:
|
| 847 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 848 |
+
_flash_attn_varlen_backward(
|
| 849 |
+
dout_padded,
|
| 850 |
+
q,
|
| 851 |
+
k,
|
| 852 |
+
v,
|
| 853 |
+
out,
|
| 854 |
+
softmax_lse,
|
| 855 |
+
dq,
|
| 856 |
+
dkv[:, 0],
|
| 857 |
+
dkv[:, 1],
|
| 858 |
+
cu_seqlens_q,
|
| 859 |
+
cu_seqlens_k,
|
| 860 |
+
ctx.max_seqlen_q,
|
| 861 |
+
ctx.max_seqlen_k,
|
| 862 |
+
ctx.dropout_p,
|
| 863 |
+
ctx.softmax_scale,
|
| 864 |
+
ctx.causal,
|
| 865 |
+
ctx.window_size[0],
|
| 866 |
+
ctx.window_size[1],
|
| 867 |
+
ctx.softcap,
|
| 868 |
+
ctx.alibi_slopes,
|
| 869 |
+
ctx.deterministic,
|
| 870 |
+
rng_state=rng_state,
|
| 871 |
+
)
|
| 872 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 873 |
+
dkv = dkv[..., : dout.shape[-1]]
|
| 874 |
+
return (
|
| 875 |
+
dq,
|
| 876 |
+
dkv,
|
| 877 |
+
None,
|
| 878 |
+
None,
|
| 879 |
+
None,
|
| 880 |
+
None,
|
| 881 |
+
None,
|
| 882 |
+
None,
|
| 883 |
+
None,
|
| 884 |
+
None,
|
| 885 |
+
None,
|
| 886 |
+
None,
|
| 887 |
+
None,
|
| 888 |
+
None,
|
| 889 |
+
None,
|
| 890 |
+
)
|
| 891 |
+
|
| 892 |
+
|
| 893 |
+
class FlashAttnFunc(torch.autograd.Function):
|
| 894 |
+
@staticmethod
|
| 895 |
+
def forward(
|
| 896 |
+
ctx,
|
| 897 |
+
q,
|
| 898 |
+
k,
|
| 899 |
+
v,
|
| 900 |
+
dropout_p,
|
| 901 |
+
softmax_scale,
|
| 902 |
+
causal,
|
| 903 |
+
window_size,
|
| 904 |
+
softcap,
|
| 905 |
+
alibi_slopes,
|
| 906 |
+
deterministic,
|
| 907 |
+
return_softmax,
|
| 908 |
+
is_grad_enabled,
|
| 909 |
+
):
|
| 910 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, k, v])
|
| 911 |
+
if softmax_scale is None:
|
| 912 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 913 |
+
head_size_og = q.size(3)
|
| 914 |
+
if head_size_og % 8 != 0:
|
| 915 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 916 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 917 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 918 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_forward(
|
| 919 |
+
q,
|
| 920 |
+
k,
|
| 921 |
+
v,
|
| 922 |
+
dropout_p,
|
| 923 |
+
softmax_scale,
|
| 924 |
+
causal=causal,
|
| 925 |
+
window_size_left=window_size[0],
|
| 926 |
+
window_size_right=window_size[1],
|
| 927 |
+
softcap=softcap,
|
| 928 |
+
alibi_slopes=alibi_slopes,
|
| 929 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 930 |
+
)
|
| 931 |
+
if is_grad:
|
| 932 |
+
ctx.save_for_backward(q, k, v, out_padded, softmax_lse, rng_state)
|
| 933 |
+
ctx.dropout_p = dropout_p
|
| 934 |
+
ctx.softmax_scale = softmax_scale
|
| 935 |
+
ctx.causal = causal
|
| 936 |
+
ctx.window_size = window_size
|
| 937 |
+
ctx.softcap = softcap
|
| 938 |
+
ctx.alibi_slopes = alibi_slopes
|
| 939 |
+
ctx.deterministic = deterministic
|
| 940 |
+
out = out_padded[..., :head_size_og]
|
| 941 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 942 |
+
|
| 943 |
+
@staticmethod
|
| 944 |
+
def backward(ctx, dout, *args):
|
| 945 |
+
q, k, v, out, softmax_lse, rng_state = ctx.saved_tensors
|
| 946 |
+
dq, dk, dv = torch.empty_like(q), torch.empty_like(k), torch.empty_like(v)
|
| 947 |
+
head_size_og = dout.size(3)
|
| 948 |
+
dout_padded = dout
|
| 949 |
+
if head_size_og % 8 != 0:
|
| 950 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 951 |
+
_flash_attn_backward(
|
| 952 |
+
dout_padded,
|
| 953 |
+
q,
|
| 954 |
+
k,
|
| 955 |
+
v,
|
| 956 |
+
out,
|
| 957 |
+
softmax_lse,
|
| 958 |
+
dq,
|
| 959 |
+
dk,
|
| 960 |
+
dv,
|
| 961 |
+
ctx.dropout_p,
|
| 962 |
+
ctx.softmax_scale,
|
| 963 |
+
ctx.causal,
|
| 964 |
+
ctx.window_size[0],
|
| 965 |
+
ctx.window_size[1],
|
| 966 |
+
ctx.softcap,
|
| 967 |
+
ctx.alibi_slopes,
|
| 968 |
+
ctx.deterministic,
|
| 969 |
+
rng_state=rng_state,
|
| 970 |
+
)
|
| 971 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 972 |
+
dk = dk[..., : dout.shape[-1]]
|
| 973 |
+
dv = dv[..., : dout.shape[-1]]
|
| 974 |
+
return dq, dk, dv, None, None, None, None, None, None, None, None, None
|
| 975 |
+
|
| 976 |
+
|
| 977 |
+
class FlashAttnVarlenFunc(torch.autograd.Function):
|
| 978 |
+
@staticmethod
|
| 979 |
+
def forward(
|
| 980 |
+
ctx,
|
| 981 |
+
q,
|
| 982 |
+
k,
|
| 983 |
+
v,
|
| 984 |
+
cu_seqlens_q,
|
| 985 |
+
cu_seqlens_k,
|
| 986 |
+
max_seqlen_q,
|
| 987 |
+
max_seqlen_k,
|
| 988 |
+
dropout_p,
|
| 989 |
+
softmax_scale,
|
| 990 |
+
causal,
|
| 991 |
+
window_size,
|
| 992 |
+
softcap,
|
| 993 |
+
alibi_slopes,
|
| 994 |
+
deterministic,
|
| 995 |
+
return_softmax,
|
| 996 |
+
block_table,
|
| 997 |
+
is_grad_enabled,
|
| 998 |
+
):
|
| 999 |
+
is_grad = is_grad_enabled and any(x.requires_grad for x in [q, k, v])
|
| 1000 |
+
if softmax_scale is None:
|
| 1001 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 1002 |
+
head_size_og = q.size(2)
|
| 1003 |
+
if head_size_og % 8 != 0:
|
| 1004 |
+
q = torch.nn.functional.pad(q, [0, 8 - head_size_og % 8])
|
| 1005 |
+
k = torch.nn.functional.pad(k, [0, 8 - head_size_og % 8])
|
| 1006 |
+
v = torch.nn.functional.pad(v, [0, 8 - head_size_og % 8])
|
| 1007 |
+
out_padded, softmax_lse, S_dmask, rng_state = _flash_attn_varlen_forward(
|
| 1008 |
+
q,
|
| 1009 |
+
k,
|
| 1010 |
+
v,
|
| 1011 |
+
cu_seqlens_q,
|
| 1012 |
+
cu_seqlens_k,
|
| 1013 |
+
max_seqlen_q,
|
| 1014 |
+
max_seqlen_k,
|
| 1015 |
+
dropout_p,
|
| 1016 |
+
softmax_scale,
|
| 1017 |
+
causal=causal,
|
| 1018 |
+
window_size_left=window_size[0],
|
| 1019 |
+
window_size_right=window_size[1],
|
| 1020 |
+
softcap=softcap,
|
| 1021 |
+
alibi_slopes=alibi_slopes,
|
| 1022 |
+
return_softmax=return_softmax and dropout_p > 0,
|
| 1023 |
+
block_table=block_table,
|
| 1024 |
+
)
|
| 1025 |
+
if is_grad:
|
| 1026 |
+
ctx.save_for_backward(
|
| 1027 |
+
q, k, v, out_padded, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state
|
| 1028 |
+
)
|
| 1029 |
+
ctx.dropout_p = dropout_p
|
| 1030 |
+
ctx.max_seqlen_q = max_seqlen_q
|
| 1031 |
+
ctx.max_seqlen_k = max_seqlen_k
|
| 1032 |
+
ctx.softmax_scale = softmax_scale
|
| 1033 |
+
ctx.causal = causal
|
| 1034 |
+
ctx.window_size = window_size
|
| 1035 |
+
ctx.softcap = softcap
|
| 1036 |
+
ctx.alibi_slopes = alibi_slopes
|
| 1037 |
+
ctx.deterministic = deterministic
|
| 1038 |
+
|
| 1039 |
+
out = out_padded[..., :head_size_og]
|
| 1040 |
+
return out if not return_softmax else (out, softmax_lse, S_dmask)
|
| 1041 |
+
|
| 1042 |
+
@staticmethod
|
| 1043 |
+
def backward(ctx, dout, *args):
|
| 1044 |
+
q, k, v, out, softmax_lse, cu_seqlens_q, cu_seqlens_k, rng_state = (
|
| 1045 |
+
ctx.saved_tensors
|
| 1046 |
+
)
|
| 1047 |
+
dq, dk, dv = torch.empty_like(q), torch.empty_like(k), torch.empty_like(v)
|
| 1048 |
+
head_size_og = dout.size(2)
|
| 1049 |
+
dout_padded = dout
|
| 1050 |
+
if head_size_og % 8 != 0:
|
| 1051 |
+
dout_padded = torch.nn.functional.pad(dout, [0, 8 - head_size_og % 8])
|
| 1052 |
+
_flash_attn_varlen_backward(
|
| 1053 |
+
dout_padded,
|
| 1054 |
+
q,
|
| 1055 |
+
k,
|
| 1056 |
+
v,
|
| 1057 |
+
out,
|
| 1058 |
+
softmax_lse,
|
| 1059 |
+
dq,
|
| 1060 |
+
dk,
|
| 1061 |
+
dv,
|
| 1062 |
+
cu_seqlens_q,
|
| 1063 |
+
cu_seqlens_k,
|
| 1064 |
+
ctx.max_seqlen_q,
|
| 1065 |
+
ctx.max_seqlen_k,
|
| 1066 |
+
ctx.dropout_p,
|
| 1067 |
+
ctx.softmax_scale,
|
| 1068 |
+
ctx.causal,
|
| 1069 |
+
ctx.window_size[0],
|
| 1070 |
+
ctx.window_size[1],
|
| 1071 |
+
ctx.softcap,
|
| 1072 |
+
ctx.alibi_slopes,
|
| 1073 |
+
ctx.deterministic,
|
| 1074 |
+
rng_state=rng_state,
|
| 1075 |
+
)
|
| 1076 |
+
dq = dq[..., : dout.shape[-1]] # We could have padded the head dimension
|
| 1077 |
+
dk = dk[..., : dout.shape[-1]]
|
| 1078 |
+
dv = dv[..., : dout.shape[-1]]
|
| 1079 |
+
return (
|
| 1080 |
+
dq,
|
| 1081 |
+
dk,
|
| 1082 |
+
dv,
|
| 1083 |
+
None,
|
| 1084 |
+
None,
|
| 1085 |
+
None,
|
| 1086 |
+
None,
|
| 1087 |
+
None,
|
| 1088 |
+
None,
|
| 1089 |
+
None,
|
| 1090 |
+
None,
|
| 1091 |
+
None,
|
| 1092 |
+
None,
|
| 1093 |
+
None,
|
| 1094 |
+
None,
|
| 1095 |
+
None,
|
| 1096 |
+
None,
|
| 1097 |
+
)
|
| 1098 |
+
|
| 1099 |
+
|
| 1100 |
+
def flash_attn_qkvpacked_func(
|
| 1101 |
+
qkv,
|
| 1102 |
+
dropout_p=0.0,
|
| 1103 |
+
softmax_scale=None,
|
| 1104 |
+
causal=False,
|
| 1105 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1106 |
+
softcap=0.0, # <=0.0 means deactivate
|
| 1107 |
+
alibi_slopes=None,
|
| 1108 |
+
deterministic=False,
|
| 1109 |
+
return_attn_probs=False,
|
| 1110 |
+
):
|
| 1111 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1112 |
+
If Q, K, V are already stacked into 1 tensor, this function will be faster than
|
| 1113 |
+
calling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1114 |
+
of the gradients of Q, K, V.
|
| 1115 |
+
For multi-query and grouped-query attention (MQA/GQA), please see
|
| 1116 |
+
flash_attn_kvpacked_func and flash_attn_func.
|
| 1117 |
+
|
| 1118 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1119 |
+
will only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.
|
| 1120 |
+
|
| 1121 |
+
Arguments:
|
| 1122 |
+
qkv: (batch_size, seqlen, 3, nheads, headdim)
|
| 1123 |
+
dropout_p: float. Dropout probability.
|
| 1124 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1125 |
+
Default to 1 / sqrt(headdim).
|
| 1126 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1127 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1128 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1129 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|) is added to
|
| 1130 |
+
the attention score of query i and key j.
|
| 1131 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1132 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1133 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1134 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1135 |
+
(they might not have the right scaling).
|
| 1136 |
+
Return:
|
| 1137 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1138 |
+
softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The
|
| 1139 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1140 |
+
normalization factor).
|
| 1141 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1142 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1143 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1144 |
+
"""
|
| 1145 |
+
return FlashAttnQKVPackedFunc.apply(
|
| 1146 |
+
qkv,
|
| 1147 |
+
dropout_p,
|
| 1148 |
+
softmax_scale,
|
| 1149 |
+
causal,
|
| 1150 |
+
window_size,
|
| 1151 |
+
softcap,
|
| 1152 |
+
alibi_slopes,
|
| 1153 |
+
deterministic,
|
| 1154 |
+
return_attn_probs,
|
| 1155 |
+
torch.is_grad_enabled(),
|
| 1156 |
+
)
|
| 1157 |
+
|
| 1158 |
+
|
| 1159 |
+
def flash_attn_kvpacked_func(
|
| 1160 |
+
q,
|
| 1161 |
+
kv,
|
| 1162 |
+
dropout_p=0.0,
|
| 1163 |
+
softmax_scale=None,
|
| 1164 |
+
causal=False,
|
| 1165 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1166 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1167 |
+
alibi_slopes=None,
|
| 1168 |
+
deterministic=False,
|
| 1169 |
+
return_attn_probs=False,
|
| 1170 |
+
):
|
| 1171 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1172 |
+
If K, V are already stacked into 1 tensor, this function will be faster than
|
| 1173 |
+
calling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1174 |
+
of the gradients of K, V.
|
| 1175 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1176 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1177 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1178 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1179 |
+
|
| 1180 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1181 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1182 |
+
1 1 1 1 0
|
| 1183 |
+
1 1 1 1 1
|
| 1184 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1185 |
+
0 0
|
| 1186 |
+
0 0
|
| 1187 |
+
0 0
|
| 1188 |
+
1 0
|
| 1189 |
+
1 1
|
| 1190 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1191 |
+
|
| 1192 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1193 |
+
will only attend to keys between
|
| 1194 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1195 |
+
|
| 1196 |
+
Arguments:
|
| 1197 |
+
q: (batch_size, seqlen, nheads, headdim)
|
| 1198 |
+
kv: (batch_size, seqlen, 2, nheads_k, headdim)
|
| 1199 |
+
dropout_p: float. Dropout probability.
|
| 1200 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1201 |
+
Default to 1 / sqrt(headdim).
|
| 1202 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1203 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1204 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1205 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1206 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1207 |
+
is added to the attention score of query i and key j.
|
| 1208 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1209 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1210 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1211 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1212 |
+
(they might not have the right scaling).
|
| 1213 |
+
Return:
|
| 1214 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1215 |
+
softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The
|
| 1216 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1217 |
+
normalization factor).
|
| 1218 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1219 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1220 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1221 |
+
"""
|
| 1222 |
+
return FlashAttnKVPackedFunc.apply(
|
| 1223 |
+
q,
|
| 1224 |
+
kv,
|
| 1225 |
+
dropout_p,
|
| 1226 |
+
softmax_scale,
|
| 1227 |
+
causal,
|
| 1228 |
+
window_size,
|
| 1229 |
+
softcap,
|
| 1230 |
+
alibi_slopes,
|
| 1231 |
+
deterministic,
|
| 1232 |
+
return_attn_probs,
|
| 1233 |
+
torch.is_grad_enabled(),
|
| 1234 |
+
)
|
| 1235 |
+
|
| 1236 |
+
|
| 1237 |
+
def flash_attn_func(
|
| 1238 |
+
q,
|
| 1239 |
+
k,
|
| 1240 |
+
v,
|
| 1241 |
+
dropout_p=0.0,
|
| 1242 |
+
softmax_scale=None,
|
| 1243 |
+
causal=False,
|
| 1244 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1245 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1246 |
+
alibi_slopes=None,
|
| 1247 |
+
deterministic=False,
|
| 1248 |
+
return_attn_probs=False,
|
| 1249 |
+
):
|
| 1250 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1251 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1252 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1253 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1254 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1255 |
+
|
| 1256 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1257 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1258 |
+
1 1 1 1 0
|
| 1259 |
+
1 1 1 1 1
|
| 1260 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1261 |
+
0 0
|
| 1262 |
+
0 0
|
| 1263 |
+
0 0
|
| 1264 |
+
1 0
|
| 1265 |
+
1 1
|
| 1266 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1267 |
+
|
| 1268 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1269 |
+
will only attend to keys between
|
| 1270 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1271 |
+
|
| 1272 |
+
Arguments:
|
| 1273 |
+
q: (batch_size, seqlen, nheads, headdim)
|
| 1274 |
+
k: (batch_size, seqlen, nheads_k, headdim)
|
| 1275 |
+
v: (batch_size, seqlen, nheads_k, headdim)
|
| 1276 |
+
dropout_p: float. Dropout probability.
|
| 1277 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1278 |
+
Default to 1 / sqrt(headdim).
|
| 1279 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1280 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1281 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1282 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1283 |
+
is added to the attention score of query i and key j.
|
| 1284 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1285 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1286 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1287 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1288 |
+
(they might not have the right scaling).
|
| 1289 |
+
Return:
|
| 1290 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1291 |
+
softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The
|
| 1292 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1293 |
+
normalization factor).
|
| 1294 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1295 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1296 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1297 |
+
"""
|
| 1298 |
+
return FlashAttnFunc.apply(
|
| 1299 |
+
q,
|
| 1300 |
+
k,
|
| 1301 |
+
v,
|
| 1302 |
+
dropout_p,
|
| 1303 |
+
softmax_scale,
|
| 1304 |
+
causal,
|
| 1305 |
+
window_size,
|
| 1306 |
+
softcap,
|
| 1307 |
+
alibi_slopes,
|
| 1308 |
+
deterministic,
|
| 1309 |
+
return_attn_probs,
|
| 1310 |
+
torch.is_grad_enabled(),
|
| 1311 |
+
)
|
| 1312 |
+
|
| 1313 |
+
|
| 1314 |
+
def flash_attn_varlen_qkvpacked_func(
|
| 1315 |
+
qkv,
|
| 1316 |
+
cu_seqlens,
|
| 1317 |
+
max_seqlen,
|
| 1318 |
+
dropout_p=0.0,
|
| 1319 |
+
softmax_scale=None,
|
| 1320 |
+
causal=False,
|
| 1321 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1322 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1323 |
+
alibi_slopes=None,
|
| 1324 |
+
deterministic=False,
|
| 1325 |
+
return_attn_probs=False,
|
| 1326 |
+
):
|
| 1327 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1328 |
+
If Q, K, V are already stacked into 1 tensor, this function will be faster than
|
| 1329 |
+
calling flash_attn_varlen_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1330 |
+
of the gradients of Q, K, V.
|
| 1331 |
+
For multi-query and grouped-query attention (MQA/GQA), please see
|
| 1332 |
+
flash_attn_varlen_kvpacked_func and flash_attn_varlen_func.
|
| 1333 |
+
|
| 1334 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1335 |
+
will only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.
|
| 1336 |
+
|
| 1337 |
+
Arguments:
|
| 1338 |
+
qkv: (total, 3, nheads, headdim), where total = total number of tokens in the batch.
|
| 1339 |
+
cu_seqlens: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1340 |
+
of the sequences in the batch, used to index into qkv.
|
| 1341 |
+
max_seqlen: int. Maximum sequence length in the batch.
|
| 1342 |
+
dropout_p: float. Dropout probability.
|
| 1343 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1344 |
+
Default to 1 / sqrt(headdim).
|
| 1345 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1346 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1347 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1348 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|)
|
| 1349 |
+
is added to the attention score of query i and key j.
|
| 1350 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1351 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1352 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1353 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1354 |
+
(they might not have the right scaling).
|
| 1355 |
+
Return:
|
| 1356 |
+
out: (total, nheads, headdim).
|
| 1357 |
+
softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The
|
| 1358 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1359 |
+
normalization factor).
|
| 1360 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1361 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1362 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1363 |
+
"""
|
| 1364 |
+
return FlashAttnVarlenQKVPackedFunc.apply(
|
| 1365 |
+
qkv,
|
| 1366 |
+
cu_seqlens,
|
| 1367 |
+
max_seqlen,
|
| 1368 |
+
dropout_p,
|
| 1369 |
+
softmax_scale,
|
| 1370 |
+
causal,
|
| 1371 |
+
window_size,
|
| 1372 |
+
softcap,
|
| 1373 |
+
alibi_slopes,
|
| 1374 |
+
deterministic,
|
| 1375 |
+
return_attn_probs,
|
| 1376 |
+
torch.is_grad_enabled(),
|
| 1377 |
+
)
|
| 1378 |
+
|
| 1379 |
+
|
| 1380 |
+
def flash_attn_varlen_kvpacked_func(
|
| 1381 |
+
q,
|
| 1382 |
+
kv,
|
| 1383 |
+
cu_seqlens_q,
|
| 1384 |
+
cu_seqlens_k,
|
| 1385 |
+
max_seqlen_q,
|
| 1386 |
+
max_seqlen_k,
|
| 1387 |
+
dropout_p=0.0,
|
| 1388 |
+
softmax_scale=None,
|
| 1389 |
+
causal=False,
|
| 1390 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1391 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1392 |
+
alibi_slopes=None,
|
| 1393 |
+
deterministic=False,
|
| 1394 |
+
return_attn_probs=False,
|
| 1395 |
+
):
|
| 1396 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1397 |
+
If K, V are already stacked into 1 tensor, this function will be faster than
|
| 1398 |
+
calling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation
|
| 1399 |
+
of the gradients of K, V.
|
| 1400 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1401 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1402 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1403 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1404 |
+
|
| 1405 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1406 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1407 |
+
1 1 1 1 0
|
| 1408 |
+
1 1 1 1 1
|
| 1409 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1410 |
+
0 0
|
| 1411 |
+
0 0
|
| 1412 |
+
0 0
|
| 1413 |
+
1 0
|
| 1414 |
+
1 1
|
| 1415 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1416 |
+
|
| 1417 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1418 |
+
will only attend to keys between
|
| 1419 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1420 |
+
|
| 1421 |
+
Arguments:
|
| 1422 |
+
q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.
|
| 1423 |
+
kv: (total_k, 2, nheads_k, headdim), where total_k = total number of key tokens in the batch.
|
| 1424 |
+
cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1425 |
+
of the sequences in the batch, used to index into q.
|
| 1426 |
+
cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1427 |
+
of the sequences in the batch, used to index into kv.
|
| 1428 |
+
max_seqlen_q: int. Maximum query sequence length in the batch.
|
| 1429 |
+
max_seqlen_k: int. Maximum key sequence length in the batch.
|
| 1430 |
+
dropout_p: float. Dropout probability.
|
| 1431 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1432 |
+
Default to 1 / sqrt(headdim).
|
| 1433 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1434 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1435 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1436 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1437 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1438 |
+
is added to the attention score of query i and key j.
|
| 1439 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1440 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1441 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1442 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1443 |
+
(they might not have the right scaling).
|
| 1444 |
+
Return:
|
| 1445 |
+
out: (total, nheads, headdim).
|
| 1446 |
+
softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The
|
| 1447 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1448 |
+
normalization factor).
|
| 1449 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1450 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1451 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1452 |
+
"""
|
| 1453 |
+
return FlashAttnVarlenKVPackedFunc.apply(
|
| 1454 |
+
q,
|
| 1455 |
+
kv,
|
| 1456 |
+
cu_seqlens_q,
|
| 1457 |
+
cu_seqlens_k,
|
| 1458 |
+
max_seqlen_q,
|
| 1459 |
+
max_seqlen_k,
|
| 1460 |
+
dropout_p,
|
| 1461 |
+
softmax_scale,
|
| 1462 |
+
causal,
|
| 1463 |
+
window_size,
|
| 1464 |
+
softcap,
|
| 1465 |
+
alibi_slopes,
|
| 1466 |
+
deterministic,
|
| 1467 |
+
return_attn_probs,
|
| 1468 |
+
torch.is_grad_enabled(),
|
| 1469 |
+
)
|
| 1470 |
+
|
| 1471 |
+
|
| 1472 |
+
def flash_attn_varlen_func(
|
| 1473 |
+
q,
|
| 1474 |
+
k,
|
| 1475 |
+
v,
|
| 1476 |
+
cu_seqlens_q,
|
| 1477 |
+
cu_seqlens_k,
|
| 1478 |
+
max_seqlen_q,
|
| 1479 |
+
max_seqlen_k,
|
| 1480 |
+
dropout_p=0.0,
|
| 1481 |
+
softmax_scale=None,
|
| 1482 |
+
causal=False,
|
| 1483 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1484 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1485 |
+
alibi_slopes=None,
|
| 1486 |
+
deterministic=False,
|
| 1487 |
+
return_attn_probs=False,
|
| 1488 |
+
block_table=None,
|
| 1489 |
+
):
|
| 1490 |
+
"""dropout_p should be set to 0.0 during evaluation
|
| 1491 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in K, V with fewer heads
|
| 1492 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1493 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1494 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1495 |
+
|
| 1496 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1497 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1498 |
+
1 1 1 1 0
|
| 1499 |
+
1 1 1 1 1
|
| 1500 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1501 |
+
0 0
|
| 1502 |
+
0 0
|
| 1503 |
+
0 0
|
| 1504 |
+
1 0
|
| 1505 |
+
1 1
|
| 1506 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1507 |
+
|
| 1508 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1509 |
+
will only attend to keys between
|
| 1510 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1511 |
+
|
| 1512 |
+
Arguments:
|
| 1513 |
+
q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.
|
| 1514 |
+
k: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.
|
| 1515 |
+
v: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.
|
| 1516 |
+
cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1517 |
+
of the sequences in the batch, used to index into q.
|
| 1518 |
+
cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths
|
| 1519 |
+
of the sequences in the batch, used to index into kv.
|
| 1520 |
+
max_seqlen_q: int. Maximum query sequence length in the batch.
|
| 1521 |
+
max_seqlen_k: int. Maximum key sequence length in the batch.
|
| 1522 |
+
dropout_p: float. Dropout probability.
|
| 1523 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1524 |
+
Default to 1 / sqrt(headdim).
|
| 1525 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1526 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1527 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1528 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1529 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1530 |
+
is added to the attention score of query i and key j.
|
| 1531 |
+
deterministic: bool. Whether to use the deterministic implementation of the backward pass,
|
| 1532 |
+
which is slightly slower and uses more memory. The forward pass is always deterministic.
|
| 1533 |
+
return_attn_probs: bool. Whether to return the attention probabilities. This option is for
|
| 1534 |
+
testing only. The returned probabilities are not guaranteed to be correct
|
| 1535 |
+
(they might not have the right scaling).
|
| 1536 |
+
Return:
|
| 1537 |
+
out: (total, nheads, headdim).
|
| 1538 |
+
softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The
|
| 1539 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1540 |
+
normalization factor).
|
| 1541 |
+
S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).
|
| 1542 |
+
The output of softmax (possibly with different scaling). It also encodes the dropout
|
| 1543 |
+
pattern (negative means that location was dropped, nonnegative means it was kept).
|
| 1544 |
+
"""
|
| 1545 |
+
return FlashAttnVarlenFunc.apply(
|
| 1546 |
+
q,
|
| 1547 |
+
k,
|
| 1548 |
+
v,
|
| 1549 |
+
cu_seqlens_q,
|
| 1550 |
+
cu_seqlens_k,
|
| 1551 |
+
max_seqlen_q,
|
| 1552 |
+
max_seqlen_k,
|
| 1553 |
+
dropout_p,
|
| 1554 |
+
softmax_scale,
|
| 1555 |
+
causal,
|
| 1556 |
+
window_size,
|
| 1557 |
+
softcap,
|
| 1558 |
+
alibi_slopes,
|
| 1559 |
+
deterministic,
|
| 1560 |
+
return_attn_probs,
|
| 1561 |
+
block_table,
|
| 1562 |
+
False if q.device.type == "cpu" else torch.is_grad_enabled(),
|
| 1563 |
+
)
|
| 1564 |
+
|
| 1565 |
+
|
| 1566 |
+
def flash_attn_with_kvcache(
|
| 1567 |
+
q,
|
| 1568 |
+
k_cache,
|
| 1569 |
+
v_cache,
|
| 1570 |
+
k=None,
|
| 1571 |
+
v=None,
|
| 1572 |
+
rotary_cos=None,
|
| 1573 |
+
rotary_sin=None,
|
| 1574 |
+
cache_seqlens: Optional[Union[(int, torch.Tensor)]] = None,
|
| 1575 |
+
cache_batch_idx: Optional[torch.Tensor] = None,
|
| 1576 |
+
cache_leftpad: Optional[torch.Tensor] = None,
|
| 1577 |
+
block_table: Optional[torch.Tensor] = None,
|
| 1578 |
+
softmax_scale=None,
|
| 1579 |
+
causal=False,
|
| 1580 |
+
window_size=(-1, -1), # -1 means infinite context window
|
| 1581 |
+
softcap=0.0, # 0.0 means deactivated
|
| 1582 |
+
rotary_interleaved=True,
|
| 1583 |
+
alibi_slopes=None,
|
| 1584 |
+
num_splits=0,
|
| 1585 |
+
return_softmax_lse=False,
|
| 1586 |
+
):
|
| 1587 |
+
"""
|
| 1588 |
+
If k and v are not None, k_cache and v_cache will be updated *inplace* with the new values from
|
| 1589 |
+
k and v. This is useful for incremental decoding: you can pass in the cached keys/values from
|
| 1590 |
+
the previous step, and update them with the new keys/values from the current step, and do
|
| 1591 |
+
attention with the updated cache, all in 1 kernel.
|
| 1592 |
+
|
| 1593 |
+
If you pass in k / v, you must make sure that the cache is large enough to hold the new values.
|
| 1594 |
+
For example, the KV cache could be pre-allocated with the max sequence length, and you can use
|
| 1595 |
+
cache_seqlens to keep track of the current sequence lengths of each sequence in the batch.
|
| 1596 |
+
|
| 1597 |
+
Also apply rotary embedding if rotary_cos and rotary_sin are passed in. The key @k will be
|
| 1598 |
+
rotated by rotary_cos and rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.
|
| 1599 |
+
If causal or local (i.e., window_size != (-1, -1)), the query @q will be rotated by rotary_cos
|
| 1600 |
+
and rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.
|
| 1601 |
+
If not causal and not local, the query @q will be rotated by rotary_cos and rotary_sin at
|
| 1602 |
+
indices cache_seqlens only (i.e. we consider all tokens in @q to be at position cache_seqlens).
|
| 1603 |
+
|
| 1604 |
+
See tests/test_flash_attn.py::test_flash_attn_kvcache for examples of how to use this function.
|
| 1605 |
+
|
| 1606 |
+
Supports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads
|
| 1607 |
+
than Q. Note that the number of heads in Q must be divisible by the number of heads in KV.
|
| 1608 |
+
For example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head
|
| 1609 |
+
0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.
|
| 1610 |
+
|
| 1611 |
+
If causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.
|
| 1612 |
+
For example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:
|
| 1613 |
+
1 1 1 1 0
|
| 1614 |
+
1 1 1 1 1
|
| 1615 |
+
If seqlen_q = 5 and seqlen_k = 2, the causal mask is:
|
| 1616 |
+
0 0
|
| 1617 |
+
0 0
|
| 1618 |
+
0 0
|
| 1619 |
+
1 0
|
| 1620 |
+
1 1
|
| 1621 |
+
If the row of the mask is all zero, the output will be zero.
|
| 1622 |
+
|
| 1623 |
+
If window_size != (-1, -1), implements sliding window local attention. Query at position i
|
| 1624 |
+
will only attend to keys between
|
| 1625 |
+
[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.
|
| 1626 |
+
|
| 1627 |
+
Note: Does not support backward pass.
|
| 1628 |
+
|
| 1629 |
+
Arguments:
|
| 1630 |
+
q: (batch_size, seqlen, nheads, headdim)
|
| 1631 |
+
k_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,
|
| 1632 |
+
or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)
|
| 1633 |
+
page_block_size must be a multiple of 256.
|
| 1634 |
+
v_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,
|
| 1635 |
+
or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)
|
| 1636 |
+
k [optional]: (batch_size, seqlen_new, nheads_k, headdim). If not None, we concatenate
|
| 1637 |
+
k with k_cache, starting at the indices specified by cache_seqlens.
|
| 1638 |
+
v [optional]: (batch_size, seqlen_new, nheads_k, headdim). Similar to k.
|
| 1639 |
+
rotary_cos [optional]: (seqlen_ro, rotary_dim / 2). If not None, we apply rotary embedding
|
| 1640 |
+
to k and q. Only applicable if k and v are passed in. rotary_dim must be divisible by 16.
|
| 1641 |
+
rotary_sin [optional]: (seqlen_ro, rotary_dim / 2). Similar to rotary_cos.
|
| 1642 |
+
cache_seqlens: int, or (batch_size,), dtype torch.int32. The sequence lengths of the
|
| 1643 |
+
KV cache.
|
| 1644 |
+
cache_batch_idx: (batch_size,), dtype torch.int32. The indices used to index into the KV cache.
|
| 1645 |
+
If None, we assume that the batch indices are [0, 1, 2, ..., batch_size - 1].
|
| 1646 |
+
If the indices are not distinct, and k and v are provided, the values updated in the cache
|
| 1647 |
+
might come from any of the duplicate indices.
|
| 1648 |
+
cache_leftpad: (batch_size,), dtype torch.int32. The index that the KV cache starts. If None, assume 0.
|
| 1649 |
+
block_table [optional]: (batch_size, max_num_blocks_per_seq), dtype torch.int32.
|
| 1650 |
+
softmax_scale: float. The scaling of QK^T before applying softmax.
|
| 1651 |
+
Default to 1 / sqrt(headdim).
|
| 1652 |
+
causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).
|
| 1653 |
+
window_size: (left, right). If not (-1, -1), implements sliding window local attention.
|
| 1654 |
+
softcap: float. Anything > 0 activates softcapping attention.
|
| 1655 |
+
rotary_interleaved: bool. Only applicable if rotary_cos and rotary_sin are passed in.
|
| 1656 |
+
If True, rotary embedding will combine dimensions 0 & 1, 2 & 3, etc. If False,
|
| 1657 |
+
rotary embedding will combine dimensions 0 & rotary_dim / 2, 1 & rotary_dim / 2 + 1
|
| 1658 |
+
(i.e. GPT-NeoX style).
|
| 1659 |
+
alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of
|
| 1660 |
+
(-alibi_slope * |i + seqlen_k - seqlen_q - j|)
|
| 1661 |
+
is added to the attention score of query i and key j.
|
| 1662 |
+
num_splits: int. If > 1, split the key/value into this many chunks along the sequence.
|
| 1663 |
+
If num_splits == 1, we don't split the key/value. If num_splits == 0, we use a heuristic
|
| 1664 |
+
to automatically determine the number of splits.
|
| 1665 |
+
Don't change this unless you know what you are doing.
|
| 1666 |
+
return_softmax_lse: bool. Whether to return the logsumexp of the attention scores.
|
| 1667 |
+
|
| 1668 |
+
Return:
|
| 1669 |
+
out: (batch_size, seqlen, nheads, headdim).
|
| 1670 |
+
softmax_lse [optional, if return_softmax_lse=True]: (batch_size, nheads, seqlen). The
|
| 1671 |
+
logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax
|
| 1672 |
+
normalization factor).
|
| 1673 |
+
"""
|
| 1674 |
+
assert k_cache.stride(-1) == 1, "k_cache must have contiguous last dimension"
|
| 1675 |
+
assert v_cache.stride(-1) == 1, "v_cache must have contiguous last dimension"
|
| 1676 |
+
q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
|
| 1677 |
+
if softmax_scale is None:
|
| 1678 |
+
softmax_scale = q.shape[-1] ** (-0.5)
|
| 1679 |
+
if cache_seqlens is not None and isinstance(cache_seqlens, int):
|
| 1680 |
+
cache_seqlens = torch.full(
|
| 1681 |
+
(k_cache.shape[0],), cache_seqlens, dtype=torch.int32, device=k_cache.device
|
| 1682 |
+
)
|
| 1683 |
+
cache_seqlens = maybe_contiguous(cache_seqlens)
|
| 1684 |
+
cache_batch_idx = maybe_contiguous(cache_batch_idx)
|
| 1685 |
+
block_table = maybe_contiguous(block_table)
|
| 1686 |
+
out, softmax_lse = flash_attn.fwd_kvcache(
|
| 1687 |
+
q,
|
| 1688 |
+
k_cache,
|
| 1689 |
+
v_cache,
|
| 1690 |
+
k,
|
| 1691 |
+
v,
|
| 1692 |
+
cache_seqlens,
|
| 1693 |
+
rotary_cos,
|
| 1694 |
+
rotary_sin,
|
| 1695 |
+
cache_batch_idx,
|
| 1696 |
+
cache_leftpad,
|
| 1697 |
+
block_table,
|
| 1698 |
+
alibi_slopes,
|
| 1699 |
+
None,
|
| 1700 |
+
softmax_scale,
|
| 1701 |
+
causal,
|
| 1702 |
+
window_size[0],
|
| 1703 |
+
window_size[1],
|
| 1704 |
+
softcap,
|
| 1705 |
+
rotary_interleaved,
|
| 1706 |
+
num_splits,
|
| 1707 |
+
)
|
| 1708 |
+
return (out, softmax_lse) if return_softmax_lse else out
|
build/torch-stable-abi210-cu134-aarch64-linux/metadata.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "flash-attn2",
|
| 3 |
+
"id": "_flash_attn2_cuda_460047c",
|
| 4 |
+
"version": 4,
|
| 5 |
+
"kernels-minver": "0.14.0",
|
| 6 |
+
"license": "BSD-3-Clause",
|
| 7 |
+
"python-depends": [],
|
| 8 |
+
"kernel-depends": [],
|
| 9 |
+
"backend": {
|
| 10 |
+
"type": "cuda",
|
| 11 |
+
"archs": [
|
| 12 |
+
"10.0",
|
| 13 |
+
"12.0",
|
| 14 |
+
"8.0",
|
| 15 |
+
"9.0"
|
| 16 |
+
]
|
| 17 |
+
},
|
| 18 |
+
"digest": {
|
| 19 |
+
"algorithm": "sha256",
|
| 20 |
+
"files": {
|
| 21 |
+
"__init__.py": "Nz8hqrusjoUHQqszpxfF2USMwUXn1VfpvcmtAAvutSM=",
|
| 22 |
+
"_flash_attn2_cuda_460047c.abi3.so": "kjvVCXGj2U9FuaX6vCIjp/3KHUDYzP9ISJB+uFDpm0w=",
|
| 23 |
+
"_ops.py": "DV4Eo4+s3aaNmDsfXoZiYKNLnRUJqlsdDGlMsdKFgk4=",
|
| 24 |
+
"flash_attn_interface.py": "6UYUhfUax4+yOUygyS7K8dVjrIjU5GQr1AJ2gSp8rPo=",
|
| 25 |
+
"symbols.json": "uvC+87tHUhtHv7L/Nl53T/Ms7ceX317/jwQBoqHY14A="
|
| 26 |
+
}
|
| 27 |
+
},
|
| 28 |
+
"provenance": {
|
| 29 |
+
"kernel-builder": {
|
| 30 |
+
"version": "0.18.0-dev0",
|
| 31 |
+
"commit": "d054906a13710b811b96697b4635f03020842733",
|
| 32 |
+
"dirty": false
|
| 33 |
+
},
|
| 34 |
+
"kernel": {
|
| 35 |
+
"commit": "460047c291fc7f0b3dbd4239b46bd5e1281b1806",
|
| 36 |
+
"dirty": false
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
}
|
build/torch-stable-abi210-cu134-aarch64-linux/metadata.json.sigstore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"mediaType":"application/vnd.dev.sigstore.bundle.v0.3+json","verificationMaterial":{"certificate":{"rawBytes":"MIIHLDCCBrKgAwIBAgIUfIlqLNu6UdXYN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8p7o4AAAGhazxDoAAABAMARzBFAiAwLD/CeVrpcA2C2j58s920o2EJYCRTjPvcMRrbsTS6RwIhAPfV39SmThkryIVjNRuewtpScIsCH/2NACYy+FMTtc+GMAoGCCqGSM49BAMDA2gAMGUCMGv48brzSXkUdf5w2ftOJMGQQiZhmnV1/BvuBvoSNKxmjnCwI50V0ijkF5zcDNcD/QIxANLbDO4W25uC2/31J9S8JTlIx+8apDRx5Gide5gHyzLSgV1lj4/1jM5pN2u+aoI2Gg=="},"tlogEntries":[{"logIndex":"3430233537","logId":{"keyId":"wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="},"kindVersion":{"kind":"hashedrekord","version":"0.0.1"},"integratedTime":"1792800474","inclusionPromise":{"signedEntryTimestamp":"MEQCIGf4qRksR2TOvKJqv5C3OXL9KCWq4DohDNE5OiRqroDSAiBZ/na5GYKHZMVmMM/RBb1tA3aWMI0vOAvXzqPbefcYcQ=="},"inclusionProof":{"logIndex":"3308329275","rootHash":"gvJkaoo5K4nnBj5tgxAdNtAsuOVBE3dwxp4HnZkfvek=","treeSize":"3308329751","hashes":["A6lD2MPXJCkNJ03unZasE28kCBO4cEhrMfr35263otA=","2juSPfQ+oiHAxdHnLkvjhIT+ZK12WdDckwwg3N92P7A=","LifhnEL2YNR6i6SL1PtcvHuNSG8cMuLHlq/xkxrLIl8=","bsl+fw0R4ouIsjrASTpknFPjkE8rV44VNY9PzMjKZXY=","7m7Os3c6xSIltD1PYdtmZWTvYcp/y98WcmkA5VHZLMc=","NrwiN5u5p9JLACtCux17Ga5le7OR7KG91Swm1vKzN4I=","B+n7TQ5+p34ZRpHoH7r7iRTI8eA90txEiNvVk/XQGlo=","ornPIqk+dhfmtF5rp9z75eQBaUggI9Zd0Yoov3BG4Zw=","0YVZixFviDG94SVGteh82jVzdNtBsMQZbb6BiHiUA30=","2Vc45+NdnNK2xlrvQ9A2rn3JmookZpsttqolVggzpFM=","eIbVG1biupwReGylDyasAnDJDAjvcA3MN0/o/j5H/Vg=","gdS39fsn5MOVlKluUgGY2sdKF3H5oauxkHMa7DSSNcg=","8x0N/oAmvpY+6DQUGTU+i6a1Cuqphro2WbV5WZ/RHL8=","DMchGrSAeKV9qHo75XJV3UFZ/CHF8zofPRu+NgVRwA4=","V6dXjeDcwYxBG/9gVSBM8rYdPrAqGpZsf1e7v6l67GA=","iDfImp65w8dirRfYGNgFA34JTUYDWbcJwNBBU/Ok+X4=","YYCr61A8azar3dfO8Ct+pri7LqDxkUlUkfs7fiqYErU=","1DaDKzrCNNBhmSdY5vFjz+NpAmxmYfYEgBCdPLrMP1A=","xH/DCseLHr9eKoYT8qsORZK7zVdEGYWHuVtsVrD95wY="],"checkpoint":{"envelope":"rekor.sigstore.dev - 1193050959916656506\n3308329751\ngvJkaoo5K4nnBj5tgxAdNtAsuOVBE3dwxp4HnZkfvek=\n\n— rekor.sigstore.dev wNI9ajBEAiA7HK7JgdGaQLRpTJ61zoG8UJzLcQbCNxmOd2H6oBto3QIgPoF4fB3lpbTOp7T38nRRszHe0SI4Tet8YnGxCwxSXWI=\n"}},"canonicalizedBody":"eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoiaGFzaGVkcmVrb3JkIiwic3BlYyI6eyJkYXRhIjp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiIyNTI4NjhhNGQyOGI4NzZlYzYyZjMxNmUzMWRkYTA5ZDQ5ZTlmNDYxYWQwNTk1MzlmNTc2YjJkYjJlZTE1YWMxIn19LCJzaWduYXR1cmUiOnsiY29udGVudCI6Ik1FWUNJUURsaktTUFVEQWtlYU9TMzFTTlFSMWt6amhrMGpwaVgvQy95bENaRS9zVW5nSWhBTHo4SEFwalYyM0E5ei9uRHZZNFRGdWZ6K2YvalBobkZJZkozNnRaRS9TTiIsInB1YmxpY0tleSI6eyJjb250ZW50IjoiTFMwdExTMUNSVWRKVGlCRFJWSlVTVVpKUTBGVVJTMHRMUzB0Q2sx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GHuvMFDL8uKjosqI4sMMAoGCCqGSM49BAMCBGgwZgIxAOfOfD0hEGMls7xwJHci7OLQt6Qvku2I1Nb2833ad+2sRiZplkmYRU975nVt0EqtBwIxAInS0x2jMo+2BSef7XYiRS+na+f//QqAjBUE3FBJqXjdgCv8yOVhN0+f26chU1s4og=="}]}},"messageSignature":{"messageDigest":{"algorithm":"SHA2_256","digest":"JShopNKLh27GLzFuMd2gnUnp9GGtBZU59Xay2y7hWsE="},"signature":"MEYCIQDljKSPUDAkeaOS31SNQR1kzjhk0jpiX/C/ylCZE/sUngIhALz8HApjV23A9z/nDvY4TFufz+f/jPhnFIfJ36tZE/SN"}}
|
build/torch-stable-abi210-cu134-aarch64-linux/symbols.json
ADDED
|
@@ -0,0 +1,1273 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 9 |
+
"kind": "function",
|
| 10 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (batch_size, seqlen, nheads, headdim)\n k: (batch_size, seqlen, nheads_k, headdim)\n v: (batch_size, seqlen, nheads_k, headdim)\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 11 |
+
"signature": {
|
| 12 |
+
"parameters": [
|
| 13 |
+
{
|
| 14 |
+
"name": "q",
|
| 15 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 16 |
+
"default": null,
|
| 17 |
+
"annotation": null
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"name": "k",
|
| 21 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 22 |
+
"default": null,
|
| 23 |
+
"annotation": null
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"name": "v",
|
| 27 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 28 |
+
"default": null,
|
| 29 |
+
"annotation": null
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"name": "dropout_p",
|
| 33 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 34 |
+
"default": "0.0",
|
| 35 |
+
"annotation": null
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"name": "softmax_scale",
|
| 39 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 40 |
+
"default": "None",
|
| 41 |
+
"annotation": null
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"name": "causal",
|
| 45 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 46 |
+
"default": "False",
|
| 47 |
+
"annotation": null
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"name": "window_size",
|
| 51 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 52 |
+
"default": "(-1, -1)",
|
| 53 |
+
"annotation": null
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"name": "softcap",
|
| 57 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 58 |
+
"default": "0.0",
|
| 59 |
+
"annotation": null
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"name": "alibi_slopes",
|
| 63 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 64 |
+
"default": "None",
|
| 65 |
+
"annotation": null
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"name": "deterministic",
|
| 69 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 70 |
+
"default": "False",
|
| 71 |
+
"annotation": null
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"name": "return_attn_probs",
|
| 75 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 76 |
+
"default": "False",
|
| 77 |
+
"annotation": null
|
| 78 |
+
}
|
| 79 |
+
],
|
| 80 |
+
"return_annotation": null
|
| 81 |
+
}
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
"name": "flash_attn_kvpacked_func",
|
| 85 |
+
"qualname": "flash_attn_kvpacked_func",
|
| 86 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 87 |
+
"kind": "function",
|
| 88 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of K, V.\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (batch_size, seqlen, nheads, headdim)\n kv: (batch_size, seqlen, 2, nheads_k, headdim)\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 89 |
+
"signature": {
|
| 90 |
+
"parameters": [
|
| 91 |
+
{
|
| 92 |
+
"name": "q",
|
| 93 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 94 |
+
"default": null,
|
| 95 |
+
"annotation": null
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"name": "kv",
|
| 99 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 100 |
+
"default": null,
|
| 101 |
+
"annotation": null
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"name": "dropout_p",
|
| 105 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 106 |
+
"default": "0.0",
|
| 107 |
+
"annotation": null
|
| 108 |
+
},
|
| 109 |
+
{
|
| 110 |
+
"name": "softmax_scale",
|
| 111 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 112 |
+
"default": "None",
|
| 113 |
+
"annotation": null
|
| 114 |
+
},
|
| 115 |
+
{
|
| 116 |
+
"name": "causal",
|
| 117 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 118 |
+
"default": "False",
|
| 119 |
+
"annotation": null
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"name": "window_size",
|
| 123 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 124 |
+
"default": "(-1, -1)",
|
| 125 |
+
"annotation": null
|
| 126 |
+
},
|
| 127 |
+
{
|
| 128 |
+
"name": "softcap",
|
| 129 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 130 |
+
"default": "0.0",
|
| 131 |
+
"annotation": null
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
"name": "alibi_slopes",
|
| 135 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 136 |
+
"default": "None",
|
| 137 |
+
"annotation": null
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"name": "deterministic",
|
| 141 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 142 |
+
"default": "False",
|
| 143 |
+
"annotation": null
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"name": "return_attn_probs",
|
| 147 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 148 |
+
"default": "False",
|
| 149 |
+
"annotation": null
|
| 150 |
+
}
|
| 151 |
+
],
|
| 152 |
+
"return_annotation": null
|
| 153 |
+
}
|
| 154 |
+
},
|
| 155 |
+
{
|
| 156 |
+
"name": "flash_attn_qkvpacked_func",
|
| 157 |
+
"qualname": "flash_attn_qkvpacked_func",
|
| 158 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 159 |
+
"kind": "function",
|
| 160 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf Q, K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of Q, K, V.\nFor multi-query and grouped-query attention (MQA/GQA), please see\nflash_attn_kvpacked_func and flash_attn_func.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.\n\nArguments:\n qkv: (batch_size, seqlen, 3, nheads, headdim)\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|) is added to\n the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 161 |
+
"signature": {
|
| 162 |
+
"parameters": [
|
| 163 |
+
{
|
| 164 |
+
"name": "qkv",
|
| 165 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 166 |
+
"default": null,
|
| 167 |
+
"annotation": null
|
| 168 |
+
},
|
| 169 |
+
{
|
| 170 |
+
"name": "dropout_p",
|
| 171 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 172 |
+
"default": "0.0",
|
| 173 |
+
"annotation": null
|
| 174 |
+
},
|
| 175 |
+
{
|
| 176 |
+
"name": "softmax_scale",
|
| 177 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 178 |
+
"default": "None",
|
| 179 |
+
"annotation": null
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
"name": "causal",
|
| 183 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 184 |
+
"default": "False",
|
| 185 |
+
"annotation": null
|
| 186 |
+
},
|
| 187 |
+
{
|
| 188 |
+
"name": "window_size",
|
| 189 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 190 |
+
"default": "(-1, -1)",
|
| 191 |
+
"annotation": null
|
| 192 |
+
},
|
| 193 |
+
{
|
| 194 |
+
"name": "softcap",
|
| 195 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 196 |
+
"default": "0.0",
|
| 197 |
+
"annotation": null
|
| 198 |
+
},
|
| 199 |
+
{
|
| 200 |
+
"name": "alibi_slopes",
|
| 201 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 202 |
+
"default": "None",
|
| 203 |
+
"annotation": null
|
| 204 |
+
},
|
| 205 |
+
{
|
| 206 |
+
"name": "deterministic",
|
| 207 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 208 |
+
"default": "False",
|
| 209 |
+
"annotation": null
|
| 210 |
+
},
|
| 211 |
+
{
|
| 212 |
+
"name": "return_attn_probs",
|
| 213 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 214 |
+
"default": "False",
|
| 215 |
+
"annotation": null
|
| 216 |
+
}
|
| 217 |
+
],
|
| 218 |
+
"return_annotation": null
|
| 219 |
+
}
|
| 220 |
+
},
|
| 221 |
+
{
|
| 222 |
+
"name": "flash_attn_varlen_func",
|
| 223 |
+
"qualname": "flash_attn_varlen_func",
|
| 224 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 225 |
+
"kind": "function",
|
| 226 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in K, V with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.\n k: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.\n v: (total_k, nheads_k, headdim), where total_k = total number of key tokens in the batch.\n cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into q.\n cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into kv.\n max_seqlen_q: int. Maximum query sequence length in the batch.\n max_seqlen_k: int. Maximum key sequence length in the batch.\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (total, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 227 |
+
"signature": {
|
| 228 |
+
"parameters": [
|
| 229 |
+
{
|
| 230 |
+
"name": "q",
|
| 231 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 232 |
+
"default": null,
|
| 233 |
+
"annotation": null
|
| 234 |
+
},
|
| 235 |
+
{
|
| 236 |
+
"name": "k",
|
| 237 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 238 |
+
"default": null,
|
| 239 |
+
"annotation": null
|
| 240 |
+
},
|
| 241 |
+
{
|
| 242 |
+
"name": "v",
|
| 243 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 244 |
+
"default": null,
|
| 245 |
+
"annotation": null
|
| 246 |
+
},
|
| 247 |
+
{
|
| 248 |
+
"name": "cu_seqlens_q",
|
| 249 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 250 |
+
"default": null,
|
| 251 |
+
"annotation": null
|
| 252 |
+
},
|
| 253 |
+
{
|
| 254 |
+
"name": "cu_seqlens_k",
|
| 255 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 256 |
+
"default": null,
|
| 257 |
+
"annotation": null
|
| 258 |
+
},
|
| 259 |
+
{
|
| 260 |
+
"name": "max_seqlen_q",
|
| 261 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 262 |
+
"default": null,
|
| 263 |
+
"annotation": null
|
| 264 |
+
},
|
| 265 |
+
{
|
| 266 |
+
"name": "max_seqlen_k",
|
| 267 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 268 |
+
"default": null,
|
| 269 |
+
"annotation": null
|
| 270 |
+
},
|
| 271 |
+
{
|
| 272 |
+
"name": "dropout_p",
|
| 273 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 274 |
+
"default": "0.0",
|
| 275 |
+
"annotation": null
|
| 276 |
+
},
|
| 277 |
+
{
|
| 278 |
+
"name": "softmax_scale",
|
| 279 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 280 |
+
"default": "None",
|
| 281 |
+
"annotation": null
|
| 282 |
+
},
|
| 283 |
+
{
|
| 284 |
+
"name": "causal",
|
| 285 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 286 |
+
"default": "False",
|
| 287 |
+
"annotation": null
|
| 288 |
+
},
|
| 289 |
+
{
|
| 290 |
+
"name": "window_size",
|
| 291 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 292 |
+
"default": "(-1, -1)",
|
| 293 |
+
"annotation": null
|
| 294 |
+
},
|
| 295 |
+
{
|
| 296 |
+
"name": "softcap",
|
| 297 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 298 |
+
"default": "0.0",
|
| 299 |
+
"annotation": null
|
| 300 |
+
},
|
| 301 |
+
{
|
| 302 |
+
"name": "alibi_slopes",
|
| 303 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 304 |
+
"default": "None",
|
| 305 |
+
"annotation": null
|
| 306 |
+
},
|
| 307 |
+
{
|
| 308 |
+
"name": "deterministic",
|
| 309 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 310 |
+
"default": "False",
|
| 311 |
+
"annotation": null
|
| 312 |
+
},
|
| 313 |
+
{
|
| 314 |
+
"name": "return_attn_probs",
|
| 315 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 316 |
+
"default": "False",
|
| 317 |
+
"annotation": null
|
| 318 |
+
},
|
| 319 |
+
{
|
| 320 |
+
"name": "block_table",
|
| 321 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 322 |
+
"default": "None",
|
| 323 |
+
"annotation": null
|
| 324 |
+
}
|
| 325 |
+
],
|
| 326 |
+
"return_annotation": null
|
| 327 |
+
}
|
| 328 |
+
},
|
| 329 |
+
{
|
| 330 |
+
"name": "flash_attn_varlen_kvpacked_func",
|
| 331 |
+
"qualname": "flash_attn_varlen_kvpacked_func",
|
| 332 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 333 |
+
"kind": "function",
|
| 334 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of K, V.\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nArguments:\n q: (total_q, nheads, headdim), where total_q = total number of query tokens in the batch.\n kv: (total_k, 2, nheads_k, headdim), where total_k = total number of key tokens in the batch.\n cu_seqlens_q: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into q.\n cu_seqlens_k: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into kv.\n max_seqlen_q: int. Maximum query sequence length in the batch.\n max_seqlen_k: int. Maximum key sequence length in the batch.\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (total, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 335 |
+
"signature": {
|
| 336 |
+
"parameters": [
|
| 337 |
+
{
|
| 338 |
+
"name": "q",
|
| 339 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 340 |
+
"default": null,
|
| 341 |
+
"annotation": null
|
| 342 |
+
},
|
| 343 |
+
{
|
| 344 |
+
"name": "kv",
|
| 345 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 346 |
+
"default": null,
|
| 347 |
+
"annotation": null
|
| 348 |
+
},
|
| 349 |
+
{
|
| 350 |
+
"name": "cu_seqlens_q",
|
| 351 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 352 |
+
"default": null,
|
| 353 |
+
"annotation": null
|
| 354 |
+
},
|
| 355 |
+
{
|
| 356 |
+
"name": "cu_seqlens_k",
|
| 357 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 358 |
+
"default": null,
|
| 359 |
+
"annotation": null
|
| 360 |
+
},
|
| 361 |
+
{
|
| 362 |
+
"name": "max_seqlen_q",
|
| 363 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 364 |
+
"default": null,
|
| 365 |
+
"annotation": null
|
| 366 |
+
},
|
| 367 |
+
{
|
| 368 |
+
"name": "max_seqlen_k",
|
| 369 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 370 |
+
"default": null,
|
| 371 |
+
"annotation": null
|
| 372 |
+
},
|
| 373 |
+
{
|
| 374 |
+
"name": "dropout_p",
|
| 375 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 376 |
+
"default": "0.0",
|
| 377 |
+
"annotation": null
|
| 378 |
+
},
|
| 379 |
+
{
|
| 380 |
+
"name": "softmax_scale",
|
| 381 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 382 |
+
"default": "None",
|
| 383 |
+
"annotation": null
|
| 384 |
+
},
|
| 385 |
+
{
|
| 386 |
+
"name": "causal",
|
| 387 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 388 |
+
"default": "False",
|
| 389 |
+
"annotation": null
|
| 390 |
+
},
|
| 391 |
+
{
|
| 392 |
+
"name": "window_size",
|
| 393 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 394 |
+
"default": "(-1, -1)",
|
| 395 |
+
"annotation": null
|
| 396 |
+
},
|
| 397 |
+
{
|
| 398 |
+
"name": "softcap",
|
| 399 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 400 |
+
"default": "0.0",
|
| 401 |
+
"annotation": null
|
| 402 |
+
},
|
| 403 |
+
{
|
| 404 |
+
"name": "alibi_slopes",
|
| 405 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 406 |
+
"default": "None",
|
| 407 |
+
"annotation": null
|
| 408 |
+
},
|
| 409 |
+
{
|
| 410 |
+
"name": "deterministic",
|
| 411 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 412 |
+
"default": "False",
|
| 413 |
+
"annotation": null
|
| 414 |
+
},
|
| 415 |
+
{
|
| 416 |
+
"name": "return_attn_probs",
|
| 417 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 418 |
+
"default": "False",
|
| 419 |
+
"annotation": null
|
| 420 |
+
}
|
| 421 |
+
],
|
| 422 |
+
"return_annotation": null
|
| 423 |
+
}
|
| 424 |
+
},
|
| 425 |
+
{
|
| 426 |
+
"name": "flash_attn_varlen_qkvpacked_func",
|
| 427 |
+
"qualname": "flash_attn_varlen_qkvpacked_func",
|
| 428 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 429 |
+
"kind": "function",
|
| 430 |
+
"doc": "dropout_p should be set to 0.0 during evaluation\nIf Q, K, V are already stacked into 1 tensor, this function will be faster than\ncalling flash_attn_varlen_func on Q, K, V since the backward pass avoids explicit concatenation\nof the gradients of Q, K, V.\nFor multi-query and grouped-query attention (MQA/GQA), please see\nflash_attn_varlen_kvpacked_func and flash_attn_varlen_func.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between [i - window_size[0], i + window_size[1]] inclusive.\n\nArguments:\n qkv: (total, 3, nheads, headdim), where total = total number of tokens in the batch.\n cu_seqlens: (batch_size + 1,), dtype torch.int32. The cumulative sequence lengths\n of the sequences in the batch, used to index into qkv.\n max_seqlen: int. Maximum sequence length in the batch.\n dropout_p: float. Dropout probability.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of (-alibi_slope * |i - j|)\n is added to the attention score of query i and key j.\n deterministic: bool. Whether to use the deterministic implementation of the backward pass,\n which is slightly slower and uses more memory. The forward pass is always deterministic.\n return_attn_probs: bool. Whether to return the attention probabilities. This option is for\n testing only. The returned probabilities are not guaranteed to be correct\n (they might not have the right scaling).\nReturn:\n out: (total, nheads, headdim).\n softmax_lse [optional, if return_attn_probs=True]: (nheads, total_q_seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).\n S_dmask [optional, if return_attn_probs=True]: (batch_size, nheads, seqlen, seqlen).\n The output of softmax (possibly with different scaling). It also encodes the dropout\n pattern (negative means that location was dropped, nonnegative means it was kept).",
|
| 431 |
+
"signature": {
|
| 432 |
+
"parameters": [
|
| 433 |
+
{
|
| 434 |
+
"name": "qkv",
|
| 435 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 436 |
+
"default": null,
|
| 437 |
+
"annotation": null
|
| 438 |
+
},
|
| 439 |
+
{
|
| 440 |
+
"name": "cu_seqlens",
|
| 441 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 442 |
+
"default": null,
|
| 443 |
+
"annotation": null
|
| 444 |
+
},
|
| 445 |
+
{
|
| 446 |
+
"name": "max_seqlen",
|
| 447 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 448 |
+
"default": null,
|
| 449 |
+
"annotation": null
|
| 450 |
+
},
|
| 451 |
+
{
|
| 452 |
+
"name": "dropout_p",
|
| 453 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 454 |
+
"default": "0.0",
|
| 455 |
+
"annotation": null
|
| 456 |
+
},
|
| 457 |
+
{
|
| 458 |
+
"name": "softmax_scale",
|
| 459 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 460 |
+
"default": "None",
|
| 461 |
+
"annotation": null
|
| 462 |
+
},
|
| 463 |
+
{
|
| 464 |
+
"name": "causal",
|
| 465 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 466 |
+
"default": "False",
|
| 467 |
+
"annotation": null
|
| 468 |
+
},
|
| 469 |
+
{
|
| 470 |
+
"name": "window_size",
|
| 471 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 472 |
+
"default": "(-1, -1)",
|
| 473 |
+
"annotation": null
|
| 474 |
+
},
|
| 475 |
+
{
|
| 476 |
+
"name": "softcap",
|
| 477 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 478 |
+
"default": "0.0",
|
| 479 |
+
"annotation": null
|
| 480 |
+
},
|
| 481 |
+
{
|
| 482 |
+
"name": "alibi_slopes",
|
| 483 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 484 |
+
"default": "None",
|
| 485 |
+
"annotation": null
|
| 486 |
+
},
|
| 487 |
+
{
|
| 488 |
+
"name": "deterministic",
|
| 489 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 490 |
+
"default": "False",
|
| 491 |
+
"annotation": null
|
| 492 |
+
},
|
| 493 |
+
{
|
| 494 |
+
"name": "return_attn_probs",
|
| 495 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 496 |
+
"default": "False",
|
| 497 |
+
"annotation": null
|
| 498 |
+
}
|
| 499 |
+
],
|
| 500 |
+
"return_annotation": null
|
| 501 |
+
}
|
| 502 |
+
},
|
| 503 |
+
{
|
| 504 |
+
"name": "flash_attn_with_kvcache",
|
| 505 |
+
"qualname": "flash_attn_with_kvcache",
|
| 506 |
+
"module": "_flash_attn2_cuda_460047c.flash_attn_interface",
|
| 507 |
+
"kind": "function",
|
| 508 |
+
"doc": "If k and v are not None, k_cache and v_cache will be updated *inplace* with the new values from\nk and v. This is useful for incremental decoding: you can pass in the cached keys/values from\nthe previous step, and update them with the new keys/values from the current step, and do\nattention with the updated cache, all in 1 kernel.\n\nIf you pass in k / v, you must make sure that the cache is large enough to hold the new values.\nFor example, the KV cache could be pre-allocated with the max sequence length, and you can use\ncache_seqlens to keep track of the current sequence lengths of each sequence in the batch.\n\nAlso apply rotary embedding if rotary_cos and rotary_sin are passed in. The key @k will be\nrotated by rotary_cos and rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.\nIf causal or local (i.e., window_size != (-1, -1)), the query @q will be rotated by rotary_cos\nand rotary_sin at indices cache_seqlens, cache_seqlens + 1, etc.\nIf not causal and not local, the query @q will be rotated by rotary_cos and rotary_sin at\nindices cache_seqlens only (i.e. we consider all tokens in @q to be at position cache_seqlens).\n\nSee tests/test_flash_attn.py::test_flash_attn_kvcache for examples of how to use this function.\n\nSupports multi-query and grouped-query attention (MQA/GQA) by passing in KV with fewer heads\nthan Q. Note that the number of heads in Q must be divisible by the number of heads in KV.\nFor example, if Q has 6 heads and K, V have 2 heads, head 0, 1, 2 of Q will attention to head\n0 of K, V, and head 3, 4, 5 of Q will attention to head 1 of K, V.\n\nIf causal=True, the causal mask is aligned to the bottom right corner of the attention matrix.\nFor example, if seqlen_q = 2 and seqlen_k = 5, the causal mask (1 = keep, 0 = masked out) is:\n 1 1 1 1 0\n 1 1 1 1 1\nIf seqlen_q = 5 and seqlen_k = 2, the causal mask is:\n 0 0\n 0 0\n 0 0\n 1 0\n 1 1\nIf the row of the mask is all zero, the output will be zero.\n\nIf window_size != (-1, -1), implements sliding window local attention. Query at position i\nwill only attend to keys between\n[i + seqlen_k - seqlen_q - window_size[0], i + seqlen_k - seqlen_q + window_size[1]] inclusive.\n\nNote: Does not support backward pass.\n\nArguments:\n q: (batch_size, seqlen, nheads, headdim)\n k_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,\n or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)\n page_block_size must be a multiple of 256.\n v_cache: (batch_size_cache, seqlen_cache, nheads_k, headdim) if there's no block_table,\n or (num_blocks, page_block_size, nheads_k, headdim) if there's a block_table (i.e. paged KV cache)\n k [optional]: (batch_size, seqlen_new, nheads_k, headdim). If not None, we concatenate\n k with k_cache, starting at the indices specified by cache_seqlens.\n v [optional]: (batch_size, seqlen_new, nheads_k, headdim). Similar to k.\n rotary_cos [optional]: (seqlen_ro, rotary_dim / 2). If not None, we apply rotary embedding\n to k and q. Only applicable if k and v are passed in. rotary_dim must be divisible by 16.\n rotary_sin [optional]: (seqlen_ro, rotary_dim / 2). Similar to rotary_cos.\n cache_seqlens: int, or (batch_size,), dtype torch.int32. The sequence lengths of the\n KV cache.\n cache_batch_idx: (batch_size,), dtype torch.int32. The indices used to index into the KV cache.\n If None, we assume that the batch indices are [0, 1, 2, ..., batch_size - 1].\n If the indices are not distinct, and k and v are provided, the values updated in the cache\n might come from any of the duplicate indices.\n cache_leftpad: (batch_size,), dtype torch.int32. The index that the KV cache starts. If None, assume 0.\n block_table [optional]: (batch_size, max_num_blocks_per_seq), dtype torch.int32.\n softmax_scale: float. The scaling of QK^T before applying softmax.\n Default to 1 / sqrt(headdim).\n causal: bool. Whether to apply causal attention mask (e.g., for auto-regressive modeling).\n window_size: (left, right). If not (-1, -1), implements sliding window local attention.\n softcap: float. Anything > 0 activates softcapping attention.\n rotary_interleaved: bool. Only applicable if rotary_cos and rotary_sin are passed in.\n If True, rotary embedding will combine dimensions 0 & 1, 2 & 3, etc. If False,\n rotary embedding will combine dimensions 0 & rotary_dim / 2, 1 & rotary_dim / 2 + 1\n (i.e. GPT-NeoX style).\n alibi_slopes: (nheads,) or (batch_size, nheads), fp32. A bias of\n (-alibi_slope * |i + seqlen_k - seqlen_q - j|)\n is added to the attention score of query i and key j.\n num_splits: int. If > 1, split the key/value into this many chunks along the sequence.\n If num_splits == 1, we don't split the key/value. If num_splits == 0, we use a heuristic\n to automatically determine the number of splits.\n Don't change this unless you know what you are doing.\n return_softmax_lse: bool. Whether to return the logsumexp of the attention scores.\n\nReturn:\n out: (batch_size, seqlen, nheads, headdim).\n softmax_lse [optional, if return_softmax_lse=True]: (batch_size, nheads, seqlen). The\n logsumexp of each row of the matrix QK^T * scaling (e.g., log of the softmax\n normalization factor).",
|
| 509 |
+
"signature": {
|
| 510 |
+
"parameters": [
|
| 511 |
+
{
|
| 512 |
+
"name": "q",
|
| 513 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 514 |
+
"default": null,
|
| 515 |
+
"annotation": null
|
| 516 |
+
},
|
| 517 |
+
{
|
| 518 |
+
"name": "k_cache",
|
| 519 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 520 |
+
"default": null,
|
| 521 |
+
"annotation": null
|
| 522 |
+
},
|
| 523 |
+
{
|
| 524 |
+
"name": "v_cache",
|
| 525 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 526 |
+
"default": null,
|
| 527 |
+
"annotation": null
|
| 528 |
+
},
|
| 529 |
+
{
|
| 530 |
+
"name": "k",
|
| 531 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 532 |
+
"default": "None",
|
| 533 |
+
"annotation": null
|
| 534 |
+
},
|
| 535 |
+
{
|
| 536 |
+
"name": "v",
|
| 537 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 538 |
+
"default": "None",
|
| 539 |
+
"annotation": null
|
| 540 |
+
},
|
| 541 |
+
{
|
| 542 |
+
"name": "rotary_cos",
|
| 543 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 544 |
+
"default": "None",
|
| 545 |
+
"annotation": null
|
| 546 |
+
},
|
| 547 |
+
{
|
| 548 |
+
"name": "rotary_sin",
|
| 549 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 550 |
+
"default": "None",
|
| 551 |
+
"annotation": null
|
| 552 |
+
},
|
| 553 |
+
{
|
| 554 |
+
"name": "cache_seqlens",
|
| 555 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 556 |
+
"default": "None",
|
| 557 |
+
"annotation": "int | torch.Tensor | None"
|
| 558 |
+
},
|
| 559 |
+
{
|
| 560 |
+
"name": "cache_batch_idx",
|
| 561 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 562 |
+
"default": "None",
|
| 563 |
+
"annotation": "torch.Tensor | None"
|
| 564 |
+
},
|
| 565 |
+
{
|
| 566 |
+
"name": "cache_leftpad",
|
| 567 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 568 |
+
"default": "None",
|
| 569 |
+
"annotation": "torch.Tensor | None"
|
| 570 |
+
},
|
| 571 |
+
{
|
| 572 |
+
"name": "block_table",
|
| 573 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 574 |
+
"default": "None",
|
| 575 |
+
"annotation": "torch.Tensor | None"
|
| 576 |
+
},
|
| 577 |
+
{
|
| 578 |
+
"name": "softmax_scale",
|
| 579 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 580 |
+
"default": "None",
|
| 581 |
+
"annotation": null
|
| 582 |
+
},
|
| 583 |
+
{
|
| 584 |
+
"name": "causal",
|
| 585 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 586 |
+
"default": "False",
|
| 587 |
+
"annotation": null
|
| 588 |
+
},
|
| 589 |
+
{
|
| 590 |
+
"name": "window_size",
|
| 591 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 592 |
+
"default": "(-1, -1)",
|
| 593 |
+
"annotation": null
|
| 594 |
+
},
|
| 595 |
+
{
|
| 596 |
+
"name": "softcap",
|
| 597 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 598 |
+
"default": "0.0",
|
| 599 |
+
"annotation": null
|
| 600 |
+
},
|
| 601 |
+
{
|
| 602 |
+
"name": "rotary_interleaved",
|
| 603 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 604 |
+
"default": "True",
|
| 605 |
+
"annotation": null
|
| 606 |
+
},
|
| 607 |
+
{
|
| 608 |
+
"name": "alibi_slopes",
|
| 609 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 610 |
+
"default": "None",
|
| 611 |
+
"annotation": null
|
| 612 |
+
},
|
| 613 |
+
{
|
| 614 |
+
"name": "num_splits",
|
| 615 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 616 |
+
"default": "0",
|
| 617 |
+
"annotation": null
|
| 618 |
+
},
|
| 619 |
+
{
|
| 620 |
+
"name": "return_softmax_lse",
|
| 621 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 622 |
+
"default": "False",
|
| 623 |
+
"annotation": null
|
| 624 |
+
}
|
| 625 |
+
],
|
| 626 |
+
"return_annotation": null
|
| 627 |
+
}
|
| 628 |
+
},
|
| 629 |
+
{
|
| 630 |
+
"name": "fwd",
|
| 631 |
+
"qualname": "fwd",
|
| 632 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 633 |
+
"kind": "function",
|
| 634 |
+
"doc": "Forward pass for multi-head attention.\n\nArgs:\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n out: Optional output tensor, same shape as q\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n return_softmax: Whether to return softmax weights\n gen: Optional random number generator\n\nReturns:\n List of tensors: [output, softmax_lse, (softmax if return_softmax)]",
|
| 635 |
+
"signature": {
|
| 636 |
+
"parameters": [
|
| 637 |
+
{
|
| 638 |
+
"name": "q",
|
| 639 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 640 |
+
"default": null,
|
| 641 |
+
"annotation": "torch.Tensor"
|
| 642 |
+
},
|
| 643 |
+
{
|
| 644 |
+
"name": "k",
|
| 645 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 646 |
+
"default": null,
|
| 647 |
+
"annotation": "torch.Tensor"
|
| 648 |
+
},
|
| 649 |
+
{
|
| 650 |
+
"name": "v",
|
| 651 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 652 |
+
"default": null,
|
| 653 |
+
"annotation": "torch.Tensor"
|
| 654 |
+
},
|
| 655 |
+
{
|
| 656 |
+
"name": "out",
|
| 657 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 658 |
+
"default": "None",
|
| 659 |
+
"annotation": "torch.Tensor | None"
|
| 660 |
+
},
|
| 661 |
+
{
|
| 662 |
+
"name": "alibi_slopes",
|
| 663 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 664 |
+
"default": "None",
|
| 665 |
+
"annotation": "torch.Tensor | None"
|
| 666 |
+
},
|
| 667 |
+
{
|
| 668 |
+
"name": "p_dropout",
|
| 669 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 670 |
+
"default": "0.0",
|
| 671 |
+
"annotation": "float"
|
| 672 |
+
},
|
| 673 |
+
{
|
| 674 |
+
"name": "softmax_scale",
|
| 675 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 676 |
+
"default": "None",
|
| 677 |
+
"annotation": "float | None"
|
| 678 |
+
},
|
| 679 |
+
{
|
| 680 |
+
"name": "is_causal",
|
| 681 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 682 |
+
"default": "False",
|
| 683 |
+
"annotation": "bool"
|
| 684 |
+
},
|
| 685 |
+
{
|
| 686 |
+
"name": "window_size_left",
|
| 687 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 688 |
+
"default": "-1",
|
| 689 |
+
"annotation": "int"
|
| 690 |
+
},
|
| 691 |
+
{
|
| 692 |
+
"name": "window_size_right",
|
| 693 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 694 |
+
"default": "-1",
|
| 695 |
+
"annotation": "int"
|
| 696 |
+
},
|
| 697 |
+
{
|
| 698 |
+
"name": "softcap",
|
| 699 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 700 |
+
"default": "0.0",
|
| 701 |
+
"annotation": "float"
|
| 702 |
+
},
|
| 703 |
+
{
|
| 704 |
+
"name": "return_softmax",
|
| 705 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 706 |
+
"default": "False",
|
| 707 |
+
"annotation": "bool"
|
| 708 |
+
},
|
| 709 |
+
{
|
| 710 |
+
"name": "gen",
|
| 711 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 712 |
+
"default": "None",
|
| 713 |
+
"annotation": "torch._C.Generator | None"
|
| 714 |
+
}
|
| 715 |
+
],
|
| 716 |
+
"return_annotation": "List[torch.Tensor]"
|
| 717 |
+
}
|
| 718 |
+
},
|
| 719 |
+
{
|
| 720 |
+
"name": "varlen_fwd",
|
| 721 |
+
"qualname": "varlen_fwd",
|
| 722 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 723 |
+
"kind": "function",
|
| 724 |
+
"doc": "Forward pass for multi-head attention with variable sequence lengths.\n\nArgs:\n q: Query tensor of shape [total_q, num_heads, head_size]\n k: Key tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n v: Value tensor of shape [total_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]\n cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]\n out: Optional output tensor of shape [total_q, num_heads, head_size]\n seqused_k: Optional tensor specifying how many keys to use per batch element [batch_size]\n leftpad_k: Optional left padding for keys of shape [batch_size]\n block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n max_seqlen_q: Maximum sequence length for queries\n max_seqlen_k: Maximum sequence length for keys\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n zero_tensors: Whether to zero tensors before computation\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n return_softmax: Whether to return softmax weights\n gen: Optional random number generator\n\nReturns:\n List of tensors: [output, softmax_lse, (softmax if return_softmax)]",
|
| 725 |
+
"signature": {
|
| 726 |
+
"parameters": [
|
| 727 |
+
{
|
| 728 |
+
"name": "q",
|
| 729 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 730 |
+
"default": null,
|
| 731 |
+
"annotation": "torch.Tensor"
|
| 732 |
+
},
|
| 733 |
+
{
|
| 734 |
+
"name": "k",
|
| 735 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 736 |
+
"default": null,
|
| 737 |
+
"annotation": "torch.Tensor"
|
| 738 |
+
},
|
| 739 |
+
{
|
| 740 |
+
"name": "v",
|
| 741 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 742 |
+
"default": null,
|
| 743 |
+
"annotation": "torch.Tensor"
|
| 744 |
+
},
|
| 745 |
+
{
|
| 746 |
+
"name": "cu_seqlens_q",
|
| 747 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 748 |
+
"default": null,
|
| 749 |
+
"annotation": "torch.Tensor"
|
| 750 |
+
},
|
| 751 |
+
{
|
| 752 |
+
"name": "cu_seqlens_k",
|
| 753 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 754 |
+
"default": null,
|
| 755 |
+
"annotation": "torch.Tensor"
|
| 756 |
+
},
|
| 757 |
+
{
|
| 758 |
+
"name": "out",
|
| 759 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 760 |
+
"default": "None",
|
| 761 |
+
"annotation": "torch.Tensor | None"
|
| 762 |
+
},
|
| 763 |
+
{
|
| 764 |
+
"name": "seqused_k",
|
| 765 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 766 |
+
"default": "None",
|
| 767 |
+
"annotation": "torch.Tensor | None"
|
| 768 |
+
},
|
| 769 |
+
{
|
| 770 |
+
"name": "leftpad_k",
|
| 771 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 772 |
+
"default": "None",
|
| 773 |
+
"annotation": "torch.Tensor | None"
|
| 774 |
+
},
|
| 775 |
+
{
|
| 776 |
+
"name": "block_table",
|
| 777 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 778 |
+
"default": "None",
|
| 779 |
+
"annotation": "torch.Tensor | None"
|
| 780 |
+
},
|
| 781 |
+
{
|
| 782 |
+
"name": "alibi_slopes",
|
| 783 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 784 |
+
"default": "None",
|
| 785 |
+
"annotation": "torch.Tensor | None"
|
| 786 |
+
},
|
| 787 |
+
{
|
| 788 |
+
"name": "max_seqlen_q",
|
| 789 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 790 |
+
"default": "0",
|
| 791 |
+
"annotation": "int"
|
| 792 |
+
},
|
| 793 |
+
{
|
| 794 |
+
"name": "max_seqlen_k",
|
| 795 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 796 |
+
"default": "0",
|
| 797 |
+
"annotation": "int"
|
| 798 |
+
},
|
| 799 |
+
{
|
| 800 |
+
"name": "p_dropout",
|
| 801 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 802 |
+
"default": "0.0",
|
| 803 |
+
"annotation": "float"
|
| 804 |
+
},
|
| 805 |
+
{
|
| 806 |
+
"name": "softmax_scale",
|
| 807 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 808 |
+
"default": "None",
|
| 809 |
+
"annotation": "float | None"
|
| 810 |
+
},
|
| 811 |
+
{
|
| 812 |
+
"name": "zero_tensors",
|
| 813 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 814 |
+
"default": "False",
|
| 815 |
+
"annotation": "bool"
|
| 816 |
+
},
|
| 817 |
+
{
|
| 818 |
+
"name": "is_causal",
|
| 819 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 820 |
+
"default": "False",
|
| 821 |
+
"annotation": "bool"
|
| 822 |
+
},
|
| 823 |
+
{
|
| 824 |
+
"name": "window_size_left",
|
| 825 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 826 |
+
"default": "-1",
|
| 827 |
+
"annotation": "int"
|
| 828 |
+
},
|
| 829 |
+
{
|
| 830 |
+
"name": "window_size_right",
|
| 831 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 832 |
+
"default": "-1",
|
| 833 |
+
"annotation": "int"
|
| 834 |
+
},
|
| 835 |
+
{
|
| 836 |
+
"name": "softcap",
|
| 837 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 838 |
+
"default": "0.0",
|
| 839 |
+
"annotation": "float"
|
| 840 |
+
},
|
| 841 |
+
{
|
| 842 |
+
"name": "return_softmax",
|
| 843 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 844 |
+
"default": "False",
|
| 845 |
+
"annotation": "bool"
|
| 846 |
+
},
|
| 847 |
+
{
|
| 848 |
+
"name": "gen",
|
| 849 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 850 |
+
"default": "None",
|
| 851 |
+
"annotation": "torch._C.Generator | None"
|
| 852 |
+
}
|
| 853 |
+
],
|
| 854 |
+
"return_annotation": "List[torch.Tensor]"
|
| 855 |
+
}
|
| 856 |
+
},
|
| 857 |
+
{
|
| 858 |
+
"name": "bwd",
|
| 859 |
+
"qualname": "bwd",
|
| 860 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 861 |
+
"kind": "function",
|
| 862 |
+
"doc": "Backward pass for multi-head attention.\n\nArgs:\n dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]\n softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]\n dq: Optional gradient tensor for queries, same shape as q\n dk: Optional gradient tensor for keys, same shape as k\n dv: Optional gradient tensor for values, same shape as v\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n deterministic: Whether to use deterministic algorithms\n gen: Optional random number generator\n rng_state: Optional RNG state from forward pass\n\nReturns:\n List of tensors: [dq, dk, dv]",
|
| 863 |
+
"signature": {
|
| 864 |
+
"parameters": [
|
| 865 |
+
{
|
| 866 |
+
"name": "dout",
|
| 867 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 868 |
+
"default": null,
|
| 869 |
+
"annotation": "torch.Tensor"
|
| 870 |
+
},
|
| 871 |
+
{
|
| 872 |
+
"name": "q",
|
| 873 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 874 |
+
"default": null,
|
| 875 |
+
"annotation": "torch.Tensor"
|
| 876 |
+
},
|
| 877 |
+
{
|
| 878 |
+
"name": "k",
|
| 879 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 880 |
+
"default": null,
|
| 881 |
+
"annotation": "torch.Tensor"
|
| 882 |
+
},
|
| 883 |
+
{
|
| 884 |
+
"name": "v",
|
| 885 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 886 |
+
"default": null,
|
| 887 |
+
"annotation": "torch.Tensor"
|
| 888 |
+
},
|
| 889 |
+
{
|
| 890 |
+
"name": "out",
|
| 891 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 892 |
+
"default": null,
|
| 893 |
+
"annotation": "torch.Tensor"
|
| 894 |
+
},
|
| 895 |
+
{
|
| 896 |
+
"name": "softmax_lse",
|
| 897 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 898 |
+
"default": null,
|
| 899 |
+
"annotation": "torch.Tensor"
|
| 900 |
+
},
|
| 901 |
+
{
|
| 902 |
+
"name": "dq",
|
| 903 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 904 |
+
"default": "None",
|
| 905 |
+
"annotation": "torch.Tensor | None"
|
| 906 |
+
},
|
| 907 |
+
{
|
| 908 |
+
"name": "dk",
|
| 909 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 910 |
+
"default": "None",
|
| 911 |
+
"annotation": "torch.Tensor | None"
|
| 912 |
+
},
|
| 913 |
+
{
|
| 914 |
+
"name": "dv",
|
| 915 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 916 |
+
"default": "None",
|
| 917 |
+
"annotation": "torch.Tensor | None"
|
| 918 |
+
},
|
| 919 |
+
{
|
| 920 |
+
"name": "alibi_slopes",
|
| 921 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 922 |
+
"default": "None",
|
| 923 |
+
"annotation": "torch.Tensor | None"
|
| 924 |
+
},
|
| 925 |
+
{
|
| 926 |
+
"name": "p_dropout",
|
| 927 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 928 |
+
"default": "0.0",
|
| 929 |
+
"annotation": "float"
|
| 930 |
+
},
|
| 931 |
+
{
|
| 932 |
+
"name": "softmax_scale",
|
| 933 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 934 |
+
"default": "None",
|
| 935 |
+
"annotation": "float | None"
|
| 936 |
+
},
|
| 937 |
+
{
|
| 938 |
+
"name": "is_causal",
|
| 939 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 940 |
+
"default": "False",
|
| 941 |
+
"annotation": "bool"
|
| 942 |
+
},
|
| 943 |
+
{
|
| 944 |
+
"name": "window_size_left",
|
| 945 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 946 |
+
"default": "-1",
|
| 947 |
+
"annotation": "int"
|
| 948 |
+
},
|
| 949 |
+
{
|
| 950 |
+
"name": "window_size_right",
|
| 951 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 952 |
+
"default": "-1",
|
| 953 |
+
"annotation": "int"
|
| 954 |
+
},
|
| 955 |
+
{
|
| 956 |
+
"name": "softcap",
|
| 957 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 958 |
+
"default": "0.0",
|
| 959 |
+
"annotation": "float"
|
| 960 |
+
},
|
| 961 |
+
{
|
| 962 |
+
"name": "deterministic",
|
| 963 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 964 |
+
"default": "False",
|
| 965 |
+
"annotation": "bool"
|
| 966 |
+
},
|
| 967 |
+
{
|
| 968 |
+
"name": "gen",
|
| 969 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 970 |
+
"default": "None",
|
| 971 |
+
"annotation": "torch._C.Generator | None"
|
| 972 |
+
},
|
| 973 |
+
{
|
| 974 |
+
"name": "rng_state",
|
| 975 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 976 |
+
"default": "None",
|
| 977 |
+
"annotation": "torch.Tensor | None"
|
| 978 |
+
}
|
| 979 |
+
],
|
| 980 |
+
"return_annotation": "List[torch.Tensor]"
|
| 981 |
+
}
|
| 982 |
+
},
|
| 983 |
+
{
|
| 984 |
+
"name": "varlen_bwd",
|
| 985 |
+
"qualname": "varlen_bwd",
|
| 986 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 987 |
+
"kind": "function",
|
| 988 |
+
"doc": "Backward pass for multi-head attention with variable sequence lengths.\n\nArgs:\n dout: Gradient tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n k: Key tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n v: Value tensor of shape [batch_size, seqlen_k, num_heads_k, head_size]\n out: Output tensor from forward pass of shape [batch_size, seqlen_q, num_heads, head_size]\n softmax_lse: Log-sum-exp values from forward pass of shape [batch_size, num_heads, seqlen_q]\n cu_seqlens_q: Cumulative sequence lengths for queries of shape [batch_size+1]\n cu_seqlens_k: Cumulative sequence lengths for keys of shape [batch_size+1]\n dq: Optional gradient tensor for queries, same shape as q\n dk: Optional gradient tensor for keys, same shape as k\n dv: Optional gradient tensor for values, same shape as v\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n max_seqlen_q: Maximum sequence length for queries\n max_seqlen_k: Maximum sequence length for keys\n p_dropout: Dropout probability\n softmax_scale: Scale factor for softmax\n zero_tensors: Whether to zero tensors before computation\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n deterministic: Whether to use deterministic algorithms\n gen: Optional random number generator\n rng_state: Optional RNG state from forward pass\n\nReturns:\n List of tensors: [dq, dk, dv]",
|
| 989 |
+
"signature": {
|
| 990 |
+
"parameters": [
|
| 991 |
+
{
|
| 992 |
+
"name": "dout",
|
| 993 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 994 |
+
"default": null,
|
| 995 |
+
"annotation": "torch.Tensor"
|
| 996 |
+
},
|
| 997 |
+
{
|
| 998 |
+
"name": "q",
|
| 999 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1000 |
+
"default": null,
|
| 1001 |
+
"annotation": "torch.Tensor"
|
| 1002 |
+
},
|
| 1003 |
+
{
|
| 1004 |
+
"name": "k",
|
| 1005 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1006 |
+
"default": null,
|
| 1007 |
+
"annotation": "torch.Tensor"
|
| 1008 |
+
},
|
| 1009 |
+
{
|
| 1010 |
+
"name": "v",
|
| 1011 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1012 |
+
"default": null,
|
| 1013 |
+
"annotation": "torch.Tensor"
|
| 1014 |
+
},
|
| 1015 |
+
{
|
| 1016 |
+
"name": "out",
|
| 1017 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1018 |
+
"default": null,
|
| 1019 |
+
"annotation": "torch.Tensor"
|
| 1020 |
+
},
|
| 1021 |
+
{
|
| 1022 |
+
"name": "softmax_lse",
|
| 1023 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1024 |
+
"default": null,
|
| 1025 |
+
"annotation": "torch.Tensor"
|
| 1026 |
+
},
|
| 1027 |
+
{
|
| 1028 |
+
"name": "cu_seqlens_q",
|
| 1029 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1030 |
+
"default": null,
|
| 1031 |
+
"annotation": "torch.Tensor"
|
| 1032 |
+
},
|
| 1033 |
+
{
|
| 1034 |
+
"name": "cu_seqlens_k",
|
| 1035 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1036 |
+
"default": null,
|
| 1037 |
+
"annotation": "torch.Tensor"
|
| 1038 |
+
},
|
| 1039 |
+
{
|
| 1040 |
+
"name": "dq",
|
| 1041 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1042 |
+
"default": "None",
|
| 1043 |
+
"annotation": "torch.Tensor | None"
|
| 1044 |
+
},
|
| 1045 |
+
{
|
| 1046 |
+
"name": "dk",
|
| 1047 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1048 |
+
"default": "None",
|
| 1049 |
+
"annotation": "torch.Tensor | None"
|
| 1050 |
+
},
|
| 1051 |
+
{
|
| 1052 |
+
"name": "dv",
|
| 1053 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1054 |
+
"default": "None",
|
| 1055 |
+
"annotation": "torch.Tensor | None"
|
| 1056 |
+
},
|
| 1057 |
+
{
|
| 1058 |
+
"name": "alibi_slopes",
|
| 1059 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1060 |
+
"default": "None",
|
| 1061 |
+
"annotation": "torch.Tensor | None"
|
| 1062 |
+
},
|
| 1063 |
+
{
|
| 1064 |
+
"name": "max_seqlen_q",
|
| 1065 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1066 |
+
"default": "0",
|
| 1067 |
+
"annotation": "int"
|
| 1068 |
+
},
|
| 1069 |
+
{
|
| 1070 |
+
"name": "max_seqlen_k",
|
| 1071 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1072 |
+
"default": "0",
|
| 1073 |
+
"annotation": "int"
|
| 1074 |
+
},
|
| 1075 |
+
{
|
| 1076 |
+
"name": "p_dropout",
|
| 1077 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1078 |
+
"default": "0.0",
|
| 1079 |
+
"annotation": "float"
|
| 1080 |
+
},
|
| 1081 |
+
{
|
| 1082 |
+
"name": "softmax_scale",
|
| 1083 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1084 |
+
"default": "None",
|
| 1085 |
+
"annotation": "float | None"
|
| 1086 |
+
},
|
| 1087 |
+
{
|
| 1088 |
+
"name": "zero_tensors",
|
| 1089 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1090 |
+
"default": "False",
|
| 1091 |
+
"annotation": "bool"
|
| 1092 |
+
},
|
| 1093 |
+
{
|
| 1094 |
+
"name": "is_causal",
|
| 1095 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1096 |
+
"default": "False",
|
| 1097 |
+
"annotation": "bool"
|
| 1098 |
+
},
|
| 1099 |
+
{
|
| 1100 |
+
"name": "window_size_left",
|
| 1101 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1102 |
+
"default": "-1",
|
| 1103 |
+
"annotation": "int"
|
| 1104 |
+
},
|
| 1105 |
+
{
|
| 1106 |
+
"name": "window_size_right",
|
| 1107 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1108 |
+
"default": "-1",
|
| 1109 |
+
"annotation": "int"
|
| 1110 |
+
},
|
| 1111 |
+
{
|
| 1112 |
+
"name": "softcap",
|
| 1113 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1114 |
+
"default": "0.0",
|
| 1115 |
+
"annotation": "float"
|
| 1116 |
+
},
|
| 1117 |
+
{
|
| 1118 |
+
"name": "deterministic",
|
| 1119 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1120 |
+
"default": "False",
|
| 1121 |
+
"annotation": "bool"
|
| 1122 |
+
},
|
| 1123 |
+
{
|
| 1124 |
+
"name": "gen",
|
| 1125 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1126 |
+
"default": "None",
|
| 1127 |
+
"annotation": "torch._C.Generator | None"
|
| 1128 |
+
},
|
| 1129 |
+
{
|
| 1130 |
+
"name": "rng_state",
|
| 1131 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1132 |
+
"default": "None",
|
| 1133 |
+
"annotation": "torch.Tensor | None"
|
| 1134 |
+
}
|
| 1135 |
+
],
|
| 1136 |
+
"return_annotation": "List[torch.Tensor]"
|
| 1137 |
+
}
|
| 1138 |
+
},
|
| 1139 |
+
{
|
| 1140 |
+
"name": "fwd_kvcache",
|
| 1141 |
+
"qualname": "fwd_kvcache",
|
| 1142 |
+
"module": "_flash_attn2_cuda_460047c",
|
| 1143 |
+
"kind": "function",
|
| 1144 |
+
"doc": "Forward pass for multi-head attention with KV cache.\n\nArgs:\n q: Query tensor of shape [batch_size, seqlen_q, num_heads, head_size]\n kcache: Key cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n vcache: Value cache tensor of shape [batch_size_c, seqlen_k, num_heads_k, head_size] or [num_blocks, page_block_size, num_heads_k, head_size]\n k: Optional new keys tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]\n v: Optional new values tensor of shape [batch_size, seqlen_knew, num_heads_k, head_size]\n seqlens_k: Optional sequence lengths for keys of shape [batch_size]\n rotary_cos: Optional rotary cosine tensor of shape [seqlen_ro, rotary_dim/2]\n rotary_sin: Optional rotary sine tensor of shape [seqlen_ro, rotary_dim/2]\n cache_batch_idx: Optional indices to index into the KV cache\n leftpad_k: Optional left padding for keys of shape [batch_size]\n block_table: Optional block table of shape [batch_size, max_num_blocks_per_seq]\n alibi_slopes: Optional ALiBi slopes tensor of shape [num_heads] or [batch_size, num_heads]\n out: Optional output tensor, same shape as q\n softmax_scale: Scale factor for softmax\n is_causal: Whether to use causal attention\n window_size_left: Window size for left context (-1 for unlimited)\n window_size_right: Window size for right context (-1 for unlimited)\n softcap: Soft cap for attention weights\n is_rotary_interleaved: Whether rotary embeddings are interleaved\n num_splits: Number of splits for computation\n\nReturns:\n List of tensors: [output, softmax_lse]",
|
| 1145 |
+
"signature": {
|
| 1146 |
+
"parameters": [
|
| 1147 |
+
{
|
| 1148 |
+
"name": "q",
|
| 1149 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1150 |
+
"default": null,
|
| 1151 |
+
"annotation": "torch.Tensor"
|
| 1152 |
+
},
|
| 1153 |
+
{
|
| 1154 |
+
"name": "kcache",
|
| 1155 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1156 |
+
"default": null,
|
| 1157 |
+
"annotation": "torch.Tensor"
|
| 1158 |
+
},
|
| 1159 |
+
{
|
| 1160 |
+
"name": "vcache",
|
| 1161 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1162 |
+
"default": null,
|
| 1163 |
+
"annotation": "torch.Tensor"
|
| 1164 |
+
},
|
| 1165 |
+
{
|
| 1166 |
+
"name": "k",
|
| 1167 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1168 |
+
"default": "None",
|
| 1169 |
+
"annotation": "torch.Tensor | None"
|
| 1170 |
+
},
|
| 1171 |
+
{
|
| 1172 |
+
"name": "v",
|
| 1173 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1174 |
+
"default": "None",
|
| 1175 |
+
"annotation": "torch.Tensor | None"
|
| 1176 |
+
},
|
| 1177 |
+
{
|
| 1178 |
+
"name": "seqlens_k",
|
| 1179 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1180 |
+
"default": "None",
|
| 1181 |
+
"annotation": "torch.Tensor | None"
|
| 1182 |
+
},
|
| 1183 |
+
{
|
| 1184 |
+
"name": "rotary_cos",
|
| 1185 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1186 |
+
"default": "None",
|
| 1187 |
+
"annotation": "torch.Tensor | None"
|
| 1188 |
+
},
|
| 1189 |
+
{
|
| 1190 |
+
"name": "rotary_sin",
|
| 1191 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1192 |
+
"default": "None",
|
| 1193 |
+
"annotation": "torch.Tensor | None"
|
| 1194 |
+
},
|
| 1195 |
+
{
|
| 1196 |
+
"name": "cache_batch_idx",
|
| 1197 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1198 |
+
"default": "None",
|
| 1199 |
+
"annotation": "torch.Tensor | None"
|
| 1200 |
+
},
|
| 1201 |
+
{
|
| 1202 |
+
"name": "leftpad_k",
|
| 1203 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1204 |
+
"default": "None",
|
| 1205 |
+
"annotation": "torch.Tensor | None"
|
| 1206 |
+
},
|
| 1207 |
+
{
|
| 1208 |
+
"name": "block_table",
|
| 1209 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1210 |
+
"default": "None",
|
| 1211 |
+
"annotation": "torch.Tensor | None"
|
| 1212 |
+
},
|
| 1213 |
+
{
|
| 1214 |
+
"name": "alibi_slopes",
|
| 1215 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1216 |
+
"default": "None",
|
| 1217 |
+
"annotation": "torch.Tensor | None"
|
| 1218 |
+
},
|
| 1219 |
+
{
|
| 1220 |
+
"name": "out",
|
| 1221 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1222 |
+
"default": "None",
|
| 1223 |
+
"annotation": "torch.Tensor | None"
|
| 1224 |
+
},
|
| 1225 |
+
{
|
| 1226 |
+
"name": "softmax_scale",
|
| 1227 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1228 |
+
"default": "None",
|
| 1229 |
+
"annotation": "float | None"
|
| 1230 |
+
},
|
| 1231 |
+
{
|
| 1232 |
+
"name": "is_causal",
|
| 1233 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1234 |
+
"default": "False",
|
| 1235 |
+
"annotation": "bool"
|
| 1236 |
+
},
|
| 1237 |
+
{
|
| 1238 |
+
"name": "window_size_left",
|
| 1239 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1240 |
+
"default": "-1",
|
| 1241 |
+
"annotation": "int"
|
| 1242 |
+
},
|
| 1243 |
+
{
|
| 1244 |
+
"name": "window_size_right",
|
| 1245 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1246 |
+
"default": "-1",
|
| 1247 |
+
"annotation": "int"
|
| 1248 |
+
},
|
| 1249 |
+
{
|
| 1250 |
+
"name": "softcap",
|
| 1251 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1252 |
+
"default": "0.0",
|
| 1253 |
+
"annotation": "float"
|
| 1254 |
+
},
|
| 1255 |
+
{
|
| 1256 |
+
"name": "is_rotary_interleaved",
|
| 1257 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1258 |
+
"default": "False",
|
| 1259 |
+
"annotation": "bool"
|
| 1260 |
+
},
|
| 1261 |
+
{
|
| 1262 |
+
"name": "num_splits",
|
| 1263 |
+
"kind": "POSITIONAL_OR_KEYWORD",
|
| 1264 |
+
"default": "1",
|
| 1265 |
+
"annotation": "int"
|
| 1266 |
+
}
|
| 1267 |
+
],
|
| 1268 |
+
"return_annotation": "List[torch.Tensor]"
|
| 1269 |
+
}
|
| 1270 |
+
}
|
| 1271 |
+
],
|
| 1272 |
+
"layers": []
|
| 1273 |
+
}
|