[Bug]: apply_per_channel_scale reads and writes past the last row when rows % kProcessRows != 0

オープン
#22,999 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Super262 がすでに取り組んでいます。

2026年11月28日 から。

  • #23011 @Super262 による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp

調査の方向性

Start with cpp/tensorrt_llm/kernels/preQuantScaleKernel.cu, especially the row guards and processing loop at lines 52–59, then check the launcher configuration at lines 128–145. Reproduce with the per_channel_scale_4rows_tail case using the Volta command in the issue. Done means the kernel accesses no rows beyond rows or num_valid_tokens_ptr; verify both the per-channel and per-expert launchers.

索引モデルが issue の本文から書いたものです。

説明

Customized kernels

We found this with Volta, a verifier we develop for PTX kernels: it symbolically executes a kernel's compiled PTX for a concrete launch and checks the recorded execution for data races, out-of-bounds accesses and PTX ISA rule violations. This report comes from that analysis of the sm_100a PTX at main 3babde6, not from a wrong result observed on a GPU.

System Info
  • Static analysis, no GPU run.
  • TensorRT-LLM main at 3babde6b1b88168220fa60567403a7e2b37fb352; cpp/tensorrt_llm/kernels/preQuantScaleKernel.cu compiled with nvcc -ptx -arch=sm_100a -O3 (CUDA 13.2.1, nvidia/cuda:13.2.1-devel-ubuntu24.04).
Who can help?

No response

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

Once rows * cols >= 2048 * 2048, apply_per_channel_scale_kernel_launcher (and the _per_expert_ launcher) uses kProcessRows = 4, 8 or 16 rows per block (preQuantScaleKernel.cu:128-145), with a grid of ceil(rows / kProcessRows) blocks. The kernel's guards test only the block's first row:

if (col_offset * kElems >= cols || row_offset * kProcessRows >= rows)
    return;
if (num_valid_tokens_ptr && (row_offset * kProcessRows >= *num_valid_tokens_ptr))
    return;
...
for (int i = 0; i < kProcessRows; ++i)
{
    ... act + i * cols ...           // read
    ... smoothed_act + i * cols ...  // write

(:52-59). When rows % kProcessRows != 0, the last block therefore reads act and writes smoothed_act up to kProcessRows - 1 rows past rows. It likewise processes rows past *num_valid_tokens_ptr.

Volta reports this for rows = 4097, cols = 1024 (kProcessRows = 4, block 1024 covers rows 4096-4099): an out-of-bounds global read of act row 4097, one past the end. To reproduce with Volta (--build compiles the PTX in Docker):

python3 external/ptx/verify.py TensorRT-LLM -k per_channel_scale --build

The case is per_channel_scale_4rows_tail (cases.py:1356-1364).

Expected behavior

The kernel touches only rows < rows (and < *num_valid_tokens_ptr, when given).

actual behavior

The last block reads and writes up to kProcessRows - 1 rows past the end of act and smoothed_act.

additional notes

In the one caller we found, CutlassMoeFCRunner::applyPrequantScale (moe_kernels.cu:3724), the extra rows appear to stay inside the MoE workspace: smoothed_act is sized at twice max(permuted_elems, interbuf_elems). So this looks latent there, but the launchers are a public API (preQuantScaleKernel.h) and nothing documents that requirement on the buffers.

A possible fix is to bound the loop per row:

int const row_end = min(kProcessRows, rows - row_offset * kProcessRows);
int const valid_end = num_valid_tokens_ptr
    ? min<int64_t>(row_end, *num_valid_tokens_ptr - row_offset * kProcessRows) : row_end;
for (int i = 0; i < valid_end; ++i)
主要言語
Python
スター
15.2k
フォーク
3k
平均マージ
2日 21時間
マージ済み PR(30日)
477

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

NVIDIA/TensorRT-LLM のほかの issue

NVIDIA/TensorRT-LLM の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。