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): reject oversized integer baseline scores (#1903)
dipesh-singh074a6bab3cac3d
diff --git a/changelog.d/0.76.0/1865.fixed.md b/changelog.d/0.76.0/1865.fixed.mdnew file mode 100644index 00000000..ee762479--- /dev/null+++ b/changelog.d/0.76.0/1865.fixed.md@@ -0,0 +1 @@+- Oversized integer baseline scores now raise `ValueError` instead of leaking `OverflowError` (#1865 by @dipesh-singh07 in #1903)diff --git a/src/soup_cli/eval/gate.py b/src/soup_cli/eval/gate.pyindex b6f0d57f..38c118f2 100644--- a/src/soup_cli/eval/gate.py+++ b/src/soup_cli/eval/gate.py@@ -164,6 +164,21 @@ def current_baseline_stamp() -> dict[str, object]:}+def _finite_score(value: object, *, name: str, context: str) -> float:+ """Convert and validate that a score is a finite float (#1865)."""+ try:+ fval = float(value) # type: ignore[arg-type]+ except OverflowError as exc:+ raise ValueError(+ f"{context}: score for {name!r} is out of range (must be finite)"+ ) from exc+ if not math.isfinite(fval):+ raise ValueError(+ f"{context}: score for {name!r} must be finite"+ )+ return fval++def stamp_baseline_scores(scores: Mapping[str, float]) -> dict[str, object]:"""Build the stamped baseline envelope (shared writer helper, #404).@@ -183,12 +198,7 @@ def stamp_baseline_scores(scores: Mapping[str, float]) -> dict[str, object]:f"baseline score for {name!r} must be a number, "f"got {type(value).__name__}")- fval = float(value)- if not math.isfinite(fval):- raise ValueError(- f"baseline score for {name!r} must be finite, got {value}"- )- clean[name] = fval+ clean[name] = _finite_score(value, name=name, context="baseline score")return {_BASELINE_SCORES_KEY: clean,_BASELINE_PROVENANCE_KEY: current_baseline_stamp(),@@ -228,12 +238,7 @@ def _coerce_score_map(raw: Mapping[object, object], *, context: str) -> dict[strf"{context}: score for {name!r} must be a number, "f"got {type(value).__name__}")- fval = float(value)- if not math.isfinite(fval):- raise ValueError(- f"{context}: score for {name!r} must be finite, got {value}"- )- out[name] = fval+ out[name] = _finite_score(value, name=name, context=context)return out@@ -621,10 +626,11 @@ def run_gate(f"baseline score for {base_name!r} must be a number, "f"got {type(base_val).__name__}")- if not math.isfinite(base_val):- raise ValueError(- f"baseline score for {base_name!r} must be finite, got {base_val}"- )+ _finite_score(+ base_val,+ name=str(base_name),+ context="baseline score",+ )_require_gate_tasks(suite)task_results: list[GateTaskResult] = []any_regressed = Falsediff --git a/tests/test_issue1773_finite_baseline.py b/tests/test_issue1773_finite_baseline.pyindex 3cfe5c2c..125b7145 100644--- a/tests/test_issue1773_finite_baseline.py+++ b/tests/test_issue1773_finite_baseline.py@@ -74,6 +74,24 @@ class TestWriterHelperRefusal:write_baseline_file(str(target), {"control": bad_val})assert not target.exists()+ @pytest.mark.parametrize("bad_val", [10**400, -(10**400)])+ def test_stamp_baseline_scores_rejects_oversized_integer(self, bad_val):+ with pytest.raises(ValueError, match="control") as exc_info:+ stamp_baseline_scores({"control": bad_val})+ msg = str(exc_info.value).lower()+ assert "finite" in msg or "out of range" in msg++ @pytest.mark.parametrize("bad_val", [10**400, -(10**400)])+ def test_write_baseline_file_rejects_oversized_integer_and_creates_no_file(+ self, tmp_path, bad_val+ ):+ target = tmp_path / "out.json"+ with pytest.raises(ValueError, match="control") as exc_info:+ write_baseline_file(str(target), {"control": bad_val})+ msg = str(exc_info.value).lower()+ assert "finite" in msg or "out of range" in msg+ assert not target.exists()+class TestReaderRefusal:"""resolve_baseline must reject non-finite scores in files and registry."""@@ -102,6 +120,34 @@ class TestReaderRefusal:resolve_baseline(str(base_file.name))assert "finite" in str(exc_info.value).lower()+ @pytest.mark.parametrize("raw_num", [str(10**400), str(-(10**400))])+ def test_resolve_baseline_legacy_file_rejects_oversized_integer(+ self, tmp_path, monkeypatch, raw_num+ ):+ monkeypatch.chdir(tmp_path)+ base_file = tmp_path / "baseline.json"+ base_file.write_text(f'{{"control": {raw_num}}}', encoding="utf-8")+ with pytest.raises(ValueError, match="control") as exc_info:+ resolve_baseline(str(base_file.name))+ msg = str(exc_info.value).lower()+ assert "finite" in msg or "out of range" in msg++ @pytest.mark.parametrize("raw_num", [str(10**400), str(-(10**400))])+ def test_resolve_baseline_stamped_envelope_rejects_oversized_integer(+ self, tmp_path, monkeypatch, raw_num+ ):+ monkeypatch.chdir(tmp_path)+ base_file = tmp_path / "baseline_stamped.json"+ base_file.write_text(+ f'{{"scores": {{"control": {raw_num}}}, '+ f'"provenance": {{"soup_version": "x", "scorer_revision": 1}}}}',+ encoding="utf-8",+ )+ with pytest.raises(ValueError, match="control") as exc_info:+ resolve_baseline(str(base_file.name))+ msg = str(exc_info.value).lower()+ assert "finite" in msg or "out of range" in msg+@pytest.mark.parametrize("bad_score", [float("-inf"), float("inf")])def test_resolve_baseline_registry_rejects_infinite_db_rows(self, tmp_path, monkeypatch, bad_score@@ -181,6 +227,25 @@ class TestGateExecutionRefusal:run_gate(suite, generate_fn=lambda p: "", baseline={"control": bad_val})assert "finite" in str(exc_info.value).lower()+ @pytest.mark.parametrize("bad_val", [10**400, -(10**400)])+ def test_run_gate_rejects_oversized_integer_baseline(self, tmp_path, bad_val):+ suite = EvalSuite(+ suite="probe",+ tasks=[+ GateTask(+ type="custom",+ name="control",+ threshold=0.0,+ tasks=str(tmp_path / "dummy.jsonl"),+ scorer="exact",+ )+ ],+ )+ with pytest.raises(ValueError, match="control") as exc_info:+ run_gate(suite, generate_fn=lambda p: "", baseline={"control": bad_val})+ msg = str(exc_info.value).lower()+ assert "finite" in msg or "out of range" in msg+def test_run_gate_rejects_non_mapping_baseline(self):suite = EvalSuite(suite="probe", tasks=[])with pytest.raises(TypeError, match="mapping"):@@ -334,6 +399,48 @@ class TestCliNonSuccess:assert "finite" in output.lower()assert "control" in output+ @pytest.mark.parametrize("raw_num", [str(10**400), str(-(10**400))])+ def test_cli_refuses_oversized_integer(self, tmp_path, monkeypatch, raw_num):+ monkeypatch.chdir(tmp_path)+ suite_file, _ = _make_suite_and_tasks(tmp_path)+ base_file = tmp_path / "baseline.json"+ base_file.write_text(f'{{"control": {raw_num}}}', encoding="utf-8")++ result = runner.invoke(+ app,+ ["eval", "gate", "--suite", str(suite_file.name), "--baseline", str(base_file.name)],+ )+ assert result.exit_code == EXIT_USAGE_ERROR+ output = strip_ansi(result.output)+ assert "GATE PASSED" not in output+ assert "control" in output+ assert "finite" in output.lower() or "out of range" in output.lower()++ @pytest.mark.parametrize("raw_num", [str(10**400), str(-(10**400))])+ def test_ship_cli_refuses_oversized_integer_baseline(self, tmp_path, monkeypatch, raw_num):+ monkeypatch.chdir(tmp_path)+ base_file = tmp_path / "b.json"+ base_file.write_text(f'{{"control": {raw_num}}}', encoding="utf-8")+ tasks = tmp_path / "tasks.jsonl"+ tasks.write_text(+ '{"prompt": "x", "expected": "y", "scoring": "exact"}\n', encoding="utf-8"+ )++ result = runner.invoke(+ app,+ [+ "ship",+ "--base", "m",+ "--tuned", "m",+ "--task-eval", str(tasks.name),+ "--baseline", str(base_file.name),+ ],+ )+ assert result.exit_code == EXIT_USAGE_ERROR+ output = strip_ansi(result.output)+ assert "control" in output+ assert "finite" in output.lower() or "out of range" in output.lower()+class TestHealthyControlsPreserved:"""Healthy finite controls must behave exactly as before."""