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.

fix(ci): require fully valid data in generated gates (#2079)

Nurkhan Esenbek149451cb8e77
diff --git a/changelog.d/0.76.0/2079.fixed.md b/changelog.d/0.76.0/2079.fixed.md
new file mode 100644
index 00000000..f69b7567
--- /dev/null
+++ b/changelog.d/0.76.0/2079.fixed.md
@@ -0,0 +1 @@
+- Generated fine-tuning gates require every training-data row to convert by passing `--min-valid-fraction 1.0`; standalone validation and existing workflows are unchanged. (#2079 by @kok-o)
diff --git a/docs/compliance.md b/docs/compliance.md
index e82ef1af..6fec38e4 100644
--- a/docs/compliance.md
+++ b/docs/compliance.md
@@ -117,11 +117,16 @@ soup ci init --data data/train.jsonl --suite expectations.yaml --evidence ship_e
The generated job runs, in order:
```
-soup data validate <data> # dataset format compliance
+soup data validate <data> --min-valid-fraction 1.0 # every row must convert
soup expect <data> <suite> # PII / token-length / refusal / judge expectations
soup ship --evidence <ev.json> # SHIP / DON'T-SHIP (exit 2 blocks the merge)
```
+The generated data gate refuses any dropped row, including skipped JSONL records.
+The standalone validator keeps its permissive default. To tolerate partial data,
+edit `--min-valid-fraction` in your workflow. Existing workflow files are unchanged
+until you regenerate them with `soup ci init --force`.
+
A minimal `expectations.yaml` for the second step:
```yaml
diff --git a/src/soup_cli/utils/ci_workflow.py b/src/soup_cli/utils/ci_workflow.py
index f323098a..9d23beb4 100644
--- a/src/soup_cli/utils/ci_workflow.py
+++ b/src/soup_cli/utils/ci_workflow.py
@@ -3,7 +3,7 @@
``soup ci init`` writes ``.github/workflows/soup-gate.yml`` — a CI job that
gates every PR on three Soup checks:
- soup data validate <data> # dataset format compliance
+ soup data validate <data> --min-valid-fraction 1.0 # every row must convert
soup expect <data> <suite> # expectations suite (PII / length / refusal)
soup ship --evidence <ev.json> # SHIP / DON'T-SHIP verdict (exit 2 = block)
@@ -43,6 +43,7 @@ _WORKFLOW_TEMPLATE = """\
# Gates every PR on: data validate -> expectations -> SHIP verdict.
# Edit the paths below to match your repo. The `soup ship` step needs a
# committed evidence JSON (see `soup ship --evidence`); remove it if unused.
+# Data validation requires every row; edit --min-valid-fraction to allow drops.
name: Soup Fine-tuning Gate
on:
@@ -69,7 +70,7 @@ jobs:
- name: Validate training data
run: |
set +e
- soup data validate {data}
+ soup data validate {data} --min-valid-fraction 1.0
rc=$?
set -e
if [ "$rc" -eq 2 ]; then
diff --git a/tests/test_ci_workflow.py b/tests/test_ci_workflow.py
new file mode 100644
index 00000000..72325db0
--- /dev/null
+++ b/tests/test_ci_workflow.py
@@ -0,0 +1,66 @@
+"""Run the rendered validator command against actual dataset quality boundaries."""
+
+import json
+import shlex
+
+import pytest
+import yaml
+from typer.testing import CliRunner
+
+from soup_cli.cli import app
+from soup_cli.utils.ci_workflow import render_soup_gate_workflow
+
+
+def _validation_args(body):
+ steps = yaml.safe_load(body)["jobs"]["soup-gate"]["steps"]
+ step, = [item for item in steps if item.get("name") == "Validate training data"]
+ command, = [line.strip() for line in step["run"].splitlines()
+ if line.strip().startswith("soup data validate ")]
+ args = shlex.split(command)
+ assert args[:3] == ["soup", "data", "validate"]
+ return args[1:]
+
+
[email protected]("name", ["train.jsonl", "train's set.jsonl"])
[email protected]("valid,total,expected", [(1, 10, 2), (9, 10, 2), (10, 10, 0)])
+def test_rendered_gate_refuses_any_partial_drop(
+ tmp_path, monkeypatch, name, valid, total, expected,
+):
+ monkeypatch.chdir(tmp_path)
+ rows = [{"instruction": "hi", "output": "hello"}] * valid
+ rows += [{"instruction": "missing output"}] * (total - valid)
+ (tmp_path / name).write_text("".join(json.dumps(row) + "\n" for row in rows), encoding="utf-8")
+ body = render_soup_gate_workflow(
+ data_path=name, suite_path="expectations.yaml", evidence_path="evidence.json",
+ )
+ runner = CliRunner()
+ result = runner.invoke(app, _validation_args(body))
+ assert result.exit_code == expected, (result.output, repr(result.exception))
+ # The strict policy belongs to the generated gate, not standalone validation.
+ standalone = runner.invoke(app, ["data", "validate", name])
+ assert standalone.exit_code == 0, (standalone.output, repr(standalone.exception))
+
+
[email protected]("content", ["", "\n", '{"instruction":"hi","output":"ok"}\n42\n'])
+def test_rendered_gate_refuses_empty_or_skipped_rows(tmp_path, monkeypatch, content):
+ monkeypatch.chdir(tmp_path)
+ (tmp_path / "train.jsonl").write_text(content, encoding="utf-8")
+ body = render_soup_gate_workflow(
+ data_path="train.jsonl", suite_path="expectations.yaml", evidence_path="evidence.json",
+ )
+ result = CliRunner().invoke(app, _validation_args(body))
+ assert result.exit_code in (2, 3), (result.output, repr(result.exception))
+
+
+def test_ci_init_writes_strict_command_and_preserves_existing_workflow(tmp_path, monkeypatch):
+ monkeypatch.chdir(tmp_path)
+ runner = CliRunner()
+ result = runner.invoke(app, ["ci", "init"])
+ assert result.exit_code == 0, result.output
+ workflow = tmp_path / ".github/workflows/soup-gate.yml"
+ args = _validation_args(workflow.read_text(encoding="utf-8"))
+ assert args[-2:] == ["--min-valid-fraction", "1.0"]
+ workflow.write_text("operator-owned workflow\n", encoding="utf-8")
+ result = runner.invoke(app, ["ci", "init"])
+ assert result.exit_code == 1, result.output
+ assert workflow.read_text(encoding="utf-8") == "operator-owned workflow\n"