Skip to content

feat(forest): add opt-in row-scoped failure and whitening options - #5069

Open
bg51717 wants to merge 70 commits into
mainfrom
biguo/forest-ppo-parity
Open

bg51717 wants to merge 70 commits into
mainfrom
biguo/forest-ppo-parity

Conversation

@bg51717

@bg51717 bg51717 commented Nov 4, 2026 •

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

What and why

Under Forest training, one failed segment masks the whole logical rollout, and GAE whitening runs only over rows that train. Jiaqi Zeng's SWE PPO branch (fab3ba82d) behaves differently in these cases. This PR adds them as opt-in options; every default keeps current behaviour.

  • token_capture.forest.owner_failure_scope: row: a failed segment masks only its own row, unless it holds the scored call. Sequence-logprob and overlong filtering mask each failing row alone, the scored row included. Default owner masks the whole rollout.
  • token_capture.forest.mask_retried_roots: true: masks a root that was never continued when a continued root started from the same prompt tokens (a retried first request). The masked root carries no loss, and its token checks do not count toward the penalty.
  • ppo.adv_estimator.normalize_over: all_rows (PPO only): GAE and whitening also run over real rows masked from the loss; those rows still never train, and execution padding stays out. Requires name: gae and normalize_advantages: true; the legacy run_ppo.py rejects it. Default kept_rows.
token_capture:
  forest:
    enabled: true
    owner_failure_scope: row
    mask_retried_roots: true
ppo:
  adv_estimator:
    normalize_over: all_rows

Stacked on #5167.

Issues

Follow-up to #5047.

Convergence / perf / functionality proof

N/A: opt-in options whose defaults leave current runs unchanged.

Unit tests on GB200 at 2148a4db0: default lane 3688 passed, NeMo-Gym lane 970 passed.

Needs upstream changes

None

bg51717 and others added 7 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]>
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]>
Add opt-in options for training independent sessions such as subagents
as their own rows. Defaults are unchanged.

- selection_policy: continued_chains. The scored chain (its ancestors
  only), then one continued chain per other root in admission order.
  Ambiguous forks and byte-identical retries are dropped, and calls that
  did not finish trainably end a chain instead of poisoning the owner.
- token_capture.max_rows_per_rollout: keep the scored root plus the
  first N-1 other selected roots.
- token_capture.owner_failure_scope: row. A failed segment, or one that
  fails sequence-logprob filtering, is masked alone unless it holds the
  scored call.
- token_capture.invalid_group_policy: placeholder. A group whose
  rollouts all failed publishes masked single-token rows instead of
  being dropped.
- token_capture.mask_retried_roots. Mask an uncontinued root whose
  prompt tokens also started a continued root.
- token_capture.invalidate_rewritten_history. When a later call carries
  assistant history that matches no captured call, the vLLM worker
  serves it but fails its capture, masking the rollout instead of
  training earlier generations as prompt. Megatron generation rejects
  the option.
- token_capture.unserved_call_failure: ignore treats a call that served
  no completion as never made, instead of masking the whole rollout.
- token_capture.forest_truncation_scope: row marks only rows that fill
  max_seq_len as truncated, instead of every row of a rollout with any
  length stop.

With row scope or mask_retried_roots, rows the finalizer masks inside a
valid owner no longer decide that owner's validity in the advantage
stage; otherwise any masked row still voids its owner.

When no witness attributes the scored response and the harness declares
no terminal, continued_chains and all_captured take the terminal from
Gym's select_terminal_call. If that is ambiguous, or a declared terminal
is not attributable, the owner is masked (terminal_not_identified)
instead of failing the rollout. finalize/terminal_selection_* reports
witness vs heuristic.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: bg51717 <[email protected]>
@bg51717 bg51717 added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Nov 4, 2026
@copy-pr-bot

copy-pr-bot Bot commented Nov 4, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Nov 4, 2026
bg51717 and others added 9 commits November 4, 2026 17:11
# Conflicts:
#	nemo_rl/environments/nemo_gym.py
The actor reads max_rows_per_rollout and unserved_call_failure under Forest,
and Forest receipts record the stage that named the scored call.

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]>
@terrykong terrykong added CI:L1 Run doctests, unit tests, and functional tests CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) CI:L1 Run doctests, unit tests, and functional tests labels Nov 5, 2026
bg51717 and others added 4 commits November 7, 2026 22:32
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]>
Also drops a default-value assertion and a pydantic readback from the Forest
config tests.

Signed-off-by: bg51717 <[email protected]>
…l-rows

The Forest keys moved into token_capture.forest in #5068, so
max_rows_per_rollout moves there too, as forest.max_rows_per_rollout, and its
"requires forest_training" check goes away with the others.

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]>
With max_rows_per_rollout and penalty_scope: all_segments, the cap removed
rows before finalization, so their unwanted tokens or malformed think tags
never reached the owner's reward. Under all_segments with a token penalty,
dropped rows are now finalized and checked too, and one that fails
verification masks the owner. The cap also keeps its rows in planning order
instead of moving the scored row first.

Adds finalize/segments_dropped_by_cap and
finalize/terminal_not_identified_rollouts, and corrects the terminal
fallback docs: with several continued roots the heuristic follows the
earliest-admitted one.

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]>
…arity

Restacks the row-scoped failure options on #5167. Files this branch changed
take #5167's version here; the options that stay (owner_failure_scope,
mask_retried_roots) and normalize_over are re-added under the token_capture.forest
block in the following commits. forest_truncation_scope, invalid_group_policy
and unserved_call_failure are dropped.

Signed-off-by: bg51717 <[email protected]>
token_capture.forest.owner_failure_scope: row masks a failed segment alone
unless it holds the scored call; sequence-logprob and overlong filtering then
mask each failing row alone. token_capture.forest.mask_retried_roots masks an
uncontinued root whose prompt also started a continued root (a retried first
request). Both default to the current behaviour. A dropped row that fails
verification under #5167's cap check still masks the owner.

Signed-off-by: bg51717 <[email protected]>
… loss

ppo.adv_estimator.normalize_over: all_rows runs GAE and whitens over every
real row's response tokens, including rows masked from the loss, which still
never train; Forest execution padding has no owner and stays out. The default
kept_rows keeps the current population. Requires name=gae and
normalize_advantages; the legacy PPO entrypoint rejects it.

Signed-off-by: bg51717 <[email protected]>
@bg51717 bg51717 changed the title feat(forest): add opt-in row-scoped failure options feat(forest): add opt-in row-scoped failure and whitening options Dec 1, 2026
@bg51717
bg51717 changed the base branch from biguo/forest-ppo-penalty to biguo/forest-ppo-terminal-rows December 1, 2026 13:08
@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:convergence Needs convergence proof (W&B runs). Set by Autobot PR classify (skills/pr-classify) labels Dec 1, 2026
… 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]>
…l-rows

main's #4968 took rollout recovery schema 9 for failure_kind, so the
Forest selection's max_rows_per_rollout moves to schema 10; ledgers before
10 load uncapped.

Signed-off-by: bg51717 <[email protected]>
…arity

Signed-off-by: bg51717 <[email protected]>

# Conflicts:
#	examples/run_ppo.py
#	nemo_rl/algorithms/single_controller_utils/logical_advantage.py
#	tests/unit/experience/test_selected_forest_boundaries.py
…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]>
@bg51717

bg51717 commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

/ok to test c2dcf7f

@bg51717
bg51717 marked this pull request as ready for review December 2, 2026 02:46
…inal-rows

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
#	nemo_rl/environments/nemo_gym.py
#	nemo_rl/experience/rollout_reassembler.py
#	tests/unit/environments/test_nemo_gym_episode_collection.py
#	tests/unit/environments/test_nemo_gym_utils.py
#	tests/unit/experience/test_selected_forest_boundaries.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
…into biguo/forest-ppo-parity

Signed-off-by: bg51717 <[email protected]>

# Conflicts:
#	docs/guides/context-compaction.md
#	tests/unit/single_controller/test_setup.py
@bg51717

bg51717 commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

/ok to test 2ab6e39

Base automatically changed from biguo/forest-ppo-terminal-rows to main December 4, 2026 07:54

This branch has not been deployed

No deployments
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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants