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 spreadsheet-facing CSV labels (#1950)
Alpamys Makazhanf157be10e7d2
diff --git a/changelog.d/0.76.0/1950.fixed.md b/changelog.d/0.76.0/1950.fixed.mdnew file mode 100644index 00000000..637e3819--- /dev/null+++ b/changelog.d/0.76.0/1950.fixed.md@@ -0,0 +1 @@+- Leaderboard CSV exports prefix a model or benchmark name that a spreadsheet would read as a formula with a quote. (#1950)diff --git a/src/soup_cli/eval/leaderboard.py b/src/soup_cli/eval/leaderboard.pyindex e44ea3c8..b605e2fd 100644--- a/src/soup_cli/eval/leaderboard.py+++ b/src/soup_cli/eval/leaderboard.py@@ -9,6 +9,7 @@ from dataclasses import dataclass, fieldfrom typing import Optionalfrom soup_cli.eval.results import newest_eval_rows+from soup_cli.utils.csv_safe import spreadsheet_safe@dataclass@@ -155,10 +156,12 @@ def export_leaderboard(# Preserve the existing empty benchmark column for an empty export.benchmarks = sorted(all_benchmarks) or [""]- lines = [_csv_line(["model", *benchmarks, "average"])]+ # Names are free text; scores and the average are numbers and stay as they are.+ header = ["model", *(spreadsheet_safe(name) for name in benchmarks), "average"]+ lines = [_csv_line(header)]for model, scores, avg in sorted_models:vals = [str(scores.get(bench, "")) for bench in benchmarks]- lines.append(_csv_line([model, *vals, f"{avg:.4f}"]))+ lines.append(_csv_line([spreadsheet_safe(model), *vals, f"{avg:.4f}"]))return "\n".join(lines)# Default: JSONdiff --git a/src/soup_cli/utils/csv_safe.py b/src/soup_cli/utils/csv_safe.pynew file mode 100644index 00000000..b2e5263d--- /dev/null+++ b/src/soup_cli/utils/csv_safe.py@@ -0,0 +1,23 @@+"""Spreadsheet-safe text for CSV cells.++A cell whose text starts with ``=``, ``+``, ``-``, ``@``, TAB, CR or LF is read as a+formula by Excel, LibreOffice and Sheets. :func:`spreadsheet_safe` prefixes such a+cell with a single quote, the convention spreadsheets honour.+"""++from __future__ import annotations++_FORMULA_LEADERS = ("=", "+", "-", "@", "\t", "\r", "\n")+++def spreadsheet_safe(value: object) -> str:+ """Return ``str(value)``, prefixed with ``'`` if a spreadsheet would read it as a formula.++ Apply this to free-text cells only (model, benchmark and similar names). Numeric+ columns must be formatted separately and left alone, so a negative score such as+ -0.5 stays -0.5.+ """+ text = str(value)+ if text.startswith(_FORMULA_LEADERS):+ return "'" + text+ return textdiff --git a/tests/test_eval_leaderboard_csv.py b/tests/test_eval_leaderboard_csv.pyindex b8727277..8b045acc 100644--- a/tests/test_eval_leaderboard_csv.py+++ b/tests/test_eval_leaderboard_csv.py@@ -166,7 +166,38 @@ def test_csv_order_missing_cells_and_average_format_unchanged() -> None:)-def test_formula_like_identity_is_not_sanitized() -> None:- model = "=SUM(1,2)"- board = make_leaderboard(model, "custom")- assert parse_csv(export_leaderboard(board, fmt="csv"))[1][0] == model[email protected]("lead", ["=", "+", "-", "@", "\t", "\r", "\n"])+def test_formula_like_names_are_prefixed_with_a_quote(lead: str) -> None:+ name = lead + "SUM(1,2)"+ model_rows = parse_csv(export_leaderboard(make_leaderboard(name, "custom"), fmt="csv"))+ assert model_rows == [+ ["model", "custom", "average"],+ ["'" + name, "0.75", "0.7500"],+ ]+ bench_rows = parse_csv(export_leaderboard(make_leaderboard("models/base", name), fmt="csv"))+ assert bench_rows == [+ ["model", "'" + name, "average"],+ ["models/base", "0.75", "0.7500"],+ ]+++def test_plain_names_and_negative_score_are_unchanged() -> None:+ # A formula character that is not the first character is left alone, and so is a+ # negative score: only the name cells are prefixed.+ board = Leaderboard(entries=[+ LeaderboardEntry(model_path="models/a=b-c@d+e", benchmark="delta-x", score=-0.5),+ ])+ board.compute()+ assert export_leaderboard(board, fmt="csv") == (+ "model,delta-x,average\nmodels/a=b-c@d+e,-0.5,-0.5000"+ )+++def test_spreadsheet_safe_helper() -> None:+ from soup_cli.utils.csv_safe import spreadsheet_safe++ assert spreadsheet_safe("=A1") == "'=A1"+ assert spreadsheet_safe("\nx") == "'\nx"+ assert spreadsheet_safe("plain") == "plain"+ assert spreadsheet_safe("") == ""+ assert spreadsheet_safe(-0.5) == "'-0.5" # callers keep numbers out of it