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
Studio: make every model a defaults file covers actually load it (#8726)
Vineeth Sai Varikuntla4f5658a9f005
diff --git a/studio/backend/tests/test_model_defaults_aliases_resolve.py b/studio/backend/tests/test_model_defaults_aliases_resolve.pynew file mode 100644index 00000000000..ec26381d109--- /dev/null+++ b/studio/backend/tests/test_model_defaults_aliases_resolve.py@@ -0,0 +1,94 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Every model a defaults file says it applies to has to actually load it.++A model id reaches its YAML either through MODEL_NAME_MAPPING or through the+`org/model` -> `org_model.yaml` filename convention, and it has to get there+whether it arrives bare or as the tail of a local model directory. When it does+not, the model silently falls back to default.yaml with generic hyperparameters+instead of its tuned ones.+"""++import re+from pathlib import Path++import pytest+import yaml++from utils.models.model_config import load_model_defaults++_DEFAULTS_DIR = Path(__file__).parent.parent / "assets" / "configs" / "model_defaults"+_ALSO_APPLIES_RE = re.compile(r"^#\s*Also applies to:\s*(.+)$", re.MULTILINE)++_DEFAULT_CONFIG = yaml.safe_load((_DEFAULTS_DIR / "default.yaml").read_text(encoding = "utf-8"))+++def _configs():+ """Every tuned defaults file, by filename."""+ return sorted(p.name for p in _DEFAULTS_DIR.rglob("*.yaml") if p.name != "default.yaml")+++def _claimed_aliases():+ """(config filename, alias) for every name a defaults file claims to cover."""+ for path in sorted(_DEFAULTS_DIR.rglob("*.yaml")):+ if path.name == "default.yaml":+ continue+ header = path.read_text(encoding = "utf-8")[:1000]+ match = _ALSO_APPLIES_RE.search(header)+ if match is None:+ continue+ for alias in match.group(1).split(","):+ alias = alias.strip().strip('"').strip()+ # Skip prose such as "and its GGUF variants".+ if alias and " " not in alias:+ yield path.name, alias+++_CONFIGS = _configs()+_CLAIMED = list(_claimed_aliases())+++def _primary_name(config_name):+ return config_name[: -len(".yaml")].replace("_", "/", 1)+++def _on_disk(model_id):+ """The id as an LM Studio or custom scan folder hands it over: <root>/<publisher>/<model>.++ Those rows carry the filesystem path, not a repo id, so this is the form the defaults+ lookup actually receives for a locally stored model.+ """+ return f"/home/u/.lmstudio/models/{model_id}"+++def _load_tuned(model_id, config_name):+ """Load `model_id`'s defaults, failing if it fell through to default.yaml."""+ config = load_model_defaults(model_id)+ assert config and config != _DEFAULT_CONFIG, (+ f"{model_id} got default.yaml, not {config_name}: it reaches its config through "+ f"neither MODEL_NAME_MAPPING nor the org/model -> org_model.yaml convention"+ )+ return config+++def test_the_fixtures_are_not_empty():+ """A rename or a header reformat should fail loudly, not quietly pass."""+ assert len(_CONFIGS) > 20, f"only found {len(_CONFIGS)} defaults files"+ assert len(_CLAIMED) > 20, f"only found {len(_CLAIMED)} claimed aliases"++[email protected]("config_name", _CONFIGS, ids = lambda v: v)+def test_config_loads_under_its_own_name(config_name):+ """Bare id and local directory both have to reach the file named after them."""+ primary = _primary_name(config_name)+ own = _load_tuned(primary, config_name)+ assert _load_tuned(_on_disk(primary), config_name) == own++[email protected]("config_name, alias", _CLAIMED, ids = lambda v: v)+def test_claimed_alias_loads_its_own_defaults(config_name, alias):+ """Same for every name the header claims, in both forms."""+ own = _load_tuned(_primary_name(config_name), config_name)+ assert _load_tuned(alias, config_name) == own+ assert _load_tuned(_on_disk(alias), config_name) == owndiff --git a/studio/backend/utils/inference/inference_config.py b/studio/backend/utils/inference/inference_config.pyindex a264e06c85b..b0e95330192 100644--- a/studio/backend/utils/inference/inference_config.py+++ b/studio/backend/utils/inference/inference_config.py@@ -14,7 +14,6 @@ import structlogfrom loggers import get_loggerfrom utils.models.model_config import load_model_defaults-from utils.paths import is_local_path, normalize_pathlogger = get_logger(__name__)@@ -71,38 +70,26 @@ def get_family_inference_params(model_id: str) -> Dict[str, Any]:def _has_specific_yaml(model_identifier: str) -> bool:- """Check if a model has its own YAML config (not just default.yaml)."""- from utils.models.model_config import _REVERSE_MODEL_MAPPING+ """Check if a model has its own YAML config (not just default.yaml).++ Shares defaults_lookup_names with load_model_defaults so this answer cannot disagree with+ the config it actually loaded -- disagreeing would let family defaults override a model's+ own inference params.+ """+ from utils.models.model_config import _REVERSE_MODEL_MAPPING, defaults_lookup_namesscript_dir = Path(__file__).parent.parent.parentdefaults_dir = script_dir / "assets" / "configs" / "model_defaults"- if model_identifier.lower() in _REVERSE_MODEL_MAPPING:+ names = defaults_lookup_names(model_identifier)+ if any(name.lower() in _REVERSE_MODEL_MAPPING for name in names):return True- # For local paths, normalize backslashes so Path().parts splits correctly,- # then match the last 1-2 components against the registry (mirrors load_model_defaults).- _is_local = is_local_path(model_identifier)- _normalized = normalize_path(model_identifier) if _is_local else model_identifier-- if _is_local:- parts = Path(_normalized).parts- for depth in (2, 1):- if len(parts) >= depth:- suffix = "/".join(parts[-depth:])- if suffix.lower() in _REVERSE_MODEL_MAPPING:- return True- _lookup = Path(_normalized).name- else:- _lookup = model_identifier-- # Exact filename match (basename for local paths; absolute paths break rglob on Windows).- model_filename = _lookup.replace("/", "_") + ".yaml"- for config_path in defaults_dir.rglob(model_filename):- if config_path.is_file():- return True-- return False+ return any(+ config_path.is_file()+ for name in names+ for config_path in defaults_dir.rglob(name.replace("/", "_") + ".yaml")+ )def load_inference_config(model_identifier: str) -> Dict[str, Any]:diff --git a/studio/backend/utils/models/model_config.py b/studio/backend/utils/models/model_config.pyindex ad5fd1ea485..26b28573c76 100644--- a/studio/backend/utils/models/model_config.py+++ b/studio/backend/utils/models/model_config.py@@ -215,18 +215,22 @@ MODEL_NAME_MAPPING = {"unsloth_gemma-4-31B-it.yaml": ["unsloth/gemma-4-31B-it","google/gemma-4-31B-it",+ "unsloth/gemma-4-31B-it-GGUF",],"unsloth_gemma-4-26B-A4B-it.yaml": ["unsloth/gemma-4-26B-A4B-it","google/gemma-4-26B-A4B-it",+ "unsloth/gemma-4-26B-A4B-it-GGUF",],"unsloth_gemma-4-E2B-it.yaml": ["unsloth/gemma-4-E2B-it","google/gemma-4-E2B-it",+ "unsloth/gemma-4-E2B-it-GGUF",],"unsloth_gemma-4-E4B-it.yaml": ["unsloth/gemma-4-E4B-it","google/gemma-4-E4B-it",+ "unsloth/gemma-4-E4B-it-GGUF",],"unsloth_gemma-4-31B.yaml": ["unsloth/gemma-4-31B",@@ -441,6 +445,10 @@ MODEL_NAME_MAPPING = {"Qwen/Qwen3-4B-Instruct-2507-FP8","unsloth/Qwen3-4B-Instruct-2507-FP8",],+ "unsloth_Qwen3-30B-A3B-Instruct-2507.yaml": [+ "Qwen/Qwen3-30B-A3B-Instruct-2507",+ "unsloth/Qwen3-30B-A3B-Instruct-2507-bnb-4bit",+ ],"unsloth_Qwen3-4B-Thinking-2507.yaml": ["unsloth/Qwen3-4B-Thinking-2507-unsloth-bnb-4bit","Qwen/Qwen3-4B-Thinking-2507",@@ -486,6 +494,11 @@ MODEL_NAME_MAPPING = {"unsloth/tinyllama","TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T",],+ "unsloth_GLM-4.7-Flash.yaml": [+ "unsloth/GLM-4.7-Flash-unsloth-bnb-4bit",+ "unsloth/GLM-4.7-Flash-bnb-4bit",+ "THUDM/GLM-4.7-Flash",+ ],"unsloth_whisper-large-v3.yaml": ["unsloth/whisper-large-v3","openai/whisper-large-v3",@@ -3496,6 +3509,23 @@ def _log_model_defaults(getattr(logger, level)(message)+def defaults_lookup_names(model_name: str) -> List[str]:+ """Names to look a model id up under in configs/model_defaults, most specific first.++ A repo id is used as-is. A local path also contributes its last two and last one path+ components, so a model on disk resolves to the same config as the id it came from: an+ LM Studio or custom scan folder is laid out `<root>/<publisher>/<model>`, and an adapter+ can point at `<root>/Spark-TTS-0.5B/LLM`. The drive or root is dropped: it is part of no+ id, and it makes rglob raise "Non-relative patterns are unsupported" on Windows.+ """+ if not is_local_path(model_name):+ return [model_name]+ # Normalize Windows backslashes: pathlib treats them as literals on POSIX/WSL.+ path = Path(normalize_path(model_name))+ parts = path.parts[1:] if path.anchor else path.parts+ return ["/".join(parts[-depth:]) for depth in (2, 1) if len(parts) >= depth]++def load_model_defaults(model_name: str) -> Dict[str, Any]:"""Load default training parameters for a model from a YAML file.@@ -3511,53 +3541,35 @@ def load_model_defaults(model_name: str) -> Dict[str, Any]:script_dir = Path(__file__).parent.parent.parentdefaults_dir = script_dir / "assets" / "configs" / "model_defaults"- if model_name.lower() in _REVERSE_MODEL_MAPPING:- canonical_file = _REVERSE_MODEL_MAPPING[model_name.lower()]+ lookup_names = defaults_lookup_names(model_name)++ for name in lookup_names:+ canonical_file = _REVERSE_MODEL_MAPPING.get(name.lower())+ if canonical_file is None:+ continuefor config_path in defaults_dir.rglob(canonical_file):if config_path.is_file():with open(config_path, "r", encoding = "utf-8") as f:config = yaml.safe_load(f) or {}_log_model_defaults(- f"Loaded model defaults from {config_path} (via mapping)",+ f"Loaded model defaults from {config_path} (via mapping '{name}')",f"{model_name}|{config_path}|mapping",)return config- # For local paths (e.g. .../Spark-TTS-0.5B/LLM from adapter_config.json, or a Windows- # path), match the last 1-2 path components against the registry.- _is_local_path = is_local_path(model_name)- # Normalize Windows backslashes: pathlib treats them as literals on POSIX/WSL.- _normalized = normalize_path(model_name) if _is_local_path else model_name- if model_name.lower() not in _REVERSE_MODEL_MAPPING and _is_local_path:- parts = Path(_normalized).parts- for depth in [2, 1]:- if len(parts) >= depth:- suffix = "/".join(parts[-depth:])- if suffix.lower() in _REVERSE_MODEL_MAPPING:- canonical_file = _REVERSE_MODEL_MAPPING[suffix.lower()]- for config_path in defaults_dir.rglob(canonical_file):- if config_path.is_file():- with open(config_path, "r", encoding = "utf-8") as f:- config = yaml.safe_load(f) or {}- _log_model_defaults(- f"Loaded model defaults from {config_path} (via path suffix '{suffix}')",- f"{model_name}|{config_path}|suffix",- )- return config-- # Exact name match (backward compat). For local paths use only the dir basename: absolute- # paths make rglob raise "Non-relative patterns are unsupported" on Windows.- _lookup_name = Path(_normalized).name if _is_local_path else model_name- model_filename = _lookup_name.replace("/", "_") + ".yaml"- for config_path in defaults_dir.rglob(model_filename):- if config_path.is_file():- with open(config_path, "r", encoding = "utf-8") as f:- config = yaml.safe_load(f) or {}- _log_model_defaults(- f"Loaded model defaults from {config_path}",- f"{model_name}|{config_path}|exact",- )- return config+ # org/model -> org_model.yaml. Runs after the whole registry so an alias never loses to+ # a filename, and over every lookup name so a config covers its own id from a local path+ # too, without having to repeat that id in MODEL_NAME_MAPPING.+ for name in lookup_names:+ for config_path in defaults_dir.rglob(name.replace("/", "_") + ".yaml"):+ if config_path.is_file():+ with open(config_path, "r", encoding = "utf-8") as f:+ config = yaml.safe_load(f) or {}+ _log_model_defaults(+ f"Loaded model defaults from {config_path} (via name '{name}')",+ f"{model_name}|{config_path}|exact",+ )+ return configdefault_config_path = defaults_dir / "default.yaml"if default_config_path.exists():