Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Pin what the MLX self-heal installs, and correct the mlx-lm floor (#9557)

Daniel Hanff46e06152ca
diff --git a/studio/backend/tests/test_mlx_repair.py b/studio/backend/tests/test_mlx_repair.py
index 7ee020a9601..b4331442641 100644
--- a/studio/backend/tests/test_mlx_repair.py
+++ b/studio/backend/tests/test_mlx_repair.py
@@ -47,9 +47,20 @@ def test_uv_cmd_targets_this_interpreter_with_mlx_packages(monkeypatch):
assert cmd is not None
assert cmd[:5] == ["/usr/bin/uv", "pip", "install", "--python", sys.executable]
assert set(mr.MLX_PACKAGES) <= set(cmd)
- # Minimum versions are pinned so the resolver cannot backtrack to an old
- # mlx-vlm that imports but breaks VLM Train/Export.
- assert "mlx-vlm>=0.4.4" in cmd
+ # mlx-vlm keeps a floor so the resolver cannot backtrack to an old one that
+ # imports but breaks VLM Train/Export, and a ceiling so this unattended
+ # install cannot cross a major line on its own.
+ assert "mlx-vlm>=0.4.4,<0.7.0" in cmd
+ # Pinned, not floored: see _MLX_INSTALL_SPECS.
+ assert "mlx==0.32.1" in cmd
+ assert "mlx-lm==0.31.3" in cmd
+ # Look the requirement up by name rather than by prefix. Asserting on
+ # startswith("mlx==") could only ever be checked on a spec that already
+ # pins, so it passed vacuously the moment the pin was relaxed, which is the
+ # one case worth catching.
+ for name in ("mlx", "mlx-lm"):
+ spec = mr._MLX_INSTALL_SPECS[name]
+ assert spec.startswith("=="), f"{name} must be pinned, not floored: got {spec}"
def test_uv_executable_finds_installer_location_when_path_is_minimal(monkeypatch, tmp_path):
@@ -208,6 +219,32 @@ def test_repair_rejects_inadequate_stack(monkeypatch):
assert mr.attempt_mlx_repair() is False
+def test_inadequate_stack_warning_names_the_floors_not_the_install_pins(monkeypatch):
+ # The gate this message reports on is mlx_stack_available(), which tests the
+ # floors. Quoting the install pins instead would tell an operator running a
+ # perfectly usable mlx 0.33 that they need exactly 0.32.1.
+ class _Result:
+ returncode = 0
+ stdout = ""
+
+ warnings = []
+ # Pin both, or this test measures the host. attempt_mlx_repair returns early
+ # when _uv_executable() finds nothing, long before the message under test, so
+ # on a machine without uv the warning list comes back empty and the unpack
+ # below fails rather than the assertion. That is what took CI red while this
+ # passed locally.
+ monkeypatch.setattr(mr, "_uv_executable", lambda: "/usr/bin/uv")
+ monkeypatch.setattr(mr, "_transformers_constraint_args", lambda: ([], None))
+ monkeypatch.setattr(mr.subprocess, "run", lambda *a, **k: _Result())
+ monkeypatch.setattr(mr, "mlx_stack_available", lambda: False)
+ monkeypatch.setattr(mr.logger, "warning", lambda msg, *args, **kw: warnings.append(msg % args))
+ assert mr.attempt_mlx_repair() is False
+ (message,) = [w for w in warnings if "incomplete or too-old" in w]
+ for name, floor in mr._MLX_MIN_VERSIONS.items():
+ assert f"{name}>={floor}" in message
+ assert "==" not in message
+
+
def test_repair_invalidates_import_caches_before_stack_check(monkeypatch):
events = []
diff --git a/studio/backend/tests/test_mlx_stack_blockers.py b/studio/backend/tests/test_mlx_stack_blockers.py
index b7e13d9eaa1..aa32a08ad55 100644
--- a/studio/backend/tests/test_mlx_stack_blockers.py
+++ b/studio/backend/tests/test_mlx_stack_blockers.py
@@ -36,15 +36,25 @@ def _fake_versions(monkeypatch, installed: dict[str, str]):
monkeypatch.setattr("importlib.metadata.version", version)
+def _healthy(**overrides: str) -> dict[str, str]:
+ """The floors mlx_repair requires, so "healthy" here follows a floor bump.
+
+ Hardcoding a healthy version made raising the mlx-lm floor to 0.31.2 fail six
+ tests that are about mlx-vlm, import errors and line length, none of which had
+ anything to say about mlx-lm.
+ """
+ return {**mr._MLX_MIN_VERSIONS, **overrides}
+
+
def test_a_healthy_stack_reports_no_blockers(monkeypatch):
- _fake_versions(monkeypatch, {"mlx": "0.30.0", "mlx-lm": "0.30.0", "mlx-vlm": "0.5.0"})
+ _fake_versions(monkeypatch, _healthy())
monkeypatch.setattr(mr, "_mlx_runtime_import_blocker", lambda: None)
assert mr.mlx_stack_blockers() == []
assert mr.mlx_stack_available() is True
def test_a_missing_package_is_named_with_the_version_it_needs(monkeypatch):
- _fake_versions(monkeypatch, {"mlx": "0.30.0", "mlx-lm": "0.30.0"})
+ _fake_versions(monkeypatch, {k: v for k, v in _healthy().items() if k != "mlx-vlm"})
monkeypatch.setattr(mr, "_mlx_runtime_import_blocker", lambda: None)
blockers = mr.mlx_stack_blockers()
assert any("mlx-vlm is not installed" in blocker for blocker in blockers)
@@ -54,7 +64,7 @@ def test_a_missing_package_is_named_with_the_version_it_needs(monkeypatch):
def test_a_backtracked_package_names_the_version_it_found(monkeypatch):
# The reported shape: present, importable, and too old for VLM Train/Export.
- _fake_versions(monkeypatch, {"mlx": "0.30.0", "mlx-lm": "0.30.0", "mlx-vlm": "0.1.0"})
+ _fake_versions(monkeypatch, _healthy(**{"mlx-vlm": "0.1.0"}))
monkeypatch.setattr(mr, "_mlx_runtime_import_blocker", lambda: None)
blockers = mr.mlx_stack_blockers()
assert blockers == ["mlx-vlm 0.1.0 is older than 0.4.4"]
@@ -70,7 +80,7 @@ def test_every_bad_package_is_listed_not_just_the_first(monkeypatch):
def test_an_import_that_raises_is_reported_with_its_error(monkeypatch):
# Versions satisfied but the module will not load, which is what a mlx-vlm
# built against a different transformers looks like from here.
- _fake_versions(monkeypatch, {"mlx": "0.30.0", "mlx-lm": "0.30.0", "mlx-vlm": "0.5.0"})
+ _fake_versions(monkeypatch, _healthy())
def explode(module: str):
raise ImportError("cannot import name 'AutoProcessor' from 'transformers'")
@@ -85,7 +95,7 @@ def test_an_import_that_raises_is_reported_with_its_error(monkeypatch):
def test_versions_are_checked_before_imports(monkeypatch):
"""A too-old package must be named without loading it into this process."""
- _fake_versions(monkeypatch, {"mlx": "0.30.0", "mlx-lm": "0.30.0", "mlx-vlm": "0.1.0"})
+ _fake_versions(monkeypatch, _healthy(**{"mlx-vlm": "0.1.0"}))
def never(module: str):
raise AssertionError("imported a package the version check already rejected")
@@ -157,7 +167,7 @@ def test_a_discarded_verdict_takes_the_detail_with_it(monkeypatch):
from utils.hardware import hardware as hw
monkeypatch.setattr(hw, "CHAT_ONLY_REASON", "mlx_unavailable")
- monkeypatch.setattr(hw, "CHAT_ONLY_DETAIL", "mlx-lm is not installed (needs >=0.22.0)")
+ monkeypatch.setattr(hw, "CHAT_ONLY_DETAIL", "mlx-lm is not installed (needs >=0.31.2)")
hw._discard_detection_locked()
assert hw.CHAT_ONLY_REASON is None
assert hw.CHAT_ONLY_DETAIL is None
@@ -247,7 +257,7 @@ def test_an_unreadable_gate_falls_back_to_the_bare_import(monkeypatch):
# A blocker line goes into /api/health and into the Train row's native tooltip. Neither
# renders a paragraph, and a dyld failure lists every path it tried.
def test_a_long_import_error_is_folded_to_one_bounded_line(monkeypatch):
- _fake_versions(monkeypatch, {"mlx": "0.30.0", "mlx-lm": "0.30.0", "mlx-vlm": "0.5.0"})
+ _fake_versions(monkeypatch, _healthy())
def explode(module: str):
raise ImportError(
@@ -267,7 +277,7 @@ def test_a_long_import_error_is_folded_to_one_bounded_line(monkeypatch):
def test_a_malformed_installed_version_is_bounded_too(monkeypatch):
"""Version metadata is read from disk, and an interrupted install can leave junk."""
junk = "1.0\n" + "y" * 500
- _fake_versions(monkeypatch, {"mlx": junk, "mlx-lm": "0.30.0", "mlx-vlm": "0.5.0"})
+ _fake_versions(monkeypatch, _healthy(mlx = junk))
monkeypatch.setattr(mr, "_mlx_runtime_import_blocker", lambda: None)
blocker = mr.mlx_stack_blockers()[0]
assert "\n" not in blocker
diff --git a/studio/backend/utils/mlx_repair.py b/studio/backend/utils/mlx_repair.py
index bbbef8a0a2c..02a502f7b71 100644
--- a/studio/backend/utils/mlx_repair.py
+++ b/studio/backend/utils/mlx_repair.py
@@ -50,10 +50,35 @@ _UNRESOLVED_PYTHON_MARKER = "No virtual environment or system Python installatio
# Minimum versions unsloth-zoo requires on Apple Silicon (its pyproject darwin
# deps). mlx-vlm especially must be >=0.4.4: an older one still imports but
# breaks VLM Train/Export, so installing it would wrongly clear chat-only.
-_MLX_MIN_VERSIONS = {"mlx": "0.22.0", "mlx-lm": "0.22.0", "mlx-vlm": "0.4.4"}
+# mlx-lm's floor tracks unsloth-zoo, which needs GenerationBatch.Response and
+# BatchGenerator.next_generated from 0.31.2; it read 0.22.0 here, which would
+# have let a stack too old for batched generation clear the chat-only gate.
+_MLX_MIN_VERSIONS = {"mlx": "0.22.0", "mlx-lm": "0.31.2", "mlx-vlm": "0.4.4"}
_MLX_PACKAGE_NAMES = tuple(_MLX_MIN_VERSIONS)
_MLX_RUNTIME_IMPORTS = ("mlx.core", "mlx_lm", "mlx_lm.sample_utils", "mlx_vlm")
-MLX_PACKAGES = tuple(f"{name}>={version}" for name, version in _MLX_MIN_VERSIONS.items())
+# What the self-heal INSTALLS, as opposed to the floors above, which judge a
+# stack that is already there. Pinned rather than floored because this install is
+# unattended and default-on, and mlx ships breaking changes in patch releases:
+# 0.32.1 broke model loading here (unslothai/unsloth#9466). A floor would fetch
+# whatever shipped since the user last opened Unsloth, unasked.
+#
+# Keep in sync with unsloth-zoo's pyproject darwin deps. mlx-vlm stays a range so
+# the resolver can pick 0.6.15 here, where the installer overrides mlx-vlm's
+# transformers requirement, and 0.6.4 under the plain cap.
+#
+# 0.32.1 is chosen with its known defect, not in ignorance of it: it segfaults at
+# interpreter finalization when a fused Metal custom kernel is the last work a
+# process did, which unsloth-zoo measured and works around in
+# tests/_run_then_exit_hard.py. Staying on 0.32.0 to dodge that would give back
+# mlx#3833, where two fast.metal_kernel instances sharing a name but not a source
+# silently run the first kernel's code for the second. A noisy exit after the work
+# is finished beats wrong numbers from the fused kernels this stack is built on.
+_MLX_INSTALL_SPECS = {
+ "mlx": "==0.32.1",
+ "mlx-lm": "==0.31.3",
+ "mlx-vlm": ">=0.4.4,<0.7.0",
+}
+MLX_PACKAGES = tuple(f"{name}{spec}" for name, spec in _MLX_INSTALL_SPECS.items())
_MLX_REINSTALL_ARGS = tuple(
arg for name in _MLX_PACKAGE_NAMES for arg in ("--reinstall-package", name)
)
@@ -500,6 +525,9 @@ def attempt_mlx_repair(*, timeout: int = _REPAIR_TIMEOUT_S) -> bool:
logger.warning(
"MLX self-heal produced an incomplete or too-old MLX stack "
"(need %s); staying chat-only.",
+ # The floors, not MLX_PACKAGES: the gate above tests the floors, so
+ # quoting the install pins would tell someone on a usable mlx 0.33
+ # that they need exactly 0.32.1.
", ".join(f"{name}>={ver}" for name, ver in _MLX_MIN_VERSIONS.items()),
)
return False