Skip to content

feat(ppo): support non-colocated generation - #3262

Merged
yuki-97 merged 19 commits into
NVIDIA-NeMo:mainfrom
bg51717:feat/ppo-noncolocated-clean
Aug 6, 2026
Merged

yuki-97 merged 19 commits into
NVIDIA-NeMo:mainfrom
bg51717:feat/ppo-noncolocated-clean

Conversation

@bg51717

@bg51717 bg51717 commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

What does this PR do ?

Adds synchronous non-colocated PPO, with the policy and value model sharing a training cluster while vLLM generation runs on a separate inference cluster.

Design

The main changes are:

  • Create separate training and inference RayVirtualClusters when policy.generation.colocated.enabled=false.
  • Support both splitting GPUs on a single node and assigning complete nodes to generation in multi-node runs, with fail-fast validation for invalid resource configurations.
  • Initialize the cross-cluster collective used to transfer updated policy weights to vLLM after training.
  • Coordinate policy and value offloading so they can continue to time-share the training GPUs while generation remains resident on the inference GPUs.
  • Apply topology constraints to the training and inference clusters when cluster.segment_size is configured.
  • Keep the existing colocated PPO path supported and reject non-colocated SGLang explicitly because it does not provide the required cross-cluster refit path.
  • Align PPO's sequence-level train/generation logprob-error metrics and optional masking with the shared GRPO implementation, including an explicit error when filtering leaves no valid response tokens.
  • Add AutoModel and Megatron functional tests, 40-step convergence recipes, unit coverage, and PPO deployment documentation.

Related correctness fixes

  • Filtered-sample GAE semantics: Compute PPO advantages with token_mask * sample_mask, matching GRPO, so samples removed by overlong_filtering do not affect GAE or advantage normalization. When truncated samples are present, this changes the previous PPO advantage numerics even if the optional sequence-level threshold is disabled.
  • Reward-model resource detection for structured data configs: Collect env_name from every dict or list entry under data.train, data.validation, and data.default. Previously, list-shaped dataset configs were skipped, which could prevent PPO from reserving resources for an active reward-model environment.

Usage

Set policy.generation.colocated.enabled=false and reserve resources for vLLM generation:

policy:
  generation:
    backend: vllm
    colocated:
      enabled: false
      resources:
        gpus_per_node: 4
        num_nodes: null

For a single-node run, gpus_per_node reserves that many GPUs for generation on the node. For a multi-node run, generation uses complete nodes, so set num_nodes and keep gpus_per_node equal to cluster.gpus_per_node.

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you run the unit tests and functional tests locally? Visit our Testing Guide for how to run tests.
  • Did you add or update any necessary documentation? Visit our Document Development Guide for how to write, build and test the docs.

Test

The following test matrix passed:

  • Unit and regression tests passed for PPO masking and resource validation, shared async/GRPO compatibility, data/config parsing, checkpoint resolution, recipe validation, and Megatron value-worker coverage.
  • AutoModel functional tests: colocated and non-colocated PPO checks passed.
  • Megatron functional tests: colocated and non-colocated PPO checks passed, including critic warmup and sequence logprob-error masking.
  • AutoModel 40-step non-colocated E2E: step-40 reward 0.8408, validation accuracy 0.7500, median token probability error 1.0076, and median maximum sequence probability error 1.0261.
image
  • Megatron 40-step non-colocated E2E: step-40 reward 0.8467, validation accuracy 0.7383, median token probability error 1.0087, and median maximum sequence probability error 1.0270.
image

@bg51717
bg51717 requested review from a team as code owners July 17, 2026 09:18
@copy-pr-bot

copy-pr-bot Bot commented Jul 17, 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 Jul 17, 2026
@bg51717 bg51717 added the CI:L1 Run doctests, unit tests, and functional tests label Jul 17, 2026
@bg51717

bg51717 commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

/ok to test 4fe31a4

@bg51717

bg51717 commented Jul 17, 2026 •

Copy link
Copy Markdown
Member Author

/ok to test 5910124

@bg51717 bg51717 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 Jul 17, 2026
@bg51717

bg51717 commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

/ok to test 5910124

@bg51717

bg51717 commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

/ok to test 6767e6d

@bg51717 bg51717 mentioned this pull request Jul 29, 2026
4 tasks done

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

Overall LGTM on the non-colocated surface after auditing offload/onload sequencing and node allocation against the GRPO reference on main.

Offload/onload — parity verified. All 3 refit sites (ppo.py:1163-1170 initial-val, 1227-1269 loop, 1574-1587 val-in-loop) correctly add an explicit if not colocated_inference: policy.offload_to_cpu() after refit_policy_generation returns, mirroring the fact that the shared refit helper intentionally skips policy offload in non-colocated mode (weights transfer via NCCL, vLLM stays resident). Value ↔ policy time-share the training GPUs via explicit finish_training / finish_inference boundaries — no double-resident window. Checkpoint save at ppo.py:1796-1831 does the same policy → save → offload → value → save dance.

Node allocation — parity verified. RayVirtualCluster construction, all 4 assert guards (train-gpus-per-node > 0, inference_nodes explicit for multi-node, gpus_per_node full-node for multi-node, nodes_per_instance divisibility), and cluster.segment_size handling all mirror grpo.py on main, with two intentional PPO-specific divergences:

  1. max_colocated_worker_groups=2 on train_cluster — necessary since PPO hosts both policy and value_model worker groups on the same train cluster (GRPO has policy only, uses =1).
  2. required_nodes for the segment_size check uses train_nodes when shared-node non-colocated (single node hosts both train and inference), train_nodes + inference_nodes otherwise. Stricter-correct than GRPO's always-sum for the rare single-node + segment_size combo.

Comments below are the remaining findings.

Comment thread nemo_rl/algorithms/ppo.py Resolved
Comment thread tests/unit/algorithms/test_ppo.py Resolved
Comment thread tests/unit/algorithms/test_ppo.py Resolved
Comment thread nemo_rl/algorithms/ppo.py Resolved
Comment thread nemo_rl/data/datasets/utils.py Resolved
@bg51717
bg51717 force-pushed the feat/ppo-noncolocated-clean branch from 8689b05 to e4e64e8 Compare July 31, 2026 05:55
@bg51717

bg51717 commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

/ok to test e4e64e8

@bg51717

bg51717 commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

/ok to test 08c888c

@bg51717
bg51717 requested a review from yuki-97 July 31, 2026 07:46
@bg51717

bg51717 commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

/ok to test fbcfbe3

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

overall LGTM, just one small comment. @terrykong could you take a review as well?

Comment thread nemo_rl/algorithms/ppo.py Resolved
@bg51717

bg51717 commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

/ok to test 6f176b3

@anwithk anwithk mentioned this pull request Aug 4, 2026

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review at 6f176b3b4. Six agents (RL/domain, bug-finder, test, design, comment, adversarial) went over this.

All 7 prior review threads are fixed. I verified each against the code at head rather than on the replies — including that the four assert branches each hit their intended branch (not a sibling), and that the topology port-back in 6f176b3b4 is faithful to grpo.py:816-878. Replies are on the individual threads.

No correctness bug was found in the new non-colocated path. Three agents diffed it line-by-line against grpo.py: the GPU-resource arithmetic (including the reward-model x node-count boundaries), the policy/value offload coordination, and the token_mask * sample_mask change all came back clean — every mask consumer is consistent, with no sibling left on the old mask, and PPO is actually more consistent here than GRPO, which still uses bare token_loss_mask for its own response_advantages metric. The required_nodes shared-node refinement is a genuine improvement over grpo's version. Nice work; the five comments below are all low-severity.

Everything here is static analysis only. pre-commit and pytest could not be run (the lockfile supports Linux x86_64/aarch64 only and this review ran on macOS), so nothing below is a passing result and the suggested tests are syntax-checked, not executed.

Twelve candidate findings were dropped during the adversarial pass, several of which are worth naming so they don't get re-raised later:

  • A proposed .get() change to the seq_logprob_error_threshold read — PPO's bare subscript is convention-correct for a required TypedDict field, and .get(key, default) is the forbidden hidden-default pattern.
  • A suggestion to delete the unreachable trtllm/sglang branches in the topology block — those were added at a reviewer's explicit request in the previous round.
  • A gpu_memory_utilization: 0.4 concern, withdrawn once the right peer group was checked: 0.4 is what every 1.5B PPO recipe uses, colocated included, so the new recipes follow house style rather than diverging from it.
  • The new RuntimeError on a fully-masked batch: it does change PPO's prior behavior (previously a benign zero-gradient no-op — masked_mean divides by sum(mask) + 1e-8, so there was never a NaN), but firing it needs all 1024 samples in a step truncated simultaneously, and the 40-step runs on both recipes are empirical evidence it doesn't happen. Fail-loud there is a defensible choice.

Two design observations belong with the already-tracked #3464 rather than this PR, and I'll add them there: the non-colocated layout arithmetic is inlined in setup(), which is why ~450 of the 1043 new test lines are Ray mock scaffolding (a pure plan_noncolocated_layout(...) helper would make those validation tests ~3 lines each); and the post-refit policy.offload_to_cpu() is now a caller obligation duplicated at three sites.

Generated by Claude Code

Comment thread nemo_rl/algorithms/ppo.py Resolved
Comment thread nemo_rl/algorithms/ppo.py Resolved
Comment thread tests/unit/algorithms/test_ppo.py Resolved
Comment thread docs/guides/ppo.md Resolved
@bg51717

bg51717 commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

/ok to test f298610

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

LGTM, thanks @bg51717 !

@yuki-97
yuki-97 merged commit d4c0d4d into NVIDIA-NeMo:main Aug 6, 2026
81 checks passed
cspades pushed a commit to cspades/RL that referenced this pull request Aug 6, 2026
tianyi-zhang-02 added a commit to tianyi-zhang-02/RL that referenced this pull request Sep 12, 2026
…KL pairing

Sync PPO and sync GRPO both guard skip_reference_policy_logprobs_calculation
against a non-zero reference_policy_kl_penalty with a bare, message-less

    assert master_config.loss_fn.reference_policy_kl_penalty == 0

python -O removes it entirely, so the run proceeds to train against a KL term
whose reference logprobs were never computed. Even with asserts enabled, a
message-less one says nothing about which two settings conflict.

async_ppo_train already does this as an if + ValueError. This is the same
defect class yuki-97 raised on NVIDIA-NeMo#3262 ("assert backend == 'vllm' gets stripped
under python -O"), which was converted there but left in these two siblings.

Both now use the async form, verbatim, so the three read alike.

Tests run under python -O as well as normally, which is what separates this
from a cosmetic change: with the assert restored, both modes fail.

Signed-off-by: Tianyi Zhang <[email protected]>
Signed-off-by: Tianyi Zhang <[email protected]>
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.

3 participants