Repository navigation
Conversation
|
CC: @Augustin-Zidek |
|
Thanks for the PR. How was this tested? |
|
Hi @Augustin-Zidek, thanks for your question and I am sorry for my late reply, I was on leave. This was tested on:
For end-to-end correctness we verified the inference results through this script.
using this script. Identical-code GPU runs showed an approximately 0.20–0.22 Å RMSD drift because of diffusion and nondeterministic GPU reductions. The end-to-end acceptance threshold was therefore calibrated to 0.30 Å, with:
The complete candidate passed at both ends of the tested range:
The
The de-subbatching change was tested to ensure operator equivalence, using shared parameters and identical inputs. |
|
@Augustin-Zidek is there anything we should consider in the setup to have this better tested? thank you |
|
Hey, sorry for the late reply... This looks great, we will do some internal testing on this and merge if things look good. |
No worries Augustin. Thanks very much indeed |
Summary
This change optimises the
GridSelfAttentionby:mapping.inference_subbatchloop;key_value_seq_lengths.Tokamax FlashAttention already tiles the operation internally. In the measured kernels it uses 64 x 64 query/key tiles, so the additional AlphaFold-level row subbatching fragmented an operation that was already memory-aware.
The change preserves the attention calculation for valid tokens, while substantially reducing launches, dynamic slicing, device-to-device copies, and host-side scheduling overhead.
results were tested with the following input tokens: 512, 1024, 2048, 3072.
We have used:
Explanation
Before Alphafold divided the first residue dimension into small row subbatches:
The changed simplified this view as:
At 1024 tokens, the original chunk size was 128, resulting in eight separate outer attention calls, at 2048 the chunk size fell to 32. Each subbatch processes different query rows, so AF was not mathematically recomputing the same attention outputs.
HOWEVER, The redundancy was in the execution machinery around those calculations. Analysing the Before/After profiles we could see:
Implementation changes
Previously we had
now we're exploiting directly tokamax and identifying with
key_lengthsthe valid keys end and paddings:The complete
acttensor is passed to Tokamax. Tokamax remains responsible for the lower-level GPU tiling, online softmax and memory movement within the FlashAttention kernel.This removes only the redundant outer chunking layer—it does not disable attention tiling.
key_lengthsis independent of subbatching. It does not control how Tokamax partitions the work; it describes which keys are valid for each attention row.In particular, for
GridSelfAttention, Q/K/V have shape:AlphaFold pads tokens contiguously at the end. Consequently, every row’s valid keys form a prefix:
For a bucket of eight tokens containing five real tokens:
The dense attention-side mask therefore contains no more information than one integer per row.
Passing
key_value_seq_lengthsallows Tokamax to:Even for a bucket-aligned input, where every length equals N, this avoids dense-mask operations. For padded inputs, it can additionally avoid computing key blocks beyond the real sequence length.
Results
Here are the results on A100 machine, measured as GPU time in seconds, or warm time, given as average +/- stdev
on a B300 machine
Profile comparison
The 1024-token traces provide direct evidence that XLA was executing the outer subbatch loop and was not optimizing it away.
Across 5 warm runs we had: