docstr: labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
          Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
          config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
          (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
  
  Returns:
  
  Examples:
  
  ```python
  >>> from transformers import FuyuProcessor, FuyuForCausalLM
  >>> from PIL import Image
  >>> import requests
  
  >>> processor = FuyuProcessor.from_pretrained("adept/fuyu-8b")
  >>> model = FuyuForCausalLM.from_pretrained("adept/fuyu-8b")
  
  >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
  >>> image = Image.open(requests.get(url, stream=True).raw)
  >>> prompt = "Generate a coco-style caption.\n"
  
  >>> inputs = processor(text=text_prompt, images=image, return_tensors="pt")
  >>> outputs = model(**inputs)
  
  >>> generated_ids = model.generate(**model_inputs, max_new_tokens=7)
  >>> generation_text = processor.batch_decode(generated_ids, skip_special_tokens=True)
  >>> print(generation_text)
  'A bus parked on the side of a road.'
  ```
docstr_tok: ["labels","(","`","torch.LongTensor","`","of","shape","`","(","batch_size",",","sequence_length",")","`",",","*","optional","*",")",":","Labels","for","computing","the","masked","language","modeling","loss",".","Indices","should","either","be","in","`","[","0",",","...",",","config.vocab_size","]","`","or","-100","(","see","`","input_ids","`","docstring",")",".","Tokens","with","indices","set","to","`","-100","`","are","ignored","(","masked",")",",","the","loss","is","only","computed","for","the","tokens","with","labels","in","`","[","0",",","...",",","config.vocab_size","]","`",".","Returns",":","Examples",":","``","`","python",">",">",">","from","transformers","import","FuyuProcessor",",","FuyuForCausalLM",">",">",">","from","PIL","import","Image",">",">",">","import","requests",">",">",">","processor","=","FuyuProcessor.from_pretrained","(","``","adept\/fuyu-8b","''",")",">",">",">","model","=","FuyuForCausalLM.from_pretrained","(","``","adept\/fuyu-8b","''",")",">",">",">","url","=","``","http",":","\/\/images.cocodataset.org\/val2017\/000000039769.jpg","''",">",">",">","image","=","Image.open","(","requests.get","(","url",",","stream=True",")",".raw",")",">",">",">","prompt","=","``","Generate","a","coco-style","caption.\\n","''",">",">",">","inputs","=","processor","(","text=text_prompt",",","images=image",",","return_tensors=","''","pt","''",")",">",">",">","outputs","=","model","(","*","*","inputs",")",">",">",">","generated_ids","=","model.generate","(","*","*","model_inputs",",","max_new_tokens=7",")",">",">",">","generation_text","=","processor.batch_decode","(","generated_ids",",","skip_special_tokens=True",")",">",">",">","print","(","generation_text",")","'","A","bus","parked","on","the","side","of","a","road",".","'","``","`"]
code: def forward(
      self,
      input_ids: torch.LongTensor = None,
      image_patches: torch.Tensor = None,  # [batch_size, num_total_patches, patch_size_ x patch_size x num_channels ]
      image_patches_indices: torch.Tensor = None,
      attention_mask: Optional[torch.Tensor] = None,
      position_ids: Optional[torch.LongTensor] = None,
      past_key_values: Optional[List[torch.FloatTensor]] = None,
      inputs_embeds: Optional[torch.FloatTensor] = None,
      use_cache: Optional[bool] = None,
      labels: Optional[torch.Tensor] = None,
      output_attentions: Optional[bool] = None,
      output_hidden_states: Optional[bool] = None,
      return_dict: Optional[bool] = None,
  ) -> Union[Tuple, CausalLMOutputWithPast]:
      r"""
      labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
              Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
              config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
              (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
  
      Returns:
  
      Examples:
  
      ```python
      >>> from transformers import FuyuProcessor, FuyuForCausalLM
      >>> from PIL import Image
      >>> import requests
  
      >>> processor = FuyuProcessor.from_pretrained("adept/fuyu-8b")
      >>> model = FuyuForCausalLM.from_pretrained("adept/fuyu-8b")
  
      >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
      >>> image = Image.open(requests.get(url, stream=True).raw)
      >>> prompt = "Generate a coco-style caption.\n"
  
      >>> inputs = processor(text=text_prompt, images=image, return_tensors="pt")
      >>> outputs = model(**inputs)
  
      >>> generated_ids = model.generate(**model_inputs, max_new_tokens=7)
      >>> generation_text = processor.batch_decode(generated_ids, skip_special_tokens=True)
      >>> print(generation_text)
      'A bus parked on the side of a road.'
      ```"""
  
      output_attentions = (
          output_attentions
          if output_attentions is not None
          else self.config.output_attentions
      )
      output_hidden_states = (
          output_hidden_states
          if output_hidden_states is not None
          else self.config.output_hidden_states
      )
      use_cache = (
          use_cache if use_cache is not None else self.config.use_cache
      )
  
      return_dict = (
          return_dict
          if return_dict is not None
          else self.config.use_return_dict
      )
  
      if input_ids is not None and inputs_embeds is not None:
          raise ValueError(
              "You cannot specify both input_ids and inputs_embeds at the same time"
          )
      elif input_ids is not None:
          batch_size, seq_length = input_ids.shape
      elif inputs_embeds is not None:
          batch_size, seq_length, _ = inputs_embeds.shape
      else:
          raise ValueError(
              "You have to specify either input_is or inputs_embeds"
          )
  
      seq_length_with_past = seq_length
      past_key_values_length = 0
  
      if past_key_values is not None:
          past_key_values_length = past_key_values[0][0].shape[2]
          seq_length_with_past = (
              seq_length_with_past + past_key_values_length
          )
  
      if position_ids is None:
          device = (
              input_ids.device
              if input_ids is not None
              else inputs_embeds.device
          )
          position_ids = torch.arange(
              past_key_values_length,
              seq_length + past_key_values_length,
              dtype=torch.long,
              device=device,
          )
          position_ids = position_ids.unsqueeze(0)
  
      if inputs_embeds is None:
          inputs_embeds = self.language_model.get_input_embeddings()(
              input_ids
          )
          if image_patches is not None and past_key_values is None:
              patch_embeddings = [
                  self.vision_embed_tokens(
                      patch.to(self.vision_embed_tokens.weight.dtype)
                  ).squeeze(0)
                  for patch in image_patches
              ]
              inputs_embeds = self.gather_continuous_embeddings(
                  word_embeddings=inputs_embeds,
                  continuous_embeddings=patch_embeddings,
                  image_patch_input_indices=image_patches_indices,
              )
  
      outputs = self.language_model(
          inputs_embeds=inputs_embeds,
          attention_mask=attention_mask,
          position_ids=position_ids,
          past_key_values=past_key_values,
          output_attentions=output_attentions,
          output_hidden_states=output_hidden_states,
          labels=labels,
          use_cache=use_cache,
          return_dict=return_dict,
      )
  
      return outputs
  
file_path: transformers/src/transformers/models/fuyu/modeling_fuyu.py
imports: from typing import List, Optional, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from torch import nn
  from ...modeling_outputs import CausalLMOutputWithPast
  from ...modeling_utils import PreTrainedModel
  from ...models.auto.modeling_auto import AutoModelForCausalLM
  from ...utils import add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from .configuration_fuyu import FuyuConfig
label_desc: Use image node_id 5 for calling the FuyuForCausalLM obj's underlying member method code with example usage: obj.forward(input_ids, image_patches, image_patches_indices, attention_mask, position_ids, past_key_values, inputs_embeds, use_cache, labels, output_attentions, output_hidden_states, return_dict) and returns: outputs