code: def load_model(ckpt_path, device, config, model_type="text"):
      logger.info(f"loading {model_type} model from {ckpt_path}...")
  
      if device == "cpu":
          logger.warning(
              "No GPU being used. Careful, Inference might be extremely slow!"
          )
      if model_type == "text":
          ConfigClass = GPTConfig
          ModelClass = GPT
      elif model_type == "coarse":
          ConfigClass = GPTConfig
          ModelClass = GPT
      elif model_type == "fine":
          ConfigClass = FineGPTConfig
          ModelClass = FineGPT
      else:
          raise NotImplementedError()
      if (
          not config.USE_SMALLER_MODELS
          and os.path.exists(ckpt_path)
          and _md5(ckpt_path)
          != config.REMOTE_MODEL_PATHS[model_type]["checksum"]
      ):
          logger.warning(
              f"found outdated {model_type} model, removing..."
          )
          os.remove(ckpt_path)
      if not os.path.exists(ckpt_path):
          logger.info(f"{model_type} model not found, downloading...")
          _download(
              config.REMOTE_MODEL_PATHS[model_type]["path"],
              ckpt_path,
              config.CACHE_DIR,
          )
  
      checkpoint = torch.load(ckpt_path, map_location=device)
      # this is a hack
      model_args = checkpoint["model_args"]
      if "input_vocab_size" not in model_args:
          model_args["input_vocab_size"] = model_args["vocab_size"]
          model_args["output_vocab_size"] = model_args["vocab_size"]
          del model_args["vocab_size"]
  
      gptconf = ConfigClass(**checkpoint["model_args"])
      if model_type == "text":
          config.semantic_config = gptconf
      elif model_type == "coarse":
          config.coarse_config = gptconf
      elif model_type == "fine":
          config.fine_config = gptconf
  
      model = ModelClass(gptconf)
      state_dict = checkpoint["model"]
      # fixup checkpoint
      unwanted_prefix = "_orig_mod."
      for k, _ in list(state_dict.items()):
          if k.startswith(unwanted_prefix):
              state_dict[k[len(unwanted_prefix) :]] = state_dict.pop(k)
      extra_keys = set(state_dict.keys()) - set(
          model.state_dict().keys()
      )
      extra_keys = set(
          k for k in extra_keys if not k.endswith(".attn.bias")
      )
      missing_keys = set(model.state_dict().keys()) - set(
          state_dict.keys()
      )
      missing_keys = set(
          k for k in missing_keys if not k.endswith(".attn.bias")
      )
      if len(extra_keys) != 0:
          raise ValueError(f"extra keys found: {extra_keys}")
      if len(missing_keys) != 0:
          raise ValueError(f"missing keys: {missing_keys}")
      model.load_state_dict(state_dict, strict=False)
      n_params = model.get_num_params()
      val_loss = checkpoint["best_val_loss"].item()
      logger.info(
          f"model loaded: {round(n_params/1e6,1)}M params, {round(val_loss,3)} loss"
      )
      model.eval()
      model.to(device)
      del checkpoint, state_dict
      clear_cuda_cache()
      return model, config
  
file_path: TTS/TTS/tts/layers/bark/load_model.py
imports: import contextlib
  import functools
  import hashlib
  import logging
  import os
  import requests
  import torch
  import tqdm
  from TTS.tts.layers.bark.model import GPT, GPTConfig
  from TTS.tts.layers.bark.model_fine import FineGPT, FineGPTConfig
label_desc: Use image node_id 5 for calling a global function with example usage: load_model(ckpt_path, device, config, model_type) and returns: model,  config