Skip to content

feat(forest): pad Forest rows once per training batch - #5379

Merged
yuki-97 merged 48 commits into
mainfrom
biguo/forest-step-padding
Dec 2, 2026
Merged

yuki-97 merged 48 commits into
mainfrom
biguo/forest-step-padding

Conversation

@bg51717

@bg51717 bg51717 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member
  • I, the PR author, have personally reviewed every line of this PR.

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_mask zeroed, 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.

  • Only behaviour. Per-group padding is removed. No new config key.
  • Checkpoints. A rollout snapshot taken mid-step keeps that step's pad copies, and resume deletes them before checking the replay inventory. Forest checkpoints saved before this change record the per-group row multiple (above 1 on almost any multi-GPU run), so resuming any of them, at a step boundary or mid-step, fails at startup with an error that says so; non-Forest checkpoints are unaffected.
  • Metric. forest_padding_rows reports 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:

Run Padding Rows trained Padding rows
Nightly (4 steps, resume at 2) per group 136 82 (60%)
Nightly (4 steps, resume at 2) per batch 56 9 (16%)
Same recipe, 40 steps per group 1520 791 (52%)
Same recipe, 40 steps per batch 680 108 (16%)
  • 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_error 1.020 for both.

  • Mean time per step over steps 2-40 of the two 40-step runs (seconds):

    Padding Step Generation (exposed) Training phases Policy training Value training
    per group 41.2 12.1 25.2 9.2 8.7
    per batch 32.4 11.3 17.1 4.7 6.5

    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

bg51717 and others added 30 commits November 3, 2026 07:13
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]>
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]>
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]>
@bg51717 bg51717 reopened this Nov 26, 2026
@bg51717

ghost commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

/ok to test 4ad63de

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 group and with step, 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

@terrykong terrykong removed the Documentation Improvements or additions to documentation label Nov 28, 2026
bg51717 added 2 commits November 29, 2026 05:11
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]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added complexity:high Large or cross-cutting change. Set by Autobot PR classify (skills/pr-classify) convergence-risk:high Likely to change training results. Set by Autobot PR classify (skills/pr-classify) proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify) proof:convergence Needs convergence proof (W&B runs). Set by Autobot PR classify (skills/pr-classify) proof:perf Needs performance proof. Set by Autobot PR classify (skills/pr-classify) labels Nov 30, 2026
bg51717 added 2 commits November 30, 2026 04:50
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]>
@bg51717

ghost commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

/ok to test 7c382d4

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_mask and 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_utils package 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

Comment thread nemo_rl/algorithms/single_controller.py Resolved
Comment thread docs/guides/context-compaction.md Resolved
Comment thread nemo_rl/algorithms/single_controller.py Resolved

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 --check passed.

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

bg51717 added 4 commits December 1, 2026 18:57
…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]>
@bg51717

ghost commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

/ok to test dbc971b

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_utils move — pad_forest_step_rows matches the old controller method, and nothing refers to the old module path or method name.
  • Checkpoint padding check — the execution_row_multiple parameter 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_utils move made unnecessary.
  • Module docstrings on the two new forest_utils files.
  • A TYPE_CHECKING import 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

@yuki-97
yuki-97 enabled auto-merge (squash) December 2, 2026 06:59
@yuki-97
yuki-97 merged commit 0be64f4 into main Dec 2, 2026
@yuki-97
yuki-97 deleted the biguo/forest-step-padding branch December 2, 2026 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) complexity:high Large or cross-cutting change. Set by Autobot PR classify (skills/pr-classify) convergence-risk:high Likely to change training results. Set by Autobot PR classify (skills/pr-classify) proof:convergence Needs convergence proof (W&B runs). Set by Autobot PR classify (skills/pr-classify) proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify) proof:perf Needs performance proof. Set by Autobot PR classify (skills/pr-classify)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants