class_docstr: ``PromptModel`` with generation loss calculation and generation utils integrated.
  
  
  Args:
      plm (:obj:`PretrainedModel`): A pre-traiend model you decide to use for generation, e.g. GPT.
      template (:obj:`Template`): A ``Template`` object you use to wrap the input text for classification, e.g. ``PrefixTuningTemplate``.
      tokenizer (:obj:`Tokenizer`): A ``Tokenizer`` of the current model.
      gen_config (:obj:`CfgNode`): The generation configs to pass into `GenerationMixin.generate <https://huggingface.co/transformers/_modules/transformers/generation_utils.html#GenerationMixin.generate>`_
      freeze_plm (:obj:`bool`): whether or not to freeze the pretrained language model
      plm_eval_mode (:obj:`bool`): this is a stronger freezing mode than freeze_plm, i.e. the dropout of the model is turned off. No matter whether the other part is set to train.
class_docstr_tok: ["``","PromptModel","``","with","generation","loss","calculation","and","generation","utils","integrated",".","Args",":","plm","(",":","obj",":","`","PretrainedModel","`",")",":","A","pre-traiend","model","you","decide","to","use","for","generation",",","e.g",".","GPT",".","template","(",":","obj",":","`","Template","`",")",":","A","``","Template","``","object","you","use","to","wrap","the","input","text","for","classification",",","e.g",".","``","PrefixTuningTemplate","``",".","tokenizer","(",":","obj",":","`","Tokenizer","`",")",":","A","``","Tokenizer","``","of","the","current","model",".","gen_config","(",":","obj",":","`","CfgNode","`",")",":","The","generation","configs","to","pass","into","`","GenerationMixin.generate","<","https",":","\/\/huggingface.co\/transformers\/_modules\/transformers\/generation_utils.html","#","GenerationMixin.generate",">","`","_","freeze_plm","(",":","obj",":","`","bool","`",")",":","whether","or","not","to","freeze","the","pretrained","language","model","plm_eval_mode","(",":","obj",":","`","bool","`",")",":","this","is","a","stronger","freezing","mode","than","freeze_plm",",","i.e",".","the","dropout","of","the","model","is","turned","off",".","No","matter","whether","the","other","part","is","set","to","train","."]
code: def __init__(
      self,
      plm: PreTrainedModel,
      template: Template,
      freeze_plm: bool = False,
      plm_eval_mode: bool = False,
      gen_config: Optional[CfgNode] = None,
      tokenizer: Optional[PreTrainedTokenizer] = None,
  ):
      super().__init__()
      self.freeze_plm = freeze_plm
      if tokenizer is None:
          assert (
              template.tokenizer is not None
          ), "Tokenizer can't be set from input args or template"
          self.tokenizer = template.tokenizer
      else:
          self.tokenizer = tokenizer
      self.prompt_model = PromptModel(
          plm, template, freeze_plm, plm_eval_mode
      )
  
      self.loss_fct = nn.CrossEntropyLoss(reduction="none")
      self.config = plm.config
      if gen_config:
          for key in gen_config:
              setattr(self.config, key, gen_config[key])
      self.in_generation_function = False
  
      self.main_input_name = self.prompt_model.main_input_name
  
imports: from pickle import FALSE
  from torch.utils.data.sampler import RandomSampler
  from transformers.configuration_utils import PretrainedConfig
  from transformers.generation_utils import GenerationMixin
  import torch
  import torch.nn
  from torch.utils.data import Dataset
  from typing import *
  from openprompt.data_utils import InputExample, InputFeatures
  from torch.utils.data._utils.collate import default_collate
  from tqdm.std import tqdm
  from transformers.tokenization_utils import PreTrainedTokenizer
  from transformers.utils.dummy_pt_objects import PreTrainedModel
  from openprompt.plms.utils import TokenizerWrapper
  from openprompt.prompt_base import Template, Verbalizer
  from collections import defaultdict
  from openprompt.utils import round_list, signature
  import numpy
  from torch.utils.data import DataLoader
  from yacs.config import CfgNode
  from openprompt.utils.logging import logger
  from transformers import AdamW, get_linear_schedule_with_warmup
label_desc: Use image node_id 1 to create a new PromptForGeneration object from inherited base classes: nn, GenerationMixin with example: obj = PromptForGeneration(plm, template, freeze_plm, plm_eval_mode, gen_config, tokenizer)