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(rl-checkpoint): report what a save wrote and stage the unsaved include flags (#808) (#1980)

Srinivasan R85aaac1ef270
diff --git a/changelog.d/0.76.0/1980.fixed.md b/changelog.d/0.76.0/1980.fixed.md
new file mode 100644
index 00000000..20f02d27
--- /dev/null
+++ b/changelog.d/0.76.0/1980.fixed.md
@@ -0,0 +1 @@
+- The RL checkpoint manifest now reports `has_ref_model: false` and `has_rollout_buffer: false`, because no save writes reference-model or rollout-buffer state. Before, it copied `training.rl_checkpoint_include_ref_model` and `training.rl_checkpoint_include_rollout_buffer` from the config, so a checkpoint holding only the adapter and optimizer claimed both. Setting either flag to `true` now warns at load as a staged field and is refused from v0.77 (#808 by @Srinivasan8888 in #1980).
diff --git a/docs/config-reference.md b/docs/config-reference.md
index e375d460..034c3ed5 100644
--- a/docs/config-reference.md
+++ b/docs/config-reference.md
@@ -207,8 +207,8 @@ Sections:
| `training.rl_checkpoint_save_every_steps` | `int \| null` | `null` | `>= 1`, `<= 10000000` | Save an RL-aware mid-epoch checkpoint every N steps. None = use HF Trainer's per-epoch checkpoint only. Requires task in {'grpo', 'ppo'}; the callback persists the policy adapter, optional optimizer state, and a manifest. |
| `training.rl_checkpoint_keep_last` | `int` | `3` | `>= 1`, `<= 100` | Number of recent RL checkpoints to retain. Older ones are pruned at write time. (v0.70.0) |
| `training.rl_checkpoint_include_optimizer` | `bool` | `true` | | Include AdamW / Lion optimizer state in the mid-epoch RL checkpoint. (v0.70.0) |
-| `training.rl_checkpoint_include_ref_model` | `bool` | `false` | | Include the frozen reference model state in the RL checkpoint. Default False (ref model is reconstructable from cfg.base). (v0.70.0) |
-| `training.rl_checkpoint_include_rollout_buffer` | `bool` | `false` | | Include the rollout / replay buffer in the RL checkpoint so resumed runs don't lose collected experience. (v0.70.0) |
+| `training.rl_checkpoint_include_ref_model` | `bool` | `false` | | Not saved yet (#808): the RL checkpoint holds no reference model state whatever this says, and its manifest reports has_ref_model: false. (v0.70.0) |
+| `training.rl_checkpoint_include_rollout_buffer` | `bool` | `false` | | Not saved yet (#808): the RL checkpoint holds no rollout or replay buffer whatever this says, and its manifest reports has_rollout_buffer: false. (v0.70.0) |
| `training.minillm_enabled` | `bool` | `false` | | Enable MiniLLM-style on-policy distillation (Gu et al. 2024). Requires task='distill' on a non-mlx backend; installs the teacher-mixed sampling and reverse-KL loss path. |
| `training.minillm_teacher_mix_ratio` | `float` | `0.0` | `>= 0.0`, `<= 1.0` | Teacher mixture used by MiniLLM. Offline (minillm_on_policy=false): weight of the teacher distribution in the reverse-KL target (ratio \* teacher + (1 - ratio) \* stopgrad(student)). 0.0 is rejected when MiniLLM is enabled because the teacher then has zero weight. On-policy: probability of sampling from the teacher at rollout time; 0.0 = student-only sampling, and the loss is still KL(student \|\| teacher). Typical range 0.2-0.5. (v0.70.0; offline zero rejected in #692) |
| `training.minillm_length_normalize` | `bool` | `true` | | Length-normalise the rollout log-probability before the reverse-KL term. Prevents long completions from dominating the gradient. (v0.70.0) |
diff --git a/src/soup_cli/config/schema.py b/src/soup_cli/config/schema.py
index af6f3068..479c7e5a 100644
--- a/src/soup_cli/config/schema.py
+++ b/src/soup_cli/config/schema.py
@@ -2188,16 +2188,17 @@ class TrainingConfig(BaseModel):
rl_checkpoint_include_ref_model: bool = Field(
default=False,
description=(
- "Include the frozen reference model state in the RL "
- "checkpoint. Default False (ref model is reconstructable "
- "from cfg.base). (v0.70.0)"
+ "Not saved yet (#808): the RL checkpoint holds no reference "
+ "model state whatever this says, and its manifest reports "
+ "has_ref_model: false. (v0.70.0)"
),
)
rl_checkpoint_include_rollout_buffer: bool = Field(
default=False,
description=(
- "Include the rollout / replay buffer in the RL checkpoint "
- "so resumed runs don't lose collected experience. (v0.70.0)"
+ "Not saved yet (#808): the RL checkpoint holds no rollout or "
+ "replay buffer whatever this says, and its manifest reports "
+ "has_rollout_buffer: false. (v0.70.0)"
),
)
diff --git a/src/soup_cli/config/staged_fields.py b/src/soup_cli/config/staged_fields.py
index ddf472d7..42dd6a98 100644
--- a/src/soup_cli/config/staged_fields.py
+++ b/src/soup_cli/config/staged_fields.py
@@ -66,6 +66,9 @@ STAGED_FIELDS: dict[tuple[str, str], Any] = {
("training", "checkpoint_keep_top"): 3,
("training", "convergence_window"): 50,
("training", "convergence_rel_tol"): 0.005,
+ # #808 item 2: accepted, but no save writes reference-model or rollout-buffer state.
+ ("training", "rl_checkpoint_include_ref_model"): False,
+ ("training", "rl_checkpoint_include_rollout_buffer"): False,
("data", "video_dir"): None,
("data", "video_fps"): None,
("data", "video_maxlen"): None,
diff --git a/src/soup_cli/utils/peft_wiring.py b/src/soup_cli/utils/peft_wiring.py
index 0925b457..497ef20f 100644
--- a/src/soup_cli/utils/peft_wiring.py
+++ b/src/soup_cli/utils/peft_wiring.py
@@ -1479,12 +1479,6 @@ def _build_rl_checkpoint_cb(tcfg: Any, *, output_dir: str, task: str) -> Any:
include_optimizer_state=bool(
getattr(tcfg, "rl_checkpoint_include_optimizer", True)
),
- include_ref_model=bool(
- getattr(tcfg, "rl_checkpoint_include_ref_model", False)
- ),
- include_rollout_buffer=bool(
- getattr(tcfg, "rl_checkpoint_include_rollout_buffer", False)
- ),
keep_last=int(getattr(tcfg, "rl_checkpoint_keep_last", 3)),
)
return build_rl_checkpoint_callback(
diff --git a/src/soup_cli/utils/rl_checkpoint.py b/src/soup_cli/utils/rl_checkpoint.py
index fcea2ab3..4dd67d51 100644
--- a/src/soup_cli/utils/rl_checkpoint.py
+++ b/src/soup_cli/utils/rl_checkpoint.py
@@ -111,11 +111,9 @@ class RLCheckpointConfig:
- ``save_every_steps``: int >= 1; ``[1, 10_000_000]`` cap.
- ``include_optimizer_state``: include AdamW / Lion state in the
checkpoint. Default True (the whole point of mid-epoch RL ckpt).
- - ``include_ref_model``: include the frozen reference model state.
- Default False (ref model can usually be reconstructed from
- ``cfg.base``).
- - ``include_rollout_buffer``: include the replay / rollout buffer
- so resumed runs don't lose collected experience.
+ - ``include_ref_model`` / ``include_rollout_buffer``: accepted but not
+ saved yet (#808). No save writes reference-model or rollout-buffer
+ state, and the manifest reports ``false`` for both.
- ``keep_last``: number of recent checkpoints to retain. Older
checkpoints get pruned at write time.
"""
@@ -147,8 +145,8 @@ class RLCheckpointState:
- ``checkpoint_dir``: directory holding the saved tensors. Shape
validated only (cwd-containment deferred to v0.70.1 disk hook).
- ``task``: must be in the RL allowlist (``grpo`` / ``ppo``).
- - ``has_optimizer``/``has_ref_model``/``has_rollout_buffer``: real
- bools (no str/int coercion).
+ - ``has_optimizer``/``has_ref_model``/``has_rollout_buffer``: what this
+ save actually wrote, as real bools (no str/int coercion).
- ``soup_version``: capped at 32 chars; null-byte rejected.
"""
@@ -347,8 +345,11 @@ class _RLCheckpointCallback_body: # type: ignore[misc, valid-type] # noqa: N80
checkpoint_dir=ckpt_dir,
task=self.task,
has_optimizer=has_optimizer,
- has_ref_model=bool(self.config.include_ref_model),
- has_rollout_buffer=bool(self.config.include_rollout_buffer),
+ # #808: like has_optimizer, report what this save wrote. Nothing
+ # writes reference-model or rollout-buffer state, whatever the
+ # include_* flags say, so the manifest must not claim either.
+ has_ref_model=False,
+ has_rollout_buffer=False,
soup_version=self.soup_version,
)
atomic_write_text(
diff --git a/tests/test_issue748_config_fields_reach_a_consumer.py b/tests/test_issue748_config_fields_reach_a_consumer.py
index af119322..7374459c 100644
--- a/tests/test_issue748_config_fields_reach_a_consumer.py
+++ b/tests/test_issue748_config_fields_reach_a_consumer.py
@@ -368,6 +368,13 @@ KNOWN_UNCONSUMED = {
"training.grace_codebook": "#808 -- warns at load from v0.76, refused as of v0.77 "
"(the string appears as an artifact-kind name in "
"store.py:52 / edit.py:312, unrelated to this field)",
+ "training.rl_checkpoint_include_ref_model": "#808 -- warns at load from v0.76, "
+ "refused as of v0.77; no save writes "
+ "reference-model state, so nothing reads it",
+ "training.rl_checkpoint_include_rollout_buffer": "#808 -- warns at load from "
+ "v0.76, refused as of v0.77; no save "
+ "writes rollout-buffer state, so "
+ "nothing reads it",
# -- #807: read ONLY inside a function nothing in src/ references, so the
# read is not consumption. Surfaced by the dead-function gate, which
# the guard previously applied to @property resolvers only.
@@ -749,8 +756,8 @@ def test_the_allowlist_size_is_pinned_exactly():
half: it names WHICH entry went stale, where this one only says the count
moved.
"""
- assert len(KNOWN_UNCONSUMED) == 32, (
- f"KNOWN_UNCONSUMED is {len(KNOWN_UNCONSUMED)}, pinned at 32. Going UP "
+ assert len(KNOWN_UNCONSUMED) == 34, (
+ f"KNOWN_UNCONSUMED is {len(KNOWN_UNCONSUMED)}, pinned at 34. Going UP "
"means a field was allowlisted rather than wired; going DOWN means an "
"entry was retired, which is the good direction -- lower this number "
"in the same commit."
diff --git a/tests/test_issue808_staged_config_fields.py b/tests/test_issue808_staged_config_fields.py
index da13818b..8dc372aa 100644
--- a/tests/test_issue808_staged_config_fields.py
+++ b/tests/test_issue808_staged_config_fields.py
@@ -125,12 +125,12 @@ class TestTheDeadline:
class TestStagedFieldsInventory:
- """Validate inventory size and default handling across all 29 staged fields."""
+ """Validate inventory size and default handling across all 31 staged fields."""
- def test_exactly_29_staged_fields_registered(self) -> None:
- # 17 from #808 initial, 3 from #761, plus 9 Group B knobs from #808.
- assert len(STAGED_FIELDS) == 29, (
- f"Expected exactly 29 staged fields, got {len(STAGED_FIELDS)}"
+ def test_exactly_31_staged_fields_registered(self) -> None:
+ # 17 from #808 initial, 3 from #761, 9 Group B knobs and 2 RL checkpoint flags (#808).
+ assert len(STAGED_FIELDS) == 31, (
+ f"Expected exactly 31 staged fields, got {len(STAGED_FIELDS)}"
)
@pytest.mark.parametrize(
@@ -165,6 +165,8 @@ class TestStagedFieldsInventory:
("data", "resize_vocab", True),
("data", "extend_conversation", True),
("data", "skip_prepare_dataset", True),
+ ("training", "rl_checkpoint_include_ref_model", True),
+ ("training", "rl_checkpoint_include_rollout_buffer", True),
],
)
def test_each_staged_field_detected_when_non_default(
@@ -242,6 +244,15 @@ class TestStagedFieldsInventory:
assert found[0].path == "training.staged_dummy"
assert found[0].value == 999
+ @pytest.mark.parametrize(
+ "name", ["rl_checkpoint_include_ref_model", "rl_checkpoint_include_rollout_buffer"]
+ )
+ def test_the_staged_rl_checkpoint_flags_say_nothing_is_saved(self, name: str) -> None:
+ """The descriptions must not drift back to claiming the state is saved (#808)."""
+ from soup_cli.config.schema import TrainingConfig
+
+ assert "Not saved yet" in TrainingConfig.model_fields[name].description
+
class TestLoaderStagedFieldIntegration:
"""Test loader behavior under warning vs error severity."""
diff --git a/tests/test_rl_checkpoint_manifest.py b/tests/test_rl_checkpoint_manifest.py
new file mode 100644
index 00000000..8c32f810
--- /dev/null
+++ b/tests/test_rl_checkpoint_manifest.py
@@ -0,0 +1,121 @@
+"""The RL checkpoint manifest reports what a save wrote (#808, item 2).
+
+`training.rl_checkpoint_include_ref_model` and
+`training.rl_checkpoint_include_rollout_buffer` are accepted, but no save
+writes reference-model or rollout-buffer state. The manifest used to copy both
+flags from the config, so a checkpoint holding only the adapter and the
+optimizer claimed `has_ref_model: true, has_rollout_buffer: true`.
+"""
+
+from __future__ import annotations
+
+import json
+import os
+
+import pytest
+
+
+def _optimizer():
+ import torch
+
+ model = torch.nn.Linear(4, 2)
+ opt = torch.optim.AdamW(model.parameters(), lr=1e-3)
+ model(torch.randn(3, 4)).sum().backward()
+ opt.step()
+ return opt
+
+
+def _save(tcfg, optimizer):
+ """Build the callback the trainers build from a `training:` block, and save once."""
+ from soup_cli.utils.peft_wiring import _build_rl_checkpoint_cb
+
+ cb = _build_rl_checkpoint_cb(tcfg, output_dir="run", task="grpo")
+ ckpt_dir = cb.save_checkpoint(step=1, model=None, optimizer=optimizer)
+ with open(os.path.join(ckpt_dir, "manifest.json"), encoding="utf-8") as fh:
+ return sorted(os.listdir(ckpt_dir)), json.load(fh)
+
+
+def cwd(tmp_path, monkeypatch):
+ monkeypatch.chdir(tmp_path) # the checkpoint root must stay under cwd
+ return tmp_path
+
+
+def test_both_flags_true_save_neither_state_and_the_manifest_says_so(cwd):
+ from soup_cli.config.schema import TrainingConfig
+
+ tcfg = TrainingConfig(
+ rl_checkpoint_save_every_steps=1,
+ rl_checkpoint_include_ref_model=True,
+ rl_checkpoint_include_rollout_buffer=True,
+ )
+
+ files, manifest = _save(tcfg, _optimizer())
+
+ assert files == ["manifest.json", "optimizer.pt"], files
+ assert manifest["has_ref_model"] is False, manifest
+ assert manifest["has_rollout_buffer"] is False, manifest
+
+
[email protected]("ref, buf", [(True, False), (False, True)])
+def test_each_flag_alone_is_reported_false_too(cwd, ref, buf):
+ from soup_cli.config.schema import TrainingConfig
+
+ tcfg = TrainingConfig(
+ rl_checkpoint_save_every_steps=1,
+ rl_checkpoint_include_ref_model=ref,
+ rl_checkpoint_include_rollout_buffer=buf,
+ )
+
+ _files, manifest = _save(tcfg, _optimizer())
+
+ assert (manifest["has_ref_model"], manifest["has_rollout_buffer"]) == (False, False)
+
+
+def test_has_optimizer_still_follows_the_optimizer_save(cwd):
+ """Control: the one flag that was already honest is unchanged."""
+ from soup_cli.config.schema import TrainingConfig
+
+ saved_files, saved = _save(
+ TrainingConfig(rl_checkpoint_save_every_steps=1), _optimizer()
+ )
+ assert "optimizer.pt" in saved_files
+ assert saved["has_optimizer"] is True
+
+ from soup_cli.utils.peft_wiring import _build_rl_checkpoint_cb
+
+ cb = _build_rl_checkpoint_cb(
+ TrainingConfig(
+ rl_checkpoint_save_every_steps=1, rl_checkpoint_include_optimizer=False
+ ),
+ output_dir="run-no-opt",
+ task="grpo",
+ )
+ ckpt_dir = cb.save_checkpoint(step=1, model=None, optimizer=_optimizer())
+ with open(os.path.join(ckpt_dir, "manifest.json"), encoding="utf-8") as fh:
+ manifest = json.load(fh)
+ assert "optimizer.pt" not in os.listdir(ckpt_dir)
+ assert manifest["has_optimizer"] is False
+
+
+
[email protected](("ref", "buf"), [(True, True), (True, False), (False, True)])
+def test_the_manifest_ignores_include_flags_set_on_the_callback_config(cwd, ref, buf):
+ """Set directly on RLCheckpointConfig, the flags still save nothing,
+ so the manifest says false."""
+ from soup_cli.utils.rl_checkpoint import RLCheckpointConfig, build_rl_checkpoint_callback
+
+ cfg = RLCheckpointConfig(
+ save_every_steps=1,
+ include_optimizer_state=True,
+ include_ref_model=ref,
+ include_rollout_buffer=buf,
+ )
+ cb = build_rl_checkpoint_callback(cfg, output_dir="run", task="grpo")
+ ckpt_dir = cb.save_checkpoint(step=1, model=None, optimizer=_optimizer())
+ with open(os.path.join(ckpt_dir, "manifest.json"), encoding="utf-8") as fh:
+ manifest = json.load(fh)
+ assert sorted(os.listdir(ckpt_dir)) == ["manifest.json", "optimizer.pt"]
+ assert manifest["has_ref_model"] is False
+ assert manifest["has_rollout_buffer"] is False
+ assert manifest["has_optimizer"] is True