Skip to content

Conv

conv

WeightNorm

WeightNorm(module: Module, weight_name: str = 'weight', dim: int = 0)

Bases: Module

Weight normalization wrapper for any module with a weight parameter.

Decomposes the weight into a magnitude (g) and direction (v): weight = g * (v / ||v||)

Parameters:

Name Type Description Default
module Module

The module to wrap (e.g., nn.Conv1d, nn.Linear).

required
weight_name str

Name of the weight parameter to normalize.

'weight'
dim int

Dimension over which to compute the norm. Default 0 normalizes per output channel.

0

weight_norm

Weight normalization for MLX modules.

Implements weight normalization (Salimans & Kingma, 2016) as a wrapper that reparameterizes a weight tensor as w = g * (v / ||v||).

WeightNorm

WeightNorm(module: Module, weight_name: str = 'weight', dim: int = 0)

Bases: Module

Weight normalization wrapper for any module with a weight parameter.

Decomposes the weight into a magnitude (g) and direction (v): weight = g * (v / ||v||)

Parameters:

Name Type Description Default
module Module

The module to wrap (e.g., nn.Conv1d, nn.Linear).

required
weight_name str

Name of the weight parameter to normalize.

'weight'
dim int

Dimension over which to compute the norm. Default 0 normalizes per output channel.

0

weight_norm

weight_norm(module: Module, weight_name: str = 'weight', dim: int = 0) -> WeightNorm

Apply weight normalization to a module.

Parameters:

Name Type Description Default
module Module

Module to wrap (e.g., nn.Conv1d, nn.Linear).

required
weight_name str

Name of the weight parameter.

'weight'
dim int

Dimension for per-channel normalization.

0

Returns:

Type Description
WeightNorm

WeightNorm wrapper around the module.

Example::

conv = weight_norm(nn.Conv1d(16, 32, 3))
out = conv(x)