Skip to content

AF3: --fast_kernels with fused triangle kernels; AlphaFold 3 v3.0.4 - #646

Merged
DimaMolod merged 11 commits into
mainfrom
exp/af3-v3.0.4
Oct 7, 2026
Merged

DimaMolod merged 11 commits into
mainfrom
exp/af3-v3.0.4

Conversation

@DimaMolod

Copy link
Copy Markdown
Collaborator

Summary

--fast_kernels off|on|auto now covers the AlphaFold 3 backend. It switches on the fork's opt-in fused triangle kernels (KosinskiLab/alphafold3#4). The default stays off, which runs exactly the previous code. AlphaFold 2's behaviour and API are unchanged.

  • The AF3 policy has its own module, alphapulldown/prediction/af3_fused_triangles.py:
    • resolve(mode, device) checks the GPU before any weights load: an NVIDIA card with compute capability ≥ 8.0, a known tile table and memory budget, and a smoke compile-and-run of both fused blocks on that GPU.
    • on raises an error with the missing requirement; auto falls back with a log line.
    • Per card: Pallas attention on 8.0, 9.0 and 12.0; tokamax's attention core on 8.6 and 8.9; triangle multiplication on every card from 8.0. sm_100 is not enabled.
    • fast_kernels.py (AF2) is byte-identical to main; the two backends share only normalise_mode.
  • Traceable: each AF3 output directory gets inference_kernels.json, keyed seed-N. It records the requested mode, what each operation ran and the reason. Writing it never fails a finished prediction.
  • Flags: FAST_KERNEL_FLAGS is shared by AF2 and AF3; AlphaLink still rejects the flag.
  • Docs: docs/af3_fused_triangles.md, linked from the README and the AF3 installation section.
  • AlphaFold 3 v3.0.4 (separate commit): the submodule moves to the fork's main, which now carries upstream v3.0.4 (Update fork to AlphaFold 3 v3.0.4 alphafold3#3) and the fused kernels (Opt-in fused triangle kernels (Pallas) for inference alphafold3#4). The alphafold3 extra pins jax 0.10.2 / tokamax 0.0.12, matching the submodule's uv.lock, which the image installs. The Dockerfile version stamp and README follow.

Bug fix, separate commit: run_multimer_jobs.py never forwarded --fast_kernels. It takes its flags from run_structure_prediction, but builds its own argument list, which never passed --fast_kernels on for either backend and dropped --jax_compilation_cache_dir for AlphaFold 2. Both are now forwarded to AF2 and AF3; AlphaLink and UniFold still reject them.

Validation

  • Unit suite (serial): 726 passed, 10 skipped. That includes the new test_af3_fused_triangles.py and the metadata-helper tests, one of them with a corrupt existing file. The AF2 fast_kernels tests are unchanged.

  • AF3 image, CPU smoke: device_settings per card; smoke_test for both attention variants in Pallas interpret mode; resolve fallback and failure; metadata against the real GlobalConfig; importing the backend.

  • GPU campaign (AF3 image, DeepMind weights; every job its own SLURM job). Warm speed-up, fused vs stock on the same card:

    H100 A100 A40 L40S RTX 3090 RTX Pro 6000
    1.15–1.30× 1.18–1.66× 1.14–2.03× 1.11–1.34× 1.08–1.53× 1.12–1.23×
    • The largest fold each card holds is unchanged.
    • --fast_kernels=off is bit-identical to the previous fork on all 6 cards (deterministic XLA); on is deterministic.
    • 12 post-cutoff heterodimers, paired seeds 0–1 (stock also seed 2): Δranking and ΔDockQ are 0.00 on nearly all of them. The two A40 outliers come from stock seeds; a 10-seed follow-up is planned.
    • Protein–RNA, protein–ligand and template inputs give the same ranking with and without the kernels.
    • The campaign ran this feature before a refactor that kept its behaviour: module split, renamed config and seed-key spelling.
  • Before any release: the GPU campaign is re-run on the AF3 image that CI builds from this branch (jax 0.10.2). The numbers above were measured on jax 0.9.1, and so far the v3.0.4 stack has been tested on CPU only: the fork's 90 fused tests, the golden config, and this unit suite.

Companion PR: the workflow accepts the flag for AF3 (KosinskiLab/AlphaPulldownSnakemake#SMPR).

🤖 Generated with Claude Code

DimaMolod and others added 11 commits October 6, 2026 15:09
Move the submodule to KosinskiLab/alphafold3 73f260e (branch
exp/af3-fused-triangle), where the fused triangle kernels moved under
alphafold3/jax/fused_triangle and the config fields are named like
flash_attention_implementation:

  fused_triangle_multiplication=True   -> triangle_multiplication_implementation='pallas'
  fused_triangle_attention='auto'      -> triangle_attention_implementation='auto'
  network.fused_triangle.fpf_pallas_serve.card_policy/select
      -> jax.fused_triangle.dispatch.device_policy/select_implementation

The per-device choices are unchanged. Dispatch now names the original
body 'default' (was 'stock', reason 'not_requested' instead of 'off'),
so the per-seed record keys its operations triangle_multiplication_cN /
triangle_attention_cN with an 'implementation' field. The fork no longer
exposes the kit's source commit; its SOURCE.md records it, and the
record keeps the dispatch policy version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the AlphaFold 3 decision out of prediction/fast_kernels.py into
prediction/af3_fused_triangles.py, so fast_kernels.py is AF2-only again,
byte-identical to main, and its resolve(mode) API is unchanged. The new
module reuses fast_kernels.normalise_mode and exposes:

  resolve(mode, device) -> FusedTriangleChoice (enabled, reason, mode,
      settings; global_config_update())
  OFF                    the choice for --fast_kernels=off
  device_settings(device) GlobalConfig fields for the device (was _af3_settings)
  smoke_test(settings)   (was _af3_smoke_test)
  metadata(global_config, choice, *, num_tokens) (was af3_metadata)

ModelRunner keeps the resolved FusedTriangleChoice (fused_triangles)
instead of a re-normalised mode string and a reason. Decisions, the
GlobalConfig fields set and the record's fields are unchanged.

The AF3 tests move from test_fast_kernels.py (back to main's) to
test_af3_fused_triangles.py, and the backend's own checks are separate
tests instead of additions to the MSA and setup tests. The light-import
test covers the new module: the AF3 backend imports it, and it imports
neither JAX nor the fork until a kernel mode is resolved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
smoke_test compiled and ran the two fused triangle layers on JAX's
default device, while device_settings had read the limits of the device
the model runs on. It now takes that device and runs inside
jax.default_device(device), so the check and the model see the same GPU.

An --fast_kernels=auto fallback now records its reason as
"--fast_kernels=auto: ...", like AlphaFold 2's, instead of the bare
problem, so inference_kernels.json says which mode fell back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The per-seed inference_kernels.json update was inline in the seed loop:
a corrupt existing file, or a fork without the dispatch module, raised
out of predict_structure after the model had run, and its time was
counted in "Model inference for seed N took". It is now
_record_inference_kernels, mirroring AlphaFold 2's: it runs after
structure extraction, replaces an unreadable file with a warning, and
logs and skips any other failure. Entries are keyed seed-N, AF3's own
spelling in output names, instead of seed_N.

make_model_config read the fused-triangle decision from the enclosing
scope, assigned only later in setup(); the GlobalConfig update is now
passed in explicitly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
--fast_kernels was listed twice, as AF2_EXTRA_FLAGS and inside
AF3_FLAGS, under a comment that still said AlphaFold 2 only. Both
backends now take it from one FAST_KERNEL_FLAGS set, whose comment says
which kernels each backend uses and why AlphaLink has none. The flags
each backend accepts are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ents

Rewrite docs/af3_fused_triangles.md in sections like docs/mmseqs2_rna.md:
turning the kernels on, what runs on which GPU, memory limits, how they
were measured, the output record, troubleshooting, and source and
licence. Define the terms the old text assumed (Pallas, the attention
core, Anthropic's Pallas flash-attention core vs tokamax's), drop "this
branch", and state the measurement: Gate 0 and the full-model campaign
on A100, A40, RTX 3090, L40S, H100 and RTX Pro 6000 Blackwell with
JAX 0.9.1 / tokamax 0.0.11; Pallas attention on compute capability
8.0/9.0/12.0, the tokamax core on 8.6/8.9, multiplication on all of
them, nothing on 10.0 (B200) or newer. The record section follows the
renamed fields and seed-N keys. Troubleshooting says that scripts
importing the AF3 backend should call jax.devices() first.

Link the page from the README's AlphaFold3 flags, and move the link in
backend_installation.md from the top into the AlphaFold3 backend notes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The submodule points at KosinskiLab/alphafold3 exp/af3-fused-triangle-v3.0.4
(ab98e22): upstream v3.0.4 merged into the fork without conflicts (de1577e),
with the fused-triangle commits replayed on top. The fork's fused-triangle
test passes 90/90 on it, on jax 0.9.1 and on jax 0.10.2 / tokamax 0.0.12
(CPU, Pallas interpret mode), and make_model_config() matches the golden
model_config.json.

v3.0.4 moves AF3 to jax 0.10.2 and tokamax 0.0.12, so the alphafold3
extra, the image's version stamp and the README follow. The image installs
AF3 from the submodule's uv.lock, which v3.0.4 already updates.

Experimental: needs a rebuilt AF3 image and the GPU campaign rerun on it
before any PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
run_multimer_jobs takes its flags from run_structure_prediction but built
its own argument list and never passed --fast_kernels on, for either
backend, and dropped --jax_compilation_cache_dir on the AlphaFold 2 path.
Both are now forwarded to AlphaFold 2 and AlphaFold 3. AlphaLink and
UniFold reject them, so they stay out of those commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
, #4)

Fork main 7809148: upstream v3.0.4 (#3) plus the fused triangle kernels (#4).
Same tree as the tested ab98e22 apart from upstream's data-test fix (43525e6).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@DimaMolod
DimaMolod merged commit 5c7ac98 into main Oct 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant