code: def convert_fairseq_model(args):
      if not args.save_dir:
          args.save_dir = (
              os.path.basename(args.fairseq_model_path) + "_gluon"
          )
      if not os.path.exists(args.save_dir):
          os.makedirs(args.save_dir)
  
      fairseq_bart = fairseq_BARTModel.from_pretrained(
          args.fairseq_model_path, checkpoint_file="model.pt"
      )
      vocab_size = convert_vocab(args, fairseq_bart)
      gluon_cfg = convert_config(
          fairseq_bart.cfg.model,
          vocab_size,
          BartModel.get_cfg().clone(),
      )
      with open(os.path.join(args.save_dir, "model.yml"), "w") as of:
          of.write(gluon_cfg.dump())
  
      ctx = mx.gpu(args.gpu) if args.gpu is not None else mx.cpu()
      gluon_bart = convert_params(fairseq_bart, gluon_cfg, ctx)
      if args.test:
          test_model(fairseq_bart, gluon_bart, args.gpu)
  
      gluon_bart.save_parameters(
          os.path.join(args.save_dir, "model.params"), deduplicate=True
      )
      logging.info(
          "Convert the BART MLM model in {} to {}".format(
              os.path.join(args.fairseq_model_path, "model.pt"),
              os.path.join(args.save_dir, "model.params"),
          )
      )
  
      logging.info("Conversion finished!")
      logging.info("Statistics:")
      old_names = os.listdir(args.save_dir)
      for old_name in old_names:
          new_name, long_hash = naming_convention(
              args.save_dir, old_name
          )
          old_path = os.path.join(args.save_dir, old_name)
          new_path = os.path.join(args.save_dir, new_name)
          shutil.move(old_path, new_path)
          file_size = os.path.getsize(new_path)
          logging.info(
              "\t{}/{} {} {}".format(
                  args.save_dir, new_name, long_hash, file_size
              )
          )
  
file_path: gluon-nlp/docs/model_zoo/conversion_toolkits/convert_fairseq_bart.py
imports: import os
  import shutil
  import logging
  import argparse
  import mxnet
  import numpy
  from numpy.testing import assert_allclose
  import torch
  from fairseq.models.bart import BARTModel
  from gluonnlp.utils.misc import sha1sum, logging_config, naming_convention
  from gluonnlp.models.bart import BartModel
  from convert_fairseq_roberta import convert_vocab
label_desc: Use image node_id 6 for calling a global function with example usage: convert_fairseq_model(args) without return types