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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Decision models on MLX: refuse a config.json model_file unless trusted (#17391)
Daniel Han3144ae631879
diff --git a/tests/test_decision_mlx_guards.py b/tests/test_decision_mlx_guards.pyindex bd4d6f83598..11dc6baeda7 100644--- a/tests/test_decision_mlx_guards.py+++ b/tests/test_decision_mlx_guards.py@@ -202,3 +202,41 @@ def test_an_older_zoo_is_told_to_upgrade_for_a_d1(decision_mlx, monkeypatch, tmpmonkeypatch.setattr(decision_mlx, "_decision_zoo", lambda: zoo)with pytest.raises(ImportError, match = "newer unsloth-zoo"):_load_d1(decision_mlx, tmp_path)++[email protected]("head", ["d1", "clef"])+def test_a_language_model_naming_its_own_model_file_is_refused(+ decision_mlx, monkeypatch, tmp_path, head+):+ # mlx-vlm / mlx-lm exec a config.json model_file, so it must never reach the zoo loaders.+ zoo, *_ = _d1_zoo(tmp_path)+ zoo.load_language_model_as_d1 = lambda *args, **kwargs: pytest.fail(+ "model_file reached the d1 loader"+ )+ zoo.load_language_model_as_clef = lambda *args, **kwargs: pytest.fail(+ "model_file reached the Clef loader"+ )+ monkeypatch.setattr(decision_mlx, "_decision_zoo", lambda: zoo)+ (tmp_path / "config.json").write_text(+ json.dumps({"model_type": "lfm3_vl", "model_file": "evil.py"}), encoding = "utf-8"+ )+ with pytest.raises(ValueError, match = "repository code"):+ _load_d1(decision_mlx, tmp_path, head)+++def test_a_decision_checkpoint_naming_its_own_model_file_is_refused(+ decision_mlx, monkeypatch, tmp_path+):+ monkeypatch.setattr(decision_mlx, "_checkpoint_folder", lambda *args: tmp_path)+ monkeypatch.setattr(decision_mlx, "is_clef_checkpoint", lambda folder: True)+ monkeypatch.setattr(decision_mlx, "_is_plain_lm", lambda *args: False)+ monkeypatch.setattr(+ decision_mlx,+ "_load_clef",+ lambda *args, **kwargs: pytest.fail("model_file reached the loader"),+ )+ (tmp_path / "config.json").write_text(+ json.dumps({"architectures": ["D1Model"], "model_file": "evil.py"}), encoding = "utf-8"+ )+ with pytest.raises(ValueError, match = "repository code"):+ decision_mlx.FastDecisionModel.from_pretrained(str(tmp_path))diff --git a/unsloth/models/decision_mlx.py b/unsloth/models/decision_mlx.pyindex d71df89f442..7d00ffdedd0 100644--- a/unsloth/models/decision_mlx.py+++ b/unsloth/models/decision_mlx.py@@ -681,6 +681,20 @@ def _d1_temperatures(folder) -> dict:}+def _refuse_model_file(folder):+ # mlx-lm / mlx-vlm exec a config.json `model_file` on load, and decision models never take remote code.+ path = Path(folder) / "config.json"+ try:+ declared = json.loads(path.read_text(encoding = "utf-8")).get("model_file")+ except (OSError, ValueError, AttributeError):+ return+ if declared:+ raise ValueError(+ f"Unsloth: {folder} names its own model code ({declared!r}) in config.json. "+ "Decision models do not run repository code, so it cannot be loaded."+ )++def _load_lm_as_d1(zoo,folder,@@ -753,6 +767,7 @@ def _load_lm_as_clef(f"Unsloth: {folder} holds LoRA adapters over a base model, which MLX does not load. ""Merge them into the base model first.")+ _refuse_model_file(folder)zoo = _decision_zoo()d1 = getattr(zoo, "FAMILIES", {}).get("d1")if decision_head == "d1" or (d1 is not None and d1.matches(folder)):@@ -814,6 +829,7 @@ class FastDecisionModel:lm = kwargs.get("decision_head") is not Noneif not lm:folder = _checkpoint_folder(model_name, subfolder, token, revision, local_files_only)+ _refuse_model_file(folder)if (lm or is_clef_checkpoint(folder)) and dtype is not None:raise NotImplementedError(f"Unsloth: Clef on MLX trains at its checkpoint's precision, not {dtype}."