code: def test_gpt_eval(self):
      # test greedy
      length_params: LengthParam = {
          "max_length": 30,
          "min_length": 0,
      }
  
      sampling_params: SamplingParam = {
          "use_greedy": True,
          "temperature": 1.0,
          "top_k": 0,
          "top_p": 1.0,
          "repetition_penalty": 1.0,
          "add_BOS": True,
          "all_probs": False,
          "compute_logprob": False,
          "end_strings": ["<|endoftext|>"],
      }
  
      # test logprob
      sampling_params["compute_logprob"] = True
      sentence = "run gpt in inference mode"
      response = self.model.generate(
          inputs=[sentence],
          length_params=length_params,
          sampling_params=sampling_params,
      )
      assert response["sentences"][0] == sentence
      gt_token_ids = [5143, 308, 457, 287, 32278, 4235]
      assert np.array_equal(
          np.array(response["token_ids"][0]), gt_token_ids
      )
      assert len(response["full_logprob"][0]) == 5
      gt_log_prob = [
          -7.9579081535339355,
          -7.195970058441162,
          -5.269130706787109,
          -12.75404167175293,
          -4.631799697875977,
      ]
      assert np.allclose(
          np.array(response["logprob"][0]), gt_log_prob, atol=1e-4
      )
      gt_offsets = [0, 3, 5, 7, 10, 20]
      assert np.array_equal(
          np.array(response["offsets"][0]), gt_offsets
      )
  
      # # test top_p
      sampling_params["compute_logprob"] = False
      sampling_params["use_greedy"] = False
      sampling_params["top_p"] = 0.8
      sampling_params["repetition_penalty"] = 1.2
  
      gt_token_ids = [
          50256,
          15,
          59,
          198,
          59,
          2,
          16,
          59,
          2,
          17,
          58,
          57,
          59,
          62,
          37,
          7,
          39,
          15437,
          90,
          92,
          357,
          2481,
          8,
          3467,
          2,
          18,
          30109,
          9,
          43215,
          13,
          5416,
      ]
      gt_text = "0\\\n\\#1\\#2[Z\\_F(H)]{} (21) \\#3[[*Phys. Rev"
      response = self.model.generate(
          inputs=[""],
          length_params=length_params,
          sampling_params=sampling_params,
      )
      assert np.array_equal(
          np.array(response["token_ids"][0]), gt_token_ids
      )
      assert response["sentences"][0] == gt_text
  
file_path: NeMo/tests/collections/nlp/test_gpt_eval.py
imports: import os
  import numpy
  import pytest
  from pytorch_lightning.trainer.trainer import Trainer
  from nemo.collections.nlp.models.language_modeling.megatron_gpt_model import MegatronGPTModel
  from nemo.collections.nlp.modules.common.transformer.text_generation import LengthParam, SamplingParam
  from nemo.collections.nlp.parts.nlp_overrides import NLPDDPStrategy
label_desc: Use image node_id 2 for calling the TestGPTEval obj's underlying member method code with example usage: obj.test_gpt_eval() without return types