Skip to content

Inference: Cudagraph-aware admission gating in prefill scheduler#4870

Open
mathemakitten wants to merge 4 commits into
NVIDIA:mainfrom
mathemakitten:helenn-admit-chunked-prefill
Open

Inference: Cudagraph-aware admission gating in prefill scheduler#4870
mathemakitten wants to merge 4 commits into
NVIDIA:mainfrom
mathemakitten:helenn-admit-chunked-prefill

Conversation

@mathemakitten
Copy link
Copy Markdown
Contributor

What does this PR do ?

Presently, schedule_chunked_prefill and schedule_non_chunked_prefill admit requests based on the available token/request budget only without consideration for whether the resulting batch shape will match any captured CG. When a request pushes the batch into a shape the captured set doesn't cover, the engine silently falls back to eager mode. While Transformer models can absorb extra decodes into prefill slots, for hybrid models, the matcher requires captured_decode_req_count >= real_decode_req_count (strict mode), so we fallback to eager more often.

Now, when cuda_graph_all_prefills is on, _find_cg_chunk_size(max_chunk_tokens) traverses the list of cudagraphs to find the best-fit cudagraph for (active_token_count + chunk_size, num_prefill_requests + 1, num_decode_requests). schedule_chunked_prefill snaps prefill_chunk_length to the largest CG-aligned boundary in the token budget, and if no CG covers the resulting shape, the request is deferred.

This is designed without an eager fallback: if there is no cudagraph, the deferred request waits until the present decode finishes, when the next prefill will be automatically admitted. The worst case of this is max_sequence_length. This avoids the one-off version of forcing an eager step which then continues to trigger eager due to the imbalance, and ensures that we run every step cudagraphed.

#3509 needs to be merged first to avoid unnecessary starvation for hybrid inference. These two PRs together ensure that no steps will run eager.

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.

For MRs into `dev` branch The proposed review process for `dev` branch is under active discussion.

MRs are mergable after one approval by either eharper@nvidia.com or zijiey@nvidia.com.

@mathemakitten mathemakitten requested review from a team as code owners May 19, 2026 16:32
@svcnvidia-nemo-ci svcnvidia-nemo-ci marked this pull request as draft May 19, 2026 16:32
@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.

@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 19, 2026

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.

@santhnm2
Copy link
Copy Markdown
Contributor

The code changes LGTM but can we add some tests which exercise the code path that defers a request due to lack of a CUDA graph match? Basically we should confirm that even if a request is deferred:
A) the other scheduled requests still proceed successfully
B) the deferred request eventually gets scheduled
C) graphs are active for all batches

Comment on lines +380 to +381
for _ in range(20):
assert engine._cg_admission_check(req, candidate) is False
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.

Can you add a comment that this is happening 20 times to increment the wait iterations?

token_count=8, prefill_req_count=0, decode_req_count=1
)

# Iterate the "scheduler". Each iteration: try both, record outcomes.
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.

Can you clarify that this loop is increasing the waiting step count?

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Final Review PR is in the "final review" stage label May 20, 2026
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.

3 participants