[Bug] LigerGroupNormFunction.backward crashes on any 4D (N, C, H, W) tensor (H > 1) and hardcodes tl.bfloat16 for float16 inputs
Maintainers usually reply within 3 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- machine-learning
Research direction
Read group_norm_backward at liger_kernel/ops/group_norm.py:242-255 and compare it with how forward flattens spatial dims. Run the posted reproducer on a GPU to see the DX.view(*shape) crash, then fix hidden_size to cover all spatial dims (e.g. math.prod(shape[2:])) and map torch.float16 to tl.float16 instead of hardcoding tl.bfloat16. Done means 4D backward returns (N, C, H, W) grads matching F.group_norm and fp16 weight/bias grads are no longer cast through bfloat16.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 673
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 19
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from linkedin/Liger-Kernel
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
linkedin/Liger-Kernel#1693 ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
linkedin/Liger-Kernel#1692 ·
Maintainers usually reply within 3 days
-
[Bug] LigerFusedGateUpSiLUMulFunction.backward crashes with shape mismatch on any 3D (B, T, 2*H) input tensorPossibly taken @shotsan claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
linkedin/Liger-Kernel#1675 · 1 comment ·
Maintainers usually reply within 3 days
-
[Bug] Silent backward gradient corruption in LigerCrossEntropy on non-contiguous logits (returns raw input logits as dL/dlogits)Possibly taken @shotsan claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
linkedin/Liger-Kernel#1674 ·
Maintainers usually reply within 3 days
-
GroupNorm: int32 batch offset overflows once a sample starts past 2**31 elementsPossibly taken @0z5a claimed this 7 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
linkedin/Liger-Kernel#1667 ·
Maintainers usually reply within 3 days
All issues in linkedin/Liger-Kernel
Similar issues
-
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)Possibly taken @rahul05ranjan claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
pallets-eco/croniter#309 ·
Maintainers usually reply within 1 day
-
[Bug]: MLX text downloads omit the requested Hub token and cache directoryPossibly taken @abhijithneilabraham claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vllm-project/vllm-metal#1423 ·
Maintainers usually reply within 1 day
-
Growl: a server-rejected notification is reported as a successPossibly taken @rahul05ranjan claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
gke-labs/kube-agents#7441 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100