Repository navigation
Resolve device auto to Apple Silicon MPS in instruction_tuning - #544
davemaguire wants to merge 2 commits into
Conversation
resolve_device() previously fell back straight to CPU on Macs. It now tries CUDA, then MPS, then CPU, and validates an explicit "mps" request. Co-Authored-By: Claude <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d787b53f10
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| elif torch.backends.mps.is_available(): | ||
| device = "mps" |
There was a problem hiding this comment.
Avoid auto-selecting MPS when default bf16 is unsupported
On Apple Silicon running macOS 12.3 or 13, this predicate can be true even though PyTorch's MPS backend only supports bfloat16 on macOS 14+. The checked-in config enables bf16 (code/instruction_tuning/configs/sft_olmo2_1b.yaml:22), and load_model constructs a bfloat16 model before .to(device) (utils.py:118-124), so the documented default command now fails while moving the model instead of retaining its previous CPU path. Gate MPS selection on bfloat16 support or choose a compatible dtype/fallback.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Hi, I remember doing this cuda-mps-cpu order in the first place and backed out for that ~same codex review (and simplicity) in #514 (review). Although no idea if MPS is more stable/better now
Co-Authored-By: Claude <noreply@anthropic.com>
Thanks Nathan for the book. This is a great resource. I opened this pr adding the apple mps device to
resolve_device()for ch 4. As is, the script runs on my mac's CPU. With this change it can actually finish. I didn't make the corresponding modification to the script for other chapters.Claude Opus 5.5 — full change description
What changed
code/instruction_tuning/utils.py:resolve_device()now checkstorch.backends.mps.is_available()after CUDA whendevice="auto", and accepts and validates an explicitdevice="mps". The error message for unsupported values listsmps.Why
Running
uv run python -m instruction_tuning.train --config instruction_tuning/configs/sft_olmo2_1b.yamlon a Mac trained on the CPU even though the GPU was available.How to test
On an Apple Silicon Mac:
I checked this on torch 2.15.0 on macOS, and a bf16 forward and backward pass also ran on MPS. I didn't run a full training job.
Notes / follow-ups
utils.py, as requested. TheConfig.devicetype hint (Literal["auto", "cuda", "cpu"]) and the--deviceCLIchoicesstill leave out"mps", so--device mpsis rejected by argparse.autoworks. A follow-up could add"mps"to both.🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com