Repository navigation
[None][feat] Enable MiniMax-M3 on Rubin (SM107): NVFP4 KV exemption and 128-token paged FMHA kernels #20167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
peihu-nv
merged 10 commits into
NVIDIA:main
from
peihu-nv:peihengh/m3-rubin-main-port-20261012
Oct 23, 2026
+869
−30
Merged
[None][feat] Enable MiniMax-M3 on Rubin (SM107): NVFP4 KV exemption and 128-token paged FMHA kernels #20167
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2a58057
[None][feat] Enable MiniMax-M3 on Rubin (SM107): NVFP4 KV exemption a…
peihu-nv e94d5a5
[None][fix] Use FlashInfer TRTLLM-Gen FMHA on SM107 for extra KV page…
yuxianq e780557
rework #20167: route SM107 P128 FMHA to FlashInfer, drop the NVRTC path
peihu-nv f36816a
fail fast when the SM107 P128 opt-in has no FlashInfer route
peihu-nv c968f35
derive the SM107 P128 oracle tolerances from a seed sweep at 16:1
peihu-nv 620402c
document the SM107 P128 FlashInfer cubin set and offline seeding
peihu-nv ed19a8a
fail fast when TLLM_FMHA_LIBS tries fallback before the SM107 P128 Fl…
peihu-nv 8e7b3e3
require the SM107 P128 FlashInfer route only for shared draft layers
peihu-nv c9a7160
Merge upstream/main into the #20167 branch
peihu-nv cbb1420
[None][fix] Simplify the MiniMax-M3 SM107 P128 route check and always…
peihu-nv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
93 changes: 93 additions & 0 deletions
93
tests/unittest/_torch/attention/sparse/msa/test_minimax_m3_kv_pool_zero_init.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """MiniMax-M3 KV pools start zeroed. | ||
|
|
||
| Readers that consume a whole block or page (the CSR sparse prefill's V dequant, | ||
| the full-context decode on a last page's tail) also read bytes no request has | ||
| written, so every pool view must hold zeros, not uninitialized memory, before | ||
| the first request. | ||
| """ | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
| from tensorrt_llm._torch.attention.backends.sparse.minimax_m3.cache_manager import ( | ||
| MiniMaxM3KVCacheManagerV2, | ||
| ) | ||
| from tensorrt_llm.bindings import DataType | ||
| from tensorrt_llm.bindings.internal.batch_manager import CacheType | ||
| from tensorrt_llm.llmapi.llm_args import ( | ||
| Eagle3DecodingConfig, | ||
| KvCacheConfig, | ||
| MiniMaxM3SparseAttentionConfig, | ||
| ) | ||
| from tensorrt_llm.mapping import Mapping | ||
|
|
||
|
|
||
| def _nonzero_bytes(view: torch.Tensor) -> int: | ||
| """Count nonzero bytes; a strided view that cannot be reinterpreted in place is copied first.""" | ||
| try: | ||
| raw = view.view(torch.uint8) | ||
| except RuntimeError: | ||
| raw = view.contiguous().view(torch.uint8) | ||
| return int(torch.count_nonzero(raw).item()) | ||
|
|
||
|
|
||
| @pytest.mark.skipif(not torch.cuda.is_available(), reason="requires CUDA cache pools") | ||
| @pytest.mark.parametrize("with_draft", [False, True], ids=["target_only", "shared_eagle3"]) | ||
| def test_every_pool_view_is_zero_after_construction(with_draft: bool) -> None: | ||
| torch.cuda.init() | ||
| manager = MiniMaxM3KVCacheManagerV2( | ||
| KvCacheConfig( | ||
| max_gpu_total_bytes=16 << 20, | ||
| host_cache_size=0, | ||
| enable_block_reuse=False, | ||
| enable_swa_scratch_reuse=False, | ||
| ), | ||
| CacheType.SELF, | ||
| num_layers=4, | ||
| num_kv_heads=[2, 2, 2, 2, 1] if with_draft else [2, 2, 2, 2], | ||
| head_dim=128, | ||
| tokens_per_block=128, | ||
| max_seq_len=256, | ||
| max_batch_size=2, | ||
| max_num_tokens=256, | ||
| mapping=Mapping(world_size=1, rank=0, tp_size=1, pp_size=1), | ||
| dtype=DataType.NVFP4, | ||
| vocab_size=16, | ||
| spec_config=( | ||
| Eagle3DecodingConfig(max_draft_len=3, speculative_model="unused") | ||
| if with_draft | ||
| else None | ||
| ), | ||
| sparse_attention_config=MiniMaxM3SparseAttentionConfig( | ||
| implementation="msa", indexer_kv_dtype="fp8" | ||
| ), | ||
| ) | ||
| try: | ||
| views = { | ||
| **{("kv",) + key: view for key, view in manager._kv_buffers.items()}, | ||
| **{("scale",) + key: view for key, view in manager._block_scale_buffers.items()}, | ||
| **{("index_k", key): view for key, view in manager._index_k_buffers.items()}, | ||
| } | ||
| assert any(name[0] == "kv" for name in views) | ||
| assert any(name[0] == "scale" for name in views) | ||
| assert any(name[0] == "index_k" and view is not None for name, view in views.items()) | ||
| torch.cuda.synchronize() | ||
| counts = {name: _nonzero_bytes(view) for name, view in views.items() if view is not None} | ||
| nonzero = {name: count for name, count in counts.items() if count} | ||
| assert not nonzero, f"pool views with nonzero bytes after construction: {nonzero}" | ||
| finally: | ||
| manager.shutdown() |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.