VQVAEConfig
GenerativeModelConfigVQVAEConfig(sample_size: int | tuple[int, int] = 32, in_channels: int = 3, out_channels: int = 3, act_fn: Literal['silu', 'swish', 'relu', 'gelu'] = 'relu', num_embeddings: int = 512, embedding_dim: int = 256, hidden_channels: int = 256, num_downsample_layers: int = 2, num_residual_layers: int = 2, residual_hidden_channels: int = 256, commitment_cost: float = 0.25, recon_loss: Literal['mse', 'bce'] = 'mse')Frozen configuration for the VQ-VAE family.
Defaults reproduce the image experiments of van den Oord et al., 2017
(Section 4.1): two stride-2 encoder convolutions with a 4x4 window,
two residual blocks, 256 hidden units throughout, a 512 x 256
codebook, and commitment_cost = 0.25.
Parameters
sample_sizeint or tuple of int= 32GenerativeModelConfig. Must be divisible by
2 ** num_downsample_layers.in_channelsint= 3out_channelsint= 3in_channels.act_fn(silu, swish, relu, gelu)= "silu""silu".num_embeddingsint= 512embedding_dimint= 256hidden_channelsint= 256num_downsample_layersint= 2sample_size / 2 ** num_downsample_layers on a side.num_residual_layersint= 2residual_hidden_channelsint= 256commitment_costfloat= 0.25recon_loss(mse, bce)= "mse""mse") or Bernoulli
("bce", for data in [0, 1]).Attributes
latent_grid_sizetuple of int(H, W) of the discrete latent field, derived from
sample_size and num_downsample_layers.Notes
Reference: van den Oord, Vinyals, and Kavukcuoglu, "Neural Discrete Representation Learning", NeurIPS, 2017 (arXiv:1711.00937).
The paper reports a single image architecture rather than a table of
sized variants, so this family exposes one nominal factory rather than
_small / _base / _large siblings. Scale it by overriding
the fields above at create_model time.
The paper's Appendix A.1 also describes an exponential-moving-average alternative to the codebook loss. That variant changes how the codebook is updated rather than what the network computes, so it belongs to a training loop rather than to the architecture, and is not modelled here.
Examples
>>> from lucid.models.generative.vqvae import VQVAEConfig
>>> cfg = VQVAEConfig(sample_size=32)
>>> cfg.latent_grid_size
(8, 8)
>>> cfg.num_embeddings, cfg.embedding_dim
(512, 256)Used by 3
Constructors
1__init__
→None__init__(sample_size: int | tuple[int, int] = 32, in_channels: int = 3, out_channels: int = 3, act_fn: Literal['silu', 'swish', 'relu', 'gelu'] = 'relu', num_embeddings: int = 512, embedding_dim: int = 256, hidden_channels: int = 256, num_downsample_layers: int = 2, num_residual_layers: int = 2, residual_hidden_channels: int = 256, commitment_cost: float = 0.25, recon_loss: Literal['mse', 'bce'] = 'mse')