diffusion_models.models.SmallAttentionUnet
Module Contents
- class ResidualBlock(in_channels, out_channels, time_emb_dim, num_groups, dropout)[source]
A GroupNorm residual block conditioned on the timestep embedding.
- class SelfAttention2d(channels, num_groups, num_heads=4)[source]
Multi-head self-attention over the spatial positions of a feature map.
- class Downsample(channels)[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- class Upsample(channels)[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- class SmallAttentionUnet(diffuser, image_channels, base_channels=64, channel_multipliers=(1, 2, 4, 4), num_res_blocks=2, attention_levels=2, num_groups=32, dropout=0.0)[source]
A small DDPM-style Unet with GroupNorm and low-resolution attention.
Compared to
SimpleUnet, this model uses GroupNorm (so training and evaluation behave identically, which matters for sampling and EMA), residual blocks, and self-attention only at the lowestattention_levelsresolutions. With the defaults it has roughly 25M parameters and fits comfortably on a small GPU at 64x64.- Parameters:
diffuser (BaseDiffuser) – A gaussian diffuser.
image_channels (int) – The number of image channels.
base_channels (int) – The channel count at the highest resolution.
channel_multipliers (Sequence[int]) – Per level channel multiplier. Every level but the first halves the resolution.
num_res_blocks (int) – The number of residual blocks per level (down path).
attention_levels (int) – The number of lowest-resolution levels (and the bottleneck) which get self-attention.
num_groups (int) – The number of GroupNorm groups.
dropout (float) – The dropout probability inside residual blocks.