class_docstr: Discrete Autoencoder Codec (DAC) for audio data encoding and decoding.
  
  This class implements an autoencoder architecture with quantization for efficient audio processing.
  It includes an encoder, quantizer, and decoder for transforming audio data into a compressed latent representation and reconstructing it back into audio.
  This implementation supports both initializing a new model and loading a pretrained model.
  
  Parameters
  ----------
  encoder_dim : int
      Dimensionality of the encoder.
  encoder_rates : List[int]
      Downsampling rates for each encoder layer.
  latent_dim : int, optional
      Dimensionality of the latent space, automatically calculated if None.
  decoder_dim : int
      Dimensionality of the decoder.
  decoder_rates : List[int]
      Upsampling rates for each decoder layer.
  n_codebooks : int
      Number of codebooks for vector quantization.
  codebook_size : int
      Size of each codebook.
  codebook_dim : Union[int, list]
      Dimensionality of each codebook entry.
  quantizer_dropout : bool
      Whether to use dropout in the quantizer.
  sample_rate : int
      Sample rate of the audio data.
  model_type : str
      Type of the model to load (if pretrained).
  model_bitrate : str
      Bitrate of the model to load (if pretrained).
  tag : str
      Specific tag of the model to load (if pretrained).
  load_path : str, optional
      Path to load the pretrained model from, automatically downloaded if None.
  strict : bool
      Whether to strictly enforce the state dictionary match.
  load_pretrained : bool
      Whether to load a pretrained model.
  
  Example
  -------
  Creating a new DAC instance:
  
  >>> dac = DAC()
  >>> audio_data = torch.randn(1, 1, 16000) # Example shape: [Batch, Channels, Time]
  >>> tokens, embeddings = dac(audio_data)
  
  
  Loading a pretrained DAC instance:
  
  >>> dac = DAC(load_pretrained=True, model_type="44KHz", model_bitrate="8kbps", tag="latest")
  >>> audio_data = torch.randn(1, 1, 16000) # Example shape: [Batch, Channels, Time]
  >>> tokens, embeddings = dac(audio_data)
  
  The tokens and the discrete embeddings obtained above or from other sources can be decoded:
  
  >>> dac = DAC(load_pretrained=True, model_type="44KHz", model_bitrate="8kbps", tag="latest")
  >>> audio_data = torch.randn(1, 1, 16000) # Example shape: [Batch, Channels, Time]
  >>> tokens, embeddings = dac(audio_data)
  >>> decoded_audio = dac.decode(embeddings)
class_docstr_tok: ["Discrete","Autoencoder","Codec","(","DAC",")","for","audio","data","encoding","and","decoding",".","This","class","implements","an","autoencoder","architecture","with","quantization","for","efficient","audio","processing",".","It","includes","an","encoder",",","quantizer",",","and","decoder","for","transforming","audio","data","into","a","compressed","latent","representation","and","reconstructing","it","back","into","audio",".","This","implementation","supports","both","initializing","a","new","model","and","loading","a","pretrained","model",".","Parameters","--","--","--","--","--","encoder_dim",":","int","Dimensionality","of","the","encoder",".","encoder_rates",":","List","[","int","]","Downsampling","rates","for","each","encoder","layer",".","latent_dim",":","int",",","optional","Dimensionality","of","the","latent","space",",","automatically","calculated","if","None",".","decoder_dim",":","int","Dimensionality","of","the","decoder",".","decoder_rates",":","List","[","int","]","Upsampling","rates","for","each","decoder","layer",".","n_codebooks",":","int","Number","of","codebooks","for","vector","quantization",".","codebook_size",":","int","Size","of","each","codebook",".","codebook_dim",":","Union","[","int",",","list","]","Dimensionality","of","each","codebook","entry",".","quantizer_dropout",":","bool","Whether","to","use","dropout","in","the","quantizer",".","sample_rate",":","int","Sample","rate","of","the","audio","data",".","model_type",":","str","Type","of","the","model","to","load","(","if","pretrained",")",".","model_bitrate",":","str","Bitrate","of","the","model","to","load","(","if","pretrained",")",".","tag",":","str","Specific","tag","of","the","model","to","load","(","if","pretrained",")",".","load_path",":","str",",","optional","Path","to","load","the","pretrained","model","from",",","automatically","downloaded","if","None",".","strict",":","bool","Whether","to","strictly","enforce","the","state","dictionary","match",".","load_pretrained",":","bool","Whether","to","load","a","pretrained","model",".","Example","--","--","--","-","Creating","a","new","DAC","instance",":",">",">",">","dac","=","DAC","(",")",">",">",">","audio_data","=","torch.randn","(","1",",","1",",","16000",")","#","Example","shape",":","[","Batch",",","Channels",",","Time","]",">",">",">","tokens",",","embeddings","=","dac","(","audio_data",")","Loading","a","pretrained","DAC","instance",":",">",">",">","dac","=","DAC","(","load_pretrained=True",",","model_type=","''","44KHz","''",",","model_bitrate=","''","8kbps","''",",","tag=","''","latest","''",")",">",">",">","audio_data","=","torch.randn","(","1",",","1",",","16000",")","#","Example","shape",":","[","Batch",",","Channels",",","Time","]",">",">",">","tokens",",","embeddings","=","dac","(","audio_data",")","The","tokens","and","the","discrete","embeddings","obtained","above","or","from","other","sources","can","be","decoded",":",">",">",">","dac","=","DAC","(","load_pretrained=True",",","model_type=","''","44KHz","''",",","model_bitrate=","''","8kbps","''",",","tag=","''","latest","''",")",">",">",">","audio_data","=","torch.randn","(","1",",","1",",","16000",")","#","Example","shape",":","[","Batch",",","Channels",",","Time","]",">",">",">","tokens",",","embeddings","=","dac","(","audio_data",")",">",">",">","decoded_audio","=","dac.decode","(","embeddings",")"]
docstr: Encode given audio data and return quantized latent codes
  
  Parameters
  ----------
  audio_data : Tensor[B x 1 x T]
      Audio data to encode
  n_quantizers : int, optional
      Number of quantizers to use, by default None
      If None, all quantizers are used.
  
  Returns
  -------
  "z" : Tensor[B x D x T]
      Quantized continuous representation of input
  "codes" : Tensor[B x N x T]
      Codebook indices for each codebook
      (quantized discrete representation of input)
  "latents" : Tensor[B x N*D x T]
      Projected latents (continuous representation of input before quantization)
  "vq/commitment_loss" : Tensor[1]
      Commitment loss to train encoder to predict vectors closer to codebook
      entries
  "vq/codebook_loss" : Tensor[1]
      Codebook loss to update the codebook
  "length" : int
      Number of samples in input audio
docstr_tok: ["Encode","given","audio","data","and","return","quantized","latent","codes","Parameters","--","--","--","--","--","audio_data",":","Tensor","[","B","x","1","x","T","]","Audio","data","to","encode","n_quantizers",":","int",",","optional","Number","of","quantizers","to","use",",","by","default","None","If","None",",","all","quantizers","are","used",".","Returns","--","--","--","-","''","z","''",":","Tensor","[","B","x","D","x","T","]","Quantized","continuous","representation","of","input","''","codes","''",":","Tensor","[","B","x","N","x","T","]","Codebook","indices","for","each","codebook","(","quantized","discrete","representation","of","input",")","''","latents","''",":","Tensor","[","B","x","N","*","D","x","T","]","Projected","latents","(","continuous","representation","of","input","before","quantization",")","''","vq\/commitment_loss","''",":","Tensor","[","1","]","Commitment","loss","to","train","encoder","to","predict","vectors","closer","to","codebook","entries","''","vq\/codebook_loss","''",":","Tensor","[","1","]","Codebook","loss","to","update","the","codebook","''","length","''",":","int","Number","of","samples","in","input","audio"]
code: def encode(
      self,
      audio_data: torch.Tensor,
      n_quantizers: int = None,
  ):
      """Encode given audio data and return quantized latent codes
  
      Parameters
      ----------
      audio_data : Tensor[B x 1 x T]
          Audio data to encode
      n_quantizers : int, optional
          Number of quantizers to use, by default None
          If None, all quantizers are used.
  
      Returns
      -------
      "z" : Tensor[B x D x T]
          Quantized continuous representation of input
      "codes" : Tensor[B x N x T]
          Codebook indices for each codebook
          (quantized discrete representation of input)
      "latents" : Tensor[B x N*D x T]
          Projected latents (continuous representation of input before quantization)
      "vq/commitment_loss" : Tensor[1]
          Commitment loss to train encoder to predict vectors closer to codebook
          entries
      "vq/codebook_loss" : Tensor[1]
          Codebook loss to update the codebook
      "length" : int
          Number of samples in input audio
      """
      z = self.encoder(audio_data)
      (
          z,
          codes,
          latents,
          commitment_loss,
          codebook_loss,
      ) = self.quantizer(z, n_quantizers)
      return z, codes, latents, commitment_loss, codebook_loss
  
imports: import math
  from pathlib import Path
  from typing import List, Union
  import logging
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.nn.utils.parametrizations import weight_norm
label_desc: Use image node_id 2 for calling the DAC obj's underlying member method code with example usage: obj.encode(audio_data, n_quantizers) and returns: z,  codes,  latents,  commitment_loss,  codebook_loss