Repository navigation
enable minimax m3 fp8 index cache and fuse index_score_kernel with partial_topk kernel - #1473
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the MiniMax-M3 sparse attention/index-topk path to support FP8 for the index-key cache and to reduce decode-time overhead by fusing index-score computation with partial top-k selection in Triton.
Changes:
- Enable FP8 dtype for the MiniMax-M3 index cache allocation/binding when KV cache is FP8.
- Add FP8-aware dot-product handling in the index block-score kernel.
- Fuse decode index-score + partial top-k into a new Triton kernel and adjust decode chunking parameters.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| atom/plugin/vllm/attention/minimax_m3_attnetion.py | Passes FP8 cache dtype through to the vLLM indexer-cache layer when KV cache dtype indicates FP8. |
| atom/model_ops/minimax_m3/index_topk.py | Adds FP8 handling in scoring and fuses decode scoring with partial top-k to remove the intermediate score tensor. |
| atom/model_ops/attentions/aiter_attention.py | Allocates the sparse attention index cache in FP8 when the configured KV cache dtype indicates FP8. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
236
to
240
| self.index_cache_layer = MiniMaxM3SparseIndexerCache( | ||
| layer_name=f"{self.layer_name}.index_cache", | ||
| head_dim=index_head_dim, | ||
| kv_cache_dtype="auto", | ||
| kv_cache_dtype=cache_dtype if str(cache_dtype).startswith("fp8") else "auto", | ||
| ) |
Comment on lines
+543
to
+547
| index_cache_dtype = ( | ||
| dtypes.d_dtypes[config.kv_cache_dtype] | ||
| if str(config.kv_cache_dtype).startswith("fp8") | ||
| else config.torch_dtype | ||
| ) |
Comment on lines
236
to
242
| self.index_cache_layer = MiniMaxM3SparseIndexerCache( | ||
| layer_name=f"{self.layer_name}.index_cache", | ||
| head_dim=index_head_dim, | ||
| kv_cache_dtype="auto", | ||
| kv_cache_dtype=( | ||
| cache_dtype if str(cache_dtype).startswith("fp8") else "auto" | ||
| ), | ||
| ) |
valarLip
previously approved these changes
Jul 7, 2026
Comment on lines
1168
to
1172
| kv_cache_dtype=kv_cache_dtype, | ||
| index_cache_dtype=self.index_cache_dtype, | ||
| k_scale=fused_k_scale, | ||
| v_scale=fused_v_scale, | ||
| asm_layout=True, |
ganyi1996ppo
force-pushed
the
ganyi/fuse_score_topk
branch
from
July 13, 2026 11:29
97326c9 to
2d2bef9
Compare
Signed-off-by: ganyi <ygan@amd.com>
Signed-off-by: ganyi <ygan@amd.com>
Signed-off-by: ganyi <ygan@amd.com>
Signed-off-by: ganyi <ygan@amd.com>
Signed-off-by: ganyi <ygan@amd.com>
ganyi1996ppo
force-pushed
the
ganyi/fuse_score_topk
branch
from
July 15, 2026 06:42
2d2bef9 to
fab5a7a
Compare
Comment on lines
236
to
+240
| self.index_cache_layer = MiniMaxM3SparseIndexerCache( | ||
| layer_name=f"{self.layer_name}.index_cache", | ||
| head_dim=index_head_dim, | ||
| kv_cache_dtype="auto", | ||
| kv_cache_dtype=( | ||
| cache_dtype if str(cache_dtype).startswith("fp8") else "auto" |
valarLip
reviewed
Jul 15, 2026
| return bool(getattr(impl, "is_indexed_sparse_attention", False)) | ||
|
|
||
|
|
||
| def _resolve_minimax_m3_index_cache_dtype(config) -> torch.dtype: |
Contributor
Author
There was a problem hiding this comment.
change to _resolve_index_cache_dtype
Signed-off-by: ganyi <ygan@amd.com>
Comment on lines
+239
to
+241
| kv_cache_dtype=( | ||
| cache_dtype if str(cache_dtype).startswith("fp8") else "auto" | ||
| ), |
Comment on lines
424
to
426
| for blk in tl.range(chunk_start_block, chunk_end_block): | ||
| page = tl.load(bt_row + blk).to(tl.int64) | ||
| pos = blk * BLOCK_SIZE_K + off_k | ||
| pos_mask = pos < causal_len | ||
| k = tl.load( |
valarLip
reviewed
Jul 16, 2026
| type=str, | ||
| default="auto", | ||
| help=( | ||
| "MiniMax-M3 index cache type. 'auto' uses the model dtype; " |
Collaborator
There was a problem hiding this comment.
"MiniMax-M3 index cache type"?
it's better default =kv_cache_dtype?
Signed-off-by: ganyi <ygan@amd.com>
Comment on lines
1271
to
+1274
| factors.append(vllm_factors) | ||
| factors.append(self.tensor_parallel_size) | ||
| factors.append(self.enable_dp_attention) | ||
| factors.append(self.index_cache_dtype) |
| quant_config: Optional[QuantizationConfig] = None, | ||
| prefix: str = "", | ||
| cache_config: str = "bf16", | ||
| index_cache_config: str = "auto", |
| quant_config: Optional[QuantizationConfig] = None, | ||
| prefix: str = "", | ||
| cache_config: str = "bf16", | ||
| index_cache_config: str = "auto", |
| config: PretrainedConfig, | ||
| prefix: str, | ||
| cache_config: str = "bf16", | ||
| index_cache_config: str = "auto", |
Signed-off-by: ganyi <ygan@amd.com>
Comment on lines
236
to
242
| self.index_cache_layer = MiniMaxM3SparseIndexerCache( | ||
| layer_name=f"{self.layer_name}.index_cache", | ||
| head_dim=index_head_dim, | ||
| kv_cache_dtype="auto", | ||
| kv_cache_dtype=( | ||
| cache_dtype if str(cache_dtype).startswith("fp8") else "auto" | ||
| ), | ||
| ) |
Comment on lines
674
to
676
| cache_config = atom_config.kv_cache_dtype | ||
| index_cache_config = atom_config.index_cache_dtype | ||
| quant_config = atom_config.quant_config |
Comment on lines
+1068
to
1072
| _decode_index_score_topk_partial_kernel[(total_q, num_idx_heads, num_topk_chunks)]( | ||
| idx_q, | ||
| index_kv_cache, | ||
| topk_score_partial, | ||
| topk_idx_partial, |
Comment on lines
1271
to
+1274
| factors.append(vllm_factors) | ||
| factors.append(self.tensor_parallel_size) | ||
| factors.append(self.enable_dp_attention) | ||
| factors.append(self.index_cache_dtype) |
Comment on lines
236
to
242
| self.index_cache_layer = MiniMaxM3SparseIndexerCache( | ||
| layer_name=f"{self.layer_name}.index_cache", | ||
| head_dim=index_head_dim, | ||
| kv_cache_dtype="auto", | ||
| kv_cache_dtype=( | ||
| cache_dtype if str(cache_dtype).startswith("fp8") else "auto" | ||
| ), | ||
| ) |
valarLip
approved these changes
Jul 17, 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.
Motivation
deps on aiter PR ROCm/aiter#4098
launch script:
accuracy:
Perf
This PR
before
Technical Details
Test Plan
Test Result
Submission Checklist