code: def convert_ls2hf(
      checkpoint_path, hf_checkpoint_name, pytorch_dump_folder_path
  ):
      device = "cuda:0"
      dirname, modelname = split_checkpoint_path(checkpoint_path)
  
      hf_config = BartConfig.from_pretrained(hf_checkpoint_name)
      ls_model = (
          LSBARTModel.from_pretrained(
              dirname, checkpoint_file=modelname, fp16=False
          )
          .to(device)
          .eval()
      )
      args, model = ls_model.args, ls_model.model
      state_dict = ls_model.model.state_dict()
  
      if args.task != "translation":
          ValueError("task name should be translation")
      if args.arch.startswith("ls"):
          ValueError("Only lightseq model is supported")
  
      # upgrade state dict
      _upgrade_pytorch_state_dict(state_dict, args, model)
      _upgrade_huggingface_bart_base_state_dict(
          state_dict, args.arch, hf_config
      )
  
      # load huggface model
      hf_model = load_huggingface_model(
          state_dict, hf_config, hf_checkpoint_name
      ).to(device)
  
      # forward
      tokens = ls_model.encode(SAMPLE_TEXT).unsqueeze(0).to(device)
      tokens2 = (
          BartTokenizer.from_pretrained(hf_checkpoint_name)
          .encode(SAMPLE_TEXT, return_tensors="pt")
          .unsqueeze(0)
          .to(device)
      )
  
      ls_outputs = ls_model.extract_features(tokens)
      hf_outputs = hf_model.model(tokens)[0]
  
      # Check results
      assert torch.eq(tokens, tokens2).all()
      assert ls_outputs.shape == hf_outputs.shape
      assert torch.allclose(
          ls_outputs.flatten(),
          hf_outputs.flatten(),
          rtol=1e-1,
          atol=1e-1,
          equal_nan=False,
      )
      Path(pytorch_dump_folder_path).mkdir(exist_ok=True)
      hf_model.save_pretrained(pytorch_dump_folder_path)
      print(f"saved model and config in {pytorch_dump_folder_path}")
  
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 8 for calling a global function with example usage: convert_ls2hf(checkpoint_path, hf_checkpoint_name, pytorch_dump_folder_path) without return types