Skip to content

feat(vllm): support generation-prefix cuts with multiple HTTP frontends - #5267

Merged
terrykong merged 2 commits into
mainfrom
amahishi/multi-frontend-prefix-cuts-5176
Nov 25, 2026
Merged

terrykong merged 2 commits into
mainfrom
amahishi/multi-frontend-prefix-cuts-5176

Conversation

@macandro96

@macandro96 macandro96 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What and why

Problem. #5074 added several vLLM HTTP frontends per worker (vllm_cfg.http_api_server_count > 1) but rejected them with prefix-level rollout recovery (rollout_recovery.target_level: prefix). All frontends accept from one shared socket, and a model call's decoding state lives only in the frontend that accepted its request. Gym sends one generation-cut request per backend per checkpoint, which reaches one frontend, so every call on the other frontends would regenerate after a restore.

Change. The frontend that Gym's cut reaches fans it out to the others and returns one merged receipt, as the Dynamo frontend already does across engines (EngineCutFanOut).

sequenceDiagram
    participant Gym
    participant C1 as child 1 (reached by Gym)
    participant Own as owner
    participant C2 as child 2
    Gym->>C1: POST /ng-control/v1/generation-cut (inventory)
    par one deadline for every frontend
        C1->>C1: run_cut(held_only=True)
    and
        C1->>Own: POST /generation-cut/frontend (inventory, deadline), loopback
        Own->>Own: run_cut(held_only=True)
        Own-->>C1: acks of the calls it holds
    and
        C1->>C2: POST /generation-cut/frontend (inventory, deadline), loopback
        C2->>C2: run_cut(held_only=True)
        C2-->>C1: acks of the calls it holds
    end
    C1->>C1: merge_cut_receipts (a call no frontend holds fails)
    C1-->>Gym: one GenerationCutReceipt
Loading
  • Loopback control port. With more than one frontend, each frontend also serves its app on 127.0.0.1:0. The owner collects every frontend's URL (children return theirs from start) and sends the list to all of them (peers). The port opens whenever http_api_server_count > 1, even with cuts off, because frontends start before setup_token_capture decides on cuts.
  • FrontendCutFanOut (generation_cut_route.py) runs this frontend's cut and POSTs the inventory and one wall-clock deadline to every peer's new /ng-control/v1/generation-cut/frontend route, which takes the same control bearer. A peer that errors or misses the deadline answers nothing, so its calls regenerate; the checkpoint never fails on it. It shares fan_out_cut with Dynamo's EngineCutFanOut: wait to one deadline, cancel and name late targets, merge in target order.
  • held_only. Every frontend gets the whole inventory. With run_cut(..., held_only=True), a frontend cuts only the calls it runs or has a finished record of, answers with an ack for each of them (cut, or a failure it logged itself) and says nothing about the rest. merge_cut_receipts, shared with Dynamo, prefers a cut ack over a failure for the same call, gives any call no frontend holds a failure ack, and logs one warning per cut naming the first few. A call that has not started decoding is held, so it does not trip that warning. Dynamo engines now pass held_only=True too, so they no longer warn once per call held by another engine.
  • Child frontends get every capture setting. The owner forwards all of setup_token_capture's keyword arguments to each child (media_family, the cut settings, the prefix batch limits). flush reaches the children, and the driver sums prefix counts per frontend (get_generation_prefix_counts_per_frontend). Restores need no coordination: any frontend reads the prefix from TQ.
  • Cost. Each frontend runs its own PrefixWritePipeline and, on a TransferQueue data plane, its own prefix-writer actor, which needs 1 free CPU on the generation node: N frontends use N writer CPUs per worker. Each frontend also looks up every inventory call, including the ones it does not hold.

A single frontend keeps the existing path: Gym's cut runs run_cut on it directly. No Gym change and no new config keys.

CI coverage. The L1 prefix-recovery run (L1_Functional_Tests_SingleController_3.sh, score-centering variant) now runs with http_api_server_count=2. Its snapshot selection requires a restored call that the other frontend cut, read from the fan-out's per-peer log line, so the test cannot pass with every call on one frontend.

Issues

Follows #5074. Supersedes #5261.

Convergence / perf / functionality proof

The earlier numbers were measured on the previous design and are removed.

  • Unit tests (all passing; ruff and pyrefly clean): test_vllm_token_capture_hosting.py, test_prefix_write_pipeline.py and test_prefix_writer_actor.py 205 passed; cut-route tests in test_vllm_generation.py 16 passed; test_vllm_multi_api.py and test_gym_prefix_recovery_parity.py 50 passed; test_vllm_captured_call_progress.py 19 passed; test_dynamo_vllm_adapter_capture.py 13 passed; test_dynamo_generation_cut.py 2 passed.
  • Functional (H100): the L1 run, grpo_async_gym_single_controller_prefix_recovery.sh with its score-centering overrides and http_api_server_count=2, passed in 447 s:
    • 8 calls restored from their prefix, one of them cut by the frontend Gym's cut did not reach;
    • generation logprobs bit-identical to the uninterrupted reference over 9,312 tokens;
    • no frontend late or failed, no call left uncut, and no "cannot cut completed model call" warnings.
  • Benchmark: Qwen3-1.7B on H100, one TP1 vLLM engine, one Gym backend, 32 prompts × 8 generations of long lists, a snapshot attempt every 3 s, one run per setting.
1 frontend 4 frontends
Cut wall time, snapshots that cut 70–136 calls 0.19–1.17 s 0.07–0.15 s
Each frontend's own share of a cut n/a 0.04–0.09 s
gym_parked_seconds, average of the four snapshots that cut the most calls 1.34 s 1.12 s
  • A second 4-frontend run, after the last change to how frontends answer, cut in 0.06–0.16 s except its first snapshot (0.78 s), with no merge warnings.
  • With 4 frontends, each held 15–43 of the calls in a cut, and a peer's answer took 0.05–0.15 s round trip.
  • Every call left uncut in either run had no generated tokens yet: the engine decodes at most 128 sequences at once, so no cut exceeds 128 calls.
  • With 4 frontends the cut takes at most 0.15 s of a 0.6–1.9 s pause, so most of gym_parked_seconds is Gym's prepare/commit and the TQ save, not the cut. The 1-frontend run's 1.17 s cut is one outlier; its other large cuts took 0.19–0.26 s.

Needs upstream changes

None

PR commands and CI
  • CI label, exactly one:
    • CI:Lfast: the default for most PRs. Runs a fast test subset.
    • CI:L1: dependency or container changes (pyproject.toml, uv.lock, Dockerfile) or broad core changes. Builds a new image and runs unit and functional tests.
    • CI:docs: docs-only changes. Runs doc tests only.
  • /ok to test <full-commit-sha>: start CI for that commit. Post again after each push.
  • /review: automated review comments. Add mode=strict for a stricter review, reset=true for a fresh full review.
  • /resolve-conflict: Autobot merges main into this PR and resolves the conflicts. PRs from forks must allow edits by maintainers.
  • Locally: /review-pr-team <pr-number> for a team review before you ask for human review.
  • Contributor guidelines

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Nov 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 Nov 17, 2026
@macandro96
macandro96 added this pull request to stack #5181 November 17, 2026 06:05
Base automatically changed from amahishi/pr4508-prefix-write-pipeline-actor to main November 21, 2026 08:57
@macandro96
macandro96 force-pushed the amahishi/multi-frontend-prefix-cuts-5176 branch from 955c92c to dd52a6e Compare November 22, 2026 03:06
@github-actions github-actions Bot added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Nov 22, 2026
@macandro96
macandro96 force-pushed the amahishi/multi-frontend-prefix-cuts-5176 branch from dd52a6e to 67c4c0c Compare November 22, 2026 03:31

@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 after the rebase onto main. The earlier comments are rewritten for this head.

This PR lets prefix-level rollout recovery run with several HTTP frontends. Gym's generation-cut call reaches one frontend, which runs the cut on its own calls, asks every other frontend over a loopback control port to do the same, and merges the answers into one receipt. The setup-time refusal for multiple frontends is gone, and each child frontend now gets the cut settings.

Thanks for moving the shared pieces into one module used by both the native frontends and Dynamo (merge_cut_receipts, durable_prefixes, local_deadline), for sharing the token check between both routes (_refusal), and for the late-frontend test. The earlier C3 (stalled peer frontend) is now covered by test_generation_cut_fan_out_merges_without_a_late_frontend.

  1. (C1) Child frontends never get media_family, so VLM capture with more than one frontend fails at setup; no test checks this dict.
  2. (C2) No CI run does prefix recovery with more than one frontend; add 2 HTTP servers to the existing L1 prefix-recovery run and make it prove another frontend restored a call.
  3. (C5) Each cut logs a false "cannot cut completed model call" warning for every call another frontend holds.
  4. (C6) The PR description still describes the earlier claims design and its benchmark numbers; rewrite it and rerun the numbers.
  5. (C7) One frontend slower than aiohttp's 300 s timeout fails the whole cut, because this copy of Dynamo's fan-out loop catches fewer errors; share one helper.

Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5267-many-frontends-cut.html

nemo-rl-review: kind=expert harness=claude-code/2.1.332 model=claude-opus-5-5 effort=medium review-pr-team=v3 reviewed=67c4c0c

macandro96 and others added 2 commits November 25, 2026 11:10
With http_api_server_count > 1, every frontend accepts from one shared
socket, and a model call's decoding state lives only in the frontend that
accepted its request. Gym's single cut call reached one frontend, which
could not cut the others' calls, so #5074 rejected prefix cuts there.

Cut across frontends the way the Dynamo frontend cuts across engines. Each
frontend also listens on a loopback control port. The frontend Gym's call
reaches runs FrontendCutFanOut: it runs its own run_cut and posts the
inventory, with one wall-clock deadline, to every other frontend's new
/ng-control/v1/generation-cut/frontend route. Each answers with the durable
acks of the calls it cut, and merge_cut_receipts fails any call no frontend
cut, so it regenerates after a restore. A frontend that does not answer by
the deadline claims nothing.

merge_cut_receipts and CUT_REPLY_MARGIN_S move from the Dynamo cut module
to generation_cut_route.py, beside new durable_prefixes and local_deadline
helpers that the Dynamo engine adapter now uses too.

The owner hands every frontend the others' control URLs after start-up,
forwards the cut settings and prefix write/read limits to children with
the capture command, and fans out obsolete-row flushes and per-frontend
prefix counts. Each frontend runs its own write pipeline and writer actor.
A single frontend keeps the existing cut path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
- Send child frontends every setup_token_capture keyword argument,
  including media_family, which a VLM capture needs; a test now checks
  the forwarded settings against the method's signature.
- Cut with held_only on every fan-out participant (HTTP frontends and
  Dynamo engines): each answers only for the calls it holds, cut or not,
  so frontends no longer warn about each other's calls. The merge
  prefers a cut ack, fails any call no engine holds, and warns once per
  cut about those calls only.
- Share one fan_out_cut between FrontendCutFanOut and Dynamo's
  EngineCutFanOut: one deadline, late targets named, merge in target
  order. A peer frontend's request no longer has aiohttp's 300 s timeout
  and catches any error, so one slow or failing frontend costs only its
  own calls instead of failing the whole cut.
- Log the calls each peer frontend cut. The L1 prefix-recovery run now
  uses two HTTP frontends, and its snapshot selection requires a
  restored call that the other frontend cut.
- Document the per-frontend prefix-writer actor's CPU cost.

Signed-off-by: Anish Mahishi <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@macandro96
macandro96 force-pushed the amahishi/multi-frontend-prefix-cuts-5176 branch from 67c4c0c to 1bdac8e Compare November 25, 2026 19:58
@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test 1bdac8e

@terrykong
terrykong enabled stacked auto-merge (squash) November 25, 2026 20:19
@terrykong
terrykong merged commit c18ac13 into main Nov 25, 2026
107 of 125 checks passed
@terrykong
terrykong deleted the amahishi/multi-frontend-prefix-cuts-5176 branch November 25, 2026 22:58
shikicloud added a commit to shikicloud/RL that referenced this pull request Nov 26, 2026
main d040a22 brings NVIDIA-NeMo#4801 (Megatron prefill/decode behind Dynamo), which adds
its own disagg_layout.py with a subset of this branch's helpers, plus NVIDIA-NeMo#5267
(prefix counts per HTTP frontend) and NVIDIA-NeMo#5158 (multi-harness).

- disagg_layout.py: this branch's module, with main's replica_width_from and
  main's plan_engines (ValueError instead of assert, role-count check).
  validate_disagg_entrypoint lets megatron + dynamo through to its own checks.
- trtllm/config.py, trtllm_generation.py, grpo.py: keep the shared-module
  wrappers of this branch.
- vllm_generation.py: fan the per-frontend prefix counts out per engine.
- nemo_gym.py: pass both forward_session_id_as_conversation_id and
  multi_harness.

Signed-off-by: Shiki Wu <[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.

2 participants