Skip to content

Studio: install MLX on Chat only Macs so MLX models can chat - #18727

Merged
danielhanchen merged 7 commits into
unslothai:mainfrom
oobabooga:studio-mlx-chat-only-mac
Nov 22, 2026
Merged

danielhanchen merged 7 commits into
unslothai:mainfrom
oobabooga:studio-mlx-chat-only-mac

Conversation

@oobabooga

Copy link
Copy Markdown
Member

Problem

On Apple Silicon, a Chat only install (the Desktop "Chat only (GGUF)" checkbox, or install.sh --no-torch) never installed MLX, because every MLX step in install_python_stack.py was gated on IS_MAC_ARM and not NO_TORCH. Loading an MLX model on such a Mac fails with Unsloth: torch not found. Please install torch first. MLX does not need torch, so these Macs should get it.

Fix

  • Installer: the MLX install, re-resolve and health report run on every Apple Silicon install, --no-torch included. The opt-in mflux image engine stays off there, since mflux declares torch.
  • Backend: unsloth-zoo's MLX trainer and export still import torch, so a Chat only Mac with a working MLX stack reports device mlx but stays chat_only with reason no_torch. Export reports no_torch, and /api/train/start returns a 400 pointing to the full install.
  • mlx_inference in /api/health: true when the detected device is MLX. no_torch alone cannot say whether MLX loads, because a Chat only Mac without usable MLX (macOS 13, Python 3.9, a broken install) reports the same reason. The frontend and unsloth start decide MLX eligibility from this field, and fall back to the reason for a backend that does not send it.
  • Frontend: the Model Hub, chat auto-load and both model pickers no longer treat "chat only" as "GGUF only" on a Mac that serves MLX. Each decides whether a row is MLX through one of two shared helpers: cachedRepoIsMlx (name, card tag, library) or localRowIsMlx (names, path, oMLX source).
  • Copy: the Desktop checkbox drops "(GGUF)" in every locale, and the README's --no-torch lines mention MLX on Apple Silicon.

Size

On an M1 (macOS 14.5, Python 3.13), ./install.sh --local --no-torch adds 79 MB of downloads and 279 MB on disk (venv 972 MB to 1,251 MB). Most of it is mlx-metal (45 MB download, 174 MB installed) and opencv-python (26 MB, 43 MB, pulled in by mlx-vlm). No existing package changes version. An existing Chat only Mac downloads the same set on its next update.

Behavior boundaries

  • Train and Export stay off on Chat only Macs. The full install is still how to get them.
  • macOS 13 and Python 3.9 still skip MLX, since mlx 0.32.4 has no wheels for them.
  • The startup MLX self-heal still does not reinstall MLX unattended on a no-torch install. unsloth studio update does.
  • The Settings "Install type" row and the upgrade dialog still say a Chat only install runs GGUF models.

Verification

On the M1, with fresh --no-torch installs. The last column runs this branch's backend on the main-branch install, which has no MLX:

main this PR this PR, no MLX on disk
Device / mlx_inference cpu / absent mlx / true cpu / false
Load mlx-community/Qwen2.5-0.5B-Instruct-4bit fails, "torch not found" loads, answers "Paris" fails, "torch not found"
unsloth start accepts an MLX model not run yes no
/api/train/start 200, job queued 400, Chat only message 200, as on main
Export off, no_torch off, no_torch off, no_torch

The Hub, picker and auto-load changes are covered by unit and scenario tests, not exercised in a browser.

On Linux, the backend, CLI and installer test files for these paths: 3,624 passed. The one failure, test_offload_planner_seam.py::test_linux_smt_and_non_smt_core_counts, also fails on main. The frontend tests in the affected files: 4,281 passed. tsc is clean, eslint reports no new findings, and ruff check passes.

A --no-torch (Chat only) install on Apple Silicon skipped the MLX stack, so
MLX models failed to load with "torch not found". Install mlx, mlx-metal,
mlx-lm and mlx-vlm on those installs too.

unsloth_zoo's MLX trainer and export still import torch, so a Chat only Mac
now detects as an MLX device for chat while staying chat_only with reason
no_torch: Train and Export stay off, export_capability reports no_torch, and
/api/train/start refuses with a clear message. The frontend and
`unsloth start` no longer treat no_torch as unable to load MLX. The opt-in
mflux image engine stays off on --no-torch installs, since it declares torch.
/api/health now reports mlx_inference, true when the detected device is
MLX. A Chat only Mac reports no_torch both with a working MLX stack and
without one (macOS 13, Python 3.9, a broken install), so the frontend
and `unsloth start` no longer infer MLX from the reason. isServedByMlx
reads mlx_inference and falls back to the reason set (no_torch included)
for a backend that does not send it.

Model Hub offers Run for MLX models and their precision folders on a
Chat only Mac that serves MLX, and drops the GGUF-only chip there. Chat
auto-load and the Downloaded view keep cached MLX repos on such a Mac
instead of discarding every cached non-GGUF repo.

The Desktop install checkbox drops "(GGUF)" in every locale, and the
README describes --no-torch as chat only with MLX on Apple Silicon.
Chat auto-load matched a cached repo as MLX by name only, while the
Downloaded picker also reads the card tag and library, so a tag-only MLX
repo showed in the picker but was skipped at auto-load. Both now use
cachedRepoIsMlx. The Hub inspector now classifies a local folder by its
path, title and oMLX source the way its inventory row does, so Run is
offered for a local MLX folder on a Mac that serves MLX.

/api/health takes mlx_inference from the same seqlocked snapshot as the
verdict instead of a later DEVICE read. The frontend resets mlxInference
to null on a settled reply that omits it, so a reconnect to an older
backend falls back to the reason.
Chat auto-load and the picker's local MLX filter matched a local model
by its names only, while the Hub inventory also counts an oMLX source.
An oMLX folder with a plain name such as Qwen3-8B-4bit got Run in the
Hub, but auto-load skipped it and started the default GGUF download.
Both now use localRowIsMlx, built on the Hub's namedOrTaggedMlx.
The composer classified a local row by its id alone, so an oMLX folder
with a plain name such as Qwen3-8B-4bit showed as Safetensors and was
missing under the MLX filter, while the Hub and chat auto-load already
read it as MLX. chatLocalModelOptions now carries the scan's source on
the option, and loraFormat asks localRowIsMlx like the other two.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T05:31:00.280767Z 56bcc48 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 56bcc4850d

ℹ️ 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".

danielhanchen added a commit that referenced this pull request Nov 21, 2026
…ed (#18735)

## Problem

`Windows No Compiler CI` failed 5 of its 21 completed runs in the last
day, on `main` (run 44728450095) and on unrelated PRs (#16729 three
times, #18727). Every failure was the same void, always in `Require the
desktop mode to run without a compiler` (`install.ps1 --tauri --local`):

```
the file watcher on C:\Users\RUNNER~1\AppData\Local\Temp, C:\Users\runneradmin\AppData\Local\Temp raised an
error, so creations under it may have been dropped. A compile whose intermediates were deleted before the
final sweep is visible only in those events. This run cannot say whether a compiler ran.
```

None of them recorded a compiler. The `FileSystemWatcher` buffer is
already at its 64 KB maximum, so a burst of temp-file creations during
the install can still overflow it.

## Fix

`Invoke-WithCompilerWatch` takes `-Attempts` (default 1, so every
existing caller is unchanged). The two installer measurements in
`windows-no-compiler-ci.yml` pass `-Attempts 2`; the positive control
still measures once.

- A run that is void **only** because a watcher raised an error is
measured again, as a complete new measurement with its own evidence
files (`installer-tauri-attempt2-*.txt`), and a `::warning::` names the
void attempt.
- A void run is still never scored as clean: if every attempt's watcher
fails, the step fails with the same message as before.
- A run whose temp sweep could not read a directory with no watcher on
it is not retried (unchanged void).
- A compiler that event 4688 recorded is now reported as a hit even when
the watcher failed, instead of being reported as "cannot say". 4688 is
the authoritative detector, so a real compile can never be retried away.

## Tests

New pwsh tests in `tests/studio/test_installer_av_shapes.py` run the
real `Invoke-WithCompilerWatch` with `Stop-StudioTempWatch` reporting a
failed root on the first N measurements:

| Case | Result |
|---|---|
| watcher error, `-Attempts 1` | void, 1 measurement |
| watcher error once, `-Attempts 2` | measured clean on attempt 2,
attempt-2 evidence written |
| watcher error on both attempts | void, 2 measurements |
| watcher error and 4688 saw a compiler | reported as 1 compiler, not
retried |

`tests/python/test_compiler_watch_temp_scan.py` lifts the verdict block
out of the shipped script; its harness now supplies the inputs that
block reads (`$compilers`, `$Attempt`, `$Attempts`, `$Name`) for a
single compiler-free attempt.

- `tests/studio/test_installer_av_shapes.py` and
`tests/python/test_compiler_watch_temp_scan.py`: 275 passed, 1 skipped.
- Sabotage: with the script from `main`, the four new tests fail.

This PR touches `.github/scripts/Watch-ForCompiler.ps1`, so its own
`Windows No Compiler CI` run exercises the real Windows path.
@NilayYadav

Copy link
Copy Markdown
Collaborator

Tested on an Apple Silicon Mac with --no-torch installs of main and this branch.

main this PR
MLX installed no yes, no torch
Load and chat with an MLX model fails, "torch not found" works
MLX vision model with an image fails works
Chat auto load with a cached MLX model downloads a GGUF instead loads the MLX model
Hub Run on a cached MLX model not offered offered
unsloth start with an MLX model refused accepted
Train and Export off still off

Updating an existing Chat only install and upgrading to the full install both work as expected. PR tests pass and fail on main.

@danielhanchen danielhanchen self-assigned this Nov 22, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 22, 2026
danielhanchen added a commit that referenced this pull request Nov 22, 2026
… test (order-dependent red) (#18867)

## Summary


`studio/backend/tests/test_warm_window_review_fixes.py::test_an_absent_torch_is_still_just_absent`
fails whenever torch has not been imported earlier in the process. It
failed on the staging cross-platform leg for #18727 (ubuntu-latest), and
it fails on `main` when the file runs on its own:

```
AssertionError: a --no-torch install would be reported as a detection failure
assert 'stale' is None
 +  where 'stale' = <module 'utils.hardware.hardware'>.TORCH_IMPORT_ERROR
```

`_has_torch()` (since #14595) remembers a failed import for the current
detection epoch: while `TORCH_IMPORT_ERROR` is set,
`_TORCH_IMPORT_FAILED_EPOCH == DETECTION_EPOCH` and torch is not in
`sys.modules`, it returns `False` without trying again. The code is
right. The tests are wrong:
`test_a_broken_torch_install_is_not_reported_as_a_host_without_a_gpu`,
just above, records a failure (setting both globals) and then restores
only `TORCH_IMPORT_ERROR`. The epoch it leaves behind makes the next
`_has_torch()` short-circuit, so the absent-torch test never reaches the
import it checks. In the full CI run some earlier test has usually
imported torch, which disables the short-circuit, so this has been order
dependent rather than always red.

## Fix

An autouse fixture in that file sets `TORCH_IMPORT_ERROR` and
`_TORCH_IMPORT_FAILED_EPOCH` to `None` through `monkeypatch`, so every
test starts with no cached failure and both are restored afterwards. No
production code changes.

## Testing

- `studio/backend/tests/test_warm_window_review_fixes.py` on its own:
100 passed (`main`: 1 failed, the test above).
@danielhanchen
danielhanchen merged commit ad1fc4b into unslothai:main Nov 22, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 23, 2026
…re they run (unslothai#19040)

Follow-up to unslothai#18727, which installs MLX on Chat only (`--no-torch`) Macs
so MLX models can chat. Three gaps remained on that path; this PR closes
them without adding torch to Chat only installs.

## Problems

1. **A broken MLX stack never recovers on Chat only.** The startup MLX
self-heal (`utils/mlx_repair.py`) still opted out of `--no-torch`
installs. That rule dates from when Chat only meant no MLX at all. A
Chat only Mac with a missing, too-old or broken mlx, mlx-lm or mlx-vlm
therefore stayed unable to load MLX models. A same-version `unsloth
studio update` skips the dependency pass, and the Desktop's repair
button upgrades to the full install, torch included.
2. **`/api/train/start` accepts a Chat only Mac whose MLX is not
loaded.** The refusal keyed on `DEVICE == MLX`. A Chat only Mac whose
MLX stack is missing reports `cpu`, and `trains_on_cpu("no_torch")` is
false on Apple Silicon, so the request passed validation and failed
later in the worker.
3. **Pickers disagree about which models a Chat only Mac can run:**
- chat auto-load treated a missing `mlx_inference` (older backend) as
"served";
- the composer listed every cached and local checkpoint whatever the
verdict;
- the header picker and chat auto-load listed only MLX-named or
MLX-tagged checkpoints, though MLX also loads plain safetensors
checkpoints (a plain `unsloth/gemma-3-270m-it` loads and chats on a Chat
only Mac);
   - Discover listed plain checkpoints on any Mac;
   - the Hub inspector ignored the verdict's reason;
   - the Settings copy said Chat only runs GGUF only.

## Changes

- **Self-heal** (`utils/mlx_repair.py`, `utils/hardware/hardware.py`):
- A no-torch Mac whose verdict blames the MLX stack is now repaired. The
repair installs only `mlx`, `mlx-lm` and `mlx-vlm`, never torch.
- A no-torch Mac without MLX on disk reads `mlx_unavailable`, so the
repair runs, unless the MLX wheels cannot install there (macOS < 14,
Python < 3.10). That case stays `no_torch`.
- Train and Export stay off: after a successful repair the verdict is
`mac` / `no_torch` / `mlx_inference: true`.
- A failed repair is recorded and settles the verdict to `no_torch` for
the live lifespan and any later one, so the sidebar stops polling.
`UNSLOTH_DISABLE_MLX_AUTOREPAIR=1` still settles at once.
- **Training guard** (`routes/training.py`): a new
`hardware.chat_only_mac_install()` makes `/api/train/start` refuse any
Apple Silicon `--no-torch` install, whatever its device.
- **Frontend:**
- Every picker and auto-load gate decides MLX eligibility through the
existing `isServedByMlx()`: chat-adapter, header picker local rows and
Hub search, composer cached and local rows, Discover, and the Hub
inspector. A measured Chat only Mac that serves MLX lists non-GGUF
checkpoints as a full Mac does; a Chat only host that does not serve MLX
lists GGUF only.
- On a Mac, Chat only is a guess until `/api/health` answers, so the
guess narrows nothing.
  - Task pickers such as Transcribe keep their previous rule.
- The full-install row and dialog use new `descriptionMlx` /
`confirmDescriptionMlx` strings, in every locale, where MLX is served.

The SmolVLM, Idefics and DeepSeek-VL2 vision fixes for Chat only are in
unslothai/unsloth-zoo#2701.

## Size

No new dependencies. The self-heal reinstalls the same MLX packages a
Chat only install already ships: mlx-metal 242 MB, opencv-python 69 MB,
mlx-vlm 14 MB, about 348 MB in all. Site-packages did not grow after a
repair, and torch stays out (it would add about 340 MB).

## Risks

- The self-heal now runs on Chat only Macs. It is the same one-shot
background install full installs already get, and the same kill switch
applies.
- The picker changes widen unslothai#18727's rule: a Chat only Mac that serves
MLX now also lists plain safetensors checkpoints, which load through
MLX. A checkpoint MLX cannot load fails at load time with its error, as
it does on a full Mac.

## Validation

```bash
cd studio/backend
python -m pytest -q tests/test_mlx_autorepair_no_torch_optout.py tests/test_mlx_repair.py \
  tests/test_health_holds_verdict_during_mlx_repair.py tests/test_warm_window_review_fixes.py \
  tests/test_chat_only_reason.py tests/test_cpu_training_host.py tests/test_training_cached_start.py
# 520 passed

cd ../frontend
npm run typecheck
npm run i18n:check:strict
node --experimental-strip-types --test tests/chat-remembers-its-model.test.ts \
  tests/composer-picker-hub-sizes.test.ts tests/deferred-hardware-first-use.test.ts \
  tests/hub-on-device-filters.test.ts tests/context-pin-survives-load.test.ts \
  tests/provisional-hardware-verdict.test.ts tests/hardware-verdict-recovery.test.ts \
  tests/hub-runtime-boundary.test.ts
# 119 passed
```

Every new or changed test was mutation-checked: reverting the production
change makes that test fail.

Live, on an isolated Chat only install (no torch) running this branch:
- with `mlx-vlm` uninstalled, the self-heal reinstalled it in about 6 s,
and health went from held to `mac` / `no_torch` / `mlx_inference: true`;
- `uv pip list` shows no torch afterwards;
- `/api/train/start` returns 400 with the Chat only message;
- a plain bf16 checkpoint (`unsloth/gemma-3-270m-it`) loads through MLX
and chats.


## UI before / after

Chat model picker, Discover tab, searching `gemma-3-270m-it` on a
measured Chat only Mac whose MLX stack is not served (base `0721b892b`
vs head `237b37af6`; the `/api/health` verdict was set to Apple Silicon,
`no_torch`, `mlx_inference: false` in the browser, everything else came
from the real backend). Before, the picker offered 44 rows including
plain and bnb-4bit checkpoints that cannot load on that host; after, it
offers the 19 GGUF repos only. With `mlx_inference: true` the head lists
the plain checkpoints again, as a full Mac does.

![Discover before and after on a Chat only Mac without
MLX](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/19040/pr19040_ui-709022635d34.png)

---------

Co-authored-by: Daniel Han <[email protected]>
Co-authored-by: Nilay Yadav <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants