Add experimental Apple Silicon GPU inference support#699
Add experimental Apple Silicon GPU inference support#699SuhasSrinivasan wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Signed the CLA |
|
Hello, thanks for the PR. Could you simplify it so that it contains only the minimal change to make it work? There are quite a few unrelated changes, e.g. the xla_chunked seems to be redunant. Also, could you use the dependencies in pyproject.toml and make the jax-mps conditional instead of shipping them in an additional file? |
e9ef57c to
c021bbd
Compare
|
Thanks for the review — both points addressed.
The net diff is now run_alphafold.py, pyproject.toml, uv.lock, and the macOS install doc. Verified on an M2 Ultra that MPS inference selects MpsDevice(id=0) and runs. |
|
Neat! Could you rebase on top of a3b8355? That should simplify the change even further. I am going to test things on my side and I will send a PR that is inspired by this, but I want to refactor a few things (I think I will get rid of the However, I will make sure to mention you in the release notes and this PR is a great proof of concept that this is a path worth pursuing -- many thanks for sending it. |
|
Thanks again! |
No need.
I introduced the flag only last week, so it is OK to rename it, I don't think anyone depends on it yet. But feel free to try with the proposed changes, these things are easy with agents these days after all. :) |
c021bbd to
bb14755
Compare
|
Rebased onto |
|
Hello, I've done some preparatory work for this in 98a15dc. Could you rebase on top of this commit? |
Add an "mps" value to the JaxBackend enum, enabling AlphaFold 3 inference on the Apple Silicon integrated GPU via the jax-mps Metal plugin for JAX. Like "cpu", MPS inference requires --flash_attention_implementation=xla. The default backend remains "gpu" (NVIDIA CUDA) and that path is unchanged. - run_alphafold.py: add JaxBackend.MPS plus its validation and device-selection branches (device chosen via jax.local_devices(backend="mps")). - pyproject.toml: add jax-mps on darwin arm64 (the base already installs jax/jaxlib 0.10.2). uv.lock updated with the jax-mps entry. - docs: native (non-Docker) macOS GPU install guide, plus a pointer from installation.md.
bb14755 to
de989ac
Compare
|
Thank you. |
|
Thank you! |
Add experimental Apple Silicon GPU (Metal / MPS) inference support
Summary
This PR enables AlphaFold 3 inference on the Apple Silicon integrated GPU via the community
jax-mpsMetal plugin. It is an opt-in, experimental path: the default backend staysgpu(NVIDIA CUDA), and the CUDA code path is untouched. It complements the existing CPU-only macOS mode by giving Mac users a much faster GPU option for small/medium structures. All changes are additive and gated behind a new flag.Motivation: Current docs state Mac users must fall back to CPU because "jax-metal is unfinished."
jax-mpsis a different, working Metal plugin — this PR wires it in and backs it with a 52-target validation campaign (below).What changed (5 files, +650 / −56)
run_alphafold.py--jax_backend {gpu,mps}(defaultgpu); newxla_chunkedattention option; device selection/validation refactored into_select_inference_device/_validate_inference_devicerun_alphafold_device_test.pyrequirements/apple-silicon-gpu.txtdocs/installation_apple_silicon_gpu.mddocs/installation.mdBackward compatibility (nothing NVIDIA changes)
gpu(CUDA) — unchangedXLA_FLAGSworkaround)triton/cudnnattentionNew flags / usage
--jax_backendgpu(default),mpsmpsrequiresxla/xla_chunked;--use_cpu_onlyoverrides--flash_attention_implementationtriton,cudnn,xla,xla_chunked(new)xla_chunked= portable, linear-memory, slowerMPS invocation:
--jax_backend=mps --flash_attention_implementation=xlaBackend dependency stack
Installed as a post-install override of the base
jax==0.9.1pin (one expectedpip checkwarning); no change touv.lockor the default install.Validation campaign
Accuracy (best of 5 seeds, vs PDB)
Overall (n = 52)
has_clashBy molecule type (median). Read per-chain as fold quality; a high complex value with low per-chain = quaternary arrangement of a flexible assembly, not a fold error.
Highlight: nitrogenase
3U7Q(2,177 tokens, FeMoco metal cluster) — per-chain 0.42 Å, complex 0.47 Å, DockQ 0.98, ligand 0.13 Å, pTM 0.96.Performance and memory (M2 Ultra, 192 GB)
¹ MSA / data pipeline is CPU-bound and driven by the number of unique chains and RNA presence, not token count — hence non-monotonic across sizes (observed range 7–35 min). ² Inference time and peak memory are set by the padded token bucket. Inference scales ~polynomially (exponent ~1.7 → ~2.8) with a steeper Metal-specific penalty above ~1,536 tokens; unified memory (not process RSS) is the capacity limit — practical ceiling ≈ 2,200 tokens on 192 GB.
Known limitations
jax-mpsMetal plugin; not numerically certifiedxla/xla_chunkedon MPS (triton/cudnnare NVIDIA-only)--jax_compilation_cache_dirdoes not persist on MetalDeveloped with help from Claude!