Skip to content

fix(ppo): enable Automodel value dynamic batching with equivalence coverage - #3321

Merged
yuki-97 merged 10 commits into
mainfrom
test/dtensor-value-dynbatch-equivalence
Oct 29, 2026
Merged

yuki-97 merged 10 commits into
mainfrom
test/dtensor-value-dynbatch-equivalence

Conversation

@fujial-code

@fujial-code fujial-code commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Enables dynamic batching for the Automodel (DTensor/FSDP2) PPO value-model path and makes fresh Hugging Face value-head initialization deterministic across Ray value-worker launches.

Dynamic batching was temporarily disabled after #2953 reported a substantially higher critic loss at the beginning of training. The investigation found two separate concerns:

  1. The dynamic-batching OFF and ON comparisons initially used different randomly initialized regression heads. With pinned weights, the value training signal is equivalent.
  2. PPO seeds the controller process, but Automodel value models are constructed in separate Ray processes. A missing HF regression head was therefore initialized nondeterministically unless the PPO seed was passed to and applied inside each value worker before model construction.

Issues

Closes #2953

Summary of Changes

  • Remove the PPO setup assertion that rejected value.dynamic_batching.enabled=true with the Automodel value backend.
  • Pass the algorithm seed directly to the value-model runtime, and seed each Automodel value worker after distributed setup and before model construction so a missing HF regression head is initialized reproducibly.
  • Add pinned-weight train-forward equivalence coverage for:
    • TP=1 dynamic batching with DP=2.
    • TP=2 sequence parallelism plus dynamic batching.
    • Variable-length samples that force dynamic reordering and repacking across 64- and 128-token microbatches.
  • Add a fresh-initialization regression test that compares dynamic batching OFF and ON with TP=2 plus sequence parallelism without sharing a checkpoint.
  • Rename the Automodel PPO recipe and test driver to include -dynbatch, explicitly enable value dynamic batching in the recipe, and update the PPO guide and nightly manifest.

The Megatron value-model runtime behavior is unchanged.

What the equivalence tests cover

The pinned-weight test compares the deterministic value training signal across dynamic batching OFF and ON:

  • dynamic microbatch construction
  • variable-length sample sorting and repacking
  • value-model forward pass
  • temporal value right shift
  • PPO MSE value loss
  • global valid-token normalization
  • metric aggregation

It compares aggregated loss, values_mean, returns_mean, and residual_sq_mean. Metrics are reduced to microbatch-order-independent scalars because dynamic batching can change the number and ordering of microbatches. The test uses eval_mode=True so dropout masks do not confound the execution-path comparison.

The separate fresh-initialization test deliberately does not share weights. Matching valid-token values confirm that the PPO seed reaches both Ray value workers before the regression head is constructed, while the elementwise comparison also covers restoration to the original sample order on the value-inference path.

Validation

Ran a 100-step pinned PPO comparison with:

  • Model: Qwen2.5-1.5B-Instruct
  • Dataset: GSM8K
  • Value topology: TP=2 with sequence parallelism
  • Dynamic batching: OFF vs ON
  • Both runs resumed from the same checkpoint
  • Matched training configuration

Results:

  • train/critic/loss follows the same decay and convergence behavior.
  • train/reward follows the same learning trajectory.
  • Both runs reach approximately 0.90 reward by step 100.
  • No persistent dynamic-batching-specific critic-loss divergence is observed.

Remaining scope

The remaining vLLM 0.25 critic-fit and gradient-norm investigation is tracked in #3412 and is outside this PR. The comparison above deliberately uses the same checkpoint and matched configuration, so it isolates dynamic batching from value-head initialization.

Critic Loss

image

Reward

image

These results support removing the temporary Automodel value dynamic-batching guard.

@fujial-code
fujial-code requested review from a team as code owners July 23, 2026 08:48
@fujial-code
fujial-code requested a review from yuki-97 July 23, 2026 08:49
@copy-pr-bot

copy-pr-bot Bot commented Jul 23, 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.

@fujial-code fujial-code added CI Relating to CI CI:L1 Run doctests, unit tests, and functional tests labels Jul 23, 2026
@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test c9a8bcb

@fujial-code
fujial-code force-pushed the test/dtensor-value-dynbatch-equivalence branch from c9a8bcb to 64e7a82 Compare July 30, 2026 03:20
@github-actions github-actions Bot removed the CI Relating to CI label Jul 30, 2026
@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test db5cf5f

@copy-pr-bot

copy-pr-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

/ok to test db5cf5f

@fujial-code, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test db5cf5f

@copy-pr-bot

copy-pr-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

/ok to test db5cf5f

@fujial-code, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test 64e7a82

@yuki-97 yuki-97 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.

@fujial-code thanks for verifying and adding the tests.

besides one inline comment, according to our discussion offline, dynamic batching for dtensor PPO is fine (curve in the PR description), but the critic/loss in #2953 may be related to the random init weights of value model.

  1. could you update the PR description adding how you tested it to get the correct result? (I remember you saved a ckpt for test)
  2. file a new issue (or change the title & content of #2953) to track this, since the mismatch is not due to dynamic batching.
  3. for changing the threshold in nightly test, let's do it after we figure out the init weights things.

then I think there's no other block for this PR.

Comment thread nemo_rl/algorithms/ppo.py Resolved
@fujial-code
fujial-code requested review from a team as code owners August 5, 2026 08:48
@fujial-code
fujial-code force-pushed the test/dtensor-value-dynbatch-equivalence branch from e84b33c to c502f33 Compare August 6, 2026 03:53
@fujial-code fujial-code added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L1 Run doctests, unit tests, and functional tests labels Aug 6, 2026
@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test c502f33

@copy-pr-bot

copy-pr-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

/ok to test c502f33

@fujial-code, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test 4fed1ba

@fujial-code
fujial-code requested a review from a team as a code owner August 12, 2026 17:01
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Aug 12, 2026
@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test 1a9f496

@fujial-code fujial-code added CI:L1 Run doctests, unit tests, and functional tests and removed CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) labels Aug 18, 2026
@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test 10b73a0

@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test ab44ef9

@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test ee75aa1

@fujial-code
fujial-code force-pushed the test/dtensor-value-dynbatch-equivalence branch from ee75aa1 to 49bbca0 Compare October 18, 2026 17:51
@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test 49bbca0

@fujial-code
fujial-code force-pushed the test/dtensor-value-dynbatch-equivalence branch from 49bbca0 to e618cb5 Compare October 18, 2026 18:08
@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test e618cb5

@yuki-97 yuki-97 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, and CI is red at e618cb5 on 1 failure caused by this PR.

Tracking the #2953 critic-loss gap down to the unseeded value-head init rather than dynamic batching is a great find; this PR lifts the Automodel value dynamic-batching guard on that basis and seeds each Automodel value worker before model construction.

Thanks for posting the 100-step pinned OFF/ON comparison with the critic-loss and reward curves in the description: the two runs line up clearly. Thanks also for the extensive self-review.

Scope: the full PR, at e618cb5

Checked:

  • Previous review threads — all six fixes hold at the current head
  • Seed placement — set_seed runs before the meta-device build and initialize_model_weights, and the DTensor RNG tracker broadcasts rank 0's state, so the score head matches across shards
  • Value(...) call sites — every one in the repo passes seed except test_lm_value.py
  • Removed guard — DB + sequence packing, CP>1 and PP>1 are still rejected elsewhere, and no doc still calls Automodel value dynamic batching unsupported
  • New tests — all three Automodel value tests run and pass in L0_Unit_Tests_Automodel, none skipped

Remaining comments are on:

  • The test_lm_value.py call that misses the new required seed

PR title — please change "DTensor" to "Automodel" to match the rest of the repo.

Comment thread tests/test_suites/nightly.txt Resolved
Comment thread nemo_rl/models/value/lm_value.py Resolved
Comment thread nemo_rl/models/value/lm_value.py Resolved
@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test bd88c7a

@fujial-code fujial-code added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L1 Run doctests, unit tests, and functional tests labels Oct 28, 2026
@fujial-code
fujial-code force-pushed the test/dtensor-value-dynbatch-equivalence branch from bd88c7a to 01005ab Compare October 28, 2026 09:54
@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test 01005ab

@fujial-code

Copy link
Copy Markdown
Contributor Author

/ok to test 445a4e7

@yuki-97 yuki-97 changed the title fix(ppo): enable DTensor value dynamic batching with equivalence coverage fix(ppo): enable Automodel value dynamic batching with equivalence coverage Oct 29, 2026
@yuki-97
yuki-97 merged commit 6f6772f into main Oct 29, 2026
96 of 97 checks passed
@yuki-97
yuki-97 deleted the test/dtensor-value-dynbatch-equivalence branch October 29, 2026 09:33
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) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PPO DTensor value-head initialization is nondeterministic across Ray worker launches

2 participants