Skip to content

Add DPRequestRouter and use it in generator - #3768

Merged
pzhan9 merged 1 commit into
pytorch:mainfrom
pzhan9:generator-dp-real-routing
Jun 26, 2026
Merged

pzhan9 merged 1 commit into
pytorch:mainfrom
pzhan9:generator-dp-real-routing

Conversation

@pzhan9

@pzhan9 pzhan9 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Note: the first 2 comments are submitted in it own PR in #3765. Review that first. For this PR, only review the commits after that.

This PR adds a DPRequestRouter, and use it in generator DP routing. It does a refactoring on generator_router.py, so the routing strategy classes, such as StickySessionRoutingStrategy can be shared.

TODO: Currently StickySessionRoutingStrategy will not re-route a sticky session even if the assigned DP or generator is overloaded. We should add a fail-over policy to address that. But that is not in the scope of this PR.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 24, 2026
@pzhan9
pzhan9 requested review from felipemello1 and tianyu-l June 24, 2026 15:59
else:
# TODO: investigate whether token length is the optimial property
# for load estimation.
estimated_cost = len(request.prompt_token_ids)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is it better to use request count here?

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.

request count sounds better, as prompt length only represents prefill work?

Related:
@yichuan-w also complained that by default combining group_id + sample_idx as routing session id makes it less efficient for prefix cache sharing. He said in reality every generator is saturated anyway. cc @felipemello1

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.

Sorry, i want to make sure i understand it. Is the complaint that we route based on the rollout, but not the group?

@tianyu-l tianyu-l Jun 25, 2026 •

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.

@felipemello1 correct. Context is that the task has many groups to rollout, so no worries on load imbalance (aka some generator idle)

@felipemello1 felipemello1 Jun 25, 2026 •

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 motivation to route on the rollout_id instead of the group_id is not to reduce generator idle time.

It is that the generator may be too busy to process ALL requests at once.

Say we have N=32, and the generator can process 31. Say that it takes T time to process one request on average. Now, this entire group will take 2*T to be processed, instead of T, because it has to process 31, and only then process the 32nd

Worse: say the generator can process 15 at a time. Now it will take 3T to finish all 32..

However, if we spread the requests, we have a better chance of making sure that all 32 are computed in parallel, and finish together -- no stragglers. Does this make sense?

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 generator can process 31

This is made up, right? Continuous batching would continuously process requests.

Also what we care is E2E time, which potentially includes many groups of N=32.

@felipemello1 felipemello1 Jun 25, 2026 •

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.

would continuously process requests.

We add the request, but vllm will compute based on capacity. We can add 1M requests. They wont be processed in parallel. In fact, if kvcache grows, inflight requests will be requeued to make room.

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.

thats what i mean by my example, say theres capacity for 31 -- the 32nd will stay in the queue

@felipemello1 felipemello1 Jun 25, 2026 •

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.

but, i mean, i am not dying on this hill. Its fine to change back to group and we can empirically check which is faster when we push for better perf.

@pzhan9 pzhan9 Jun 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this makes things too complicated:

we could add a fail-over parameter to StickySessionStrategy, and pass both group_id and rollout_id into it. Then:

  1. the strategy put requests with the same group_id into 1 generator/DP until that generator/DP hits the fail-over parameter. Then
  2. assign a new generator/DP.

The the strategy's dict's key will be (group_id, rollout_id).

Anyway, I think it might be helpful to have some data in production runs to see which direction we want to optimize for.

else:
# TODO: investigate whether token length is the optimial property
# for load estimation.
estimated_cost = len(request.prompt_token_ids)

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.

request count sounds better, as prompt length only represents prefill work?

Related:
@yichuan-w also complained that by default combining group_id + sample_idx as routing session id makes it less efficient for prefix cache sharing. He said in reality every generator is saturated anyway. cc @felipemello1

"""Caller-defined reserved load on this DP rank."""


class DPRequestRouter:

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.

nit on naming:

  • In GeneratorRouter, generator is routing candidate, where we are routing request.
  • In DPRequestRouter, request is what we route

Do you think we could rename to

  • InterGenerator(Request)Router
  • IntraGenerator(Request)Router

which also reflects our 2-layer routing design. Request is optional depending on how long you want it to be.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I used InterGeneratorRouter and IntraGeneratoRouter. It is a little long, but I think it reflects the 2-layer routing explicitly.

Comment thread torchtitan/experiments/rl/trainer.py Outdated
# Load is measured as in-flight request count (one unit per call).
routing_ctx=RoutingContext(
estimated_cost=len(prompt_token_ids),
estimated_cost=1,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

since we use request count for DP routing, maybe we should use request count for inter-generator routing too?

)
"""Parallelism configuration for the vLLM engine."""

dp_routing_strategy: RoutingStrategy.Config = field(

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.

should be part of RequestDispatcher.Config (or even IntraGeneratorRouter.Config, to be symmetric to InterGeneratorRouter), not Generator.Config

@pzhan9
pzhan9 force-pushed the generator-dp-real-routing branch from e2e1281 to 10c3bb8 Compare June 26, 2026 19:57
@pzhan9
pzhan9 merged commit 574502c into pytorch:main Jun 26, 2026
8 of 12 checks passed
@pzhan9
pzhan9 deleted the generator-dp-real-routing branch June 26, 2026 20:25
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.

3 participants