[Performance]: XQA multi-block is disabled for FP8 KV on SM89, slowing small-batch decode
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 領域
- backend, performance
調査の方向性
Start in cpp/tensorrt_llm/thop/attentionOp.cpp at the guards in MHA::convertMMHAParamsToXQAParams and MLA::fillXqaParams, then read the related INT8 change in #22216 and report #22213. Check the XQA reference tests and run an op-level test plus racecheck for FP8 on SM89; the issue says these checks have not been run. Done means establishing whether the guard is needed for any configuration and, if it can be removed, validating correctness and the small-batch performance change.
索引モデルが issue の本文から書いたものです。
説明
Proposal to improve performance
Summary
I was profiling Qwen3-8B on an RTX 4090 (SM89) and found an odd batch-size result with FP8 KV cache: the FP8 checkpoint is slower at batch 2 than at batch 1 or 4. At batch 1–2 it uses masked_multihead_attention_kernel instead of XQA.
The reason seems to be this guard in cpp/tensorrt_llm/thop/attentionOp.cpp, in both MHA::convertMMHAParamsToXQAParams and MLA::fillXqaParams (checked on main @ c4b868196):
if (xqaParams.kv_cache_data_type == DATA_TYPE_E4M3 && mSM < kSM_90)
{
xqaParams.multi_block_mode = false;
}
With multi-block disabled, DecoderXQARunner::mayHavePerfGain uses num_kv_heads * batch_size * 4.0 >= SM count. Qwen3-8B has 8 KV heads and the 4090 has 128 SMs, so the heuristic rejects XQA below batch 4. I confirmed the MMHA fallback at batches 1 and 2; I have not measured batch 3.
For the NVFP4 checkpoint (BF16 activations, FP8 KV), MMHA is not supported, so it uses single-block XQA instead. That path gets noticeably slower at longer context lengths.
I removed the FP8/SM89 restriction at both call sites and rebuilt TensorRT-LLM v1.4.0rc4. On this GPU, small-batch decode improves, though there is a 2–3.4% regression in some short-context cases. I am not sure whether the FP8 restriction is still guarding a correctness issue.
Change tested
v1.4.0rc4 still has the INT8 guard from before #22216, so this is the diff I used at both sites:
- if (xqaParams.kv_cache_data_type == DATA_TYPE_INT8
- || (xqaParams.kv_cache_data_type == DATA_TYPE_E4M3 && mSM < kSM_90))
+ if (xqaParams.kv_cache_data_type == DATA_TYPE_INT8)
{
xqaParams.multi_block_mode = false;
}
On main, #22216 already removed the INT8 part. Only the E4M3 restriction remains. This is related to the earlier INT8 report, #22213, but I have only tested FP8 KV on an RTX 4090.
Decode measurements
These are whole decode-step GPU times from Nsight Systems (--cuda-graph-trace=node), median over the steps in one capture per cell. The unmodified engine is nvcr.io/nvidia/tensorrt-llm/release:1.4.0rc4; the patched engine uses libraries rebuilt from tag v1.4.0rc4 in the matching devel container. Profiled time per token was within 1% of the unprofiled run.
| Checkpoint | Batch | Context | Default (ms) | Patched (ms) |
|---|---|---|---|---|
| FP8 | 1 | 128 | 11.76 | 10.21 |
| FP8 | 1 | 2048 | 11.78 | 10.32 |
| FP8 | 1 | 3900 | 11.98 | 10.47 |
| FP8 | 2 | 128 | 13.50 | 10.32 |
| FP8 | 2 | 2048 | 13.60 | 10.64 |
| FP8 | 4 | 128 | 10.28 | 10.53 |
| FP8 | 4 | 2048 | 11.13 | 11.11 |
| NVFP4 | 1 | 128 | 7.28 | 7.43 |
| NVFP4 | 1 | 2048 | 8.14 | 7.59 |
| NVFP4 | 1 | 3900 | 8.96 | 7.75 |
| NVFP4 | 2 | 128 | 7.37 | 7.54 |
| NVFP4 | 2 | 2048 | 8.21 | 7.91 |
| NVFP4 | 4 | 128 | 7.41 | 7.66 |
| NVFP4 | 4 | 2048 | 8.29 | 8.31 |
For the unmodified FP8 checkpoint, MMHA takes about 2.18 ms per step at batch 1 and 3.81 ms at batch 2, compared with about 0.40 ms for the XQA attention path at batch 4. Removing the guard avoids that fallback.
The NVFP4 result is different: it already uses XQA, but with a single block per KV head. In an earlier 1.4.0rc2 trace at batch 1, a single kernel_mha launch took 35.1 µs at context 2048 and 57.9 µs at 3900. With multi-block enabled, those became 17.8 µs and 22.2 µs. The FP8 checkpoint shows the same pattern when XQA is forced (33.7 / 56.5 µs single-block against 15.9 / 21.0 µs).
The short-context slowdown is also visible in the trace. Inside the decode CUDA graph, kernel_mha uses 16 blocks per sequence even at context 128, which is what computeMultiBlockCount gives for the configured max_seq_len of 4096 (I have not traced where the graph capture gets that length). Outside the graph it uses the actual context length. At context 128, a 16-block FP8 launch took 13.6 µs versus 10.4 µs with one block. BF16 KV already uses the same fixed 16-block grid under CUDA graphs, so this behavior is not specific to the patch.
I also repeated the default/patched profiles on 1.4.0rc2; corresponding decode-step times were within 0.06 ms of the rc4 values. The raw tables and build notes are here.
Checks so far
-
XQA reference tests: Built
cpp/kernels/xqafrom main @2c9473ea8bfor SM89.RefCheck.llama_V2_70bandRefCheck.attention_sinkspass with multi-block on and forced off. Thirty consecutive multi-block runs passed with identical output hashes. -
Small-batch kernel tests: I added local cases for 8 KV heads, batches 1/2/4, and contexts 128–4096, including
HEAD_GRP_SIZE=4and BF16 input. They passed the reference checks with multi-block on and off. -
Serving/GSM8K: Ran all 1,319 questions, 5-shot greedy, through
trtllm-serveon rc4. Strict-match accuracy:Checkpoint Default (two runs) Patched Correct/incorrect answers that flipped: default vs default Patched vs each default FP8 86.7% / 87.1% 87.0% 53 76 / 71 NVFP4 85.8% / 86.6% 86.2% 38 47 / 43
The patched accuracy falls within the two default runs for each checkpoint, and the paired McNemar tests did not detect a difference (p >= 0.54). There are more per-question changes than between two default runs, especially for FP8. I have not isolated the source of those changes; a different attention reduction order is one possibility. These tests do not establish that enabling multi-block is safe for all FP8 configurations.
I have not run an op-level test for this change, compute-sanitizer racecheck, batch 3, a build of current main, or tests on other GPUs.
Question
Is the E4M3 && SM < 90 guard still required? #22213 describes the earlier INT8 multi-block restriction and the race fixes that allowed INT8 to be re-enabled. I don't know whether FP8 has a separate issue on SM80–SM89. If it does, could you point me to a reproducer or the affected configuration? (I have seen #17964, the SM89 XQA bug at head size 256 that was fixed in #17976. Qwen3-8B has head size 128, so these runs do not cover that path.)
If multi-block must stay disabled, would it make sense to adjust mayHavePerfGain for FP8 KV so that small-batch FP8 decode does not fall back to the much slower MMHA path? Forcing XQA in my earlier rc2 test helped at batch 1–2, although single-block XQA still slowed down with context length.
I'm happy to put together a PR and an op-level test if removing the restriction is acceptable.
Report of performance regression
No response
Misc discussion on performance
No response
Your current environment (if you think it is necessary)
System Information:
- OS: Ubuntu 24.04.4 LTS (container
nvcr.io/nvidia/tensorrt-llm/release:1.4.0rc4) - Python version: 3.12.3
- CUDA version: 13.4 (nvcc 13.4.59)
- GPU model(s): NVIDIA GeForce RTX 4090 (SM89, 128 SMs)
- Driver version: 580.126.09
- TensorRT version: n/a (PyTorch backend)
- PyTorch version: 2.14.0a0+b2c75dd062.nv26.9
- TensorRT-LLM version: 1.4.0rc4 (release container); patched libraries built from tag
v1.4.0rc4withscripts/build_wheel.py -a "89"
Setup and data:
- TensorRT-LLM:
release:1.4.0rc4; patchedlibtensorrt_llm.so,libth_common.so,libdecoder_attention_{0,1}.so, and Python bindings built fromv1.4.0rc4in the matchingdevelcontainer withbuild_wheel.py -a "89" - Models:
nvidia/Qwen3-8B-FP8,nvidia/Qwen3-8B-NVFP4(Qwen3-8B, 8 KV heads, head dim 128) - KV cache:
dtype: fp8,enable_block_reuse: false,host_cache_size: 0; CUDA graphs with padding enabled; NVFP4 using the Marlin GEMM backend - Scripts, trace summaries, run environments, and GSM8K output: llm-inference-bench, especially
results/profile_rc4,results/profile_rc4_patched,results/gsm8k_rc4, andresults/gsm8k_rc4_patched. The full.nsys-reptraces are reproducible with the scripts but are not committed.
Before submitting a new issue...
- Make sure you already searched for relevant issues, and checked the documentation and examples for answers to frequently asked questions.
- 主要言語
- Python
- スター
- 15.2k
- フォーク
- 3k
- 平均マージ
- 2日 21時間
- マージ済み PR(30日)
- 477
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
NVIDIA/TensorRT-LLM のほかの issue
-
Bug: AttributeError: 'GptOssConfig' object has no attribute 'rope_scaling_factor' with transformers >= 5.x対応中かも @NimaVaziri が今日担当しました。 オープンPytorch
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
NVIDIA/TensorRT-LLM#23406 ·
メンテナーはふだん 1 日以内に返信
-
Inference runtime Windows
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
NVIDIA/TensorRT-LLM#23394 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: MMLU subsampling changes when evaluators are interleaved対応中かも @LeNeLeNeWo が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
NVIDIA/TensorRT-LLM#23273 ·
メンテナーはふだん 1 日以内に返信
-
Trace-replay Pareto window includes the drain when sessions finish out of admission order対応中かも @sbeierle が 3 日前に担当しました。 オープンTesting
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
NVIDIA/TensorRT-LLM#23077 ·
メンテナーはふだん 1 日以内に返信
-
LongBench V2 blog command breaks on inline comments after continuations対応中かも @ddlw が 25 日前に担当しました。 オープンDoc
難易度 1/5 1時間未満 初心者へのやさしさ 91/100
NVIDIA/TensorRT-LLM#21879 ·
メンテナーはふだん 1 日以内に返信
NVIDIA/TensorRT-LLM の issue をすべて見る
似ている issue
-
[Resource]: Spaicelyオープンresource-submission validation-passed
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
hesreallyhim/awesome-claude-code#3875 · コメント 1 件 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
bvis/aegis-hass#725 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
datasektionen/cashflow#468 ·
-
dont call alembic upgrade until we check whether or not the cache DB has an alembic version stampオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
#1643 unrecoverable split: 1 digest with a 403 — two earlier captures of the same URL are real 200sオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
Robin-IA/Congressional-Letters-Dev#1684 ·
メンテナーはふだん 1 日以内に返信