Performance: fused MHA reaches 77-125 TFLOPS for BERT-large attention on RTX PRO 6000 Blackwell, 2-4x below FlashAttention-2 on the same GPU

Ouverte
#4,881 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 6 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
8/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
cpp, python

Piste de recherche

The slow kernel is _gemm_mha_v2 in the trtexec layer profile, and the reproduction is the trtexec command sequence in the issue body with the profile JSON files. Start by reproducing the FP8 engine per-layer timings at 256 and 640 tokens. Finding why the kernel choice depends on the surrounding graph would mean working inside TensorRT's kernel selection, which is closed source. Done would mean the fused MHA reaching FlashAttention-2 throughput on the same shapes.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Module:Performance

Description

In BERT-style encoders on an RTX PRO 6000 Blackwell Server Edition (SM120), TensorRT's fused attention kernel (_gemm_mha_v2 in the layer profile) runs at 77-125 TFLOPS. FlashAttention-2 on the same GPU and shapes (through vLLM's encoder attention) runs at 204-332 TFLOPS. The gap grows with the sequence length, and attention ends up as the largest part of the engine: 66.5 ms of the FP8 engine's 160.8 ms at 128 sequences x 640 tokens.

Model: BAAI/bge-reranker-v2-m3 (XLM-R large: 24 layers, 16 heads of 64), 128 sequences without padding (attention mask all ones), FP8 and NVFP4 engines (ModelOpt's default configs quantize only the Linear layers, so the attention inputs are FP16 in both). Time of the fused MHA kernel per layer from trtexec --dumpProfile --separateProfileRun, and TFLOPS counting QK^T and PV only (4 x 128 x 16 x L^2 x 64 FLOP per layer):

tokens per sequence FP8 engine NVFP4 engine FlashAttention-2 (flash_fwd_kernel in vLLM, same GPU)
256 0.297 ms (116 TFLOPS) 0.502 ms (68)
320 0.263 ms (204)
384 0.730 ms (106) 1.036 ms (75)
448 0.843 ms (125) 1.366 ms (77)
512 1.386 ms (99) 1.744 ms (79)
576 2.037 ms (85) 2.172 ms (80)
640 2.774 ms (77) 2.632 ms (82) 0.645 ms (332)
768 3.873 ms (80) 3.714 ms (83)
  • The attention inputs are the same in both engines, yet the NVFP4 engine's MHA is slower than the FP8 engine's up to 512 tokens, so the kernel choice seems to depend on the surrounding graph.
  • Builder optimization level 3 (default), TensorRT 11.3.0.99 from the Triton 26.09 image. TensorRT 11.4.0.106 builds the same kernel mix with the same engine times at 320 and 640 tokens.

Environment

TensorRT Version: 11.3.0.99 (also 11.4.0.106)

NVIDIA GPU: RTX PRO 6000 Blackwell Server Edition (SM120)

NVIDIA Driver Version: 595.91.07

CUDA Version: 13.4

CUDNN Version: not used

Operating System: Ubuntu 24.04 (GCP g4-standard-48)

Python Version (if applicable): 3.12

Baremetal or Container (if so, version): nvcr.io/nvidia/tritonserver:26.09-py3

Relevant Files

Model link: BAAI/bge-reranker-v2-m3, quantized with ModelOpt (FP8_DEFAULT_CFG, or NVFP4_DEFAULT_CFG with Q/K/V exported as one MatMul, see #4879) and exported with get_onnx_bytes_and_metadata(..., weights_dtype="fp16"). The ONNX files (about 700 MB each) can be shared on request.

Steps To Reproduce

trtexec --onnx=model.onnx --saveEngine=model.plan --minShapes=input_ids:1x128,attention_mask:1x128 \
  --optShapes=input_ids:32x640,attention_mask:32x640 --maxShapes=input_ids:128x768,attention_mask:128x768 \
  --profilingVerbosity=detailed --skipInference
# token ids in [1000, 200000), attention mask all ones, int64
for L in 256 384 448 512 576 640 768; do
  trtexec --loadEngine=model.plan --shapes=input_ids:128x$L,attention_mask:128x$L \
    --loadInputs=input_ids:ids-$L.bin,attention_mask:mask-$L.bin --warmUp=1000 --duration=5 --noDataTransfers \
    --useSpinWait --separateProfileRun --profilingVerbosity=detailed --exportProfile=profile-$L.json
done

The _gemm_mha_v2 rows of each profile give the per-layer time.

Have you tried the latest release?: yes, 11.4.0.106.

Langage dominant
C++
Étoiles
13.5k
Forks
2.4k
Merge moyen
6 j 21 h
PR mergées (30 j)
3

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de NVIDIA/TensorRT

Toutes les issues de NVIDIA/TensorRT

Issues similaires

Plus d'issues C++

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.