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(loop): probe the thumbs columns the harvest reads; drop the dead traces guard (#1440) (#1966)
Srinivasan R1f5c7ba3dd9e
diff --git a/changelog.d/0.76.0/1966.fixed.md b/changelog.d/0.76.0/1966.fixed.mdnew file mode 100644index 00000000..abbb102f--- /dev/null+++ b/changelog.d/0.76.0/1966.fixed.md@@ -0,0 +1 @@+- `soup loop watch` now refuses a thumbs database whose `thumbs` table lacks a column the harvest reads (`prompt`, `response`, `thumb` or `ts`) before the loop starts, with the same exit 2 as a missing or unreadable database. Before, the pre-flight only checked that the table existed, so a hand-made table with other columns passed it and the first iteration failed, which under `--detach` ends without a message (#1440 by @Srinivasan8888 in #1966).diff --git a/docs/adapters-and-governance.md b/docs/adapters-and-governance.mdindex e9f4d933..5dbd084d 100644--- a/docs/adapters-and-governance.md+++ b/docs/adapters-and-governance.md@@ -118,9 +118,9 @@ soup loop watch --pre-wired --pack-cans --poll-interval 300# Learn from Soup's own serving (#1440): the pre-wired harvest also reads the# thumbs `soup serve --record-thumbs` captures through POST /v1/thumbs, pairing-# the latest π and π answer per prompt. The database must stay under cwd and-# exist as a thumbs database: start the serve first, or `soup loop watch` refuses,-# naming the field.+# the latest thumbs-up and thumbs-down answer per prompt. The database must+# stay under cwd and exist as a thumbs database: start the serve first, or+# `soup loop watch` refuses, naming the field.soup serve --model ./base --record-thumbs ./rl.dbsoup loop init registry://abc12 --eval evals/lock.json --baseline registry://prod \--pre-wired --thumbs-db ./rl.dbdiff --git a/src/soup_cli/utils/local_rl.py b/src/soup_cli/utils/local_rl.pyindex e1518d1f..ca7b0270 100644--- a/src/soup_cli/utils/local_rl.py+++ b/src/soup_cli/utils/local_rl.py@@ -286,6 +286,10 @@ def record_thumb(conn.commit()+# The one definition of what the harvest reads; ``checked_thumbs_db`` probes it.+THUMBS_HARVEST_SELECT = "SELECT prompt, response, thumb, ts FROM thumbs"++def harvest_dpo_pairs(db_path: str) -> Tuple[DpoPair, ...]:"""Pair up/down responses to the same prompt into DPO training rows.@@ -300,9 +304,7 @@ def harvest_dpo_pairs(db_path: str) -> Tuple[DpoPair, ...]:if not os.path.exists(real):raise FileNotFoundError(f"db_path not found: {db_path!r}")with sqlite3.connect(real) as conn:- rows = conn.execute(- "SELECT prompt, response, thumb, ts FROM thumbs ORDER BY ts ASC"- ).fetchall()+ rows = conn.execute(f"{THUMBS_HARVEST_SELECT} ORDER BY ts ASC").fetchall()last_up: dict[str, str] = {}last_down: dict[str, str] = {}for prompt, response, thumb, _ts in rows:@@ -615,6 +617,7 @@ def run_nightly_train(__all__ = [+ "THUMBS_HARVEST_SELECT","SUPPORTED_LOCAL_RL_BACKENDS","SUPPORTED_LOCAL_RL_TRAIN_METHODS","MAX_PROMPT_LEN",diff --git a/src/soup_cli/utils/loop_stages.py b/src/soup_cli/utils/loop_stages.pyindex 7975638e..1a530973 100644--- a/src/soup_cli/utils/loop_stages.py+++ b/src/soup_cli/utils/loop_stages.py@@ -120,7 +120,7 @@ def checked_thumbs_db(state: LoopState) -> Optional[str]:if resolved is None:return Nonepath, field = resolved- from soup_cli.utils.local_rl import validate_db_path+ from soup_cli.utils.local_rl import THUMBS_HARVEST_SELECT, validate_db_pathtry:validate_db_path(path)@@ -137,7 +137,7 @@ def checked_thumbs_db(state: LoopState) -> Optional[str]:try:# Short timeout: a lock is not a verdict, so do not wait out sqlite's 5 s.with contextlib.closing(sqlite3.connect(os.path.abspath(path), timeout=0.1)) as conn:- conn.execute("SELECT 1 FROM thumbs LIMIT 1")+ conn.execute(f"{THUMBS_HARVEST_SELECT} LIMIT 1")except sqlite3.Error as exc:if "locked" in str(exc).lower():return path@@ -190,7 +190,7 @@ def harvest_from_traces(state: LoopState) -> Mapping[str, object]:trace_dir = _resolve_trace_dir(state)traces = list(parse_soup_serve(trace_dir)) if trace_dir else []- pairs = list(build_pairs(traces, signal="thumbs_up")) if traces else []+ pairs = list(build_pairs(traces, signal="thumbs_up"))thumbs = _thumbs_pairs(state)seen = {(p.prompt, p.chosen, p.rejected) for p in pairs}for p in thumbs:diff --git a/tests/test_loop_thumbs_harvest.py b/tests/test_loop_thumbs_harvest.pyindex b2df46e7..8f10d364 100644--- a/tests/test_loop_thumbs_harvest.py+++ b/tests/test_loop_thumbs_harvest.py@@ -537,6 +537,59 @@ def test_watch_detach_refuses_a_file_that_is_not_a_thumbs_database(cwd, monkeypaassert spawned == []+def _make_wrong_columns_db(columns: str = "x", path: str = "thumbs.db") -> None:+ """A hand-made ``thumbs`` table that lacks some columns the harvest reads."""+ conn = sqlite3.connect(path)+ conn.execute(f"CREATE TABLE thumbs({columns})")+ conn.commit()+ conn.close()++[email protected]("missing", ["prompt", "response", "thumb", "ts"])+def test_watch_refuses_a_thumbs_table_without_the_harvest_columns(cwd, monkeypatch, missing):+ kept = [c for c in ("prompt", "response", "thumb", "ts") if c != missing]+ _make_wrong_columns_db(", ".join(kept))+ _init_loop(True)+ monkeypatch.setenv("SOUP_LOOP_THUMBS_DB", "thumbs.db")++ result, text = _watch()++ assert result.exit_code == 2, text+ assert "is not a readable thumbs database" in text, text+ assert "Traceback" not in text, text+ assert not os.path.exists(".soup-loops"), "no iteration may run"+++def test_watch_detach_refuses_a_thumbs_table_without_the_harvest_columns(cwd, monkeypatch):+ import soup_cli.commands.loop as loop_cmd++ spawned = []+ monkeypatch.setattr(loop_cmd.subprocess, "Popen", lambda *a, **k: spawned.append(a))+ _make_wrong_columns_db()+ _init_loop(True)+ monkeypatch.setenv("SOUP_LOOP_THUMBS_DB", "thumbs.db")++ result, text = _watch("--detach")++ assert result.exit_code == 2, text+ assert "is not a readable thumbs database" in text, text+ assert spawned == []+++def test_watch_still_accepts_a_database_made_by_init_local_rl_db(cwd, monkeypatch):+ """Control: the real schema passes the column-list probe."""+ from soup_cli.utils import local_rl++ local_rl.init_local_rl_db("thumbs.db")+ _init_loop(True)+ monkeypatch.setenv("SOUP_LOOP_THUMBS_DB", "thumbs.db")++ result, text = _watch()++ assert "not a readable thumbs database" not in text, text+ assert result.exit_code == 0, text++def test_watch_does_not_let_a_control_sequence_in_the_path_reach_the_terminal(cwd, monkeypatch):_init_loop(True)monkeypatch.setenv("SOUP_LOOP_THUMBS_DB", "a\x1b[2Jb.db")