Skip to content

vllm_omni.model_executor.models.mimo_audio.quantization

EuclideanCodebook

Bases: Module

Codebook with Euclidean distance. Args: dim (int): Dimension. codebook_size (int): Codebook size. kmeans_init (bool): Whether to use k-means to initialize the codebooks. If set to true, run the k-means algorithm on the first training batch and use the learned centroids as initialization. kmeans_iters (int): Number of iterations used for k-means algorithm at initialization. decay (float): Decay for exponential moving average over the codebooks. epsilon (float): Epsilon value for numerical stability. threshold_ema_dead_code (int): Threshold for dead code expiration. Replace any codes that have an exponential moving average cluster size less than the specified threshold with randomly selected vector from the current batch.

codebook_size instance-attribute

codebook_size = codebook_size

decay instance-attribute

decay = decay

epsilon instance-attribute

epsilon = epsilon

kmeans_iters instance-attribute

kmeans_iters = kmeans_iters

threshold_ema_dead_code instance-attribute

threshold_ema_dead_code = threshold_ema_dead_code

decode

decode(embed_ind)

dequantize

dequantize(embed_ind)

encode

encode(x)

expire_codes_

expire_codes_(batch_samples)

forward

forward(x)

init_embed_

init_embed_(data)

postprocess_emb

postprocess_emb(embed_ind, shape)

preprocess

preprocess(x)

quantize

quantize(x)

replace_

replace_(samples, mask)

ResidualVectorQuantization

Bases: Module

Residual vector quantization implementation. Follows Algorithm 1. in https://arxiv.org/pdf/2107.03312.pdf

layers instance-attribute

layers = ModuleList(
    [
        (
            VectorQuantization(
                codebook_size=codebook_size[i], **kwargs
            )
        )
        for i in (range(num_quantizers))
    ]
)

decode

decode(q_indices: Tensor, st: int = 0) -> Tensor

encode

encode(
    x: Tensor, n_q: int | None = None, st: int | None = None
) -> Tensor

forward

forward(
    x, n_q: int | None = None, layers: list | None = None
)

ResidualVectorQuantizer

Bases: Module

Residual Vector Quantizer. Args: dimension (int): Dimension of the codebooks. n_q (int): Number of residual vector quantizers used. bins (int): Codebook size. decay (float): Decay for exponential moving average over the codebooks. kmeans_init (bool): Whether to use kmeans to initialize the codebooks. kmeans_iters (int): Number of iterations used for kmeans initialization. threshold_ema_dead_code (int): Threshold for dead code expiration. Replace any codes that have an exponential moving average cluster size less than the specified threshold with randomly selected vector from the current batch.

bins instance-attribute

bins = bins

decay instance-attribute

decay = decay

dimension instance-attribute

dimension = dimension

kmeans_init instance-attribute

kmeans_init = kmeans_init

kmeans_iters instance-attribute

kmeans_iters = kmeans_iters

n_q instance-attribute

n_q = n_q

threshold_ema_dead_code instance-attribute

threshold_ema_dead_code = threshold_ema_dead_code

vq instance-attribute

vq = ResidualVectorQuantization(
    dim=dimension,
    codebook_size=bins,
    num_quantizers=n_q,
    decay=decay,
    kmeans_init=kmeans_init,
    kmeans_iters=kmeans_iters,
    threshold_ema_dead_code=threshold_ema_dead_code,
)

decode

decode(codes: Tensor, st: int = 0) -> Tensor

Decode the given codes to the quantized representation. Args: codes (torch.Tensor): Input indices for each quantizer. st (int): Start to decode input codes from which layers. Default: 0.

encode

encode(
    x: Tensor, n_q: int | None = None, st: int | None = None
) -> Tensor

Encode a given input tensor with the specified sample rate at the given bandwidth. The RVQ encode method sets the appropriate number of quantizer to use and returns indices for each quantizer. Args: x (torch.Tensor): Input tensor. n_q (int): Number of quantizer used to quantize. Default: All quantizers. st (int): Start to encode input from which layers. Default: 0.

forward

forward(
    x: Tensor,
    n_q: int | None = None,
    layers: list | None = None,
)

Residual vector quantization on the given input tensor. Args: x (torch.Tensor): Input tensor. n_q (int): Number of quantizer used to quantize. Default: All quantizers. layers (list): Layer that need to return quantized. Default: None. Returns: QuantizedResult: The quantized (or approximately quantized) representation with the associated number quantizers and layer quantized required to return.

VectorQuantization

Bases: Module

Vector quantization implementation. Currently supports only euclidean distance. Args: dim (int): Dimension codebook_size (int): Codebook size codebook_dim (int): Codebook dimension. If not defined, uses the specified dimension in dim. decay (float): Decay for exponential moving average over the codebooks. epsilon (float): Epsilon value for numerical stability. kmeans_init (bool): Whether to use kmeans to initialize the codebooks. kmeans_iters (int): Number of iterations used for kmeans initialization. threshold_ema_dead_code (int): Threshold for dead code expiration. Replace any codes that have an exponential moving average cluster size less than the specified threshold with randomly selected vector from the current batch. commitment_weight (float): Weight for commitment loss.

codebook property

codebook

codebook_size instance-attribute

codebook_size = codebook_size

commitment_weight instance-attribute

commitment_weight = commitment_weight

epsilon instance-attribute

epsilon = epsilon

project_in instance-attribute

project_in = (
    Linear(dim, _codebook_dim)
    if requires_projection
    else Identity()
)

project_out instance-attribute

project_out = (
    Linear(_codebook_dim, dim)
    if requires_projection
    else Identity()
)

decode

decode(embed_ind)

encode

encode(x)

forward

forward(x)

default

default(val: Any, d: Any) -> Any

ema_inplace

ema_inplace(moving_avg, new, decay: float)

kmeans

kmeans(samples, num_clusters: int, num_iters: int = 10)

laplace_smoothing

laplace_smoothing(
    x, n_categories: int, epsilon: float = 1e-05
)

rank

rank()

sample_vectors

sample_vectors(samples, num: int)

uniform_init

uniform_init(*shape: int)

world_size

world_size()