Skip to content

Fix GroupNormalization with num_groups=1 to include channel axis in reduction - #1052

Open
ssam18 wants to merge 1 commit into
onnx:10.16-GAfrom
ssam18:fix/groupnorm-num-groups-1
Open

Fix GroupNormalization with num_groups=1 to include channel axis in reduction#1052
ssam18 wants to merge 1 commit into
onnx:10.16-GAfrom
ssam18:fix/groupnorm-num-groups-1

Conversation

@ssam18

@ssam18 ssam18 commented May 20, 2026

Copy link
Copy Markdown

Summary

ONNX GroupNormalization with num_groups equal to 1 was silently producing per channel instance normalization instead of the LayerNorm over CHW behavior that the ONNX spec and PyTorch group_norm define. The cause was that the importer built axesMask from spatial dimensions only and excluded the channel axis, so when INormalizationLayer ran with nbGroups equal to 1 there was no implicit reduction over channels and the result collapsed to per channel statistics. This patch adds the channel axis to axesMask in the nbGroups equal to 1 case while keeping the existing spatial only mask for nbGroups greater than 1 (where the runtime explicitly forbids axis 1 in axesMask) and for InstanceNormalization.

Test plan

  • Built nvonnxparser locally against TensorRT 10.16.1.11 headers and swapped it into the pip wheel layout to validate against a real engine on RTX 4060
  • Reproducer from issue 4756 now matches PyTorch and ONNX Runtime within fp32 noise (max abs diff goes from 0.66 to about 1.2e-7)
  • Sweep over num_groups in {1, 2, 4, C} on 4D inputs, {1, 2, 3, C} on 5D inputs, all passing against PyTorch and ORT references
  • InstanceNormalization regression check passes
  • Enabled the ONNX backend test_group_normalization_* cases (num_groups equal to 2 with C equal to 4), which also exercises the proper multi group path

Fixes NVIDIA/TensorRT#4756
Signed-off-by: Samaresh Kumar Singh ssam3003@gmail.com

…eduction

When num_groups equals 1 the ONNX importer was building axesMask from only the spatial dimensions, so INormalizationLayer ended up reducing per channel and the output silently matched InstanceNorm instead of the LayerNorm over CHW behavior that ONNX and PyTorch group_norm specify. This change threads an includeChannelAxis flag through normalizationHelper and adds axis 1 to axesMask only when num_groups is 1, leaving InstanceNormalization and the proper multi group case untouched. Fixes NVIDIA/TensorRT#4756
Signed-off-by: Samaresh Kumar Singh <ssam3003@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect GroupNormalization result of TensorRT 10.16.1.11 when running ONNX GroupNormalization(num_groups=1) on GPU

1 participant