code: def _upgrade_huggingface_bart_base_state_dict(
      state_dict, arch, hf_config
  ):
      embed_weight = state_dict["encoder.embed_tokens.weight"]
      offset = hf_config.vocab_size - embed_weight.shape[0]
      if offset > 0:
          h = torch.zeros(offset, embed_weight.shape[1]).to(
              embed_weight
          )
  
      def truncate_emb(key):
          if key in state_dict:
              if offset > 0:
                  state_dict[key] = torch.cat(
                      (state_dict[key], h), dim=0
                  )
              else:
                  state_dict[key] = state_dict[key][:offset, :]
  
      if offset != 0:
          truncate_emb("encoder.embed_tokens.weight")
          truncate_emb("decoder.embed_tokens.weight")
          truncate_emb("encoder.output_projection.weight")
          truncate_emb("decoder.output_projection.weight")
  
      state_dict["shared.weight"] = state_dict[
          "decoder.embed_tokens.weight"
      ]
  
file_path: lightseq/examples/training/fairseq/ls_finetune_bart/convert_lightseq_to_huggingface.py
imports: import argparse
  from pathlib import Path
  import fairseq
  import torch
  from packaging import version
  from torch import nn
  from transformers import BartConfig, BartForConditionalGeneration, BartForSequenceClassification, BartModel, BartTokenizer
  from lightseq.training.cli.fs_modules import LSBARTModel
  from fairseq.models.bart import BARTModel
label_desc: Use image node_id 4 for calling a global function with example usage: _upgrade_huggingface_bart_base_state_dict(state_dict, arch, hf_config) without return types