Skip to content

Make generator actor aware of DP rank layout - #3743

Merged
pzhan9 merged 2 commits into
pytorch:mainfrom
pzhan9:generator-dp
Jun 24, 2026
Merged

pzhan9 merged 2 commits into
pytorch:mainfrom
pzhan9:generator-dp

Conversation

@pzhan9

@pzhan9 pzhan9 commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Currently when generator's data_parallel_degree > 1, generator will simply send the same requests to all DP ranks to process, but only use the results from DP rank 0, and discard the results from other DP ranks. This PR changes that.

Specifically, it:

  • make each generator actor aware of its DP rank layout.
  • when rank 0 makes LoopDecision, it will assign requests by DP ranks in its requests_per_dp_rank field. And actors will only process requests belong to its own DP rank.
  • For now, rank 0 will assign all requests to DP rank 0. This will enable us to test whether our vllm integration supports splitting request among DP ranks.
    • In a future PR, will replace the "hardcode DP rank 0" with a routing logic.

When testing this PR, I encountered a vllm bug in its v2 model runner. Specifically,

So we have this disvergence:

To workaround, I switched the MOE model config to v1 runner. This PR also adds a field use_v2_model_runner to VLLMGenerator.Config to make the switch possible.

What does the bug break

Let us assume we have DP=2, TP=2, EP=4. The change of this PR will route all requests to DP0, which leads to a busy DP0, and idle DP1.

vllm has logic in place to accommodate the idle DP problem. In def has_unfinished_requests, when DP > 1, it does a all-reduce to check if any rank still has unfinished requests, if yes, the idle rank will execute a dummy batch. Executing the dummy batch means the idle DP rank will enters the collective in step().

Normally, the busy rank, i.e. DP0 should also enters the collective in step(). That is the whole point of the dummy batch. However, when DP0's total_num_scheduled_tokens == 0, in v2 runner, DP0 will return early, without entering the collective. That makes DP1's step() not having a pair from DP0. Furthermore, DP0 will move to its next iteration, which it will issue a different collective. DP0 and DP1's collective will collide, and we will see error like:

terminate called after throwing an instance of 'gloo::EnforceNotMet'
  what():  [enforce fail at /__w/pytorch/pytorch/third_party/gloo/gloo/transport/tcp/pair.cc:464] op.preamble.length <= op.nbytes. 8 vs 4. Received data size doesn't match expected size. Is there a distributed collective mismatch in your code?

Test plan

Note: the trunk is broken for the MOE configs. I had to patch locally with this change to workaround.

Run the rl_grpo_qwen3_30b_a3b_varlen config locally to verify it still works.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 23, 2026
@pzhan9
pzhan9 marked this pull request as draft June 23, 2026 00:51
@pzhan9
pzhan9 force-pushed the generator-dp branch 3 times, most recently from 38b235d to 2539076 Compare June 23, 2026 19:35
@pzhan9
pzhan9 marked this pull request as ready for review June 23, 2026 20:23
@pzhan9

pzhan9 commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor Author

@tianyu-l I added some additional changes to workaround a v2 model runner bug. I explain the bug briefly in the PR description. Please take a look at that first.

update: switched to v1 in #3749 to workaround the v2 model runner bug.

pzhan9 added a commit that referenced this pull request Jun 23, 2026
We do not need V2 model runner for now. On the other hand, v2 runner has
a bug which blocks it from being used with `DP>1` generator setup (see
the PR description in #3743).

As a result, switch back to V1.
@pzhan9
pzhan9 merged commit 395833a into pytorch:main Jun 24, 2026
9 of 12 checks passed
@pzhan9
pzhan9 deleted the generator-dp branch June 24, 2026 13:03
saforem2 added a commit to saforem2/torchtitan that referenced this pull request Jun 24, 2026
Merged upstream/main into ezpz (merge 2c0daba, no conflicts). The
single commit (pytorch#3743, generator DP rank layout) touches only
experiments/rl/; ezpz/rl doesn't fork upstream rl/actors/generator.py
so no replay needed. ezpz imports verified clean post-merge.
pzhan9 added a commit that referenced this pull request Jun 25, 2026
…ighest DP rank (#3765)

In #3743, generator was
changed so its rank 0 starts to route requests among its DP ranks. In
that PR, the routing was hardcoded to DP0.

In this PR, we change the hardcoded routing to the highest DP rank. The
main difference between the highest DP rank and DP0 is,
* rank 0 is on DP0. So when requests are processed by DP0, the results
are accessed by rank 0 locally.
* But if requests are processed by other DPs, rank 0 no long has local
access. Instead, the peer DPs need to send their results back to rank 0,
aka. "fan-in", so rank 0 can further process them, and return the final
responses back to controller.

In summary, this PR does 2 changes:
1. add the fan-in mechanism;
2. change the hardcoding to the highest DP rank, so we can verify the
fan-in works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants