ai.onnx.GroupNormalization

ai.onnx · standard ONNX operator · ONNX opset ≥ 21

Description

Applies group normalization to the input: y = scale * (x - mean) / sqrt(variance + epsilon) + bias, where mean and variance are computed per instance per group of channels. The number of groups num_groups must divide the channel count C evenly; when num_groups == C this is equivalent to InstanceNormalization, and when num_groups == 1 it is equivalent to LayerNormalization. The normalization stage supports TensorProto stash_type values 1 (float32) and 10 (float16).

See the ONNX GroupNormalization spec for the reference semantics.

Inputs

Name Upstream name Logical dtype Rank Shape Description Presence
x X T — — Input data tensor of shape (N x C x D1 x ... x Dn) where N is batch size and C is the number of channels. required
scale — T 1 — Scale tensor of shape (C), one value per channel. required
bias — T 1 — Bias tensor of shape (C), one value per channel. required

Outputs

Name Upstream name Logical dtype Rank Shape Description Presence
y Y T same as x same as x Normalized output tensor of the same shape as X. required

Attributes

Attributes and default values (overridable per request):

Attribute Default Description
epsilon 0.00001 Small value added to the variance denominator to avoid division by zero.
num_groups — Required number of groups to divide the channels into; must be a divisor of C.
stash_type 1 TensorProto element type used for the normalization stage: 1 computes in float32, while 10 computes in float16. Normalized values are cast back to the input type before scale and bias are applied.

Type constraints

Variable Allowed dtypes
T float32, float16

Files

Use with @huggingface/kernels

npm install --save-exact @huggingface/kernels@0.0.1-preview.4

Paste the example into a browser app that resolves npm imports. Serve the app over HTTPS or localhost with WebGPU available.

Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.

The version: 1 option selects the published kernel contract; it is independent of any operator opset, contrib since_version, or model version. It follows the v1 branch as fixes land. To pin exact artifact bytes, pass a 40-character commit revision instead of version.

import { getKernel } from "@huggingface/kernels";

const kernel = await getKernel("webgpu-kernels/ai.onnx.GroupNormalization", { version: 1 });

const xData = Float32Array.of(1, 2, 3, 4, 5, 6);
const scaleData = Float32Array.of(1, 1);
const biasData = Float32Array.of(2, 1);

const { y } = await kernel({
  x: { data: xData, shape: [1, 2, 3] },
  scale: { data: scaleData, shape: [2] },
  bias: { data: biasData, shape: [2] },
}, {
  attrs: { num_groups: 1 },
});
console.log({ y });
Downloads last month
-
kernel
webgpu
wgsl
apache-2.0
WebGPU

Requires WebGPU support. See the compatibility table.