Skip to content

Prevent FlashInfer sampling from running with CUDA graphs#5791

Merged
santhnm2 merged 17 commits into
NVIDIA:mainfrom
santhnm2:fix_flashinfer_sampling
Jul 25, 2026
Merged

Prevent FlashInfer sampling from running with CUDA graphs#5791
santhnm2 merged 17 commits into
NVIDIA:mainfrom
santhnm2:fix_flashinfer_sampling

Conversation

@santhnm2

@santhnm2 santhnm2 commented Jul 13, 2026

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

What does this PR do?

Prevents FlashInfer sampling from running with CUDA graphs enabled due to a known issue regarding the RNG state not being CUDA-graph safe.
See here for more details: https://www.linkedin.com/pulse/pinned-rng-drifting-crash-from-cuda-graph-chenyang-zhao-csuac/

Also enables more fine-grained dispatching across sampling kernels depending on the batch composition (i.e., different kernels for only top-k, only top-p, and mixed batches).

⚠️ 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.

Signed-off-by: Keshav Santhanam <ksanthanam@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 13, 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.

@santhnm2

Copy link
Copy Markdown
Contributor Author

/ok to test 50a7417

@kvareddy

Copy link
Copy Markdown
Contributor

@tdene can you please take a look at this MR?

Comment thread megatron/core/inference/sampling/flashinfer_sampling.py Outdated
@sidsingh-nvidia

Copy link
Copy Markdown
Contributor

Can we make flashinfer the default backend (just like vllm) and gracefully fallback to torch if it is not installed?

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Final Review PR is in the "final review" stage label Jul 14, 2026
@santhnm2
santhnm2 requested review from a team as code owners July 14, 2026 20:58
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the Final Review PR is in the "final review" stage label Jul 14, 2026
@santhnm2

Copy link
Copy Markdown
Contributor Author

/ok to test f1c60b5

@santhnm2

Copy link
Copy Markdown
Contributor Author

Can we make flashinfer the default backend (just like vllm) and gracefully fallback to torch if it is not installed?

Done

@santhnm2

Copy link
Copy Markdown
Contributor Author

/ok to test d84e7b6

santhnm2 added 3 commits July 20, 2026 14:06
Signed-off-by: Keshav Santhanam <ksanthanam@nvidia.com>
Signed-off-by: Keshav Santhanam <ksanthanam@nvidia.com>
@santhnm2

Copy link
Copy Markdown
Contributor Author

/ok to test 4fb14c2

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/29784575241

@santhnm2

Copy link
Copy Markdown
Contributor Author

/ok to test 519baaa

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/29864635950

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/29875881427

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/29890584858

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/29909532601

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/29935241695

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/29974160691

Signed-off-by: Siddharth Singh <sidsingh@nvidia.com>
@sidsingh-nvidia

Copy link
Copy Markdown
Contributor

Pushed a commit to fix the failing test harness.

@sidsingh-nvidia

Copy link
Copy Markdown
Contributor

/ok to test b571fcd

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/30133076428

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/30136325005

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants