code: def __init__(
      self,
      device="cuda",
      pretrained="gpt2",
      revision="main",
      low_cpu_mem_usage=None,
      torch_dtype=None,
      device_map=None,
      subfolder=None,
      tokenizer=None,
      batch_size=1,
      load_in_8bit: Optional[bool] = False,
      trust_remote_code: Optional[bool] = False,
      use_fast: Optional[bool] = True,
  ):
      super().__init__()
  
      assert isinstance(device, str)
      assert isinstance(pretrained, str)
      assert isinstance(batch_size, int)
  
      if device:
          if device not in ["cuda", "cpu"]:
              device = int(device)
          self._device = torch.device(device)
          print(f"Using device '{device}'")
      else:
          print("Device not specified")
          print(f"Cuda Available? {torch.cuda.is_available()}")
          self._device = (
              torch.device("cuda")
              if torch.cuda.is_available()
              else torch.device("cpu")
          )
  
      # TODO: update this to be less of a hack once subfolder is fixed in HF
      revision = revision + (
          "/" + subfolder if subfolder is not None else ""
      )
  
      self.gpt2 = transformers.AutoModelForCausalLM.from_pretrained(
          pretrained,
          load_in_8bit=load_in_8bit,
          low_cpu_mem_usage=low_cpu_mem_usage,
          torch_dtype=torch_dtype,
          device_map=device_map,
          revision=revision,
          trust_remote_code=trust_remote_code,
      ).eval()
      if not load_in_8bit:
          try:
              self.gpt2.to(self.device)
          except:  # noqa: E722
              print(
                  "Failed to place model onto specified device. This may be because the model is quantized via `bitsandbytes`. If the desired GPU is being used, this message is safe to ignore."
              )
      self.tokenizer = transformers.AutoTokenizer.from_pretrained(
          pretrained if tokenizer is None else tokenizer,
          revision=revision,
          trust_remote_code=trust_remote_code,
          use_fast=use_fast,
      )
      self.vocab_size = self.tokenizer.vocab_size
  
      # multithreading and batching
      self.batch_size_per_gpu = batch_size
  
file_path: lm-evaluation-harness/lm_eval/models/gpt2.py
imports: import torch
  import transformers
  from typing import Optional, Union
  from lm_eval.base import BaseLM
label_desc: Use image node_id 1 to create a new HFLM object from inherited base classes: BaseLM with example: obj = HFLM(device, pretrained, revision, low_cpu_mem_usage, torch_dtype, device_map, subfolder, tokenizer, batch_size, load_in_8bit, trust_remote_code, use_fast)