Skip to content

[rl] Move GenerationServer to torchtitan/rl/generator (9/14) - #5505

Closed
felipemello1 wants to merge 7 commits into
felipemello1/http/1-generator-drainfrom
felipemello1/http/2-move-generation-server
Closed

felipemello1 wants to merge 7 commits into
felipemello1/http/1-generator-drainfrom
felipemello1/http/2-move-generation-server

Conversation

@felipemello1

@felipemello1 felipemello1 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

TLDR: examples/verifiers/generation_server.py moves to generator/generation_server.py with no content change, and its imports follow. PR 10 serves it from each generator.

Stack (14 PRs, merge bottom-up; this PR is in bold)

PRs 2-7 don't need the HTTP design and can be reviewed now. PRs 8-14 wait on the design discussion on PRs 9 and 10.

# PR Independent? Needs (stack positions)
1 Verifiers 0.4.0 (merged) yes —
2 Verifiers: release each finished rollout's routing session yes — (resolves its test overlap with 1)
3 Verifiers generation server: no per-request access log yes —
4 Verifiers generation server: faster request path, required sampling params yes — (resolves its test overlap with 1-3)
5 Rollout workers write structured logs yes —
6 Drain in-flight rollouts during shutdown yes —
7 Rollouts that fail outside the policy are recorded, not trained no 2 (resolves its overlap with 4-6)
8 Generator drains itself before a hot_swap=False weight load yes —
9 Move GenerationServer to torchtitan/rl/generator yes, in code — (it moves the file 3 and 4 edit)
10 Every generate call goes over HTTP to its generator no 1, 2, 3, 4, 7, 8, 9
11 Generator aborts a request whose caller left no 10
12 Cancel a rollout group on its worker no 5, 6, 7, 10
13 Run Verifiers groups in rollout workers no 7, 10, 12
14 Optional native rollout timeout no 7, 13
torchtitan/rl/{examples/verifiers => generator}/generation_server.py   (rename, no content change)
imports updated: examples/verifiers/rollouter.py, examples/verifiers/README.md,
                 torchtitan_recipes/rl/verifiers_dapo_math.py, verifiers_terminal_bench.py,
                 tests/rl/unit_tests/cpu/test_verifiers.py

You may ask: why its own PR? Combined with PR 10's edits, the move is only 54% similar, just above git's 50% rename cutoff, so a later edit can turn it into a delete plus a new file. On its own it's a 100% rename, reviewed at a glance.

Test plan

pytest tests/rl/unit_tests/cpu   # verifiers 0.4.0, at this position (local, 11-04): 613 passed, 4 skipped (same as PR 8)

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 18, 2026
@felipemello1
felipemello1 added this pull request to stack #5508 October 18, 2026 22:49
@felipemello1
felipemello1 removed this pull request from stack #5508 October 18, 2026 23:25
@felipemello1
felipemello1 force-pushed the felipemello1/http/2-move-generation-server branch from aa0cdbc to d596a8e Compare October 18, 2026 23:31
@felipemello1
felipemello1 changed the base branch from felipemello1/http/base to felipemello1/http/1-generator-drain October 18, 2026 23:31
@felipemello1
felipemello1 added this pull request to stack #5513 October 18, 2026 23:32
@felipemello1
felipemello1 force-pushed the felipemello1/http/1-generator-drain branch from ba0dc0b to 3a10979 Compare October 19, 2026 00:37
@felipemello1
felipemello1 force-pushed the felipemello1/http/2-move-generation-server branch from d596a8e to c8a316a Compare October 19, 2026 00:38
@felipemello1
felipemello1 force-pushed the felipemello1/http/1-generator-drain branch from 3a10979 to 94f44ea Compare October 19, 2026 01:16
@felipemello1
felipemello1 force-pushed the felipemello1/http/2-move-generation-server branch from c8a316a to 5761d00 Compare October 19, 2026 01:16
@felipemello1
felipemello1 marked this pull request as ready for review October 19, 2026 03:20
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Oct 19, 2026
@felipemello1 felipemello1 changed the title [rl] Move GenerationServer to torchtitan/rl/generator (no behavior change) [rl] Move GenerationServer to torchtitan/rl/generator (8/14) Oct 19, 2026
@pzhan9

pzhan9 commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

This stack's GenerationServer related changes mix two separate decisions:

  1. change router from a reverse proxy to a look-aside load balancer.
  2. change the RollouterWorker to Generator path's from monarch messaging to HTTP, even for the native path (i.e. non-verifiers path).

Change 1 is a valid design, except the obvious trade-offs:

  • some small complexity on the client side for releasing the lease. (it could get worse quickly though, if we start to consider generator fault-tolerance, or try to integrate a generation stack with stock router).
  • the picked generator is pinned throughout the rollout session. We lose the ability to pick a different generator in the middle of the rollout session, e.g. for load re-balancing, or failover.
    • this potentially is a deal break when we run jobs at scale.

Change 2 makes sense for Verifiers but is unnecessary for the native path, and it makes the code more convoluted. It should be an easy fix to make the HTTP path opt-in only for the verifier path. Or more generically speaking, for path that needs an HTTP endpoint of the generation stack.

Nevertheless, before we commit to the look-aside pattern, I think we should look into the following choice first, and at least demonstrate it is not working, since that would be a much smaller change:

  • Move the HTTP server to the router, it is off the controller's GIL.
  • Forward opaque bytes inside the router, so there is no repeated serialization inside router.

This is how the topology would look like:

  Verifiers agent --HTTP--> router (only HTTP server, loopback on controller host)
  native worker   --Monarch: router.generate(...)--> router
  router --Monarch: generate_raw(body: bytes) -> bytes--> generator rank 0

No generator hosts an HTTP server: no aiohttp, sockets, ports or URLs on generators.

I like the reverse proxy because it hides the whole generation stack behind the router, which makes it easier to extend:

  • We keep rebalancing and failover mid-rollout.
  • Elasticity becomes a router (and launcher) change.
  • Swapping in a stock vLLM/sglang stack needs mostly router changes, not rollouter/controller changes (not saying we should integrate stock vllm/sglang. Just using them as an example to show the extensibility).

With lookaside, each of these is coupled to the clients.

The trade-offs of using reverse proxy over lookaside are:

  1. Router only has 1 GIL. Fixable with a router mesh, e.g. sharded by session id.
  2. One extra hop each way for the payload (in the current code, extra kernel copies). Fixable, e.g. with RDMABuffer, as on the trainer path.

Depending on the workload or complexity, this is where lookaside might win.

@felipemello1
felipemello1 force-pushed the felipemello1/http/2-move-generation-server branch from 5761d00 to efa6953 Compare October 22, 2026 23:31
@felipemello1
felipemello1 force-pushed the felipemello1/http/1-generator-drain branch from 052cb87 to ca5281f Compare October 23, 2026 07:34
@felipemello1
felipemello1 force-pushed the felipemello1/http/2-move-generation-server branch from efa6953 to dbc8b18 Compare October 23, 2026 07:34

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

motivation is clear but approach needs to be discussed

@felipemello1
felipemello1 removed this pull request from stack #5513 October 27, 2026 14:27
@felipemello1
felipemello1 force-pushed the felipemello1/http/1-generator-drain branch from ca5281f to 8da6b9d Compare October 27, 2026 14:30
@felipemello1
felipemello1 force-pushed the felipemello1/http/2-move-generation-server branch from dbc8b18 to 51ddd7c Compare October 27, 2026 14:31
@felipemello1 felipemello1 changed the title [rl] Move GenerationServer to torchtitan/rl/generator (8/14) [rl] Move GenerationServer to torchtitan/rl/generator (9/14) Oct 27, 2026
@felipemello1
felipemello1 added this pull request to stack #5639 October 27, 2026 14:33
@felipemello1
felipemello1 marked this pull request as draft November 3, 2026 16:16
@pytorch-bot pytorch-bot Bot removed the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Nov 3, 2026
@felipemello1
felipemello1 force-pushed the felipemello1/http/1-generator-drain branch from 8da6b9d to bd9bd75 Compare November 5, 2026 00:36
@felipemello1
felipemello1 force-pushed the felipemello1/http/2-move-generation-server branch from 51ddd7c to 49739f6 Compare November 5, 2026 00:37
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: Superseded. This move only prepared #5506, which is closing too: #5990 removes the router hop with look-aside routing, and the #5520 -> #5876 stack runs Verifiers groups in the rollout workers without HTTP generation, with GenerationServer staying in examples/verifiers/. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl 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