Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.
Python cliconsumer-gpudpofine-tuningggufhuggingfacellmllmopslocal-ailocal-llmloralow-vrammachine-learningollamapeftpythonpytorchqlorasfttransformers
fix(eval): refuse zero-task gate suites (#1798) (#1821)
Tal58d249844a93
diff --git a/changelog.d/0.76.0/1821.fixed.md b/changelog.d/0.76.0/1821.fixed.mdnew file mode 100644index 00000000..4db87760--- /dev/null+++ b/changelog.d/0.76.0/1821.fixed.md@@ -0,0 +1 @@+- Refuse empty, missing, or misspelled eval-gate task lists before reporting a verdict; direct `run_gate` calls also reject a suite emptied after loading. Nonempty gate scores, thresholds, baselines, the no-model smoke generator, and unknown-key handling are unchanged (#1798 by @taljeon in #1821).diff --git a/docs/evaluation.md b/docs/evaluation.mdindex 86a80789..5fcb69a5 100644--- a/docs/evaluation.md+++ b/docs/evaluation.md@@ -258,6 +258,13 @@ tasks:`judge_model` accepts `ollama://<model>`, `http://localhost:<port>/<model>` or `https://<host>/<model>`. An `https://` judge URL uses `OPENAI_API_KEY` only when its host is `api.openai.com`; other hosts are called as an OpenAI-compatible server without that key. A judge URL whose host is a private, link-local or reserved IP literal is refused when the suite loads (loopback stays allowed): `soup eval gate` and `soup train --gate` stop with the error, and a suite named in `training.eval_gate` is skipped with a warning. Address an internal judge by its hostname. A host written only as numbers that is not a valid IPv4 address (`10.0.0.256`, `4294967296`) is refused the same way.+An eval gate must contain at least one task. Empty or missing `tasks` lists,+including a misspelled key that leaves the list empty, are refused with a+`ValueError` naming the suite and `tasks`; `soup eval gate` exits `3` before model+construction or a verdict. Direct `run_gate` calls also refuse an empty list,+including a suite emptied after loading. Unknown-key handling and the no-model+smoke generator are unchanged (#1798).+Baselines may be a registry reference (`registry://<name-or-id>`), a file path, or omitted for the first run. A registry baseline uses the newest eval row for each benchmark — re-measuring a benchmark replaces its baseline score — and warns, per benchmark, when that row's scorer stamp is missing or from a different scorer revision. A task whose evaluation raises (`ValueError`, `FileNotFoundError`, `OSError`, or a judge that stays unreachable) gets no score and fails the gate closed under `on_regression: stop`; the log line lists it as a task that could not be scored, with the error, rather than as a regression (#1447).diff --git a/src/soup_cli/eval/gate.py b/src/soup_cli/eval/gate.pyindex 8d875fc9..ec1056a5 100644--- a/src/soup_cli/eval/gate.py+++ b/src/soup_cli/eval/gate.py@@ -123,6 +123,13 @@ class EvalSuite(BaseModel):tasks: list[GateTask] = Field(default_factory=list)+def _require_gate_tasks(suite: EvalSuite) -> None:+ if not suite.tasks:+ raise ValueError(+ f"eval-gate suite {suite.suite!r} field 'tasks' must contain at least one task"+ )++def load_suite(path: str) -> EvalSuite:"""Load and validate an eval suite from disk."""suite_path = Path(path)@@ -133,7 +140,9 @@ def load_suite(path: str) -> EvalSuite:if not suite_path.exists():raise FileNotFoundError(f"eval-gate suite not found: {path}")data = yaml.safe_load(suite_path.read_text(encoding="utf-8")) or {}- return EvalSuite(**data)+ suite = EvalSuite(**data)+ _require_gate_tasks(suite)+ return suitedef current_baseline_stamp() -> dict[str, object]:@@ -607,6 +616,7 @@ def run_gate(raise ValueError(f"baseline score for {base_name!r} must be finite, got {base_val}")+ _require_gate_tasks(suite)task_results: list[GateTaskResult] = []any_regressed = Falseany_failed_threshold = Falsediff --git a/tests/test_eval_gate_empty_suite.py b/tests/test_eval_gate_empty_suite.pynew file mode 100644index 00000000..b61bd9fc--- /dev/null+++ b/tests/test_eval_gate_empty_suite.py@@ -0,0 +1,172 @@+"""An eval gate must measure a task before it can report a verdict."""++from __future__ import annotations++import json+from pathlib import Path+from typing import Callable++import pytest+import yaml+from rich.console import Console+from typer.testing import CliRunner++from soup_cli.cli import app+from soup_cli.commands import eval as eval_command+from soup_cli.eval import gate, quant_check++from .conftest import strip_ansi++EMPTY_SUITES = [+ {"suite": "empty", "tasks": []},+ {"suite": "empty"},+ {"suite": "empty", "task": [{"name": "misspelled"}]},+]+ERROR = "eval-gate suite 'empty' field 'tasks' must contain at least one task"+++def _write_suite(tmp_path: Path, payload: dict[str, object]) -> Path:+ path = tmp_path / "gate.yaml"+ path.write_text(yaml.safe_dump(payload), encoding="utf-8")+ return path+++def _nonempty_suite(tmp_path: Path, threshold: float) -> dict[str, object]:+ tasks = tmp_path / "tasks.jsonl"+ tasks.write_text(+ json.dumps({"prompt": "control", "expected": "gold"}) + "\n", encoding="utf-8",+ )+ return {+ "suite": "control",+ "tasks": [{+ "type": "custom", "name": "control", "tasks": str(tasks),+ "scorer": "exact", "threshold": threshold,+ }],+ }++[email protected]("payload", EMPTY_SUITES, ids=["explicit", "missing", "misspelled"])+def test_load_suite_refuses_zero_tasks(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, payload: dict[str, object],+) -> None:+ monkeypatch.chdir(tmp_path)+ path = _write_suite(tmp_path, payload)+ with pytest.raises(ValueError) as caught:+ gate.load_suite(str(path))+ assert str(caught.value) == ERROR++[email protected]("payload", EMPTY_SUITES, ids=["explicit", "missing", "misspelled"])[email protected]("with_model", [False, True], ids=["smoke", "model-factory"])+def test_cli_refuses_before_model_construction(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch,+ payload: dict[str, object], with_model: bool,+) -> None:+ monkeypatch.chdir(tmp_path)+ path = _write_suite(tmp_path, payload)+ factory_calls: list[str] = []++ def factory(model: str) -> Callable[[str], str]:+ factory_calls.append(model)+ return lambda prompt: ""++ monkeypatch.setattr(quant_check, "make_model_generator", factory)+ monkeypatch.setattr(eval_command, "console", Console(width=200))+ args = ["eval", "gate", "--suite", str(path)]+ if with_model:+ args.extend(["--model", "synthetic-model"])+ result = CliRunner().invoke(app, args)+ output = " ".join(strip_ansi(result.output).split())+ assert result.exit_code == 3+ assert f"Cannot load suite: {ERROR}" in output+ assert "GATE PASSED" not in output+ assert "GATE FAILED" not in output+ assert factory_calls == []++[email protected]("payload", EMPTY_SUITES, ids=["explicit", "missing", "misspelled"])+def test_direct_run_gate_refuses_zero_tasks(payload: dict[str, object]) -> None:+ suite = gate.EvalSuite.model_validate(payload)+ calls: list[str] = []+ with pytest.raises(ValueError) as caught:+ gate.run_gate(suite, generate_fn=lambda prompt: calls.append(prompt) or "")+ assert str(caught.value) == ERROR+ assert calls == []+++def test_suite_emptied_after_loading_cannot_pass(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch,+) -> None:+ monkeypatch.chdir(tmp_path)+ payload = _nonempty_suite(tmp_path, 0.0)+ payload["suite"] = "empty"+ suite = gate.load_suite(str(_write_suite(tmp_path, payload)))+ suite.tasks.clear()+ with pytest.raises(ValueError) as caught:+ gate.run_gate(suite, generate_fn=lambda prompt: "")+ assert str(caught.value) == ERROR++[email protected]("threshold, baseline, passed, regressed", [+ (0.0, {}, True, False),+ (1.0, {}, False, False),+ (0.0, {"control": 1.0}, False, True),+])+def test_nonempty_api_preserves_score_threshold_and_baseline(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch,+ threshold: float, baseline: dict[str, float], passed: bool, regressed: bool,+) -> None:+ monkeypatch.chdir(tmp_path)+ suite = gate.load_suite(str(_write_suite(tmp_path, _nonempty_suite(tmp_path, threshold))))+ calls: list[str] = []+ result = gate.run_gate(+ suite, generate_fn=lambda prompt: calls.append(prompt) or "", baseline=baseline,+ )+ assert result.passed is passed+ assert result.regression is regressed+ assert len(result.task_results) == 1+ assert result.task_results[0].score == 0.0+ assert result.task_results[0].baseline == baseline.get("control")+ assert calls == ["control"]++[email protected]("with_model", [False, True], ids=["smoke", "model-factory"])[email protected]("threshold, baseline, exit_code", [+ (0.0, {}, 0), (1.0, {}, 2), (0.0, {"control": 1.0}, 2),+])+def test_nonempty_cli_preserves_smoke_and_model_factory_verdicts(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch,+ threshold: float, baseline: dict[str, float], exit_code: int, with_model: bool,+) -> None:+ monkeypatch.chdir(tmp_path)+ path = _write_suite(tmp_path, _nonempty_suite(tmp_path, threshold))+ baseline_path = tmp_path / "baseline.json"+ baseline_path.write_text(json.dumps(baseline), encoding="utf-8")+ calls: list[str] = []+ monkeypatch.setattr(+ quant_check, "make_model_generator",+ lambda model: lambda prompt: calls.append(prompt) or "",+ )+ monkeypatch.setattr(eval_command, "console", Console(width=200))+ args = ["eval", "gate", "--suite", str(path), "--baseline", str(baseline_path)]+ if with_model:+ args.extend(["--model", "synthetic-model"])+ result = CliRunner().invoke(app, args)+ output = strip_ansi(result.output)+ assert result.exit_code == exit_code+ assert ("GATE PASSED" in output) is (exit_code == 0)+ assert ("GATE FAILED" in output) is (exit_code == 2)+ assert calls == (["control"] if with_model else [])+++def test_empty_model_construction_is_not_a_gate_verdict() -> None:+ assert gate.EvalSuite(suite="fixture", tasks=[]).tasks == []+++def test_nonempty_suite_still_ignores_unknown_keys(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch,+) -> None:+ monkeypatch.chdir(tmp_path)+ payload = _nonempty_suite(tmp_path, 0.0)+ payload["future_key"] = True+ assert len(gate.load_suite(str(_write_suite(tmp_path, payload))).tasks) == 1diff --git a/tests/test_issue404_baseline_scorer_stamp.py b/tests/test_issue404_baseline_scorer_stamp.pyindex c74fea09..855ae199 100644--- a/tests/test_issue404_baseline_scorer_stamp.py+++ b/tests/test_issue404_baseline_scorer_stamp.py@@ -307,10 +307,14 @@ class TestWriteBaselineCli:self, tmp_path, monkeypatch):monkeypatch.chdir(tmp_path)- self._write_suite(tmp_path, tasks=[]) # no scored tasks+ self._write_suite(tmp_path)++ def unavailable(_prompt: str) -> str:+ raise ValueError("synthetic inference failure")+monkeypatch.setattr("soup_cli.eval.quant_check.make_model_generator",- lambda _model: (lambda _prompt: ""),+ lambda _model: unavailable,)result = runner.invoke(app,