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","."]
docstr: This function wraps the ``prepare_inputs_for_generation`` function in the huggingface transformers.
  
  When the `past` not in model_kwargs, we prepare the input from scratch.
  When `past` is in model_kwargs, we don't need to prepare the template wrapped input,
  instead we use the inner pretrain_models' function to prepare the next step's input.
  `model_kwargs` includes all the argument passed in the `batch`: InputFeatures, except ``input_ids``
  , as long as they do not conflict with keywords in ``generation_kwargs``.    if 'past' not in model_kwargs: # the past_key_value not in model_kwargs, then we need to prepare input from scrath
  , as long as they do not conflict with keywords in ``generation_kwargs``.
  
  Args:
      input_ids(:obj:`torch.Tensor`): Indices of input sequence tokens in the vocabulary.
docstr_tok: ["This","function","wraps","the","``","prepare_inputs_for_generation","``","function","in","the","huggingface","transformers",".","When","the","`","past","`","not","in","model_kwargs",",","we","prepare","the","input","from","scratch",".","When","`","past","`","is","in","model_kwargs",",","we","do","n't","need","to","prepare","the","template","wrapped","input",",","instead","we","use","the","inner","pretrain_models","'","function","to","prepare","the","next","step","'s","input",".","`","model_kwargs","`","includes","all","the","argument","passed","in","the","`","batch","`",":","InputFeatures",",","except","``","input_ids","``",",","as","long","as","they","do","not","conflict","with","keywords","in","``","generation_kwargs","``",".","if","'past","'","not","in","model_kwargs",":","#","the","past_key_value","not","in","model_kwargs",",","then","we","need","to","prepare","input","from","scrath",",","as","long","as","they","do","not","conflict","with","keywords","in","``","generation_kwargs","``",".","Args",":","input_ids","(",":","obj",":","`","torch.Tensor","`",")",":","Indices","of","input","sequence","tokens","in","the","vocabulary","."]
code: def prepare_inputs_for_generation(
      self, input_ids: Optional[torch.Tensor] = None, **model_kwargs
  ):
      r"""This function wraps the ``prepare_inputs_for_generation`` function in the huggingface transformers.
  
      When the `past` not in model_kwargs, we prepare the input from scratch.
      When `past` is in model_kwargs, we don't need to prepare the template wrapped input,
      instead we use the inner pretrain_models' function to prepare the next step's input.
      `model_kwargs` includes all the argument passed in the `batch`: InputFeatures, except ``input_ids``
      , as long as they do not conflict with keywords in ``generation_kwargs``.    if 'past' not in model_kwargs: # the past_key_value not in model_kwargs, then we need to prepare input from scrath
      , as long as they do not conflict with keywords in ``generation_kwargs``.
  
      Args:
          input_ids(:obj:`torch.Tensor`): Indices of input sequence tokens in the vocabulary.
      """
      if (
          self.generate_ith_token == 0
          and "encoder_outputs" not in model_kwargs
      ):  # generating the first token in decoder only setting.
          batch = InputFeatures(input_ids=input_ids, **model_kwargs)
          model_inputs = self.prompt_model.prepare_model_inputs(batch)
          # check the compatibility for more models. Having checked gpt2, T5
      else:  # generating the subsequence generation can use the default setting
          model_inputs = self.plm.prepare_inputs_for_generation(
              input_ids, **model_kwargs
          )
      self.last_model_inputs = model_inputs  # to update the model_kwargs in _update_model_kwargs_for_generation, in-place operation.
      return model_inputs
  
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 13 for calling the PromptForGeneration obj's underlying member method code with example usage: obj.prepare_inputs_for_generation(input_ids) and returns: model_inputs