Repository navigation
[Perf] [NVIDIA] fp8_fa_sm120: Use the block-scaled MMA encoding - #43390
Conversation
|
One follow-up question, separate from this PR: on SM120 the multimodal_gen default is torch_sdpa. across 10 diffusion shapes (FLUX, Wan, HunyuanVideo, H3, ...) fp8_fa_sm120 is 2.1-2.7x faster than that default on a 5080. sageattention is ~3-6% faster still, but it is an optional install. would you be open to making fp8_fa_sm120 the default on SM120 when sageattention is not installed (starting with H3)? if yes, what evidence would you want: multi-seed e2e PSNR/SSIM, real pipeline s/step, anything else? note: tested on RTX 5080 only. per the RTX PRO Blackwell whitepaper (as cited in flashinfer#5963), RTX PRO 6000 runs FP32-accumulate FP8 at full rate, so I expect this change to be neutral there. not measured yet. |
…MA encoding [batch-apply-b 2026-10-14] Squash of single upstream commit 65bd9ae (cherry-pick -x, clean: all 3 PR files byte-identical between PR base 408f5d0 and merge-4 HEAD — no local drift in kernel.py/plan.py; local fp8_fa_sm120 history lives in fused_prep.py/backends/layer.py which this PR does not touch). Block-scaled MMA (kind::mxf8f6f4, UE8M0 unit scales) for QK+PV on SM120; plain-encoding fallback kept via block_scaled_mma=False const_expr.
…layers in BF16 [batch-apply-b 2026-10-14] Cherry-pick -x of e012ffe (single commit). Backend file byte-identical to PR base; test file auto-merged 3way — PR base pre-dates sgl-project#43390's test_block_scaled_mma_is_bit_equal insertion but hunks are disjoint (new tests land after test_causal_falls_back_to_cudnn). bf16_layers + min_seq_len --attention-backend-config escape keys; complementary to sgl-project#43390 (different hunks/files: backends/*.py + docs vs kernels/ops/*).
|
/tag-and-rerun-ci |
|
CI is blocked by the required-base gate ( |
This comment has been minimized.
This comment has been minimized.
|
@BBuf merged main and CI is green, ready to merge from my side |
The fp8_fa_sm120 CuTe-DSL kernel uses only FP8 mma.sync and cp.async, which Ada (RTX 40, L4, L40) has. Since sgl-project#43390 it selects the block-scaled MMA only on sm_120a/f and sm_121a/f and keeps the plain FP8 MMA elsewhere, so it compiles and runs unchanged on sm_89 with nvidia-cutlass-dsl 4.8.0. - Share one capability set, FP8_FA_SM120_CAPABILITIES = {(8, 9), (12, 0)}, between the resolver and the backend's per-call fallback check. - Run the unit tests on SM89; skip the block-scaled bit-equality test where the block-scaled MMA is unavailable. - Document SM89 support and the cutlass-dsl requirement. Unit tests on an L4 (sm_89): 9 passed, 1 skipped (bit-equality). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Motivation
fp8_fa_sm120computes QK and PV with the plain FP8mma.sync(E4M3 x E4M3, FP32accumulate). On GeForce SM120 this instruction runs at half rate. I measured the raw MMA
peak on an RTX 5080 with back-to-back chains and no memory traffic:
QMMA.16832.F32.E4M3.E4M3QMMA.SF.16832.F32.E4M3.E4M3.E8The block-scaled encoding (
kind::mxf8f6f4.block_scale) multiplies each operand by aUE8M0 scale, one byte per 32 k elements. With every scale byte set to 0x7F (2^0) the math
is the same product. On random finite E4M3 inputs, 0 of 704 M accumulator registers differ
between the two instructions.
So the kernel was limited by the instruction encoding, not by its design.
Modifications
kernels/ops/attention/fp8_fa_sm120/kernel.pywarp.MmaMXF8Opwhen the compile target has it (sm_120a/f,sm_121a/f),
warp.MmaFP8Opotherwise.registers: no shared memory, no extra loads.
cute.gemmcalls pass[operand, scale]pairs.kernels/ops/attention/fp8_fa_sm120/plan.py: the publicfp8_attention()signature isunchanged. An internal compile-time parameter selects the encoding. It is not a user
option, because the output is bit-equal and there is no speed against accuracy choice.
Operand layouts, shared memory, the softmax, the P pack and the prep do not change.
Register count goes from 244 to 250, no stack.
Accuracy Tests
The output is bit-identical to
main. Same inputs (seed 42), SHA-256 over the O and LSEbytes,
mainagainst this branch:Unit tests: 10/10, including the new bit-equality test.
Speed Tests and Profiling
RTX 5080, H=56, D=128, median of 5 runs, same process and inputs.
main(ms)main(ms)The full call is 1.47x faster at both lengths. Against cuDNN SDPA BF16 on the same card
(226 ms at S=30272) the backend is now 2.6x faster, was 1.8x.
Checklist
CI States
Latest PR Test (Base): ✅ Run #39159895157
Latest PR Test (Extra): ❌ Run #39159895109
Latest PR Test (AMD ROCm 10): ❌ Run #39159895224