Repository navigation
feat(forest): train PPO on multi-row rollouts - #5047
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]>
bg51717
left a comment
There was a problem hiding this comment.
Claude self-review. The PPO path reuses the Forest structure well: one merged estimator guard (validate_forest_estimator), the complete-groups check now also applies to PPO, the policy and critic row multiple is computed once with an lcm in _forest_execution_row_multiple, and the policy and critic share the router checks (megatron_value_worker.py#L94-L97). The Megatron padding_mask use checks out against pinned Megatron-LM 3e95097b: expert-bias counts skip padded tokens (router.py#L908-L943), and an all-padding microbatch gives a zero z-loss and leaves the sign-based bias update unchanged (moe_utils.py#L182-L189, #L1263-L1280).
- (C1)
whiten_execution_paddingandnormalize_over: all_rowscan be set where they do nothing; reject them there. - (C2) The guide says PPO advantages count logical rollouts, and omits the
whole_batchrequirement and per-row GAE episodes. - (C3) Keep the deleted truncation / unsupported-features paragraph until #5068 edits it.
- (C4) Add the three new
token_capturekeys to the exemplar YAMLs. - (C5) Rename the critic's
validate_forest_execution_padding, since it sets the router-padding flag. - (C8) The new functional test never pads; switch it to step scope with critic MBS=2.
- (C9) Give the critic-loss check an upper bound.
- (C10) Add a pump test for step padding and its cleanup.
Please add to the PR body: padded rows and step time for step vs group scope from a functional run, and Forest PPO curves against the fab3ba82d reference.
Pre-existing, for a tracking issue rather than this PR: outside exclude_padding_from_router_stats, the Megatron critic never masks router padding while the policy does (megatron_policy_worker.py#L1141 vs megatron_value_worker.py#L617-L626).
Nothing was run locally (no GPU).
Generated by Claude Code
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]>
|
/ok to test 3f165aa |
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]>
|
/ok to test 3e65269 |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
The review found a regression in weighted non-Forest PPO advantages and a checkpoint-inventory validation gap. The remaining comments cover startup validation, documentation, required headers, and performance/convergence evidence.
The earlier fixes are present in the current source, including the legacy-entrypoint guards, detailed PPO documentation, and train-pump padding cleanup coverage.
All 35 changed files and their directly affected paths received source inspection. Three review topics were delegated; one completed child's report was unavailable, so I inspected that topic directly. Validation is source-only: tests, lint, and CI were not run, and the mounted Megatron/Gym submodule directories are empty. The reported GB200 results were not independently verified. Suggested changes and proposed checks below need verification before adoption.
Generated by Claude Code
Note: formal approval is not available for this request, so this review is posted as a comment only.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
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]>
yuki-97
left a comment
There was a problem hiding this comment.
Thanks @bg51717 for resolving the previous round's comments and for splitting the two optional features out.
Scope: fix commits 0920a1c through e9ecd3e, and the full diff at that head.
Checked:
- Method checked against CompactionRL Section 4.2: the reward sits on each row's last trained token, no value bootstraps across rows and masked tokens are excluded; the cross-segment factor is the open item, https://arxiv.org/html/2607.05378v1
- GAE inputs, whitening and the value loss use the same mask, so padding rows, filtered rollouts and tokens owned by another row get zero advantage and no critic target.
- Every unsupported Forest PPO combination (non-GAE estimator, split value training, Automodel critic, dynamic batching, interleaved PP, reward penalties) is rejected at the start of setup, and the critic's router check runs before any rollout.
- Each prompt group is padded to the least common multiple of the policy's and critic's requirements, so every chunk and the whole step divide evenly for both models; the multiple is saved in checkpoints and compared on resume.
Remaining comments are on:
- the critic LR schedule, which advances by the Forest row count
- docs that still require a zero drop budget on every PPO run
- the resume test's context-boundary check, which can fail at random
- the critic equivalence test, which does not go through the Forest PPO stage
- a result for the new nightly in its registered shape
- a follow-up issue for the cross-segment GAE factor
nit
- seven leftovers of step-scoped padding
- where
validate_forest_routerslives - folding the row-multiple helper into
forest_execution_row_multiple - two figure labels that still say one advantage per rollout
- the new recipe's logger names
- hard-wrapped sentences in the two new guide paragraphs
nemo-rl-review: kind=expert harness=claude-code/2.1.330 model=claude-fable-5-2 effort=medium review-pr-team=v2 reviewed=e9ecd3e
A Forest PPO step passes its row count as gbs, which includes padding and masked rows. The critic schedule is sized in configured-batch samples, so both train() and finish_train_step() now tick by value.train_global_batch_size and keep gbs for batching only. Signed-off-by: bg51717 <[email protected]>
Per-group padding already aligns every chunk to both models; split mode is rejected only because no test or run covers the per-chunk critic update. Signed-off-by: bg51717 <[email protected]>
…unction forest_execution_row_multiple now takes the master config and the DP sizes and returns the lcm of the policy's and, on PPO, the critic's row multiple, using a private per-consumer helper. Setup and the startup check share it, so the startup check follows logprob_passes_required for the policy instead of always requiring the logprob MBS, and the setup-side helper is gone. Signed-off-by: bg51717 <[email protected]>
A Forest PPO critic trains on the step's actual row count, so setup accepts a non-zero rollout drop budget there. The dynamic sampling section now gives the reason it covers GRPO only: SC rejects ppo.use_dynamic_sampling on every PPO run. Signed-off-by: bg51717 <[email protected]>
…me test Run 2 has only two steps, and a step exceeds eight valid rows only when a rollout reaches a context boundary, which is random. Run 1 already checks the same metric over ten steps. Signed-off-by: bg51717 <[email protected]>
…age stage The merged-row returns now come from _ppo_controller(...)._advantage_stage, so the test covers the per-row GAE routing for Forest PPO. The per-call layout still calls the estimator directly as the reference. Signed-off-by: bg51717 <[email protected]>
The logger block carried another recipe's log dir, W&B and MLflow names. grpo: null is removed because no file in the defaults chain sets grpo. Signed-off-by: bg51717 <[email protected]>
None changes behavior; inventory.py, restore.py, test_checkpoint_borrow_restore.py and test_advantage_stage.py leave the diff against main. Signed-off-by: bg51717 <[email protected]>
It is a pure check on a Megatron model and its helpers already live in common.py, so both workers import it from there and the critic no longer imports the policy worker module. Signed-off-by: bg51717 <[email protected]>
Both figure labels said one advantage per rollout, which holds only for GRPO. Signed-off-by: bg51717 <[email protected]>
Signed-off-by: bg51717 <[email protected]>
Signed-off-by: bg51717 <[email protected]>
|
/ok to test 56ea51d |
…nightly script Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: bg51717 <[email protected]>
|
/ok to test e2e4ce3 |
Conflicts with #5047 (forest PPO): the whole-batch critic call keeps both gbs and the privilege prefixes, and the nightly budget is 5534 GPU hours (base 5516 + the privileged nightly + the forest nightly). Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: fujial <[email protected]>
What and why
Lets Forest (multi-row context-compaction) training run PPO on the single controller. Forest was GRPO-only: a rollout whose history was compacted, or that ran independent sessions, trains as several physical rows that share one logical owner, and only the GRPO estimator handled those owners. This PR adds the PPO path. Defaults of existing runs are unchanged.
The Forest PPO training comes from Jiaqi Zeng's SWE PPO branch (fab3ba82d), moved onto main's Forest reconstruction (#4124) as config options.
Changes
ppo.value_training_mode=split.ppo-qwen3-0.6b-1n8g-megatron-gym-single-controller-forest): two steps with checkpoints, then resume to step 4 with the Forest, critic and checkpoint checks. The GRPO compaction resume test now runs the uninterrupted 10-step smoke with its reward and KL checks, then resumes to step 12.Two opt-in options moved out at review: one padding pass per training batch (#5379) and router statistics without execution padding (#5380). The optional
normalize_over,whiten_execution_paddingandforest_pad_sourcesettings are deferred and not part of this PR.Usage
Forest PPO supports Megatron with fixed batches or sequence packing, not dynamic batching or interleaved pipeline parallelism, the same as Forest GRPO.
Stack
#5068 (reward penalties) builds on this PR; #5126 (row selection), #5069 (row-scoped failure options) and #5127 (rewritten-history masking) build on #5068.
Issues
None.
Convergence / perf / functionality proof
Tests at
56ea51d29: the Forest PPO nightly test passes in its registered shape (1 node × 8 H100, all metric and checkpoint checks passed).Comparison of this PR's stack against fab3ba8 on a small Forest PPO run: Qwen3-4B on DAPO-Math through an OpenCode agent that delegates to a Task subagent, so each rollout trains as several Forest rows, with the critic and KL on. 50 steps on 4 nodes, one seed. The SWE recipe needs the follow-up PRs as well, so this side runs the combined branch.
Reward, critic loss, entropy and generation length match through step 30. After that the runs drift apart, mainly from how each side handles a continuation it cannot match to an earlier call: fab3ba8 rejects the whole rollout, while this branch trains it as a new row, so this branch keeps more multi-turn rollouts late in training. This recipe does not exercise compaction.
Needs upstream changes
None.