Bare convolutional VAE — vanilla / -VAE / hierarchical.
Implements the variational auto-encoder of Kingma and Welling, 2014
in three operating modes selected implicitly by
VAEConfig.latent_dim:
- Vanilla / -VAE (
intlatent_dim): a single bottleneckzis projected from the flattened final encoder stage.encode(x) -> (mu, logvar)with shape(B, D)each;decode(z: (B, D)) -> x_hat. - Hierarchical / Ladder VAE (
tuplelatent_dim, length =len(down_block_channels)): onez_lper encoder stage; the decoder injectsz_lback at the matching upsampling spatial scale.encode(x) -> (mus: list[Tensor], logvars: list[Tensor])withmus[l]of shape(B, latent_dims[l]);decode(zs: list[Tensor]) -> x_hat.
Reparameterisation is applied internally in forward —
,
— so gradients flow
pathwise through the stochastic sample.
Parameters
configVAEConfigdown_block_channels), latent topology (latent_dim), and
loss-related options. See VAEConfig for the full list.Attributes
Notes
Reference: Kingma and Welling, "Auto-Encoding Variational Bayes", ICLR, 2014 (arXiv:1312.6114); hierarchical extension from Sønderby, Raiko, Maaløe, Sønderby, and Winther, "Ladder Variational Autoencoders", NeurIPS, 2016 (arXiv:1602.02282).
The closed-form KL term used by the loss head is
Examples
>>> import lucid
>>> from lucid.models.generative.vae import VAEConfig, VAEModel
>>> cfg = VAEConfig(sample_size=32, in_channels=3, out_channels=3,
... latent_dim=16, down_block_channels=(16, 32, 64))
>>> model = VAEModel(cfg).eval()
>>> x = lucid.randn((1, 3, 32, 32))
>>> out = model(x)
>>> out.sample.shape, out.latent.shape # reconstruction + latent
((1, 3, 32, 32), (1, 16))Used by 2
Constructors
1Properties
2Instance methods
3Map a latent (or list of per-level latents) back to image space.
Return posterior parameters of q(z|x).
Vanilla mode → (mu, logvar). Hierarchical mode → (mus, logvars) with one entry per encoder stage.