[Bug] GroupNorm kernels overflow int32 sample offsets (`batch_idx * X_row_stride`) past 2^31 elements
I maintainer di solito rispondono entro 3 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- performance
Direzione di ricerca
Leggi src/liger_kernel/ops/group_norm.py, concentrandoti sui calcoli degli offset in _group_norm_forward_kernel e _group_norm_backward_kernel. Riproduci il caso N=65 se è disponibile memoria GPU sufficiente, quindi verifica che entrambi i wrapper gestiscano offset oltre 2^31 elementi senza accessi illegali alla memoria. L’ampliamento di batch_idx proposto nell’issue indica una modifica specifica da verificare; conferma anche che il caso N=64 continui a funzionare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
🐛 Describe the bug
🐛 Describe the bug
_group_norm_forward_kernel and _group_norm_backward_kernel in group_norm.py move to their sample with batch_idx * X_row_stride. batch_idx is tl.program_id(0) and X_row_stride is passed as an i32 (it is one sample's size, below 2^31), so the product is int32 (mul.lo.s32 in the PTX). The wrappers pass the strides of the contiguous (N, C, *) input, so X_row_stride = C * H * W. The first sample whose offset reaches 2^31 elements (batch_idx * C * H * W >= 2**31) wraps to a negative offset, and the kernel loads X and stores Y (forward), or loads X and dY and stores dX (backward), before the tensors. In practice this is an illegal memory access.
LigerGroupNormFunction reaches both kernels whenever the input has more than 2^31 elements and one sample has fewer (a sample of 2^31 or more elements makes Triton pass the stride as i64, and the product is then 64-bit). Nothing on the host side rejects such a shape. For example, N = 65, C = 512, H = W = 256 is enough (4.3 GB in bf16).
This is the same class of 32-bit offset arithmetic as #804, #1483 and #1659 (program_id * stride), and it is still the same on current main (85a9c40):
_group_norm_forward_kernelL53, L56-L57, L97-L98_group_norm_backward_kernelL132, L136-L138, L141-L142
(#1573 is a different overflow in the same file: the loop counter of range(0, hidden_size, BLOCK_SIZE) near 2^31.)
Reproduce
Reproduce
The module's own wrappers on one (N, 512, 256, 256) input, 2**25 elements per sample, so 2**31 elements is N = 64. To fit the input and the output in 8 GB, the tensors are int8 (the offsets are in elements, so bf16 overflows at the same N, with 4.3 GB per tensor). Every sample is the same, so every sample's output must equal sample 0's:
import torch
from liger_kernel.ops.group_norm import group_norm_backward, group_norm_forward
N, C, G, H, W = 65, 512, 32, 256, 256 # N * C * H * W = 2**31 + 2**25
x0 = torch.randint(-3, 4, (C, H, W), device="cuda", dtype=torch.int8)
X = x0.expand(N, C, H, W).contiguous()
w = torch.randn(C, device="cuda", dtype=torch.bfloat16)
b = torch.randn(C, device="cuda", dtype=torch.bfloat16)
Y, _, Mean, RSTD, _ = group_norm_forward(X, C, G, w, b, 1e-6)
torch.cuda.synchronize()
# torch.AcceleratorError: CUDA error: an illegal memory access was encountered
# backward, in its own process: the same Mean (0) and RSTD (1) for every sample, dY = X
Mean = torch.zeros(N, G, device="cuda", dtype=torch.int8)
RSTD = torch.ones(N, G, device="cuda", dtype=torch.int8)
DX, DW, DB = group_norm_backward(X, X, w, b, Mean, RSTD, C, G)
torch.cuda.synchronize()
# torch.AcceleratorError: CUDA error: an illegal memory access was encountered
With N = 64 (exactly 2**31 elements, the last sample's offset 2**31 - 2**25) both wrappers return the same output for every sample. Each case ran in its own process (repro.py fwd|bwd N):
| wrapper | N = 64 |
N = 65 |
N = 65, batch_idx int64 |
|---|---|---|---|
group_norm_forward (_group_norm_forward_kernel) |
✅ 0 of 64 samples differ | ❌ illegal memory access | ✅ 0 of 65 samples differ |
group_norm_backward (_group_norm_backward_kernel) |
✅ 0 of 64 samples differ | ❌ illegal memory access | ✅ 0 of 65 samples differ |
The fix is to widen batch_idx before the multiply, in both kernels:
- batch_idx = tl.program_id(0)
+ batch_idx = tl.program_id(0).to(tl.int64)
The patch is attached. The other offsets stay int32 and are below one sample's size: group_idx * X_col_stride and channel_idx * X_col_stride (forward and backward), and group_idx * Mean_col_stride.
Versions
Versions
torch 2.9.1+cu128, triton 3.5.1, CUDA 12.8, NVIDIA GeForce RTX 4060 Ti (8 GB), driver 595.91.07. Liger-Kernel main @ 85a9c40.
- 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
-
[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
-
GroupNorm: int32 batch offset overflows once a sample starts past 2**31 elementsForse già presa @0z5a l’ha presa 7 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
linkedin/Liger-Kernel#1667 ·
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