perf(gemm): update mm_fp4 cute-dsl tactic heuristic and autotune over a top-N ranked list#3948
Conversation
# Conflicts: # flashinfer/gemm/gemm_base.py
📝 WalkthroughWalkthroughCuTe DSL SM100 FP4 GEMM tactic selection now uses centralized scoring, shared candidate definitions, and scale-factor-aware caching and feasibility checks. The runner groups tactics by configuration, ranks them, and limits tuning to 32 configurations while preserving prefetch variants. ChangesSM100 FP4 tactic selection
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant CuteDSLFp4GemmRunner
participant _select_sm100_mm_fp4_cute_dsl_tactic
participant _compute_tactic_for_m
participant _score_sm100_mm_fp4_tactic
CuteDSLFp4GemmRunner->>_select_sm100_mm_fp4_cute_dsl_tactic: request tactic with sf_vec_size
_select_sm100_mm_fp4_cute_dsl_tactic->>_compute_tactic_for_m: compute tactic for M bucket
_compute_tactic_for_m->>_compute_tactic_for_m: check candidate feasibility with sf_dtype
_compute_tactic_for_m->>_score_sm100_mm_fp4_tactic: score feasible tile, cluster, and swap combinations
_score_sm100_mm_fp4_tactic-->>_compute_tactic_for_m: return candidate score
_compute_tactic_for_m-->>_select_sm100_mm_fp4_cute_dsl_tactic: return best tactic
_select_sm100_mm_fp4_cute_dsl_tactic-->>CuteDSLFp4GemmRunner: return selected tactic
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request refactors the SM100 FP4 GEMM tactic selection by introducing a scoring function, _score_sm100_mm_fp4_tactic, to rank and limit the number of autotuning configurations. The feedback suggests adding a guard for zero-dimension inputs to prevent division-by-zero errors, simplifying a redundant tuple lookup in the scoring calculation, and cleaning up an imprecise type annotation.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@flashinfer/gemm/gemm_base.py`:
- Around line 54-58: Import _SM100_MMA_TILER_MN_CANDIDATES from kernels.utils
alongside _SM100_CLUSTER_SHAPE_MN_CANDIDATES, then remove the duplicate local
definition near the SM100 tactic logic. Keep all existing references using the
shared imported candidate list.
In `@flashinfer/gemm/kernels/utils.py`:
- Around line 55-77: Add a feasibility filter in _compute_tactic_for_m before
calling _score_sm100_mm_fp4_tactic, validating each tile/cluster/swap_ab
combination against the supported Sm100BlockScaledPersistentDenseGemmKernel
contract, including tile_n constraints. Skip unsupported candidates before
ranking while preserving the existing 256/M cluster guard and tactic selection
behavior for feasible candidates.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 74b97ecf-f0ca-4c5a-a9b3-9873d5477508
📒 Files selected for processing (2)
flashinfer/gemm/gemm_base.pyflashinfer/gemm/kernels/utils.py
|
/bot run tests/gemm |
qiching
left a comment
There was a problem hiding this comment.
LGTM.
one thing i want to highlight: top-N is ranked by the same heuristic as top-1, so anything below the cut never gets profiled. Mostly fine, but i noticed that 2048×36864×4608 is 0.86x autotuned, ~16% slower with tuning on. Since after's set is a subset of the full ~120, tuning should be ≤ before modulo noise, so the best config for that shape is likely falling outside the top-16. Can you check whether it's pruning or just variance? If pruning: only 16 distinct configs are explored, so ranking prefetch or bumping N could recover it.
Worth nailing before we pitch re enabling autotuning to vLLM.
|
[FAILED] Pipeline #57846035: 13/20 passed |
|
My only concern is the Top-1 heuristic runtime on a cache miss would be 10x longer. Previously it was So if 1-2 ms heuristic runtime is okay on the first call/subsequent call with |
Thanks @qiching, upon remeasuring, the regression is not as severe. so 0.86x is likely from an unlucky measurement. In general however, pruning an autotune list means we are losing something; if we do not, it means the configs were not helpful to begin with. We could consider consulting vLLM about it, but we could claim that a max perf loss of <20% with geomean less than 0.5% would be a good tradeoff for substantially reduced autotuning time. |
make sense to me. thanks for confirming. @bkryu |
📌 Description
Autotuning
mm_fp4(backend='cute-dsl')currently profiles all ~120 valid tactics per shape. Each kernel compilation requires ~2.5 sec, which substantially deteriorates experience when all tactics are compiled.Current PR:
A PR for parallelizing and disk-caching ranked tactics for further reduction will follow after #3874
Performance Data measured on B200
Median kernel times are in µs. Top-1 means heuristic pick without autotune. Measured via
flashinfer_benchmark.pySpeedup >1.0 means after is faster than before.
Tuning/training testlist for deriving heuristic (147 shapes) — geomean speedup: top-1 1.01x, autotuned 1.00x
Holdout testlist for based on realistic transformer shapes (70 shapes) — geomean speedup: top-1 1.05x, autotuned 1.00x
🔍 Related Issues
🚀 Pull Request Checklist
Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete.
✅ Pre-commit Checks
pre-commitby runningpip install pre-commit(or used your preferred method).pre-commit install.pre-commit run --all-filesand fixed any reported issues.🧪 Tests
unittest, etc.).Reviewer Notes
Summary by CodeRabbit