Skip to content

enable minimax m3 fp8 index cache and fuse index_score_kernel with partial_topk kernel - #1473

Merged
valarLip merged 11 commits into
mainfrom
ganyi/fuse_score_topk
Jul 17, 2026
Merged

valarLip merged 11 commits into
mainfrom
ganyi/fuse_score_topk

Conversation

@ganyi1996ppo

@ganyi1996ppo ganyi1996ppo commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

deps on aiter PR ROCm/aiter#4098
launch script:

export HIP_VISIBLE_DEVICES=0,1,2,3
export ATOM_FORCE_ATTN_TRITON=1

python -m atom.entrypoints.openai_server --model $main_model \
  -tp 4 --server-port 8014 --trust-remote-code --gpu-memory-utilization 0.85 --block-size 128 --no-enable_prefix_caching \
  --max-num-batched-tokens 16384 --max-model-len 16384\
  --kv_cache_dtype fp8 --index-cache-dtype fp8 \
  --torch-profiler-dir ./trace

accuracy:

|Tasks|Version|     Filter     |n-shot|  Metric   |   |Value |   |Stderr|
|-----|------:|----------------|-----:|-----------|---|-----:|---|-----:|
|gsm8k|      3|flexible-extract|     5|exact_match|↑  |0.9424|±  |0.0064|
|     |       |strict-match    |     5|exact_match|↑  |0.9431|±  |0.0064|

Perf
This PR

============ Serving Benchmark Result ============
Successful requests:                     256       
Failed requests:                         0         
Maximum request concurrency:             32        
Benchmark duration (s):                  138.58    
Total input tokens:                      2097152   
Total generated tokens:                  262144    
Request throughput (req/s):              1.85      
Output token throughput (tok/s):         1891.65   
Peak output token throughput (tok/s):    3392.00   
Peak concurrent requests:                64.00     
Total token throughput (tok/s):          17024.81  
---------------Time to First Token----------------
Mean TTFT (ms):                          3490.40   
Median TTFT (ms):                        3491.54   
P99 TTFT (ms):                           6514.43   
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          13.52     
Median TPOT (ms):                        13.55     
P99 TPOT (ms):                           16.92     
---------------Inter-token Latency----------------
Mean ITL (ms):                           13.50     
Median ITL (ms):                         10.47     
P99 ITL (ms):                            12.96     
==================================================

before

============ Serving Benchmark Result ============
Successful requests:                     256       
Failed requests:                         0         
Maximum request concurrency:             32        
Benchmark duration (s):                  142.15    
Total input tokens:                      2097152   
Total generated tokens:                  262144    
Request throughput (req/s):              1.80      
Output token throughput (tok/s):         1844.15   
Peak output token throughput (tok/s):    5088.00   
Peak concurrent requests:                64.00     
Total token throughput (tok/s):          16597.33  
---------------Time to First Token----------------
Mean TTFT (ms):                          3500.17   
Median TTFT (ms):                        3498.67   
P99 TTFT (ms):                           6520.38   
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          13.94     
Median TPOT (ms):                        13.91     
P99 TPOT (ms):                           17.34     
---------------Inter-token Latency----------------
Mean ITL (ms):                           13.93     
Median ITL (ms):                         10.98     
P99 ITL (ms):                            12.66     
==================================================

Technical Details

Test Plan

Test Result

Submission Checklist

Copilot AI review requested due to automatic review settings July 6, 2026 07:30
@ganyi1996ppo
ganyi1996ppo marked this pull request as draft July 6, 2026 07:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
)
@ganyi1996ppo
ganyi1996ppo marked this pull request as ready for review July 7, 2026 02:15
@zufayu
zufayu requested a review from amd-ruitang3 July 7, 2026 02:59
Copilot AI review requested due to automatic review settings July 7, 2026 04:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

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"
),
)
Copilot AI review requested due to automatic review settings July 7, 2026 04:58
valarLip
valarLip previously approved these changes Jul 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

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,
Copilot AI review requested due to automatic review settings July 13, 2026 11:29
@ganyi1996ppo
ganyi1996ppo force-pushed the ganyi/fuse_score_topk branch from 97326c9 to 2d2bef9 Compare July 13, 2026 11:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

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>
Signed-off-by: ganyi <ygan@amd.com>
Copilot AI review requested due to automatic review settings July 15, 2026 06:42
@ganyi1996ppo
ganyi1996ppo force-pushed the ganyi/fuse_score_topk branch from 2d2bef9 to fab5a7a Compare July 15, 2026 06:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

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"
return bool(getattr(impl, "is_indexed_sparse_attention", False))


def _resolve_minimax_m3_index_cache_dtype(config) -> torch.dtype:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to _resolve_index_cache_dtype

Signed-off-by: ganyi <ygan@amd.com>
Copilot AI review requested due to automatic review settings July 15, 2026 09:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comment on lines +239 to +241
kv_cache_dtype=(
cache_dtype if str(cache_dtype).startswith("fp8") else "auto"
),
Copilot AI review requested due to automatic review settings July 15, 2026 09:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

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(
Comment thread atom/model_engine/arg_utils.py Outdated
type=str,
default="auto",
help=(
"MiniMax-M3 index cache type. 'auto' uses the model dtype; "

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"MiniMax-M3 index cache type"?
it's better default =kv_cache_dtype?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copilot AI review requested due to automatic review settings July 17, 2026 02:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Comment thread atom/config.py
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 thread atom/models/minimax_m3.py
quant_config: Optional[QuantizationConfig] = None,
prefix: str = "",
cache_config: str = "bf16",
index_cache_config: str = "auto",
Comment thread atom/models/minimax_m3.py
quant_config: Optional[QuantizationConfig] = None,
prefix: str = "",
cache_config: str = "bf16",
index_cache_config: str = "auto",
Comment thread atom/models/minimax_m3.py
config: PretrainedConfig,
prefix: str,
cache_config: str = "bf16",
index_cache_config: str = "auto",
Signed-off-by: ganyi <ygan@amd.com>
Copilot AI review requested due to automatic review settings July 17, 2026 02:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

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 thread atom/models/minimax_m3.py
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,
Signed-off-by: ganyi <ygan@amd.com>
Copilot AI review requested due to automatic review settings July 17, 2026 02:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread atom/config.py
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
valarLip merged commit c101aa0 into main Jul 17, 2026
51 of 58 checks passed
@valarLip
valarLip deleted the ganyi/fuse_score_topk branch July 17, 2026 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants