[WebNN EP] Support GroupNormalization, GroupNorm and SkipGroupNorm - #32606
Open
Wanming Lin (Honry) wants to merge 2 commits into
Open
Wanming Lin (Honry) wants to merge 2 commits into
Wanming Lin (Honry) wants to merge 2 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
Author
|
Dwayne Robinson (@fdwr), PTAL, thanks! |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Input validation, mixed-precision support, and WebNN test coverage need correction.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds WebNN lowering for standard and Microsoft group-normalization operators using InstanceNormalization.
Changes:
- Registers GroupNormalization, GroupNorm, and SkipGroupNorm.
- Implements layout handling, affine parameters, residuals, optional SiLU, and sum output.
- Updates decomposition metadata and operator documentation.
File summaries
| File | Description |
|---|---|
op_builder_factory.h |
Declares the builder factory. |
op_builder_factory.cc |
Registers supported operators. |
map_info.h |
Lists decomposed WebNN operations. |
group_norm_op_builder.cc |
Implements lowering and capability checks. |
webnn-operators.md |
Documents operator support. |
Review details
Suppressed comments (2)
onnxruntime/core/providers/webnn/builders/impl/group_norm_op_builder.cc:316
- This only validates the skip tensor's rank, so shapes such as
[4, 4]for an input[2, 3, 4, 8]are claimed as supported and then reinterpreted by the reshape as[2, 1, 1, 8], producing incorrect per-batch broadcasting. Require[N,C], the exact input shape, or a rank-matched shape with only the spatial dimensions equal to 1 before assigning the node to WebNN.
// Skip is either (N, C) or the full input shape.
if (skip_shape.size() != 2 && skip_shape.size() != input_shape.size()) {
LOGS(logger, VERBOSE) << op_type << " skip must be 2D or match the input rank.";
return false;
onnxruntime/core/providers/webnn/builders/impl/group_norm_op_builder.cc:344
- Requiring every input to have the same type rejects valid contrib GroupNorm/SkipGroupNorm nodes because their schemas intentionally separate
T(X/skip/output) fromM(gamma/beta). In particular, the repository's FP16 conversion keeps inputs 1 and 2 as float32 (python/tools/transformers/float16.py:147-149), so the common FP16 diffusion models targeted by these operators will still fall back. Support the T/M combination by inserting the required WebNN casts around the affine stage and includeCastin the decomposition capability checks.
if (!AreDataTypesSame(op_type, input_types, logger)) {
return false;
}
- Files reviewed: 5/5 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Wanming Lin (Honry)
force-pushed
the
groupNorm
branch
from
September 16, 2026 05:37
7ae3a85 to
6de6172
Compare
Support GroupNormalization and com.microsoft GroupNorm/SkipGroupNorm. WebNN has no native group-norm ops, so each is lowered to: reshape[N,G,(C/G)*spatial,1] -> instanceNormalization -> reshape back -> mul(gamma) -> add(beta) This is the InstanceNormalization pattern that backends can re-fuse into a native group normalization. Handles NHWC/NCHW layout, optional SiLU activation, the SkipGroupNorm residual sum (+ optional S output), per-group scale/bias (opset 18), and any input rank >= 3.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Support
GroupNormalizationand com.microsoftGroupNorm/SkipGroupNorm. WebNN has no native group-norm ops, so each is lowered to:reshape[N,G,(C/G)*spatial,1] -> instanceNormalization -> reshape back -> mul(gamma) -> add(beta)This is the InstanceNormalization pattern that backends can re-fuse into a native group normalization. Handles NHWC/NCHW layout, optional SiLU activation, the SkipGroupNorm residual
sum (+ optional S output), per-group scale/bias (opset 18), and any input rank >= 3.