VAEDecoder<T>

Models & Types · AiDotNet.Diffusion.VAE

Convolutional decoder for VAE that reconstructs images from latent space.

Inheritance: LayerBase<T> → VAEDecoder<T>

Implements: IShapeContract

For Beginners

The VAE decoder is like an intelligent image decompressor.

What it does step by step:

  1. Takes a compressed latent (e.g., 64x64x4)
  2. Post-quant conv: Expands channels (4 -> 512)
  3. Middle blocks: Extra processing at the bottleneck
  4. UpBlocks: Progressively doubles resolution while decreasing channels
  • Block 1: 512 channels, 64x64 -> 64x64 (no upsample at start)
  • Block 2: 512 channels, 64x64 -> 128x128
  • Block 3: 256 channels, 128x128 -> 256x256
  • Block 4: 128 channels, 256x256 -> 512x512
  1. Output: Produces 3-channel RGB image with tanh activation

The result is a high-resolution image reconstructed from the compressed latent.

How It Works

This implements the decoder portion of a VAE following the Stable Diffusion architecture:

  • Post-quant convolution to expand latent channels
  • Middle blocks at the bottleneck
  • Multiple UpBlocks with transposed conv upsampling and ResBlocks
  • Output convolution to produce final image channels

Constructors

Constructor Summary
VAEDecoder(int outputChannels, int latentChannels, int baseChannels, int[] channelMults, int numResBlocks, int numGroups, int outputSpatialSize) Initializes a new instance of the VAEDecoder class.

Properties

Property Summary
bool SupportsTraining { get; }
int LatentChannels { get; } Gets the number of latent channels.
int OutputChannels { get; } Gets the number of output channels.
int UpsampleFactor { get; } Gets the upsampling factor (spatial expansion from input to output).

Methods

Method Summary
IReadOnlyList<ILayer<T>> GetSubLayers()
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank)
ValueTask<Tensor<T>> ForwardAsync(Tensor<T> input, CancellationToken cancellationToken) Async overload of Forward — routes through the compile host’s PredictAsync.
void InvalidateCompiledPlans() Bumps the structure-version so the next Forward drops stale plans.
void ResetState() Resets the internal state of the decoder.
void UpdateParameters(T learningRate) Updates all learnable parameters using gradient descent.