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.