Skip to content

add_spectral_norm

add_spectral_norm(layer, generator=None)

Wrap layer with spectral normalization and seed the power-iteration vectors.

nn_utils.spectral_norm initializes weight_u and weight_v from the global RNG. When a local generator is provided, those buffers are overwritten here so that the full initialization is reproducible.

Parameters:

  • layer (Linear) –

    Layer to wrap.

  • generator (Generator or None, default: None ) –

    Local RNG used to re-initialize weight_u / weight_v.

Returns:

  • Module –

    Spectrally-normalized layer.