[Bug]: torch.ops.trtllm empty batch (batch_size=0) raises cudaErrorInvalidValue in rmsnorm, gated-act, and RoPE

未关闭
#22,993 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@sylvesterkaczmarek 已经在做这个了。

开始于 2026年11月28日。

  • #23017 来自 @sylvesterkaczmarek —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
56/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python, pytorch

调研方向

Start by locating the torch.ops.trtllm wrappers for the five named FlashInfer operations and tracing how they forward empty tensors to the CUDA launchers. Check the launch paths for zero-sized batches and the RoPE reshape described in the report. Done means all five operations return cleanly for the provided B=0 inputs while existing nonempty behavior remains intact; the issue names no source files or tests to run.

由索引模型根据 Issue 内容生成。

描述

Customized kernels
System Info
  • TensorRT-LLM: 1.3.0 (torch.ops.trtllm, upstream main checked @ 546c48139181)
  • GPU: NVIDIA Tesla T4 (SM 7.5, 15360 MiB, driver 580.82.07)
  • PyTorch / CUDA: 2.14.1+cu130 / CUDA 13.0
  • OS / Python: Linux-6.6.159+-x86_64-with-glibc2.39, Python 3.12.3
Reproduction
import torch
import tensorrt_llm  # registers torch.ops.trtllm

dt = torch.float16
cases = [
    ("flashinfer_rmsnorm", lambda: torch.ops.trtllm.flashinfer_rmsnorm(torch.empty(0, 64, device="cuda", dtype=dt), torch.ones(64, device="cuda", dtype=dt), 1e-6)),
    ("flashinfer_fused_add_rmsnorm", lambda: torch.ops.trtllm.flashinfer_fused_add_rmsnorm(torch.empty(0, 64, device="cuda", dtype=dt), torch.empty(0, 64, device="cuda", dtype=dt), torch.ones(64, device="cuda", dtype=dt), 1e-6)),
    ("flashinfer_silu_and_mul", lambda: torch.ops.trtllm.flashinfer_silu_and_mul(torch.empty(0, 128, device="cuda", dtype=dt))),
    ("flashinfer_gelu_tanh_and_mul", lambda: torch.ops.trtllm.flashinfer_gelu_tanh_and_mul(torch.empty(0, 128, device="cuda", dtype=dt))),
    ("flashinfer_apply_rope_with_cos_sin_cache_inplace", lambda: torch.ops.trtllm.flashinfer_apply_rope_with_cos_sin_cache_inplace(torch.empty(0, device="cuda", dtype=torch.int32), torch.empty(0, 128, device="cuda", dtype=dt), torch.empty(0, 128, device="cuda", dtype=dt), 64, torch.randn(16, 64, device="cuda", dtype=torch.float32), True)),
]
for name, fn in cases:
    try:
        fn(); torch.cuda.synchronize(); print(name, "OK")
    except Exception as e:
        print(name, "FAIL:", type(e).__name__, str(e).splitlines()[0])
Expected behavior

Passing a valid empty batch (B=0, numel() == 0) to any of these torch.ops.trtllm ops should return cleanly as a no-op (matching B=4 which succeeds on all 5 ops), rather than launching a CUDA kernel with gridDim.x = 0 or calling .view(0, -1, 64).

actual behavior
flashinfer_rmsnorm FAIL: RuntimeError Check failed: (status == cudaSuccess) is false: RMSNorm failed with error code invalid argument
flashinfer_fused_add_rmsnorm FAIL: RuntimeError Check failed: (status == cudaSuccess) is false: FusedAddRMSNorm failed with error code invalid argument
flashinfer_silu_and_mul FAIL: RuntimeError Check failed: (err == cudaSuccess) is false: Failed to launch kernel: invalid argument
flashinfer_gelu_tanh_and_mul FAIL: RuntimeError Check failed: (err == cudaSuccess) is false: Failed to launch kernel: invalid argument
flashinfer_apply_rope_with_cos_sin_cache_inplace FAIL: RuntimeError cannot reshape tensor of 0 elements into shape [0, -1, 64] because the unspecified dimension size -1 can be any value and is ambiguous
additional notes

Adding an early if (input.size(0) == 0) return ...; guard in the torch.ops.trtllm custom op wrappers before forwarding to the CUDA kernel launchers avoids cudaErrorInvalidValue on empty DP/PP microbatches.

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.

Credit given to UCSB PLSE.

主要语言
Python
星标
15.2k
派生
3k
平均合并
2 天 21 小时
30 天内合并 PR
477

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

NVIDIA/TensorRT-LLM 的其他 Issue

查看 NVIDIA/TensorRT-LLM 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。