Skip to content

Inference: Prevent the coordinator from choking at large concurrency - #6497

Open
sidsingh-nvidia wants to merge 2 commits into
NVIDIA:mainfrom
sidsingh-nvidia:siddharth/co-ordinator-fixes
Open

Inference: Prevent the coordinator from choking at large concurrency#6497
sidsingh-nvidia wants to merge 2 commits into
NVIDIA:mainfrom
sidsingh-nvidia:siddharth/co-ordinator-fixes

Conversation

@sidsingh-nvidia

@sidsingh-nvidia sidsingh-nvidia commented Aug 12, 2026

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

What does this PR do?

Splits the coordinator's ZMQ wire format into multipart frames: a small, constant-size metadata frame followed by opaque body frames. The coordinator unpacks and repacks only the metadata frame and forwards the bodies untouched.

Problem

The DP inference coordinator is a single serial event loop shared by every data-parallel rank and every frontend replica. Previously each message was one msgpack blob, so to do its job — read a header, read a request id, pick a rank — the coordinator had to unpack and repack the entire payload.

That payload is dominated by data the coordinator never looks at:

  • Inbound, the submission carries the full prompt.
  • Outbound, a finished request echoes the prompt back alongside the generated tokens, so the reply is larger than the submission that caused it.

The result is per-request coordinator CPU that scales with prompt length rather than with request count. At high concurrency with long prompts the serial loop saturates and becomes the bottleneck for every rank behind it.

Fix

Move everything the coordinator needs into frame 0 and leave the rest as opaque frames:

Message Frame 0 (metadata, decoded) Remaining frames (opaque, forwarded as-is)
SUBMIT_REQUEST [header, request_id, sampling_params] [prompt]
ENGINE_REPLY [header, [[request_id, detokenize], ...]] one frame per finished request
ENGINE_REPLY_PARTIAL [header, [request_id, ...]] one frame per partial

Issue tracking

Linked issue:

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added proper typing to my code Typing guidelines
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

Existing coordinator, client, streaming, engine, and prefix-caching-coordinator unit tests were updated to the new framing (5 test files).

Code review

Feel free to message or comment @NVIDIA/mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!

All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.

Step 1: Mark PR as "Ready for Review"

  1. When your PR is ready, click Ready for Review.
  2. An oncall reviewer is auto-assigned and expert reviewers are notified based on your changes.
    • Some PRs may jump straight to step 2. This is determined by .github/CODEOWNERS.

⚠️ Only mark as ready once merge-conflicts are resolved and the CI is passing.
Final Review might get declined if these requirements are not fulfilled.

Step 2: Final Review

For PRs that change megatron/core, once all expert reviewers have approved, the Final Review label is applied automatically and final reviewers are assigned.

For PRs outside megatron/core, this step is skipped.

Step 3: Approved

Once all required reviewers have approved, the Approved label is applied automatically.

Merge

Any member of mcore-engineers will be able to merge your PR.

@sidsingh-nvidia
sidsingh-nvidia requested review from a team as code owners August 12, 2026 21:22
@copy-pr-bot

copy-pr-bot Bot commented Aug 12, 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.

@svcnvidia-nemo-ci
svcnvidia-nemo-ci marked this pull request as draft August 12, 2026 21:22
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been automatically converted to draft because all PRs must start as drafts.

When you are ready for review, click Ready for Review to begin the review process. This will:

  1. Add the oncall reviewer (optional reviewer)
  2. Add required review teams based on your changes

See the contribution guide for more details.

@sidsingh-nvidia
sidsingh-nvidia force-pushed the siddharth/co-ordinator-fixes branch from 8082e93 to 570a137 Compare August 12, 2026 21:29
@sidsingh-nvidia
sidsingh-nvidia marked this pull request as ready for review August 19, 2026 20:58
@sidsingh-nvidia
sidsingh-nvidia force-pushed the siddharth/co-ordinator-fixes branch from 570a137 to 1e4999a Compare August 19, 2026 21:10
@sidsingh-nvidia
sidsingh-nvidia requested a review from wdykas August 19, 2026 21:15
@sidsingh-nvidia
sidsingh-nvidia force-pushed the siddharth/co-ordinator-fixes branch 5 times, most recently from 2d70fa8 to 2849a1c Compare August 19, 2026 21:57
…is metadata of constant size. This is the only thing that the coordinator needs to unpack/read and pack

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

Looks good from disag side

@santhnm2 santhnm2 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, but as a suggestion for a future PR: the design here is passing around lists of frames where frames are arbitrary packed bytes, which requires indexing of the frame list at certain indices and doesn't assign any semantic meaning to each value in the list. Would it make sense to have a wrapper class so we could refer to the header frame more explicitly?

@sidsingh-nvidia

sidsingh-nvidia commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@santhnm2 that's a fair critique. I can impose the following structure on all messages

  1. each message can only consist of two frames - [metadata, payload]
  2. metadata and payload will be dicts with bespoke keys for easy readabiity - this can remove seemingly arbitrary indexing.

@santhnm2

Copy link
Copy Markdown
Contributor

@santhnm2 that's a fair critique. I can impose the following structure on all messages

  1. each message can only consist of two frames - [metadata, payload]
  2. metadata and payload will be dicts with bespoke keys for easy readabiity - this can remove seemingly arbitrary indexing.

I think this makes sense. An even tighter contract might be a custom dataclass with metadata and payload fields, but that's a small design decision I'll defer to you

@wdykas

wdykas commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Since we wanna pack metadata and payload separately, we will have to separate them out prior to the send operation.

do you know what we are allowed to serialize with msg pack? I thought it was real stingy

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Final Review PR is in the "final review" stage label Aug 19, 2026
Addresses review feedback on NVIDIA#6497: the frame lists were passed around as
arbitrary packed bytes, indexed positionally at each site, with no semantic
meaning attached to any element.

A message's layout previously existed only as an unwritten agreement between a
packb site and an unpack site in another module -- `[header, request_id,
sampling_params]` matched by `_, request_id, sampling_params = metadata` three
files away. Nothing tied the two together, which is how a 5-field metadata frame
came to be read by a handler expecting 6.

Each message type is now declared once as a MessageSpec naming its metadata
fields and payload frames in wire order. pack and parse are both derived from
that declaration, so no frame index is written by hand and the two directions
cannot drift. Adding a field means editing one tuple.

The split between the two tuples is the contract that matters, and it is now
structural rather than prose: metadata_fields are decoded by the coordinator and
must be constant-size, payload_frames are forwarded untouched and may grow with
the prompt. Putting src_block_ids in one rather than the other is now a visible
review-time decision.

Batched engine replies keep a dedicated BatchedMessageSpec. They carry one
payload frame per finished request because the batch fans out to different
clients: collapsing it into a single frame would force the coordinator to decode
every reply just to find the boundaries, and a finished request echoes the
prompt back. Measured on a 50-reply batch with 2000-token prompts, that split
costs the coordinator 0.001 ms against 3.7 ms for a decode.

pack now asserts that a batch's entry count matches its frame count, so a
mismatch fails at the send rather than silently truncating the batch.

No wire-format change: every layout was verified to produce byte-identical
frames to the previous code.

Signed-off-by: Siddharth Singh <sidsingh@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

complexity: medium Final Review PR is in the "final review" stage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants