code: def load_test_model(opt, device_id=0, model_path=None):
      if model_path is None:
          model_path = opt.models[0]
      checkpoint = load_checkpoint(model_path)
  
      model_opt = ArgumentParser.ckpt_model_opts(checkpoint["opt"])
  
      if hasattr(model_opt, "quant_type") and model_opt.quant_type in [
          "awq_gemm",
          "awq_gemv",
      ]:  # if the loaded model is a awq quantized one, inference config cannot overwrite this
          if (
              hasattr(opt, "quant_type")
              and opt.quant_type != ""
              and opt.quant_type != model_opt.quant_type
          ):
              raise ValueError(
                  "Model is a awq quantized model, cannot overwrite with another quant method"
              )
  
      elif hasattr(opt, "quant_type") and opt.quant_type not in [
          "awq_gemm",
          "awq_gemv",
      ]:  # we still want to be able to load fp16/32 models with bnb 4bit to minimize ram footprint
          model_opt.quant_layers = opt.quant_layers
          model_opt.quant_type = opt.quant_type
          model_opt.lora_layers = []
  
      if opt.world_size > 1 and opt.parallel_mode == "tensor_parallel":
          model_opt.world_size = opt.world_size
          model_opt.parallel_mode = opt.parallel_mode
          model_opt.gpu_ranks = opt.gpu_ranks
          device = torch.device("cuda", device_id)
          offset = device_id
      else:
          if use_gpu(opt):
              if len(opt.gpu_ranks) > 0:
                  device_id = opt.gpu_ranks[0]
              elif opt.gpu > -1:
                  device_id = opt.gpu
              device = torch.device("cuda", device_id)
          else:
              device = torch.device("cpu")
          offset = 0
  
      if hasattr(opt, "self_attn_type"):
          model_opt.self_attn_type = opt.self_attn_type
  
      ArgumentParser.update_model_opts(model_opt)
      ArgumentParser.validate_model_opts(model_opt)
      vocabs = dict_to_vocabs(checkpoint["vocab"])
  
      # Avoid functionality on inference
      model_opt.update_vocab = False
      model_opt.attention_dropout = (
          0.0  # required to force no dropout at inference with flash
      )
  
      model = build_base_model(model_opt, vocabs)
  
      precision = torch.float32
  
      if opt.precision == "fp16":
          precision = torch.float16
      elif opt.precision == "int8":
          if opt.gpu >= 0:
              raise ValueError(
                  "Dynamic 8-bit quantization is not supported on GPU"
              )
          else:
              precision = torch.float32
  
      logger.info("Loading data into the model")
  
      if "model" in checkpoint.keys():
          # weights are in the .pt file
          model.load_state_dict(
              checkpoint,
              precision=precision,
              device=device,
              strict=True,
              offset=offset,
          )
      else:
          # weights are not in the .pt checkpoint but stored in the safetensors file
          base_name = (
              model_path[:-3]
              if model_path[-3:] == ".pt"
              else model_path
          )
          model.load_safe_state_dict(
              base_name,
              precision=precision,
              device=device,
              strict=True,
              offset=offset,
          )
  
      if opt.precision == torch.int8:
          torch.quantization.quantize_dynamic(
              model, dtype=torch.qint8, inplace=True
          )
  
      del checkpoint
  
      model.eval()
      for name, module in model.named_modules():
          if hasattr(module, "dropout_p"):
              module.dropout_p = 0.0
  
      return vocabs, model, model_opt
  
imports: import torch
  import torch.nn
  from torch.nn.utils import skip_init
  from torch.nn.init import xavier_uniform_, zeros_, uniform_
  from onmt.models.model import NMTModel, LanguageModel
  from onmt.encoders import str2enc
  from onmt.decoders import str2dec
  from onmt.inputters.inputter import dict_to_vocabs
  from onmt.modules import Embeddings, CopyGenerator
  from onmt.utils.misc import use_gpu
  from onmt.utils.logging import logger
  from onmt.utils.parse import ArgumentParser
  from onmt.models.model_saver import load_checkpoint
  from onmt.constants import DefaultTokens, ModelTask
  from onmt.modules.lora import replace_lora_linear, replace_lora_embedding, mark_only_lora_as_trainable
label_desc: Use image node_id 4 for calling a global function with example usage: load_test_model(opt, device_id, model_path) and returns: vocabs,  model,  model_opt