uniform_codebook_prior
uniform_codebook_prior
¶
Fixed uniform prior over discrete codebook indices.
The VQ-VAE equivalent of GaussianPrior: samples a random codebook index uniformly and returns the corresponding embedding. No learnable parameters. The codebook is shared from the VQ posterior encoder via wire_posterior().
UniformCodebookPrior
¶
Bases: PriorLatentEncoder
Fixed uniform prior over VQ codebook indices.
Samples each residual VQ layer's index uniformly from {0, ..., K-1}, then decodes to a quantized embedding via the shared codebook. No trainable parameters — the VQ equivalent of GaussianPrior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latent_dimension
|
int
|
Dimension of each codebook vector. |
required |
num_codes
|
int
|
Number of codebook entries per layer (K). |
required |
num_residual_layers
|
int
|
Number of residual VQ layers. |
required |
device
|
str
|
Device string. |
required |
Source code in src/versatil/models/decoding/latent/prior/uniform_codebook_prior.py
residual_vq
property
¶
Return the posterior-owned VQ module without registering it as a child.
__getstate__
¶
Return copy-safe state without the posterior VQ reference.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Module state with runtime wiring cleared. The owning |
dict[str, Any]
|
VariationalAlgorithm reconnects the copied prior to the copied |
dict[str, Any]
|
posterior after deepcopy or unpickling. |
Source code in src/versatil/models/decoding/latent/prior/uniform_codebook_prior.py
get_auxiliary_output_keys
¶
Uniform prior outputs only the quantized latent and sampled indices.
wire_posterior
¶
Wire shared codebook from the VQ posterior encoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
posterior
|
PosteriorLatentEncoder
|
VQ posterior encoder with a residual_vq attribute. |
required |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the posterior does not expose ResidualVQ state. |
ValueError
|
If the posterior's VQ configuration does not match. |
Source code in src/versatil/models/decoding/latent/prior/uniform_codebook_prior.py
forward
¶
Sample uniform codebook indices and decode to embedding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_latents
|
Tensor | None
|
Posterior latent used only to infer batch size. None is accepted; batch size is then derived from observations. |
required |
observations
|
dict[str, Tensor]
|
Observation features used only to infer batch size. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
Dictionary containing: - LatentKey.PRIOR_LATENT: Quantized embedding, shape (B, code_dim). - LatentKey.VQ_PRIOR_INDICES: List of per-layer indices sampled by the prior, each shape (B,). Emitted under a distinct key from the posterior's VQ_INDICES so the two do not collide when merged into the predictions dict. |
Source code in src/versatil/models/decoding/latent/prior/uniform_codebook_prior.py
sample_prior
¶
Sample latent from uniform categorical prior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Number of samples. |
required |
observations
|
dict[str, Tensor] | None
|
Unused (uniform prior is unconditional). |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Quantized latent embedding, shape (batch_size, code_dim). |