VAEResBlock<T>

Models & Types · AiDotNet.Diffusion.VAE

Residual block for VAE encoder/decoder with GroupNorm and skip connections.

Inheritance: LayerBase<T> → VAEResBlock<T>

Implements: IShapeContract

For Beginners

A residual block helps the network learn more effectively.

Think of it like taking notes during a lecture:

  • The main path (two convolutions) learns new features
  • The skip connection preserves the original information
  • Adding them together means you learn the “difference” or “improvement”

The GroupNorm helps stabilize training by normalizing activations within groups of channels, which works well even with small batch sizes commonly used in image generation tasks.

Structure:

input ─────────────────────────────────┐
│ │
├─→ GroupNorm → SiLU → Conv3x3 ─→ h │ (skip connection)
│ │
│ ↓ │
│ │
│ GroupNorm → SiLU → Conv3x3 ─→ h │
│ │
│ ↓ ↓
│ [1x1 Conv if channels differ]
│ ↓ ↓
└────────────────→ (+) ←─────────────┘
│
output

How It Works

This implements a proper VAE residual block following the Stable Diffusion VAE architecture:

  • GroupNorm -> SiLU -> Conv -> GroupNorm -> SiLU -> Conv
  • Skip connection with optional 1x1 convolution when input/output channels differ

Constructors

Constructor Summary
VAEResBlock(int inChannels, int outChannels, int numGroups, int spatialSize) Initializes a new instance of the VAEResBlock class.

Properties

Property Summary
bool SupportsTraining { get; }
int InputChannels { get; } Gets the number of input channels.
int NumGroups { get; } Gets the number of groups for GroupNorm.
int OutputChannels { get; } Gets the number of output channels.

Methods

Method Summary
IReadOnlyList<ILayer<T>> GetSubLayers()
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank)
void ResetState() Resets the internal state of the block.
void UpdateParameters(T learningRate) Updates all learnable parameters using gradient descent.