GroupNorm: int32 batch offset overflows once a sample starts past 2**31 elements

Aperta Adatta ai principianti
#1,667 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

@0z5a ci sta già lavorando.

Dal 19/11/2026.

  • #1670 di @0z5a — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

Inizia con _group_norm_forward_kernel e _group_norm_backward_kernel in src/liger_kernel/ops/group_norm.py, quindi confronta la loro aritmetica dell’offset del batch con i cast a int64 usati in altri kernel Liger, come nella correzione di #1600. Controlla i test di GroupNorm per trovare un test di regressione che eserciti un offset del batch superiore a 2**31 ed eseguilo. Il lavoro è completato quando il passaggio in avanti e quello all’indietro corrispondono al riferimento PyTorch per campione per ogni campione nel caso di batch grande segnalato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

🐛 Describe the bug

LigerGroupNorm reads and writes the wrong memory once a sample starts at element 2**31 or later of the input, even though each sample is much smaller than that.

Both _group_norm_forward_kernel and _group_norm_backward_kernel in src/liger_kernel/ops/group_norm.py move to the current sample with

batch_idx = tl.program_id(0)
...
X_ptr += batch_idx * X_row_stride + group_idx * X_col_stride

tl.program_id is int32. X_row_stride is the per-sample element count, so Triton also passes it as int32 when it fits. The product batch_idx * X_row_stride is then int32 and wraps once it reaches 2**31. The backward kernel uses the same offset for X, DX and the upstream gradient.

For C=128 and 1024x1024 spatial, one sample has 227 elements, so sample 16 starts at 231. Any batch of 17 or more at that size hits it.

Reproduce
import torch
from liger_kernel.transformers.group_norm import LigerGroupNorm

B, C, H, W, G = 20, 128, 1024, 1024, 32  # sample 16 starts at element 2**31
x = torch.randn(B, C, H, W, dtype=torch.bfloat16, device="cuda", requires_grad=True)
gn = LigerGroupNorm(C, G, eps=1e-6).to(torch.bfloat16).to("cuda")
y = gn(x)
y.backward(torch.randn_like(y))
torch.cuda.synchronize()

On NVIDIA GH200 this fails with:

torch.AcceleratorError: CUDA error: an illegal memory access was encountered

With the program ids cast to int64 (tl.program_id(0).to(tl.int64), as in other Liger kernels), the same script runs. In that run, every one of the 20 samples matches a per-sample torch.nn.functional.group_norm reference to the same level: max abs error about 0.03 for output and input grad in bf16, the same before and after sample 16.

How I found it

I was reading the Triton kernels for int32 offset arithmetic after the int64 fixes in other kernels (for example #1600). GroupNorm views the input as (B, G, -1) and only uses the program ids for the batch and group offsets, so the batch offset is the one that can cross 2**31.

Where this can show up in practice

This is my estimate; I have not seen a field report.

  • Using LigerGroupNorm in convolutional or diffusion models (VAE decoders and UNets use GroupNorm at high resolution): for example batch 17 or more at 128 channels and 1024x1024, or a smaller batch with more channels or a larger resolution.
  • Forward or backward either crashes with an illegal memory access or, depending on where the wrapped offset lands, silently reads and writes another sample's memory.
  • LigerGroupNorm is not applied by any monkey patch, so only code that uses it explicitly is affected.
Versions
  • torch 2.14.1+cu130, triton 3.8.0
  • NVIDIA GH200 480GB, Linux aarch64
  • Liger-Kernel main at 33b66dc

I can open a PR with the int64 cast and a regression test.

Lingua principale
Python
Stelle
6.7k
Fork
673
Merge medio
4g 20h
PR unite (30g)
19

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di linkedin/Liger-Kernel

Tutte le issue di linkedin/Liger-Kernel

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.