Skip to content

Commit 73c34ee

Browse files
authored
doc-string updates+ rel-notes (#220)
* docstring updates for APB * corrected doctest skip * skip doctest for apb caching * triattn docstring update for balckwell kernel * release notes updated * update torch/jax for triatn rel notes * version update
1 parent a94909e commit 73c34ee

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
## Latest Changes
22

3+
## 0.8.0 (2025-12-05)
4+
5+
### Added
6+
- [Torch/JAX] Blackwell-optimized BF16/FP16 forward and backward kernels for `cuet.triangle_attention` (runs on compute capabilities 10.0 and 10.3). These kernels provide superior performance especially for long sequences and higher head dimensions. This is only supported on cu13 builds as of this release.
7+
8+
### Bug fix
9+
- [Torch/JAX] Fixed index overflow and out of bound issues leading to illegal memory access in `cuet.triangle_attention`
10+
11+
### Notes
12+
- [Torch/JAX] Blackwell-optimized kernels require the sequence length N to be a multiple of 8 for the forward pass; pad the sequence if necessary
13+
- [Torch/JAX] Blackwell-optimized kernels are currently supported only for CUDA 13 builds
14+
315
## 0.7.0 (2025-10-13)
416

517
### Added

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.8.0rc4
1+
0.8.0

cuequivariance_torch/cuequivariance_torch/primitives/triangle.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def triangle_attention(
8080
(1) Context is saved for backward pass. You don't need to save it manually.
8181
(2) Kernel precision (fp32, bf16, fp16) is based on input dtypes. For tf32, set it from torch global scope
8282
(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. In the rare instance that the kernel does not support an input config, fallback to torch is enabled instead of erroring out.
83+
(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. Currently, this feature is supported only for cu13 builds.
8384
8485
Example:
8586
>>> import torch
@@ -333,8 +334,12 @@ def attention_pair_bias(
333334
- The proj_z output is experimental to prevent breakage when caching
334335
of pair bias tensor is enabled in the next release.
335336
- Tested for bf16, fp16, fp32 and tf32. torch.set_float32_matmul_precision maybe used to toggle between fp32/tf32.
337+
- Currently, the kernel provides superior performance only when DH (head dimension) is a multiple of 32.
338+
For non-multiples of 32, we also recommend using graph compilation techniques like torch.compile, in addition.
336339
337340
Examples:
341+
Basic usage without caching:
342+
338343
>>> import torch
339344
>>> from cuequivariance_torch import attention_pair_bias
340345
>>> if torch.cuda.is_available(): # doctest: +SKIP
@@ -365,7 +370,7 @@ def attention_pair_bias(
365370
... b_ln_z = torch.randn(z_dim,
366371
... device=device, dtype=torch.bfloat16)
367372
... # Perform operation
368-
... output, proj_z = attention_pair_bias(
373+
... output = attention_pair_bias(
369374
... s=s,
370375
... q=q,
371376
... k=k,
@@ -378,9 +383,36 @@ def attention_pair_bias(
378383
... w_proj_o=w_proj_o,
379384
... w_ln_z=w_ln_z,
380385
... b_ln_z=b_ln_z,
386+
... return_z_proj=False,
381387
... )
382388
... print(output.shape) # torch.Size([1, 32, 64])
383389
torch.Size([1, 32, 64])
390+
391+
Example with caching (recommended for inference when z doesn't change):
392+
393+
>>> # Check cache and determine if z is already projected
394+
>>> if model_cache is not None and "proj_z" in model_cache: # doctest: +SKIP
395+
... z = model_cache["proj_z"]
396+
... is_cached_z = True
397+
... else:
398+
... is_cached_z = False
399+
>>>
400+
>>> # Call attention_pair_bias
401+
>>> o, proj_z = attention_pair_bias( # doctest: +SKIP
402+
... s=s, q=q, k=k, v=v, z=z, mask=mask,
403+
... num_heads=num_heads,
404+
... w_proj_z=w_proj_z if not is_cached_z else None,
405+
... w_proj_g=w_proj_g,
406+
... w_proj_o=w_proj_o,
407+
... w_ln_z=w_ln_z if not is_cached_z else None,
408+
... b_ln_z=b_ln_z if not is_cached_z else None,
409+
... return_z_proj=True,
410+
... is_cached_z_proj=is_cached_z,
411+
... )
412+
>>>
413+
>>> # Cache proj_z for next call
414+
>>> if model_cache is not None and "proj_z" not in model_cache: # doctest: +SKIP
415+
... model_cache["proj_z"] = proj_z
384416
"""
385417

386418
try:

0 commit comments

Comments
 (0)