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: Initializes DAC
  
  Parameters
  ----------
  encoder_dim : int, optional, by default 64
  encoder_rates : List[int], optional, by default [2, 4, 8, 8]
  latent_dim : int, optional, by default None
  decoder_dim : int, optional, by default 1536
  decoder_rates : List[int], optional, by default [8, 8, 4, 2]
  n_codebooks : int, optional, by default 9
  codebook_size : int, optional, by default 1024
  codebook_dim : Union[int, list], optional, by default 8
  quantizer_dropout : bool, optional, by default False
  sample_rate : int, optional, by default 44100
  model_type : str, optional, by default "44khz"
  model_bitrate : str, optional, by default "8kbps"
  tag : str, optional, by default "latest"
  load_path : str, optional, by default None
  strict : bool, optional, by default False
  load_pretrained : bool, optional
       If True, then a pretrained model is loaded, by default False
docstr_tok: ["Initializes","DAC","Parameters","--","--","--","--","--","encoder_dim",":","int",",","optional",",","by","default","64","encoder_rates",":","List","[","int","]",",","optional",",","by","default","[","2",",","4",",","8",",","8","]","latent_dim",":","int",",","optional",",","by","default","None","decoder_dim",":","int",",","optional",",","by","default","1536","decoder_rates",":","List","[","int","]",",","optional",",","by","default","[","8",",","8",",","4",",","2","]","n_codebooks",":","int",",","optional",",","by","default","9","codebook_size",":","int",",","optional",",","by","default","1024","codebook_dim",":","Union","[","int",",","list","]",",","optional",",","by","default","8","quantizer_dropout",":","bool",",","optional",",","by","default","False","sample_rate",":","int",",","optional",",","by","default","44100","model_type",":","str",",","optional",",","by","default","``","44khz","''","model_bitrate",":","str",",","optional",",","by","default","``","8kbps","''","tag",":","str",",","optional",",","by","default","``","latest","''","load_path",":","str",",","optional",",","by","default","None","strict",":","bool",",","optional",",","by","default","False","load_pretrained",":","bool",",","optional","If","True",",","then","a","pretrained","model","is","loaded",",","by","default","False"]
code: def __init__(
      self,
      encoder_dim: int = 64,
      encoder_rates: List[int] = [2, 4, 8, 8],
      latent_dim: int = None,
      decoder_dim: int = 1536,
      decoder_rates: List[int] = [8, 8, 4, 2],
      n_codebooks: int = 9,
      codebook_size: int = 1024,
      codebook_dim: Union[int, list] = 8,
      quantizer_dropout: bool = False,
      sample_rate: int = 44100,
      model_type: str = "44khz",
      model_bitrate: str = "8kbps",
      tag: str = "latest",
      load_path: str = None,
      strict: bool = False,
      load_pretrained: bool = False,
  ):
      """Initializes DAC
  
      Parameters
      ----------
      encoder_dim : int, optional, by default 64
      encoder_rates : List[int], optional, by default [2, 4, 8, 8]
      latent_dim : int, optional, by default None
      decoder_dim : int, optional, by default 1536
      decoder_rates : List[int], optional, by default [8, 8, 4, 2]
      n_codebooks : int, optional, by default 9
      codebook_size : int, optional, by default 1024
      codebook_dim : Union[int, list], optional, by default 8
      quantizer_dropout : bool, optional, by default False
      sample_rate : int, optional, by default 44100
      model_type : str, optional, by default "44khz"
      model_bitrate : str, optional, by default "8kbps"
      tag : str, optional, by default "latest"
      load_path : str, optional, by default None
      strict : bool, optional, by default False
      load_pretrained : bool, optional
           If True, then a pretrained model is loaded, by default False
      """
      super().__init__()
  
      self.encoder_dim = encoder_dim
      self.encoder_rates = encoder_rates
      self.decoder_dim = decoder_dim
      self.decoder_rates = decoder_rates
      self.sample_rate = sample_rate
      self.n_codebooks = n_codebooks
      self.codebook_size = codebook_size
      self.codebook_dim = codebook_dim
      self.latent_dim = latent_dim
      self.quantizer_dropout = quantizer_dropout
  
      if load_pretrained:
          if not load_path:
              load_path = download(
                  model_type=model_type,
                  model_bitrate=model_bitrate,
                  tag=tag,
              )
              logger.info(f"Obtained load path as: {load_path}")
          model_dict = torch.load(load_path, "cpu")
          metadata = model_dict["metadata"]
          for key, value in metadata["kwargs"].items():
              setattr(self, key, value)
  
      self.hop_length = np.prod(self.encoder_rates)
      if self.latent_dim is None:
          self.latent_dim = self.encoder_dim * (
              2 ** len(self.encoder_rates)
          )
      self.encoder = Encoder(
          self.encoder_dim, self.encoder_rates, self.latent_dim
      )
      self.quantizer = ResidualVectorQuantize(
          input_dim=self.latent_dim,
          n_codebooks=self.n_codebooks,
          codebook_size=self.codebook_size,
          codebook_dim=self.codebook_dim,
          quantizer_dropout=self.quantizer_dropout,
      )
      self.decoder = Decoder(
          self.latent_dim,
          self.decoder_dim,
          self.decoder_rates,
      )
      self.apply(init_weights)
  
      if load_pretrained:
          self.load_state_dict(model_dict["state_dict"], strict=strict)
          self.metadata = metadata
  
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 1 to create a new DAC object from inherited base classes: nn with example: obj = DAC(encoder_dim, encoder_rates, latent_dim, decoder_dim, decoder_rates, n_codebooks, codebook_size, codebook_dim, quantizer_dropout, sample_rate, model_type, model_bitrate, tag, load_path, strict, load_pretrained)