Repository navigation
Unsloth Studio: raise the mlx-vlm floor to 0.6.4 and hold the MLX gate to the installed unsloth-zoo's floors - #18487
Conversation
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.
|
@codex review |
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. |
|
Codex Review: Didn't find any major issues. Keep it up! 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". |
…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.
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! 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". |
Reproduction evidencemacOS, Apple Silicon. mlx 0.32.2 + mlx-lm 0.31.3 + mlx-vlm 0.6.3, with unsloth_zoo 2026.11.7 (
Tests: 5 fail on base and pass on head, 0 fail on head. MLX tiny SFT on macos-15: pass. |
Review and CI summary
|
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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 |
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
Summary
Companion to unslothai/unsloth-zoo#2618, which raises unsloth-zoo's mlx-vlm floor to 0.6.4. This PR:
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 inutils/mlx_repair.py(_MLX_INSTALL_SPECS) move frommlx-vlm>=0.4.4,<=0.8.0to>=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 needtransformers>=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--localoverlay 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.synchronizealready exists in mlx 0.22.0, the gate's lowest floor, so the guard in_drain_generation_streamsis removed.mlx>=0.32.0,<0.33.0, wheremx.device_infoexists (it ships from 0.30.4), so themx.metal.device_infofallback in the diffusion backend is removed.The
mx.metal.device_infofallback inutils/hardware/hardware.pystays. 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
>=0.6.4, mlx 0.32.2 against==0.32.4, and mlx-lm 0.31.2 against>=0.31.3are each blocked. The same stacks clear the gate against the old floors. The test is mutation-checked: hard-coding_MLX_MIN_VERSIONSin place of_mlx_minimumfails it.