learning.group_norm_silu#
- bartorch.learning.group_norm_silu()#
silu((group_norm(x) * weight + bias) * (1 + scale) + shift): a diffusion UNet’s block.On a card with this library’s CUDA pass, and when no gradient is asked for, the statistics take one read of
xand the rest one more read and one write, inx’s own element type (float32, float16 or bfloat16) with float32 statistics – where eager torch reads and writes the activations four or five times, with casts around the norm. Anywhere else plain torch computes the same, also with float32 statistics.xmay be contiguous or channels last (torch.channels_last_3d, which cuDNN’s convolutions prefer), and the output keeps its layout.- Parameters:
x (torch.Tensor) –
(n, channels, *spatial).groups (int) – Groups the channels are normalised in; it divides
channels.weight (torch.Tensor, default=None) –
(channels,)affine of the norm.bias (torch.Tensor, default=None) –
(channels,)affine of the norm.scale (torch.Tensor, default=None) –
(n, channels)per-item scale (applied as1 + scale) and shift, e.g. from a noise-level embedding.shift (torch.Tensor, default=None) –
(n, channels)per-item scale (applied as1 + scale) and shift, e.g. from a noise-level embedding.eps (float, default=1e-5) – Added to the variance.
silu (bool, default=True) – Apply SiLU last.
- Returns:
Of
x’s shape and dtype.- Return type:
torch.Tensor