class_docstr: Hugging Face GPT2 Agent.
  
  GPT2 is a multi-layer decoder-only Transformer.
  The decoder is initialized with pretrained weights from Hugging Face.
  Read more about this model here
  <https://huggingface.co/transformers/model_doc/gpt2.html>.
  
  GPT2 comes in five sizes: distilgpt2, small, medium, large, XL. Use the
  flag `--gpt2-size` to choose the size.
  
  If you are finetuning the Gpt2 agent as a dialogue agent, be sure
  to run `--add-special-tokens True`. To examine the performance of the
  agent out of the box, run with `--add-special-tokens False`, and make
  sure that the batch size is 1.
class_docstr_tok: ["Hugging","Face","GPT2","Agent",".","GPT2","is","a","multi-layer","decoder-only","Transformer",".","The","decoder","is","initialized","with","pretrained","weights","from","Hugging","Face",".","Read","more","about","this","model","here","<","https",":","\/\/huggingface.co\/transformers\/model_doc\/gpt2.html",">",".","GPT2","comes","in","five","sizes",":","distilgpt2",",","small",",","medium",",","large",",","XL",".","Use","the","flag","`","--","gpt2-size","`","to","choose","the","size",".","If","you","are","finetuning","the","Gpt2","agent","as","a","dialogue","agent",",","be","sure","to","run","`","--","add-special-tokens","True","`",".","To","examine","the","performance","of","the","agent","out","of","the","box",",","run","with","`","--","add-special-tokens","False","`",",","and","make","sure","that","the","batch","size","is","1","."]
code: def __init__(self, opt, shared=None):
      if not opt["add_special_tokens"] and opt.get("batchsize", 1) > 1:
          # *** STOP ***
          # You may be a future researcher who has stumbled upon this odd
          # restriction, and is tempted to comment this out. After all, the
          # code still runs when it's uncommented, why shouldn't you?
          # You should know this has serious implications, as gpt2 doesn't have
          # padding tokens. This is incompatible with ParlAI's batching,
          # which puts conversations of different length in the same
          # batch. Without a padding token, nonsense will be inserted into
          # the context, and the generations & PPL you get will be wrong.
          raise RuntimeError(
              "If using batchsize > 1, --add-special-tokens must be True."
          )
      if not opt["add_special_tokens"] and opt["add_start_token"]:
          raise RuntimeError(
              "--add-start-token true requires --add-special-tokens true"
          )
      super().__init__(opt, shared)
      if hasattr(self.model, "module"):
          self.START_IDX = self.model.module.START_IDX
          self.END_IDX = self.model.module.END_IDX
          self.NULL_IDX = self.model.module.NULL_IDX
      else:
          self.START_IDX = self.model.START_IDX
          self.END_IDX = self.model.END_IDX
          self.NULL_IDX = self.model.NULL_IDX
  
imports: from typing import Optional
  from parlai.core.params import ParlaiParser
  from parlai.core.opt import Opt
  import os
  import torch
  from parlai.agents.hugging_face.dict import Gpt2DictionaryAgent
  from parlai.core.torch_generator_agent import TorchGeneratorAgent, TorchGeneratorModel
  from parlai.utils.io import PathManager
  from parlai.utils.misc import warn_once
  from parlai.utils.torch import IdentityLayer, padded_tensor
label_desc: Use image node_id 2 to create a new Gpt2Agent object from inherited base classes: TorchGeneratorAgent with example: obj = Gpt2Agent(opt, shared)