Skip to main content

Module blocks

Module blocks 

Source
Expand description

Building blocks of the Stable-Diffusion VAE decoder.

All blocks here match the diffusers models/{resnet,upsampling, attention_processor}.py / models/unets/unet_2d_blocks.py reference layout 1:1 in parameter naming and forward semantics so the upstream state dict (runwayml/stable-diffusion-v1-5/vae/diffusion_pytorch_model.safetensors) loads byte-for-byte.

§REQ status (per .design/ferrotorch-diffusion/blocks.md)

REQStatusEvidence
REQ-1SHIPPEDResnetBlock2D at ferrotorch-diffusion/src/blocks.rs:35..215; consumer: ferrotorch-diffusion/src/vae.rs and vae_encoder.rs consume it transitively via UpDecoderBlock2D/DownEncoderBlock2D/UNetMidBlock2D
REQ-2SHIPPEDAttnBlock2D at ferrotorch-diffusion/src/blocks.rs:242..434; consumer: UNetMidBlock2D::new at blocks.rs:1010 calls AttnBlock2D::<T>::new and ferrotorch-diffusion/src/vae.rs:83 builds it
REQ-3SHIPPEDUpsample2D at ferrotorch-diffusion/src/blocks.rs:446..525; consumer: ferrotorch-diffusion/src/unet.rs:48 imports it for UNet up blocks
REQ-4SHIPPEDDownsample2D at ferrotorch-diffusion/src/blocks.rs:536..611; consumer: ferrotorch-diffusion/src/unet.rs:48 imports it for UNet down blocks
REQ-5SHIPPEDUpDecoderBlock2D at ferrotorch-diffusion/src/blocks.rs:626..786; consumer: ferrotorch-diffusion/src/vae.rs:92 constructs each decoder up-block
REQ-6SHIPPEDDownEncoderBlock2D at ferrotorch-diffusion/src/blocks.rs:806..972; consumer: ferrotorch-diffusion/src/vae_encoder.rs:123 constructs each encoder down-block
REQ-7SHIPPEDUNetMidBlock2D at ferrotorch-diffusion/src/blocks.rs:988..1127; consumer: ferrotorch-diffusion/src/vae.rs:83 and vae_encoder.rs:130 both invoke UNetMidBlock2D::<T>::new

Structs§

AttnBlock2D
Single-head spatial self-attention with residual + GroupNorm — the VAE mid-block attention.
DownEncoderBlock2D
DownEncoderBlock2D — a stack of layers_per_block resnets at out_channels, optionally followed by a Downsample2D.
Downsample2D
Diffusers-style Downsample2D — a single Conv2d(C, C, k=3, stride=2, pad=1, bias=True).
ResnetBlock2D
ResnetBlock2D — the building block of every UNet/VAE up/down/mid stack.
UNetMidBlock2D
UNetMidBlock2D configured the way the SD VAE uses it:
UpDecoderBlock2D
UpDecoderBlock2D — a stack of layers_per_block + 1 resnets at out_channels, optionally followed by an Upsample2D.
Upsample2D
Diffusers-style Upsample2D — nearest-neighbor 2x interpolation followed by a Conv2d(C, C, k=3, pad=1, bias=True).