Repository navigation
[Diffusion][MiniMax-H3] Add SM120 Sage compute for SubBlock sparse attention #40116
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
BBuf
merged 4 commits into
sgl-project:main
from
antgroup:codex/subblock-sage-fp8-sm120
Sep 20, 2026
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7610593
feat(diffusion): add SM120 Sage FP8 compute for SubBlock attention
IPostYellow 77fd979
docs(diffusion): add FlashInfer install instructions for SM120 Sage
IPostYellow 78ac961
Merge branch 'main' into codex/subblock-sage-fp8-sm120
IPostYellow 495e77d
Merge branch 'main' into codex/subblock-sage-fp8-sm120
IPostYellow 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """Manual SM120 Sage correctness check against selected-block FP32 attention. | ||
|
|
||
| Requires an SM120 GPU and FlashInfer with the CuTe-DSL SM120 Sage backend. | ||
| Run: python test/manual/attention/test_subblock_sage_fp8_sm120.py | ||
| """ | ||
|
|
||
| import unittest | ||
|
|
||
| import torch | ||
|
|
||
| from sglang.test.test_utils import CustomTestCase | ||
|
|
||
|
|
||
| @unittest.skipUnless( | ||
| torch.cuda.is_available() and torch.cuda.get_device_capability() == (12, 0), | ||
| "requires an SM120 GPU", | ||
| ) | ||
| class TestSubBlockSageFp8Sm120(CustomTestCase): | ||
| def test_ragged_sparse_plan_with_empty_rows(self): | ||
| from sglang.multimodal_gen.runtime.layers.attention.backends.subblock_sparse_attn import ( | ||
| _sm120_sage_fp8_sparse_attention, | ||
| ) | ||
|
|
||
| torch.manual_seed(19) | ||
| q = torch.randn(1, 65, 2, 128, device="cuda", dtype=torch.bfloat16) | ||
| k = torch.randn(1, 129, 2, 128, device="cuda", dtype=torch.bfloat16) | ||
| v = torch.randn_like(k) | ||
| index = torch.tensor( | ||
| [[[[2, 0], [1, 0]], [[0, 2], [2, 1]]]], device="cuda", dtype=torch.int32 | ||
| ) | ||
| counts = torch.tensor([[[2, 1], [0, 2]]], device="cuda", dtype=torch.int32) | ||
| mask = torch.zeros(1, 2, 65, 129, device="cuda", dtype=torch.bool) | ||
| mask[0, 0, :64, :64] = True | ||
| mask[0, 0, :64, 128:] = True | ||
| mask[0, 0, 64:, 64:128] = True | ||
| mask[0, 1, 64:, 64:] = True | ||
| scale = 128**-0.5 | ||
| logits = torch.einsum("bqhd,bkhd->bhqk", q.float(), k.float()) * scale | ||
| probs = logits.masked_fill(~mask, -float("inf")).softmax(-1).nan_to_num() | ||
| expected = torch.einsum("bhqk,bkhd->bqhd", probs, v.float()) | ||
| actual = _sm120_sage_fp8_sparse_attention(q, k, v, index, 2, scale, counts) | ||
| self.assertEqual(actual.dtype, torch.bfloat16) | ||
| self.assertTrue(actual.is_contiguous()) | ||
| self.assertTrue(torch.isfinite(actual).all()) | ||
| self.assertEqual(torch.count_nonzero(actual[0, :64, 1]).item(), 0) | ||
| torch.testing.assert_close(actual.float(), expected, atol=5e-2, rtol=5e-2) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking: could we include a source-install link/command or the minimum FlashInfer version providing both SM120 Sage symbols here? The default FlashInfer pin remains
0.6.18; the PR description points to flashinfer-ai/flashinfer#4691 and the tested commit, but users following this README only get the symbol names. Carrying that installation guidance into the README would make the opt-in mode easier to use.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review. I'll add the FlashInfer source-installation guidance and the tested commit to the README so users can enable SM120 Sage without referring to the PR description.