[BUG] Triton inference `softmax(input, mask)` reads the wrong mask row for a per-batch mask (wrong batch / out of bounds)
メンテナーはふだん 2 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 25/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
調査の方向性
The issue identifies the launcher and kernel in deepspeed.ops.transformer.inference.triton.softmax, the attention entry point in deepspeed/ops/transformer/inference/triton/attention.py, and coverage in tests/unit/ops/transformer/inference/test_attention.py. Start by tracing how the launcher flattens the mask and how the kernel selects a row; compare that indexing with the broadcast behavior of torch.softmax(input + mask, -1). Done means broadcastable per-batch masks match the reference without out-of-bounds reads; pull request #9061 is already open.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
deepspeed.ops.transformer.inference.triton.softmax(input, mask) assumes that the mask either has one row
(shared by every input row) or one row per input row. The launcher flattens the mask with
mask.view(-1, mask.shape[-1]) and sets mask_stride = n_cols whenever the flattened mask has more than one
row; the kernel then reads mask row row_idx, the flat input row.
For a mask that broadcasts against the input — the usual per-batch attention mask [B, 1, 1, S] against scores
[B, H, Q, S] — the flattened mask has B rows but the kernel indexes it with b*H*Q + h*Q + q. So:
- for
b = 0, headsh >= 1use the mask of a later batch; - every row with
b*H*Q + h*Q + q >= Breads past the end of the mask buffer.
torch.softmax(input + mask, -1) (the reference used by tests/unit/ops/transformer/inference/test_attention.py)
broadcasts the mask instead. Shapes like [B, 1, Q, S] are affected the same way.
Where it is reached
_triton_attention in deepspeed/ops/transformer/inference/triton/attention.py calls softmax(output, input_mask)
on the non-flash path (use_triton_flash=False, triangular=False). TritonSelfAttention takes that path when
get_accelerator().is_triton_supported() is false, e.g. use_triton=True on a CUDA GPU with compute capability
< 8.0, and the attention mask of an encoder model (BERT) is the per-batch [B, 1, 1, S] mask. The flash path
already indexes the mask by batch (mask + batch * stride_mz), and the CUDA softmax this op replaces also picks
the mask row by batch.
On a GPU with compute capability >= 8.0, TritonSelfAttention uses the flash path, so a model there does not hit
this. My reproductions ran on such a GPU (RTX PRO 6000, compute capability 12.0), calling the op and
_triton_attention(..., use_triton_flash=False) directly; I have not run a model end to end on a pre-Ampere
GPU. That non-flash path is what test_attention.py covers with use_flash=False, which currently only uses
BATCH=1 and a full-size mask, so it does not catch this.
To Reproduce
import torch
from deepspeed.ops.transformer.inference.triton import softmax
torch.manual_seed(0)
B, H, Q, S = 2, 2, 1, 16
x = torch.randn(B, H, Q, S, device="cuda")
mask = torch.zeros(B, 1, 1, S, device="cuda")
mask[1, ..., S // 2:] = -10000.0 # batch 1 pads its second half
out = softmax(x, mask)
ref = torch.softmax(x + mask, dim=-1)
print((out - ref).abs().amax(dim=-1).squeeze(-1)) # b=0, h=1 is wrong: it used batch 1's mask
On an RTX PRO 6000 (Triton 3.8.0, torch 2.14): batch 0 head 1 differs by 0.22. With B, H, Q, S = 3, 4, 5, 100
and random padding masks the max error is 0.34 in fp32 for [B,1,1,S] (NaN in fp16, from the out-of-bounds
reads) and 0.37 for [B,1,Q,S]. A shared [1,1,1,S] mask and a full [B,H,Q,S] mask are correct.
The same happens through the attention entry point. Set up exactly like test_attention.py with
use_flash=False (fp16, H=12, D_HEAD=64, skip_autotune()), but with BATCH=2 and the per-batch padding mask
[B, 1, 1, N_CTX] that the flash branch of that test uses, compared with
softmax(q @ k^T * scale + mask) @ v:
out = _triton_attention(qkv, input_mask=mask, layer_past=None, alibi=None, scale=0.3, head_size=64,
triangular=False, use_cuda_flash=False, use_triton_flash=False, use_ds_attention=False)
| BATCH, N_CTX | max abs error | (batch, head) pairs wrong |
|---|---|---|
| 1, 128 | 3.7e-4 | 0 / 12 |
| 2, 16 | 0.45 | 24 / 24 |
| 2, 128 | NaN | 24 / 24 (11 of them NaN) |
| 4, 128 | 0.21 | 48 / 48 |
Every row is affected, not only later heads, because the query dimension is flattened into the row index too.
Expected behavior
The result equals torch.softmax(input + mask, dim=-1) for any mask that broadcasts to input, or the call
fails loudly for a mask that does not.
System info
DeepSpeed master (2026-11-11), Triton 3.8.0, torch 2.14.0+cu130, NVIDIA RTX PRO 6000 Blackwell.
A fix is proposed in #9061.
- 主要言語
- Python
- スター
- 43.3k
- フォーク
- 5.1k
- 平均マージ
- 5日 10時間
- マージ済み PR(30日)
- 85
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
deepspeedai/DeepSpeed のほかの issue
-
[Bug] DeepSpeedEngine.step leaves _running_engine_step=True permanently on exception, corrupting is_gradient_accumulation_boundary()対応中かも @its-amann が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
deepspeedai/DeepSpeed#9190 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
[Bug] PipelineEngine._exec_reduce_grads and _exec_optimizer_step leave _force_grad_boundary=True permanently after any exception対応中かも @bantianyue が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
deepspeedai/DeepSpeed#9183 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
deepspeedai/DeepSpeed#9019 · コメント 2 件 ·
メンテナーはふだん 2 日以内に返信
-
fp16 `hysteresis: 0` (or negative) makes DynamicLossScaler never lower the loss scale, so every overflowing step is skipped forever対応中かも @damienen が 26 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
deepspeedai/DeepSpeed#8982 ·
メンテナーはふだん 2 日以内に返信
-
[BUG] OneCycle applies the minimum momentum to the first Adam update対応中かも @ai-yang が 30 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
deepspeedai/DeepSpeed#8951 ·
メンテナーはふだん 2 日以内に返信
deepspeedai/DeepSpeed の issue をすべて見る
似ている issue
-
area/auth comp/agent P3 type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
NousResearch/hermes-agent#161417 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
Dao-AILab/flash-attention#3251 ·
メンテナーはふだん 2 日以内に返信
-
[New Check]: sqlserver_public_network_access_disabled対応中かも @pouria-l が今日担当しました。 オープンfeature-request status/needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
prowler-cloud/prowler#13607 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
external langchain
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
langchain-ai/docs#8184 ·
メンテナーはふだん 1 日以内に返信