[CuTe, SM120] Optimize backward on consumer Blackwell - #2771
Draft
guoriyue wants to merge 1 commit into
Draft
Conversation
Add SM120-specific 256-thread accumulator, dQ/dKV postprocess, and vector-atomic mappings for CuTe DSL backward. Select tuned dense D64 and D128 configurations, repair the register-resident P/dS path, and gate masking optimizations to compatible layouts. Extend CUDA coverage for long, variable-length, tensor-max-seqlen, and FakeTensor compilation paths. Co-authored-by: thad0ctor <robert.gilbreth@gmail.com>
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
This adds a current-main SM120 CuTe DSL backward path for consumer Blackwell, validated on RTX 5090, without changing the public
flash_attn.cuteAPI.max_seqlenbackward paths.Mainline performance delta
BF16, 32K total tokens, model width 2048. The run order was patch / unmodified main / patch, with five timing blocks per run. Values are
main latency / median(two patch runs); greater than 1 means this PR is faster.All twelve cells improve. The geometric-mean speedup over current main is 1.098x, with a range of 1.034x to 1.154x.
FA2 parity on RTX 5090
The same 32K-token BF16 matrix compares native FA2 with the patched FA4 path. Values are
FA2 latency / FA4 latency.FA4 wins ten of twelve cells and is within 0.5% of FA2 in the remaining two. FP16 D128 S8192 measures 0.994x non-causal and 0.993x causal.
Correctness
Environment: RTX 5090 (SM120), PyTorch 2.11.0+cu128, CuTe DSL 4.6.0.dev0.
tests/cute/test_flash_attn_fast.py: 196 passed, 48 expected skips on real GPU;max_seqlencache reuse, and zero-Q dK/dV behavior pass;git diff --check,py_compile, and Ruff pass.Scope and overlap
The import surface remains:
The patch is limited to SM120 backward dispatch/kernel plumbing and tests. It does not add forward TMA, SplitKV, paged KV, D256, FP8, or FA3 support.
#2634 is a broader SM120 effort and contains overlapping backward work. This PR is intentionally a focused current-main extraction with isolated correctness and performance evidence; if #2634 lands first, this draft should be re-evaluated or closed rather than merged redundantly.
Implementation note
The long-D128
AtomLayoutMdQ=2writer requires a 256-thread dQ postprocess; the default 128-thread bridge produces large dQ errors. The defaultAtomLayoutMdQ=4path intentionally retains its correct, faster 128-thread postprocess. SM120 uses the SM80 universal register-to-shared mapping rather than the SM90stmatrixmapping.