Repository navigation
[trtllm_mha] perf: Stop allocating per-layer scratch inside the decode CUDA graph - #33063
Conversation
…reconcile-pr-33063-20260803
|
/rerun-test test/registered/models_e2e/test_qwen35_fp4_flashinfer.py test/registered/models_e2e/test_qwen35_fp4_mtp.py test/registered/lora/test_lora_qwen3_5_35b_a3b_logprob_diff.py test/registered/moe/test_flashinfer_a2a_cutedsl_v2.py |
|
/rerun-test test/registered/8-gpu-models/test_qwen35.py |
|
1 similar comment
|
|
/rerun-test test/registered/models_e2e/test_qwen35_fp4_flashinfer.py test/registered/models_e2e/test_qwen35_fp4_mtp.py |
|
/rerun-test test/registered/lora/test_lora_qwen3_5_35b_a3b_logprob_diff.py test/registered/moe/test_flashinfer_a2a_cutedsl_v2.py |
|
/rerun-test test/registered/8-gpu-models/test_qwen35.py |
|
Results for 🚀 |
|
Results for 🚀 🚀 |
|
Results for 🚀 |
|
/rerun-test test/registered/quant/test_llama8b_nvfp4_kv_cache_sm120.py test/registered/cp/test_gpt_oss_4gpu_mxfp4_cp.py test/registered/cp/test_gpt_oss_4gpu_mxfp4_cp.py |
|
Results for 🚀 🚀 |
|
/rerun-test test/registered/quant/test_llama8b_nvfp4_kv_cache_sm120.py test/registered/cp/test_gpt_oss_4gpu_mxfp4_cp.py |
|
Results for 🚀 🚀 |
|
/rerun-test test/registered/quant/test_llama8b_nvfp4_kv_cache_sm120.py test/registered/cp/test_gpt_oss_4gpu_mxfp4_cp.py test/registered/models_e2e/test_gpt_oss_4gpu_mxfp4.py |
|
Results for 🚀 🚀 🚀 |
Motivation
Two allocations in the TRTLLM-MHA decode path emit a fill kernel per attention
layer per forward, and CUDA-graph capture bakes them into every replay:
trtllm_batch_decode_with_kv_cachecall when the caller supplies none — eventhough its own docstring says the kernel self-resets the counters at the end of
each launch and that callers should own the buffer.
fused_fp8_qkv_kv_cachebuildsfloat32 [1]scale tensors withtorch.ones()when
layer.k_scale/v_scaleareNone, which is every layer of anycheckpoint without KV scales.
Three launches per full-attention layer, moving 4, 4 and ~600 bytes. They also sit
between two PDL-linked kernels, so
_fused_qk_rmsnorm_rope_gate'sgdc_launch_dependents()was signalling aFillFunctorinstead offused_fp8_qkv_kv_cache'sPDLWaitPrimary.Modifications
trtllm_mha_backend.pyonly:make_persistent_multi_ctas_kv_counter_buffer(already used bytrtllm_mla_backendanddsa_backend), sized for the widest batch the backendcan see, and pass it to the decode call and all three target-verify calls.
FlashInfer rejects an undersized buffer, never an oversized one.
float32 [1]ones tensor on the backend for layers with no checkpointKV scale.
Both are allocated at backend construction, outside graph capture.
Correctness
Semantically an identity: the same constant
1.0scale reaches the kernel, and thecounter buffer contract is FlashInfer's documented one.
GSM8K 5-shot, full 1319 questions,
sglang.test.few_shot_gsm8k --parallel 128,temperature 0,
--max-new-tokens 4096:Run-to-run spread on this harness is ~2pp, larger than the gap between arms.
Performance
Qwen3.5-397B-A17B-FP8, 4xB200, TP4,
trtllm_mha+flashinfer_trtllmMoE, fp8weights + fp8 KV cache, bs=1, input-len 8192.
-90us per decode step, 1.64% of a 5.490ms step. 45 launches removed (3 per
full-attention layer); the full-attention layer span drops 6.02us, x15 such layers.
main:

PR:

The prologue in execution order, medians over the 15 full-attention layers:
CI States
Latest PR Test (Base): ❌ Run #30963620445
Latest PR Test (Extra): ❌ Run #30963620279