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): preserve missing benchmark evidence (#1722)
Tal3f2b9a17fc75
diff --git a/changelog.d/0.75.1/1722.fixed.md b/changelog.d/0.75.1/1722.fixed.mdnew file mode 100644index 00000000..0f327130--- /dev/null+++ b/changelog.d/0.75.1/1722.fixed.md@@ -0,0 +1,5 @@+- **`soup eval benchmark`: do not store an unmeasured result as zero.**+ Missing or scoreless requested results are skipped, named and counted; a genuine+ numeric zero is retained and booleans are not scores. The saved banner counts+ persisted results, and an all-skipped invocation exits 1. Groups require their+ own numeric entry; sub-task rows are not saved implicitly. (#1718 by @taljeon in #1722)diff --git a/docs/evaluation.md b/docs/evaluation.mdindex 6cd2737c..c24d6f5e 100644--- a/docs/evaluation.md+++ b/docs/evaluation.md@@ -749,6 +749,12 @@ soup eval leaderboard --format csvsoup eval human --input prompts.jsonl --model-a ./model_a --model-b ./model_b```+`soup eval benchmark` saves only requested names with numeric metrics, including a real+`0.0` (not a boolean). Missing or scoreless results are skipped, named and counted;+the saved banner reports the saved count. It exits `0` when at least one result was+saved, or `1` when nothing was measured or saved. A requested group needs its own+numeric entry in `results`; this command does not save its sub-task rows automatically.+`soup eval judge` asks the judge for one JSON object, `{"scores": {"<criterion>": <number>, ...}, "reasoning": "..."}`, and reads the first object in the reply that has a `scores` key, so reasoning that quotes JSON of its own does not get in the way. Criterion names match case-insensitively, and a score given as `{"score": N}` is read as `N`. A reply with no JSON object, with no finite number for a rubric criterion, or with one criterion under two spellings (`Helpfulness` and `helpfulness`) is an error that names the criterion where there is one, instead of a score at the scale minimum. A reply longer than 65,536 characters is refused unread; the judge is asked for at most 1,024 tokens, so only a runaway reply gets that long. `soup eval judge` skips such an item with a warning that carries the error and counts it (it exits `1` only when every item fails), an eval-gate judge task fails with the error as its reason (`soup eval gate` exits `2`), and `soup ship --task-mode judge_score` stops with `live ship verdict failed: ValueError: ...` and exits `1` without a verdict.soup eval compare and soup eval leaderboard use the newest eval row for each benchmark (on the leaderboard, for each model and benchmark), so re-running a benchmark replaces its score; rows with the same created_at resolve to the later insert. soup registry diff compares eval scores the same way.diff --git a/src/soup_cli/commands/eval.py b/src/soup_cli/commands/eval.pyindex 34879f78..28e93055 100644--- a/src/soup_cli/commands/eval.py+++ b/src/soup_cli/commands/eval.py@@ -123,7 +123,7 @@ def benchmark(model_arg = f"{model_arg},trust_remote_code=True"benchmark_list = [b.strip() for b in benchmarks.split(",")]- console.print(f"[dim]Evaluating on: {', '.join(benchmark_list)}[/]")+ console.print(f"[dim]Evaluating on: {', '.join(for_terminal(b) for b in benchmark_list)}[/]")# Lazy import lm_evaltry:@@ -150,8 +150,13 @@ def benchmark()_display_benchmark_results(results, benchmark_list)- _save_benchmark_results(results, str(model_path), benchmark_list, run_id)- console.print("\n[green]Results saved to experiment tracker.[/]")+ saved = _save_benchmark_results(results, str(model_path), benchmark_list, run_id)+ if not saved:+ console.print("[red]Nothing measured; nothing saved to experiment tracker.[/]")+ raise typer.Exit(1)+ console.print(+ f"\n[green]Results saved to experiment tracker: {saved} of {len(benchmark_list)}.[/]"+ )# ─── soup eval aider ───@@ -1029,6 +1034,17 @@ def _run_lm_eval(return results+def _benchmark_metric(bench_data: dict) -> Optional[tuple[str, int | float]]:+ """Use the same measured-score selection for the table and tracker."""+ preferred = ["acc,none", "acc_norm,none", "exact_match,none", "em,none"]+ for key in [*preferred, *(key for key in bench_data if key not in preferred)]:+ value = bench_data.get(key)+ if (isinstance(value, (int, float)) and not isinstance(value, bool)+ and not key.startswith("alias")):+ return key.split(",")[0], value+ return None++def _display_benchmark_results(results: dict, benchmarks: list[str]) -> None:"""Display benchmark results as a rich table."""table = Table(title="Evaluation Results")@@ -1039,26 +1055,15 @@ def _display_benchmark_results(results: dict, benchmarks: list[str]) -> None:task_results = results.get("results", {})for bench in benchmarks:bench_data = task_results.get(bench, {})- if not bench_data:- table.add_row(bench, "-", "[red]not found[/]")+ if bench not in task_results:+ table.add_row(for_terminal(bench), "-", "[red]not found[/]")continue-- for metric_key in [- "acc,none", "acc_norm,none", "exact_match,none", "em,none",- ]:- if metric_key in bench_data:- metric_name = metric_key.split(",")[0]- score = bench_data[metric_key]- table.add_row(bench, metric_name, f"{score:.4f}")- break+ metric = _benchmark_metric(bench_data)+ if metric is not None:+ metric_name, score = metric+ table.add_row(for_terminal(bench), for_terminal(metric_name), f"{score:.4f}")else:- for key, val in bench_data.items():- if isinstance(val, (int, float)) and not key.startswith("alias"):- metric_name = key.split(",")[0] if "," in key else key- table.add_row(bench, metric_name, f"{val:.4f}")- break- else:- table.add_row(bench, "-", "[yellow]no numeric result[/]")+ table.add_row(for_terminal(bench), "-", "[yellow]no numeric result[/]")console.print(table)@@ -1068,35 +1073,36 @@ def _save_benchmark_results(model_path: str,benchmarks: list[str],run_id: Optional[str],-) -> None:- """Save benchmark results to the experiment tracker."""+) -> int:+ """Save measured requested results, reporting skipped names and returning the count."""from soup_cli.experiment.tracker import ExperimentTrackertracker = ExperimentTracker()task_results = results.get("results", {})-- for bench in benchmarks:- bench_data = task_results.get(bench, {})- score = 0.0- for metric_key in [- "acc,none", "acc_norm,none", "exact_match,none", "em,none",- ]:- if metric_key in bench_data:- score = bench_data[metric_key]- break- else:- for val in bench_data.values():- if isinstance(val, (int, float)):- score = val- break-- tracker.save_eval_result(- model_path=model_path,- benchmark=bench,- score=score,- details=bench_data,- run_id=run_id,- )+ saved = 0+ try:+ for bench in benchmarks:+ bench_data = task_results.get(bench, {})+ metric = _benchmark_metric(bench_data)+ if metric is None:+ reason = "not found" if bench not in task_results else "no numeric result"+ console.print(f"[yellow]Skipped {for_terminal(bench)}: {reason}[/]")+ continue+ _, score = metric+ tracker.save_eval_result(+ model_path=model_path,+ benchmark=bench,+ score=score,+ details=bench_data,+ run_id=run_id,+ )+ saved += 1+ finally:+ tracker.close()+ skipped = len(benchmarks) - saved+ if skipped:+ console.print(f"[yellow]Skipped {skipped} of {len(benchmarks)} requested benchmarks.[/]")+ return saveddef _display_custom_results(eval_results: object) -> None:diff --git a/tests/test_issue1449_trust_remote_code_dropped.py b/tests/test_issue1449_trust_remote_code_dropped.pyindex a851cf26..c8b7d17d 100644--- a/tests/test_issue1449_trust_remote_code_dropped.py+++ b/tests/test_issue1449_trust_remote_code_dropped.py@@ -157,7 +157,7 @@ class TestEvalAutoTrust:eval_cmd, "_run_lm_eval",lambda model_arg, *a, **k: seen_model_args.append(model_arg) or {"results": {}},)- monkeypatch.setattr(eval_cmd, "_save_benchmark_results", lambda *a, **k: None)+ monkeypatch.setattr(eval_cmd, "_save_benchmark_results", lambda *a, **k: 1)monkeypatch.setattr(eval_cmd, "_save_custom_results", lambda *a, **k: None)monkeypatch.setattr(custom, "_create_default_generator",diff --git a/tests/test_issue1718_benchmark_evidence.py b/tests/test_issue1718_benchmark_evidence.pynew file mode 100644index 00000000..e3ceeb90--- /dev/null+++ b/tests/test_issue1718_benchmark_evidence.py@@ -0,0 +1,130 @@+"""Unmeasured benchmark results must not become measured zeroes (#1718)."""++import sys+import types+from unittest.mock import MagicMock++import pytest+from rich.console import Console+from typer.testing import CliRunner++from soup_cli.commands import eval as eval_command+from soup_cli.experiment.tracker import ExperimentTracker+from tests.conftest import strip_ansi+++ ("data", "expected"),+ [+ (None, None),+ ({"alias": "scoreless"}, None),+ ({"acc,none": 0.0}, 0.0),+ ({"acc,none": 0.0, "acc_norm,none": 0.9}, 0.0),+ ({"acc,none": 0.75}, 0.75),+ ({"other": 0.25}, 0.25),+ ({"other": 0.25, "acc,none": 0.5}, 0.5),+ ({"other": True}, None),+ ({"acc,none": False}, None),+ ({"acc,none": "unavailable", "other": 0.25}, 0.25),+ ({"alias": 123}, None),+ ({}, None),+ ],+)+def test_helper_saves_only_measured_scores(monkeypatch, data, expected):+ tracker = MagicMock()+ monkeypatch.setattr("soup_cli.experiment.tracker.ExperimentTracker", lambda: tracker)+ payload = {"results": {} if data is None else {"requested": data}}++ count = eval_command._save_benchmark_results(payload, "model", ["requested"], "run")++ assert count == (expected is not None)+ if expected is None:+ tracker.save_eval_result.assert_not_called()+ else:+ tracker.save_eval_result.assert_called_once_with(+ model_path="model", benchmark="requested", score=expected, details=data, run_id="run",+ )+++def benchmark_cli(tmp_path, monkeypatch):+ monkeypatch.chdir(tmp_path)+ monkeypatch.setenv("SOUP_DB_PATH", str(tmp_path / "synthetic.sqlite3"))+ (tmp_path / "model").mkdir()+ monkeypatch.setattr(eval_command, "console", Console(width=200))++ def invoke(payload, names):+ lm_eval = types.ModuleType("lm_eval")+ lm_eval.simple_evaluate = lambda **kwargs: payload+ monkeypatch.setitem(sys.modules, "lm_eval", lm_eval)+ result = CliRunner().invoke(+ eval_command.app,+ ["benchmark", "--model", "model", "--benchmarks", names, "--device", "cpu"],+ )+ tracker = ExperimentTracker()+ try:+ rows = tracker.get_eval_results()+ finally:+ tracker.close()+ return result, strip_ansi(result.output), rows++ return invoke+++ ("data", "reason"),+ [(None, "not found"), ({"alias": "scoreless"}, "no numeric result"),+ ({"other": True}, "no numeric result"), ({"acc,none": False}, "no numeric result")],+)+def test_cli_nothing_measured_is_failure(benchmark_cli, data, reason):+ payload = {"results": {} if data is None else {"requested": data}}+ result, output, rows = benchmark_cli(payload, "requested")++ assert result.exit_code == 1, output+ assert rows == []+ assert f"Skipped requested: {reason}" in output+ assert "Nothing measured; nothing saved" in output+ assert "Results saved to experiment tracker" not in output+ assert "1.0000" not in output and "0.0000" not in output++[email protected]("score", [0.0, 0.75])+def test_cli_real_scores_are_saved(benchmark_cli, score):+ result, output, rows = benchmark_cli({"results": {"requested": {"acc,none": score}}},+ "requested")++ assert result.exit_code == 0, output+ assert [(row["benchmark"], row["score"]) for row in rows] == [("requested", score)]+ assert "Results saved to experiment tracker: 1 of 1" in output+++def test_cli_partial_results_name_count_and_skip_group(benchmark_cli):+ payload = {"results": {"zero": {"acc,none": 0.0}, "value": {"acc,none": 0.75},+ "group": {"alias": "group"}, "subtask": {"acc,none": 1.0}},+ "groups": {"group": {"acc,none": 1.0}}}+ result, output, rows = benchmark_cli(payload, "zero,missing,value,group")++ assert result.exit_code == 0, output+ assert {row["benchmark"]: row["score"] for row in rows} == {"zero": 0.0, "value": 0.75}+ assert "Skipped missing: not found" in output+ assert "Skipped group: no numeric result" in output+ assert "Skipped 2 of 4" in output+ assert "Results saved to experiment tracker: 2 of 4" in output+++def test_cli_group_own_numeric_entry_is_measured(benchmark_cli):+ result, output, rows = benchmark_cli(+ {"results": {"group": {"acc,none": 0.5}, "subtask": {"acc,none": 1.0}}}, "group",+ )+ assert result.exit_code == 0, output+ assert [(row["benchmark"], row["score"]) for row in rows] == [("group", 0.5)]+++def test_cli_skipped_name_is_terminal_safe(benchmark_cli):+ name = "[red]missing[/red]\x1b\x9b"+ result, output, rows = benchmark_cli({"results": {}}, name)++ assert result.exit_code == 1, output+ assert rows == []+ assert "Skipped [red]missing[/red]: not found" in output+ assert "\x1b" not in output and "\x9b" not in output