Skip to content

Don't force CPU in write_basic_config on Apple Silicon - #4498

Open
udsy19 wants to merge 1 commit into
huggingface:mainfrom
udsy19:write-basic-config-mps
Open

udsy19 wants to merge 1 commit into
huggingface:mainfrom
udsy19:write-basic-config-mps

Conversation

@udsy19

@udsy19 udsy19 commented Nov 3, 2026

Copy link
Copy Markdown

What does this PR do?

write_basic_config (used by accelerate config default) has no branch for MPS, so on Apple Silicon it falls through to the CPU-only branch and writes use_cpu: true. Any script launched with that config then runs on the CPU even though MPS is available. Launching without a config, or using the interactive accelerate config, correctly uses MPS.

Repro on an M-series Mac:

python -c "from accelerate.utils import write_basic_config; write_basic_config(save_location='cfg.yaml')"
accelerate launch --config_file cfg.yaml script.py   # Accelerator().device -> cpu (expected mps)

This adds an MPS branch that writes a single-process, non-CPU config, plus test_write_basic_config_mps in tests/test_cli.py, which mocks MPS availability so it also runs on CPU CI. The test fails on main (use_cpu is True) and passes with the fix; tests/test_cli.py passes (44 passed, 1 skipped).

Before submitting

  • Did you read the contributor guideline?
  • Did you write any new necessary tests?

Who can review?

@SunMarc

write_basic_config (and so `accelerate config default`) had no branch
for MPS, so on Apple Silicon it fell through to the CPU-only branch and
wrote use_cpu: true. Scripts launched with that config then ran on the
CPU even though the MPS device was available. Add an MPS branch that
writes a single-process, non-CPU config.

Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
@mlzerotoheroyoutube

Copy link
Copy Markdown

I tested this on an Apple M5 Pro (macOS 26.6.2, Python 3.14, torch 2.15.0), PR head 4c8407a against main at f47439c.

main this PR
write_basic_config() writes use_cpu: true use_cpu: false
accelerate launch --config_file <that file> → Accelerator().device cpu mps
same with write_basic_config(mixed_precision="fp16") cpu mps
accelerate config default, then accelerate launch with no --config_file not run mps
pytest tests/test_cli.py 1 failed (test_write_basic_config_mps), 43 passed, 1 skipped 44 passed, 1 skipped

test_accelerate_test also runs on MPS with the new default config (Device: mps, all training checks pass). So the fix does what it says on real Apple Silicon, not only with the mocked MPS in the test. LGTM.

(Testing was done with help from Claude Code; I checked the results.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants