code: def convert_params(fairseq_model, gluon_cfg, ctx):
      fairseq_params = fairseq_model.state_dict()
      fairseq_prefix = "model.encoder."
      gluon_prefix = "backbone_model."
      print("converting {} params".format(gluon_prefix))
  
      gluon_model = RobertaForMLM(backbone_cfg=gluon_cfg)
      # output all hidden states for testing
      gluon_model.backbone_model._output_all_encodings = True
      gluon_model.backbone_model.encoder._output_all_encodings = True
  
      gluon_model.initialize(ctx=ctx)
      gluon_model.hybridize()
      gluon_params = gluon_model.collect_params()
      num_layers = gluon_cfg.MODEL.num_layers
      for layer_id in range(num_layers):
          fs_atten_prefix = (
              "{}sentence_encoder.layers.{}.self_attn.".format(
                  fairseq_prefix, layer_id
              )
          )
          fs_q_weight = (
              fairseq_params[fs_atten_prefix + "q_proj.weight"]
              .cpu()
              .numpy()
          )
          fs_k_weight = (
              fairseq_params[fs_atten_prefix + "k_proj.weight"]
              .cpu()
              .numpy()
          )
          fs_v_weight = (
              fairseq_params[fs_atten_prefix + "v_proj.weight"]
              .cpu()
              .numpy()
          )
          fs_q_bias = (
              fairseq_params[fs_atten_prefix + "q_proj.bias"]
              .cpu()
              .numpy()
          )
          fs_k_bias = (
              fairseq_params[fs_atten_prefix + "k_proj.bias"]
              .cpu()
              .numpy()
          )
          fs_v_bias = (
              fairseq_params[fs_atten_prefix + "v_proj.bias"]
              .cpu()
              .numpy()
          )
          gl_qkv_prefix = "{}encoder.all_layers.{}.attn_qkv.".format(
              gluon_prefix, layer_id
          )
          gl_qkv_weight = gluon_params[gl_qkv_prefix + "weight"]
          gl_qkv_bias = gluon_params[gl_qkv_prefix + "bias"]
          gl_qkv_weight.set_data(
              np.concatenate(
                  [fs_q_weight, fs_k_weight, fs_v_weight], axis=0
              )
          )
          gl_qkv_bias.set_data(
              np.concatenate([fs_q_bias, fs_k_bias, fs_v_bias], axis=0)
          )
  
          for k, v in [
              ("self_attn.out_proj.weight", "attention_proj.weight"),
              ("self_attn.out_proj.bias", "attention_proj.bias"),
              ("self_attn_layer_norm.weight", "layer_norm.gamma"),
              ("self_attn_layer_norm.bias", "layer_norm.beta"),
              ("fc1.weight", "ffn.ffn_1.weight"),
              ("fc1.bias", "ffn.ffn_1.bias"),
              ("fc2.weight", "ffn.ffn_2.weight"),
              ("fc2.bias", "ffn.ffn_2.bias"),
              ("final_layer_norm.weight", "ffn.layer_norm.gamma"),
              ("final_layer_norm.bias", "ffn.layer_norm.beta"),
          ]:
              fs_name = "{}sentence_encoder.layers.{}.{}".format(
                  fairseq_prefix, layer_id, k
              )
              gl_name = "{}encoder.all_layers.{}.{}".format(
                  gluon_prefix, layer_id, v
              )
              gluon_params[gl_name].set_data(
                  fairseq_params[fs_name].cpu().numpy()
              )
  
      for k, v in [
          ("sentence_encoder.embed_tokens.weight", "word_embed.weight"),
          ("sentence_encoder.emb_layer_norm.weight", "embed_ln.gamma"),
          ("sentence_encoder.emb_layer_norm.bias", "embed_ln.beta"),
      ]:
          fs_name = fairseq_prefix + k
          gl_name = gluon_prefix + v
          gluon_params[gl_name].set_data(
              fairseq_params[fs_name].cpu().numpy()
          )
  
      # position embed weight
      padding_idx = fairseq_model.task.dictionary.pad_index
      fs_pos_embed_name = (
          fairseq_prefix + "sentence_encoder.embed_positions.weight"
      )
      gl_pos_embed_name = gluon_prefix + "pos_embed._embed.weight"
      gluon_params[gl_pos_embed_name].set_data(
          fairseq_params[fs_pos_embed_name]
          .cpu()
          .numpy()[padding_idx + 1 :, :]
      )
  
      for k, v in [
          ("lm_head.dense.weight", "mlm_decoder.0.weight"),
          ("lm_head.dense.bias", "mlm_decoder.0.bias"),
          ("lm_head.layer_norm.weight", "mlm_decoder.2.gamma"),
          ("lm_head.layer_norm.bias", "mlm_decoder.2.beta"),
          ("lm_head.bias", "mlm_decoder.3.bias"),
      ]:
          fs_name = fairseq_prefix + k
          gluon_params[v].set_data(
              fairseq_params[fs_name].cpu().numpy()
          )
      # assert untie=False
      assert np.array_equal(
          fairseq_params[
              fairseq_prefix + "sentence_encoder.embed_tokens.weight"
          ]
          .cpu()
          .numpy(),
          fairseq_params[fairseq_prefix + "lm_head.weight"]
          .cpu()
          .numpy(),
      )
      return gluon_model
  
imports: import os
  import re
  import sys
  import json
  import shutil
  import logging
  import argparse
  import mxnet
  import numpy
  from numpy.testing import assert_allclose
  import torch
  from gluonnlp.data.vocab import Vocab
  from gluonnlp.utils.misc import sha1sum, logging_config, naming_convention
  from fairseq.models.roberta import RobertaModel
  from gluonnlp.models.roberta import RobertaModel, RobertaForMLM
  from gluonnlp.data.tokenizers import HuggingFaceByteBPETokenizer
label_desc: Use image node_id 5 for calling a global function with example usage: convert_params(fairseq_model, gluon_cfg, ctx) and returns: gluon_model