code: def test_gpt2():
      gpt2 = models.get_model("gpt2").create_from_arg_string(
          "device=cpu"
      )
      (
          (ll_dog, ig_dog),
          (ll_cat, ig_cat),
          (_, ll_max_0),
          (_, ll_max_1),
          (_, ll_max_2),
          *vals,
      ) = gpt2.loglikelihood(LOGLIKELIHOOD_TEST_CASES)
  
      assert ll_dog > ll_cat
      assert not ig_cat
  
      assert not ll_max_0
      assert ll_max_1
      assert ll_max_2
  
      # test empty context
      gpt2.loglikelihood([("", "test")])
  
      (gen,) = gpt2.greedy_until(
          [("The quick brown fox jumps over the lazy", [".", "\n"])]
      )
  
      assert gen == ", lazy fox and they both fall to the ground"
  
      targets = [
          -61.60536193847656,
          -56.57843780517578,
          -62.131004333496094,
          -9.799489974975586,
          -153.96334838867188,
          -341.222900390625,
          -731.1475830078125,
          -61.60536193847656,
          -8.682319641113281,
      ]
  
      for (pred, _), tgt in zip(vals, targets):
          assert pred == pytest.approx(tgt, rel=1e-3)
  
file_path: lm-evaluation-harness/tests/test_models.py
imports: import hashlib
  import json
  import openai
  import os
  import pickle
  import pytest
  import unittest.mock
  import lm_eval.models
label_desc: Use image node_id 1 for calling a global function with example usage: test_gpt2() without return types