Skip to content

Add fmha_v2 attention backend for SM90/120 - #23112

Merged
YAMY1234 merged 2 commits into
sgl-project:mainfrom
akhilg-nv:fmha_v2
Aug 19, 2026
Merged

YAMY1234 merged 2 commits into
sgl-project:mainfrom
akhilg-nv:fmha_v2

Conversation

@akhilg-nv

@akhilg-nv akhilg-nv commented Apr 18, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Enables TRT-LLM's fmha_v2 prefill attention backend for SM90/120. This backend is more performant than the current default (FA3), and also enables skip-softmax feature, which can further boost performance for long-context / applications where attention output is sparse.

Modifications

Baseline enablement of trtllm's fmha_v2 prefill kernel for SM90/120. #32272 is needed for further perf improvement, and #32268 / #32269 are used for the MTP accuracy reporting.

Accuracy Tests

python3 -m sglang.launch_server \
  --model /SGL/models/Qwen3-Next-80B-A3B-Thinking-FP8 \
  --tp 4 --mem-fraction-static 0.8 \
  --disable-radix-cache --mamba-ssm-dtype float32 \
  --moe-runner-backend deep_gemm --attention-backend trtllm_mha \
  --trust-remote-code --port 30000
# --kv-cache-dtype fp8_e4m3
Config KV dtype Score Repeat range
FA3 bf16 0.725 0.712-0.742
fmha_v2 (trtllm_mha) bf16 0.723 0.702-0.753
FA3 + MTP bf16 0.734 0.712-0.758
fmha_v2 prefill + MTP (fa3 verify) bf16 0.721 0.707-0.732
FA3 fp8_e4m3 0.727 0.707-0.747
fmha_v2 (trtllm_mha) fp8_e4m3 0.724 0.682-0.753

MTP

Add to server launch: --speculative-algorithm NEXTN --speculative-num-steps 3 \ --speculative-eagle-topk 1 --speculative-num-draft-tokens 4

Config Accept len Accept rate GPQA-20 score
FA3 + MTP (bf16) 2.37 (2.35) 0.46 (0.45) 0.750
fmha_v2 prefill + MTP (bf16) 2.45 (2.30) 0.48 (0.43) 0.700
pure trtllm_mha + MTP w/ XQA mask fix (bf16, 10q) 2.20 0.40 0.70

Speed Tests and Profiling

The e2e performance is not improved with just this PR because it requires a large copy operation before the compute kernel to interleave KV. flashinfer-ai/flashinfer#3575 and #32272 address this issue.

Unit Kernel Measurements show ~15% improvement over FA3 over a variety of problem sizes, reaching 20% at small problems.

image

Skip-Softmax

This feature can provide additional speedup, especially for long-context inference where the attention logits are sparse. We define the threshold factor \lambda := a / L where a is a hyperparameter, and L is the sequence length. To demonstrate the potential speedup, we keep a = 1000 here for simplicity.

ISL Effective threshold (1000 / ISL) bf16 gain fp8 gain
8k 0.122 +1.8% +0.2%
32k 0.031 +5.2% +1.7%
128k 0.008 +12.9% + 3.5%

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ⏳ Run #32205487242
Latest PR Test (Extra): ❌ Run #32205486818

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@github-actions github-actions Bot added the blackwell SM100/SM120 label Apr 18, 2026
@akhilg-nv
akhilg-nv force-pushed the fmha_v2 branch 5 times, most recently from f8cbd73 to 3e4d3ca Compare July 21, 2026 02:33
@akhilg-nv
akhilg-nv marked this pull request as ready for review July 21, 2026 02:39
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@nvpohanh

nvpohanh commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

@akhilg-nv could you fix the merge conflict? thanks!

@nvpohanh

nvpohanh commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

cc @b8zhong for vis

@nvpohanh

Copy link
Copy Markdown
Collaborator

@akhilg-nv could you fix the conflicts? thanks

@b8zhong

b8zhong commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

@akhilg-nv I agree with Po-Han here: #32272 (comment)

By the way, if the additional diff is not super complex and is related, we can keep always keep it it in 1 PR

@akhilg-nv

Copy link
Copy Markdown
Contributor Author

@akhilg-nv I agree with Po-Han here: #32272 (comment)

By the way, if the additional diff is not super complex and is related, we can keep always keep it it in 1 PR

I've left it separated for now because #32272 is dependent on a flashinfer API change (flashinfer-ai/flashinfer#4124) that has not yet merged, but this PR is ready to merge at anytime.

@YAMY1234

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Aug 17, 2026
@YAMY1234 YAMY1234 self-assigned this Aug 18, 2026

@YAMY1234 YAMY1234 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two SM120 compatibility notes inline.

@YAMY1234
YAMY1234 merged commit 5d12280 into sgl-project:main Aug 19, 2026
62 of 96 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blackwell SM100/SM120 run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants