docstr: mc_token_ids (:obj:`torch.LongTensor` of shape :obj:`(batch_size, num_choices)`, `optional`, default to index of the last token of the input):
      Index of the classification token in each input sequence. Selected in the range ``[0, input_ids.size(-1) -
      1[``.
  labels (:obj:`torch.LongTensor` of shape :obj:`(batch_size, sequence_length)`, `optional`):
      Labels for language modeling. Note that the labels **are shifted** inside the model, i.e. you can set
      ``labels = input_ids`` Indices are selected in ``[-100, 0, ..., config.vocab_size - 1]`` All labels set to
      ``-100`` are ignored (masked), the loss is only computed for labels in ``[0, ..., config.vocab_size - 1]``
  mc_labels (:obj:`torch.LongTensor` of shape :obj:`(batch_size)`, `optional`):
      Labels for computing the multiple choice classification loss. Indices should be in ``[0, ...,
      num_choices]`` where `num_choices` is the size of the second dimension of the input tensors. (see
      `input_ids` above)
  
  Return:
  
  Example::
  
      >>> import torch
      >>> from transformers import GPT2Tokenizer, GPT2DoubleHeadsModel
  
      >>> tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
      >>> model = GPT2DoubleHeadsModel.from_pretrained('gpt2')
  
      >>> # Add a [CLS] to the vocabulary (we should train it also!)
      >>> num_added_tokens = tokenizer.add_special_tokens({'cls_token': '[CLS]'})
  
      >>> embedding_layer = model.resize_token_embeddings(len(tokenizer))  # Update the model embeddings with the new vocabulary size
  
      >>> choices = ["Hello, my dog is cute [CLS]", "Hello, my cat is cute [CLS]"]
      >>> encoded_choices = [tokenizer.encode(s) for s in choices]
      >>> cls_token_location = [tokens.index(tokenizer.cls_token_id) for tokens in encoded_choices]
  
      >>> input_ids = torch.tensor(encoded_choices).unsqueeze(0)  # Batch size: 1, number of choices: 2
      >>> mc_token_ids = torch.tensor([cls_token_location])  # Batch size: 1
  
      >>> outputs = model(input_ids, mc_token_ids=mc_token_ids)
      >>> lm_logits = outputs.logits
      >>> mc_logits = outputs.mc_logits
docstr_tok: ["mc_token_ids","(",":","obj",":","`","torch.LongTensor","`","of","shape",":","obj",":","`","(","batch_size",",","num_choices",")","`",",","`","optional","`",",","default","to","index","of","the","last","token","of","the","input",")",":","Index","of","the","classification","token","in","each","input","sequence",".","Selected","in","the","range","``","[","0",",","input_ids.size","(","-1",")","-","1","[","``",".","labels","(",":","obj",":","`","torch.LongTensor","`","of","shape",":","obj",":","`","(","batch_size",",","sequence_length",")","`",",","`","optional","`",")",":","Labels","for","language","modeling",".","Note","that","the","labels","*","*","are","shifted","*","*","inside","the","model",",","i.e",".","you","can","set","``","labels","=","input_ids","``","Indices","are","selected","in","``","[","-100",",","0",",","...",",","config.vocab_size","-","1","]","``","All","labels","set","to","``","-100","``","are","ignored","(","masked",")",",","the","loss","is","only","computed","for","labels","in","``","[","0",",","...",",","config.vocab_size","-","1","]","``","mc_labels","(",":","obj",":","`","torch.LongTensor","`","of","shape",":","obj",":","`","(","batch_size",")","`",",","`","optional","`",")",":","Labels","for","computing","the","multiple","choice","classification","loss",".","Indices","should","be","in","``","[","0",",","...",",","num_choices","]","``","where","`","num_choices","`","is","the","size","of","the","second","dimension","of","the","input","tensors",".","(","see","`","input_ids","`","above",")","Return",":","Example",":",":",">",">",">","import","torch",">",">",">","from","transformers","import","GPT2Tokenizer",",","GPT2DoubleHeadsModel",">",">",">","tokenizer","=","GPT2Tokenizer.from_pretrained","(","'gpt2","'",")",">",">",">","model","=","GPT2DoubleHeadsModel.from_pretrained","(","'gpt2","'",")",">",">",">","#","Add","a","[","CLS","]","to","the","vocabulary","(","we","should","train","it","also","!",")",">",">",">","num_added_tokens","=","tokenizer.add_special_tokens","(","{","'cls_token","'",":","'","[","CLS","]","'","}",")",">",">",">","embedding_layer","=","model.resize_token_embeddings","(","len","(","tokenizer",")",")","#","Update","the","model","embeddings","with","the","new","vocabulary","size",">",">",">","choices","=","[","``","Hello",",","my","dog","is","cute","[","CLS","]","''",",","``","Hello",",","my","cat","is","cute","[","CLS","]","''","]",">",">",">","encoded_choices","=","[","tokenizer.encode","(","s",")","for","s","in","choices","]",">",">",">","cls_token_location","=","[","tokens.index","(","tokenizer.cls_token_id",")","for","tokens","in","encoded_choices","]",">",">",">","input_ids","=","torch.tensor","(","encoded_choices",")",".unsqueeze","(","0",")","#","Batch","size",":","1",",","number","of","choices",":","2",">",">",">","mc_token_ids","=","torch.tensor","(","[","cls_token_location","]",")","#","Batch","size",":","1",">",">",">","outputs","=","model","(","input_ids",",","mc_token_ids=mc_token_ids",")",">",">",">","lm_logits","=","outputs.logits",">",">",">","mc_logits","=","outputs.mc_logits"]
code: def forward(
      self,
      input_ids=None,
      past_key_values=None,
      attention_mask=None,
      token_type_ids=None,
      position_ids=None,
      head_mask=None,
      inputs_embeds=None,
      mc_token_ids=None,
      labels=None,
      mc_labels=None,
      use_cache=None,
      output_attentions=None,
      output_hidden_states=None,
      return_dict=None,
      **kwargs,
  ):
      r"""
      mc_token_ids (:obj:`torch.LongTensor` of shape :obj:`(batch_size, num_choices)`, `optional`, default to index of the last token of the input):
          Index of the classification token in each input sequence. Selected in the range ``[0, input_ids.size(-1) -
          1[``.
      labels (:obj:`torch.LongTensor` of shape :obj:`(batch_size, sequence_length)`, `optional`):
          Labels for language modeling. Note that the labels **are shifted** inside the model, i.e. you can set
          ``labels = input_ids`` Indices are selected in ``[-100, 0, ..., config.vocab_size - 1]`` All labels set to
          ``-100`` are ignored (masked), the loss is only computed for labels in ``[0, ..., config.vocab_size - 1]``
      mc_labels (:obj:`torch.LongTensor` of shape :obj:`(batch_size)`, `optional`):
          Labels for computing the multiple choice classification loss. Indices should be in ``[0, ...,
          num_choices]`` where `num_choices` is the size of the second dimension of the input tensors. (see
          `input_ids` above)
  
      Return:
  
      Example::
  
          >>> import torch
          >>> from transformers import GPT2Tokenizer, GPT2DoubleHeadsModel
  
          >>> tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
          >>> model = GPT2DoubleHeadsModel.from_pretrained('gpt2')
  
          >>> # Add a [CLS] to the vocabulary (we should train it also!)
          >>> num_added_tokens = tokenizer.add_special_tokens({'cls_token': '[CLS]'})
  
          >>> embedding_layer = model.resize_token_embeddings(len(tokenizer))  # Update the model embeddings with the new vocabulary size
  
          >>> choices = ["Hello, my dog is cute [CLS]", "Hello, my cat is cute [CLS]"]
          >>> encoded_choices = [tokenizer.encode(s) for s in choices]
          >>> cls_token_location = [tokens.index(tokenizer.cls_token_id) for tokens in encoded_choices]
  
          >>> input_ids = torch.tensor(encoded_choices).unsqueeze(0)  # Batch size: 1, number of choices: 2
          >>> mc_token_ids = torch.tensor([cls_token_location])  # Batch size: 1
  
          >>> outputs = model(input_ids, mc_token_ids=mc_token_ids)
          >>> lm_logits = outputs.logits
          >>> mc_logits = outputs.mc_logits
  
      """
      return_dict = (
          return_dict
          if return_dict is not None
          else self.config.use_return_dict
      )
  
      transformer_outputs = self.transformer(
          input_ids,
          past_key_values=past_key_values,
          attention_mask=attention_mask,
          token_type_ids=token_type_ids,
          position_ids=position_ids,
          head_mask=head_mask,
          inputs_embeds=inputs_embeds,
          use_cache=use_cache,
          output_attentions=output_attentions,
          output_hidden_states=output_hidden_states,
          return_dict=return_dict,
      )
  
      hidden_states = transformer_outputs[0]
  
      # Set device for model parallelism
      if self.model_parallel:
          torch.cuda.set_device(self.transformer.first_device)
          hidden_states = hidden_states.to(self.lm_head.weight.device)
  
      lm_logits = self.lm_head(hidden_states)
      mc_logits = self.multiple_choice_head(
          hidden_states, mc_token_ids
      ).squeeze(-1)
  
      mc_loss = None
      if mc_labels is not None:
          loss_fct = CrossEntropyLoss()
          mc_loss = loss_fct(
              mc_logits.view(-1, mc_logits.size(-1)), mc_labels.view(-1)
          )
      lm_loss = None
      if labels is not None:
          shift_logits = lm_logits[..., :-1, :].contiguous()
          shift_labels = labels[..., 1:].contiguous()
          loss_fct = CrossEntropyLoss()
          lm_loss = loss_fct(
              shift_logits.view(-1, shift_logits.size(-1)),
              shift_labels.view(-1),
          )
  
      if not return_dict:
          output = (lm_logits, mc_logits) + transformer_outputs[1:]
          if mc_loss is not None:
              output = (mc_loss,) + output
          return (
              ((lm_loss,) + output) if lm_loss is not None else output
          )
  
      return GPT2DoubleHeadsModelOutput(
          loss=lm_loss,
          mc_loss=mc_loss,
          logits=lm_logits,
          mc_logits=mc_logits,
          past_key_values=transformer_outputs.past_key_values,
          hidden_states=transformer_outputs.hidden_states,
          attentions=transformer_outputs.attentions,
      )
  
imports: from dataclasses import dataclass
  from typing import Optional, Tuple
  from .configuration_gpt2 import GPT2Config
  from fastNLP.transformers.torch.activations import ACT2FN
  from fastNLP.transformers.torch.file_utils import ModelOutput, add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, replace_return_docstrings
  from fastNLP.transformers.torch.modeling_outputs import BaseModelOutputWithPastAndCrossAttentions, CausalLMOutputWithCrossAttentions, SequenceClassifierOutputWithPast, TokenClassifierOutput
  from fastNLP.transformers.torch.modeling_utils import Conv1D, PreTrainedModel, SequenceSummary, find_pruneable_heads_and_indices, prune_conv1d_layer
  from fastNLP.transformers.torch.utils.model_parallel_utils import assert_device_map, get_device_map
  from fastNLP.envs.imports import _NEED_IMPORT_TORCH
  from fastNLP.core.log import logger
label_desc: Use image node_id 7 for calling the GPT2DoubleHeadsModel obj's underlying member method code with example usage: obj.forward(input_ids, past_key_values, attention_mask, token_type_ids, position_ids, head_mask, inputs_embeds, mc_token_ids, labels, mc_labels, use_cache, output_attentions, output_hidden_states, return_dict) and returns: GPT2DoubleHeadsModelOutput, unknown