[Bug] LigerGroupNormFunction.backward crashes on any 4D (N, C, H, W) tensor (H > 1) and hardcodes tl.bfloat16 for float16 inputs
メンテナーはふだん 3 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 72/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
調査の方向性
liger_kernel/ops/group_norm.py:242-255 の group_norm_backward を読み、forward が空間次元をどのように平坦化しているかと比較してください。投稿された再現スクリプトを GPU 上で実行し、DX.view(*shape) でのクラッシュを確認します。そのうえで、hidden_size がすべての空間次元をカバーするように修正し(例: math.prod(shape[2:]))、tl.bfloat16 を固定で使うのではなく torch.float16 を tl.float16 に対応させます。4D の backward が F.group_norm と一致する (N, C, H, W) の勾配を返し、fp16 の重みとバイアスの勾配が bfloat16 を経由して変換されなくなれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Description
LigerGroupNormFunction has two bugs in group_norm_backward (liger_kernel/ops/group_norm.py:242-255):
- 4D backward truncation crash: On any standard 4D
(N, C, H, W)tensor withH > 1,forwardsucceeds and matchesF.group_norm, while.backward()crashes withRuntimeError: shape '[2, 16, 8, 8]' is invalid for input of size 256. - Hardcoded
tl.bfloat16forfloat16inputs: Line 255 setstriton_dtype = tl.float32 if X.dtype == torch.float32 else tl.bfloat16, silently castingtorch.float16weight/bias gradients throughbfloat16(7-bit mantissa instead of 10-bit).
- Affected Version:
liger-kernel==0.8.3(torch==2.15.0+cu132,triton==3.9.0; also reproduced on Colab L4sm_89withtorch==2.14.1) - Component:
liger_kernel/ops/group_norm.py:242-255(group_norm_backward)
Minimal Reproducer
import torch
import torch.nn.functional as F
from liger_kernel.ops import LigerGroupNormFunction
N, C, H, W, G = 2, 16, 8, 8, 4
x = torch.randn((N, C, H, W), device="cuda", dtype=torch.float32, requires_grad=True)
w = torch.randn((C,), device="cuda", dtype=torch.float32, requires_grad=True)
b = torch.randn((C,), device="cuda", dtype=torch.float32, requires_grad=True)
y = LigerGroupNormFunction.apply(x, w, b, C, G, 1e-5)
y_ref = F.group_norm(x.detach(), G, w.detach(), b.detach(), 1e-5)
print(f"4D Forward PASS: shape={tuple(y.shape)}, fwd_err={(y.detach() - y_ref).abs().max().item():.3e}")
# Crashes with: RuntimeError: shape '[2, 16, 8, 8]' is invalid for input of size 256
y.sum().backward()
Root Cause & Suggested Fix
In group_norm_backward (group_norm.py:243-250), hidden_size = dY.shape[-1] is read before flattening spatial dimensions (dY = dY.view(batch_size, num_groups, -1)), capturing only W (8) instead of H * W (64). Consequently DX is allocated with size B * C * W (256) instead of B * C * H * W (2048), the Triton kernel only processes a truncated slice, and DX.view(*shape) crashes on return.
Computing hidden_size = math.prod(shape[2:]) (or reading it after flattening spatial dimensions) and mapping torch.float16 -> tl.float16 (via torch_to_triton_dtype) fixes both issues.
- 主要言語
- Python
- スター
- 6.7k
- フォーク
- 673
- 平均マージ
- 4日 20時間
- マージ済み PR(30日)
- 19
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
linkedin/Liger-Kernel のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
linkedin/Liger-Kernel#1693 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
linkedin/Liger-Kernel#1692 ·
メンテナーはふだん 3 日以内に返信
-
[Bug] LigerFusedGateUpSiLUMulFunction.backward crashes with shape mismatch on any 3D (B, T, 2*H) input tensor対応中かも @shotsan が 2 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
linkedin/Liger-Kernel#1675 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
[Bug] Silent backward gradient corruption in LigerCrossEntropy on non-contiguous logits (returns raw input logits as dL/dlogits)対応中かも @shotsan が 5 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
linkedin/Liger-Kernel#1674 ·
メンテナーはふだん 3 日以内に返信
-
GroupNorm: int32 batch offset overflows once a sample starts past 2**31 elements対応中かも @0z5a が 7 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
linkedin/Liger-Kernel#1667 ·
メンテナーはふだん 3 日以内に返信
linkedin/Liger-Kernel の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 73/100
-
day_or=True union silently becomes the ISC cron AND bug when a day field expands to its full range (e.g. '0 0 */1 * */2' fires only Sun/Tue/Thu/Sat)対応中かも @rahul05ranjan が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
pallets-eco/croniter#309 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
chore
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
nyjc-computing/campus-admin#105 ·
メンテナーはふだん 1 日以内に返信
-
bug enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
AOSSIE-Org/Gitcord-GithubDiscordBot#248 · コメント 1 件 ·
メンテナーはふだん 4 日以内に返信