For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Mojo function
group_norm_cpu
def group_norm_cpu[dtype: DType, rank: Int, //, input_fn: def[width: Int, rank: Int](IndexList[rank]) capturing thin -> SIMD[dtype, width], gamma_fn: def[width: Int](IndexList[Int(1)]) capturing thin -> SIMD[dtype, width], beta_fn: def[width: Int](IndexList[Int(1)]) capturing thin -> SIMD[dtype, width]](shape: IndexList[rank, element_type=shape.element_type], epsilon: Float32, output: TileTensor[dtype, Storage=output.Storage, address_space=output.address_space, linear_idx_type=output.linear_idx_type], num_groups: Int, ctx: Optional[DeviceContext] = None)
Computes group normalization on CPU.
Reduces a single-pass Welford mean/variance over each (batch, group)
block of channels_per_group * spatial elements, then applies the
per-channel gamma/beta affine transform. Parallelizes across
N * num_groups blocks.
Parameters:
- dtype (
DType): Element type of the input and output tensors. - rank (
Int): Tensor rank of the input and output tensors (3 or 4). - input_fn (
def[width: Int, rank: Int](IndexList[rank]) capturing thin -> SIMD[dtype, width]): Function called to generate an input value. - gamma_fn (
def[width: Int](IndexList[Int(1)]) capturing thin -> SIMD[dtype, width]): Function called to generate a gamma value. - beta_fn (
def[width: Int](IndexList[Int(1)]) capturing thin -> SIMD[dtype, width]): Function called to generate a beta value.
Args:
- shape (
IndexList[rank, element_type=shape.element_type]): The shape of the input/output tensor. - epsilon (
Float32): Small constant for numerical stability. - output (
TileTensor[dtype, Storage=output.Storage, address_space=output.address_space, linear_idx_type=output.linear_idx_type]): Output tensor receiving the normalized result. - num_groups (
Int): Number of groups the channel dimension is split into. - ctx (
Optional[DeviceContext]): Optional device context used to size the CPU thread pool.