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.

fix(eval): reserve explicit YAML task names (#15984)

Henry Suee3c27179eab
diff --git a/unsloth_cli/commands/eval.py b/unsloth_cli/commands/eval.py
index c4901f1b152..125ea9aacd6 100644
--- a/unsloth_cli/commands/eval.py
+++ b/unsloth_cli/commands/eval.py
@@ -13,7 +13,7 @@ import time
from importlib.metadata import PackageNotFoundError, version
from importlib.util import find_spec
from pathlib import Path, PureWindowsPath
-from typing import List, Optional, Tuple
+from typing import Dict, List, Optional, Tuple
import typer
@@ -342,7 +342,17 @@ def resolve_tasks(
entries = [e.strip() for e in tasks.split(",") if e.strip()]
if not entries:
raise ValueError("No tasks provided. Pass --tasks with at least one task.")
- plain = {e for e in entries if Path(e).suffix.lower() not in _DATASET_SUFFIXES | _YAML_SUFFIXES}
+ reserved = {
+ e for e in entries if Path(e).suffix.lower() not in _DATASET_SUFFIXES | _YAML_SUFFIXES
+ }
+ yaml_tasks: Dict[str, Tuple[str, bool]] = {}
+ for entry in entries:
+ path = Path(entry)
+ if path.suffix.lower() in _YAML_SUFFIXES:
+ if not path.exists():
+ raise FileNotFoundError(f"Custom task file not found: {entry}")
+ yaml_tasks[entry] = _yaml_task_name(path)
+ reserved.add(yaml_tasks[entry][0])
names: List[str] = []
include_paths: List[str] = []
@@ -357,9 +367,7 @@ def resolve_tasks(
path = Path(entry)
suffix = path.suffix.lower()
if suffix in _YAML_SUFFIXES:
- if not path.exists():
- raise FileNotFoundError(f"Custom task file not found: {entry}")
- name, needs_dir = _yaml_task_name(path)
+ name, needs_dir = yaml_tasks[entry]
if needs_dir:
add(name, path.resolve().parent)
else:
@@ -373,7 +381,7 @@ def resolve_tasks(
raise FileNotFoundError(f"Dataset file not found: {entry}")
# An include-path task overrides a registered one of the same name, so avoid names requested alongside (gsm8k,./gsm8k.jsonl).
name, counter = path.stem, 2
- while name in names or name in plain:
+ while name in names or name in reserved:
name, counter = f"{path.stem}_{counter}", counter + 1
if name != path.stem:
typer.echo(f"Note: running dataset '{path.name}' as task '{name}'.")
diff --git a/unsloth_cli/tests/test_eval.py b/unsloth_cli/tests/test_eval.py
index f421ca094b8..182bad150f0 100644
--- a/unsloth_cli/tests/test_eval.py
+++ b/unsloth_cli/tests/test_eval.py
@@ -107,6 +107,81 @@ def test_dataset_task_stays_clear_of_names_requested_alongside(tmp_path):
assert names == ["gsm8k", "gsm8k_2", "gsm8k_3"]
[email protected]("suffix", [".yaml", ".yml"])
[email protected]("dataset_first", [True, False])
+def test_dataset_task_avoids_explicit_yaml_name(tmp_path, suffix, dataset_first):
+ data = tmp_path / "qa.jsonl"
+ data.write_text("{}\n")
+ task = tmp_path / f"custom{suffix}"
+ task.write_text("task: qa\ndataset_path: json\n")
+ entries = [data, task] if dataset_first else [task, data]
+ names, includes = evalmod.resolve_tasks(",".join(map(str, entries)), "q", "a", tmp_path / "tmp")
+ assert names == (["qa_2", "qa"] if dataset_first else ["qa", "qa_2"])
+ generated = (tmp_path / "tmp" / "generated").resolve()
+ custom = (tmp_path / "tmp" / "custom").resolve()
+ assert includes == list(map(str, [generated, custom] if dataset_first else [custom, generated]))
+ spec = yaml.safe_load((generated / "qa_2.yaml").read_text())
+ assert spec["task"] == "qa_2"
+ assert spec["dataset_kwargs"] == {"data_files": str(data.resolve())}
+ assert yaml.safe_load((custom / "qa.yaml").read_text())["task"] == "qa"
+
+
[email protected]("dataset_first", [True, False])
+def test_dataset_task_avoids_explicit_group_name(tmp_path, dataset_first):
+ data = tmp_path / "suite.csv"
+ data.write_text("q,a\n")
+ group = tmp_path / "custom.yaml"
+ group.write_text("group: suite\ntask: [a, b]\n")
+ entries = [data, group] if dataset_first else [group, data]
+ names, includes = evalmod.resolve_tasks(",".join(map(str, entries)), "q", "a", tmp_path / "tmp")
+ assert names == (["suite_2", "suite"] if dataset_first else ["suite", "suite_2"])
+ generated = (tmp_path / "tmp" / "generated").resolve()
+ assert includes == list(
+ map(
+ str,
+ [generated, tmp_path.resolve()] if dataset_first else [tmp_path.resolve(), generated],
+ )
+ )
+ spec = yaml.safe_load((generated / "suite_2.yaml").read_text())
+ assert spec["task"] == "suite_2"
+ assert spec["dataset_kwargs"] == {"data_files": str(data.resolve())}
+
+
[email protected]("dataset_first", [True, False])
+def test_dataset_tasks_avoid_explicit_yaml_numeric_suffixes(tmp_path, dataset_first):
+ data = [tmp_path / "qa.jsonl", tmp_path / "qa.csv"]
+ data[0].write_text("{}\n")
+ data[1].write_text("q,a\n")
+ tasks = [tmp_path / "custom.yaml", tmp_path / "other.yaml"]
+ tasks[0].write_text("task: qa\n")
+ tasks[1].write_text("task: qa_2\n")
+ entries = data + tasks if dataset_first else tasks + data
+ names, _ = evalmod.resolve_tasks(",".join(map(str, entries)), "q", "a", tmp_path / "tmp")
+ assert names == (
+ ["qa_3", "qa_4", "qa", "qa_2"] if dataset_first else ["qa", "qa_2", "qa_3", "qa_4"]
+ )
+ for name, path in zip(["qa_3", "qa_4"], data):
+ spec = yaml.safe_load((tmp_path / "tmp" / "generated" / f"{name}.yaml").read_text())
+ assert spec["task"] == name
+ assert spec["dataset_kwargs"] == {"data_files": str(path.resolve())}
+
+
[email protected]("duplicate", ["yaml", "same_yaml", "plain_first", "plain_last"])
+def test_explicit_yaml_names_still_reject_duplicates(tmp_path, duplicate):
+ task = tmp_path / "custom.yaml"
+ task.write_text("task: qa\n")
+ other = tmp_path / "other.yaml"
+ other.write_text("task: qa\n")
+ entries = {
+ "yaml": [str(task), str(other)],
+ "same_yaml": [str(task), str(task)],
+ "plain_first": ["qa", str(task)],
+ "plain_last": [str(task), "qa"],
+ }[duplicate]
+ with pytest.raises(ValueError, match = "Duplicate task 'qa' in --tasks"):
+ evalmod.resolve_tasks(",".join(entries), "q", "a", tmp_path / "tmp")
+
+
def test_standalone_yaml_is_copied_alone(tmp_path):
(tmp_path / "broken.yaml").write_text("task: [unclosed\n")
task = tmp_path / "mine.yml"
@@ -338,6 +413,17 @@ def test_unsloth_backend_writes_results(env, tmp_path):
assert saved["results"]["gsm8k"]["exact_match,strict"] == 0.42
+def test_eval_dataset_before_yaml_with_same_task_name(env, tmp_path):
+ data = tmp_path / "qa.jsonl"
+ data.write_text("{}\n")
+ task = tmp_path / "custom.yaml"
+ task.write_text("task: qa\ndataset_path: json\n")
+ result = _run("fake/model", "--tasks", f"{data},{task}", "-o", str(tmp_path / "out"))
+ assert result.exit_code == 0, result.output
+ assert env["tasks"] == ["qa_2", "qa"]
+ assert env["task_managers"] == 1
+
+
def test_default_output_keeps_every_run(env, tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
monkeypatch.setattr(evalmod, "time", SimpleNamespace(time = lambda: 1761480000), raising = False)