Repository navigation
fix(cli): make unsloth doctor MLX-aware on Apple Silicon - #14457
Conversation
`unsloth doctor` only knew how to probe CUDA/ROCm GPUs. On an Apple Silicon Mac running the MLX backend it printed "=== GPUs (0) ===", a false "PROBLEMS FOUND" verdict with an `nvidia-smi` hint, and exited 1 - even though `unsloth train` works there via `unsloth_zoo.mlx`. Detect the active backend with the repository's own MLX gate (`should_use_mlx_training_backend`) and, when it is active, report the MLX/Metal/device information instead of the CUDA/NCCL sections. The verdict becomes healthy (exit 0) when MLX, Metal and `unsloth_zoo.mlx` are all present, and only reports hints for real problems. The CUDA path is unchanged.
|
Tested this on an Apple M5 (32 GB, macOS 26.6, mlx 0.32.3, unsloth_zoo 2026.10.6) at The bug is real and this fixes it. On the base, I blocked a few imports to try the failure modes, and three things came up:
One small thing in the tests: Not tested: Linux CUDA or ROCm hosts (the CUDA branch is unchanged and the 34 existing tests still pass), Intel Macs, and an installed wheel instead of the source tree. |
…latform gate, require both zoo MLX modules
|
Pushed fixes for the three gaps and the test from my earlier comment to this branch as --- a/unsloth_cli/commands/doctor.py
+++ b/unsloth_cli/commands/doctor.py
@@
import importlib
import importlib.metadata
-import importlib.util
import os
@@ def mlx_backend_active() -> bool:
if os.environ.get("UNSLOTH_FORCE_GPU_PATH") == "1":
return False
+ # Not gated on mlx being importable: a Mac without it should get the MLX
+ # verdict's install hint, not the CUDA path's nvidia-smi one.
try:
- if importlib.util.find_spec("mlx") is None:
- return False
from studio.backend.core.training.training import should_use_mlx_training_backend
return bool(should_use_mlx_training_backend())
except Exception:
- return False
+ # The repo gate is a platform check; keep it if the studio backend can't import.
+ return platform.system() == "Darwin" and platform.machine() == "arm64"
@@ def collect_mlx_info() -> dict:
+ info["zoo_mlx"] = True
for module in ("unsloth_zoo.mlx.trainer", "unsloth_zoo.mlx.loader"):
try:
importlib.import_module(module)
except Exception as e:
info["errors"].append(f"{module}: {type(e).__name__}: {e}")
- else:
- info["zoo_mlx"] = True
+ info["zoo_mlx"] = False
Test changes in
The three new behaviour tests fail on Re-run on the same M5:
|
|
@codex review |
Codex Review SummaryThis 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. |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Codex review is clean at |
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Pushed Changes in this push
Checks at this commit
|
…rs at unsloth studio update
…l/unsloth into leo/pr-14457-doctor-mlx-fixes
|
Pushed Changes since
Checks at this commit
|
|
Pushed One thing changed on main underneath this PR: #14374 taught the CUDA path to pass when it sees Metal. So on main, a healthy Mac no longer fails
Codex is clean at this commit (review). CI on the mirror: 13 passed, 8 skipped, 2 failed, and neither failure involves |
|
Status at
Upstream CI is waiting on workflow approval. |
What
unsloth doctoronly knew how to probe CUDA / ROCm GPUs. Before #14374, a healthy Apple Silicon Mac, where Unsloth trains through the MLX backend (unsloth_zoo.mlx), got a false failure:Since #14374, main passes a Mac as soon as it sees Metal, but it still never checks whether MLX can train. With
mlx_lmormlx_vlmbroken, main'sunsloth doctorsays OK and exits 0 while Unsloth Studio is chat-only. This PR runs the same MLX check Unsloth Studio uses, so doctor's answer matches whether training will actually work.Why this is a real gap, not a cosmetic one
The MLX backend is a first-class path in this repo —
unsloth train,unsloth chat,unsloth inferenceandunsloth exportall detect it and run on Apple Silicon.doctoris the one command that was never taught about it, and it is the command users reach for first when something goes wrong.This is the same machine, same install, same process — only the doctor was blind:
The fix
doctornow asks the repository's own gate which backend is live (studio.backend.core.training.training.should_use_mlx_training_backend) and, when MLX is active, runs an MLX preflight instead of the CUDA/NCCL one:Details:
mlx_backend_active(): honoursUNSLOTH_FORCE_GPU_PATH=1, then defers to the repo'sshould_use_mlx_training_backend()gate. If the Unsloth Studio backend can't be imported, it falls back to the same check that gate makes (macOS on Apple Silicon). It doesn't requiremlxto be importable, so a Mac withoutmlxgets the MLX verdict's "install mlx" hint instead of the CUDA path'snvidia-smione.collect_mlx_info(): collects the platform, themlxandunsloth_zooversions, Metal availability, and the device name, architecture and memory frommx.device_info().unsloth_zoo.mlxonly counts as present when bothunsloth_zoo.mlx.trainerandunsloth_zoo.mlx.loaderimport. It also runsmlx_stack_blockers()fromstudio/backend/utils/mlx_repair.py, the same check that decides whether Unsloth Studio can train on a Mac (mlx-lm/mlx-vlmimports and minimum versions). It never raises.verdict_mlx(info): a pure function, in the same style as the existingverdict(). It reports healthy only whenmlx,unsloth_zoo.mlx, the MLX stack check, Metal and a device all pass. A stack check that couldn't run counts as a failure, since training needs the same modules. Every repair hint saysunsloth studio update, never a plainpip install, which can move Transformers to a version Unsloth Studio can't use._gpu_checks()is untouched; the only change is the branch that chooses between_mlx_checks()and_gpu_checks(timeout).Tests
unsloth_cli/tests/test_doctor_mlx.pyhas 25 tests, all runnable without a GPU. They cover:mlx, anunsloth_zoowithout MLX, only one of the two zoo MLX modules importing, the MLX stack check reporting a problem or not running at all, no Metal, no devicemlxis missingpip installUNSLOTH_FORCE_GPU_PATHdoctorexiting 0 on the MLX path and keeping the CUDA path when MLX is offThe two CUDA tests in
test_doctor_gpus.pyare pinned to the CUDA path so they don't pick up the MLX path on an Apple Silicon host.Measured at
4be4c982ea:pytest unsloth_cli/tests/test_doctor_mlx.py unsloth_cli/tests/test_doctor_gpus.pypytest tests/security/test_lint_risky_loaders.pyunsloth doctoron an Apple M5 (32 GB, macOS 26.6, mlx 0.32.3)mlx_lmbroken or structlog missinguv pip installof this branch (no mlx, no zoo)unsloth studio update, exit 1unsloth doctor(block-compile tests, a Windows WMI-timeout test)Not run: Linux CUDA or ROCm hosts (the CUDA path is unchanged by this PR).
Notes
unsloth_zoo.mlxhas shippedMLXTrainer/FastMLXModelfor a while, and this repo already routestrain,chat,inferenceandexportto it. This PR only teaches the preflight about it.mx.metal.device_info()is deprecated in favour ofmx.device_info(); the code prefers the new API and keeps the old one only as a fallback.📎 Porting index: https://github.com/shadyuwugurl/mlx-lab —
docs/PR_INDEX.mdlists every upstream PR in this effort,docs/FINDINGS.mdrecords the Apple Silicon platform findings, anddocs/MODEL_MATRIX.mdshows the verified model matrix on an M5.