diff options
Diffstat (limited to 'tests/_ref.py')
| -rw-r--r-- | tests/_ref.py | 10 |
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() |
