Skip to content

armgit / Soup

Public Imported from GitHub
0

Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.

feat(registry): record a training data file with soup registry push --data (#1764) (#1907)

Abdulwaarith Zakariyya24514015b3eb
diff --git a/changelog.d/0.76.0/1907.added.md b/changelog.d/0.76.0/1907.added.md
new file mode 100644
index 00000000..5b54d41e
--- /dev/null
+++ b/changelog.d/0.76.0/1907.added.md
@@ -0,0 +1,6 @@
+- **`soup registry push --data <file>` records a training data file's SHA-256 as the entry's `data_hash` (#1764 by @abdulwaarith0 in #1907).**
+ Registering a run used to leave `data_hash` empty. The file must be under the current
+ directory and is refused before anything is written if it is missing, not a regular file
+ or outside it. The hash records the file registered as the training input, not proof of
+ what the run trained on. `soup registry show` now prints `data_hash`, or `-` when there
+ is none.
diff --git a/docs/adapters-and-governance.md b/docs/adapters-and-governance.md
index 7701a05f..46eb6508 100644
--- a/docs/adapters-and-governance.md
+++ b/docs/adapters-and-governance.md
@@ -269,6 +269,9 @@ Every fine-tune you ship should be reproducible. Soup's local registry (`~/.soup
# Register a completed run
soup registry push --run-id run_202611_abc123 --name llama31-chat --tag v1
+# Also record the training data file's SHA-256 as data_hash
+soup registry push --run-id run_202611_abc123 --name llama31-chat --tag v1 --data data/train.jsonl
+
# List entries (filter by name, tag, base model, task)
soup registry list
soup registry list --name llama31-chat --tag prod
@@ -289,6 +292,8 @@ soup registry promote llama31-chat-v1 --tag prod
soup registry delete llama31-chat-v1 --yes
```
+**Training data:** `push --data <file>` stores the file's SHA-256 as the entry's `data_hash`, shown by `soup registry show`. It records the file registered as the training input, not proof of what the run trained on. The file must be under the current directory; without `--data` the entry has no `data_hash`.
+
**Lineage DAG** — every entry can point to a parent (its ancestor run). Walk the DAG for any name with:
```bash
diff --git a/docs/cli-reference.md b/docs/cli-reference.md
index 42c72e68..da6330c4 100644
--- a/docs/cli-reference.md
+++ b/docs/cli-reference.md
@@ -3228,6 +3228,7 @@ Usage: `soup registry push [OPTIONS]`
| `--name`, `-n` | text | | yes | Registry entry name |
| `--tag`, `-t` | text | `v1` | | Tag (e.g. v1, prod-2024) |
| `--notes` | text | `""` | | Free-form notes |
+| `--data` | text | | | Training data file to record: its SHA-256 is stored as data_hash. This is the file registered as the training input, not proof of what the run trained on. Must be a file under the current directory. |
### `soup registry search`
diff --git a/docs/commands.md b/docs/commands.md
index 570735c4..21f797b0 100644
--- a/docs/commands.md
+++ b/docs/commands.md
@@ -194,6 +194,7 @@ soup recipes verify --config soup.yaml Same check for one config, before
soup recipes verify --no-templates Recipes only; skip src/soup_cli/templates and examples/
soup recipes verify --json One JSON row per config on stdout; advisories go to stderr
soup registry push --run-id <id> --name n --tag v1 Register run
+soup registry push ... --data train.jsonl Also record that file's SHA-256 as data_hash
soup registry list [--name n] [--tag v1] List registry entries
soup registry show <ref> Entry details + artifacts + ancestors
soup registry diff <a> <b> Side-by-side config + eval delta
diff --git a/src/soup_cli/commands/registry.py b/src/soup_cli/commands/registry.py
index d16819ad..08ef00c9 100644
--- a/src/soup_cli/commands/registry.py
+++ b/src/soup_cli/commands/registry.py
@@ -42,12 +42,36 @@ def _require_entry(store: RegistryStore, ref: str) -> dict:
return entry
+def _data_file(path: str) -> str:
+ """The ``--data`` file, refused before any database is opened."""
+ from pathlib import Path
+
+ from soup_cli.utils.paths import is_under_cwd
+
+ file_path = Path(path)
+ if not file_path.exists():
+ _fail(f"--data file not found: {path}")
+ if not file_path.is_file():
+ _fail(f"--data is not a file: {path}")
+ if not is_under_cwd(file_path):
+ _fail(f"--data must be under the current working directory: {path}")
+ return str(file_path)
+
+
@app.command("push")
def push_cmd(
run_id: str = typer.Option(..., "--run-id", help="Training run id to register"),
name: str = typer.Option(..., "--name", "-n", help="Registry entry name"),
tag: str = typer.Option("v1", "--tag", "-t", help="Tag (e.g. v1, prod-2024)"),
notes: str = typer.Option("", "--notes", help="Free-form notes"),
+ data: Optional[str] = typer.Option(
+ None, "--data",
+ help=(
+ "Training data file to record: its SHA-256 is stored as data_hash. "
+ "This is the file registered as the training input, not proof of "
+ "what the run trained on. Must be a file under the current directory."
+ ),
+ ),
) -> None:
"""Register a completed training run as a registry entry."""
try:
@@ -55,6 +79,7 @@ def push_cmd(
validate_tag(tag)
except ValueError as exc:
_fail(f"Invalid input: {exc}")
+ data_path = _data_file(data) if data is not None else None
from soup_cli.experiment.tracker import ExperimentTracker
@@ -66,7 +91,7 @@ def push_cmd(
try:
entry_id = store.register_from_run(
tracker, run_id, name=name, tag=tag,
- notes=notes or None,
+ notes=notes or None, data_path=data_path,
)
except ValueError as exc:
_fail(str(exc))
@@ -150,6 +175,7 @@ def show_cmd(
("task", entry["task"]),
("run_id", entry.get("run_id") or "-"),
("entry_hash", entry.get("entry_hash", "")[:16] + "..."),
+ ("data_hash", (entry["data_hash"][:16] + "...") if entry.get("data_hash") else "-"),
("created_at", entry["created_at"]),
("notes", entry.get("notes") or ""),
]
diff --git a/src/soup_cli/registry/store.py b/src/soup_cli/registry/store.py
index 655f25f3..87720043 100644
--- a/src/soup_cli/registry/store.py
+++ b/src/soup_cli/registry/store.py
@@ -666,8 +666,14 @@ class RegistryStore:
name: str,
tag: str,
notes: Optional[str] = None,
+ data_path: Optional[str] = None,
) -> str:
- """Create a registry entry from an existing training run."""
+ """Create a registry entry from an existing training run.
+
+ ``data_path`` names the file to record as the run's training input; its
+ SHA-256 becomes ``data_hash``. It is what the caller says was trained on,
+ not proof of it. Without it, ``data_hash`` stays ``None``.
+ """
run = tracker.get_run(run_id)
if run is None:
raise ValueError(f"run not found: {run_id}")
@@ -689,7 +695,7 @@ class RegistryStore:
task=task,
run_id=run.get("run_id") or run_id,
config=config,
- data_path=None,
+ data_path=data_path,
notes=notes,
)
diff --git a/tests/test_registry_push_data.py b/tests/test_registry_push_data.py
new file mode 100644
index 00000000..cf4ae0d9
--- /dev/null
+++ b/tests/test_registry_push_data.py
@@ -0,0 +1,184 @@
+"""`soup registry push --data`: record the training input file's hash on a run's entry (#1764)."""
+
+from __future__ import annotations
+
+import os
+from pathlib import Path
+
+import pytest
+from typer.testing import CliRunner
+
+from soup_cli.cli import app
+from soup_cli.registry.hashing import hash_entry, hash_file
+from tests.conftest import strip_ansi
+
+runner = CliRunner()
+
+CONFIG = {"base": "llama", "task": "sft"}
+
+
+def _finished_run(tmp_path: Path) -> str:
+ from soup_cli.experiment.tracker import ExperimentTracker
+
+ tracker = ExperimentTracker()
+ try:
+ run_id = tracker.start_run(
+ config_dict=CONFIG, device="cpu", device_name="cpu", gpu_info={},
+ )
+ tracker.finish_run(run_id, 2.0, 0.5, 100, 60.0, str(tmp_path / "out"))
+ finally:
+ tracker.close()
+ return run_id
+
+
+def work(tmp_path, monkeypatch):
+ """A working directory with isolated experiment and registry databases."""
+ cwd = tmp_path / "work"
+ cwd.mkdir()
+ monkeypatch.setenv("SOUP_DB_PATH", str(tmp_path / "exp.db"))
+ monkeypatch.setenv("SOUP_REGISTRY_DB_PATH", str(tmp_path / "reg.db"))
+ monkeypatch.chdir(cwd)
+ return cwd
+
+
+def _push(run_id: str, *extra: str):
+ return runner.invoke(
+ app, ["registry", "push", "--run-id", run_id, "--name", "chat", "--tag", "v1", *extra],
+ )
+
+
+def _entry():
+ from soup_cli.registry.store import RegistryStore
+
+ with RegistryStore() as store:
+ return store.get(store.resolve("chat:v1"))
+
+
+def test_push_with_data_records_the_file_hash(work):
+ run_id = _finished_run(work.parent)
+ data = work / "train.jsonl"
+ data.write_text('{"text": "a"}\n{"text": "b"}\n', encoding="utf-8")
+
+ result = _push(run_id, "--data", "train.jsonl")
+
+ assert result.exit_code == 0, (result.output, repr(result.exception))
+ entry = _entry()
+ assert entry["data_hash"] == hash_file(str(data))
+ assert entry["entry_hash"] == hash_entry(
+ config=CONFIG, data_path=str(data), base_model="llama",
+ )
+ assert entry["entry_hash"] != hash_entry(config=CONFIG, data_path=None, base_model="llama")
+
+
+def test_push_without_data_is_unchanged(work):
+ run_id = _finished_run(work.parent)
+
+ result = _push(run_id)
+
+ assert result.exit_code == 0, (result.output, repr(result.exception))
+ entry = _entry()
+ assert entry["data_hash"] is None
+ assert entry["entry_hash"] == hash_entry(config=CONFIG, data_path=None, base_model="llama")
+
+
+def test_show_prints_the_data_hash(work):
+ run_id = _finished_run(work.parent)
+ data = work / "train.jsonl"
+ data.write_text('{"text": "a"}\n', encoding="utf-8")
+ assert _push(run_id, "--data", "train.jsonl").exit_code == 0
+
+ result = runner.invoke(app, ["registry", "show", "chat:v1"])
+
+ assert result.exit_code == 0, (result.output, repr(result.exception))
+ assert "data_hash" in result.output
+ assert hash_file(str(data))[:16] in result.output
+
+
+def test_show_marks_a_missing_data_hash(work):
+ run_id = _finished_run(work.parent)
+ assert _push(run_id).exit_code == 0
+
+ result = runner.invoke(app, ["registry", "show", "chat:v1"])
+
+ assert result.exit_code == 0, (result.output, repr(result.exception))
+ row = next(line for line in result.output.splitlines() if "data_hash" in line)
+ assert "-" in row.replace("data_hash", "")
+
+
+def _assert_refused_before_the_registry_opens(result, work, needle: str):
+ assert result.exit_code == 1, (result.output, repr(result.exception))
+ assert needle in " ".join(strip_ansi(result.output).split())
+ assert not (work.parent / "reg.db").exists()
+
+
+def test_missing_data_file_is_refused(work):
+ run_id = _finished_run(work.parent)
+
+ result = _push(run_id, "--data", "nope.jsonl")
+
+ _assert_refused_before_the_registry_opens(result, work, "not found")
+
+
+def test_data_directory_is_refused(work):
+ run_id = _finished_run(work.parent)
+ (work / "data").mkdir()
+
+ result = _push(run_id, "--data", "data")
+
+ _assert_refused_before_the_registry_opens(result, work, "not a file")
+
+
[email protected]("spelling", ["absolute", "relative"])
+def test_data_outside_the_working_directory_is_refused(work, spelling):
+ run_id = _finished_run(work.parent)
+ outside = work.parent / "outside.jsonl"
+ outside.write_text('{"text": "a"}\n', encoding="utf-8")
+ path = str(outside) if spelling == "absolute" else os.path.join("..", "outside.jsonl")
+
+ result = _push(run_id, "--data", path)
+
+ _assert_refused_before_the_registry_opens(result, work, "under the current working directory")
+
+
+def test_symlink_to_a_file_outside_is_refused(work):
+ run_id = _finished_run(work.parent)
+ outside = work.parent / "outside.jsonl"
+ outside.write_text('{"text": "a"}\n', encoding="utf-8")
+ (work / "train.jsonl").symlink_to(outside)
+
+ result = _push(run_id, "--data", "train.jsonl")
+
+ _assert_refused_before_the_registry_opens(result, work, "under the current working directory")
+
+
+def test_register_from_run_takes_an_optional_data_path(work):
+ from soup_cli.experiment.tracker import ExperimentTracker
+ from soup_cli.registry.store import RegistryStore
+
+ run_id = _finished_run(work.parent)
+ data = work / "train.jsonl"
+ data.write_text('{"text": "a"}\n', encoding="utf-8")
+ tracker = ExperimentTracker()
+ try:
+ with RegistryStore() as store:
+ with_data = store.register_from_run(
+ tracker, run_id, name="chat", tag="v1", data_path=str(data),
+ )
+ without = store.register_from_run(tracker, run_id, name="chat", tag="v2")
+ assert store.get(with_data)["data_hash"] == hash_file(str(data))
+ assert store.get(without)["data_hash"] is None
+ finally:
+ tracker.close()
+
+
+def test_help_describes_what_data_records():
+ result = runner.invoke(app, ["registry", "push", "--help"], env={"COLUMNS": "200"})
+
+ assert result.exit_code == 0, (result.output, repr(result.exception))
+ text = " ".join(strip_ansi(result.output).split())
+ assert "--data" in text
+ assert "training input" in text
+ assert "not proof" in text
+