Skip to main content

Module vae

Module vae 

Source
Expand description

FLUX-class VAE decoder (diffusers AutoencoderKL, the Lumina-Image 2.0 latent decoder): latents [16, h, w] → RGB [3, 8h, 8w].

First increment of the image-generation runtime (docs/GENERATIVE.ru.md): a plain-Rust NCHW decoder — conv2d, GroupNorm(32), SiLU, spatial self-attention, nearest ×2 upsampling — loaded straight from a diffusers vae/ directory (config.json + safetensors). The CMF packaging comes with the Lumina converter; parity is pinned by a numpy reference (python/vae_ref.py + tests/vae_parity.rs).

Convs run parallel over output channels via scoped threads — naive kernels, good enough to validate the pipeline end-to-end; the im2col

  • GEMM path rides later on the existing matmul kernels.

Structs§

Conv2d
2-D convolution, stride 1, square kernel, symmetric padding (pad = k/2). Parallel over output channels.
GroupNorm
GroupNorm over channel groups (eps 1e-6, affine), NCHW in place.
StTensor
One tensor from a .safetensors file, dequantized to f32.
VaeDecoder
The full decoder: conv_in → mid(res, attn, res) → up-blocks → GroupNorm + SiLU → conv_out, plus the diffusers latent de-normalization z/scaling_factor + shift_factor.

Functions§

read_safetensors
All tensors of one .safetensors file, keyed by name.
read_safetensors_each
Stream every tensor of one .safetensors file through f as f32, one at a time — a 9 GB shard costs one raw blob plus the single tensor in flight, not a second full-file f32 copy.