summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorjdj <jdj@kunix.org>2026-10-29 11:33:06 -0700
committerjdj <jdj@kunix.org>2026-10-29 11:33:06 -0700
commit2b43301947bb2b2fd2d8e3b78eb67ff27f5ed769 (patch)
treea4d493ca27d80dc49515b1e8dcb13b3ac93a82cf /tests
parent3d4aa8a382220ceeafc34c0c59af80f565d3a4a8 (diff)
downloadvolta-train-kernels-2b43301947bb2b2fd2d8e3b78eb67ff27f5ed769.tar.gz
volta-train-kernels-2b43301947bb2b2fd2d8e3b78eb67ff27f5ed769.zip
sdpa_stock: optional host-known seqlens, no device sync per call
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/_ref.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/tests/_ref.py b/tests/_ref.py
index 36ddd27..17834fa 100644
--- a/tests/_ref.py
+++ b/tests/_ref.py
@@ -46,10 +46,14 @@ def attention_fp64(q, k, v, offsets):
return out
-def sdpa_stock(q, k, v, offsets):
+def sdpa_stock(q, k, v, offsets, seqlens=None):
"""PyTorch's memory-efficient SDPA over a jagged nested tensor, the only stock
- backend that trains on sm_70. Returns (N, H, D) fp16."""
- nest = [torch.nested.nested_tensor_from_jagged(t, offsets).transpose(1, 2) for t in (q, k, v)]
+ backend that trains on sm_70. Returns (N, H, D) fp16.
+
+ seqlens=(min, max) document length, known on the host, avoids a device sync per
+ call -- as a training loop that knows its packing would do."""
+ kw = {} if seqlens is None else {"min_seqlen": seqlens[0], "max_seqlen": seqlens[1]}
+ nest = [torch.nested.nested_tensor_from_jagged(t, offsets, **kw).transpose(1, 2) for t in (q, k, v)]
with sdpa_kernel(SDPBackend.EFFICIENT_ATTENTION):
o = F.scaled_dot_product_attention(*nest, is_causal=True)
return o.transpose(1, 2).values()