flash_attention_tq4_kv
turboquant_vllm.triton.flash_attention_tq4_kv ¶
Fused TQ4 Flash Attention -- both K and V decompressed in the inner loop.
Phase 3 of the P5 roadmap. Both K and V tiles are decompressed inline
from nibble-packed uint8 indices. The query is pre-rotated by Pi^T
and the output is post-rotated by Pi outside the kernel (since K and
V share the same rotation matrix).
Attributes:
| Name | Type | Description |
|---|---|---|
triton_flash_attention_tq4_kv |
Tensor
|
Python wrapper that pre-rotates Q, launches the fused kernel, and post-rotates the output. |
Examples:
from turboquant_vllm.triton.flash_attention_tq4_kv import (
triton_flash_attention_tq4_kv,
)
out = triton_flash_attention_tq4_kv(
q,
k_packed,
k_norms,
v_packed,
v_norms,
centroids,
rotation,
sm_scale=None,
)
See Also
:mod:turboquant_vllm.triton.flash_attention_tq4: Phase 2 (K-only).
Functions¶
triton_flash_attention_tq4_kv ¶
triton_flash_attention_tq4_kv(
q: Tensor,
k_packed: Tensor,
k_norms: Tensor,
v_packed: Tensor,
v_norms: Tensor,
centroids: Tensor,
rotation: Tensor,
sm_scale: float | None = None,
is_causal: bool = False,
) -> Tensor
Fused TQ4 Flash Attention with both K and V compressed.
Pre-rotates Q by rotation^T, launches the kernel that decompresses
both K and V inline, then post-rotates the output by rotation to
return to the original coordinate space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
Tensor
|
Query |
required |
k_packed
|
Tensor
|
Nibble-packed key indices |
required |
k_norms
|
Tensor
|
Key norms |
required |
v_packed
|
Tensor
|
Nibble-packed value indices |
required |
v_norms
|
Tensor
|
Value norms |
required |
centroids
|
Tensor
|
Shared Lloyd-Max codebook |
required |
rotation
|
Tensor
|
Shared orthogonal rotation |
required |
sm_scale
|
float | None
|
Softmax scale. Defaults to |
None
|
is_causal
|
bool
|
Apply causal masking. |
False
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Attention output |
Source code in src/turboquant_vllm/triton/flash_attention_tq4_kv.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |