Implementation:Facebookresearch Audiocraft BaseQuantizer
| 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
- Repository: Facebookresearch_Audiocraft
- File: audiocraft/quantization/base.py
- Lines: 1-99
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 |