feat(attn): dynamic decode attention backend selection at CUDA graph capture#1173
Open
SAzwj wants to merge 2 commits into
Open
feat(attn): dynamic decode attention backend selection at CUDA graph capture#1173SAzwj wants to merge 2 commits into
SAzwj wants to merge 2 commits into
Conversation
Collaborator
AI Code Review - PR #1173Status: LGTM Summary: P0/0 · P1/0 · P2/0 · P3/0 lgtm ready to ci Checklist ✅ (56 items passed)Strengths
|
b5764e2 to
1619565
Compare
Collaborator
AI Code Review - PR #1173Status: BLOCKING Summary: P0/0 · P1/1 · P2/0 · P3/0 Blocking IssuesP1
Checklist Violations (1 fail / 56 total)General Principles Checklist
Strengths
|
1619565 to
e3fbe25
Compare
Collaborator
AI Code Review - PR #1173Status: LGTM Summary: P0/0 · P1/0 · P2/0 · P3/0 lgtm ready to ci Checklist ✅ (55 items passed)Strengths
|
1b041d7 to
ae7777b
Compare
Collaborator
AI Code Review - PR #1173Status: BLOCKING Summary: P0/0 · P1/1 · P2/0 · P3/0 Blocking IssuesP1
Checklist Violations (2 fail / 55 total)General Principles Checklist
Strengths
|
ae7777b to
fdd239d
Compare
Collaborator
AI Code Review - PR #1173Status: BLOCKING Summary: P0/0 · P1/1 · P2/0 · P3/0 Blocking IssuesP1
Checklist Violations (1 fail / 55 total)General Principles Checklist
Strengths
|
fdd239d to
5a92347
Compare
Collaborator
AI Code Review - PR #1173Status: LGTM Summary: P0/0 · P1/0 · P2/0 · P3/0 lgtm ready to ci Checklist ✅ (55 items passed)Strengths
|
Collaborator
|
internal source has been updated, please review the changes! |
5a92347 to
1f81990
Compare
Collaborator
AI Code Review - PR #1173Status: LGTM Summary: P0/0 · P1/0 · P2/0 · P3/0 lgtm ready to ci Checklist ✅ (55 items passed)Strengths
|
Collaborator
|
internal source has been updated, please review the changes! |
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.
Summary
Add runtime selection of the fastest decode attention backend per batch-size
bucket during CUDA graph capture, replacing the fixed first-match priority.
Controlled by
--enable_dynamic_decode_backend(envENABLE_DYNAMIC_DECODE_BACKEND),default OFF — zero behavior change when the flag is off.
How it works
At CUDA graph capture time, for each decode batch-size bucket:
for each candidate backend (XQA TRT, FlashInfer XQA, PyFlashinfer, etc.)
select_stable(requiresconsistent wins, falls back to priority on tie)
prepare_fmha_impllooks upbackend_plan[bs]at decode time(cache miss → fixed priority fallback)
Key changes
Deferred CG capture — move CUDA graph capture out of
PyWrappedModelconstructor to engine-driven
triggerInitCapture(), opening a window forbench/dispatch before graphs are recorded.
dispatch/ package — new
selector,backend_bench,backend_selectormodules + C++ wiring (
enable_dynamic_decode_backendconfig flag,CudaGraphDecodeplan storage,module_basebackend lookup).PyFlashinfer CG replay fix — call
plan()before every CG replay forall decode paths (FA2 and non-FA2) with CG-safe tensor placement, fixing a
hang on replay.
Smoke tests — dyn_decode cases for dense (qwen3 fp8pb, fp8pb tp2) and
moe (qwen3_moe fp8pt deepep). Also adds
kernel_seq_size_per_blocktonext/moe_vl cases and updates affected goldens.
Testing
test_selector,test_backend_bench,test_backend_selector