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_xlmr = fairseq_XLMRModel.from_pretrained(
          args.fairseq_model_path, checkpoint_file="model.pt"
      )
      vocab_size = convert_vocab(args, fairseq_xlmr)
  
      gluon_cfg = convert_config(
          fairseq_xlmr.args, vocab_size, XLMRModel.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_xlmr = convert_params(fairseq_xlmr, gluon_cfg, ctx)
      if args.test:
          test_model(fairseq_xlmr, gluon_xlmr, args.gpu)
  
      gluon_xlmr.save_parameters(
          os.path.join(args.save_dir, "model_mlm.params"),
          deduplicate=True,
      )
      logging.info(
          "Convert the RoBERTa MLM model in {} to {}".format(
              os.path.join(args.fairseq_model_path, "model.pt"),
              os.path.join(args.save_dir, "model_mlm.params"),
          )
      )
      gluon_xlmr.backbone_model.save_parameters(
          os.path.join(args.save_dir, "model.params"), deduplicate=True
      )
      logging.info(
          "Convert the RoBERTa backbone 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:")
      rename(args.save_dir)
  
file_path: gluon-nlp/docs/model_zoo/conversion_toolkits/convert_fairseq_xlmr.py
imports: import os
  import copy
  import logging
  import argparse
  import mxnet
  from gluonnlp.utils.misc import logging_config
  from gluonnlp.models.xlmr import XLMRModel, XLMRForMLM
  from gluonnlp.third_party import sentencepiece_model_pb2
  from fairseq.models.roberta import XLMRModel
  from convert_fairseq_roberta import rename, test_model, test_vocab, convert_config, convert_params
  from gluonnlp.data.tokenizers import SentencepieceTokenizer
label_desc: Use image node_id 3 for calling a global function with example usage: convert_fairseq_model(args) without return types