Skip to content

feat(inference): support request-local sampling seeds - #7828

Merged
wdykas merged 12 commits into
NVIDIA:mainfrom
wdykas:feat/request-local-sampling
Oct 11, 2026
Merged

wdykas merged 12 commits into
NVIDIA:mainfrom
wdykas:feat/request-local-sampling

Conversation

@wdykas

@wdykas wdykas commented Oct 2, 2026 •

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

What does this PR do?

Add optional request-local sampling seeds to dynamic Torch inference and both OpenAI-compatible completion endpoints. With a shared generator, moving a request between batches changes its draws even when its logits are unchanged. Explicit seed assigns each draw by request seed and absolute token position, independently of request IDs, batch slots, or other requests' RNG consumption.

  • Validate and serialize nonnegative int64 seeds; track them through the existing aligned request metadata.
  • Keep temperature/top-k/top-p filtering batched. Generate noise independently for seeded rows without advancing the shared generator; omitted seeds keep the existing sampling path.
  • Give HTTP choice/prompt i seed (seed + i) % 2**63, including streaming submissions.
  • Preserve the pending logits' token positions when async overlap prepares successor state before sampling.
  • Reject seeded FlashInfer, speculative, static, and custom-metadata-without-seed configurations rather than silently ignoring the seed.

Issue tracking

Closes #7827

Signed-off-by: wdykas <wdykas@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Oct 2, 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.

@wdykas

wdykas commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

/review model=claude

@wdykas

wdykas commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

/review

@wdykas

wdykas commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

this has a scalability problem I need to figure out

wdykas added 2 commits October 6, 2026 07:58
Replace per-request CUDA generator reseeding and exponential launches with a batched Philox kernel keyed by request seed, absolute token position, and vocabulary index. Preserve the CPU fallback and unseeded shared-generator behavior.

Document the seeded CUDA stream change, cover replay across batch layouts and launch tiling under contention, and add a reproducible sampler benchmark. Validated with 333 focused tests on GB200.

Signed-off-by: wdykas <wdykas@nvidia.com>
Keep the PR focused on production request-local sampling and necessary regression coverage. Remove the ad hoc benchmark, duplicate CUDA replay wrapper, and sampler position-override test already covered by the async-controller regression. Retain the required kernel determinism and distribution checks.

Validated with 331 focused tests and formatting, lint, and kernel coverage checks.

Signed-off-by: wdykas <wdykas@nvidia.com>
@wdykas

wdykas commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f2bb8b7

wdykas added 2 commits October 6, 2026 08:57
Signed-off-by: wdykas <wdykas@nvidia.com>
Signed-off-by: wdykas <wdykas@nvidia.com>
@wdykas
wdykas marked this pull request as ready for review October 6, 2026 16:36
@wdykas
wdykas requested review from a team as code owners October 6, 2026 16:36
@wdykas

wdykas commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test cdd420a



@triton.jit(do_not_specialize=["Seeds", "Positions"])
def _request_seed_noise_kernel(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed for perf. the naive way takes forever

@wdykas

wdykas commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test ca4e67c

Signed-off-by: wdykas <wdykas@nvidia.com>
@wdykas

wdykas commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e5a35e3

@nemo-automation-bot

Copy link
Copy Markdown

🔄 Merge queue validation started!

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

@nemo-automation-bot

Copy link
Copy Markdown

🔄 Merge queue validation started!

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

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 11, 2026
@wdykas
wdykas added this pull request to the merge queue Oct 11, 2026
@nemo-automation-bot

Copy link
Copy Markdown

🔄 Merge queue validation started!

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

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 11, 2026
@wdykas
wdykas added this pull request to the merge queue Oct 11, 2026
@nemo-automation-bot

Copy link
Copy Markdown

🔄 Merge queue validation started!

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

@nemo-automation-bot

Copy link
Copy Markdown

🔄 Merge queue validation started!

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

Merged via the queue into NVIDIA:main with commit 991176a Oct 11, 2026
108 checks passed
@wdykas
wdykas deleted the feat/request-local-sampling branch October 11, 2026 20:24
Waterpine added a commit to Waterpine/Megatron-LM that referenced this pull request Oct 20, 2026
torch_sampling.py is registered under the request-seed sampling kernel
since NVIDIA#7828, so changes to it must update that kernel's determinism
test. Replay an all-greedy batch with request seeds under side-stream
contention, and check that it returns per-row argmax without advancing
the shared RNG. Also update the sample_kernel docstring, which still
described no_top_k/no_top_p as ignored.

Signed-off-by: Waterpine <biansonghz@gmail.com>
@Waterpine Waterpine mentioned this pull request Oct 20, 2026
2 of 7 tasks

This branch was previously deployed

2 inactive deployments
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 complexity: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support request-local sampling seeds in dynamic inference

7 participants