Add Apple Silicon (MPS) support with bf16 autocast#88
Draft
andeplane wants to merge 1 commit into
Draft
Conversation
- Select mps device when CUDA is unavailable, with bf16 autocast - Make autocast contexts device-aware (heads keep fp32 on all backends) - Downcast precomputed RoPE freqs to complex64 on MPS (no float64 support) - Fix matplotlib>=3.9 compat: cm.get_cmap removed, use matplotlib.colormaps Runs with --use_sdpa (FlashInfer is CUDA-only). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 17, 2026
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
demo.pyon Apple Silicon GPUs (MPS backend), tested on an M4 / 48 GB withlingbot-map-long.pton the bundledexample/courthousescene (--use_sdpa, since FlashInfer is CUDA-only).mpswhen CUDA is unavailable; run bf16 under a device-aware autocast contextautocast('cuda', enabled=False)does not disable autocast on other device types, so heads would silently run bf16 on MPS)matplotlib>=3.9compat in the viewer (cm.get_cmapwas removed in 3.9)CUDA behavior is unchanged in all paths.
Related PRs
--deviceflag, auto-SDPA, the same RoPE complex64 downcast) but runs MPS in fp32 without autocast. This PR runs bf16 on MPS — matching the CUDA inference dtype at roughly half the activation/KV memory — which is what required the device-aware autocast and fp32-head-guard changes above. Happy to rebase onto Add Mac MPS accelerated inference support #17's--deviceUX if that PR is preferred as the base.utils/device.pydevice/dtype resolution layer and soft FlashInfer→SDPA fallback; if it lands first, the MPS branch here would slot naturally into those helpers.demo.pyflags.Testing
example/courthouse(286 frames, streaming,--mask_sky --use_sdpa) on M4 (macOS 26, torch 2.13): full run in progress at time of writing (~1.5 it/s early, slowing as the KV cache grows); will confirm completion + viewer output in a comment🤖 Generated with Claude Code