code: def use_embeddings_from_checkpoint(vocabs, model, checkpoint):
      # Update vocabulary embeddings with checkpoint embeddings
      logger.info(
          "Updating vocabulary embeddings with checkpoint embeddings"
      )
      # Embedding layers
      enc_emb_name = (
          "encoder.embeddings.make_embedding.emb_luts.0.weight"
      )
      dec_emb_name = (
          "decoder.embeddings.make_embedding.emb_luts.0.weight"
      )
      model_dict = {
          k: v
          for k, v in model.state_dict().items()
          if "generator" not in k
      }
      generator_dict = model.generator.state_dict()
      for side, emb_name in [
          ("src", enc_emb_name),
          ("tgt", dec_emb_name),
      ]:
          if emb_name not in checkpoint["model"]:
              continue
          new_tokens = []
          ckp_vocabs = dict_to_vocabs(checkpoint["vocab"])
          for i, tok in enumerate(vocabs[side].ids_to_tokens):
              if tok in ckp_vocabs[side]:
                  old_i = ckp_vocabs[side].lookup_token(tok)
                  model_dict[emb_name][i] = checkpoint["model"][
                      emb_name
                  ][old_i]
                  if side == "tgt":
                      generator_dict["weight"][i] = checkpoint[
                          "generator"
                      ]["weight"][old_i]
                      generator_dict["bias"][i] = checkpoint[
                          "generator"
                      ]["bias"][old_i]
              else:
                  # Just for debugging purposes
                  new_tokens.append(tok)
          logger.info("%s: %d new tokens" % (side, len(new_tokens)))
  
          # Remove old vocabulary associated embeddings
          del checkpoint["model"][emb_name]
      del (
          checkpoint["generator"]["weight"],
          checkpoint["generator"]["bias"],
      )
      fake_ckpt = {"model": model_dict, "generator": generator_dict}
      model.load_state_dict(fake_ckpt)
  
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 9 for calling a global function with example usage: use_embeddings_from_checkpoint(vocabs, model, checkpoint) without return types