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.

refactor(trainer): add warning for ignored eval_steps (#4225)

Daniel Han1c67252bcc05
diff --git a/tests/test_eval_steps_ignored_warning.py b/tests/test_eval_steps_ignored_warning.py
new file mode 100644
index 00000000000..10f0c7c78c9
--- /dev/null
+++ b/tests/test_eval_steps_ignored_warning.py
@@ -0,0 +1,78 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
+
+"""#3177: `eval_steps` is ignored unless `eval_strategy="steps"`; both checks are lifted with `ast`, CPU-only."""
+
+import ast
+import contextlib
+import io
+import warnings
+from pathlib import Path
+from typing import Optional
+
+import pytest
+from transformers import TrainingArguments
+from transformers.trainer_utils import IntervalStrategy
+
+ROOT = Path(__file__).resolve().parents[1]
+
+CASES = [
+ (10, "no", True),
+ (10, "epoch", True),
+ (10, IntervalStrategy.EPOCH, True),
+ (10, "steps", False),
+ (10, IntervalStrategy.STEPS, False),
+ (None, "no", False),
+ (None, "steps", False),
+]
+
+
+def _rl_config_snippet():
+ tree = ast.parse((ROOT / "unsloth" / "models" / "rl.py").read_text(encoding = "utf-8"))
+ for node in ast.walk(tree):
+ if (
+ isinstance(node, ast.Assign)
+ and getattr(node.targets[0], "id", None) == "check_eval_steps"
+ ):
+ return ast.literal_eval(node.value)
+ raise AssertionError("check_eval_steps not found in rl.py")
+
+
+def _unsloth_training_arguments():
+ tree = ast.parse((ROOT / "unsloth" / "trainer.py").read_text(encoding = "utf-8"))
+ cls = next(
+ n for n in tree.body if isinstance(n, ast.ClassDef) and n.name == "UnslothTrainingArguments"
+ )
+ ns = {
+ "TrainingArguments": TrainingArguments,
+ "Optional": Optional,
+ "QGaloreConfig": object,
+ "warnings": warnings,
+ }
+ exec(compile(ast.Module([cls], []), "trainer.py", "exec"), ns)
+ return ns["UnslothTrainingArguments"]
+
+
[email protected]("eval_steps,eval_strategy,warns", CASES)
+def test_rl_config_warns_on_ignored_eval_steps(eval_steps, eval_strategy, warns):
+ buf = io.StringIO()
+ with contextlib.redirect_stdout(buf):
+ exec(_rl_config_snippet(), {"eval_steps": eval_steps, "eval_strategy": eval_strategy})
+ assert ("is ignored because" in buf.getvalue()) is warns
+ if warns:
+ assert "IntervalStrategy" not in buf.getvalue()
+
+
[email protected]("eval_steps,eval_strategy,warns", CASES)
+def test_training_arguments_warns_on_ignored_eval_steps(tmp_path, eval_steps, eval_strategy, warns):
+ cls = _unsloth_training_arguments()
+ with warnings.catch_warnings(record = True) as caught:
+ warnings.simplefilter("always")
+ cls(
+ output_dir = str(tmp_path),
+ report_to = "none",
+ eval_steps = eval_steps,
+ eval_strategy = eval_strategy,
+ )
+ hits = [str(w.message) for w in caught if "is ignored because" in str(w.message)]
+ assert bool(hits) is warns
diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py
index 7671f6d98e8..cf34582ffb4 100644
--- a/unsloth/models/rl.py
+++ b/unsloth/models/rl.py
@@ -3162,6 +3162,14 @@ def _patch_trl_rl_trainers_impl(trainer_file = "grpo_trainer"):
)
extra_args += check_num_generations
+ if "eval_steps" in call_args and "eval_strategy" in call_args:
+ check_eval_steps = (
+ "if eval_steps is not None and eval_strategy != 'steps':\n"
+ ' print(f\'Unsloth: `eval_steps = {eval_steps}` is ignored because `eval_strategy` is {getattr(eval_strategy, "value", eval_strategy)!r}. Set `eval_strategy = "steps"` to evaluate every `eval_steps` steps.\')\n'
+ "\n"
+ )
+ extra_args += check_eval_steps
+
if "temperature" in call_args:
check_temperature = (
"if temperature <= 0:\n"
diff --git a/unsloth/trainer.py b/unsloth/trainer.py
index 86d92a04af8..7c5c163ad07 100644
--- a/unsloth/trainer.py
+++ b/unsloth/trainer.py
@@ -671,6 +671,13 @@ class UnslothTrainingArguments(TrainingArguments):
self.embedding_learning_rate = embedding_learning_rate
super().__init__(*args, **kwargs)
self.embedding_learning_rate = embedding_learning_rate
+ if self.eval_steps is not None and self.eval_strategy != "steps":
+ warnings.warn(
+ f"Unsloth: `eval_steps = {self.eval_steps}` is ignored because `eval_strategy` is "
+ f"{getattr(self.eval_strategy, 'value', self.eval_strategy)!r}. "
+ 'Set `eval_strategy = "steps"` to evaluate every `eval_steps` steps.',
+ stacklevel = 2,
+ )
def _create_unsloth_optimizer(