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 Save Steps 0 actually turn off checkpoints (#11232)
Nilayf250c733d494
diff --git a/studio/backend/core/training/trainer.py b/studio/backend/core/training/trainer.pyindex ad534ff7ab4..5913c486d19 100644--- a/studio/backend/core/training/trainer.py+++ b/studio/backend/core/training/trainer.py@@ -89,6 +89,7 @@ from trl import SFTTrainer, SFTConfigfrom .training import (TrainingProgress,+ apply_save_strategy,create_mlx_trainer_adapter,should_use_mlx_training_backend,)@@ -686,10 +687,7 @@ class UnslothTrainer:else:config["num_train_epochs"] = training_args.get("num_epochs", 3)- save_steps_val = training_args.get("save_steps", 0)- if save_steps_val and save_steps_val > 0:- config["save_steps"] = save_steps_val- config["save_strategy"] = "steps"+ apply_save_strategy(config, training_args.get("save_steps", 0))if extra_args:config.update(extra_args)@@ -4081,10 +4079,7 @@ class UnslothTrainer:config_args["warmup_steps"] = 5logger.info("Using default warmup_steps: 5\n")- save_steps_val = training_args.get("save_steps", 0)- if save_steps_val and save_steps_val > 0:- config_args["save_steps"] = save_steps_val- config_args["save_strategy"] = "steps"+ apply_save_strategy(config_args, training_args.get("save_steps", 0))max_steps_val = training_args.get("max_steps", 0)if max_steps_val and max_steps_val > 0:diff --git a/studio/backend/core/training/training.py b/studio/backend/core/training/training.pyindex e2e75a848bf..c19419c056f 100644--- a/studio/backend/core/training/training.py+++ b/studio/backend/core/training/training.py@@ -157,6 +157,16 @@ def _coerce_optional_bool(value, default: bool) -> bool:return bool(value)+def apply_save_strategy(config, save_steps_val):+ # Save Steps 0 means "no checkpoints"; without an explicit strategy HF defaults to every 500 steps.+ if save_steps_val and save_steps_val > 0:+ config["save_steps"] = save_steps_val+ config["save_strategy"] = "steps"+ else:+ config["save_strategy"] = "no"+ return config++def _coerce_optional_nonneg_float(name: str, value):"""Reject negatives and non-finite; `ge=0` misses raw callers, and inf never binds."""if value is None:diff --git a/studio/backend/core/training/worker.py b/studio/backend/core/training/worker.pyindex 44d6c3bb61d..07c7175ea30 100644--- a/studio/backend/core/training/worker.py+++ b/studio/backend/core/training/worker.py@@ -5057,6 +5057,7 @@ def _run_embedding_training(event_queue: Any, stop_queue: Any, config: dict) ->log_frequency = config.get("log_frequency", 50)from core.training.trainer import _drop_hf_stdout_callbacks, _hf_stdout_progress_disabled+ from core.training.training import apply_save_strategytraining_args_kwargs = {"output_dir": output_dir,@@ -5088,9 +5089,7 @@ def _run_embedding_training(event_queue: Any, stop_queue: Any, config: dict) ->elif warmup_steps_val is not None and warmup_steps_val > 0:training_args_kwargs["warmup_steps"] = warmup_steps_val- if save_steps_val and save_steps_val > 0:- training_args_kwargs["save_steps"] = save_steps_val- training_args_kwargs["save_strategy"] = "steps"+ apply_save_strategy(training_args_kwargs, save_steps_val)args = SentenceTransformerTrainingArguments(**training_args_kwargs)diff --git a/studio/backend/tests/test_save_steps_zero_disables_checkpoints.py b/studio/backend/tests/test_save_steps_zero_disables_checkpoints.pynew file mode 100644index 00000000000..d32f39e5c36--- /dev/null+++ b/studio/backend/tests/test_save_steps_zero_disables_checkpoints.py@@ -0,0 +1,149 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++from __future__ import annotations++import contextlib+import sys+from pathlib import Path++_BACKEND = Path(__file__).resolve().parent.parent+if str(_BACKEND) not in sys.path:+ sys.path.insert(0, str(_BACKEND))++import importlib # noqa: E402+import types # noqa: E402+from unittest.mock import MagicMock # noqa: E402++import pytest # noqa: E402+++_STUBBED: list[str] = []+++def _stub_if_missing(name, attrs):+ if name in sys.modules:+ return+ try:+ importlib.import_module(name)+ return+ except Exception: # noqa: BLE001 - stub unusable imports+ pass+ _STUBBED.append(name)+ mod = types.ModuleType(name)+ mod.__spec__ = None+ for attr in attrs:+ setattr(mod, attr, MagicMock())+ sys.modules[name] = mod+ parent, _, child = name.rpartition(".")+ if parent and parent in sys.modules:+ setattr(sys.modules[parent], child, mod)+++_stub_if_missing("unsloth", ("FastLanguageModel", "FastVisionModel", "is_bfloat16_supported"))+_stub_if_missing("unsloth.chat_templates", ("get_chat_template",))+_stub_if_missing("trl", ("SFTTrainer", "SFTConfig"))++from core.training import trainer as tmod # noqa: E402++for _name in reversed(_STUBBED):+ sys.modules.pop(_name, None)+++CASES = [(0, "no", None), (None, "no", None), (25, "steps", 25)]+++def trainer(monkeypatch):+ monkeypatch.setattr(tmod, "should_use_mlx_training_backend", lambda *a, **k: False)+ t = tmod.UnslothTrainer()+ t.model_name = "unsloth/csm-1b"+ return t++[email protected]("save_steps,strategy,steps", CASES)+def test_audio_training_args(trainer, tmp_path, save_steps, strategy, steps):+ transformers = pytest.importorskip("transformers")++ config = trainer._build_audio_training_args(+ {"save_steps": save_steps, "max_steps": 8, "optim": "adamw_torch"}, str(tmp_path)+ )+ assert config["save_strategy"] == strategy+ assert config.get("save_steps") == steps++ config.update(bf16 = False, fp16 = False, use_cpu = True, report_to = [])+ args = transformers.TrainingArguments(**config)+ assert args.save_strategy == strategy+ if steps:+ assert args.save_steps == steps++[email protected]("save_steps,strategy,steps", CASES)+def test_generic_sft_config_args(trainer, tmp_path, monkeypatch, save_steps, strategy, steps):+ captured = {}++ class _FakeSFTConfig:+ def __init__(self, **kwargs):+ captured.update(kwargs)++ class _FakeSFTTrainer:+ def __init__(self, **kwargs):+ pass++ def add_callback(self, cb):+ pass++ def train(self, **kwargs):+ pass++ monkeypatch.setattr(tmod, "SFTConfig", _FakeSFTConfig, raising = False)+ monkeypatch.setattr(tmod, "SFTTrainer", _FakeSFTTrainer, raising = False)+ monkeypatch.setattr(tmod, "resolve_output_dir", lambda p: tmp_path, raising = True)+ monkeypatch.setattr(tmod, "ensure_dir", lambda p: p, raising = True)+ monkeypatch.setattr(tmod, "_drop_hf_stdout_callbacks", lambda trainer: None, raising = True)+ monkeypatch.setattr(+ tmod.UnslothTrainer, "_finalize_training", lambda self, *a, **k: None, raising = True+ )+ monkeypatch.setattr(+ tmod.UnslothTrainer, "_preflight_first_batch", lambda self: None, raising = True+ )++ trainer._audio_type = "bicodec"+ trainer.model = object()+ trainer.tokenizer = object()+ trainer.model_name = "unsloth/spark-tts"++ rows = [{"text": "a"}, {"text": "b"}]+ # _train_worker runs past config construction into stubbed-out training; only the+ # captured config matters here, so let it unwind on the stubs.+ with contextlib.suppress(AttributeError, TypeError, ValueError, KeyError):+ trainer._train_worker(+ {"dataset": rows, "final_format": "audio_bicodec"},+ save_steps = save_steps,+ batch_size = 2,+ gradient_accumulation_steps = 1,+ max_steps = 8,+ warmup_steps = 0,+ output_dir = str(tmp_path),+ )++ assert captured, "the config was never built, so this asserts nothing"+ assert captured["save_strategy"] == strategy+ assert captured.get("save_steps") == steps++[email protected]("save_steps,strategy,steps", CASES)+def test_apply_save_strategy(save_steps, strategy, steps):+ from core.training.training import apply_save_strategy++ kwargs = {}+ apply_save_strategy(kwargs, save_steps)+ assert kwargs["save_strategy"] == strategy+ assert kwargs.get("save_steps") == steps+++def test_embedding_training_uses_shared_save_strategy():+ text = (_BACKEND / "core/training/worker.py").read_text(encoding = "utf-8")+ body = text[text.index("def _run_embedding_training") :]+ body = body[: body.index("SentenceTransformerTrainingArguments(")]+ assert "apply_save_strategy(training_args_kwargs, save_steps_val)" in body