class_docstr: [`FlaxVisionEncoderDecoderModel`] is a generic model class that will be instantiated as a transformer architecture
  with the module (flax.nn.Module) of one of the base vision model classes of the library as encoder module and
  another one as decoder module when created with the :meth*~transformers.FlaxAutoModel.from_pretrained* class method
  for the encoder and :meth*~transformers.FlaxAutoModelForCausalLM.from_pretrained* class method for the decoder.
class_docstr_tok: ["[","`","FlaxVisionEncoderDecoderModel","`","]","is","a","generic","model","class","that","will","be","instantiated","as","a","transformer","architecture","with","the","module","(","flax.nn.Module",")","of","one","of","the","base","vision","model","classes","of","the","library","as","encoder","module","and","another","one","as","decoder","module","when","created","with","the",":","meth","*","~transformers.FlaxAutoModel.from_pretrained","*","class","method","for","the","encoder","and",":","meth","*","~transformers.FlaxAutoModelForCausalLM.from_pretrained","*","class","method","for","the","decoder","."]
docstr: Returns:
  
  Example:
  
  ```python
  >>> from transformers import ViTFeatureExtractor, FlaxVisionEncoderDecoderModel
  >>> from PIL import Image
  >>> import requests
  
  >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
  >>> image = Image.open(requests.get(url, stream=True).raw)
  
  >>> feature_extractor = ViTFeatureExtractor.from_pretrained("google/vit-base-patch16-224-in21k")
  
  >>> # initialize a vit-gpt2 from pretrained ViT and GPT2 models. Note that the cross-attention layers will be randomly initialized
  >>> model = FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
  ...     "google/vit-base-patch16-224-in21k", "gpt2"
  ... )
  
  >>> pixel_values = feature_extractor(images=image, return_tensors="np").pixel_values
  >>> encoder_outputs = model.encode(pixel_values)
  ```
docstr_tok: ["Returns",":","Example",":","``","`","python",">",">",">","from","transformers","import","ViTFeatureExtractor",",","FlaxVisionEncoderDecoderModel",">",">",">","from","PIL","import","Image",">",">",">","import","requests",">",">",">","url","=","``","http",":","\/\/images.cocodataset.org\/val2017\/000000039769.jpg","''",">",">",">","image","=","Image.open","(","requests.get","(","url",",","stream=True",")",".raw",")",">",">",">","feature_extractor","=","ViTFeatureExtractor.from_pretrained","(","``","google\/vit-base-patch16-224-in21k","''",")",">",">",">","#","initialize","a","vit-gpt2","from","pretrained","ViT","and","GPT2","models",".","Note","that","the","cross-attention","layers","will","be","randomly","initialized",">",">",">","model","=","FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained","(","...","``","google\/vit-base-patch16-224-in21k","''",",","``","gpt2","''","...",")",">",">",">","pixel_values","=","feature_extractor","(","images=image",",","return_tensors=","''","np","''",")",".pixel_values",">",">",">","encoder_outputs","=","model.encode","(","pixel_values",")","``","`"]
code: def encode(
      self,
      pixel_values: jnp.ndarray,
      output_attentions: Optional[bool] = None,
      output_hidden_states: Optional[bool] = None,
      return_dict: Optional[bool] = None,
      train: bool = False,
      params: dict = None,
      dropout_rng: PRNGKey = None,
  ):
      r"""
      Returns:
  
      Example:
  
      ```python
      >>> from transformers import ViTFeatureExtractor, FlaxVisionEncoderDecoderModel
      >>> from PIL import Image
      >>> import requests
  
      >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
      >>> image = Image.open(requests.get(url, stream=True).raw)
  
      >>> feature_extractor = ViTFeatureExtractor.from_pretrained("google/vit-base-patch16-224-in21k")
  
      >>> # initialize a vit-gpt2 from pretrained ViT and GPT2 models. Note that the cross-attention layers will be randomly initialized
      >>> model = FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
      ...     "google/vit-base-patch16-224-in21k", "gpt2"
      ... )
  
      >>> pixel_values = feature_extractor(images=image, return_tensors="np").pixel_values
      >>> encoder_outputs = model.encode(pixel_values)
      ```"""
      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
      )
      return_dict = (
          return_dict
          if return_dict is not None
          else self.config.return_dict
      )
  
      # `FlaxViTModel` expects channel first format, but `FlaxViTModule` expects channel last format.
      # Currently, we assume this holds for all Flax vision models, and perform a transpose here.
      pixel_values = jnp.transpose(pixel_values, (0, 2, 3, 1))
  
      # Handle any PRNG if needed
      rngs = {}
      if dropout_rng is not None:
          rngs["dropout"] = dropout_rng
  
      def _encoder_forward(module, pixel_values, **kwargs):
          encode_module = module._get_encoder_module()
          return encode_module(pixel_values, **kwargs)
  
      outputs = self.module.apply(
          {"params": params or self.params},
          pixel_values=jnp.array(pixel_values, dtype=self.dtype),
          output_attentions=output_attentions,
          output_hidden_states=output_hidden_states,
          return_dict=return_dict,
          deterministic=not train,
          rngs=rngs,
          method=_encoder_forward,
      )
  
      if return_dict:
          outputs = FlaxBaseModelOutput(
              last_hidden_state=outputs.last_hidden_state,
              hidden_states=outputs.hidden_states,
              attentions=outputs.attentions,
          )
  
      return outputs
  
imports: import os
  from typing import Optional, Tuple, Union
  import flax.linen
  import jax
  import jax.numpy
  from flax.core.frozen_dict import FrozenDict, freeze, unfreeze
  from flax.traverse_util import flatten_dict, unflatten_dict
  from jax import lax
  from jax.random import PRNGKey
  from ...modeling_flax_outputs import FlaxBaseModelOutput, FlaxCausalLMOutputWithCrossAttentions, FlaxSeq2SeqLMOutput
  from ...modeling_flax_utils import FlaxPreTrainedModel
  from ...utils import add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from ..auto.configuration_auto import AutoConfig
  from ..auto.modeling_flax_auto import FlaxAutoModel, FlaxAutoModelForCausalLM
  from .configuration_vision_encoder_decoder import VisionEncoderDecoderConfig
label_desc: Use image node_id 4 for calling the FlaxVisionEncoderDecoderModel obj's underlying member method code with example usage: obj.encode(pixel_values, output_attentions, output_hidden_states, return_dict, train, params, dropout_rng) and returns: outputs, encode_module