Skip to content

[None][perf] Fast-path the MiniMax-M3 MSA plan_kernel - #17097

Closed
zheyuf wants to merge 3 commits into
NVIDIA:feat/m3_with_msafrom
zheyuf:perf/m3-planner-greedy-fastpaths
Closed

[None][perf] Fast-path the MiniMax-M3 MSA plan_kernel#17097
zheyuf wants to merge 3 commits into
NVIDIA:feat/m3_with_msafrom
zheyuf:perf/m3-planner-greedy-fastpaths

Conversation

@zheyuf

@zheyuf zheyuf commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR provides three fast path to planner. Under conc=4096, it is able to save~93% overhead in planner and have ~4.9% gain in tok/s/user while maintaining tok/s/GPU. It also shows gains for conc=64, 256, 1024.

There will be less gain after #17171 get merged. This is because

image

Fast path 1 — uniform cost ⇒ closed form (sparse/GQA decode, 94×)

When every task has the same cost, the greedy assignment is deterministic round-robin: task t → SM (t % N). We replace both greedy passes with parallel closed-form calculations. A min == max reduction guards the path; non-uniform cases use the original algorithm.

Gain: 1080 → 11.7 µs at batch 256 (94×; 113× at batch 2048).

Fast path 2 — single head ⇒ warp argmin + cached scatter (dense/proxy decode, 11×)

With num_heads == 1, each round assigns only one task, so the full per-thread rank scan is unnecessary. We use the existing warp-shuffle argmin, preserving the lowest-index tie-break, and cache pass-1 placements so pass 2 becomes a parallel scatter.

Gain: 1075 → 101 µs at batch 256 (11×).

Fast path 3 — active-row compaction (prefill/mixed, 2.8×)

Mixed steps scan the full max_qo_tiles × batch rectangle twice, although most entries are inactive—96% at concurrency 256. We compact active rows once with cub::BlockScan, preserving stock order, then run both passes over the dense list. Oversized cases fall back to the original path.

Gain: 2939 → 1062 µs per mixed call (2.8×).

Delivered as a downstream MSA patch. apply_msa_patch now applies all msa_*.patch files in sorted order using the existing patch mechanism.

@zheyuf
zheyuf force-pushed the perf/m3-planner-greedy-fastpaths branch from ea9dfef to 74be5ed Compare July 31, 2026 02:59
The fmha_sm100 plan_kernel builds three attention work plans per engine
step on a single CTA (1 of 148 SMs) with zero overlap, costing 3.2 ms of
every conc256 decode step and 5.9 ms of every mixed step. Three exact
fast paths in direct_greedy remove 93-96% of that without changing one
bit of plan output:

1. Uniform cost: with equal tile costs the greedy reduces to round-robin
   (task t -> bucket t%N), so every output becomes closed-form. Covers
   the sparse/gqa decode plan (kv extent pinned to topk*page). 94x.
2. Single head: with num_heads==1 each round needs only the cheapest
   bucket; min(pack_cost_idx(cost,idx)) via the existing warp-shuffle
   reduction replaces the O(num_buckets) per-thread rank scan, and
   memoising pass 1's placements turns pass 2 into a parallel scatter.
   Covers the proxy and dense decode plans. 11x.
3. Row compaction: mixed steps visit max_qo_tiles x batch (qt,b) pairs
   twice while ~96% are inactive; compacting active rows once via
   cub::BlockScan and walking the list removes the dead iteration space.
   Covers prefill/mixed steps. 2.8x.

Each path is guarded and falls back to the original loop unchanged.
Applied as a downstream MSA patch; apply_msa_patch now applies every
3rdparty/patches/msa_*.patch in sorted order instead of one hardcoded
file.

Measured on 4x B300 TP4/EP1, InferenceMAX lengths (noise floors
0.05-0.12%, all deltas with non-overlapping ranges):
- decode fast paths: +2.85% e2e at conc8, +3.30% at conc256
- row compaction: +1.14% further at conc256 (+4.42% cumulative)
- plan output bit-identical to stock on 386 constructed cases including
  MAX_UNSPLIT truncation, ki==0 rows, bucket-count boundaries, and
  Eagle3 spec-dec shapes with variable acceptance
- Eagle3 InferenceMAX GSM8K: 95.451 vs 95.490 reference (band
  95.15-96.06), acceptance rate 0.838, mean acceptance length 3.513

Signed-off-by: Zheyu Fu <zheyuf@NVIDIA.com>
@zheyuf
zheyuf force-pushed the perf/m3-planner-greedy-fastpaths branch from 74be5ed to de0c1e0 Compare July 31, 2026 06:04
@zheyuf

zheyuf commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63001 [ run ] triggered by Bot. Commit: de0c1e0 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63001 [ run ] completed with state SUCCESS. Commit: de0c1e0
/LLM/main/L0_MergeRequest_PR pipeline #51109 completed with status: 'SUCCESS'

CI Report

Link to invocation

zheyuf added 2 commits August 2, 2026 22:31
Signed-off-by: Zheyu Fu <zheyuf@nvidia.com>
Signed-off-by: Zheyu Fu <zheyuf@nvidia.com>
@zheyuf
zheyuf marked this pull request as ready for review August 3, 2026 08:37
@zheyuf
zheyuf requested review from a team as code owners August 3, 2026 08:37
@zheyuf
zheyuf requested review from BowenFu, QiJune, dpitman-nvda, kris1025, yiqingy0 and yuxianq and removed request for a team, BowenFu, QiJune, dpitman-nvda, kris1025, yiqingy0 and yuxianq August 3, 2026 08:37
@zheyuf
zheyuf requested review from brb-nv and peihu-nv August 3, 2026 08:38
@zheyuf

zheyuf commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63400 [ run ] triggered by Bot. Commit: ea492bb Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63400 [ run ] completed with state SUCCESS. Commit: ea492bb
/LLM/main/L0_MergeRequest_PR pipeline #51379 completed with status: 'SUCCESS'

CI Report

Link to invocation

@zheyuf zheyuf changed the title [None][perf] Fast-path the MiniMax-M3 MSA plan_kernel greedy scheduler [None][perf] Fast-path the MiniMax-M3 MSA plan_kernel Aug 3, 2026
@zheyuf zheyuf closed this Aug 11, 2026
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.

2 participants