Repository navigation
[HIP] [JIT] [gfx950] Optimize Minimax M3 scoring & top-k kernels #4787
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
valarLip
merged 12 commits into
ROCm:main
from
ukannika:minimax_m3_sparse_attn_scoring_topk_kernels
Sep 1, 2026
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
545d97c
[gfx950] Optimize Minimax M3 scoring & top-k kernels
2ed60f5
[HIP][Kernel] Minimax-M3 scoring & topk kernel changes
1bc67ec
[HIP][Kernel] Minimax-M3 scoring & topk kernel changes - formatting c…
fe0a678
Merge branch 'main' into minimax_m3_sparse_attn_scoring_topk_kernels
ukannika a13034f
Merge branch 'main' into minimax_m3_sparse_attn_scoring_topk_kernels
ukannika c0c1cc8
[HIP][Kernel] Minimax-M3 scoring & topk kernel changes - formatting c…
e7cb4a2
Merge branch 'main' into minimax_m3_sparse_attn_scoring_topk_kernels
ukannika bfcbf78
[HIP][Kernel] Minimax-M3 scoring & topk kernel changes - fix compile …
cb3c7a6
Fix msa scoring kernel test
2fcbd51
[HIP][JIT][gfx950] Minimax-M3 - Fix module name for scoring & topk ke…
49b0f30
Merge branch 'main' into minimax_m3_sparse_attn_scoring_topk_kernels
ukannika e53569d
Merge branch 'main' into minimax_m3_sparse_attn_scoring_topk_kernels
ukannika 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| # Copyright (C) 2024-2026, Advanced Micro Devices, Inc. All rights reserved. | ||
|
|
||
| """Sparse block selection for index-head attention.""" | ||
|
|
||
| import torch | ||
|
|
||
| from csrc.cpp_itfs.torch_utils import direct_register_custom_op | ||
|
|
||
| from .msa_block_select import ( | ||
| pa_sparse_block_score_decode as pa_sparse_block_score_decode_core, | ||
| ) | ||
| from .msa_block_select import ( | ||
| pa_sparse_block_score_prefill as pa_sparse_block_score_prefill_core, | ||
| ) | ||
| from .msa_block_select import pa_sparse_block_topk as pa_sparse_block_topk_core | ||
|
|
||
|
|
||
| def pa_sparse_block_score_decode( | ||
| q_idx: torch.Tensor, | ||
| key_cache_idx: torch.Tensor, | ||
| score: torch.Tensor, | ||
| block_table: torch.Tensor, | ||
| seq_lens: torch.Tensor, | ||
| init_blocks: int = 0, | ||
| local_blocks: int = 0, | ||
| query_len: int = 1, | ||
| max_seq_len: int = 0, | ||
| ) -> None: | ||
| pa_sparse_block_score_decode_core( | ||
| q_idx, | ||
| key_cache_idx, | ||
| score, | ||
| block_table, | ||
| seq_lens, | ||
| init_blocks, | ||
| local_blocks, | ||
| query_len, | ||
| max_seq_len, | ||
| ) | ||
|
|
||
|
|
||
| direct_register_custom_op( | ||
| "pa_sparse_block_score_decode", | ||
| pa_sparse_block_score_decode, | ||
| ["score"], | ||
| ) | ||
|
|
||
|
|
||
| def pa_sparse_block_score_prefill( | ||
| q_idx: torch.Tensor, | ||
| key_cache_idx: torch.Tensor, | ||
| score: torch.Tensor, | ||
| block_table: torch.Tensor, | ||
| cu_seqlens_q: torch.Tensor, | ||
| seq_lens: torch.Tensor, | ||
| init_blocks: int = 0, | ||
| local_blocks: int = 0, | ||
| max_query_len: int = 0, | ||
| max_seq_len: int = 0, | ||
| ) -> None: | ||
| pa_sparse_block_score_prefill_core( | ||
| q_idx, | ||
| key_cache_idx, | ||
| score, | ||
| block_table, | ||
| cu_seqlens_q, | ||
| seq_lens, | ||
| init_blocks, | ||
| local_blocks, | ||
| max_query_len, | ||
| max_seq_len, | ||
| ) | ||
|
|
||
|
|
||
| direct_register_custom_op( | ||
| "pa_sparse_block_score_prefill", | ||
| pa_sparse_block_score_prefill, | ||
| ["score"], | ||
| ) | ||
|
|
||
|
|
||
| def pa_sparse_block_topk( | ||
| score: torch.Tensor, | ||
| topk_idx: torch.Tensor, | ||
| block_table: torch.Tensor, | ||
| seq_lens: torch.Tensor, | ||
| sparse_bt: torch.Tensor, | ||
| sparse_ctx: torch.Tensor, | ||
| max_seq_len: int = 0, | ||
| block_size: int = 0, | ||
| query_len: int = 1, | ||
| num_waves: int = 0, | ||
| num_valid_pages: torch.Tensor | None = None, | ||
| row_req_id: torch.Tensor | None = None, | ||
| kv_lens: torch.Tensor | None = None, | ||
| num_kv_heads: int = 1, | ||
| pages_per_block: int = 8, | ||
| ) -> None: | ||
| pa_sparse_block_topk_core( | ||
| score, | ||
| topk_idx, | ||
| block_table, | ||
| seq_lens, | ||
| max_seq_len, | ||
| block_size, | ||
| query_len, | ||
| num_waves, | ||
| num_valid_pages, | ||
| sparse_bt, | ||
| sparse_ctx, | ||
| row_req_id, | ||
| kv_lens, | ||
| num_kv_heads, | ||
| pages_per_block, | ||
| ) | ||
|
|
||
|
|
||
| direct_register_custom_op( | ||
| "pa_sparse_block_topk", | ||
| pa_sparse_block_topk, | ||
| ["topk_idx", "sparse_bt", "sparse_ctx"], | ||
| ) |
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.