Repository navigation
Conversation
Forest training was GRPO-only. A PPO run now runs GAE on every physical row with that row's own critic values; the logical owner still decides validity, so a filtered segment masks all of its owner's rows. - ppo.adv_estimator.normalize_over: kept_rows (default) or all_rows, which also whitens over rows masked from the loss. Execution padding never counts. - The critic takes every Forest row as one optimizer step. - Forest row padding covers the critic's DP and microbatch sizes too. - The complete-group check now runs on the PPO path as well. - Forest requires ppo.value_training_mode=whole_batch: its row padding covers the whole step, while split mode shards each chunk on its own. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
…tics Execution padding and failed owners' borrowed inputs run through the model, so with expert-bias updates enabled their tokens count toward the router's expert loads. Forest keeps counting them by default, as ordinary training does. token_capture.exclude_padding_from_router_stats opts into masking them. The finalizer publishes router_excluded_rows for Forest rows; the policy and a PPO critic then fetch it, and the Megatron microbatch builder gives those rows no router-visible tokens in the existing padding mask, packed or not. The critic also masks sequence-packing padding. Both workers check the mask only with the option on, and raise an error naming it when the model cannot honour it, such as an expert-bias MoE with HybridBlock chunkwise context parallelism. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
Forest pads every published group to the policy and critic row multiple. With one rollout per group, most rows a step trains on are then padding: a DP of 4 turns ~154 real rows into ~512. token_capture.forest_padding_scope: step pads each training batch once instead. Pad rows copy real rows under new sample IDs with no loss, borrowed-input tags, and router exclusion flags; token_capture.forest_pad_source picks row0 or cyclic copies. ppo.adv_estimator.whiten_execution_padding lets those copies join all_rows whitening. Defaults are unchanged. A rollout snapshot taken during a step accepts that step's padding copies (<sample_id>_padN) of replayed rows, and restore deletes them before checking the replay inventory. Full trainer checkpoints run after the step clears its padding and stay strict. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
SingleController PPO rejects a rollout-failure drop budget because the critic expected a full step. A Forest critic trains on the step's actual rows, so a short step fits and Forest PPO now accepts the budget. Streaming PPO selects chunks in multiples of whole prompt groups so the rows split evenly across the policy and critic data-parallel ranks. Forest groups vary in row count and execution padding already aligns each chunk to both models, so that alignment only held back ready groups, rejected some num_prompts_per_step values, and made the sampler raise once a dropped rollout shrank the step. Forest streaming PPO now selects any group count, as streaming GRPO does. With forest_padding_scope=step, each chunk is padded. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
Unit tests, as PPO counterparts of the Forest GRPO tests: - Full-batch PPO trains every segment row per epoch and the critic takes the step's rows (gbs = rows); streaming PPO steps the policy once and trains the critic on all chunks after the refit. - Invalid logical batches and all-invalid owners never train either model; a partial step trains the critic on the surviving rows. - Whole-owner overlong filtering; the GAE advantage stage is never sharded. - Forest PPO startup rejections, policy/critic padding validation order, checkpoint restore with a critic, the critic row multiple pinned in data-plane checkpoints, and value-loss equivalence across packing bins and segments. Functional tests, both in L1_Functional_Tests_SingleController_3: - ppo_async_gym_single_controller_context_compaction.sh: PPO (GAE, Megatron critic) on the context-compaction Forest rows, two steps with checkpoints, then a resume to step 4. Its config, examples/nemo_gym/ppo_qwen3_0_6b_single_controller.yaml, composes the PPO SingleController exemplar with the Gym GRPO config. - grpo_async_gym_single_controller_context_compaction_resume.sh: the same checkpoint/resume for Forest GRPO. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
Forest training rejected reward penalties. They now run on Forest owners: rollout-scoped text checks and token checks run once on the scored segment, and the owner's rows share the resulting reward. token_capture.forest_penalty_scope chooses which segments the token checks cover: scored_segment (default) or all_segments, where a hit in any segment zeroes the owner's reward. Penalty counts ride the scored row so the finalizer metrics count each owner once. Forest results keep scalar fields only, so the duplicated-reasoning and empty-final-answer checks run on the agent's scored response when Gym post-processes the receipt, and are passed to compute_reward_checks. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
…uo/forest-ppo-penalty
whiten_execution_padding only changes whitening under Forest step padding, normalize_over=all_rows only with normalize_advantages=true, and the legacy PPO entrypoint reads neither. Reject each of these at startup. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
…on note PPO advantages are per physical row, each row a GAE episode, and Forest PPO needs whole_batch critic training. Restore the truncation and unsupported-features paragraph, which also applies to PPO overlong filtering. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
…ler exemplars Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
…sets The critic's method also sets its router padding-mask flag, so call it configure_forest_router_padding; setup calls the policy's check and the critic's setup by their own names. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
…loss With every microbatch size 1 the run never padded. A critic microbatch of 2 and step-scope padding pad steps with an odd row count, in the checkpointed run and the resumed one. The critic-loss check gets an upper bound. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
Full-batch and streaming PPO: the padding copies reach the policy and the critic, the critic gbs counts them, and the step deletes them. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
Main moved rollout checkpointing into nemo_rl/algorithms/rollout_checkpointing (#5011). Step padding handling of the replay inventory check now lives in rollout_checkpointing.inventory.validate_replay_inventory, called from the restorer ("clear") and the snapshotter ("allow"). Forest's estimator check keeps main's new seq_logprob_error_in_loss rejection. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
The stage zeroed advantages outside the mask by multiplying with it, so a dataset loss weight of 0.5 scaled the stored advantage again on top of GAE and the loss. Zero the tokens outside the mask without rescaling the rest. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
The inventory exception for forest_padding_scope=step also applied to full trainer checkpoints, so an extra _pad row passed the save check and restore deleted it. A full checkpoint never owns a streamed step's rows, so gate the exception on a rollout snapshot on save and from_rollout_snapshot on restore. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
raw_reward reads neither normalize_over nor whiten_execution_padding, so setting them promised a whitening change that never happened. Fail at config validation instead. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
The PPO exemplar and three guide summaries said every logical rollout keeps one advantage, which only holds for GRPO. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
…uo/forest-ppo-penalty Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
- List token_capture.forest_penalty_scope in the single-controller exemplars. - Say text penalties read the scored response, not a segment. - Set scored_text_checks on both receipt paths and index it, so a missing key fails instead of silently recomputing. - Cover penalize_malformed_think_tag at Forest startup and pin once-per-owner penalty counts when two segments hit. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
Add token_capture.invalidate_rewritten_history (Forest only, vLLM generation). A later call whose history holds assistant output that matches no captured call is still served, but its capture fails, which masks the rollout, so earlier generations never train as prompt. A subagent's first call carries no assistant history and roots its segment as usual. Megatron generation rejects the option. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
bg51717
left a comment
There was a problem hiding this comment.
Claude self-review of the token_capture.invalidate_rewritten_history change.
The change is small and fits the existing code:
rewrites_historyis a pure predicate with its own parametrized unit test.- The flag survives shard restarts through
_TokenCaptureSetupwithout any change to the restart code. - Masking reuses the existing
fail_callpath. - The forest-only guard is one dict entry.
- A first call that carries few-shot assistant turns (
root_reason="first_call") is kept.
Comments:
- (C1) Add a test that
preprocess_chatpassesinvalidate=Trueto_begin_request_capture. - (C2) Move the Megatron rejection into
validate_settingsso a misconfigured run fails before any build. - (C3) Doc: say that with a compacting harness the flag masks every rollout that compacts.
- (C4) Not blocking: say in the doc which metric counts the masked rollouts.
Nothing was run locally for this review.
Generated by Claude Code
| monkeypatch.setattr( | ||
| VllmAsyncGenerationWorkerImpl, | ||
| "_invalidate_rewritten_history", | ||
| False, | ||
| raising=False, | ||
| ) |
There was a problem hiding this comment.
C1 · 1 action item (missing test).
TL;DR — No test checks that preprocess_chat passes invalidate=True to _begin_request_capture. If the flag were computed a few lines later, the option would silently do nothing and every test would still pass.
invalidate_capture is computed from Gym's admission (vllm_worker_async.py#L1292-L1295), and that has to happen before admission = decision.storage (#L1318). For a text root, decide_capture_input returns a fresh CaptureAdmission(mode="text") with no request_replay, so rewrites_history on the storage admission is always False. This test is the only one that runs preprocess_chat. It pins the flag to False and never reads the kwarg.
AI-1
Parametrize this test over the flag and the root reason, then assert the kwarg. HISTORY already contains an assistant turn, so the test's existing request_replay is enough for the True case. decide_capture_input does not read root_reason, so the current assertions still hold. This can't be a suggestion block because the edit also changes the decorator, the signature, the admission and the last line, and those are outside this hunk.
@pytest.mark.asyncio
+@pytest.mark.parametrize(
+ "enabled,root_reason,expected",
+ [
+ (False, None, False),
+ (True, None, False),
+ (False, "no_prefix_match", False),
+ (True, "no_prefix_match", True),
+ ],
+)
async def test_worker_managed_root_clears_untrusted_prefix_and_keeps_media_check(
- monkeypatch,
+ monkeypatch, enabled, root_reason, expected
):
@@
monkeypatch.setattr(
VllmAsyncGenerationWorkerImpl,
"_invalidate_rewritten_history",
- False,
+ enabled,
raising=False,
)
@@
request_replay=replay_context(HISTORY, render_digest="b" * 64),
+ root_reason=root_reason,
)
@@
assert begin.call_args.args[1] == [10, 11]
+ # Computed from Gym's admission, before decide_capture_input replaces it.
+ assert begin.call_args.kwargs["invalidate"] is expectedThere was a problem hiding this comment.
Fixed in c94ae67. Parametrized the test over the flag and the root reason; it now asserts the invalidate kwarg, which is True only with the flag on and a no_prefix_match root.
| if invalidate_rewritten_history: | ||
| raise NotImplementedError( | ||
| "token_capture.invalidate_rewritten_history requires vLLM generation" | ||
| ) |
There was a problem hiding this comment.
C2 · 1 action item (fail before any build).
TL;DR — Megatron rejects this flag in setup_token_capture, which runs only after the generation and the trainer are built. A misconfigured run therefore takes GPUs and loads the model before it fails.
setup_token_capture is called at setup.py#L2288, after both builds. The interface already has a hook for this kind of check (interfaces.py#L521-L526):
Backend-specific pure-config validation, run before any build.
Setup calls it at setup.py#L1661-L1662. Megatron's validate_settings already rejects other config this backend cannot honour.
AI-1
Move this check into MegatronGeneration.validate_settings, after the generation_fleet_health check:
if master_config.token_capture.invalidate_rewritten_history:
raise NotImplementedError(
"token_capture.invalidate_rewritten_history requires vLLM generation"
)Then make two test changes:
- Point
test_generation_setup_token_capture_rejects_rewritten_history_invalidationatvalidate_settings. - Add
token_capture=SimpleNamespace(invalidate_rewritten_history=False)to_master_config_for_megatron_validation, so the existingvalidate_settingstests keep passing.
This can't be a suggestion block because the change spans megatron_generation.py and two test files.
Context — no action. The top_logprobs check just above uses the same late pattern. That check predates this PR and is not part of this ask.
There was a problem hiding this comment.
Fixed in c94ae67. Moved the check into MegatronGeneration.validate_settings, so the run fails before any build; the test now calls validate_settings, and the mcore validation helper carries token_capture.
| `token_capture.invalidate_rewritten_history` (Forest only, vLLM generation; | ||
| default `false`): a later call whose history holds assistant output that matches | ||
| no captured call is still served, but its capture fails, which masks the | ||
| rollout. A subagent's first call holds no assistant output and roots its segment | ||
| as usual. |
There was a problem hiding this comment.
C3 · 1 action item (doc only).
TL;DR — With a harness that compacts its history, this flag masks every rollout that compacts. The doc does not say so.
When BrowseComp compacts (_compact_old_tool_messages, keep_rounds), it keeps the assistant and function-call items. Gym then roots the next call as no_prefix_match or non_user_suffix (sink.py#L365-L443), with those assistant items in request_replay. So rewrites_history returns True. simple_agent_with_compaction with the recency policy behaves the same way. The flag is off by default and no functional test turns it on, so this is a gap in the doc, not a bug.
AI-1
| `token_capture.invalidate_rewritten_history` (Forest only, vLLM generation; | |
| default `false`): a later call whose history holds assistant output that matches | |
| no captured call is still served, but its capture fails, which masks the | |
| rollout. A subagent's first call holds no assistant output and roots its segment | |
| as usual. | |
| `token_capture.invalidate_rewritten_history` (Forest only, vLLM generation; | |
| default `false`): a later call whose history holds assistant output that matches | |
| no captured call is still served, but its capture fails, which masks the | |
| rollout. A subagent's first call holds no assistant output and roots its segment | |
| as usual. With a compacting harness (BrowseComp `keep_rounds`, | |
| `simple_agent_with_compaction`) this masks every rollout that compacts, so | |
| enable it only for harnesses whose new roots are subagents. |
There was a problem hiding this comment.
Fixed in c94ae67. Added the compaction caveat to the guide as suggested.
| if state.invalidate: | ||
| coords = self.token_capture.fail_call(call, reason="rewritten_history") |
There was a problem hiding this comment.
C4 · 1 action item, not blocking (doc only).
TL;DR — Nobody can count the rollouts this flag masks. The rewritten_history reason goes only to a log line, and the metric mixes these rollouts with every other worker capture failure.
Gym's fail_call writes reason only to LOGGER.warning. external_capture.py#L279-L285 then records the generic WORKER_CAPTURE_FAILED_REASON. The reassembler puts that into the rollout_failed bucket (#L1064), so these masks land in finalize/capture_failure_reason_rollout_failed_count (#L1072) together with other worker failures. The missing-top-k fail_call just below has the same limit, and it predates this PR.
AI-1
In context-compaction.md#L242-L246, say which metric counts these masks. This can't be a suggestion block because the doc is a different file from this anchor. For example:
Masked rollouts count in `finalize/capture_failure_reason_rollout_failed_count`,
together with other worker capture failures.There was a problem hiding this comment.
Fixed in c94ae67. The guide now names finalize/capture_failure_reason_rollout_failed_count. A separate count needs Gym to carry the fail_call reason into the capture record, so that is left for a Gym follow-up.
- Reject invalidate_rewritten_history in MegatronGeneration.validate_settings, before any build. - Test that preprocess_chat passes invalidate from Gym's admission. - Doc: compacting harnesses mask every compacted rollout; name the metric. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
…actor test main's new actor test builds RolloutReassemblerActorConfig without the field this PR makes required. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
The only production caller passes the scored-response text checks, so the result parameter and its fallback are removed. Signed-off-by: bg51717 <[email protected]>
A response with contains_transitions holds lists of items, which the text checks read as items and raised AttributeError. scored_text_checks now flattens them with the helper call selection uses. Signed-off-by: bg51717 <[email protected]>
selection_policy and forest_penalty_scope sat beside forest_training in TokenCaptureConfig, so each Forest-only key needed its own "requires forest_training" check. The keys now live in a token_capture.forest block with an enabled/disabled pair, as forest.enabled, forest.selection_policy and forest.penalty_scope, and are inactive while it is disabled. The old token_capture.context_compaction, forest_training and selection_policy keys fail at startup with their new names. Signed-off-by: bg51717 <[email protected]>
The Forest PPO nightly now runs the empty-final-answer and unwanted-token penalties with forest.penalty_scope: all_segments, and checks that both rates are logged. Signed-off-by: bg51717 <[email protected]>
Rows in the replay buffer keep the reward rule they were finalized with, so resuming with a different token_capture.forest.penalty_scope mixed two rules without a warning. Data-plane checkpoints now record the scope, and restore rejects a mismatch; Forest checkpoints without the key read as scored_segment. Signed-off-by: bg51717 <[email protected]>
Also drops a default-value assertion and a pydantic readback from the Forest config tests. Signed-off-by: bg51717 <[email protected]>
Resume rejected a changed token_capture.forest.penalty_scope even with no token penalty on, where the scope changes nothing. The scope now lives in the capture reward settings and is recorded and compared only while the unwanted-token or malformed-think-tag penalty runs, like the other reward rules. Signed-off-by: bg51717 <[email protected]>
The Forest block readback only exercised pydantic's union choice, and both scope values ran the same startup check. The reward-penalty docs now say which spans Forest's token checks read. Signed-off-by: bg51717 <[email protected]>
The bootstrap fingerprint now reads token_capture.forest, which every real config has. Adds a check that the scope changes the fingerprint only while a token penalty runs. Signed-off-by: bg51717 <[email protected]>
…en-history Moves the option to token_capture.forest.invalidate_rewritten_history, as #5068 moved the other Forest keys. The vLLM worker now marks the call on its per-request capture state and fails its capture at the terminal write; the non-vLLM rejection moves to validate_single_controller_config. Signed-off-by: bg51717 <[email protected]>
…fan-out Signed-off-by: bg51717 <[email protected]>
… the code does The scored segment is token-checked up to the scored call under both penalty scopes; all_segments also checks every other segment in full. Name the new key for each moved Forest key, call all_captured a selection_policy value, and use token_capture.forest.enabled in the two replay-buffer errors about the current run. Signed-off-by: bg51717 <[email protected]>
Signed-off-by: bg51717 <[email protected]>
…en-history Signed-off-by: bg51717 <[email protected]>
…e check main's privileged-value validation still read the old token_capture.forest_training key, which no longer exists. Signed-off-by: bg51717 <[email protected]>
…en-history Signed-off-by: bg51717 <[email protected]>
|
/ok to test da88057 |
…itten-history Signed-off-by: bg51717 <[email protected]> # Conflicts: # docs/guides/context-compaction.md # docs/guides/grpo.md # examples/configs/grpo_math_1B_megatron_single_controller.yaml # examples/configs/ppo_math_1B_megatron_single_controller.yaml # nemo_rl/algorithms/rollout_checkpointing/restore.py # nemo_rl/algorithms/rollout_checkpointing/snapshots.py # nemo_rl/algorithms/single_controller_utils/config.py # nemo_rl/algorithms/single_controller_utils/setup.py # tests/unit/single_controller/test_checkpoint_borrow_restore.py # tests/unit/single_controller/test_checkpointing.py # tests/unit/single_controller/test_ppo_setup.py # tests/unit/single_controller/test_setup.py
|
/ok to test 62231bb |
What and why
Under Forest training, a later call whose assistant history matches no captured call (history rewritten, or its boundary cannot be verified) starts a new segment, so earlier generations can train as prompt. Jiaqi Zeng's SWE PPO branch (fab3ba82d) masks the rollout instead.
This PR adds
token_capture.forest.invalidate_rewritten_history(defaultfalse):finalize/capture_failure_reason_rollout_failed_countwith other worker capture failures.keep_rounds,simple_agent_with_compaction) it masks every rollout that compacts, so enable it only for harnesses whose new roots are subagents.Stacked on #5068.
Issues
Follow-up to #5047.
Convergence / perf / functionality proof
N/A: opt-in option whose default leaves current runs unchanged.
Unit tests on GB200: default lane 3672 passed and NeMo-Gym lane 928 passed at
48f4a3611;test_vllm_generation_restart.py(6 passed) andtest_megatron_generation.py(54 passed, 1 expected failure already marked on main) ata08067caf, which differs only in two test files.Needs upstream changes
None