[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 小时
- 30 天内合并 PR
- 477
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 于 2 天前认领。 未关闭
难度 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 于 26 天前认领。 未关闭Doc
难度 1/5 1 小时以内 新手友好度 91/100
NVIDIA/TensorRT-LLM#21879 ·
维护者通常 1 天内回复
查看 NVIDIA/TensorRT-LLM 的全部 Issue
相似的 Issue
-
A JSON chat answer blocks the backend event loop for the whole RAG run可能已有人在做 @NopeCharon 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
The-OpenROAD-Project/ORAssistant#656 ·
维护者通常 1 天内回复
-
bug(operator): VolterraOperator built inside jax.jit with a concrete decay raises TracerBoolConversionError可能已有人在做 @jejjohnson 今天认领。 未关闭type:bug
难度 2/5 1-3 小时 新手友好度 72/100
jejjohnson/integrix#144 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
finos/ai-governance-framework#459 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
autowarefoundation/autoware_carla_scenario#2963 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复