ReadingResearchRadarInvestment framework
Sign in / Sign up
← Back to reading
NewsMaterial4 min readDisconfirmAI Editorial

AMD Engineers: Triton Kernels for AlphaFold3-Style Triangle Operations Cut Forward Peak Memory 69x

AMD's ROCm team describes geometric-nn-ops, a standalone PyTorch library of Triton kernels for the triangle attention and triangle multiplicative update in AlphaFold3-style co-folding models. The blog explains how a flash-attention-style kernel handles the row-shared pair bias without ever materializing the full O(N³) logit tensor, reducing peak memory by a factor of about 69 in their forward-pass test at N=768 on an MI355X GPU. It also documents how the same fp32 precision setting resolves to XF32 instructions on CDNA 3 but to three-product bf16 emulation on CDNA 4, and why the multiplicative update's Triton path is forward-only.

2026-12-04 08:00 GMT+8

AlphaFold3-style co-folding models update an N×N pair representation — one feature vector per pair of the complex's N tokens — with two triangle operations in every trunk block: triangle attention and the triangle multiplicative update. Both sum over a third token k, so their cost grows as N³ while the rest of the trunk grows as N². Doubling the complex size multiplies triangle-op work by up to eight and everything else by up to four, so on large complexes these two operations dominate.

AMD's ROCm engineering team has published geometric-nn-ops, a standalone PyTorch library of Triton kernels for these operations on AMD Instinct GPUs. The blog explains the central memory trick: triangle attention around the starting node computes, for every row i, the softmax over k of (q_ij · k_ik / √D + b_jk) applied to v_ik. Viewed as attention, that is a batch of N independent problems, one per row, except for the bias: b_jk does not depend on i, so all N rows share one [H, N, N] bias. A direct PyTorch implementation materializes [B, N_seq, H, N, N] logits — O(N³·H) memory per call. The Triton kernel is a flash-attention-style kernel (online softmax in the forward, recomputation in the backward) built around that shared bias, and never forms that tensor.

The mechanism is a pointer offset. Each program instance owns a 64-row query tile of one (batch, row, head) triple and streams 16-row key and value tiles past it. The bias pointer is offset by the batch and head indices only, never by the row index, so every program working on any row of a given (batch, head) pair reads the same bias tile. The broadcast across N_seq rows costs no memory: there is no [B, N_seq, H, N, N] copy. In AMD's testing on an MI355X GPU at N=768 (bf16, H=4, D=32), the forward pass peaked 0.15 GiB above its inputs against 10.41 GiB for a direct einsum-and-softmax PyTorch implementation — a reduction by a factor of about 69. For forward and backward together, the reduction factor is about 9.5.

Sign in / Sign up
ReadingResearchRadarInvestment framework

The backward pass handles the bias gradient by launching one program per tile of the bias, so each d_bias tile has exactly one owner and is summed over rows in fp32 registers without atomics. The result is deterministic. The query gradient dQ, by contrast, is accumulated with atomic adds because every key tile contributes to dQ, so gradients with respect to q can differ in the last bits from run to run.

A second concrete finding concerns fp32 precision. The library follows PyTorch's global setting torch.backends.cuda.matmul.fp32_precision. When that setting is "tf32", CDNA 3 GPUs (MI300X, MI325X) have an XF32 matrix instruction, so the Triton kernels map tf32 directly to it. CDNA 4 GPUs (MI350X, MI355X) lack XF32; their Triton backend offers ieee, bf16x3, and bf16x6, so "tf32" resolves to bf16x3 — emulating a reduced-precision fp32 product with three bf16 products. The same user-facing setting produces different numerical behavior on adjacent GPU generations without any code change. A test in the repository parses every Triton kernel and checks that each tl.dot passes an explicit input_precision, because Triton otherwise picks a default per target and the contract silently breaks.

The multiplicative update uses a different strategy: Triton kernels handle the LayerNorm and the gated projections (with compile-time flags for bias, sigmoid, multiply, and mask fused into the GEMM epilogue), while the contraction over k runs as a PyTorch batched GEMM dispatched to the platform BLAS. The Triton path is forward-only, so dispatch takes the PyTorch path whenever autograd records the call — meaning grad mode is on and an input requires grad. Checking torch.is_grad_enabled() matters: a tensor keeps requires_grad=True inside no_grad and inference_mode, so an evaluation pass inside a training loop would otherwise take the slower differentiable path.

Two numerical differences between the Triton and PyTorch paths for the multiplicative update are worth noting. The Triton LayerNorm computes variance in a single pass and uses 1/sqrt(max(var, eps)) where PyTorch uses 1/sqrt(var + eps), and the sigmoid input is clamped to ±20. At a variance equal to eps, the normalized values differ by a factor of √2. AMD's testing shows relative error of about 5e-3 at a typical position but about 8e-2 where input variance is close to eps — a visible change when a model moves between training and inference.

All figures are AMD's own measurements on AMD hardware. The library is open source (ROCm/geometric-nn-ops, v1.0.0), and the blog notes that the multiplicative update backward has no Triton kernel, and attention_pair_bias (attention over the single representation) is implemented only in PyTorch.

Sources

  • rocm.blogs.amd.comROCm Blogs↗
Continue researching →