Skip to content

Unsloth Studio: raise the mlx-vlm floor to 0.6.4 and hold the MLX gate to the installed unsloth-zoo's floors - #18487

Merged
danielhanchen merged 7 commits into
unslothai:mainfrom
Lyxot:studio-mlx-vlm-floor
Nov 20, 2026
Merged

danielhanchen merged 7 commits into
unslothai:mainfrom
Lyxot:studio-mlx-vlm-floor

Conversation

@Lyxot

@Lyxot Lyxot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

Companion to unslothai/unsloth-zoo#2618, which raises unsloth-zoo's mlx-vlm floor to 0.6.4. This PR:

  1. Raises Unsloth Studio's mlx-vlm install floor to match.
  2. Fixes a gap in the MLX chat-only gate that the higher floor exposes.
  3. Drops two guards for MLX APIs older than any stack the gate admits.

What changed

Install floor (chore(studio): raise mlx-vlm install floor to 0.6.4)

install_python_stack.py (_MLX_VLM_SPEC) and the self-heal specs in utils/mlx_repair.py (_MLX_INSTALL_SPECS) move from mlx-vlm>=0.4.4,<=0.8.0 to >=0.6.4,<=0.8.0. 0.6.4 is the last mlx-vlm release that admits transformers 5.5; 0.6.5 and later need transformers>=5.14.

Chat-only gate (fix(studio): hold the MLX chat-only gate to the installed unsloth-zoo's MLX floors)

The gate that decides whether MLX training is usable compared the installed stack against _MLX_MIN_VERSIONS. Those are the oldest floors any published unsloth-zoo declares (mlx 0.22.0, mlx-lm 0.31.2, mlx-vlm 0.4.4). The --local overlay installs unsloth-zoo with --no-deps, so nothing lifts an older stack to a newer zoo's floors. As a result, a stack with mlx-vlm 0.6.3 or mlx 0.32.2 cleared the gate beside a zoo that requires 0.6.4 or ==0.32.4. That zoo then failed at runtime, or, for mlx 0.32.2, read row 0's KV for every batch row in GQA decode.

The new _mlx_minimum(name) returns the higher of the gate's floor and the lower bound the installed zoo declares (>=, == and ~= all count). The gate and the self-heal warning both use it. An older published zoo still declares the old floors, so a working older stack beside it is not forced into chat-only.

Old MLX API guards (chore(studio): drop guards for MLX APIs older than the supported stacks)

  • mx.synchronize already exists in mlx 0.22.0, the gate's lowest floor, so the guard in _drain_generation_streams is removed.
  • MLX diffusion only activates on mlx>=0.32.0,<0.33.0, where mx.device_info exists (it ships from 0.30.4), so the mx.metal.device_info fallback in the diffusion backend is removed.
  • Comments citing mlx 0.30 and 0.32.3 are corrected.

The mx.metal.device_info fallback in utils/hardware/hardware.py stays. The gate still admits mlx below 0.30.4 beside an older zoo.

Known limitation (pre-existing, unchanged)

The gate does not check the installed zoo's upper bounds. An older zoo that declares a lower ceiling can clear the gate with a newer mlx-vlm. The installer and the self-heal both honour the ceiling when they run.

Validation

  • New gate test: mlx-vlm 0.6.3 against a zoo declaring >=0.6.4, mlx 0.32.2 against ==0.32.4, and mlx-lm 0.31.2 against >=0.31.3 are each blocked. The same stacks clear the gate against the old floors. The test is mutation-checked: hard-coding _MLX_MIN_VERSIONS in place of _mlx_minimum fails it.
  • Install tests are updated to the new range: 0.6.3 and 0.8.1 are rejected, 0.6.4 is accepted.
cd studio/backend && python -m pytest tests/test_mlx_inference_backend.py tests/test_utils.py tests/test_mlx_repair.py tests/test_mlx_stack_blockers.py -q
python -m pytest tests/studio/install/test_mlx_install.py tests/studio/install/test_dependency_pass_skips.py -q

mx.synchronize predates the chat-only gate's mlx 0.22.0 floor, and MLX diffusion only runs on mlx 0.32, where mx.device_info exists, so both fallbacks are removed. Comments citing mlx 0.30 and 0.32.3 are corrected to 0.30.4 and the install pin.
@Lyxot

Lyxot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 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-20T13:08:34.169532Z a5d7521 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: eff3c40128

ℹ️ 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 19, 2026
…get scope, classifier DDP default (#18499)

## Summary

PEFT 0.22.0 was released today, and CI installs the latest PEFT, so
every PR now fails several shards (seen on #18486, #18487 and others):

- `Repo tests (CPU, gloo)`, `gloo-tp`, `gloo-tp-env`: tensor parallel
parity tests, e.g. `test_qwen4exp_parallel_matches_one_process[tp2]`,
`test_deepseek_v41_parallel_matches_one_process[tp4]`,
`test_tp2_matches_one_process[llama]`. The saved adapter is missing
keys, or is empty.
- `Repo tests (CPU, rest)`:
`test_peft_moe_linear_targets.py::test_regex_keeps_its_scope`.
- `Repo tests (CPU, rest-2)`:
`test_ddp_find_unused_default.py::test_sequence_classification_head_defaults_to_false`
and `..._trainable_embeddings_default_to_false`.

All of them pass with PEFT 0.21.2 and fail with 0.22.0 on `main`,
locally. These are not test problems: each one is a real behaviour
change for users on PEFT 0.22.

## Root causes and fixes

### 1. Tensor parallel `save_pretrained` drops every sharded LoRA factor
(`tp_native.py`, `pp_native.py`)

`_peft_state_dict` asks PEFT which entries to save by passing the
model's state dict and matching PEFT's selection back by tensor
identity, then gathers the selected DTensors itself (`_full`, which also
puts fused tensor parallel layouts back in their 1-GPU order).

PEFT 0.22 now gathers selected DTensors inside
`get_peft_model_state_dict` (`_gather_state_dict_for_save`), returning
new plain tensors. None of them match by identity, so every sharded
factor was silently left out. Only replicated tensors survived, and the
adapter written by `save_tp_adapter` was partial or empty.

Fix: PEFT now selects over each DTensor's local shard (`to_local()`),
which it does not gather, and each selection maps back to its key. The
gather and fused-layout handling stay in Unsloth as before. The pipeline
parallel adapter gather (`adapter_state_dict` in `pp_native.py`) had the
same exposure for FSDP2 / tensor parallel stages: PEFT's own gather
would skip the fused-layout lookup. It gets the same change. On PEFT
0.21 both paths behave exactly as before.

### 2. A regex `target_modules` loses its scope on MoE models
(`import_fixes.py`)

PEFT 0.22 rewrote the v5 MoE target conversion so that dense Linears
that share an expert name keep LoRA (what #12281 patched in for older
PEFT). It converts a regex `target_modules` to the bare leaf names it
resolves to, so a regex scoped to one layer's projections, e.g.
`model\Wlayers\W1\Wmlp\Wshared_experts\W(gate_proj|up_proj|down_proj)`,
now puts LoRA on every layer's `gate_proj` / `up_proj` / `down_proj`.
PEFT's own code carries a TODO noting it "may match too broadly if only
specific layers are targeted".

Fix: after conversion, a bare leaf target that names only Linears, some
of which the regex did not match, goes back to exactly the module names
the regex matched. Parameter targets and `all-linear` are untouched.

### 3. DDP `find_unused_parameters` default for sequence classification
(`_ddp_defaults.py`)

PEFT 0.22 adds DistilBERT's `pre_classifier` to the default SEQ_CLS
`modules_to_save` (`classifier`, `score`, `pre_classifier`). Unsloth's
list of classifier heads that run every forward was `("score",
"classifier")`, so a plain classifier LoRA no longer counted as safe and
DDP fell back to `find_unused_parameters=True`, which crashes reentrant
checkpointing ("ready only once"). `pre_classifier` runs every forward
too, so it joins the list.

## Testing

| | PEFT 0.21.2 | PEFT 0.22.0 |
|---|---|---|
| `main` | passes | 5 tensor parallel parity cells, the regex scope test
and 2 DDP default tests fail (the CI failures) |
| this branch | 336 passed, 9 skipped | 336 passed, 9 skipped |

The 336 cover the tensor and pipeline parallel gloo set
(`test_qwen4exp_parallel_gloo.py`, `test_parallel_deepseek_v41_gloo.py`,
`test_tp_native_oracle.py`, `test_tp_kv_replicated_gloo.py`,
`test_pp_fsdp2_gloo.py`, `test_pp_native_gloo.py`,
`test_pp_env_gloo.py`, `test_pp_schedules_gloo.py`,
`test_frozen_table_tp_gloo.py`, `test_frozen_table_pp_gloo.py`),
`test_ddp_find_unused_default.py`, `test_peft_moe_linear_targets.py` and
`tests/version_compat/test_peft_conversion_symbol_backfill.py`. The
existing parity tests are the guard: each compares the saved adapter and
the LoRA targets with a single-process reference, and they fail on
`main` under PEFT 0.22.0.
@NilayYadav NilayYadav self-assigned this Nov 19, 2026
@NilayYadav

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 95cf72ed82

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

@NilayYadav

NilayYadav commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Reproduction evidence

macOS, Apple Silicon. mlx 0.32.2 + mlx-lm 0.31.3 + mlx-vlm 0.6.3, with unsloth_zoo 2026.11.7 (mlx==0.32.4) installed --no-deps:

  • Merge base 2f2490c19: mlx_stack_blockers() -> [], Train stays on
  • PR head 95cf72ed8: ['mlx 0.32.2 is older than 0.32.4']; self-heal installs mlx 0.32.4 / mlx-lm 0.32.2 / mlx-vlm 0.8.0, then []

Tests: 5 fail on base and pass on head, 0 fail on head. MLX tiny SFT on macos-15: pass.

@Lyxot

Lyxot commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator Author

Review and CI summary

  • Codex: Didn't find any major issues on the current head 95cf72ed8. That head includes the comment trim and the main merge pushed during review. No review threads were opened.
  • CI on 95cf72ed8: 88 pass. The 3 failing jobs fail on tests outside this PR, and Core zoo was cancelled before it reported:
    • Python 3.13, diffusion: test_apply_loras_quant_unbaked_requires_reload and test_apply_loras_quant_baked_matrix fail identically on the merged main commit f4ced1fcc and pass on current main.
    • Repo tests (CPU, rest-2): an encoding check on tests/test_fused_label_smoothing.py.
    • Repo tests (CPU, studio): features/images/images-page.tsx.
    • The MLX tests this PR touches pass, and so do the install tests, apart from two pip-bootstrap tests that also fail on main.
  • Staging: the staging copy was opened while the upstream jobs were queued. It is closed now that upstream CI has run on the current head.
  • Changed during this round: nothing by the author; only the two maintainer commits above.

@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. Already looking forward to the next diff.

Reviewed commit: 4fb18d37f9

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

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: a5d75211ff

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

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