code: def build_base_model(model_opt, vocabs):
      """Build a model from opts.
  
      Args:
          model_opt: the option loaded from checkpoint. It's important that
              the opts have been updated and validated. See
              :class:`onmt.utils.parse.ArgumentParser`.
          vocabs (dict[str, Vocab]):
              `Field` objects for the model.
  
      Returns:
          the NMTModel.
      """
  
      # for back compat when attention_dropout was not defined
      try:
          model_opt.attention_dropout
      except AttributeError:
          model_opt.attention_dropout = model_opt.dropout
  
      # Build Model
      model = build_task_specific_model(model_opt, vocabs)
  
      nonlora_to_quant = [
          layer
          for layer in getattr(model_opt, "quant_layers", [])
          if layer not in getattr(model_opt, "lora_layers", [])
      ]
  
      if (
          hasattr(model_opt, "quant_layers")
          and len(nonlora_to_quant) > 0
      ):
          if model_opt.quant_type in ["bnb_8bit", "bnb_FP4", "bnb_NF4"]:
              logger.info(
                  "%s compression of layer %s"
                  % (model_opt.quant_type, nonlora_to_quant)
              )
              try:
                  from onmt.modules.bnb_linear import replace_bnb_linear
              except ImportError:
                  raise ImportError(
                      "Install bitsandbytes to use 4/8bit compression"
                  )
              model = replace_bnb_linear(
                  model,
                  module_to_convert=nonlora_to_quant,
                  q_type=model_opt.quant_type,
              )
          elif model_opt.quant_type in ["awq_gemm", "awq_gemv"]:
              logger.info(
                  "%s compression of layer %s"
                  % (model_opt.quant_type, nonlora_to_quant)
              )
              try:
                  from onmt.modules.awq_linear import replace_awq_linear
              except ImportError:
                  raise ImportError(
                      "Install AutoAWQ to use awq quantized model"
                  )
              model = replace_awq_linear(
                  model,
                  module_to_convert=nonlora_to_quant,
                  w_bit=model_opt.w_bit,
                  group_size=model_opt.group_size,
                  q_type=model_opt.quant_type,
              )
          else:
              logger.info(
                  "compression type %s not supported."
                  % model_opt.quant_type
              )
  
      mark_lora = False
      if (
          hasattr(model_opt, "lora_layers")
          and len(model_opt.lora_layers) > 0
      ):
          if model_opt.freeze_encoder or model_opt.freeze_decoder:
              raise ValueError(
                  "Cannot use LoRa with Enc/Dec-oder freezing"
              )
          for layer in model_opt.lora_layers:
              if (
                  hasattr(model_opt, "quant_layers")
                  and layer in model_opt.quant_layers
              ):
                  quant_type = model_opt.quant_type
              else:
                  quant_type = None
              logger.info(
                  "Adding LoRa layers for %s quant %s"
                  % (layer, quant_type)
              )
              model = replace_lora_linear(
                  model,
                  r=model_opt.lora_rank,
                  lora_alpha=model_opt.lora_alpha,
                  lora_dropout=model_opt.lora_dropout,
                  layer=layer,
                  quant_type=quant_type,
                  use_ckpting=model_opt.use_ckpting,
              )
          mark_lora = True
      if (
          hasattr(model_opt, "lora_embedding")
          and model_opt.lora_embedding
      ):
          if model_opt.freeze_encoder or model_opt.freeze_decoder:
              raise ValueError(
                  "Cannot use LoRa with Enc/Dec-oder freezing"
              )
          logger.info("Adding LoRa Embeddings")
          model = replace_lora_embedding(
              model,
              r=model_opt.lora_rank,
              lora_alpha=model_opt.lora_alpha,
          )
          mark_lora = True
  
      if mark_lora:
          mark_only_lora_as_trainable(model, bias="lora_only")
  
      # Build Generator.
      if not model_opt.copy_attn:
          generator = skip_init(
              nn.Linear,
              in_features=model_opt.dec_hid_size,
              out_features=len(vocabs["tgt"]),
          )
          if model_opt.share_decoder_embeddings:
              generator.weight = (
                  model.decoder.embeddings.word_lut.weight
              )
      else:
          vocab_size = len(vocabs["tgt"])
          pad_idx = vocabs["tgt"][DefaultTokens.PAD]
          generator = CopyGenerator(
              model_opt.dec_hid_size, vocab_size, pad_idx
          )
          if model_opt.share_decoder_embeddings:
              generator.linear.weight = (
                  model.decoder.embeddings.word_lut.weight
              )
  
      model.generator = generator
  
      return model
  
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 10 for calling a global function with example usage: build_base_model(model_opt, vocabs) and returns: model