Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Facebookresearch Audiocraft BaseQuantizer

From Leeroopedia
Revision as of 12:32, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Facebookresearch_Audiocraft_BaseQuantizer.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Quantization, Audio_Compression
Last Updated 2026-02-14 01:00 GMT

Overview

Concrete tool for defining the abstract quantizer interface and data structures used by all vector quantization implementations in AudioCraft.

Description

This module defines QuantizedResult (a dataclass holding quantized tensor, codes, bandwidth, and penalty), BaseQuantizer (the abstract base class with encode/decode/forward interface), and DummyQuantizer (a pass-through implementation for testing). All concrete quantizers (RVQ, etc.) implement this interface.

Usage

Import these base classes when building or extending quantization modules. DummyQuantizer is useful for testing compression models without actual quantization.

Code Reference

Source Location

Signature

@dataclass
class QuantizedResult:
    x: torch.Tensor
    codes: torch.Tensor
    bandwidth: torch.Tensor
    penalty: tp.Optional[torch.Tensor] = None

class BaseQuantizer(nn.Module):
    @abstractmethod
    def forward(self, x: torch.Tensor, frame_rate: int) -> QuantizedResult: ...
    @abstractmethod
    def encode(self, x: torch.Tensor) -> torch.Tensor: ...
    @abstractmethod
    def decode(self, codes: torch.Tensor) -> torch.Tensor: ...

class DummyQuantizer(BaseQuantizer): ...

Import

from audiocraft.quantization.base import BaseQuantizer, QuantizedResult, DummyQuantizer

I/O Contract

Inputs

Name Type Required Description
x torch.Tensor Yes Continuous latent tensor [B, D, T]
frame_rate int Yes Frame rate for bandwidth computation

Outputs

Name Type Description
result QuantizedResult Quantized output with codes and bandwidth

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment