Add MPS (Apple Silicon) support via jax-mps#69
Open
vlordier wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds Apple Silicon (MPS) support by introducing an mps extra dependency, documenting installation/usage, and tweaking MJX model/data creation to work with jax-mps.
Changes:
- Add
mpsoptional dependency (jax-mps) inpyproject.toml. - Update
Sim.build_mjx_modelto force the JAX implementation when running on MPS. - Document MPS installation and usage in the README.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pyproject.toml | Adds an mps extra to install jax-mps. |
| crazyflow/sim/sim.py | Forces MJX to use the JAX impl for MPS devices. |
| README.md | Documents crazyflow[mps] installation and MPS runtime notes. |
Comment on lines
+238
to
+241
| # MJX does not recognize 'mps' as a platform; force JAX impl to work with jax-mps. | ||
| impl = "JAX" if self.device.platform == "mps" else None | ||
| mjx_model = mjx.put_model(mj_model, device=self.device, impl=impl) | ||
| mjx_data = mjx.put_data(mj_model, mj_data, device=self.device, impl=impl) |
|
|
||
| [project.optional-dependencies] | ||
| gpu = ["jax[cuda12]"] | ||
| mps = ["jax-mps"] |
Comment on lines
+239
to
+241
| impl = "JAX" if self.device.platform == "mps" else None | ||
| mjx_model = mjx.put_model(mj_model, device=self.device, impl=impl) | ||
| mjx_data = mjx.put_data(mj_model, mj_data, device=self.device, impl=impl) |
Always pass impl='JAX' to mjx.put_model/put_data — this works with any JAX backend (cpu, gpu, tpu, mps) and avoids MJX's platform whitelist check that rejects unknown platforms. Add mps optional dependency to pyproject.toml. Document MPS usage in README.
a55a6ab to
e1e6465
Compare
Collaborator
|
Hey @vlordier , thanks for the PR. As far as I know, there is a |
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
Enables crazyflow to run on Apple Silicon Macs using the jax-mps plugin, which exposes Apple's Metal Performance Shaders as a JAX backend.
Changes
impl='JAX'tomjx.put_model/mjx.put_datawhendevice.platform == 'mps'. MJX's_resolve_implonly recognizescpu,gpu, andtpuplatforms; forcing the JAX impl bypasses this check while still placing data on the MPS device.mps = ["jax-mps"]optional dependency.Testing
All 331 tests (262 unit + 69 integration) pass on an M-series MacBook Pro with
JAX_MPS_ASYNC_DISPATCH=1. Thedevice='cpu'tests also pass since jax-mps auto-registers alongside the CPU backend.Performance (first-principles physics, 1 drone)