You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,9 @@
1
1
## Latest Changes
2
2
## (unreleased)
3
3
4
+
### Added
5
+
-[Torch]`cuet.triangle_attention` accepts `kv_lengths`, an int32 per-row key/value length tensor for right-padded sequence masks. Passing `kv_lengths` selects the Blackwell sm100f length fast path when available; dense `mask` remains the correct fallback path for arbitrary masks. Added `cuet.mask_to_kv_lengths` to convert and validate prefix masks.
capability 10.0 or 10.3), will be cast to match q/k/v dtype (bf16/fp16) for best
69
109
performance.
70
110
mask (torch.Tensor, optional): Mask tensor of shape (B, N, 1, 1, K). For B=1, can also be (N, 1, 1, K).
71
-
Will be cast to bool internally.
111
+
Will be cast to bool internally. Dense masks accept any pattern and route to the
112
+
correct fallback path. For right-padded masks, pass ``kv_lengths`` instead to use
113
+
the Blackwell sm100f length fast path.
72
114
scale (float, optional): Float scale for q (s in the equation). If None, value 1/sqrt(d) is used.
73
115
return_aux (bool): If True, two auxiliary tensors are returned along with the result.
74
116
Defaults to False.
117
+
kv_lengths (torch.Tensor, optional): int32 tensor of shape (B, N, 1, 1, 1)
118
+
containing each row's effective K length. This represents a right-padded /
119
+
prefix mask: positions ``j < kv_lengths[b, n]`` are valid and later positions
120
+
are masked. Pass either ``mask`` or ``kv_lengths``, not both. On supported
121
+
Blackwell cu13 builds, ``kv_lengths`` selects the sm100f length fast path.
75
122
76
123
Note:
77
124
- B: batch size
@@ -90,12 +137,12 @@ def triangle_attention(
90
137
(1) Context is saved for backward pass. You don't need to save it manually.
91
138
(2) Kernel precision (fp32, bf16, fp16) is based on input dtypes. For tf32, set it from torch global scope
92
139
(3) Triangle attention kernel supports: all hidden_dim<=32 and divisible by 4 for tf32/fp32, and for all hidden_dim<=128 and divisible by 8 for bf16/fp16 (standard kernels). On Blackwell GPUs (compute capability 10.0 or 10.3), the sm100f kernel supports hidden_dim<=256 for forward passes and hidden_dim<=128 for backward passes. In the rare instance that the kernel does not support an input config, fallback to torch is enabled instead of erroring out.
93
-
(4) Blackwell-optimized kernels (for compute capabilities 10.0 and 10.3) provide superior performance especially for long sequences and higher head dimensions. These kernels require the sequence length N to be a multiple of 8 for the forward pass; pad the sequence if necessary. The kernel provides optimal performance for a "padding mask" consisting in (all True, followed by all False) in the last dimension. Currently, this feature is supported only for cu13 builds.
140
+
(4) Blackwell-optimized kernels (for compute capabilities 10.0 and 10.3) provide superior performance especially for long sequences and higher head dimensions. These kernels require the key/value sequence length K to be a multiple of 8 for the forward pass; pad the sequence if necessary. Use ``kv_lengths`` for right-padded sequence masks to select the sm100f length fast path. A dense ``mask`` without ``kv_lengths`` remains correct for arbitrary or holey patterns, but it routes to the fallback path.
94
141
95
142
Example:
96
143
>>> import torch
97
144
>>> import math
98
-
>>> from cuequivariance_torch import triangle_attention
145
+
>>> from cuequivariance_torch import mask_to_kv_lengths, triangle_attention
99
146
>>> if torch.cuda.is_available(): # doctest: +SKIP
0 commit comments