fn

remove_weight_norm

Module
remove_weight_norm(module: Module, name: str = 'weight')
source

Reverse weight_norm and restore a plain leaf parameter.

Materialises W=gv/v\mathbf{W} = g \cdot \mathbf{v}/\|\mathbf{v}\| one last time, writes the result back as a single leaf parameter module.<name>, drops <name>_g / <name>_v, and detaches the forward pre-hook. Typical use is right before exporting a model for inference where the reparametrised form is not needed.

Parameters

moduleModule
Module previously passed through weight_norm.
namestr= 'weight'
Attribute name of the parameter to un-normalise. Must match the name used at registration. Default "weight".

Returns

Module

The same module, with <name> restored as a plain lucid.nn.parameter.Parameter and the g/v helpers removed.

Raises

ValueError
If no weight-norm registration exists on <name>.

Notes

The materialised parameter is detached from the autograd graph — any history accumulated through the reparametrisation is discarded. If you need the original v direction back, copy it out before calling this.

Examples

>>> remove_weight_norm(layer)
>>> "weight_g" in dict(layer.named_parameters())
False