Repository navigation
Studio: repair MLX on Chat only Macs and offer MLX models exactly where they run - #19040
Conversation
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.
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. |
…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.
ba1241a to
91c711b
Compare
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ 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". |
… 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.
[skip ci]
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ 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". |
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]
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ 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". |
|
That test reads |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ 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 |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 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()) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ 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". |
…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.
…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]>
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
utils/mlx_repair.py) still opted out of--no-torchinstalls. 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-versionunsloth studio updateskips the dependency pass, and the Desktop's repair button upgrades to the full install, torch included./api/train/startaccepts a Chat only Mac whose MLX is not loaded. The refusal keyed onDEVICE == MLX. A Chat only Mac whose MLX stack is missing reportscpu, andtrains_on_cpu("no_torch")is false on Apple Silicon, so the request passed validation and failed later in the worker.mlx_inference(older backend) as "served";unsloth/gemma-3-270m-itloads and chats on a Chat only Mac);Changes
utils/mlx_repair.py,utils/hardware/hardware.py):mlx,mlx-lmandmlx-vlm, never torch.mlx_unavailable, so the repair runs, unless the MLX wheels cannot install there (macOS < 14, Python < 3.10). That case staysno_torch.mac/no_torch/mlx_inference: true.no_torchfor the live lifespan and any later one, so the sidebar stops polling.UNSLOTH_DISABLE_MLX_AUTOREPAIR=1still settles at once.routes/training.py): a newhardware.chat_only_mac_install()makes/api/train/startrefuse any Apple Silicon--no-torchinstall, whatever its device.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./api/healthanswers, so the guess narrows nothing.descriptionMlx/confirmDescriptionMlxstrings, 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
Validation
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:
mlx-vlmuninstalled, the self-heal reinstalled it in about 6 s, and health went from held tomac/no_torch/mlx_inference: true;uv pip listshows no torch afterwards;/api/train/startreturns 400 with the Chat only message;unsloth/gemma-3-270m-it) loads through MLX and chats.UI before / after
Chat model picker, Discover tab, searching
gemma-3-270m-iton a measured Chat only Mac whose MLX stack is not served (base0721b892bvs head237b37af6; the/api/healthverdict was set to Apple Silicon,no_torch,mlx_inference: falsein 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. Withmlx_inference: truethe head lists the plain checkpoints again, as a full Mac does.