class_docstr: Solver for compression task.
  
  The compression task combines a set of perceptual and objective losses
  to train an EncodecModel (composed of an encoder-decoder and a quantizer)
  to perform high fidelity audio reconstruction.
class_docstr_tok: ["Solver","for","compression","task",".","The","compression","task","combines","a","set","of","perceptual","and","objective","losses","to","train","an","EncodecModel","(","composed","of","an","encoder-decoder","and","a","quantizer",")","to","perform","high","fidelity","audio","reconstruction","."]
code: def load_from_pretrained(self, name: str) -> dict:
      model = models.CompressionModel.get_pretrained(name)
      if isinstance(model, models.DAC):
          raise RuntimeError("Cannot fine tune a DAC model.")
      elif isinstance(model, models.HFEncodecCompressionModel):
          self.logger.warning(
              "Trying to automatically convert a HuggingFace model "
              "to AudioCraft, this might fail!"
          )
          state = model.model.state_dict()
          new_state = {}
          for k, v in state.items():
              if (
                  k.startswith("decoder.layers")
                  and ".conv." in k
                  and ".block." not in k
              ):
                  # We need to determine if this a convtr or a regular conv.
                  layer = int(k.split(".")[2])
                  if isinstance(
                      model.model.decoder.layers[layer].conv,
                      torch.nn.ConvTranspose1d,
                  ):
                      k = k.replace(".conv.", ".convtr.")
              k = k.replace("encoder.layers.", "encoder.model.")
              k = k.replace("decoder.layers.", "decoder.model.")
              k = k.replace("conv.", "conv.conv.")
              k = k.replace("convtr.", "convtr.convtr.")
              k = k.replace("quantizer.layers.", "quantizer.vq.layers.")
              k = k.replace(".codebook.", "._codebook.")
              new_state[k] = v
          state = new_state
      elif isinstance(model, models.EncodecModel):
          state = model.state_dict()
      else:
          raise RuntimeError(
              f"Cannot fine tune model type {type(model)}."
          )
      return {"best_state": {"model": state}}
  
imports: import logging
  import multiprocessing
  from pathlib import Path
  import typing
  import flashy
  import omegaconf
  import torch
  from torch import nn
  from .None import base, builders
  from ..None import models, quantization
  from ..utils import checkpoint
  from ..utils.samples.manager import SampleManager
  from ..utils.utils import get_pool_executor
label_desc: Use image node_id 10 for calling the CompressionSolver obj's underlying member method code with example usage: obj.load_from_pretrained(name) and returns: dict