docstr: start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
      Labels for position (index) of the start of the labelled span for computing the token classification loss.
      Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
      are not taken into account for computing the loss.
  end_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
      Labels for position (index) of the end of the labelled span for computing the token classification loss.
      Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
      are not taken into account for computing the loss.
  
  Returns:
  
  Example:
  
  ```python
  >>> from transformers import GPT2Tokenizer, OPTForQuestionAnswering
  >>> import torch
  
  >>> torch.manual_seed(4)  # doctest: +IGNORE_RESULT
  >>> tokenizer = GPT2Tokenizer.from_pretrained("facebook/opt-350m")
  
  >>> # note: we are loading a OPTForQuestionAnswering from the hub here,
  >>> # so the head will be randomly initialized, hence the predictions will be random
  >>> model = OPTForQuestionAnswering.from_pretrained("facebook/opt-350m")
  
  >>> question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet"
  
  >>> inputs = tokenizer(question, text, return_tensors="pt")
  >>> with torch.no_grad():
  ...     outputs = model(**inputs)
  
  >>> answer_start_index = outputs.start_logits.argmax()
  >>> answer_end_index = outputs.end_logits.argmax()
  
  >>> predict_answer_tokens = inputs.input_ids[0, answer_start_index : answer_end_index + 1]
  >>> predicted = tokenizer.decode(predict_answer_tokens)
  >>> predicted
  ' Henson?'
  ```
docstr_tok: ["start_positions","(","`","torch.LongTensor","`","of","shape","`","(","batch_size",",",")","`",",","*","optional","*",")",":","Labels","for","position","(","index",")","of","the","start","of","the","labelled","span","for","computing","the","token","classification","loss",".","Positions","are","clamped","to","the","length","of","the","sequence","(","`","sequence_length","`",")",".","Position","outside","of","the","sequence","are","not","taken","into","account","for","computing","the","loss",".","end_positions","(","`","torch.LongTensor","`","of","shape","`","(","batch_size",",",")","`",",","*","optional","*",")",":","Labels","for","position","(","index",")","of","the","end","of","the","labelled","span","for","computing","the","token","classification","loss",".","Positions","are","clamped","to","the","length","of","the","sequence","(","`","sequence_length","`",")",".","Position","outside","of","the","sequence","are","not","taken","into","account","for","computing","the","loss",".","Returns",":","Example",":","``","`","python",">",">",">","from","transformers","import","GPT2Tokenizer",",","OPTForQuestionAnswering",">",">",">","import","torch",">",">",">","torch.manual_seed","(","4",")","#","doctest",":","+IGNORE_RESULT",">",">",">","tokenizer","=","GPT2Tokenizer.from_pretrained","(","``","facebook\/opt-350m","''",")",">",">",">","#","note",":","we","are","loading","a","OPTForQuestionAnswering","from","the","hub","here",",",">",">",">","#","so","the","head","will","be","randomly","initialized",",","hence","the","predictions","will","be","random",">",">",">","model","=","OPTForQuestionAnswering.from_pretrained","(","``","facebook\/opt-350m","''",")",">",">",">","question",",","text","=","``","Who","was","Jim","Henson","?","``",",","``","Jim","Henson","was","a","nice","puppet","''",">",">",">","inputs","=","tokenizer","(","question",",","text",",","return_tensors=","''","pt","''",")",">",">",">","with","torch.no_grad","(",")",":","...","outputs","=","model","(","*","*","inputs",")",">",">",">","answer_start_index","=","outputs.start_logits.argmax","(",")",">",">",">","answer_end_index","=","outputs.end_logits.argmax","(",")",">",">",">","predict_answer_tokens","=","inputs.input_ids","[","0",",","answer_start_index",":","answer_end_index","+","1","]",">",">",">","predicted","=","tokenizer.decode","(","predict_answer_tokens",")",">",">",">","predicted","'","Henson","?","'","``","`"]
code: def forward(
      self,
      input_ids: Optional[torch.LongTensor] = None,
      attention_mask: Optional[torch.FloatTensor] = None,
      head_mask: Optional[torch.FloatTensor] = None,
      past_key_values: Optional[Tuple[Tuple[torch.Tensor]]] = None,
      inputs_embeds: Optional[torch.FloatTensor] = None,
      start_positions: Optional[torch.LongTensor] = None,
      end_positions: Optional[torch.LongTensor] = None,
      use_cache: Optional[bool] = None,
      output_attentions: Optional[bool] = None,
      output_hidden_states: Optional[bool] = None,
      return_dict: Optional[bool] = None,
  ) -> Union[Tuple, QuestionAnsweringModelOutput]:
      r"""
      start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
          Labels for position (index) of the start of the labelled span for computing the token classification loss.
          Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
          are not taken into account for computing the loss.
      end_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
          Labels for position (index) of the end of the labelled span for computing the token classification loss.
          Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
          are not taken into account for computing the loss.
  
      Returns:
  
      Example:
  
      ```python
      >>> from transformers import GPT2Tokenizer, OPTForQuestionAnswering
      >>> import torch
  
      >>> torch.manual_seed(4)  # doctest: +IGNORE_RESULT
      >>> tokenizer = GPT2Tokenizer.from_pretrained("facebook/opt-350m")
  
      >>> # note: we are loading a OPTForQuestionAnswering from the hub here,
      >>> # so the head will be randomly initialized, hence the predictions will be random
      >>> model = OPTForQuestionAnswering.from_pretrained("facebook/opt-350m")
  
      >>> question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet"
  
      >>> inputs = tokenizer(question, text, return_tensors="pt")
      >>> with torch.no_grad():
      ...     outputs = model(**inputs)
  
      >>> answer_start_index = outputs.start_logits.argmax()
      >>> answer_end_index = outputs.end_logits.argmax()
  
      >>> predict_answer_tokens = inputs.input_ids[0, answer_start_index : answer_end_index + 1]
      >>> predicted = tokenizer.decode(predict_answer_tokens)
      >>> predicted
      ' Henson?'
      ```"""
      return_dict = (
          return_dict
          if return_dict is not None
          else self.config.use_return_dict
      )
  
      transformer_outputs = self.model(
          input_ids,
          past_key_values=past_key_values,
          attention_mask=attention_mask,
          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]
  
      logits = self.qa_outputs(hidden_states)
      start_logits, end_logits = logits.split(1, dim=-1)
      start_logits = start_logits.squeeze(-1).contiguous()
      end_logits = end_logits.squeeze(-1).contiguous()
  
      total_loss = None
      if start_positions is not None and end_positions is not None:
          # If we are on multi-GPU, split add a dimension
          if len(start_positions.size()) > 1:
              start_positions = start_positions.squeeze(-1)
          if len(end_positions.size()) > 1:
              end_positions = end_positions.squeeze(-1)
          # sometimes the start/end positions are outside our model inputs, we ignore these terms
          ignored_index = start_logits.size(1)
          start_positions = start_positions.clamp(0, ignored_index)
          end_positions = end_positions.clamp(0, ignored_index)
  
          loss_fct = CrossEntropyLoss(ignore_index=ignored_index)
          start_loss = loss_fct(start_logits, start_positions)
          end_loss = loss_fct(end_logits, end_positions)
          total_loss = (start_loss + end_loss) / 2
  
      if not return_dict:
          output = (start_logits, end_logits) + transformer_outputs[2:]
          return (
              ((total_loss,) + output)
              if total_loss is not None
              else output
          )
  
      return QuestionAnsweringModelOutput(
          loss=total_loss,
          start_logits=start_logits,
          end_logits=end_logits,
          hidden_states=transformer_outputs.hidden_states,
          attentions=transformer_outputs.attentions,
      )
  
imports: import random
  from typing import List, Optional, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from torch import nn
  from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
  from ...activations import ACT2FN
  from ...modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast, QuestionAnsweringModelOutput, SequenceClassifierOutputWithPast
  from ...modeling_utils import PreTrainedModel
  from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from .configuration_opt import OPTConfig
label_desc: Use image node_id 2 for calling the OPTForQuestionAnswering obj's underlying member method code with example usage: obj.forward(input_ids, attention_mask, head_mask, past_key_values, inputs_embeds, start_positions, end_positions, use_cache, output_attentions, output_hidden_states, return_dict) and returns: QuestionAnsweringModelOutput, unknown