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.

Move the Unsloth Studio MLX stack to mlx 0.32.4 and mlx-lm 0.32.2 (#13992)

Long Yixing5021249ccc21
diff --git a/studio/backend/core/inference/mlx_inference.py b/studio/backend/core/inference/mlx_inference.py
index 7a0bc330809..13415cf03fb 100644
--- a/studio/backend/core/inference/mlx_inference.py
+++ b/studio/backend/core/inference/mlx_inference.py
@@ -3766,7 +3766,6 @@ class _TextBatchSession:
all_tokens = [prefix],
samplers = [plan.sampler],
logits_processors = [_row_logits_processors(plan.processors)],
- state_machines = None,
)
if len(uids) != 1:
self.generator.remove(list(uids))
diff --git a/studio/backend/core/inference/mlx_memory.py b/studio/backend/core/inference/mlx_memory.py
index 5ad29f8938f..5f175db3960 100644
--- a/studio/backend/core/inference/mlx_memory.py
+++ b/studio/backend/core/inference/mlx_memory.py
@@ -493,7 +493,9 @@ def _bound_spec(entry):
def _entry_bytes(entry) -> int:
import mlx.core as mx
- state = entry.state
+ # mlx-lm 0.32's KV `state` is the whole preallocated buffer; `keys_and_values` is the held part.
+ held = getattr(entry, "keys_and_values", None)
+ state = held() if callable(held) and getattr(entry, "keys", None) is not None else entry.state
if isinstance(state, mx.array):
state = (state,)
elif not isinstance(state, (list, tuple)):
@@ -540,8 +542,12 @@ def _conv_width(entry) -> int:
state = entry.state
if not isinstance(state, (list, tuple)):
return 0
+ # mlx-lm 0.32's ArraysCache state is (arrays, left_padding, lengths).
+ items = [
+ sub for item in state for sub in (item if isinstance(item, (list, tuple)) else (item,))
+ ]
return sum(
- int(item.shape[-1]) for item in state if isinstance(item, mx.array) and item.ndim == 3
+ int(item.shape[-1]) for item in items if isinstance(item, mx.array) and item.ndim == 3
)
diff --git a/studio/backend/tests/test_memory_estimate.py b/studio/backend/tests/test_memory_estimate.py
index b3be5d2094f..b5f0e5ee4d2 100644
--- a/studio/backend/tests/test_memory_estimate.py
+++ b/studio/backend/tests/test_memory_estimate.py
@@ -4184,6 +4184,18 @@ def _local_snapshot(repo):
return os.path.dirname(hits[0])
+@_NEEDS_MLX
[email protected]("module", ["mlx_lm.models.cache", "mlx_vlm.models.cache"])
+def test_a_linear_attention_cache_reports_its_convolution_width(module):
+ import importlib
+
+ import mlx.core as mx
+
+ cache = importlib.import_module(module).ArraysCache(2)
+ cache[0], cache[1] = mx.zeros((1, 3, 8192)), mx.zeros((1, 32, 128, 128))
+ assert mm._conv_width(cache) == 8192
+
+
def _on_bfloat16_chip():
import mlx.core as mx
if mm._runtime_dtype() is not mx.bfloat16:
diff --git a/studio/backend/tests/test_mlx_inference_backend.py b/studio/backend/tests/test_mlx_inference_backend.py
index 164a4772495..1020300d9d5 100644
--- a/studio/backend/tests/test_mlx_inference_backend.py
+++ b/studio/backend/tests/test_mlx_inference_backend.py
@@ -7835,7 +7835,9 @@ def test_the_grammar_stops_on_the_token_the_decode_loop_stops_on():
tokenizer, runtime_stop = _two_stop_tokenizer()
wrapped = TokenizerWrapper(tokenizer, eos_token_ids = [runtime_stop])
- assert _stop_offered_after_the_document(wrapped, tokenizer) == {runtime_stop}
+ # mlx-lm 0.32 also keeps the tokenizer's own end token in the wrapper's stop set.
+ assert runtime_stop in wrapped.eos_token_ids
+ assert _stop_offered_after_the_document(wrapped, tokenizer) == set(wrapped.eos_token_ids)
assert _stop_offered_after_the_document(tokenizer, tokenizer) == {tokenizer.eos_token_id}
@@ -8194,12 +8196,19 @@ def test_mlx_stream_detokenizer_handles_one_that_cannot_be_copied():
def decode(self, token_ids):
return "".join(f"<{token_id}>" for token_id in token_ids)
+ def encode(
+ self,
+ text,
+ add_special_tokens = True,
+ ):
+ return [ord(c) for c in text]
+
class _PerRead:
"""Stands in for ``TokenizerWrapper``, whose ``detokenizer`` is a property."""
@property
def detokenizer(self):
- return detokenizers.NaiveStreamingDetokenizer(_Tok())
+ return _uncopyable_naive_detokenizer(detokenizers)(_Tok())
source = _PerRead()
with pytest.raises(AttributeError):
diff --git a/studio/backend/tests/test_mlx_repair.py b/studio/backend/tests/test_mlx_repair.py
index 333bbd29fe8..62a51feb7c5 100644
--- a/studio/backend/tests/test_mlx_repair.py
+++ b/studio/backend/tests/test_mlx_repair.py
@@ -64,15 +64,14 @@ def test_uv_cmd_targets_this_interpreter_with_mlx_packages(monkeypatch):
# install cannot cross a major line on its own.
assert "mlx-vlm>=0.4.4,<=0.7.8" in cmd
# Pinned, not floored: see _MLX_INSTALL_SPECS.
- assert "mlx==0.32.3" in cmd
- assert "mlx-lm==0.31.3" in cmd
+ assert "mlx==0.32.4" in cmd
+ assert "mlx-lm>=0.31.3,<=0.32.2" 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}"
+ spec = mr._MLX_INSTALL_SPECS["mlx"]
+ assert spec.startswith("=="), f"mlx must be pinned, not floored: got {spec}"
def test_install_narrows_mlx_vlm_to_what_the_installed_zoo_declares(monkeypatch):
@@ -85,10 +84,18 @@ def test_install_narrows_mlx_vlm_to_what_the_installed_zoo_declares(monkeypatch)
packages = mr._install_packages()
vlm = next(p for p in packages if p.startswith("mlx-vlm"))
assert "<0.7.0" in vlm
- # mlx and mlx-lm are pinned at both ends, so they are left alone: intersecting them with a
- # zoo one patch release behind would empty the range and break every self-heal.
- assert "mlx==0.32.3" in packages
- assert "mlx-lm==0.31.3" in packages
+ # mlx is pinned at both ends, so it is left alone: intersecting it with a zoo one patch
+ # release behind would empty the range and break every self-heal.
+ assert "mlx==0.32.4" in packages
+ assert "mlx-lm>=0.31.3,<=0.32.2" in packages
+
+
+def test_install_keeps_an_older_zoos_mlx_lm(monkeypatch):
+ # A zoo pinning mlx-lm 0.31.3 cannot drive 0.32's loader and cache changes.
+ monkeypatch.setattr(
+ mr, "_zoo_declared_specifier", lambda name: "==0.31.3" if name == "mlx-lm" else ""
+ )
+ assert "mlx-lm>=0.31.3,<=0.32.2,==0.31.3" in mr._install_packages()
def test_install_keeps_the_full_range_when_the_zoo_declares_nothing(monkeypatch):
diff --git a/studio/backend/utils/mlx_repair.py b/studio/backend/utils/mlx_repair.py
index cc2410dbc9a..50582508378 100644
--- a/studio/backend/utils/mlx_repair.py
+++ b/studio/backend/utils/mlx_repair.py
@@ -30,10 +30,10 @@ _UNRESOLVED_PYTHON_MARKER = "No virtual environment or system Python installatio
_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")
-# What the self-heal INSTALLS (the floors above judge a stack already there). Pinned, not floored: this install is unattended and mlx breaks in patch releases (0.32.1, unslothai/unsloth#9466). Keep in sync with unsloth-zoo's darwin deps. mlx 0.32.3 rather than mlx-vlm's 0.32.2 floor: 0.32.2's GQA-8 decode kernel read the first sequence's KV for every batch row (mlx#4431). mlx-vlm stays a range: 0.7.8 under the installer's transformers override, 0.6.4 under the plain cap.
+# What the self-heal INSTALLS (the floors above judge a stack already there). Pinned, not floored: this install is unattended and mlx breaks in patch releases (0.32.1, unslothai/unsloth#9466). Keep in sync with unsloth-zoo's darwin deps. mlx 0.32.4 rather than mlx-vlm's 0.32.2 floor: 0.32.2's GQA-8 decode kernel read the first sequence's KV for every batch row (mlx#4431). mlx-vlm stays a range: 0.7.8 under the installer's transformers override, 0.6.4 under the plain cap. mlx-lm is a range too: 0.32 requires Python 3.11, so Python 3.10 resolves 0.31.3.
_MLX_INSTALL_SPECS = {
- "mlx": "==0.32.3",
- "mlx-lm": "==0.31.3",
+ "mlx": "==0.32.4",
+ "mlx-lm": ">=0.31.3,<=0.32.2",
"mlx-vlm": ">=0.4.4,<=0.7.8",
}
MLX_PACKAGES = tuple(f"{name}{spec}" for name, spec in _MLX_INSTALL_SPECS.items())
@@ -75,15 +75,15 @@ def _zoo_declared_specifier(package: str) -> str:
def _install_packages() -> tuple[str, ...]:
- """MLX_PACKAGES, with mlx-vlm narrowed to what the installed unsloth-zoo declares.
+ """MLX_PACKAGES, with mlx-lm and mlx-vlm narrowed to what the installed unsloth-zoo declares.
- Only mlx-vlm: it is the one whose call shape the zoo has to match, and mlx/mlx-lm are pinned
- exactly at both ends, so intersecting those would just empty the range on any zoo a patch release
- behind. Both specifiers are passed and uv intersects them.
+ The ranged two, whose call shapes the zoo has to match: a zoo pinning mlx-lm 0.31.3 keeps 0.31.3.
+ mlx is pinned exactly at both ends, so intersecting it would just empty the range on any zoo a
+ patch release behind. Both specifiers are passed and uv intersects them.
"""
packages = []
for name, spec in _MLX_INSTALL_SPECS.items():
- declared = _zoo_declared_specifier(name) if name == "mlx-vlm" else ""
+ declared = _zoo_declared_specifier(name) if name in ("mlx-lm", "mlx-vlm") else ""
packages.append(f"{name}{spec},{declared}" if declared else f"{name}{spec}")
return tuple(packages)
diff --git a/studio/install_python_stack.py b/studio/install_python_stack.py
index e12f388a496..328958cec1c 100644
--- a/studio/install_python_stack.py
+++ b/studio/install_python_stack.py
@@ -903,7 +903,7 @@ def _macos_release_major() -> "int | None":
# The pinned MLX versions publish macosx_14_0_arm64 wheels, no sdist and no cp39, so
# macOS 13 and Python 3.9 have nothing to resolve to (`uv pip install --python-platform
-# aarch64-apple-darwin mlx==0.32.3`). Asked before the install, like
+# aarch64-apple-darwin mlx==0.32.4`). Asked before the install, like
# _torchcodec_spec_is_installable: pip_install exits on failure, so trying would end an
# install that today just comes up chat-only.
_MLX_MIN_PYTHON = (3, 10)
@@ -10605,11 +10605,16 @@ def _has_working_git() -> bool:
# The MLX stack, one place; test_mlx_install.py compares it with utils/mlx_repair.py's
# _MLX_INSTALL_SPECS.
-_MLX_PINS: tuple[str, ...] = ("mlx==0.32.3", "mlx-metal==0.32.3", "mlx-lm==0.31.3")
+_MLX_PINS: tuple[str, ...] = ("mlx==0.32.4", "mlx-metal==0.32.4")
+# A range, like mlx-vlm: 0.32 requires Python 3.11, so Python 3.10 resolves 0.31.3.
+_MLX_LM_SPEC = "mlx-lm>=0.31.3,<=0.32.2"
_MLX_VLM_SPEC = "mlx-vlm>=0.4.4,<=0.7.8"
# Exact: llguidance.mlx / llguidance.hf are the API grammar_constraint.py binds to.
_LLGUIDANCE_PIN = "llguidance==1.8.0"
-_MLX_NAMES: tuple[str, ...] = tuple(spec.partition("==")[0] for spec in _MLX_PINS) + ("mlx-vlm",)
+_MLX_NAMES: tuple[str, ...] = tuple(spec.partition("==")[0] for spec in _MLX_PINS) + (
+ "mlx-lm",
+ "mlx-vlm",
+)
# mflux goes in --no-deps: its declared torch / transformers floors would move the MLX pins, and Z-Image
# needs only the deps below. Best-effort: a failure must never mark the MLX stack broken.
_MLX_DIFFUSION_PINS: tuple[str, ...] = ("mflux==0.22.0",)
@@ -10656,7 +10661,15 @@ def _install_mlx_diffusion_engine() -> None:
def _mlx_vlm_spec_for_installed_zoo() -> str:
- """_MLX_VLM_SPEC, intersected with the range the INSTALLED unsloth-zoo declares.
+ return _mlx_spec_for_installed_zoo(_MLX_VLM_SPEC)
+
+
+def _mlx_lm_spec_for_installed_zoo() -> str:
+ return _mlx_spec_for_installed_zoo(_MLX_LM_SPEC)
+
+
+def _mlx_spec_for_installed_zoo(spec: str) -> str:
+ """`spec`, intersected with the range the INSTALLED unsloth-zoo declares for its package.
This step runs before the core phase, and on a fresh install (SKIP_STUDIO_BASE=1) the core
phase is skipped entirely, so the zoo install.sh already put down is the one that stays.
@@ -10664,31 +10677,33 @@ def _mlx_vlm_spec_for_installed_zoo() -> str:
accept it, so admitting 0.7.1 beside such a zoo raises TypeError at the first Qwen3.5 VLM
training step, after mlx_stack_available() has cleared the chat-only gate. Reading what the
installed zoo itself declares keeps the two in step without naming a zoo version here, and it
- widens on its own once a zoo declaring 0.7.1 is installed. Mirrors utils/mlx_repair.py's
- _install_packages, which does the same for the unattended self-heal.
+ widens on its own once a zoo declaring 0.7.1 is installed. Likewise a zoo pinning mlx-lm 0.31.3
+ keeps 0.31.3. Mirrors utils/mlx_repair.py's _install_packages, which does the same for the
+ unattended self-heal.
"""
try:
from importlib.metadata import requires
from packaging.requirements import Requirement
from packaging.utils import canonicalize_name
except ImportError:
- return _MLX_VLM_SPEC
+ return spec
try:
declared = requires("unsloth_zoo") or ()
+ wanted = canonicalize_name(Requirement(spec).name)
except Exception: # noqa: BLE001 - not installed, or unreadable metadata
- return _MLX_VLM_SPEC
+ return spec
for raw in declared:
try:
requirement = Requirement(raw)
except Exception: # noqa: BLE001 - a requirement string packaging cannot parse
continue
- if canonicalize_name(requirement.name) == "mlx-vlm" and str(requirement.specifier):
- return f"{_MLX_VLM_SPEC},{requirement.specifier}"
- return _MLX_VLM_SPEC
+ if canonicalize_name(requirement.name) == wanted and str(requirement.specifier):
+ return f"{spec},{requirement.specifier}"
+ return spec
def _mlx_stack_is_current() -> bool:
- """Whether the three exact pins and mlx-vlm's range are all already satisfied.
+ """Whether the exact pins and the mlx-lm and mlx-vlm ranges are all already satisfied.
Without this the step ran `--upgrade` on every update and fetched ~60 MB of wheels
it then discarded, because the pins were already exact and the upgrade only moved
@@ -10696,12 +10711,18 @@ def _mlx_stack_is_current() -> bool:
"""
if not all(_exact_distribution_spec_is_installed(spec) for spec in _MLX_PINS):
return False
- installed = _installed_distribution_version("mlx-vlm")
- if not installed:
+ installed, installed_lm = (
+ _installed_distribution_version(name) for name in ("mlx-vlm", "mlx-lm")
+ )
+ if not installed or not installed_lm:
return False
try:
from packaging.requirements import Requirement
-
+ if not Requirement(_mlx_lm_spec_for_installed_zoo()).specifier.contains(
+ installed_lm,
+ prereleases = True,
+ ):
+ return False
# The narrowed spec, not the static one: with an older zoo beside an already-installed
# 0.7.1 the static range reads as satisfied and the step skips the very install that
# would put mlx-vlm back where the zoo can drive it.
@@ -10747,7 +10768,10 @@ def _mlx_closure_unmet() -> bool:
os.close(_fd)
handle = Path(_name)
handle.write_text(
- "\n".join([*_MLX_PINS, _mlx_vlm_spec_for_installed_zoo()]) + "\n",
+ "\n".join(
+ [*_MLX_PINS, _mlx_lm_spec_for_installed_zoo(), _mlx_vlm_spec_for_installed_zoo()]
+ )
+ + "\n",
encoding = "utf-8",
)
unmet = install_manifest.closure_unmet_requirements(handle, _installed_index())
@@ -10802,8 +10826,10 @@ def _mlx_health_fingerprint() -> dict:
"""What a recorded MLX verdict is only valid for."""
return {
# The narrowed spec, so installing a different zoo invalidates a recorded verdict.
- "pins": list(_MLX_PINS) + [_mlx_vlm_spec_for_installed_zoo()],
+ "pins": list(_MLX_PINS)
+ + [_mlx_lm_spec_for_installed_zoo(), _mlx_vlm_spec_for_installed_zoo()],
"python": _installer_python_tag(),
+ "mlx_lm": _installed_distribution_version("mlx-lm") or "",
"mlx_vlm": _installed_distribution_version("mlx-vlm") or "",
# Versions as installed; an older record without this key is probed once and rewritten.
"imports": {
@@ -12517,6 +12543,7 @@ def install_python_stack() -> int:
# None when the MLX step did not run at all, so the re-resolve after the core phase has
# nothing to compare against.
_mlx_vlm_spec_used: Optional[str] = None
+ _mlx_lm_spec_used: Optional[str] = None
if IS_MAC_ARM and not NO_TORCH:
# Both branches spend the slot, so the denominator does not depend on the host.
if _mlx_pins_are_installable():
@@ -12539,12 +12566,14 @@ def install_python_stack() -> int:
# transitive dependency; _build_pip_cmd translates back for pip.
*[arg for name in _MLX_NAMES for arg in ("--upgrade-package", name)],
*_MLX_PINS,
+ _mlx_lm_spec_for_installed_zoo(),
_mlx_vlm_spec_for_installed_zoo(),
)
# Inside the MLX slot, after the pins it runs on; its own check, so a satisfied
# stack still gets a missing engine.
_install_mlx_diffusion_engine()
_mlx_vlm_spec_used = _mlx_vlm_spec_for_installed_zoo()
+ _mlx_lm_spec_used = _mlx_lm_spec_for_installed_zoo()
else:
_progress("MLX stack (skipped, no wheel for this macOS or Python)")
_note(
@@ -12657,7 +12686,11 @@ def install_python_stack() -> int:
# moved, so the common update pays a metadata read and nothing else.
if IS_MAC_ARM and not NO_TORCH:
_mlx_vlm_spec_now = _mlx_vlm_spec_for_installed_zoo()
- if _mlx_vlm_spec_used is None or _mlx_vlm_spec_now == _mlx_vlm_spec_used:
+ _mlx_lm_spec_now = _mlx_lm_spec_for_installed_zoo()
+ if _mlx_vlm_spec_used is None or (_mlx_vlm_spec_now, _mlx_lm_spec_now) == (
+ _mlx_vlm_spec_used,
+ _mlx_lm_spec_used,
+ ):
_progress("MLX stack (zoo unchanged, skipped)")
else:
_progress("MLX stack (re-resolved for the new zoo)")
@@ -12667,6 +12700,7 @@ def install_python_stack() -> int:
"--no-cache-dir",
*[arg for name in _MLX_NAMES for arg in ("--upgrade-package", name)],
*_MLX_PINS,
+ _mlx_lm_spec_now,
_mlx_vlm_spec_now,
)
diff --git a/tests/studio/install/test_dependency_pass_skips.py b/tests/studio/install/test_dependency_pass_skips.py
index aff5226ba61..224f6f4f779 100644
--- a/tests/studio/install/test_dependency_pass_skips.py
+++ b/tests/studio/install/test_dependency_pass_skips.py
@@ -860,14 +860,24 @@ def test_a_pip_that_cannot_run_is_bootstrapped_again(monkeypatch) -> None:
def test_the_mlx_stack_is_current_only_when_all_four_hold(monkeypatch) -> None:
- versions = {"mlx": "0.32.3", "mlx-metal": "0.32.3", "mlx-lm": "0.31.3", "mlx-vlm": "0.5.0"}
+ versions = {"mlx": "0.32.4", "mlx-metal": "0.32.4", "mlx-lm": "0.32.2", "mlx-vlm": "0.5.0"}
monkeypatch.setattr(stack, "_installed_distribution_version", lambda name: versions.get(name))
monkeypatch.setattr(stack, "_mlx_closure_unmet", lambda: False)
+ monkeypatch.setattr(stack, "_mlx_lm_spec_for_installed_zoo", lambda: stack._MLX_LM_SPEC)
assert stack._mlx_stack_is_current() is True
+ for lm in ("0.31.3", "0.32.2"): # either end of the range, as Python 3.10 and 3.11+ resolve
+ monkeypatch.setattr(
+ stack,
+ "_installed_distribution_version",
+ lambda n, v = {**versions, "mlx-lm": lm}: v.get(n),
+ )
+ assert stack._mlx_stack_is_current() is True, lm
for name, wrong in (
("mlx", "0.32.0"),
("mlx-metal", None),
("mlx-lm", "0.31.2"),
+ ("mlx-lm", "0.32.3"),
+ ("mlx-lm", None),
("mlx-vlm", "0.8.0"),
("mlx-vlm", None),
):
@@ -880,7 +890,7 @@ def test_the_mlx_stack_is_current_only_when_all_four_hold(monkeypatch) -> None:
def test_a_satisfied_mlx_pin_with_a_broken_closure_is_not_current(monkeypatch, tmp_path) -> None:
"""This step installs WITH dependencies, so it is what repairs an mlx-vlm whose own
miniaudio or mlx-audio is gone. Versions alone would skip that repair."""
- versions = {"mlx": "0.32.3", "mlx-metal": "0.32.3", "mlx-lm": "0.31.3", "mlx-vlm": "0.5.0"}
+ versions = {"mlx": "0.32.4", "mlx-metal": "0.32.4", "mlx-lm": "0.32.2", "mlx-vlm": "0.5.0"}
monkeypatch.setattr(stack, "_installed_distribution_version", lambda name: versions.get(name))
monkeypatch.setattr(stack, "_mlx_closure_unmet", lambda: True)
assert stack._mlx_stack_is_current() is False
@@ -931,7 +941,9 @@ def test_the_mlx_closure_audit_reads_the_pins_and_cleans_up(monkeypatch, tmp_pat
monkeypatch.setattr(stack.install_manifest, "closure_unmet_requirements", _closure)
monkeypatch.setattr(stack, "_installed_index", lambda: {})
assert stack._mlx_closure_unmet() is True
- assert seen and all(spec in seen[0] for spec in [*stack._MLX_PINS, stack._MLX_VLM_SPEC])
+ assert seen and all(
+ spec in seen[0] for spec in [*stack._MLX_PINS, stack._MLX_LM_SPEC, stack._MLX_VLM_SPEC]
+ )
assert not list(tmp_path.glob("unsloth-mlx-*.txt"))
assert written and written[0].parent == tmp_path
assert not written[0].exists()
@@ -946,7 +958,7 @@ def test_the_mlx_closure_audit_reads_the_pins_and_cleans_up(monkeypatch, tmp_pat
def test_the_mlx_pins_match_the_runtime_repair() -> None:
"""One stack, two callers. The self-heal at startup reinstalls whatever this
installed, so a pin that drifts here is a repair loop there."""
- names = {spec.partition("==")[0] for spec in stack._MLX_PINS} | {"mlx-vlm"}
+ names = {spec.partition("==")[0] for spec in stack._MLX_PINS} | {"mlx-lm", "mlx-vlm"}
assert set(stack._MLX_NAMES) == names
assert stack._MLX_VLM_SPEC.startswith("mlx-vlm")
@@ -1381,13 +1393,16 @@ def test_the_fingerprint_names_everything_a_verdict_depends_on(monkeypatch) -> N
monkeypatch.setattr(stack, "_installed_distribution_version", lambda _n: "0.4.5")
fingerprint = stack._mlx_health_fingerprint()
# The installed zoo narrows the mlx-vlm range, so changing the zoo must invalidate the verdict.
- assert fingerprint["pins"] == list(stack._MLX_PINS) + [stack._mlx_vlm_spec_for_installed_zoo()]
+ assert fingerprint["pins"] == list(stack._MLX_PINS) + [
+ stack._mlx_lm_spec_for_installed_zoo(),
+ stack._mlx_vlm_spec_for_installed_zoo(),
+ ]
assert fingerprint["pins"][-1].startswith(stack._MLX_VLM_SPEC)
assert fingerprint["python"] == stack._installer_python_tag()
assert fingerprint["imports"] == {n: "0.4.5" for n in stack._MLX_IMPORTED_DEPENDENCIES}
assert {"transformers", "tokenizers", "numpy", "huggingface-hub"} <= set(fingerprint["imports"])
- # mlx-vlm floats inside a range: the pin string alone does not identify what is installed.
- assert fingerprint["mlx_vlm"] == "0.4.5"
+ # mlx-lm and mlx-vlm float inside ranges: the pin strings alone do not identify what is installed.
+ assert fingerprint["mlx_lm"] == fingerprint["mlx_vlm"] == "0.4.5"
monkeypatch.setattr(stack, "_installed_distribution_version", lambda _n: None)
assert stack._mlx_health_fingerprint()["mlx_vlm"] == ""
diff --git a/tests/studio/install/test_mlx_install.py b/tests/studio/install/test_mlx_install.py
index 8462776bca7..41c3fc65e1a 100644
--- a/tests/studio/install/test_mlx_install.py
+++ b/tests/studio/install/test_mlx_install.py
@@ -183,6 +183,7 @@ def test_mlx_install_respects_platform_mode_and_pins(
):
# The repo's declared spec, not the installed zoo's narrowing (tested below).
monkeypatch.setattr(stack, "_mlx_vlm_spec_for_installed_zoo", lambda: stack._MLX_VLM_SPEC)
+ monkeypatch.setattr(stack, "_mlx_lm_spec_for_installed_zoo", lambda: stack._MLX_LM_SPEC)
calls = _run_to_extras(
monkeypatch,
platform = platform,
@@ -292,7 +293,7 @@ def test_mlx_command_preserves_pins_and_interpreter_on_fallback(monkeypatch, ret
"python_version, macos_major, installable",
[
((3, 9, 6), 15, False), # macOS ships 3.9; no release in the pinned set has a cp39 wheel
- ((3, 10, 0), 15, True),
+ ((3, 10, 0), 15, True), # mlx-lm 0.32 requires Python 3.11; 3.10 resolves 0.31.3
((3, 12, 0), 13, False), # Apple Silicon on Ventura: the pins are macosx_14_0 only
((3, 12, 0), 14, True),
((3, 12, 0), 26, True),
@@ -304,7 +305,7 @@ def test_mlx_command_preserves_pins_and_interpreter_on_fallback(monkeypatch, ret
def test_mlx_pin_floor_matches_the_published_wheels(
monkeypatch, python_version, macos_major, installable
):
- """0.32.3 ships macosx_14_0_arm64 wheels, no sdist, and the pinned set starts at cp310."""
+ """mlx 0.32.4 ships macosx_14_0_arm64 wheels, no sdist, and the pinned set starts at cp310."""
monkeypatch.setattr(stack.sys, "version_info", python_version)
monkeypatch.setattr(stack, "_macos_release_major", Mock(return_value = macos_major))
assert stack._mlx_pins_are_installable() is installable
@@ -313,8 +314,8 @@ def test_mlx_pin_floor_matches_the_published_wheels(
def test_pin_floor_is_revisited_whenever_the_pins_move():
"""A pin bumped without its floor silently starts failing installs, so tie them here."""
assert _repair_specs() == {
- "mlx": "==0.32.3",
- "mlx-lm": "==0.31.3",
+ "mlx": "==0.32.4",
+ "mlx-lm": ">=0.31.3,<=0.32.2",
"mlx-vlm": ">=0.4.4,<=0.7.8",
}
assert (stack._MLX_MIN_PYTHON, stack._MLX_MIN_MACOS_MAJOR) == ((3, 10), 14)
@@ -376,11 +377,13 @@ def test_mlx_vlm_spec_is_intersected_with_the_installed_zoo(monkeypatch):
lambda _name: [
'mlx==0.32.1; sys_platform == "darwin" and platform_machine == "arm64"',
'mlx-vlm<0.7.0,>=0.4.4; sys_platform == "darwin" and platform_machine == "arm64"',
+ 'mlx-lm==0.31.3; sys_platform == "darwin" and platform_machine == "arm64"',
],
)
spec = stack._mlx_vlm_spec_for_installed_zoo()
assert spec.startswith(stack._MLX_VLM_SPEC)
- assert "<0.7.0" in spec
+ assert "<0.7.0" in spec and "0.31.3" not in spec
+ assert stack._mlx_lm_spec_for_installed_zoo() == f"{stack._MLX_LM_SPEC},==0.31.3"
def test_mlx_vlm_spec_is_unchanged_without_an_installed_zoo(monkeypatch):
@@ -393,14 +396,36 @@ def test_mlx_vlm_spec_is_unchanged_without_an_installed_zoo(monkeypatch):
assert stack._mlx_vlm_spec_for_installed_zoo() == stack._MLX_VLM_SPEC
+def test_an_mlx_lm_outside_the_installed_zoos_range_is_not_current(monkeypatch):
+ monkeypatch.setattr(stack, "_exact_distribution_spec_is_installed", lambda _spec: True)
+ monkeypatch.setattr(stack, "_mlx_closure_unmet", lambda: [])
+ monkeypatch.setattr(stack, "_mlx_vlm_spec_for_installed_zoo", lambda: stack._MLX_VLM_SPEC)
+ monkeypatch.setattr(stack, "_mlx_lm_spec_for_installed_zoo", lambda: stack._MLX_LM_SPEC)
+ monkeypatch.setattr(
+ stack,
+ "_installed_distribution_version",
+ lambda name: "0.32.2" if name == "mlx-lm" else "0.7.8",
+ )
+ assert stack._mlx_stack_is_current() is True
+ monkeypatch.setattr(
+ stack, "_mlx_lm_spec_for_installed_zoo", lambda: f"{stack._MLX_LM_SPEC},==0.31.3"
+ )
+ assert stack._mlx_stack_is_current() is False
+
+
def test_the_skip_predicate_uses_the_narrowed_range(monkeypatch):
"""0.7.1 already installed beside a zoo declaring <0.7.0 must NOT read as current, or the
step skips the install that would put mlx-vlm back where the zoo can drive it."""
monkeypatch.setattr(stack, "_exact_distribution_spec_is_installed", lambda _spec: True)
- monkeypatch.setattr(stack, "_installed_distribution_version", lambda _name: "0.7.1")
+ monkeypatch.setattr(
+ stack,
+ "_installed_distribution_version",
+ lambda name: "0.32.2" if name == "mlx-lm" else "0.7.1",
+ )
monkeypatch.setattr(stack, "_mlx_closure_unmet", lambda: [])
monkeypatch.setattr(stack, "_mlx_vlm_spec_for_installed_zoo", lambda: stack._MLX_VLM_SPEC)
+ monkeypatch.setattr(stack, "_mlx_lm_spec_for_installed_zoo", lambda: stack._MLX_LM_SPEC)
assert stack._mlx_stack_is_current() is True
monkeypatch.setattr(
@@ -417,6 +442,7 @@ def _zoo_spec_sequence(monkeypatch, specs):
return remaining.pop(0) if len(remaining) > 1 else remaining[0]
monkeypatch.setattr(stack, "_mlx_vlm_spec_for_installed_zoo", spec)
+ monkeypatch.setattr(stack, "_mlx_lm_spec_for_installed_zoo", lambda: stack._MLX_LM_SPEC)
def test_the_core_phase_upgrading_the_zoo_re_resolves_mlx(monkeypatch):
@@ -430,7 +456,22 @@ def test_the_core_phase_upgrading_the_zoo_re_resolves_mlx(monkeypatch):
assert len(calls) == 2
assert "MLX stack (re-resolved for the new zoo)" in _run_to_extras.steps
assert narrow in list(calls[0].args[1:])
- assert stack._MLX_VLM_SPEC in list(calls[1].args[1:])
+ assert {stack._mlx_lm_spec_for_installed_zoo(), stack._MLX_VLM_SPEC} <= set(calls[1].args[1:])
+
+
+def test_a_zoo_moving_only_its_mlx_lm_range_re_resolves_mlx(monkeypatch):
+ _zoo_spec_sequence(monkeypatch, [stack._MLX_VLM_SPEC])
+ narrow = f"{stack._MLX_LM_SPEC},==0.31.3"
+ answers = [narrow, narrow, stack._MLX_LM_SPEC]
+ monkeypatch.setattr(
+ stack,
+ "_mlx_lm_spec_for_installed_zoo",
+ lambda: answers.pop(0) if len(answers) > 1 else answers[0],
+ )
+ calls = _run_to_extras(monkeypatch, platform = "macos_arm", skip_base = False, no_torch = False)
+ assert len(calls) == 2
+ assert narrow in list(calls[0].args[1:])
+ assert stack._MLX_LM_SPEC in list(calls[1].args[1:])
def test_an_unchanged_zoo_does_not_re_resolve_mlx(monkeypatch):
@@ -444,7 +485,7 @@ def test_an_unchanged_zoo_does_not_re_resolve_mlx(monkeypatch):
def test_mlx_image_engine_pins_leave_the_mlx_stack_alone():
- assert stack._MLX_PINS == ("mlx==0.32.3", "mlx-metal==0.32.3", "mlx-lm==0.31.3")
+ assert stack._MLX_PINS == ("mlx==0.32.4", "mlx-metal==0.32.4")
names = {Requirement(spec).name.lower() for spec in stack._MLX_DIFFUSION_PINS}
names |= {Requirement(spec).name.lower() for spec in stack._MLX_DIFFUSION_DEPS}
assert names == {"mflux", "piexif", "platformdirs", "toml"}
@@ -469,6 +510,7 @@ def test_mlx_image_engine_installs_no_deps_only_where_the_mlx_stack_does(
monkeypatch, platform, no_torch
):
monkeypatch.setattr(stack, "_mlx_vlm_spec_for_installed_zoo", lambda: stack._MLX_VLM_SPEC)
+ monkeypatch.setattr(stack, "_mlx_lm_spec_for_installed_zoo", lambda: stack._MLX_LM_SPEC)
monkeypatch.setattr(stack, "_mlx_diffusion_engine_is_current", lambda: False)
_run_to_extras(monkeypatch, platform = platform, skip_base = True, no_torch = no_torch)
calls = _run_to_extras.engine_calls