[None][perf] Optimize MiniMax-M3 CTX block selection#16818
Merged
peihu-nv merged 2 commits intoJul 24, 2026
Merged
Conversation
Add warp-specialized selector kernels for up to 128 allocated blocks and emit a head-major backing during pure prefill so the selector-to-K2Q handoff is zero-copy. Keep mixed and decode batches Q-major and cover routing, strides, ties, forcing, and CUDA graph replay. Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
peihu-nv
requested review from
kris1025,
mikeiovine,
pengbowang-nv and
tongyuantongyu
July 24, 2026 01:01
zheyuf
self-requested a review
July 24, 2026 20:50
2 tasks
zheyuf
approved these changes
Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@coderabbitai summary
Description
MiniMax-M3 sparse planning had two independent costs in pure prefill: the
general block-selector kernel was inefficient for the common at-most-128-block
shape, and its Q-major output was materialized into a separate head-major
tensor immediately before K2Q planning.
This PR makes two complementary optimizations:
warp kernels cover at most 32, 64, and 128 candidates using register-resident
selection and sorting. Shapes above 128 continue to use the existing general
selector.
writes directly into head-major backing storage while preserving the public
logical
[Q, Hkv, 16]view. The existingresult.permute(1, 0, 2).contiguous()K2Q handoff therefore becomes acontiguous view instead of launching a materialization copy. This layout
optimization also applies when shapes above 128 use the general selector;
mixed and decode batches retain the existing Q-major backing.
In a matched GB200 1P1D run (TP4/EP4 per server, 8K input / 1K output,
concurrency 64):
(-36.9%).
prefill; selected int32 copy work fell from 61 calls / 0.181 ms to 4 calls /
0.008 ms.
resulting in approximately +1.1% context throughput.
Test Coverage
ties, forced blocks, 64/128-block dispatch, output strides, and CUDA graph
replay.
contiguous head-major K2Q input, and zero CUDA events during
permute(...).contiguous().2469230completed; corrected validation job2469447completed.2469565completed 1,000/1,000 requests. Normalized8K results: selector 6.264 to 3.951 ms (-36.9%), sparse planning 11.230 to
8.818 ms (-21.5%), and CTX forward 318.359 to 314.991 ms (-1.06%),
equivalent to approximately +1.1% context throughput.
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of up-to-date bot commands, post
/bot helpas a PR comment and check the bot's reply.