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(config): refuse citation span weights on pretrain (#1406) (#1843)

Nurkhan Esenbek44d67b64e232
diff --git a/changelog.d/0.76.0/1843.fixed.md b/changelog.d/0.76.0/1843.fixed.md
new file mode 100644
index 00000000..a352b3e9
--- /dev/null
+++ b/changelog.d/0.76.0/1843.fixed.md
@@ -0,0 +1 @@
+- Refuse training.citation_faithful on pretrain, whose trainer does not apply citation span weights; use task: sft with data.format: raft. (#1406 by @kok-o in #1843)
diff --git a/docs/training.md b/docs/training.md
index 696b256a..d2671696 100644
--- a/docs/training.md
+++ b/docs/training.md
@@ -1897,7 +1897,7 @@ score = score_citations(
# CitationScore(precision=1.0, recall=1.0, f1=1.0, predicted_count=1, expected_count=1)
```
-Citation-faithful FT is gated to `task in {sft, pretrain}` + `data.format='raft'` — misconfigured runs fail at config load with a named-field message.
+Citation-faithful FT requires `task: sft` + `data.format: raft` — misconfigured runs fail at config load with a named-field message. The pretrain trainer does not apply citation span weights and refuses `training.citation_faithful: true`.
Under the hood, a `format: raft` run trains **answer-only**: each row is composed into a prompt (golden + distractor docs, shuffled deterministically by `data.raft_shuffle_seed`, each labelled `[doc-N]`) followed by the answer; the prompt span is masked out of the loss and — when `citation_faithful: true` — the bracketed `[doc-id]` spans in the answer get a boosted per-token loss weight. Rows whose prompt fills `max_length` (answer fully truncated) are dropped with a warning rather than silently shrinking the dataset.
diff --git a/src/soup_cli/config/schema.py b/src/soup_cli/config/schema.py
index 203f021a..25bea321 100644
--- a/src/soup_cli/config/schema.py
+++ b/src/soup_cli/config/schema.py
@@ -7801,10 +7801,8 @@ class SoupConfig(BaseModel):
* ``citation_faithful=True`` requires ``data.format='raft'`` (the
RAFT row carries the doc references; other formats can't supply
ground-truth citation IDs).
- * ``citation_faithful=True`` requires ``task in {sft, pretrain}``
- (the span-mask runtime only makes sense for the SFT family;
- mirrors v0.52.0 distill / classifier
- task-gate policy — review M3 fix).
+ * ``citation_faithful=True`` requires ``task='sft'``: only its
+ RAFT route applies the citation span weights.
* ``citation_style`` set without ``citation_faithful=True`` is a
silent-no-op footgun — rejected (mirrors v0.61.0 unlearn_alpha /
v0.62.0 Part B ra_dit_retriever_model policy).
@@ -7833,12 +7831,11 @@ class SoupConfig(BaseModel):
"Citation-faithful FT pairs with the v0.62.0 Part A "
"RAFT data format (which carries the doc references)."
)
- if self.task not in ("sft", "pretrain"):
+ if self.task != "sft":
raise ValueError(
"training.citation_faithful=true requires "
- f"task in {{sft, pretrain}}; got task={self.task!r}. "
- "Citation-faithful FT is an SFT-family feature: its "
- "span-mask runtime runs in the SFT trainer."
+ f"task='sft'; got task={self.task!r}. "
+ "Use task: sft with data.format: raft to apply citation span weights."
)
return self
diff --git a/tests/test_issue1406_citation_sft_only.py b/tests/test_issue1406_citation_sft_only.py
new file mode 100644
index 00000000..e666ac2a
--- /dev/null
+++ b/tests/test_issue1406_citation_sft_only.py
@@ -0,0 +1,31 @@
+"""Citation span weighting is implemented by the SFT RAFT route only."""
+
+import pytest
+
+from soup_cli.config.schema import SoupConfig
+
+
+def test_pretrain_citation_weighting_is_refused() -> None:
+ with pytest.raises(ValueError) as exc_info:
+ SoupConfig(
+ base="test/model", task="pretrain", data={"train": "raft.jsonl", "format": "raft"},
+ training={"citation_faithful": True},
+ )
+ message = str(exc_info.value)
+ assert "training.citation_faithful" in message
+ assert "pretrain" in message
+ assert "task: sft" in message
+ assert "data.format: raft" in message
+
+
+def test_sft_raft_still_accepts_citation_weighting() -> None:
+ cfg = SoupConfig(
+ base="test/model", task="sft", data={"train": "raft.jsonl", "format": "raft"},
+ training={"citation_faithful": True, "citation_style": "bracket"},
+ )
+ assert cfg.training.citation_faithful is True
+
+
+def test_pretrain_without_citation_weighting_is_unchanged() -> None:
+ cfg = SoupConfig(base="test/model", task="pretrain", data={"train": "d.jsonl"})
+ assert cfg.training.citation_faithful is False
diff --git a/tests/test_v0620_followups.py b/tests/test_v0620_followups.py
index 1e34be1e..50366526 100644
--- a/tests/test_v0620_followups.py
+++ b/tests/test_v0620_followups.py
@@ -2,7 +2,7 @@
Closes coverage gaps surfaced by the TDD review:
-* H1 — citation_faithful + non-SFT-family task gate.
+* H1 — citation_faithful + non-SFT task gate.
* H2 — RAFT _MAX_RAFT_FIELD_LEN per-field oversize boundary.
* H3 — RAFT null-byte rejection on golden_doc / answer / distractors.
* H5 — `soup steer train --plan-only` deferred-marker stripping regression guard.
@@ -52,7 +52,7 @@ output: ./output
with pytest.raises(Exception, match="sft|pretrain"):
load_config_from_string(yaml_text)
- def test_citation_faithful_on_pretrain_accepted(self):
+ def test_citation_faithful_on_pretrain_rejected(self):
from soup_cli.config.loader import load_config_from_string
yaml_text = """\
@@ -71,8 +71,8 @@ training:
output: ./output
"""
- cfg = load_config_from_string(yaml_text)
- assert cfg.training.citation_faithful is True
+ with pytest.raises(ValueError, match="task='sft'"):
+ load_config_from_string(yaml_text)
def test_citation_faithful_on_dpo_rejected(self):
from soup_cli.config.loader import load_config_from_string