Skip to content

Inference: Move tokenizer to a separate thread and scale frontend replicas with DP-size - #6223

Open
sidsingh-nvidia wants to merge 7 commits into
NVIDIA:mainfrom
sidsingh-nvidia:siddharth/frontend-tokenize-thread
Open

Inference: Move tokenizer to a separate thread and scale frontend replicas with DP-size#6223
sidsingh-nvidia wants to merge 7 commits into
NVIDIA:mainfrom
sidsingh-nvidia:siddharth/frontend-tokenize-thread

Conversation

@sidsingh-nvidia

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

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

What does this PR do?

⚠️ For major changes (either in lines of code or in its impact), please make sure to first share a design doc with the team. If you're unsure what's the best way to do so, contact @NVIDIA/mcore-oncall.

Issue tracking

For PRs from open-source community contributors:

  • New features: a linked issue is required. Please open a feature request and reference it here before submitting the PR.
  • Small updates (bug fixes, minor improvements): a linked issue is recommended and will accelerate the PR review process.

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

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 3, 2026 20:42
@svcnvidia-nemo-ci
svcnvidia-nemo-ci marked this pull request as draft August 3, 2026 20:43
@github-actions

github-actions Bot commented Aug 3, 2026

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.

@copy-pr-bot

copy-pr-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

Comment thread tools/run_dynamic_text_generation_server.py Outdated

@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 % addressing @wdykas's comment

@sidsingh-nvidia
sidsingh-nvidia marked this pull request as ready for review August 6, 2026 20:38
@sidsingh-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 87dfbd8

@sidsingh-nvidia sidsingh-nvidia self-assigned this Aug 6, 2026
@sidsingh-nvidia
sidsingh-nvidia requested a review from wdykas August 6, 2026 21:13
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Final Review PR is in the "final review" stage label Aug 6, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added Approved All necessary approvals have been made and removed Final Review PR is in the "final review" stage labels Aug 11, 2026
@shanmugamr1992

shanmugamr1992 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

NeMo-RL functional tests

cluster: oci-hsg · image: nvcr.io/nvidian/nemo-rl:nightly · updated 2026-08-12 00:26 UTC

Exactly what was tested

Component Ref Commit
megatron-core #6223 head 8b136146
Megatron-Bridge refs/heads/main — an override, not the Bridge NeMo-RL pins 6fe6e59b
NeMo-RL nrlta/integration e41b19aa
Test Status Comment
grpo_megatron_generation ✅ pass
grpo_megatron_generation_topology ✅ pass
grpo_megatron_generation_non_colocated ✅ pass
grpo_megatron_generation_async ✅ pass
grpo_megatron_generation_colocated_async ✅ pass
grpo_megatron_generation_async_gym ✅ pass
grpo_megatron_generation_topp_topk ⚠️ fail (pre-existing) Reproduces on megatron-core main at 80cda5db (same token_mult_prob_error threshold miss). Tracked as known issue topp-topk-token-mult-prob-error-over-threshold; not caused by this PR.
grpo_megatron_generation_colocated_gym ✅ pass
grpo_megatron_generation_async_prefix_caching ⚠️ fail (pre-existing) Reproduces on megatron-core main at da18ed66 with the same metric check failed: max(data["train/token_mult_prob_error"]) < 1.1. Not caused by this PR; L2 nano-3.5 suite is still landing.
grpo_megatron_generation_async_mxfp8 ⚠️ fail (pre-existing) Reproduces on megatron-core main at da18ed66 with the same metric check failed: max(data["train/token_mult_prob_error"]) < 1.5. Not caused by this PR; L2 nano-3.5 suite is still landing.

Megatron-Bridge was pinned to main for this run because the NeMo-RL submodule pin still lags the merged FSDP isinstance fix (Bridge#5431; NeMo-RL bump still open as #3577). NeMo-RL integration also carries the unmerged L2 Megatron functional suite. No failures were attributed to this PR.

Posted by the nemo-rl-testing-agent. Re-runs edit this comment in place.

@copy-pr-bot

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

@sidsingh-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 929bf14

The replicas shared one listening socket: the parent bound it and passed the
same fd to every forked worker, so all of them accepted from a single queue.
That does not balance. Whichever worker is already running tends to win the
wakeup, and it keeps winning, because an event loop with work in flight polls
more often than one blocked in accept. SO_REUSEPORT was set on that socket but
was inert -- the kernel only load-balances when several sockets are bound to
the port and it can hash a connection's 4-tuple to choose between them.

Measured with 32 replicas and a fresh connection per request, ~90% of traffic
landed on 5 of them, 20 replicas served exactly one request each, and
throughput was 3.7x lower than the same server under a pooled client that
opened its connections up front. Load made it worse rather than averaging it
out: at 2048 requests the busiest replica took 604x the quietest.

Each replica now binds its own socket on the shared port, so every one gets its
own accept queue. Spread became max/min 1.5x with all replicas serving, and
throughput 2.5x on the fresh-connection path. A pooled client is unaffected in
steady state, which is the point: how well the frontend spreads no longer
depends on connection behaviour the server cannot observe.

start_text_gen_server now returns the base URL it is serving on. Callers that
start a frontend on more than one rank need the addresses to spread requests
over; previously they had to reconstruct them. The signature is otherwise
unchanged, including sock, which still fixes the port -- it is closed rather
than shared, since replicas bind their own.

tools/run_dynamic_text_generation_server.py gains --frontend-on-all-ranks,
which hosts a frontend on every rank and gathers the URLs. Frontend work is
CPU-bound and otherwise confined to one rank's CPU allocation while the rest of
the job's cores go unused.

Signed-off-by: Siddharth Singh <sidsingh@nvidia.com>
(cherry picked from commit 1001ca9)
@sidsingh-nvidia
sidsingh-nvidia force-pushed the siddharth/frontend-tokenize-thread branch from 929bf14 to 54522c4 Compare August 19, 2026 22:23
@sidsingh-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 890d9f2

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

Labels

Approved All necessary approvals have been made NemoRLTest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants