Add onnx-graphsurgeon example for folding legacy GroupNorm pattern#4749
Open
ssam18 wants to merge 2 commits intoNVIDIA:mainfrom
Open
Add onnx-graphsurgeon example for folding legacy GroupNorm pattern#4749ssam18 wants to merge 2 commits intoNVIDIA:mainfrom
ssam18 wants to merge 2 commits intoNVIDIA:mainfrom
Conversation
PyTorch versions before 2.5 export nn.GroupNorm at opset under 18 as a Reshape, InstanceNormalization, Reshape, Mul, Add chain. The new example walks through detecting that pattern and rewriting it as a single native GroupNormalization node so users can sidestep the fused-norm path that has shown accuracy drift on large reductions. Verified end to end against ONNX Runtime CPU on both a synthesised toy model and a real SegVit export, with max abs diff 1e-5 in FP32. Signed-off-by: Samaresh Kumar Singh <ssam3003@gmail.com>
Refactors fold.py to build the legacy GroupNorm template once as a GraphPattern and rely on match_all for discovery, replacing the manual node-by-node walk. Signed-off-by: Samaresh Kumar Singh <ssam3003@gmail.com>
pranavm-nvidia
approved these changes
May 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a new onnx-graphsurgeon example that detects the legacy Reshape, InstanceNormalization, Reshape, Mul, Add pattern emitted by PyTorch under 2.5 when exporting nn.GroupNorm at an ONNX opset below 18. The example rewrites every match into a single native GroupNormalization node and bumps the model opset to 21, which is the version where per channel scale and bias are accepted. The motivation is that the legacy template can drift inside the fused norm path when reduction extents are large, so giving users a clean single op gives them a way to route around the issue. The fold has been validated end to end on ONNX Runtime CPU against both a tiny synthesised model and a real SegVit export, with max abs diff staying inside FP32 noise. Fixes #4741