Repository navigation
[#20379][perf] trtllm-gen FMHA: split the KV partials of a row across thread groups in fmhaReductionKernel - #20380
Draft
lucifer1004 wants to merge 2 commits into
Draft
lucifer1004 wants to merge 2 commits into
lucifer1004 wants to merge 2 commits into
Conversation
…across thread groups in fmhaReductionKernel Signed-off-by: Zihua Wu <13583761+lucifer1004@users.noreply.github.com>
1 of 2 tasks
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 #20379.
fmhaReductionKernelmerges the multi-CTA-KV partials of each output row in one thread, serially over allnumCtasKvpartials. At low batch its grid is only a few CTAs, so the kernel costs a fixed several microseconds per attention call.This PR adds a
KvSplittemplate parameter:KvSplitgroups. Group g runs the existing online-softmax merge over partials g, g + KvSplit, ... of the same rows. Group 0 then combines the per-group (max, sum, O) through shared memory, rescaling each byexp2(scaleLog2 * (groupMax - max))and skipping empty groups. Sinks, softmax-stats export and the store are unchanged and done by group 0.1/KvSplitof the rows (NumBytePerSliceis per group), so the host launchesKvSplittimes more slices.TLLM_FMHA_REDUCTION_KV_SPLIT=<2|4|8|16>is an upper bound, and the host halves it until every group holds at least one whole row and the slices still fit the existing2 x SMs / gridCTA budget. Unset or 1 selectsKvSplit = 1, which runs the same per-thread loop as before.KvSplit > 1.Measured on SM107 with Kimi K3 MLA decode (grouped Q64 kernels, batch 1): per-call time -1.9 / -7.3 / -7.4 / -6.5 us at 2K / 8K / 32K / 128K with KvSplit 8, and an end-to-end decode step of -0.10 / -0.23 / -0.21 ms at 2K / 32K / 128K (details in #20379). It is opt-in for now because SM100 / SM103 are not measured.
Test Coverage
runFmhaReductiondirectly. With the variable unset the launch isKvSplit = 1, the same per-thread loop as before.TllmGenFmhaRunnermicrobenchmark; end-to-end accuracy unchanged with KvSplit 8.nvcc -arch=sm_100acompile offmhaReduction.cuand pre-commit clean. Not yet run on a GPU; SM100 / SM103 not run. Happy to add a dedicated reduction test with synthetic partials if reviewers want one.PR Checklist