Repository navigation
[CUDA] Bound fpA_intB tactic profiling time for expensive GEMMs - #32758
Merged
Tianlei Wu (tianleiwu) merged 1 commit intoSep 24, 2026
Merged
Conversation
Every candidate tactic ran 5 warmup and 10 timed launches regardless of cost, so profiling a large GEMM took seconds per tactic. Profiling Qwen3.8-27B's lm_head (N=248320, K=5120) at M=4096 took about 50 s, which stalls the first serving step that reaches an unprofiled M bucket. Time one warm launch first. Launches of at most 2 ms keep the 10-run average. Costlier tactics are skipped when already 1.5x slower than the best so far, and are otherwise averaged within a 20 ms budget. The lm_head lazy profile drops to about 12 s and picks the same tactic.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused implementation is consistent with its stated policy and has appropriate boundary coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Bounds CUDA fpA_intB GEMM tactic-profiling latency while preserving full sampling for inexpensive tactics.
Changes:
- Adds probe-based pruning and a 20 ms timing budget.
- Uses RAII for CUDA events and adds policy unit tests.
| File | Description |
|---|---|
onnxruntime/​contrib_ops/​cuda/​llm/​gemm_profiler.h |
Implements adaptive tactic timing. |
onnxruntime/​test/​providers/​cuda/​test_cases/​matmul_nbits_workspace_test.cc |
Tests timing, budgeting, and pruning thresholds. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Baiju Meswani (baijumeswani)
approved these changes
Sep 23, 2026
Tianlei Wu (tianleiwu)
deleted the
tlwu/20260923/fpa_intb_adaptive_profiling
branch
September 24, 2026 00:37
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.
Description
The fpA_intB MatMulNBits tactic profiler ran 5 warmup and 10 timed launches for every candidate tactic, no matter how long a launch took. For large GEMMs this makes profiling very expensive. On H200, profiling Qwen3.8-27B's
lm_head(N=248320, K=5120, INT4) at M=4096 covers 60 valid tactics with a median launch time of 50 ms. That is about 48 s for one GEMM shape.The cost matters because unprofiled M buckets are profiled lazily inside
Compute(). The default initial sweep stops at M=2048, so the first run with M=4096 (for example, a GenAI Engine withmax_scheduled_tokens=4096doing batched prefill) stalls. In an 8-request, 512-token-prompt batch the first step took 71–98 s. The same step takes 1–2 s once M=4096 is profiled. That looked like a hang in end-to-end serving tests.This change makes tactic timing adaptive:
Summary of Changes
onnxruntime/contrib_ops/cuda/llm/gemm_profiler.hGetProfileTimedRuns()(the timing policy).profileTacticForProblem()now probes one warm launch, prunes or budgets the timed runs, and uses RAII for its CUDA events.onnxruntime/test/providers/cuda/test_cases/matmul_nbits_workspace_test.ccTesting
MatMulNBitsWorkspace.*CUDA EP internal tests: 26/26 pass, including the newTacticProfilerTimedRunsPruneOnlyExpensiveSlowTactics.onnxruntime/test/python/quantization/test_op_matmulnbits_prepacked_cuda.py: 4 passed, 9 skipped because the weight packer is not available in the local build.Standalone MatMulNBits node,
lm_headshape (N=248320, K=5120, block 32, INT4):Tactic selection across the 8 Qwen3.8-27B GEMM shapes and 13 M buckets (1…4096):
End to end: Qwen3.8-27B INT4 + DFlash2, GenAI Engine, batch 8 × 512-token prompts, H200:
max_scheduled_tokens=4096(lazy M=4096 profile)max_scheduled_tokens=512(load + run)max_scheduled_tokens=512Motivation and Context
Reported from a GenAI Engine probe that appeared to stall indefinitely with
max_scheduled_tokens=4096. Root cause:Deployments that know their largest M can still set
ep.cuda.fpa_intb_profile_mso all profiling happens at session creation. This change makes both paths considerably cheaper.