Skip to content

[WebNN EP] Support GroupNormalization, GroupNorm and SkipGroupNorm - #32606

Open
Wanming Lin (Honry) wants to merge 2 commits into
microsoft:mainfrom
Honry:groupNorm
Open

Wanming Lin (Honry) wants to merge 2 commits into
microsoft:mainfrom
Honry:groupNorm

Conversation

@Honry

Copy link
Copy Markdown
Contributor

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.

Copilot AI balanced review requested due to automatic review settings September 15, 2026 08:34
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@Honry

Copy link
Copy Markdown
Contributor Author

Dwayne Robinson (@fdwr), PTAL, thanks!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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) from M (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 include Cast in 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) and others added 2 commits September 16, 2026 13:37
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>
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.

2 participants