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.

Studio: chat with a full fine-tune in 16-bit instead of a 4-bit copy (#11479)

Nilay3ecdfa3d4b89
diff --git a/studio/backend/core/inference/worker.py b/studio/backend/core/inference/worker.py
index 3e8ccb0989e..c27a5160e64 100644
--- a/studio/backend/core/inference/worker.py
+++ b/studio/backend/core/inference/worker.py
@@ -211,6 +211,11 @@ def _resolve_lora_4bit(mc, load_in_4bit: bool) -> bool:
on); unknown method -> force off only when the base is not a -bnb-4bit repo.
A missing or unreadable adapter_config.json leaves the value unchanged.
"""
+ from utils.models.checkpoints import is_full_finetune_output
+
+ if load_in_4bit and not mc.is_lora and is_full_finetune_output(mc.path):
+ logger.info("Full fine-tune output has no quantization_config — setting load_in_4bit=False")
+ return False
if not (mc.is_lora and mc.path):
return load_in_4bit
diff --git a/studio/backend/routes/export.py b/studio/backend/routes/export.py
index 789bd253dd7..c9bc02ee772 100644
--- a/studio/backend/routes/export.py
+++ b/studio/backend/routes/export.py
@@ -142,20 +142,15 @@ def _is_unquantized_full_finetune(checkpoint_path: str, hf_token: HfTokenArg = N
Only ever used to turn 4-bit OFF, so every uncertain answer here is False and
behaves exactly as the code did before.
"""
- checkpoint_dir = Path(checkpoint_path)
- config_file = checkpoint_dir / "config.json"
+ from utils.models.checkpoints import is_unquantized_full_model_dir
+
try:
- if config_file.is_file():
- if (checkpoint_dir / "adapter_config.json").exists():
- return False
- config = json.loads(config_file.read_text(encoding = "utf-8-sig"))
- elif checkpoint_dir.exists():
- # A local directory without a config.json is not a full model.
- return False
- else:
- config = _hub_config(checkpoint_path, hf_token)
- except (OSError, ValueError):
+ is_local = Path(checkpoint_path).exists()
+ except OSError:
return False
+ if is_local:
+ return is_unquantized_full_model_dir(checkpoint_path)
+ config = _hub_config(checkpoint_path, hf_token)
return isinstance(config, dict) and "quantization_config" not in config
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py
index d7baf7b7ae5..457622dae1f 100644
--- a/studio/backend/routes/inference.py
+++ b/studio/backend/routes/inference.py
@@ -74,6 +74,7 @@ from urllib.parse import quote as _urlquote
# Model size extraction (shared with core/inference/llama_cpp.py)
from utils.models import extract_model_size_b as _extract_model_size_b
+from utils.models.checkpoints import is_full_finetune_output
from utils.api_errors import openai_error_body, anthropic_error_body, error_body_for_path
from utils.audio_tokens import GGUF_TTS_AUDIO_TYPES as _GGUF_TTS_AUDIO_TYPES
@@ -10633,6 +10634,10 @@ def _effective_load_in_4bit(config: ModelConfig, requested: bool) -> bool:
if getattr(config, "audio_type", None) in NATIVE_AUDIO_TYPES:
return False
load_in_4bit = requested
+ if not getattr(config, "is_lora", False) and is_full_finetune_output(
+ getattr(config, "path", None)
+ ):
+ return False
if not getattr(config, "is_lora", False) or not getattr(config, "path", None):
return load_in_4bit
adapter_cfg_path = Path(config.path) / "adapter_config.json"
diff --git a/studio/backend/tests/test_chat_load_during_training.py b/studio/backend/tests/test_chat_load_during_training.py
index b52624dad74..e094f671aa3 100644
--- a/studio/backend/tests/test_chat_load_during_training.py
+++ b/studio/backend/tests/test_chat_load_during_training.py
@@ -902,6 +902,58 @@ class TestEffectiveLoadIn4bit(unittest.TestCase):
cfg = SimpleNamespace(is_lora = True, path = d, base_model = "x")
self.assertTrue(self.route._effective_load_in_4bit(cfg, True)) # no crash
+ def _model_dir(
+ self,
+ root,
+ name,
+ config = None,
+ adapter = None,
+ ):
+ import json
+
+ d = Path(root) / name
+ d.mkdir(parents = True)
+ (d / "config.json").write_text(json.dumps(config or {"model_type": "llama"}))
+ (d / "model.safetensors").write_bytes(b"")
+ if adapter is not None:
+ (d / "adapter_config.json").write_text(json.dumps(adapter))
+ return str(d)
+
+ def _studio_home(self):
+ import os
+ import tempfile
+
+ home = tempfile.TemporaryDirectory()
+ self.addCleanup(home.cleanup)
+ patcher = patch.dict(os.environ, {"UNSLOTH_STUDIO_HOME": home.name})
+ patcher.start()
+ self.addCleanup(patcher.stop)
+ return Path(home.name)
+
+ def test_full_finetune_output_loads_16bit(self):
+ home = self._studio_home()
+ path = self._model_dir(home / "outputs", "unsloth_Qwen3-0.6B_1771227800")
+ cfg = SimpleNamespace(is_lora = False, path = path, base_model = None)
+ self.assertFalse(self.route._effective_load_in_4bit(cfg, True))
+ ckpt = self._model_dir(Path(path), "checkpoint-10")
+ cfg = SimpleNamespace(is_lora = False, path = ckpt, base_model = None)
+ self.assertFalse(self.route._effective_load_in_4bit(cfg, True))
+
+ def test_quantized_or_foreign_models_keep_4bit(self):
+ home = self._studio_home()
+ outputs = home / "outputs"
+ quantized = self._model_dir(
+ outputs, "q", {"quantization_config": {"quant_method": "bitsandbytes"}}
+ )
+ adapter = self._model_dir(outputs, "a", adapter = {})
+ outside = self._model_dir(home / "exports", "merged")
+ for path in (quantized, adapter, outside, "unsloth/Qwen3-0.6B"):
+ cfg = SimpleNamespace(is_lora = False, path = path, base_model = None)
+ self.assertTrue(self.route._effective_load_in_4bit(cfg, True), path)
+ qlora = self._model_dir(outputs, "qlora", adapter = {"unsloth_training_method": "qlora"})
+ cfg = SimpleNamespace(is_lora = True, path = qlora, base_model = "x")
+ self.assertTrue(self.route._effective_load_in_4bit(cfg, True))
+
def test_native_audio_uses_full_precision_for_admission(self):
cfg = SimpleNamespace(
is_lora = False,
diff --git a/studio/backend/tests/test_worker_full_finetune_4bit.py b/studio/backend/tests/test_worker_full_finetune_4bit.py
new file mode 100644
index 00000000000..fe8beda0081
--- /dev/null
+++ b/studio/backend/tests/test_worker_full_finetune_4bit.py
@@ -0,0 +1,81 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import json
+from pathlib import Path
+from types import SimpleNamespace
+
+import pytest
+
+from core.inference import worker
+
+
+def outputs(monkeypatch, tmp_path):
+ monkeypatch.setenv("UNSLOTH_STUDIO_HOME", str(tmp_path))
+ return tmp_path / "outputs"
+
+
+def _model_dir(
+ root,
+ name,
+ config = None,
+ adapter = None,
+):
+ d = root / name
+ d.mkdir(parents = True)
+ (d / "config.json").write_text(json.dumps(config or {"model_type": "llama"}))
+ (d / "model.safetensors").write_bytes(b"")
+ if adapter is not None:
+ (d / "adapter_config.json").write_text(json.dumps(adapter))
+ return str(d)
+
+
+def _mc(
+ path,
+ is_lora = False,
+ base_model = None,
+):
+ return SimpleNamespace(is_lora = is_lora, path = path, base_model = base_model)
+
+
+def test_full_finetune_output_loads_16bit(outputs):
+ path = _model_dir(outputs, "unsloth_Qwen3-0.6B_1771227800")
+ assert worker._resolve_lora_4bit(_mc(path), True) is False
+ assert worker._resolve_lora_4bit(_mc(path), False) is False
+
+
+def test_quantized_or_foreign_models_keep_4bit(outputs, tmp_path):
+ quantized = _model_dir(outputs, "q", {"quantization_config": {"quant_method": "bitsandbytes"}})
+ adapter = _model_dir(outputs, "a", adapter = {})
+ outside = _model_dir(tmp_path / "exports", "merged")
+ for path in (quantized, adapter, outside, "unsloth/Qwen3-0.6B"):
+ assert worker._resolve_lora_4bit(_mc(path), True) is True, path
+ qlora = _model_dir(outputs, "qlora", adapter = {"unsloth_training_method": "qlora"})
+ assert worker._resolve_lora_4bit(_mc(qlora, is_lora = True, base_model = "x"), True) is True
+
+
+def test_symlink_loop_under_outputs_keeps_4bit(outputs, monkeypatch):
+ """A looped link under outputs/ must read as "not a full fine-tune", not fault the load.
+
+ Before 3.13, resolve() reports a symlink loop as RuntimeError whatever `strict` is,
+ and RuntimeError is neither OSError nor ValueError. The call sites in this module and
+ in routes/inference.py sit outside any handler, so an escape would surface as a 500.
+ """
+ outputs.mkdir(parents = True, exist_ok = True)
+ looped, partner = outputs / "loop_a", outputs / "loop_b"
+ looped.symlink_to(partner)
+ partner.symlink_to(looped)
+ assert worker._resolve_lora_4bit(_mc(str(looped)), True) is True
+
+ # Pin that spelling on every interpreter; on 3.13+ resolve() no longer raises, so
+ # without this the test is vacuous there.
+ real_resolve = Path.resolve
+
+ def loop_raises(self, *args, **kwargs):
+ if self.name.startswith("loop_"):
+ raise RuntimeError(f"Symlink loop from {self!s}")
+ return real_resolve(self, *args, **kwargs)
+
+ monkeypatch.setattr(Path, "resolve", loop_raises)
+ assert worker._resolve_lora_4bit(_mc(str(looped)), True) is True
diff --git a/studio/backend/utils/models/checkpoints.py b/studio/backend/utils/models/checkpoints.py
index d38c570ae43..9bbc49e9709 100644
--- a/studio/backend/utils/models/checkpoints.py
+++ b/studio/backend/utils/models/checkpoints.py
@@ -269,6 +269,29 @@ def _is_model_dir(path: Path) -> bool:
return (path / "config.json").exists() or (path / "adapter_config.json").exists()
+def is_unquantized_full_model_dir(path: str | Path) -> bool:
+ model_dir = Path(path)
+ try:
+ if (model_dir / "adapter_config.json").exists():
+ return False
+ config = json.loads((model_dir / "config.json").read_text(encoding = "utf-8-sig"))
+ except (OSError, ValueError):
+ return False
+ return isinstance(config, dict) and "quantization_config" not in config
+
+
+def is_full_finetune_output(path: Optional[str]) -> bool:
+ if not path:
+ return False
+ try:
+ # Below 3.13 a symlink loop comes back as RuntimeError, not OSError, whatever
+ # `strict` says, and both callers run this outside any handler.
+ Path(path).resolve().relative_to(outputs_root().resolve())
+ except (OSError, RuntimeError, ValueError):
+ return False
+ return is_unquantized_full_model_dir(path)
+
+
def has_preview_model(output_dir: Optional[str]) -> bool:
"""True when ``output_dir`` holds a previewable root model (what ``/p/{run}``
resolves). A cancelled run keeps ``output_dir`` but saves no root adapter."""