arXiv:2610.05854cs.LGOct 2026

Manuscript Offprint

arXiv:2610.05854

TurboPairFormer: Fast and Stable Protein Folding Model Training with an Optimized Triangle Attention Kernel

Yide Ran, Chelsea Lowman, Jan Domański, David Hartmann, Jenke Scheen, Jennifer Wei, Chuan Li, Jianwen Xie, Zhaozhuo Xu

ABSTRACT

Triangular attention is a core computation in AlphaFold3-style biomolecular models, with computational cost that grows cubically with token count. FlashAttention reduces attention memory traffic through IO-aware tiling and backward recomputation. However, the shared pair bias in triangular attention adds a gradient reduction across attention slices to the usual reductions over queries and keys. The open-source backends we examine handle these reductions through repeated probability recomputation, floating-point atomics, or full score-gradient storage. Separately, computing the softmax backward correction from BF16-rounded forward outputs incurs a loss of numerical precision. We present TurboPairFormer, a triangular attention implementation for NVIDIA Hopper GPUs that addresses these two issues. Our key-tile-parallel backward algorithm recomputes each probability tile once and reuses it for the query, key, value, and pair-bias gradients, using ordered partial reductions to achieve deterministic accumulation without floating-point atomics or full score-gradient storage. Our output-residual compensation retains a BF16 approximation of the output-rounding residual and uses it to compute the backward correction more accurately in FP32, without changing the BF16 output. With BF16 inputs at crop sizes 384, 640, and 768 and head dimensions 16 and 32, TurboPairFormer achieves the lowest mean query, key, and pair-bias gradient RMSE against an FP64 reference among eight evaluated implementations; residual compensation mitigates the precision loss from output rounding, reducing these RMSE values by 28–47% in controlled ablations. All four gradients are bitwise identical across five repeated calls in all 600 input cases under fixed execution conditions. Integrated into OpenFold3 together with our triangle multiplication kernels, TurboPairFormer achieves the lowest GPU computation time per optimizer step among eight evaluated backend configurations on 16 H100 GPUs, with speedups of 1.73×1.73\times over OpenFold3's Triton backend and 1.13×1.13\times over cuEquivariance at crop size 768.

1 INTRODUCTION

AlphaFold3 predicts the joint structure of complexes containing proteins, nucleic acids, and small molecules (Abramson et al., 2024). OpenFold3 provides an open-source implementation of AlphaFold3 with support for training and fine-tuning (The OpenFold3 Team, 2025). Both models use one token per standard amino acid or nucleotide residue and one token per heavy atom for other components. They maintain a pair representation, with one learned vector for each pair of tokens, and repeatedly update it through triangular attention and triangle multiplication. In triangular attention, fixing one token index, which we call the outer index, selects the pair vectors between that token and every token in the crop. These vectors form an attention slice with one query and one key per token, as in standard attention, and all slices share the same pair bias. There is one slice per token, and the cost of each slice grows with the square of the token count. The cost of triangular attention therefore grows with the cube of the token count: doubling the training crop makes it eight times as expensive.

†^{\dagger}Equal advising Website: https://pypi.org/project/turbopairformer

IO-aware kernels such as FlashAttention fuse attention into tiled kernels and recompute probabilities in the backward pass instead of storing them (Dao et al., 2022); their successors improve parallelism and overlap data movement with computation on Hopper GPUs (Dao, 2024; Shah et al., 2024). However, extending these kernels to triangular attention requires an additional reduction of the shared pair-bias gradient across slices. The backward pass thus has three reduction directions (Figure 1a): the query gradient sums over keys, the key and value gradients over queries, and the pair-bias gradient over outer indices. All four gradients reuse the same probability tiles, but their reductions favor different work partitionings. With one recomputation, they share one work partitioning, so any gradient whose reduction axis is split across thread blocks requires a cross-block reduction.

The open-source triangular-attention kernels we inspect make different compromises to handle this reduction (Figure 1b): TriFast (Atkinson, 2025) and Protenix (ByteDance AML AI4Science Team et al., 2025) recompute the probabilities three times, DeepSpeed-Evo (Song et al., 2023) accumulates the pair-bias gradient with floating-point atomics whose order is not fixed, and ScaleFold (Zhu et al., 2024) stores the full FP32 score gradient. FlashAttention-3's deterministic mode orders in-place query-gradient updates with semaphores, and DASH improves its scheduling (Shah et al., 2024; Qiang et al., 2026), but neither computes a bias gradient.

a Triangular attention: N slices share one pair bias

Figure

dQ sums over keys, within a slice

dK, dV sum over queries, within a slice

dbias sums over the outer index, across slices

All four gradients reuse the same tiles P and dS.

b Backward designs for the four gradients

Figure 1: Triangular attention and backward design comparison. (a) Triangular attention consists of N slices sharing one pair bias. Its backward pass involves three reduction axes: dQ over keys, dK and dV over queries, and d bias across outer slices. All four gradients share the same intermediates (P and dS). (b) Prior backends either recompute probabilities 3×3 \times, use non-deterministic atomics, or store the full score gradient dS, whose size is cubic in N. TurboPairFormer evaluates P and dS only once: it keeps dK and dV in local registers, writes dQ and d bias into independent partial buffers, and reduces them in a deterministic FP32 order.

Determinism does not guarantee accuracy. In the softmax backward pass, all score gradients in a query row depend on the same correction δ\delta, the dot product of the output gradient and the forward output for that row (Dao et al., 2022). Kernels usually compute δ\delta from the saved BF16 output, whose rounding error can shift these score gradients in the same direction. A deterministic kernel reproduces this error on every run. The forward pass matters as well: with 64-row query tiles and head dimension 32, a bias tile holds as many bytes as the key and value tiles combined, and recycling and checkpointing run two to five forward passes per backward pass. Our challenge is therefore threefold: to reuse each recomputed probability tile for all four gradients with fixed accumulation orders and sufficient parallelism, to compute δ\delta accurately, and to stage the shared bias efficiently in the forward pass.

We propose TurboPairFormer, a triangular-attention kernel for Hopper GPUs:

  1. Work partitioning for three reduction directions: We analyze how the shared pair bias trades recomputation against parallelism and storage (Section 2.1 and Appendix I), and assign each thread block a key tile and a group of outer indices, which keeps the key and value gradients local and leaves two cross-block reductions.

  2. Single recomputation with ordered partial reductions: Like DeepSpeed-Evo and ScaleFold, TurboPairFormer recomputes each probability tile once for all four gradients, but without floating-point atomics or full score-gradient storage. Query and pair-bias partials have unique writers and are reduced in fixed FP32 orders, without blocks waiting for one another. Gradient bits do not depend on thread-block completion order or on supported workspace schedules; the cost is a query-partial buffer cubic in crop size (Appendix E).

  3. Output-residual compensation: The forward epilogue saves a BF16 approximation of the output-rounding residual, which the backward pass adds to the BF16 output in FP32 when computing δ\delta (Qiu & Yao, 2026; Henry et al., 2019). This lowers the mean RMSE of the query, key, and pair-bias gradients by 28–47% in controlled ablations, without changing the BF16 output or adding a recomputation; the cost is one extra output-sized BF16 tensor.

  4. Forward staging of the shared bias: The forward kernel loads each bias tile with the Tensor Memory Accelerator alongside the key and value tiles, reads it directly in the score-accumulator register layout, prefetches the key mask, and evaluates probabilities in 16-key chunks just before value aggregation, without changing the floating-point operations or their order.

We evaluate TurboPairFormer on H100 GPUs at crop sizes of 384, 640, and 768 and head dimensions D=16D = 16 and 32. Compared with the other methods evaluated in this paper, TurboPairFormer produces more accurate query, key, and pair-bias gradients, as measured by mean RMSE against an FP64 reference. All four gradients are bitwise identical across five repeated calls in all 600 fixed-input cases (Appendix G.4), whereas cuEquivariance, OpenFold3 Triton, and DeepSpeed-Evo pass none; the fastest non-deterministic variants of our kernel take 2.8–4.1% less backward time at D=32D = 32 and 11.0–13.7% less at D=16D = 16 (Appendix I). One TurboPairFormer attention call takes 35.6–45.6% less forward-plus-backward time than cuEquivariance (NVIDIA Corporation, 2026) and ranges from 7.4% faster to 3.6% slower than Protenix (Appendix H.1); the forward changes cut forward time by 25.5–27.5% at D=32D = 32 (Appendix H.2). Combined with our triangle multiplication kernels, TurboPairFormer has the lowest GPU computation time per step among eight OpenFold3 backend configurations on 16 H100 GPUs, 1.73×1.73\times faster than OpenFold3 Triton and 1.13×1.13\times faster than cuEquivariance at crop 768. In paired 400-update continuations from a shared step-1000 checkpoint, the losses of runs using an earlier build of our kernels remain finite, whereas OpenFold3 Triton produces NaN losses within 10 updates (Section 3.3).

References (30)