[Performance]: XQA multi-block is disabled for FP8 KV on SM89, slowing small-batch decode
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- backend, performance
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 15.2k
- Fork
- 3k
- Merge trung bình
- 2 ngày 21 giờ
- Pull request đã merge (30 ngày)
- 477
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của NVIDIA/TensorRT-LLM
-
Bug: AttributeError: 'GptOssConfig' object has no attribute 'rope_scaling_factor' with transformers >= 5.xCó thể đã có người làm @NimaVaziri đã nhận hôm nay. Đang mởPytorch
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NVIDIA/TensorRT-LLM#23406 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Inference runtime Windows
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
NVIDIA/TensorRT-LLM#23394 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: MMLU subsampling changes when evaluators are interleavedCó thể đã có người làm @LeNeLeNeWo đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
NVIDIA/TensorRT-LLM#23273 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Trace-replay Pareto window includes the drain when sessions finish out of admission orderCó thể đã có người làm @sbeierle đã nhận 3 ngày trước. Đang mởTesting
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
NVIDIA/TensorRT-LLM#23077 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
LongBench V2 blog command breaks on inline comments after continuationsCó thể đã có người làm @ddlw đã nhận 25 ngày trước. Đang mởDoc
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
NVIDIA/TensorRT-LLM#21879 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của NVIDIA/TensorRT-LLM
Issue tương tự
-
bug(operator): VolterraOperator built inside jax.jit with a concrete decay raises TracerBoolConversionErrorCó thể đã có người làm @jejjohnson đã nhận hôm nay. Đang mởtype:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
jejjohnson/integrix#144 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
finos/ai-governance-framework#459 ·
-
slurm: a case outcome nested too deep crashes status/collect instead of reading as no outcomeĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
autowarefoundation/autoware_carla_scenario#2963 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
freelawproject/litigant-portal#1307 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
type/bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
h2oai/h2o-llmstudio#1163 ·
Maintainer thường phản hồi trong vòng 1 ngày