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
Legacy CLI: accept --dtype None on every backend, not only MLX (#15775)
Vineeth Sai Varikuntla69854d6b9075
diff --git a/unsloth-cli.py b/unsloth-cli.pyindex a50cb011009..7d03c19df53 100644--- a/unsloth-cli.py+++ b/unsloth-cli.py@@ -26,8 +26,8 @@ def _is_mlx_backend(unsloth_module):return bool(getattr(unsloth_module, "_IS_MLX", False))-def _normalize_dtype(dtype, is_mlx):- if is_mlx and isinstance(dtype, str) and dtype.strip().lower() in {"", "none", "auto"}:+def _normalize_dtype(dtype):+ if isinstance(dtype, str) and dtype.strip().lower() in {"", "none", "auto"}:return Nonereturn dtype@@ -233,7 +233,7 @@ def run(args):model, tokenizer = FastLanguageModel.from_pretrained(model_name = args.model_name,max_seq_length = args.max_seq_length,- dtype = _normalize_dtype(args.dtype, is_mlx),+ dtype = _normalize_dtype(args.dtype),load_in_4bit = args.load_in_4bit,device_map = device_map,)diff --git a/unsloth/models/loader.py b/unsloth/models/loader.pyindex dbf53df547f..9b84f8f449a 100644--- a/unsloth/models/loader.py+++ b/unsloth/models/loader.py@@ -1403,7 +1403,7 @@ class FastLanguageModel(FastLlamaModel):)return _mark_requested_float32(delegated, user_float32), tokenizer- if isinstance(dtype, str) and dtype in ["float16", "bfloat16"]:+ if isinstance(dtype, str) and dtype in ["float16", "bfloat16", "float32"]:dtype = getattr(torch, dtype)assert (dtype is None@@ -2329,6 +2329,8 @@ class FastModel(FastBaseModel):check_tiling_available(unsloth_tiled_mlp)# Login to allow private models. Before normalization: dtype is also derived below from a 4bit config's compute dtype, which is not a request for the whole model.user_float32 = _requested_float32(dtype)+ if isinstance(dtype, str) and dtype in ["float16", "bfloat16", "float32"]:+ dtype = getattr(torch, dtype)token = hf_login(token)if whisper_language is not None:assert type(whisper_language) is strdiff --git a/unsloth_cli/tests/test_legacy_cli_dtype.py b/unsloth_cli/tests/test_legacy_cli_dtype.pynew file mode 100644index 00000000000..33cdd5d79fd--- /dev/null+++ b/unsloth_cli/tests/test_legacy_cli_dtype.py@@ -0,0 +1,76 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""unsloth-cli.py documents `--dtype None` for auto detection, but the loader wants a real None."""++import importlib.util+import sys+import types+from pathlib import Path++import pytest++_REPO_ROOT = Path(__file__).resolve().parents[2]+++class _Stop(Exception):+ pass+++def _load_legacy_cli():+ spec = importlib.util.spec_from_file_location(+ "unsloth_legacy_cli_dtype", _REPO_ROOT / "unsloth-cli.py"+ )+ module = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(module)+ return module+++def _module(name, **attrs):+ module = types.ModuleType(name)+ module.__dict__.update(attrs)+ return module+++ "spelling, expected",+ [("None", None), ("none", None), ("auto", None), ("", None), ("bfloat16", "bfloat16")],+)+def test_dtype_reaches_the_loader_as_none_or_unchanged(monkeypatch, spelling, expected):+ seen = {}++ class FastLanguageModel:+ @staticmethod+ def from_pretrained(**kwargs):+ seen.update(kwargs)+ raise _Stop++ for name, module in {+ "unsloth": _module(+ "unsloth",+ FastLanguageModel = FastLanguageModel,+ is_bfloat16_supported = lambda: False,+ RawTextDataLoader = object,+ ),+ "unsloth.models": _module("unsloth.models"),+ "unsloth.models.loader_utils": _module(+ "unsloth.models.loader_utils", prepare_device_map = lambda: (None, False)+ ),+ "datasets": _module("datasets", load_dataset = None),+ "transformers": _module("transformers"),+ "transformers.utils": _module("transformers.utils", strtobool = None),+ "trl": _module("trl", SFTTrainer = None, SFTConfig = None),+ }.items():+ monkeypatch.setitem(sys.modules, name, module)++ legacy_cli = _load_legacy_cli()+ args = types.SimpleNamespace(+ model_name = "unsloth/llama-3-8b",+ max_seq_length = 2048,+ dtype = spelling,+ load_in_4bit = True,+ use_dora = False,+ )+ with pytest.raises(_Stop):+ legacy_cli.run(args)+ assert seen["dtype"] == expected