Repository navigation
[#20634][perf] CSA2: tinygemm2 for the BF16 wq_a / wkv projections at decode on SM107 - #20636
Draft
lucifer1004 wants to merge 1 commit into
Draft
lucifer1004 wants to merge 1 commit into
lucifer1004 wants to merge 1 commit into
Conversation
…ons at decode on SM107 Signed-off-by: Zihua Wu <13583761+lucifer1004@users.noreply.github.com>
This branch has not been deployed
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
Fixes #20634.
Depends on #20512: the new path is taken only when the CSA2 projections run in BF16 on SM107, which is what #20512 enables. Without #20512 the DeepSeek-V4.1 model always requests MXFP8 projections, which SM107 rejects and SM100/SM103 keep, so nothing changes for the model.
At decode sizes the two hidden-state projections of
DeepseekV41Attention(wq_a: 5120 -> 1280,wkv: 5120 -> 512) are N-small, K = hidden_size GEMMs. In BF16 on Vera Rubin (SM107) cuBLAS reaches 0.9-2 TB/s on them;trtllm::tinygemm2streams the same weights 1.6-1.8x faster. This PR uses it for those two projections in the BF16 projection mode on SM107:post_load_weightscopies thewq_aandwkvweights into one row-concatenated[1792, 5120]tensor and rebinds bothLinearweights as views into it (no extra memory). Checkpoint reloads copy into the views, so the aliasing survives them.[1, N]strides.Linearpath. This includes more tokens, other dtypes, unaligned or non-contiguous inputs, a weight that is no longer a view of the concatenated tensor (for example a replacedParameter), MXFP8 projections, and other GPUs.tinygemm2callscudaTriggerProgrammaticLaunchCompletion()before its output stores and is always launched with programmatic stream serialization (the concern in #15729 / #15790, both closed). The consumers here, theq_norm/kv_normRMSNorms (FlashInfer, PDL enabled by default), wait withgriddepcontrol.wait, which covers completion and memory visibility of the preceding grid. We also stress-tested this exact pattern (see Test Coverage). Moving the trigger after the stores in the kernel would still be the more robust fix and is left to a separate change.Measured on Vera Rubin (TP4/EP4, DeepSeek-V4.1-Flash, batch 1, 32K context, CUDA graphs, BF16 CSA2 projections):
Test Coverage
tests/unittest/_torch/attention/sparse/csa2/test_module.py::test_tinygemm_hidden_state_projections(new; SM107 only). It builds the native test module (BF16 projections), callspost_load_weights, and checks:torch.ops.trtllm.tinygemm2sees one fused call for 1 token, two calls for 2 and 8 tokens, and none for 9 and 32;F.linearreference;wkvparameter, which falls back to separate calls._native_model(test helper) now skips non-SM100/103 GPUs only for MXFP8 projections, so the BF16 module can be built on SM107.test_module_sends_whole_context_and_generation_phasesbuilds its module without__init__and now sets the two new attributes.test_module.py73 passed, 17 skipped, 1 failed;post_load_weights);test_module.py72 passed, 17 skipped, 2 failed.test_module_composed_flash_helper[flash_mla]: the FlashMLA module is not installed in our image.pre-commiton the changed files: clean.PR Checklist