[feat][JAX] Add Apple Silicon MPS support - #1979
Conversation
71c6cf3 to
7e8a200
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces experimental support for Apple Silicon (macOS 14+) in the JAX backend using the jax-mps PJRT plugin. It includes documentation updates, dependency adjustments in pyproject.toml, and custom workarounds in the attention layers and KV cache update logic to bypass current jax-mps limitations. Additionally, it implements ephemeral in-memory sampler checkpoints to avoid redundant disk writes. Feedback on the changes highlights a behavioral discrepancy in the custom MPS KV cache update logic, where negative start indices are incorrectly wrapped instead of clamped to zero as standard JAX dynamic_update_slice does. Suggestions have been provided to simplify this logic and update the corresponding unit tests.
99a2d51 to
eb2176e
Compare
eb2176e to
56f7fd8
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 56f7fd8. Configure here.
Signed-off-by: bvolpato <brunocvcunha@gmail.com>
Signed-off-by: bvolpato <brunocvcunha@gmail.com>
56f7fd8 to
8d4a12b
Compare
Signed-off-by: Bruno Volpato <brunocvcunha@gmail.com>
Signed-off-by: bvolpato <brunocvcunha@gmail.com>

Summary
Add opt-in Apple Silicon support for SkyRL's JAX backend using
jax-mps.Changes
mpsdependency extra for Apple Silicon macOS.dynamic_update_sliceboundary behavior in the KV-cache fallback.Validation
The checkpoint-restore follow-up has two CPU regressions covering both optimizer-restore settings. Both fail before the fix and pass afterward using actual training and sampler checkpoint round trips. The focused optimizer and ephemeral-checkpoint controls also pass. Required pre-commit hooks pass.
Earlier Linux validation after rebasing onto
mainat38ef74d3:30 passed)9 passedwith eight forced XLA CPU devices)2 passed)uv lock --checkandgit diff --checkThe same branch code also passed the documentation type check and production build (
66 pages), plus a focused type check with no branch-added diagnostics compared withmain, before the final dependency-only rebase.Earlier branch validation on an M4 Max covered the MPS JAX backend, DeepSeek-V3 against its Hugging Face reference, and Qwen3-0.6B forward, backward, optimizer update, and sampling. Those hardware results predate the latest rebase and fallback fixes; current fixes have CPU regression coverage but have not been rerun on Apple hardware.
Limitations
jax-mpsremains experimental and supports one Apple GPU.einsumfallback until batched scatter support lands upstream.Note
Medium Risk
Changes shared JAX attention/generation paths and training–sampling weight coherence; incorrect invalidation or MPS fallbacks could affect correctness on all platforms when jax-mps is installed, though regressions are partly covered by new tests.
Overview
Adds opt-in Apple Silicon support for the JAX backend via a new
mpsextra (jax-mpson macOS arm64), plus docs forJAX_PLATFORMS=mpsLoRA training/sampling and an end-to-end Tinker RL smoke path.Runtime workarounds for jax-mps limits: causal attention (with padding masks) forces XLA SDPA when the jax-mps patch is active; decoding uses MPS-specific KV-cache updates and attention-mask updates instead of
vmap(dynamic_update_slice)/.at[...].set.Sampler weight lifecycle: ephemeral
save_weights_for_samplersyncs can skip disk (persist=False) while marking in-memory weights as loaded; optimizer steps and training checkpoint restore clearloaded_checkpoint_idso sampling cannot reuse stale LoRA weights. Dependency overrides widentransformers/ml_dtypespins beyond Linux-only for the JAX stack on macOS.Tests cover MPS attention routing, KV-cache fallback, ephemeral sampler checkpoints, and post-restore sampler reload.
Reviewed by Cursor Bugbot for commit 8ef4c5a. Bugbot is set up for automated code reviews on this repo. Configure here.