Repository navigation
feat(forest): pad Forest rows once per training batch - #5379
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]>
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]>
Signed-off-by: bg51717 <[email protected]>
Signed-off-by: bg51717 <[email protected]>
Signed-off-by: bg51717 <[email protected]>
Signed-off-by: bg51717 <[email protected]>
Remove token_capture.forest_padding_scope and its step mode: the controller's once-per-batch padding, the rollout snapshot's tolerance for step padding copies, the config, docs and tests. Forest groups keep padding themselves to the policy and critic row multiple. Signed-off-by: bg51717 <[email protected]>
Remove token_capture.exclude_padding_from_router_stats: the router_excluded_rows field the finalizer publishes, the policy and critic masks built from it, the critic's extra train fields, the config, docs and tests. Both models keep the Forest router check, which rejects routing that execution padding could perturb. Signed-off-by: bg51717 <[email protected]>
Signed-off-by: bg51717 <[email protected]>
…never shipped Signed-off-by: bg51717 <[email protected]>
Signed-off-by: bg51717 <[email protected]>
Signed-off-by: bg51717 <[email protected]>
Both PPO estimators now return zero advantages where the mask is zero, so the advantage stage no longer clears them a second time. Signed-off-by: bg51717 <[email protected]>
commented
Nov 26, 2026
|
/ok to test 4ad63de |
left a comment
There was a problem hiding this comment.
Merge blockers — please rebase on main; the PR is 17 commits behind and the "Check if PR branch is up to date" job allows at most 10.
Thanks for splitting step padding out of #5047 as requested. This PR adds token_capture.forest_padding_scope: step, which pads a Forest training batch once instead of padding every published group.
Thanks also for the extensive self-review: 14 threads, 13 of them fixed at this head.
Scope: only the files outside nemo_rl/ and config.py, at 4ad63de. I will continue the review after #5379 (comment) is resolved, since removing group changes several places.
Remaining comments are on:
- The nightly result with
groupand withstep, with the padding rows per step. - Making step padding the only behaviour and removing
group.
nemo-rl-review: kind=expert harness=claude-code/2.1.332 model=claude-fable-5-2 effort=medium review-pr-team=v3 reviewed=4ad63de
Remove token_capture.forest_padding_scope and per-group padding. Forest groups now publish only their owner segment rows, and the controller pads each training batch once to the policy and critic row multiple. The execution_row_multiple plumbing through RolloutManager, the reassembler actor and forest_row_ids is removed. Forest checkpoints record a row multiple of 1, so a checkpoint saved with per-group padding (multiple > 1) is rejected at resume by the existing padding-mismatch check. Signed-off-by: bg51717 <[email protected]>
Per-group padding reported finalize/execution_padding_rows; per-batch padding reported nothing. The step now logs forest_padding_rows, summed over the step's chunks. Tests cover two padded streaming chunks and the GRPO path. Signed-off-by: bg51717 <[email protected]>
The old message (saved=4, current=1) read like a config mismatch; per-group padded checkpoints cannot resume under any config. Signed-off-by: bg51717 <[email protected]>
commented
Dec 1, 2026
|
/ok to test 7c382d4 |
left a comment
There was a problem hiding this comment.
Merge blockers — please rebase on main and resolve conflicts.
Thanks for making per-batch padding the only behaviour and for posting the comparison of both padding modes in the description.
Scope: fix commits 387b25e through 7c382d4, checked against the open threads from the previous review, plus the nemo_rl/ changes that the previous review did not cover.
Checked:
- Removal of per-group padding —
forest_padding_scope, its check, the reassembler padder and the row multiple passed down to it have no reference left. - Old checkpoints — one saved with per-group padding is rejected at restore before any saved row is read.
- Padding copies — they have a zero
sample_maskand no owner, so they add no loss, reward vote or violation count, and the step cleanup clears them. - Comparison in the description — the row totals of both modes are multiples of 8, the row multiple of the recipe.
Remaining comments:
- A
forest_utilspackage for the Forest helpers, with the step padder moved into it. - A guide sentence that still says padding IDs are fixed before publication.
- The step time of the two padding modes.
nit
- A single-caller helper and an unused default in the replay inventory check.
- A condition that is always true in the checkpoint padding check, and the parameter behind it.
nemo-rl-review: kind=expert harness=claude-code/2.1.333 model=claude-fable-5-2 effort=medium review-pr-team=v3 reviewed=7c382d4
left a comment
There was a problem hiding this comment.
The branch still has merge conflicts; please resolve them and the existing review requests before merging. Approving the reviewed implementation at 7c382d4: no new correctness issue found in masking, normalization, chunk handling or checkpoint recovery.
Validation:
- 1,173 tests passed locally on CPU, plus 10 supplemental probes. Padding remains ownerless and masked; reward votes, PPO whitening and loss denominators exclude it. The probes confirmed loss/count/real-row-gradient parity and preservation of captured image tensors, geometry metadata and router-replay fields.
- Checkpoint tests exercised snapshot saving with buffered/training-owned rows and padding, replay-metadata loading, removal of temporary copies on restore, and rejection of missing rows, unrelated extras and incompatible old per-group-padded checkpoints.
- Full/streamed controller tests verified per-chunk row IDs, policy/critic inputs and cleanup. Split-loss probes use globally prepared advantages; they do not establish end-to-end streaming equivalence.
- Repository-pinned Ruff lint/import-order/format checks and
git diff --checkpassed.
Limits: local tests used --noconftest with CPU/fake storage or the NoOp data plane. Thirteen GPU/dependency cases were unavailable and three tests skipped. No independent GPU training, distributed reduction or production TQ transport test was run. The author's reported PPO save/resume run and 40-step comparisons were reviewed, not rerun. Existing MoE router-load/bias effects of padding remain applicable.
nemo-rl-review: kind=expert harness=codex/0.171.0-alpha.13 model=gpt-6-astra effort=high review-pr-team=v3 reviewed=7c382d4
…ding Signed-off-by: bg51717 <[email protected]> # Conflicts: # nemo_rl/algorithms/single_controller.py # nemo_rl/algorithms/single_controller_utils/setup.py # nemo_rl/data_plane/schema.py
…est_utils pad_forest_step_rows only needs the data-plane client, the checkpoint barrier and the row multiple, so it becomes a module-level function in the new nemo_rl/algorithms/forest_utils package, next to logical_advantage.py moved from single_controller_utils. Signed-off-by: bg51717 <[email protected]>
…se helper validate_forest_checkpoint_metadata derives the current row multiple from forest_training, since restore always passed 1 under Forest; the replay inventory folds its one-expression padding helper in and requires step_padding. The guide no longer says padding IDs are fixed before publication. Signed-off-by: bg51717 <[email protected]>
…critic fake Signed-off-by: bg51717 <[email protected]>
commented
Dec 2, 2026
|
/ok to test dbc971b |
left a comment
There was a problem hiding this comment.
Thanks for the fixes: the forest_utils package, the simpler checkpoint padding check and the timing in the description.
Scope: fix commits b61d792 through dbc971b, checked against the open threads from the previous review, plus a scan of the changed files for new issues.
Checked:
forest_utilsmove —pad_forest_step_rowsmatches the old controller method, and nothing refers to the old module path or method name.- Checkpoint padding check — the
execution_row_multipleparameter and its always-true condition are gone, and the unreachable test case is replaced. - Merge of main — both sides of each conflict are kept, and the infra-failure masking from main runs before the padding.
- Timing in the description — per-batch padding takes 32.4 s per step against 41.2 s, and 17.1 s against 25.2 s in the training phases.
nit
These do not block merging; they can be done in #5380.
- A deferred import and its comment that the
forest_utilsmove made unnecessary. - Module docstrings on the two new
forest_utilsfiles. - A
TYPE_CHECKINGimport where there is no import cycle.
nemo-rl-review: kind=expert harness=claude-code/2.1.334 model=claude-fable-5-2 effort=medium review-pr-team=v3 reviewed=dbc971b
What and why
Forest training (#5047) pads every published group up to the policy/critic row multiple. With few rollouts per group, most of the rows a step trains on can be padding.
This PR pads once per training batch instead: just before training, the controller pads the batch up to the row multiple. Pad rows copy the batch's last row under new sample IDs with
sample_maskzeroed, so they carry no loss and are left out of advantage whitening. When a step trains in chunks (streaming GRPO or PPO), each chunk is padded on its own.forest_padding_rowsreports the copies each step adds.Issues
Follow-up to #5047.
Convergence / perf / functionality proof
The Forest PPO nightly (
ppo-qwen3-0.6b-1n8g-megatron-gym-single-controller-forest), on GB200 as 2 nodes x 4 GPUs with the 1n8g layout. The comparison ran on the branch before per-group padding was removed, once with each padding mode, logging the rows trained per step and how many were padding:Both nightly runs pass their metric checks, and so does the nightly at the PR head (2 steps, then resume to 4).
Over 40 steps the two modes train alike: mean reward 0.119 for both, critic loss 0.057 / 0.058, policy loss -0.009 / -0.010,
token_mult_prob_error1.020 for both.Mean time per step over steps 2-40 of the two 40-step runs (seconds):
Training phases are logprobs, value inference, policy training and value training. The two runs drew different rollouts (729 vs 572 real rows), so per real row the training phases take about 1.38 s per group and 1.20 s per batch.
Unit tests on GB200 at the PR head: default lane 3748 passed, NeMo-Gym lane 908 passed (3 vLLM rollout tests on a rerun after a Hugging Face rate limit); Megatron lane 89 passed at
387b25e21.Needs upstream changes
None