GroupNorm: int32 batch offset overflows once a sample starts past 2**31 elements
I maintainer di solito rispondono entro 3 giorni
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
- Ambito
- backend, performance
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
LigerGroupNormin 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.
LigerGroupNormis 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
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di linkedin/Liger-Kernel
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
linkedin/Liger-Kernel#1693 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
linkedin/Liger-Kernel#1692 ·
I maintainer di solito rispondono entro 3 giorni
-
[Bug] LigerGroupNormFunction.backward crashes on any 4D (N, C, H, W) tensor (H > 1) and hardcodes tl.bfloat16 for float16 inputsForse già presa @shotsan l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
linkedin/Liger-Kernel#1676 · 2 commenti ·
I maintainer di solito rispondono entro 3 giorni
-
[Bug] LigerFusedGateUpSiLUMulFunction.backward crashes with shape mismatch on any 3D (B, T, 2*H) input tensorForse già presa @shotsan l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
linkedin/Liger-Kernel#1675 · 1 commento ·
I maintainer di solito rispondono entro 3 giorni
-
[Bug] Silent backward gradient corruption in LigerCrossEntropy on non-contiguous logits (returns raw input logits as dL/dlogits)Forse già presa @shotsan l’ha presa 5 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
linkedin/Liger-Kernel#1674 ·
I maintainer di solito rispondono entro 3 giorni
Tutte le issue di linkedin/Liger-Kernel
Issue simili
-
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)Forse già presa @rahul05ranjan l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
pallets-eco/croniter#309 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: MLX text downloads omit the requested Hub token and cache directoryForse già presa @abhijithneilabraham l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
vllm-project/vllm-metal#1423 ·
I maintainer di solito rispondono entro 1 giorno
-
Growl: a server-rejected notification is reported as a successForse già presa @rahul05ranjan l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
gke-labs/kube-agents#7441 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100