Skip to content

Allow mixed-batch sampling in dynamic inference - #1927

Merged
tdene merged 21 commits into
NVIDIA:mainfrom
tdene:tde/mixed_sampling
Oct 29, 2025
Merged

Allow mixed-batch sampling in dynamic inference#1927
tdene merged 21 commits into
NVIDIA:mainfrom
tdene:tde/mixed_sampling

Conversation

@tdene

@tdene tdene commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

This MR allows for dynamic inference to process requests with non-uniform sampling parameters.

Future MRs will provide large optimizations.

@tdene
tdene requested review from a team as code owners October 24, 2025 21:03
@tdene tdene self-assigned this Oct 24, 2025
@tdene tdene added the Expert Review [deprecated] Apply this label to indicate that your PR is ready for expert review. label Oct 24, 2025

@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, just left a few comments about keeping arguments as optional for now to preserve backwards compatibility.

Comment thread examples/inference/gpt/gpt_dynamic_inference.py Outdated
Comment thread examples/inference/gpt/gpt_dynamic_inference.py
Comment thread examples/inference/gpt/gpt_dynamic_inference_with_coordinator.py
new_sample = torch.zeros(batch_size, dtype=torch.int64, device=last_token_logits.device)
termination_id = torch.zeros_like(new_sample, dtype=torch.int64)

for sampling_params, mask in active_sampling_map:

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 we avoid this loop when not necessary? in cases where users dont have sampling params per request ? (maybe add a paramter that users can set which notes that the same sampling params will be used for all requests ? )
Will there be a performance difference ?

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.

If there's only 1 sets of sampling params, the active_sampling_map will only have 1 entry. We'll only go through the loop once in this particular piece of code, so there should be no performance difference here.

But you are right, however, that there is a loop that cannot be avoided in dynamic_engine.py L598, here. That loop only runs once per step and loops through every currently-active request.

I have a later PR in this series that solves this performance issues by overlapping the CPU and GPU compute. But I will also solve the issue in this PR, instead of leaving it for later. Let me think and address this.

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.

Addressed in the most recent commit. Does that seem good @shanmugamr1992, as a temporary solution until future PRs optimize this even more?

Comment thread megatron/core/inference/engines/dynamic_engine.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Final Review PR is in the "final review" stage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants