Fix: pass tl dtypes as DTYPE constexpr (triton 3.8 rejects torch.dtype in .to())
Browse files- fa2_repro.py +9 -3
fa2_repro.py
CHANGED
|
@@ -342,6 +342,12 @@ def _attn_bwd_dkdv(Q, K, V, DO, DK, DV, LSE, Delta, sm_scale,
|
|
| 342 |
# PyTorch wrapper (autograd Function)
|
| 343 |
# ---------------------------------------------------------------------------
|
| 344 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
class _attention(torch.autograd.Function):
|
| 346 |
@staticmethod
|
| 347 |
def forward(ctx, q, k, v, causal, sm_scale):
|
|
@@ -368,7 +374,7 @@ class _attention(torch.autograd.Function):
|
|
| 368 |
lse.stride(0), lse.stride(1),
|
| 369 |
H_Q, S,
|
| 370 |
GQA_RATIO=GQA_RATIO, HEAD_DIM=D,
|
| 371 |
-
CAUSAL=causal, STAGE=stage, DTYPE=q.dtype,
|
| 372 |
)
|
| 373 |
ctx.save_for_backward(q, k, v, o, lse)
|
| 374 |
ctx.sm_scale = sm_scale
|
|
@@ -407,7 +413,7 @@ class _attention(torch.autograd.Function):
|
|
| 407 |
H_Q, S,
|
| 408 |
GQA_RATIO=GQA_RATIO, HEAD_DIM=D,
|
| 409 |
BLOCK_M1=BLOCK_M1, BLOCK_N1=BLOCK_N1,
|
| 410 |
-
CAUSAL=ctx.causal, DTYPE=q.dtype,
|
| 411 |
num_warps=4, num_stages=3)
|
| 412 |
|
| 413 |
grid_dq = (S // BLOCK_M2, B, H_Q)
|
|
@@ -421,7 +427,7 @@ class _attention(torch.autograd.Function):
|
|
| 421 |
H_Q, S,
|
| 422 |
GQA_RATIO=GQA_RATIO, HEAD_DIM=D,
|
| 423 |
BLOCK_M2=BLOCK_M2, BLOCK_N2=BLOCK_N2,
|
| 424 |
-
CAUSAL=ctx.causal, DTYPE=q.dtype,
|
| 425 |
num_warps=4, num_stages=3)
|
| 426 |
|
| 427 |
return dq, dk, dv, None, None
|
|
|
|
| 342 |
# PyTorch wrapper (autograd Function)
|
| 343 |
# ---------------------------------------------------------------------------
|
| 344 |
|
| 345 |
+
def _tl_dtype(t):
|
| 346 |
+
"""Triton constexpr dtypes must be tl dtypes, not torch dtypes."""
|
| 347 |
+
assert t in (torch.float16, torch.bfloat16), f"unsupported dtype {t}"
|
| 348 |
+
return tl.float16 if t == torch.float16 else tl.bfloat16
|
| 349 |
+
|
| 350 |
+
|
| 351 |
class _attention(torch.autograd.Function):
|
| 352 |
@staticmethod
|
| 353 |
def forward(ctx, q, k, v, causal, sm_scale):
|
|
|
|
| 374 |
lse.stride(0), lse.stride(1),
|
| 375 |
H_Q, S,
|
| 376 |
GQA_RATIO=GQA_RATIO, HEAD_DIM=D,
|
| 377 |
+
CAUSAL=causal, STAGE=stage, DTYPE=_tl_dtype(q.dtype),
|
| 378 |
)
|
| 379 |
ctx.save_for_backward(q, k, v, o, lse)
|
| 380 |
ctx.sm_scale = sm_scale
|
|
|
|
| 413 |
H_Q, S,
|
| 414 |
GQA_RATIO=GQA_RATIO, HEAD_DIM=D,
|
| 415 |
BLOCK_M1=BLOCK_M1, BLOCK_N1=BLOCK_N1,
|
| 416 |
+
CAUSAL=ctx.causal, DTYPE=_tl_dtype(q.dtype),
|
| 417 |
num_warps=4, num_stages=3)
|
| 418 |
|
| 419 |
grid_dq = (S // BLOCK_M2, B, H_Q)
|
|
|
|
| 427 |
H_Q, S,
|
| 428 |
GQA_RATIO=GQA_RATIO, HEAD_DIM=D,
|
| 429 |
BLOCK_M2=BLOCK_M2, BLOCK_N2=BLOCK_N2,
|
| 430 |
+
CAUSAL=ctx.causal, DTYPE=_tl_dtype(q.dtype),
|
| 431 |
num_warps=4, num_stages=3)
|
| 432 |
|
| 433 |
return dq, dk, dv, None, None
|