Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 16, 2025

This PR implements opset 24 versions of normalization operators with optional scale and bias inputs, allowing for optimization when scale=1.0 and bias=0.0.

Changes Made

New Opset 24 Operators

  • BatchNormalization (opset 24) - scale and bias inputs now optional
  • InstanceNormalization (opset 24) - scale and bias inputs now optional
  • GroupNormalization (opset 24) - scale and bias inputs now optional
  • LayerNormalization (opset 24) - scale and bias inputs now both optional (bias was already optional in opset 17)

Key Features

  • Optional Inputs: Scale defaults to 1.0, bias defaults to 0.0 when not provided
  • Smart Function Builders: Handle all 4 input combinations:
    • Both scale and bias provided
    • Only scale provided
    • Only bias provided
    • Neither provided
  • Backwards Compatibility: Old versions moved to old.cc to maintain existing functionality

Implementation Details

// Example: InstanceNormalization with optional inputs
.Input(1, "scale", "The input 1-dimensional scale tensor of size C. Default value is 1.0.", "T", OpSchema::Optional, ...)
.Input(2, "B", "The input 1-dimensional bias tensor of size C. Default value is 0.0.", "T", OpSchema::Optional, ...)

Function builders include conditional logic:

if (ctx.hasInput(1) && ctx.hasInput(2)) {
  // Both scale and bias provided
} else if (ctx.hasInput(1)) {
  // Only scale provided
} else if (ctx.hasInput(2)) {
  // Only bias provided  
} else {
  // Neither provided - use defaults
}

Benefits

  • Model Optimization: Enables removal of unnecessary scale/bias parameters when they equal default values
  • Consistency: Makes all normalization operators behave consistently regarding optional parameters
  • Backwards Compatible: Existing models continue to work unchanged

Files Modified

  • onnx/defs/nn/defs.cc: Added new opset 24 definitions, removed old versions
  • onnx/defs/nn/old.cc: Added old opset versions (15, 17, 21, 22) for backwards compatibility

Fixes #6552.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Make InstanceNormalization weights and bias optional Make normalization operator weights and bias optional in opset 24 Jul 16, 2025
Copilot finished work on behalf of justinchuby July 16, 2025 17:39
Copilot AI requested a review from justinchuby July 16, 2025 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

Make InstanceNormalization weights and bias optional

2 participants