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
CLI: refuse unsloth train when num_epochs and max_steps are both 0 (#17116)
Vineeth Sai Varikuntlad26a6ce18699
diff --git a/unsloth_cli/commands/train.py b/unsloth_cli/commands/train.pyindex d497e90bf01..be6ae595d06 100644--- a/unsloth_cli/commands/train.py+++ b/unsloth_cli/commands/train.py@@ -332,6 +332,15 @@ def train(typer.echo(f"Error: {e}", err = True)raise typer.Exit(code = 2)+ # Otherwise it trains 0 steps, saves an untrained adapter and exits 0 (Studio refuses this too).+ if cfg.training.num_epochs <= 0 and cfg.training.max_steps <= 0:+ typer.echo(+ "Error: num_epochs (--num-epochs) or max_steps (--max-steps) must be > 0; "+ f"got num_epochs={cfg.training.num_epochs}, max_steps={cfg.training.max_steps}.",+ err = True,+ )+ raise typer.Exit(code = 2)+# CLI/env tokens take precedence; guard against unresolved typer.Option.from typer.models import OptionInfodiff --git a/unsloth_cli/tests/test_train_cli_override_validation.py b/unsloth_cli/tests/test_train_cli_override_validation.pyindex 6dd31639051..bd9ce56b637 100644--- a/unsloth_cli/tests/test_train_cli_override_validation.py+++ b/unsloth_cli/tests/test_train_cli_override_validation.py@@ -92,6 +92,37 @@ def test_valid_flags_still_override_the_config(tmp_path):assert "num_epochs: 5" in result.output+ "args",+ [("--num-epochs", "0"), ("--num-epochs", "-2", "--max-steps", "-5")],+)+def test_no_epochs_and_no_max_steps_exits_2(args):+ result = _dry_run(*args)++ assert result.exit_code == 2+ assert result.output.startswith("Error: ")+ assert "--num-epochs" in result.output+ assert "--max-steps" in result.output+++def test_a_config_with_zero_epochs_and_no_max_steps_exits_2(tmp_path):+ path = tmp_path / "config.yaml"+ path.write_text("training:\n num_epochs: 0\n", encoding = "utf-8")++ result = _dry_run("--config", str(path))++ assert result.exit_code == 2+ assert "num_epochs" in result.output+++def test_zero_epochs_with_max_steps_is_accepted():+ result = _dry_run("--num-epochs", "0", "--max-steps", "50")++ assert result.exit_code == 0, result.output+ assert "num_epochs: 0" in result.output+ assert "max_steps: 50" in result.output++def test_apply_overrides_raises_config_error_and_names_the_flag():with pytest.raises(ConfigError) as excinfo:Config().apply_overrides(training_type = "lroa")