code: def test_roberta(model_name):
      # test from pretrained
      with tempfile.TemporaryDirectory() as root:
          (
              cfg,
              tokenizer,
              params_path,
              mlm_params_path,
          ) = get_pretrained_roberta(
              model_name, load_backbone=True, load_mlm=True, root=root
          )
          assert cfg.MODEL.vocab_size == len(tokenizer.vocab)
          # test backbone
          roberta_model = RobertaModel.from_cfg(cfg)
          roberta_model.load_parameters(params_path)
          roberta_model.hybridize()
          # test mlm model
          roberta_mlm_model = RobertaForMLM(cfg)
          if mlm_params_path is not None:
              roberta_mlm_model.load_parameters(mlm_params_path)
          roberta_mlm_model = RobertaForMLM(cfg)
          roberta_mlm_model.backbone_model.load_parameters(params_path)
  
          # test forward
          batch_size = 3
          seq_length = 32
          vocab_size = len(tokenizer.vocab)
          input_ids = mx.np.array(
              np.random.randint(
                  2, vocab_size, (batch_size, seq_length)
              ),
              dtype=np.int32,
          )
          valid_length = mx.np.array(
              np.random.randint(
                  seq_length // 2, seq_length, (batch_size,)
              ),
              dtype=np.int32,
          )
          roberta_model(input_ids, valid_length)
          mx.npx.waitall()
          # test backward
          label_smooth_loss = LabelSmoothCrossEntropyLoss(
              num_labels=vocab_size
          )
          with mx.autograd.record():
              contextual_embeddings, pooled_out = roberta_model(
                  input_ids, valid_length
              )
              loss = label_smooth_loss(contextual_embeddings, input_ids)
              loss.backward()
          mx.npx.waitall()
  
file_path: gluon-nlp/tests/test_models_roberta.py
imports: import pytest
  import numpy
  import mxnet
  import tempfile
  from numpy.testing import assert_allclose
  from gluonnlp.models.roberta import RobertaModel, RobertaForMLM, list_pretrained_roberta, get_pretrained_roberta
  from gluonnlp.loss import LabelSmoothCrossEntropyLoss
  from gluonnlp.utils.testing import verify_backbone_fp16
label_desc: Use image node_id 3 for calling a global function with example usage: test_roberta(model_name) without return types