Skip to content
heliaEDGE
Reference
HELIA

residual_vector_quantizer

Machine-readable model

class

Residual Vector Quantizer (RVQ) with straight-through estimator.

helia_edge/layers/residual_vector_quantizer.py:8

ResidualVectorQuantizer(
num_levels: int,
num_embeddings: int | Sequence[int],
embedding_dim: int,
beta: float = 0.25,
**kwargs={},
)

Residual Vector Quantizer (RVQ) with straight-through estimator.

Input: […, D] (last dim = embedding_dim) Output: […, D] (sum of per-level dequantized vectors; gradients pass through x)

Metrics (logged via metrics property):

  • rvq_l{l}_perplexity, rvq_l{l}_usage, rvq_l{l}_bits_per_index
  • rvq_perplexity_mean, rvq_usage_mean, rvq_bits_per_index_sum (entropy lower bound)
Parameters of ResidualVectorQuantizer
NameTypeDefaultDescription
num_levelsintRequiredint, number of residual VQ stages (M >= 1)
num_embeddingsint | Sequence[int]Requiredint OR sequence[int], codebook size K for each level
embedding_dimintRequiredint, latent dimensionality D
betafloat0.25float, commitment coefficient per level
method

call

Python

helia_edge/layers/residual_vector_quantizer.py:93

call(
x: keras.KerasTensor,
return_indices: bool = False,
) -> keras.KerasTensor | tuple[keras.KerasTensor, list[keras.KerasTensor]]
Parameters of call
NameTypeDefaultDescription
xkeras.KerasTensorRequired[..., D] latent to be quantized.
return_indicesboolFalseif True, also returns list of flat indices (one tensor per level).
Returns of call
TypeDescription
keras.KerasTensor | tuple[keras.KerasTensor, list[keras.KerasTensor]]y or (y, indices_list): dequantized vector and optional per-level indices.