IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Python class

GroupNorm

GroupNorm​

class max.experimental.nn.norm.GroupNorm(num_groups, num_channels, eps=1e-05, affine=True)

source

Bases: Module

Group normalization block.

Divides channels into groups and computes normalization stats per group. Follows the implementation pattern from PyTorch’s group_norm.

This implementation uses Tensor instead of Weight, which automatically handles dtype matching with input tensors, eliminating the need for dtype workarounds.

Example:

from max.experimental.nn import GroupNorm
from max.experimental.tensor import Tensor

norm = GroupNorm(num_groups=32, num_channels=128)
x = Tensor.ones([1, 128, 32, 32])
result = norm(x)

Initialize GroupNorm module.

Parameters:

  • num_groups (int) – Number of groups to separate the channels into
  • num_channels (int) – Number of input channels
  • eps (float) – Small constant added to denominator for numerical stability. Default: 1e-5
  • affine (bool) – If True, apply learnable affine transform parameters. Default: True

bias​

bias: Tensor | None

source

The bias tensor with shape [num_channels] (None if affine=False).

eps​

eps: float

source

Small constant added to denominator for numerical stability.

forward()​

forward(x)

source

Apply group normalization to input tensor.

Parameters:

x (Tensor) – Input tensor of shape [N, C, …] where C is number of channels

Returns:

Normalized tensor of same shape as input

Return type:

Tensor

num_channels​

num_channels: int

source

Number of input channels.

num_groups​

num_groups: int

source

Number of groups to separate the channels into.

weight​

weight: Tensor | None

source

The weight tensor with shape [num_channels] (None if affine=False).