Skip to content

Studio: repair MLX on Chat only Macs and offer MLX models exactly where they run - #19040

Merged
danielhanchen merged 10 commits into
unslothai:mainfrom
Lyxot:fix/chat-only-mlx-followups
Nov 23, 2026
Merged

danielhanchen merged 10 commits into
unslothai:mainfrom
Lyxot:fix/chat-only-mlx-followups

Conversation

@Lyxot

@Lyxot Lyxot commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #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 Studio: install MLX on Chat only Macs so MLX models can chat #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

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

Chat only Macs serve MLX models since the MLX stack ships with --no-torch installs, but the startup self-heal still declined them, so a missing or broken mlx, mlx-lm or mlx-vlm left MLX models unloadable with no way back short of the full install. The self-heal now repairs a no-torch Mac whose verdict blames the MLX stack; it 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. 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 keeps settling at once.
/api/train/start refused a Chat only Mac only while it reported the MLX device. One whose MLX stack was missing or still being repaired reported cpu, and on Apple Silicon trains_on_cpu() is false for no_torch, so the request passed validation and failed later in the worker. The refusal now keys on the install itself: an Apple Silicon --no-torch install never trains, whatever the state of its MLX stack.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 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-23T15:32:36.133934Z 1c4b4a4 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.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…re MLX is served

MLX loads plain safetensors checkpoints as well as MLX-quantized ones, so a measured Chat only Mac that serves MLX now lists cached, local, Discover and Hub search checkpoints as a full Mac does, and a Chat only host that does not serve MLX lists GGUF only. Every picker and chat auto-load gate decides this through isServedByMlx, which reads mlx_inference and falls back to the verdict's reason for older backends. Until /api/health answers, the Chat only guess narrows nothing; task pickers such as Transcribe keep the Mac rule. Settings' full-install copy says Chat only runs GGUF and MLX where MLX is served, in every locale.
@Lyxot
Lyxot force-pushed the fix/chat-only-mlx-followups branch from ba1241a to 91c711b Compare November 23, 2026 10:37
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 91c711b2a9

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

… model picker barrel

The barrel import made src/features/chat/index.ts statically reachable from the
sidebar's full install dialog, which the Vite config rejects as an ineffective
dynamic import, failing npm run build (and install.sh) on this branch.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 237b37af61

ℹ️ 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 to Imagineer99/unsloth that referenced this pull request Nov 23, 2026
danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Nov 23, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 23, 2026
danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Nov 23, 2026
A GPU-less host with torch is Chat only (no_gpu) but loads safetensors
checkpoints on the CPU, and the composer listed them before. Hide cached and
local checkpoints only on a measured Chat only host that neither serves MLX
nor trains on the CPU.

[skip ci]
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 803f83ceea

ℹ️ 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 to Imagineer99/unsloth that referenced this pull request Nov 23, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Composer (macos-latest, browsers) on the latest head fails one frontend unit test, and it comes from this PR's picker change rather than the runner:

not ok 90 - composer search keeps Mac-native repos, as the header picker did
  location: studio/frontend/tests/composer-model-picker.test.ts:442
  The input did not match the regular expression /discoverListsCheckpoints\(\s+isMac,[\s\S]{0,120}?\) &&\s+isRecommendableFormat\(r\.id, r\.isGguf, true, r\.quantMethod\)/

That test reads composer-model-picker.tsx and pins the composer search filter to discoverListsCheckpoints(isMac, ...) && isRecommendableFormat(r.id, r.isGguf, true, r.quantMethod), which this branch rewrites. If the new filter still keeps Mac-native repos in composer search, the test needs updating to the new shape (ideally checking the behaviour on a sample row rather than the source text); if it no longer does, that is the regression the test is there for.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 23, 2026
@NilayYadav NilayYadav self-assigned this Nov 23, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 895a9bafd0

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

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c4b4a481e

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

and (
_NO_TORCH_SETTLED_EPOCH == current_detection_epoch()
or not _mlx_distribution_installed()
or (not _mlx_distribution_installed() and _no_torch_mac_without_mlx_wheels())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor the MLX wheel blocker when old MLX metadata exists

If an Apple Silicon Chat-only venv is below the MLX wheel floors (for example, Python 3.9) but retains an older or broken mlx distribution, this short-circuit skips the wheel blocker and publishes mlx_unavailable. The newly enabled no-torch repair then attempts to install a pinned stack that the host cannot install, keeping /api/health provisional until the futile install finishes or reaches its 900-second timeout. Previously, no-torch installs settled without attempting that install. Apply _no_torch_mac_without_mlx_wheels() to every unusable no-torch stack, regardless of whether distribution metadata is present.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping this as is. Only an unusable stack reaches this branch, and on a host the MLX wheels skip the repair's wheels-only resolve fails at once and settles the verdict to no_torch, the same end state. Skipping the probe whenever mlx metadata is present would instead settle no_torch from a version parse alone, which drops the post-warm overturn the existing tests rely on.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 1c4b4a481e

ℹ️ 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
danielhanchen merged commit 956e627 into unslothai:main Nov 23, 2026
danielhanchen added a commit that referenced this pull request Nov 23, 2026
…ness (#19121)

## Problem

Three Studio tests are red on `main` since #19040 (they fail on `Repo
tests (CPU, studio)` for every PR based on it, for example #18775 and
#19110):

-
`tests/studio/test_chat_autoload_failure_gate.py::test_a_chat_only_mac_without_mlx_skips_its_cached_mlx_repo`
-
`tests/studio/test_chat_autoload_failure_gate.py::test_a_chat_only_mac_auto_loads_an_omlx_folder_with_a_plain_name[false-False]`
-
`tests/studio/test_model_picker_contracts.py::test_cached_non_gguf_rows_get_the_chat_only_platform_gate`

Bisected: all three pass on `956e62778b^` and fail on `956e62778b`
(#19040).

## Cause

#19040 is correct. It routes every Chat only MLX gate in
`chat-adapter.ts` through the shared `isServedByMlx(isGguf, deviceType,
chatOnlyReason, mlxInference)`, which answers from `mlx_inference` when
the backend reports it.

The tests were behind it:

- The auto-load harness kept a hand-written `isServedByMlx` that took
three arguments and ignored `mlx_inference`. A Chat only Mac reporting
`mlx_inference: false` therefore looked like it served MLX, and the
scenarios loaded an MLX repo where the shipped code does not.
- The contract test pinned the old `platform.mlxInference === true`
literal, which #19040 replaced with `return
platformServesMlx(platform);`.

## Fix

- The harness now inlines `NO_MLX_REASONS` and `isServedByMlx` from
`per-model-config.ts` as shipped, the same way it already inlines
`isOtherCacheSnapshot`, `llamaServerLoadFields` and the server-model
wait gate. A missing definition fails with a clear message instead of a
silent stub.
- The contract test pins the new shape: the cached-row gate returns
`platformServesMlx(platform)`, and that helper calls
`isServedByMlx(...)` with `platform.mlxInference`.

## Verification

- Both files: 305 passed (were 3 failed on `main`).
- Sabotage 1: drop the `typeof mlxInference === "boolean"` branch from
`isServedByMlx` in `per-model-config.ts`; the two harness scenarios fail
again.
- Sabotage 2: pass `null` instead of `platform.mlxInference` in
`chat-adapter.ts`; the contract test and both scenarios fail.

Tests only; no product code changes.
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-zoo-staging-2 that referenced this pull request Nov 24, 2026
…lothai#2701)

## Problem

Unsloth Studio's Chat only installs (`--no-torch`) on Apple Silicon
serve MLX models, including vision models. Two vision families failed to
load there:

- **SmolVLM / Idefics3 / Idefics2:** the load stops with `Unrecognized
image processor`. Transformers 5 tags `image_processing_pil_idefics3`
(also `idefics2` and `smolvlm`) as needing `torch`, `torchvision` and
`vision`, yet those modules import neither. Without torch,
`get_image_processor_class_from_name("Idefics3ImageProcessorPil")`
therefore returns a placeholder (`DummyObject`), and
`AutoImageProcessor` rejects the checkpoint. mlx-vlm's own Idefics3
processor goes through `AutoImageProcessor`, so it hits the same
placeholder.
- **DeepSeek-VL2 / DeepSeek OCR:** the load fails with `modeling_llama
requires the PyTorch library`.
`_patch_deepseek_ocr_transformers_import_compat` probes `modeling_llama`
with `hasattr`. Without torch, that module is a placeholder whose
attribute access raises `ImportError`, which `hasattr` does not catch.

## Changes

- `_patch_torch_free_image_processor_lookup()` wraps
`get_image_processor_class_from_name`. When the original returns a
placeholder, it imports the class from the module transformers records
for it (`_class_to_module`), and keeps the placeholder if that class is
still a placeholder.
- It never replaces a real class, so backend selection with torch
installed is unchanged.
- It skips Transformers 4's `(slow, fast)` tuple entries, which have no
PIL entry.
- It is idempotent, and `FastMLXModel.from_pretrained` calls it ahead of
the runtime-quantized, distributed and plain VLM load paths.
- The DeepSeek compat patch now treats `ImportError` from the
`modeling_llama` placeholder as "nothing to alias".

I checked every mlx-vlm family against a torch-free transformers 5.5.4.
Idefics2, Idefics3 and SmolVLM are the only chat families whose image
processor needs this. LFM2-VL and Llama 4 ship their own torch-free
processors in mlx-vlm, and SAM 3 and PP-DocLayout are not chat models.

## Validation

```bash
python -m pytest -q tests/test_mlx_vlm_label_masks.py
# 473 passed
```

The new tests cover:
- placeholder resolution, passthrough of real classes, idempotence, and
the tuple entries;
- the call site;
- the DeepSeek placeholder module.

Each was mutation-checked: reverting the production change makes exactly
that test fail.

Live, on an isolated Unsloth Studio Chat only install (no torch, mlx-vlm
0.8.0, transformers 5.5.4), image chat through the backend:

| Model | Before | After |
|---|---|---|
| `mlx-community/SmolVLM-256M-Instruct-4bit` | `Unrecognized image
processor` | "Circle." |
| `mlx-community/deepseek-vl2-tiny-4bit` | `modeling_llama requires the
PyTorch library` | "The shape is a circle and the color is red." |
| `mlx-community/Qwen2.5-VL-3B-Instruct-4bit` | works | works
(unaffected) |

Companion Unsloth Studio PR: unslothai/unsloth#19040.

---------

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants