Repository navigation
Opt-in fused triangle kernels (Pallas) for inference - #4
Merged
Merged
Conversation
Anthropic's FlashPairformer Pallas kernels for TriangleMultiplication and GridSelfAttention, with their serve layer (tile tables, served-shape checks), copied verbatim from uplifting-biomolecular-modeling @ f4f62fa6 (Apache-2.0). Nothing imports them yet; later commits adapt and wire them, so each change shows as a diff against the original. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AlphaFold 3 keeps its own JAX building blocks under alphafold3/jax/, next to geometry/. Move the two vendored Pallas kernels, the kit's NOTICE and SOURCE.md there with git mv; the kernel files stay byte-identical to the kit at f4f62fa6. The package __init__ re-exports nothing so that the Triton backend is imported only once a kernel is selected. The Haiku adapters now import the kernels by absolute path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace fused_triangle_multiplication (bool) and fused_triangle_attention
('off'/'auto'/'pallas'/'tokamax') with fields named and valued like
flash_attention_implementation:
triangle_multiplication_implementation: 'default' | 'pallas'
triangle_attention_implementation:
'default' | 'pallas' | 'pallas_tokamax_core' | 'auto'
Old values map off -> default, True/pallas -> pallas, tokamax ->
pallas_tokamax_core, auto -> auto. Dispatch reports the same names, and
an unknown multiplication implementation now raises like the attention
one. fused_triangle_compute_capability and fused_triangle_memory_gib are
unchanged.
Add the four GlobalConfig fields to the model_config.json golden; the
fields added with the adapters had left run_alphafold_data_test's
test_config failing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fpf_pallas_serve.py had been cut from the kit's 820 lines to 131 lines of this fork's own policy while keeping the kit's file name. Remove it from the vendored set and put the policy in alphafold3/jax/fused_triangle/ dispatch.py, in AlphaFold 3 style: device_policy, select_implementation and the two tile lookups. The dispatch takes the requested implementation and a DevicePolicy instead of reading GlobalConfig, so alphafold3.jax does not depend on alphafold3.model. Only the bf16 tile rows are copied from the kit, credited in a comment. Decisions are unchanged; select_implementation now names the original body 'default' (was 'stock'), with reason 'not_requested' (was 'off'). Checked against the removed file over 1.8M argument combinations. SOURCE.md now lists the three files vendored unchanged, the file whose tile rows were copied, the copyright holder, and that NOTICE's paths are paths of the kit repository. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the Haiku adapters out of the fused_triangle package __init__ into the module alphafold3/model/network/fused_triangle.py (AlphaFold 3 __init__ files only re-export), and restyle them like modules.py: 2-space indent, absolute imports, licence header, Google docstrings, type hints, descriptive names, pyink formatting at 80 columns. The adapters take the module settings they need (equation, use_glu_kernel, num_head) instead of the module config; the unused key= parameter and the lazy haiku, jnp, hm and tokamax imports are gone. modules.py imports the adapter module at the top and formats the hooks like the surrounding code; the hooks stay where they were and initialisation stays on the original body. Only the two kernel modules are imported lazily, so importing modules.py does not import them; the lazy-import test now checks exactly that. (jax.experimental.pallas.triton is already imported by tokamax, through model_config.) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move tests/test_fused_triangle.py beside the module it tests, as src/alphafold3/model/network/fused_triangle_test.py (run_alphafold_test.py sits beside run_alphafold.py the same way), and convert it from pytest to absltest + parameterized with the AlphaFold 3 licence header, 2-space indent and 80 columns. tests/ is gone. The adapter test that made seven kinds of assertion per case is split into focused tests: parameter compatibility at init, finite output, nonzero-output parity, determinism, padding invariance, the pallas_tokamax_core path, and the float32 fallback. A new check that the fused config actually traces pallas_call guards the GlobalConfig to dispatch wiring, which parity alone cannot see. Shared reference outputs are cached, so the 80 tests take about as long as the old 28. CI already runs CPU absltest files with `uv run python`, with the same JAX, tokamax and Haiku versions the tests were verified with, so add the file as a step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When triangle_multiplication_implementation or triangle_attention_implementation asks for a fused kernel but a layer runs the original module body, log an absl warning at trace time that names the requested implementation, the activation shape and the reason (dispatch reasons, plus the adapters' glu_kernel_disabled, mask_dtype_mismatch and unsupported_equation). Each reason is logged once per process. Nothing raises; the default implementation, and layers that do run a kernel (including their initialisation), log nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
3 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Opt-in fused triangle kernels for inference. They are Anthropic's FlashPairformer Pallas kernels for
TriangleMultiplicationandGridSelfAttention, from uplifting-biomolecular-modeling @ f4f62fa6 (Apache-2.0). Off by default; with the defaults the model runs exactly the original code.9aedcb1;trimul_pallas.py,triattn_pallas.pyandNOTICEare byte-identical to the kit):src/alphafold3/jax/fused_triangle/, the place AF3 kept its own Pallas kernels before tokamax;SOURCE.md.jax/fused_triangle/dispatch.py: per-device tile tables and size and memory limits. The tile rows are copied from the kit and credited.model/network/fused_triangle.py: Haiku adapters that read the stock parameters, so the weights load unchanged. They use DeepMind's ending-node bias convention, not OpenFold's.modules.py.initalways runs the stock module.flash_attention_implementation:triangle_multiplication_implementation:'default'or'pallas';triangle_attention_implementation:'default','pallas','pallas_tokamax_core'or'auto';fused_triangle_compute_capabilityandfused_triangle_memory_gib, which the caller sets.test_data/model_config.jsongains the new fields.Validation
This branch carries the same commits as #2, replayed onto the v3.0.4 update (#3); the fused code is byte-identical between the two. The GPU numbers below were measured on the v3.0.3 / jax 0.9.1 stack. The v3.0.4 / jax 0.10.2 stack is validated on CPU here, and gets the full GPU campaign on the rebuilt AlphaPulldown image before any release.
fused_triangle_test.py(absltest, added to CI): 90 tests, passing on jax 0.9.1 and on 0.10.2 / tokamax 0.0.12 on CPU in Pallas interpret mode. They cover:Layer level on GPU, 6 cards:
End to end through AlphaPulldown, DeepMind weights, warm calls, fused vs stock on the same card:
🤖 Generated with Claude Code