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): use newest evaluation scores consistently (#1291)
Krishna2efb6c49bcd5
diff --git a/changelog.d/0.75.1/1291.fixed.md b/changelog.d/0.75.1/1291.fixed.mdnew file mode 100644index 00000000..21b58511--- /dev/null+++ b/changelog.d/0.75.1/1291.fixed.md@@ -0,0 +1,2 @@+- **`soup registry diff`, `soup eval compare` and `soup eval leaderboard` now use the newest eval row per benchmark instead of the oldest (#1270 by @Ru0k3 in #1291).**+ Each built its score map by overwriting in the order the experiment tracker returns rows, which is newest first, so the oldest score won and a re-measurement was ignored: with run A logging 0.30 and then 0.45, and run B logging 0.50 and then 0.40, `soup registry diff` and `soup eval compare` reported +0.20 and no regression instead of the -0.05 regression. All three commands and the eval gate's `registry://` baseline now pick rows through one helper, `soup_cli.eval.results.newest_eval_rows` (newest `created_at` first, then insertion order for equal timestamps); the leaderboard keeps the newest row for each model and benchmark.diff --git a/docs/evaluation.md b/docs/evaluation.mdindex adaac4ca..2c91d810 100644--- a/docs/evaluation.md+++ b/docs/evaluation.md@@ -700,6 +700,8 @@ soup eval leaderboard --format csvsoup eval human --input prompts.jsonl --model-a ./model_a --model-b ./model_b```+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.+### Aider PolyglotThe `aider-chat` wheel does not include Aider's benchmark harness. Thediff --git a/src/soup_cli/eval/gate.py b/src/soup_cli/eval/gate.pyindex 79b3bb61..020dafe0 100644--- a/src/soup_cli/eval/gate.py+++ b/src/soup_cli/eval/gate.py@@ -18,6 +18,7 @@ import yamlfrom pydantic import BaseModel, Field, field_validatorfrom soup_cli import __version__+from soup_cli.eval.results import newest_eval_rowsfrom soup_cli.utils.paths import atomic_write_text, is_under_cwdlogger = logging.getLogger(__name__)@@ -282,23 +283,6 @@ def _row_provenance(row: Mapping[str, object]) -> Optional[dict[str, object]]:return None-def _newest_row_per_benchmark(rows: list[dict]) -> dict[str, dict]:- """Keep the newest scored row for each benchmark.-- ``rows`` arrive newest first (``created_at DESC, rowid DESC``), so the- first row seen for a benchmark is the one that counts. Score and- provenance must both come from that row: a re-measurement replaces the- stale score instead of only silencing its warning (#1224).- """- newest: dict[str, dict] = {}- for row in rows:- name = row.get("benchmark")- if not name or row.get("score") is None or name in newest:- continue- newest[name] = row- return newest--def resolve_baseline(spec: Optional[str],*,@@ -335,7 +319,10 @@ def resolve_baseline(f"registry baseline not found: {ref} (use `soup registry list`)")rows = store.get_eval_results(entry_id)- newest = _newest_row_per_benchmark(rows)+ newest = {+ row["benchmark"]: row+ for row in newest_eval_rows(rows)+ }scores = {name: float(row["score"]) for name, row in newest.items()}# Registry rows predate the stamp (or carry it inside details_json).# Checked per benchmark: re-measuring one benchmark says nothing aboutdiff --git a/src/soup_cli/eval/leaderboard.py b/src/soup_cli/eval/leaderboard.pyindex 2be7c390..b60bd1d4 100644--- a/src/soup_cli/eval/leaderboard.py+++ b/src/soup_cli/eval/leaderboard.py@@ -6,6 +6,8 @@ import jsonfrom dataclasses import dataclass, fieldfrom typing import Optional+from soup_cli.eval.results import newest_eval_rows+@dataclassclass LeaderboardEntry:@@ -64,7 +66,9 @@ def build_leaderboard_from_tracker(eval_results = tracker.get_eval_results(run_id=run_id)entries = []- for row in eval_results:+ for row in newest_eval_rows(+ eval_results, key_fields=("model_path", "benchmark")+ ):entries.append(LeaderboardEntry(model_path=row.get("model_path", ""),benchmark=row.get("benchmark", ""),@@ -91,11 +95,11 @@ def compare_runs(results_2 = tracker.get_eval_results(run_id=run_id_2)scores_1: dict[str, float] = {}- for row in results_1:+ for row in newest_eval_rows(results_1):scores_1[row["benchmark"]] = row["score"]scores_2: dict[str, float] = {}- for row in results_2:+ for row in newest_eval_rows(results_2):scores_2[row["benchmark"]] = row["score"]all_benchmarks = sorted(set(scores_1.keys()) | set(scores_2.keys()))diff --git a/src/soup_cli/eval/results.py b/src/soup_cli/eval/results.pynew file mode 100644index 00000000..b40c7fd3--- /dev/null+++ b/src/soup_cli/eval/results.py@@ -0,0 +1,43 @@+"""Helpers for selecting the latest rows from evaluation results."""++from __future__ import annotations++from collections.abc import Iterable, Mapping, Sequence+from typing import Any+++def _row_order(row: Mapping[str, Any]) -> tuple[str, int]:+ """Return the database ordering used to identify the newest row."""+ created_at = row.get("created_at")+ stamp = "" if created_at is None else str(created_at)+ raw_id = row.get("rowid", row.get("id", -1))+ try:+ insertion_id = int(raw_id)+ except (TypeError, ValueError):+ insertion_id = -1+ return stamp, insertion_id+++def newest_eval_rows(+ rows: Iterable[Mapping[str, Any]],+ *,+ key_fields: Sequence[str] = ("benchmark",),+) -> list[dict[str, Any]]:+ """Keep the newest scored row for each evaluation key.++ Rows are ordered by ``created_at DESC, rowid DESC``. SQLite exposes the+ ``INTEGER PRIMARY KEY`` column as both ``id`` and ``rowid``; accepting both+ names keeps this helper usable with database rows and small test doubles.+ Rows with missing or empty key fields are ignored, matching the eval gate's+ previous ``if not name`` behavior.+ """+ newest: dict[tuple[Any, ...], dict[str, Any]] = {}+ ordered = sorted(rows, key=_row_order, reverse=True)+ for row in ordered:+ if row.get("score") is None:+ continue+ key = tuple(row.get(field) for field in key_fields)+ if any(value is None or value == "" for value in key) or key in newest:+ continue+ newest[key] = dict(row)+ return list(newest.values())diff --git a/src/soup_cli/registry/diff.py b/src/soup_cli/registry/diff.pyindex 89f0f33a..81b2298b 100644--- a/src/soup_cli/registry/diff.py+++ b/src/soup_cli/registry/diff.py@@ -5,6 +5,8 @@ from __future__ import annotationsfrom dataclasses import dataclassfrom typing import Any+from soup_cli.eval.results import newest_eval_rows+@dataclass(frozen=True)class ConfigChange:@@ -57,8 +59,14 @@ def eval_delta(left: list[dict], right: list[dict],) -> list[dict]:"""Compute per-benchmark delta given two eval_results lists."""- left_map = {row.get("benchmark"): row.get("score") for row in left}- right_map = {row.get("benchmark"): row.get("score") for row in right}+ left_map = {+ row["benchmark"]: row.get("score")+ for row in newest_eval_rows(left)+ }+ right_map = {+ row["benchmark"]: row.get("score")+ for row in newest_eval_rows(right)+ }deltas: list[dict] = []for bench in sorted(set(left_map) | set(right_map)):diff --git a/tests/test_issue1270_newest_eval_rows.py b/tests/test_issue1270_newest_eval_rows.pynew file mode 100644index 00000000..846dcb1c--- /dev/null+++ b/tests/test_issue1270_newest_eval_rows.py@@ -0,0 +1,108 @@+"""#1270 — eval comparisons must use the newest row per benchmark."""++from __future__ import annotations++from unittest.mock import MagicMock++import pytest++from soup_cli.eval.leaderboard import build_leaderboard_from_tracker, compare_runs+from soup_cli.eval.results import newest_eval_rows+from soup_cli.registry.diff import eval_delta+++def _row(benchmark: str, score: float, created_at: str, rowid: int) -> dict:+ return {+ "benchmark": benchmark,+ "score": score,+ "created_at": created_at,+ "id": rowid,+ "model_path": "model",+ }+++def test_newest_eval_rows_breaks_equal_timestamps_by_insertion_order():+ rows = [+ _row("mmlu", 0.30, "2026-01-01T00:00:00", 1),+ _row("mmlu", 0.45, "2026-01-01T00:00:00", 2),+ ]++ assert [row["score"] for row in newest_eval_rows(rows)] == [0.45]+++def test_registry_diff_uses_newest_rows_on_both_sides():+ left = [+ _row("mmlu", 0.45, "2026-01-02T00:00:00", 2),+ _row("mmlu", 0.30, "2026-01-01T00:00:00", 1),+ ]+ right = [+ _row("mmlu", 0.40, "2026-01-02T00:00:00", 4),+ _row("mmlu", 0.50, "2026-01-01T00:00:00", 3),+ ]++ result = eval_delta(left, right)++ assert result == [{+ "benchmark": "mmlu",+ "left": 0.45,+ "right": 0.40,+ "delta": pytest.approx(-0.05),+ }]+++def test_eval_compare_uses_newest_rows_on_both_sides():+ tracker = MagicMock()+ tracker.get_eval_results.side_effect = [+ [+ _row("mmlu", 0.45, "2026-01-02T00:00:00", 2),+ _row("mmlu", 0.30, "2026-01-01T00:00:00", 1),+ ],+ [+ _row("mmlu", 0.40, "2026-01-02T00:00:00", 4),+ _row("mmlu", 0.50, "2026-01-01T00:00:00", 3),+ ],+ ]++ result = compare_runs(tracker, "run-a", "run-b")++ assert result["comparisons"] == [{+ "benchmark": "mmlu",+ "run_1_score": 0.45,+ "run_2_score": 0.40,+ "delta": pytest.approx(-0.05),+ }]+ assert result["regressions"] == ["mmlu"]+++def test_leaderboard_uses_newest_row_per_model_and_benchmark():+ tracker = MagicMock()+ tracker.get_eval_results.return_value = [+ _row("mmlu", 0.45, "2026-01-02T00:00:00", 2),+ _row("mmlu", 0.30, "2026-01-01T00:00:00", 1),+ ]++ leaderboard = build_leaderboard_from_tracker(tracker)++ assert leaderboard.models == {"model": {"mmlu": 0.45}}+++def test_leaderboard_keeps_the_newest_row_for_every_model():+ tracker = MagicMock()+ tracker.get_eval_results.return_value = [+ {**_row("mmlu", 0.45, "2026-01-02T00:00:00", 3), "model_path": "model-a"},+ {**_row("mmlu", 0.40, "2026-01-02T00:00:00", 2), "model_path": "model-b"},+ {**_row("mmlu", 0.30, "2026-01-01T00:00:00", 1), "model_path": "model-a"},+ ]++ leaderboard = build_leaderboard_from_tracker(tracker)++ assert leaderboard.models == {+ "model-a": {"mmlu": 0.45},+ "model-b": {"mmlu": 0.40},+ }+++def test_newest_eval_rows_skips_empty_benchmark_names():+ rows = [_row("", 0.5, "2026-01-01T00:00:00", 1)]++ assert newest_eval_rows(rows) == []