[Bug]: trtllm-gen persistent context FMHA hangs on SM103 (B300/GB300): synccheck "Missing wait"

Đang mở
#22,799 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
5/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp, python, pytorch
Lĩnh vực
backend, performance

Hướng nghiên cứu

The path is FmhaDispatcher → TileScheduler::Persistent → fmhaSm103aKernel_…PersistentContext; reproduce with the supplied repro_issue.py under compute-sanitizer --tool synccheck, comparing max_num_tokens=256 and 16384. Compare the SM103 persistent context cubin SASS with the SM100a build, which waits on every iteration. The payload says the fix is in generated cubins, not this repository; done means regenerated SM103 context cubins where softmax WG1 waits on its ping-pong barrier on the last KV iteration, with a clean synccheck run.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug Customized kernels
System Info
  • GPU: NVIDIA B300 SXM6 AC (sm_103, 148 SMs), driver 580.126.20
  • CPU: x86_64; OS: Ubuntu 24.04.4 LTS
  • Container: nvcr.io/nvidia/tensorrt-llm/release:1.3.0 (TensorRT-LLM 1.3.0, torch 2.14.0a0+nv26.09)
  • compute-sanitizer 2026.1.1
  • Also present in the cubins on main @ d7d81834c8ad (see additional notes)
Who can help?

@laikhtewari @kaiyux

Information
  • The official example scripts
  • My own modified scripts
Tasks
  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)
Reproduction

On SM103 the context attention path (FmhaDispatcher, which always uses TileScheduler::Persistent) launches fmhaSm103aKernel_…PersistentContext. Under compute-sanitizer --tool synccheck, this kernel reports Barrier error detected. Missing wait. as soon as a CTA has to process more than one tile, and the launch then fails.

The script builds a tiny random-weight Llama locally and starts LLM. The executor warmup runs a context-only forward of up to max_num_tokens tokens. max_num_tokens=16384 gives a context grid much larger than the 148 SMs, so CTAs take several tiles. max_num_tokens=256 (a single 256-token q-tile per head) is the control.

# repro_issue.py
# compute-sanitizer --tool synccheck --kernel-name kns=Sm103aKernel python3 repro_issue.py {256|16384}
import os, sys, tempfile
import torch
from transformers import LlamaConfig, LlamaForCausalLM
from tensorrt_llm import LLM, SamplingParams
from tensorrt_llm.llmapi import KvCacheConfig

def main():
    max_num_tokens = int(sys.argv[1])  # the executor warmup runs a context-only batch of this many tokens

    # Tiny random-weight Llama (bf16, 1 layer, 8 q / 2 kv heads, head_dim 128); nothing is downloaded.
    path = os.path.join(tempfile.gettempdir(), "tiny-llama-h128")
    if not os.path.exists(os.path.join(path, "config.json")):
        torch.manual_seed(0)
        cfg = LlamaConfig(hidden_size=1024, intermediate_size=1024, num_hidden_layers=1, num_attention_heads=8,
                          num_key_value_heads=2, head_dim=128, vocab_size=1024, max_position_embeddings=32768)
        LlamaForCausalLM(cfg).to(torch.bfloat16).save_pretrained(path)

    llm = LLM(model=path, skip_tokenizer_init=True, max_num_tokens=max_num_tokens, max_seq_len=16384,
              max_batch_size=1, cuda_graph_config=None, kv_cache_config=KvCacheConfig(free_gpu_memory_fraction=0.1))
    out = llm.generate([list(range(1, 201))], SamplingParams(max_tokens=1, detokenize=False, end_id=2, pad_id=2))
    print("ok, generated", out[0].outputs[0].token_ids)
    llm.shutdown()


if __name__ == "__main__":  # required: the LLM API spawns MPI workers that re-import this file
    main()
docker run --rm --gpus '"device=0"' --ipc=host -v $PWD:/w -w /w nvcr.io/nvidia/tensorrt-llm/release:1.3.0 \
  compute-sanitizer --tool synccheck --kernel-name kns=Sm103aKernel python3 repro_issue.py 16384

Output (16384):

========= Barrier error detected. Missing wait.
=========     at fmhaSm103aKernel_QkvBfloat16OBfloat16H128PagedKvCausalP32VarSeqQ256Kv128PersistentContext+0xc350
=========     by thread (32,0,0) in block (0,1,0)
=========     Barrier is located at shared address 0x288a0
=========         Host Frame: tensorrt_llm::_v1::kernels::TllmGenFmhaKernel::run(...) in libtensorrt_llm.so
=========         Host Frame: tensorrt_llm::_v1::kernels::FmhaDispatcher::run(...) in libtensorrt_llm.so
=========         Host Frame: tensorrt_llm::_v1::common::op::AttentionOp::enqueueContext<__nv_bfloat16, ...KVBlockArray>(...) in libtensorrt_llm.so
=========         ... (model_engine.py warmup)
...
[TRT-LLM] [E] [executor] Failed to initialize executor on rank 0: CUDA error: unspecified launch failure
========= ERROR SUMMARY: 1152 errors
max_num_tokens (warmup batch) tiles per CTA synccheck result
256 1 0 errors completes
16384 > 1 1,152 Missing wait unspecified launch failure, executor init fails
Expected behavior

synccheck reports 0 errors and the context kernel always completes, regardless of how many tiles each CTA processes.

actual behavior
  • Under the sanitizer: whenever a CTA processes more than one tile, the kernel reports Missing wait on a softmax mbarrier and the launch fails.
  • Without the sanitizer: the same kernel family hangs forever under serving load.
    • We hit this in vLLM with FlashInfer, which ships the same trtllm-gen FMHA kernels.
    • The GPU shows 100 % util, SM_ACTIVE ≈ 0.01 and DRAM 0, with no Xid.
    • Switching to the static tile scheduler removed both the sanitizer errors and the hangs.
    • We have not run TensorRT-LLM under serving load, so we have not seen the hang in TensorRT-LLM itself.
additional notes

Likely cause (SASS). The two softmax warpgroups alternate on a pair of ping-pong mbarriers: each waits on its own barrier and then arrives on the other's. In the SM103 persistent context cubins, warpgroup 1 skips its own wait on the last KV iteration of a tile:

PLOP3.LUT P0, PT, PT, PT, UP2, 0x80, 0x8          // P0 = last KV iteration of the tile
ISETP.GT.U32.AND P1, PT, R34, 0x3, PT             // P1 = warp > 3 (softmax WG1)
@P0 BRA P1, <after wait>                          // WG1 on the last iteration: skip the wait
SYNCS.PHASECHK.TRANS64.TRYWAIT P0, [UR20], R36    // own ping-pong barrier
  • One tile per CTA: harmless, because WG1 exits.
  • Persistent CTA: WG1 starts the next tile and arrives on WG0's barrier again before the previous phase was waited on. This is the reported Missing wait. If it gets two phases ahead, a parity wait may never return, which matches the hang. (This hang mechanism is inferred; we have not observed it directly.)

The SM100a builds of the same kernels have no such branch: both warpgroups wait on every iteration.

Workaround. FlashInfer selects TileScheduler::Static for SM103 context (flashinfer-ai/flashinfer#9702, merged; ragged path in a follow-up PR):

  • outputs are bit-identical to Persistent;
  • synccheck is clean;
  • kernel latency changes by +0.2 to +0.6 % geomean over 10 shapes, and long-KV batches are about 1 % faster.

Requests
The root cause is in the generated cubins, which cannot be fixed from this repository. So:

  1. Could you fix this trtllm-gen persistent context FMHA kernel?
  2. Or could you forward this to the trtllm-gen FMHA kernel team? The fix would be for softmax WG1 to also wait on its ping-pong barrier on the last KV iteration when the tile scheduler is persistent, followed by regenerated SM103 context cubins.

thank you in advance 😄

Related: flashinfer-ai/flashinfer#9700, flashinfer-ai/flashinfer#9728, flashinfer-ai/flashinfer#9702.

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

Mở trong Codespaces

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.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của NVIDIA/TensorRT-LLM

Tất cả issue của NVIDIA/TensorRT-LLM

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.