import{S as Hm,i as Um,s as Zm,e as a,k as c,w as b,t,M as Ym,c as s,d as n,m as p,a as i,x as w,h as r,b as l,G as e,g,y as T,q as y,o as E,B as k,v as Jm,L as hn}from"../../chunks/vendor-hf-doc-builder.js";import{T as Oc}from"../../chunks/Tip-hf-doc-builder.js";import{D as H}from"../../chunks/Docstring-hf-doc-builder.js";import{C as U}from"../../chunks/CodeBlock-hf-doc-builder.js";import{I as Y}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{E as mn}from"../../chunks/ExampleCodeBlock-hf-doc-builder.js";function Km(P){let h,$,_,f,v;return f=new U({props:{code:`from transformers import BertConfig, ViTConfig, VisionEncoderDecoderConfig, VisionEncoderDecoderModel

# Initializing a ViT & BERT style configuration
config_encoder = ViTConfig()
config_decoder = BertConfig()

config = VisionEncoderDecoderConfig.from_encoder_decoder_configs(config_encoder, config_decoder)

# Initializing a ViTBert model (with random weights) from a ViT & bert-base-uncased style configurations
model = VisionEncoderDecoderModel(config=config)

# Accessing the model configuration
config_encoder = model.config.encoder
config_decoder = model.config.decoder
# set decoder config to causal lm
config_decoder.is_decoder = True
config_decoder.add_cross_attention = True

# Saving the model, including its configuration
model.save_pretrained("my-model")

# loading model and config from pretrained folder
encoder_decoder_config = VisionEncoderDecoderConfig.from_pretrained("my-model")
model = VisionEncoderDecoderModel.from_pretrained("my-model", config=encoder_decoder_config)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BertConfig, ViTConfig, VisionEncoderDecoderConfig, VisionEncoderDecoderModel

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a ViT &amp; BERT style configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>config_encoder = ViTConfig()
<span class="hljs-meta">&gt;&gt;&gt; </span>config_decoder = BertConfig()

<span class="hljs-meta">&gt;&gt;&gt; </span>config = VisionEncoderDecoderConfig.from_encoder_decoder_configs(config_encoder, config_decoder)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a ViTBert model (with random weights) from a ViT &amp; bert-base-uncased style configurations</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = VisionEncoderDecoderModel(config=config)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Accessing the model configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>config_encoder = model.config.encoder
<span class="hljs-meta">&gt;&gt;&gt; </span>config_decoder = model.config.decoder
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># set decoder config to causal lm</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>config_decoder.is_decoder = <span class="hljs-literal">True</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>config_decoder.add_cross_attention = <span class="hljs-literal">True</span>

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Saving the model, including its configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model.save_pretrained(<span class="hljs-string">&quot;my-model&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># loading model and config from pretrained folder</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>encoder_decoder_config = VisionEncoderDecoderConfig.from_pretrained(<span class="hljs-string">&quot;my-model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = VisionEncoderDecoderModel.from_pretrained(<span class="hljs-string">&quot;my-model&quot;</span>, config=encoder_decoder_config)`}}),{c(){h=a("p"),$=t("Examples:"),_=c(),b(f.$$.fragment)},l(d){h=s(d,"P",{});var u=i(h);$=r(u,"Examples:"),u.forEach(n),_=p(d),w(f.$$.fragment,d)},m(d,u){g(d,h,u),e(h,$),g(d,_,u),T(f,d,u),v=!0},p:hn,i(d){v||(y(f.$$.fragment,d),v=!0)},o(d){E(f.$$.fragment,d),v=!1},d(d){d&&n(h),d&&n(_),k(f,d)}}}function Qm(P){let h,$,_,f,v;return{c(){h=a("p"),$=t("Although the recipe for forward pass needs to be defined within this function, one should call the "),_=a("code"),f=t("Module"),v=t(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(d){h=s(d,"P",{});var u=i(h);$=r(u,"Although the recipe for forward pass needs to be defined within this function, one should call the "),_=s(u,"CODE",{});var S=i(_);f=r(S,"Module"),S.forEach(n),v=r(u,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),u.forEach(n)},m(d,u){g(d,h,u),e(h,$),e(h,_),e(_,f),e(h,v)},d(d){d&&n(h)}}}function Xm(P){let h,$,_,f,v;return f=new U({props:{code:`from transformers import AutoProcessor, VisionEncoderDecoderModel
import requests
from PIL import Image
import torch

processor = AutoProcessor.from_pretrained("microsoft/trocr-base-handwritten")
model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten")

# load image from the IAM dataset
url = "https://fki.tic.heia-fr.ch/static/img/a01-122-02.jpg"
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")

# training
model.config.decoder_start_token_id = processor.tokenizer.cls_token_id
model.config.pad_token_id = processor.tokenizer.pad_token_id
model.config.vocab_size = model.config.decoder.vocab_size

pixel_values = processor(image, return_tensors="pt").pixel_values
text = "hello world"
labels = processor.tokenizer(text, return_tensors="pt").input_ids
outputs = model(pixel_values=pixel_values, labels=labels)
loss = outputs.loss

# inference (generation)
generated_ids = model.generate(pixel_values)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoProcessor, VisionEncoderDecoderModel
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>processor = AutoProcessor.from_pretrained(<span class="hljs-string">&quot;microsoft/trocr-base-handwritten&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = VisionEncoderDecoderModel.from_pretrained(<span class="hljs-string">&quot;microsoft/trocr-base-handwritten&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># load image from the IAM dataset</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">&quot;https://fki.tic.heia-fr.ch/static/img/a01-122-02.jpg&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw).convert(<span class="hljs-string">&quot;RGB&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># training</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model.config.decoder_start_token_id = processor.tokenizer.cls_token_id
<span class="hljs-meta">&gt;&gt;&gt; </span>model.config.pad_token_id = processor.tokenizer.pad_token_id
<span class="hljs-meta">&gt;&gt;&gt; </span>model.config.vocab_size = model.config.decoder.vocab_size

<span class="hljs-meta">&gt;&gt;&gt; </span>pixel_values = processor(image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).pixel_values
<span class="hljs-meta">&gt;&gt;&gt; </span>text = <span class="hljs-string">&quot;hello world&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>labels = processor.tokenizer(text, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).input_ids
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(pixel_values=pixel_values, labels=labels)
<span class="hljs-meta">&gt;&gt;&gt; </span>loss = outputs.loss

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># inference (generation)</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>generated_ids = model.generate(pixel_values)
<span class="hljs-meta">&gt;&gt;&gt; </span>generated_text = processor.batch_decode(generated_ids, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]`}}),{c(){h=a("p"),$=t("Examples:"),_=c(),b(f.$$.fragment)},l(d){h=s(d,"P",{});var u=i(h);$=r(u,"Examples:"),u.forEach(n),_=p(d),w(f.$$.fragment,d)},m(d,u){g(d,h,u),e(h,$),g(d,_,u),T(f,d,u),v=!0},p:hn,i(d){v||(y(f.$$.fragment,d),v=!0)},o(d){E(f.$$.fragment,d),v=!1},d(d){d&&n(h),d&&n(_),k(f,d)}}}function eh(P){let h,$,_,f,v;return f=new U({props:{code:`from transformers import VisionEncoderDecoderModel

# initialize a vit-bert from a pretrained ViT and a pretrained BERT model. Note that the cross-attention layers will be randomly initialized
model = VisionEncoderDecoderModel.from_encoder_decoder_pretrained(
    "google/vit-base-patch16-224-in21k", "bert-base-uncased"
)
# saving model after fine-tuning
model.save_pretrained("./vit-bert")
# load fine-tuned model
model = VisionEncoderDecoderModel.from_pretrained("./vit-bert")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> VisionEncoderDecoderModel

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># initialize a vit-bert from a pretrained ViT and a pretrained BERT model. Note that the cross-attention layers will be randomly initialized</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = VisionEncoderDecoderModel.from_encoder_decoder_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;google/vit-base-patch16-224-in21k&quot;</span>, <span class="hljs-string">&quot;bert-base-uncased&quot;</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># saving model after fine-tuning</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model.save_pretrained(<span class="hljs-string">&quot;./vit-bert&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># load fine-tuned model</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = VisionEncoderDecoderModel.from_pretrained(<span class="hljs-string">&quot;./vit-bert&quot;</span>)`}}),{c(){h=a("p"),$=t("Example:"),_=c(),b(f.$$.fragment)},l(d){h=s(d,"P",{});var u=i(h);$=r(u,"Example:"),u.forEach(n),_=p(d),w(f.$$.fragment,d)},m(d,u){g(d,h,u),e(h,$),g(d,_,u),T(f,d,u),v=!0},p:hn,i(d){v||(y(f.$$.fragment,d),v=!0)},o(d){E(f.$$.fragment,d),v=!1},d(d){d&&n(h),d&&n(_),k(f,d)}}}function oh(P){let h,$,_,f,v;return{c(){h=a("p"),$=t("Although the recipe for forward pass needs to be defined within this function, one should call the "),_=a("code"),f=t("Module"),v=t(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(d){h=s(d,"P",{});var u=i(h);$=r(u,"Although the recipe for forward pass needs to be defined within this function, one should call the "),_=s(u,"CODE",{});var S=i(_);f=r(S,"Module"),S.forEach(n),v=r(u,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),u.forEach(n)},m(d,u){g(d,h,u),e(h,$),e(h,_),e(_,f),e(h,v)},d(d){d&&n(h)}}}function nh(P){let h,$,_,f,v;return f=new U({props:{code:`from transformers import AutoImageProcessor, AutoTokenizer, TFVisionEncoderDecoderModel
from PIL import Image
import requests

image_processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224-in21k")
decoder_tokenizer = AutoTokenizer.from_pretrained("gpt2")

# initialize a bert2gpt2 from a pretrained BERT and GPT2 models. Note that the cross-attention layers will be randomly initialized
model = TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
    "google/vit-base-patch16-224-in21k", "gpt2"
)

url = "http://images.cocodataset.org/val2017/000000039769.jpg"
img = Image.open(requests.get(url, stream=True).raw)

# forward
pixel_values = image_processor(images=img, return_tensors="tf").pixel_values  # Batch size 1
decoder_input_ids = decoder_tokenizer("Linda Davis", return_tensors="tf").input_ids  # Batch size 1
outputs = model(pixel_values=pixel_values, decoder_input_ids=decoder_input_ids)

# training
outputs = model(pixel_values=pixel_values, decoder_input_ids=decoder_input_ids, labels=decoder_input_ids)
loss, logits = outputs.loss, outputs.logits

# save and load from pretrained
model.save_pretrained("vit-gpt2")
model = TFVisionEncoderDecoderModel.from_pretrained("vit-gpt2")

# generation
generated = model.generate(pixel_values, decoder_start_token_id=model.config.decoder.bos_token_id)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor, AutoTokenizer, TFVisionEncoderDecoderModel
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests

<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&quot;google/vit-base-patch16-224-in21k&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>decoder_tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;gpt2&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># initialize a bert2gpt2 from a pretrained BERT and GPT2 models. Note that the cross-attention layers will be randomly initialized</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;google/vit-base-patch16-224-in21k&quot;</span>, <span class="hljs-string">&quot;gpt2&quot;</span>
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">&quot;http://images.cocodataset.org/val2017/000000039769.jpg&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>img = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># forward</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>pixel_values = image_processor(images=img, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>).pixel_values  <span class="hljs-comment"># Batch size 1</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>decoder_input_ids = decoder_tokenizer(<span class="hljs-string">&quot;Linda Davis&quot;</span>, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>).input_ids  <span class="hljs-comment"># Batch size 1</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(pixel_values=pixel_values, decoder_input_ids=decoder_input_ids)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># training</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(pixel_values=pixel_values, decoder_input_ids=decoder_input_ids, labels=decoder_input_ids)
<span class="hljs-meta">&gt;&gt;&gt; </span>loss, logits = outputs.loss, outputs.logits

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># save and load from pretrained</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model.save_pretrained(<span class="hljs-string">&quot;vit-gpt2&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFVisionEncoderDecoderModel.from_pretrained(<span class="hljs-string">&quot;vit-gpt2&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># generation</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>generated = model.generate(pixel_values, decoder_start_token_id=model.config.decoder.bos_token_id)`}}),{c(){h=a("p"),$=t("Examples:"),_=c(),b(f.$$.fragment)},l(d){h=s(d,"P",{});var u=i(h);$=r(u,"Examples:"),u.forEach(n),_=p(d),w(f.$$.fragment,d)},m(d,u){g(d,h,u),e(h,$),g(d,_,u),T(f,d,u),v=!0},p:hn,i(d){v||(y(f.$$.fragment,d),v=!0)},o(d){E(f.$$.fragment,d),v=!1},d(d){d&&n(h),d&&n(_),k(f,d)}}}function th(P){let h,$,_,f,v;return f=new U({props:{code:`from transformers import TFVisionEncoderDecoderModel

# initialize a vit-bert from a pretrained ViT and a pretrained BERT model. Note that the cross-attention layers will be randomly initialized
model = TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
    "google/vit-base-patch16-224-in21k", "bert-base-uncased"
)
# saving model after fine-tuning
model.save_pretrained("./vit-bert")
# load fine-tuned model
model = TFVisionEncoderDecoderModel.from_pretrained("./vit-bert")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFVisionEncoderDecoderModel

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># initialize a vit-bert from a pretrained ViT and a pretrained BERT model. Note that the cross-attention layers will be randomly initialized</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;google/vit-base-patch16-224-in21k&quot;</span>, <span class="hljs-string">&quot;bert-base-uncased&quot;</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># saving model after fine-tuning</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model.save_pretrained(<span class="hljs-string">&quot;./vit-bert&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># load fine-tuned model</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFVisionEncoderDecoderModel.from_pretrained(<span class="hljs-string">&quot;./vit-bert&quot;</span>)`}}),{c(){h=a("p"),$=t("Example:"),_=c(),b(f.$$.fragment)},l(d){h=s(d,"P",{});var u=i(h);$=r(u,"Example:"),u.forEach(n),_=p(d),w(f.$$.fragment,d)},m(d,u){g(d,h,u),e(h,$),g(d,_,u),T(f,d,u),v=!0},p:hn,i(d){v||(y(f.$$.fragment,d),v=!0)},o(d){E(f.$$.fragment,d),v=!1},d(d){d&&n(h),d&&n(_),k(f,d)}}}function rh(P){let h,$,_,f,v;return{c(){h=a("p"),$=t("Although the recipe for forward pass needs to be defined within this function, one should call the "),_=a("code"),f=t("Module"),v=t(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(d){h=s(d,"P",{});var u=i(h);$=r(u,"Although the recipe for forward pass needs to be defined within this function, one should call the "),_=s(u,"CODE",{});var S=i(_);f=r(S,"Module"),S.forEach(n),v=r(u,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),u.forEach(n)},m(d,u){g(d,h,u),e(h,$),e(h,_),e(_,f),e(h,v)},d(d){d&&n(h)}}}function ah(P){let h,$,_,f,v;return f=new U({props:{code:`from transformers import FlaxVisionEncoderDecoderModel, AutoImageProcessor, AutoTokenizer
from PIL import Image
import requests

url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)

image_processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224-in21k")

# load output tokenizer
tokenizer_output = AutoTokenizer.from_pretrained("gpt2")

# 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 = image_processor(images=image, return_tensors="np").pixel_values

# use GPT2's eos_token as the pad as well as eos token
model.config.eos_token_id = model.config.decoder.eos_token_id
model.config.pad_token_id = model.config.eos_token_id

# generation
sequences = model.generate(pixel_values, num_beams=4, max_length=12).sequences

captions = tokenizer_output.batch_decode(sequences, skip_special_tokens=True)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> FlaxVisionEncoderDecoderModel, AutoImageProcessor, AutoTokenizer
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests

<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">&quot;http://images.cocodataset.org/val2017/000000039769.jpg&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)

<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&quot;google/vit-base-patch16-224-in21k&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># load output tokenizer</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer_output = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;gpt2&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># initialize a vit-gpt2 from pretrained ViT and GPT2 models. Note that the cross-attention layers will be randomly initialized</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;google/vit-base-patch16-224-in21k&quot;</span>, <span class="hljs-string">&quot;gpt2&quot;</span>
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>pixel_values = image_processor(images=image, return_tensors=<span class="hljs-string">&quot;np&quot;</span>).pixel_values

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># use GPT2&#x27;s eos_token as the pad as well as eos token</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model.config.eos_token_id = model.config.decoder.eos_token_id
<span class="hljs-meta">&gt;&gt;&gt; </span>model.config.pad_token_id = model.config.eos_token_id

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># generation</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>sequences = model.generate(pixel_values, num_beams=<span class="hljs-number">4</span>, max_length=<span class="hljs-number">12</span>).sequences

<span class="hljs-meta">&gt;&gt;&gt; </span>captions = tokenizer_output.batch_decode(sequences, skip_special_tokens=<span class="hljs-literal">True</span>)`}}),{c(){h=a("p"),$=t("Examples:"),_=c(),b(f.$$.fragment)},l(d){h=s(d,"P",{});var u=i(h);$=r(u,"Examples:"),u.forEach(n),_=p(d),w(f.$$.fragment,d)},m(d,u){g(d,h,u),e(h,$),g(d,_,u),T(f,d,u),v=!0},p:hn,i(d){v||(y(f.$$.fragment,d),v=!0)},o(d){E(f.$$.fragment,d),v=!1},d(d){d&&n(h),d&&n(_),k(f,d)}}}function sh(P){let h,$,_,f,v;return f=new U({props:{code:`from transformers import FlaxVisionEncoderDecoderModel

# initialize a vit-gpt2 from a pretrained ViT and a pretrained GPT2 model. Note that the cross-attention layers will be randomly initialized
model = FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
    "google/vit-base-patch16-224-in21k", "gpt2"
)
# saving model after fine-tuning
model.save_pretrained("./vit-gpt2")
# load fine-tuned model
model = FlaxVisionEncoderDecoderModel.from_pretrained("./vit-gpt2")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> FlaxVisionEncoderDecoderModel

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># initialize a vit-gpt2 from a pretrained ViT and a pretrained GPT2 model. Note that the cross-attention layers will be randomly initialized</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;google/vit-base-patch16-224-in21k&quot;</span>, <span class="hljs-string">&quot;gpt2&quot;</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># saving model after fine-tuning</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model.save_pretrained(<span class="hljs-string">&quot;./vit-gpt2&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># load fine-tuned model</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = FlaxVisionEncoderDecoderModel.from_pretrained(<span class="hljs-string">&quot;./vit-gpt2&quot;</span>)`}}),{c(){h=a("p"),$=t("Example:"),_=c(),b(f.$$.fragment)},l(d){h=s(d,"P",{});var u=i(h);$=r(u,"Example:"),u.forEach(n),_=p(d),w(f.$$.fragment,d)},m(d,u){g(d,h,u),e(h,$),g(d,_,u),T(f,d,u),v=!0},p:hn,i(d){v||(y(f.$$.fragment,d),v=!0)},o(d){E(f.$$.fragment,d),v=!1},d(d){d&&n(h),d&&n(_),k(f,d)}}}function ih(P){let h,$,_,f,v,d,u,S,qa,Er,te,Ee,ft,no,Pa,gt,za,kr,x,Fa,fn,Aa,Ca,ut,Ia,Sa,gn,La,Oa,un,Na,Ra,_n,Ba,Ga,vn,Wa,Ha,_t,Ua,Za,bn,Ya,Ja,wn,Ka,Qa,Tn,Xa,es,yn,os,ns,$r,ke,ts,to,rs,as,xr,$e,ss,En,is,ds,jr,J,ls,kn,cs,ps,$n,ms,hs,Mr,re,xe,vt,ro,fs,ao,gs,bt,us,_s,Dr,Z,xn,vs,bs,jn,ws,Ts,wt,ys,Es,Vr,so,qr,ae,je,Tt,io,ks,lo,$s,yt,xs,js,Pr,M,Mn,Ms,Ds,Et,Vs,qs,Dn,Ps,zs,kt,Fs,As,$t,Cs,Is,xt,Ss,Ls,Vn,Os,Ns,Me,Rs,jt,Bs,Gs,Mt,Ws,Hs,qn,Us,Zs,zr,co,Fr,se,De,Dt,po,Ys,mo,Js,Vt,Ks,Qs,Ar,L,Xs,qt,ei,oi,Pn,ni,ti,Pt,ri,ai,Cr,Ve,si,zt,ii,di,Ir,ho,Sr,ie,qe,Ft,fo,li,go,ci,At,pi,mi,Lr,de,Ct,hi,fi,It,gi,ui,Or,uo,Nr,le,Pe,St,_o,_i,Lt,vi,Rr,O,bi,Ot,wi,Ti,Nt,yi,Ei,Rt,ki,$i,Br,vo,Gr,K,xi,bo,ji,Mi,wo,Di,Vi,Wr,ce,ze,Bt,To,qi,Gt,Pi,Hr,I,yo,zi,Fe,zn,Fi,Ai,Fn,Ci,Ii,Si,pe,Li,An,Oi,Ni,Cn,Ri,Bi,Gi,Ae,Wi,Ce,Eo,Hi,ko,Ui,In,Zi,Yi,Ji,Ie,$o,Ki,me,Qi,Wt,Xi,ed,Ht,od,nd,Ur,he,Se,Ut,xo,td,Zt,rd,Zr,D,jo,ad,fe,sd,Sn,id,dd,Ln,ld,cd,pd,Mo,md,Do,hd,fd,gd,Vo,ud,qo,_d,vd,bd,Yt,wd,Td,Po,yd,On,Ed,kd,$d,zo,xd,Fo,jd,Md,Dd,Q,Nn,Vd,qd,Jt,Pd,zd,Kt,Fd,Ad,Cd,N,Ao,Id,ge,Sd,Rn,Ld,Od,Qt,Nd,Rd,Bd,Le,Gd,Oe,Wd,R,Co,Hd,Xt,Ud,Zd,ue,Yd,er,Jd,Kd,or,Qd,Xd,el,Ne,Yr,_e,Re,nr,Io,ol,tr,nl,Jr,V,So,tl,ve,rl,Bn,al,sl,Gn,il,dl,ll,Lo,cl,Oo,pl,ml,hl,No,fl,Ro,gl,ul,_l,rr,vl,bl,Bo,wl,Wn,Tl,yl,El,Go,kl,Wo,$l,xl,jl,X,Hn,Ml,Dl,Un,Vl,ql,Zn,Pl,zl,Fl,B,Ho,Al,be,Cl,Yn,Il,Sl,ar,Ll,Ol,Nl,Be,Rl,Ge,Bl,ee,Uo,Gl,sr,Wl,Hl,We,Kr,we,He,ir,Zo,Ul,dr,Zl,Qr,q,Yo,Yl,Te,Jl,Jn,Kl,Ql,Kn,Xl,ec,oc,Jo,nc,Ko,tc,rc,ac,Qo,sc,Xo,ic,dc,lc,lr,cc,pc,en,mc,Qn,hc,fc,gc,on,uc,nn,_c,vc,bc,oe,Xn,wc,Tc,cr,yc,Ec,pr,kc,$c,xc,G,tn,jc,ye,Mc,et,Dc,Vc,mr,qc,Pc,zc,Ue,Fc,Ze,Ac,ne,rn,Cc,hr,Ic,Sc,Ye,Xr;return d=new Y({}),no=new Y({}),ro=new Y({}),so=new U({props:{code:`from transformers import BertConfig, ViTConfig, VisionEncoderDecoderConfig, VisionEncoderDecoderModel

config_encoder = ViTConfig()
config_decoder = BertConfig()

config = VisionEncoderDecoderConfig.from_encoder_decoder_configs(config_encoder, config_decoder)
model = VisionEncoderDecoderModel(config=config)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BertConfig, ViTConfig, VisionEncoderDecoderConfig, VisionEncoderDecoderModel

<span class="hljs-meta">&gt;&gt;&gt; </span>config_encoder = ViTConfig()
<span class="hljs-meta">&gt;&gt;&gt; </span>config_decoder = BertConfig()

<span class="hljs-meta">&gt;&gt;&gt; </span>config = VisionEncoderDecoderConfig.from_encoder_decoder_configs(config_encoder, config_decoder)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = VisionEncoderDecoderModel(config=config)`}}),io=new Y({}),co=new U({props:{code:`from transformers import VisionEncoderDecoderModel

model = VisionEncoderDecoderModel.from_encoder_decoder_pretrained(
    "microsoft/swin-base-patch4-window7-224-in22k", "bert-base-uncased"
)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> VisionEncoderDecoderModel

<span class="hljs-meta">&gt;&gt;&gt; </span>model = VisionEncoderDecoderModel.from_encoder_decoder_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;microsoft/swin-base-patch4-window7-224-in22k&quot;</span>, <span class="hljs-string">&quot;bert-base-uncased&quot;</span>
<span class="hljs-meta">... </span>)`}}),po=new Y({}),ho=new U({props:{code:`import requests
from PIL import Image

from transformers import GPT2TokenizerFast, ViTImageProcessor, VisionEncoderDecoderModel

# load a fine-tuned image captioning model and corresponding tokenizer and image processor
model = VisionEncoderDecoderModel.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
tokenizer = GPT2TokenizerFast.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
image_processor = ViTImageProcessor.from_pretrained("nlpconnect/vit-gpt2-image-captioning")

# let's perform inference on an image
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
pixel_values = image_processor(image, return_tensors="pt").pixel_values

# autoregressively generate caption (uses greedy decoding by default)
generated_ids = model.generate(pixel_values)
generated_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(generated_text)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> GPT2TokenizerFast, ViTImageProcessor, VisionEncoderDecoderModel

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># load a fine-tuned image captioning model and corresponding tokenizer and image processor</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = VisionEncoderDecoderModel.from_pretrained(<span class="hljs-string">&quot;nlpconnect/vit-gpt2-image-captioning&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = GPT2TokenizerFast.from_pretrained(<span class="hljs-string">&quot;nlpconnect/vit-gpt2-image-captioning&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = ViTImageProcessor.from_pretrained(<span class="hljs-string">&quot;nlpconnect/vit-gpt2-image-captioning&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># let&#x27;s perform inference on an image</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">&quot;http://images.cocodataset.org/val2017/000000039769.jpg&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)
<span class="hljs-meta">&gt;&gt;&gt; </span>pixel_values = image_processor(image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).pixel_values

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># autoregressively generate caption (uses greedy decoding by default)</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>generated_ids = model.generate(pixel_values)
<span class="hljs-meta">&gt;&gt;&gt; </span>generated_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(generated_text)
a cat laying on a blanket <span class="hljs-built_in">next</span> to a cat laying on a bed`}}),fo=new Y({}),uo=new U({props:{code:`from transformers import VisionEncoderDecoderModel, TFVisionEncoderDecoderModel

_model = VisionEncoderDecoderModel.from_pretrained("nlpconnect/vit-gpt2-image-captioning")

_model.encoder.save_pretrained("./encoder")
_model.decoder.save_pretrained("./decoder")

model = TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
    "./encoder", "./decoder", encoder_from_pt=True, decoder_from_pt=True
)
# This is only for copying some specific attributes of this particular model.
model.config = _model.config`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> VisionEncoderDecoderModel, TFVisionEncoderDecoderModel

<span class="hljs-meta">&gt;&gt;&gt; </span>_model = VisionEncoderDecoderModel.from_pretrained(<span class="hljs-string">&quot;nlpconnect/vit-gpt2-image-captioning&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>_model.encoder.save_pretrained(<span class="hljs-string">&quot;./encoder&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>_model.decoder.save_pretrained(<span class="hljs-string">&quot;./decoder&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;./encoder&quot;</span>, <span class="hljs-string">&quot;./decoder&quot;</span>, encoder_from_pt=<span class="hljs-literal">True</span>, decoder_from_pt=<span class="hljs-literal">True</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># This is only for copying some specific attributes of this particular model.</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model.config = _model.config`}}),_o=new Y({}),vo=new U({props:{code:`from transformers import ViTImageProcessor, BertTokenizer, VisionEncoderDecoderModel
from datasets import load_dataset

image_processor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224-in21k")
tokenizer = BertTokenizer.from_pretrained("bert-base-uncased")
model = VisionEncoderDecoderModel.from_encoder_decoder_pretrained(
    "google/vit-base-patch16-224-in21k", "bert-base-uncased"
)

model.config.decoder_start_token_id = tokenizer.cls_token_id
model.config.pad_token_id = tokenizer.pad_token_id

dataset = load_dataset("huggingface/cats-image")
image = dataset["test"]["image"][0]
pixel_values = image_processor(image, return_tensors="pt").pixel_values

labels = tokenizer(
    "an image of two cats chilling on a couch",
    return_tensors="pt",
).input_ids

# the forward function automatically creates the correct decoder_input_ids
loss = model(pixel_values=pixel_values, labels=labels).loss`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> ViTImageProcessor, BertTokenizer, VisionEncoderDecoderModel
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = ViTImageProcessor.from_pretrained(<span class="hljs-string">&quot;google/vit-base-patch16-224-in21k&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = BertTokenizer.from_pretrained(<span class="hljs-string">&quot;bert-base-uncased&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = VisionEncoderDecoderModel.from_encoder_decoder_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;google/vit-base-patch16-224-in21k&quot;</span>, <span class="hljs-string">&quot;bert-base-uncased&quot;</span>
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>model.config.decoder_start_token_id = tokenizer.cls_token_id
<span class="hljs-meta">&gt;&gt;&gt; </span>model.config.pad_token_id = tokenizer.pad_token_id

<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = load_dataset(<span class="hljs-string">&quot;huggingface/cats-image&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>image = dataset[<span class="hljs-string">&quot;test&quot;</span>][<span class="hljs-string">&quot;image&quot;</span>][<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>pixel_values = image_processor(image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).pixel_values

<span class="hljs-meta">&gt;&gt;&gt; </span>labels = tokenizer(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;an image of two cats chilling on a couch&quot;</span>,
<span class="hljs-meta">... </span>    return_tensors=<span class="hljs-string">&quot;pt&quot;</span>,
<span class="hljs-meta">... </span>).input_ids

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># the forward function automatically creates the correct decoder_input_ids</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>loss = model(pixel_values=pixel_values, labels=labels).loss`}}),To=new Y({}),yo=new H({props:{name:"class transformers.VisionEncoderDecoderConfig",anchor:"transformers.VisionEncoderDecoderConfig",parameters:[{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.VisionEncoderDecoderConfig.kwargs",description:`<strong>kwargs</strong> (<em>optional</em>) &#x2014;
Dictionary of keyword arguments. Notably:</p>
<ul>
<li><strong>encoder</strong> (<a href="/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig">PretrainedConfig</a>, <em>optional</em>) &#x2014; An instance of a configuration object that defines
the encoder config.</li>
<li><strong>decoder</strong> (<a href="/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig">PretrainedConfig</a>, <em>optional</em>) &#x2014; An instance of a configuration object that defines
the decoder config.</li>
</ul>`,name:"kwargs"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/vision_encoder_decoder/configuration_vision_encoder_decoder.py#L34"}}),Ae=new mn({props:{anchor:"transformers.VisionEncoderDecoderConfig.example",$$slots:{default:[Km]},$$scope:{ctx:P}}}),Eo=new H({props:{name:"from_encoder_decoder_configs",anchor:"transformers.VisionEncoderDecoderConfig.from_encoder_decoder_configs",parameters:[{name:"encoder_config",val:": PretrainedConfig"},{name:"decoder_config",val:": PretrainedConfig"},{name:"**kwargs",val:""}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/vision_encoder_decoder/configuration_vision_encoder_decoder.py#L100",returnDescription:`
<p>An instance of a configuration object</p>
`,returnType:`
<p><a
  href="/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderConfig"
>VisionEncoderDecoderConfig</a></p>
`}}),$o=new H({props:{name:"to_dict",anchor:"transformers.VisionEncoderDecoderConfig.to_dict",parameters:[],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/vision_encoder_decoder/configuration_vision_encoder_decoder.py#L117",returnDescription:`
<p>Dictionary of all the attributes that make up this configuration instance,</p>
`,returnType:`
<p><code>Dict[str, any]</code></p>
`}}),xo=new Y({}),jo=new H({props:{name:"class transformers.VisionEncoderDecoderModel",anchor:"transformers.VisionEncoderDecoderModel",parameters:[{name:"config",val:": typing.Optional[transformers.configuration_utils.PretrainedConfig] = None"},{name:"encoder",val:": typing.Optional[transformers.modeling_utils.PreTrainedModel] = None"},{name:"decoder",val:": typing.Optional[transformers.modeling_utils.PreTrainedModel] = None"}],parametersDescription:[{anchor:"transformers.VisionEncoderDecoderModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderConfig">VisionEncoderDecoderConfig</a>) &#x2014; Model configuration class with all the parameters of the model.
Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the <a href="/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/vision_encoder_decoder/modeling_vision_encoder_decoder.py#L151"}}),Ao=new H({props:{name:"forward",anchor:"transformers.VisionEncoderDecoderModel.forward",parameters:[{name:"pixel_values",val:": typing.Optional[torch.FloatTensor] = None"},{name:"decoder_input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"decoder_attention_mask",val:": typing.Optional[torch.BoolTensor] = None"},{name:"encoder_outputs",val:": typing.Optional[typing.Tuple[torch.FloatTensor]] = None"},{name:"past_key_values",val:": typing.Optional[typing.Tuple[typing.Tuple[torch.FloatTensor]]] = None"},{name:"decoder_inputs_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"labels",val:": typing.Optional[torch.LongTensor] = None"},{name:"use_cache",val:": typing.Optional[bool] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.VisionEncoderDecoderModel.forward.pixel_values",description:`<strong>pixel_values</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, num_channels, height, width)</code>) &#x2014;
Pixel values. Pixel values can be obtained using an image processor (e.g. if you use ViT as the encoder,
you should use <a href="/docs/transformers/main/en/model_doc/auto#transformers.AutoImageProcessor">AutoImageProcessor</a>). See <a href="/docs/transformers/main/en/model_doc/poolformer#transformers.PoolFormerFeatureExtractor.__call__">ViTImageProcessor.<strong>call</strong>()</a> for details.`,name:"pixel_values"},{anchor:"transformers.VisionEncoderDecoderModel.forward.decoder_input_ids",description:`<strong>decoder_input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Indices of decoder input sequence tokens in the vocabulary.</p>
<p>Indices can be obtained using <a href="/docs/transformers/main/en/main_classes/tokenizer#transformers.PreTrainedTokenizer">PreTrainedTokenizer</a>. See <a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a></p>
<p>If <code>past_key_values</code> is used, optionally only the last <code>decoder_input_ids</code> have to be input (see
<code>past_key_values</code>).</p>
<p>For training, <code>decoder_input_ids</code> are automatically created by the model by shifting the <code>labels</code> to the
right, replacing -100 by the <code>pad_token_id</code> and prepending them with the <code>decoder_start_token_id</code>.`,name:"decoder_input_ids"},{anchor:"transformers.VisionEncoderDecoderModel.forward.decoder_attention_mask",description:`<strong>decoder_attention_mask</strong> (<code>torch.BoolTensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Default behavior: generate a tensor that ignores pad tokens in <code>decoder_input_ids</code>. Causal mask will also
be used by default.`,name:"decoder_attention_mask"},{anchor:"transformers.VisionEncoderDecoderModel.forward.encoder_outputs",description:`<strong>encoder_outputs</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>) &#x2014;
This tuple must consist of (<code>last_hidden_state</code>, <em>optional</em>: <code>hidden_states</code>, <em>optional</em>: <code>attentions</code>)
<code>last_hidden_state</code> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>) is a tensor
of hidden-states at the output of the last layer of the encoder. Used in the cross-attention of the
decoder.`,name:"encoder_outputs"},{anchor:"transformers.VisionEncoderDecoderModel.forward.past_key_values",description:`<strong>past_key_values</strong> (<code>tuple(tuple(torch.FloatTensor))</code> of length <code>config.n_layers</code> with each tuple having 4 tensors of shape <code>(batch_size, num_heads, sequence_length - 1, embed_size_per_head)</code>) &#x2014;
Contains precomputed key and value hidden states of the attention blocks. Can be used to speed up decoding.</p>
<p>If <code>past_key_values</code> are used, the user can optionally input only the last <code>decoder_input_ids</code> (those that
don&#x2019;t have their past key value states given to this model) of shape <code>(batch_size, 1)</code> instead of all
<code>decoder_input_ids</code> of shape <code>(batch_size, sequence_length)</code>.`,name:"past_key_values"},{anchor:"transformers.VisionEncoderDecoderModel.forward.decoder_inputs_embeds",description:`<strong>decoder_inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, target_sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>decoder_input_ids</code> you can choose to directly pass an embedded
representation. This is useful if you want more control over how to convert <code>decoder_input_ids</code> indices
into associated vectors than the model&#x2019;s internal embedding lookup matrix.`,name:"decoder_inputs_embeds"},{anchor:"transformers.VisionEncoderDecoderModel.forward.labels",description:`<strong>labels</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Labels for computing the masked language modeling loss for the decoder. Indices should be in <code>[-100, 0, ..., config.vocab_size]</code> (see <code>input_ids</code> docstring) Tokens with indices set to <code>-100</code> are ignored
(masked), the loss is only computed for the tokens with labels in <code>[0, ..., config.vocab_size]</code>`,name:"labels"},{anchor:"transformers.VisionEncoderDecoderModel.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding (see
<code>past_key_values</code>).`,name:"use_cache"},{anchor:"transformers.VisionEncoderDecoderModel.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.VisionEncoderDecoderModel.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.VisionEncoderDecoderModel.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
If set to <code>True</code>, the model will return a <code>~utils.Seq2SeqLMOutput</code> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.VisionEncoderDecoderModel.forward.kwargs",description:`<strong>kwargs</strong> (<em>optional</em>) &#x2014; Remaining dictionary of keyword arguments. Keyword arguments come in two flavors:</p>
<ul>
<li>Without a prefix which will be input as <code>**encoder_kwargs</code> for the encoder forward function.</li>
<li>With a <em>decoder_</em> prefix which will be input as <code>**decoder_kwargs</code> for the decoder forward function.</li>
</ul>`,name:"kwargs"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/vision_encoder_decoder/modeling_vision_encoder_decoder.py#L519",returnDescription:`
<p>A <a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_outputs.Seq2SeqLMOutput"
>transformers.modeling_outputs.Seq2SeqLMOutput</a> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderConfig"
>VisionEncoderDecoderConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>loss</strong> (<code>torch.FloatTensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) \u2014 Language modeling loss.</p>
</li>
<li>
<p><strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) \u2014 Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).</p>
</li>
<li>
<p><strong>past_key_values</strong> (<code>tuple(tuple(torch.FloatTensor))</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) \u2014 Tuple of <code>tuple(torch.FloatTensor)</code> of length <code>config.n_layers</code>, with each tuple having 2 tensors of shape
<code>(batch_size, num_heads, sequence_length, embed_size_per_head)</code>) and 2 additional tensors of shape
<code>(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)</code>.</p>
<p>Contains pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
blocks) that can be used (see <code>past_key_values</code> input) to speed up sequential decoding.</p>
</li>
<li>
<p><strong>decoder_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the decoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>decoder_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the decoder, after the attention softmax, used to compute the weighted average in the
self-attention heads.</p>
</li>
<li>
<p><strong>cross_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the decoder\u2019s cross-attention layer, after the attention softmax, used to compute the
weighted average in the cross-attention heads.</p>
</li>
<li>
<p><strong>encoder_last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) \u2014 Sequence of hidden-states at the output of the last layer of the encoder of the model.</p>
</li>
<li>
<p><strong>encoder_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the encoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>encoder_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the encoder, after the attention softmax, used to compute the weighted average in the
self-attention heads.</p>
</li>
</ul>
`,returnType:`
<p><a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_outputs.Seq2SeqLMOutput"
>transformers.modeling_outputs.Seq2SeqLMOutput</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),Le=new Oc({props:{$$slots:{default:[Qm]},$$scope:{ctx:P}}}),Oe=new mn({props:{anchor:"transformers.VisionEncoderDecoderModel.forward.example",$$slots:{default:[Xm]},$$scope:{ctx:P}}}),Co=new H({props:{name:"from_encoder_decoder_pretrained",anchor:"transformers.VisionEncoderDecoderModel.from_encoder_decoder_pretrained",parameters:[{name:"encoder_pretrained_model_name_or_path",val:": str = None"},{name:"decoder_pretrained_model_name_or_path",val:": str = None"},{name:"*model_args",val:""},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.VisionEncoderDecoderModel.from_encoder_decoder_pretrained.encoder_pretrained_model_name_or_path",description:`<strong>encoder_pretrained_model_name_or_path</strong> (<code>str</code>, <em>optional</em>) &#x2014;
Information necessary to initiate the image encoder. Can be either:</p>
<ul>
<li>A string, the <em>model id</em> of a pretrained model hosted inside a model repo on huggingface.co. An
example is <code>google/vit-base-patch16-224-in21k</code>.</li>
<li>A path to a <em>directory</em> containing model weights saved using
<a href="/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel.save_pretrained">save_pretrained()</a>, e.g., <code>./my_model_directory/</code>.</li>
<li>A path or url to a <em>tensorflow index checkpoint file</em> (e.g, <code>./tf_model/model.ckpt.index</code>). In
this case, <code>from_tf</code> should be set to <code>True</code> and a configuration object should be provided as
<code>config</code> argument. This loading path is slower than converting the TensorFlow checkpoint in a
PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.</li>
</ul>`,name:"encoder_pretrained_model_name_or_path"},{anchor:"transformers.VisionEncoderDecoderModel.from_encoder_decoder_pretrained.decoder_pretrained_model_name_or_path",description:`<strong>decoder_pretrained_model_name_or_path</strong> (<code>str</code>, <em>optional</em>, defaults to <code>None</code>) &#x2014;
Information necessary to initiate the text decoder. Can be either:</p>
<ul>
<li>A string, the <em>model id</em> of a pretrained model hosted inside a model repo on huggingface.co.
Valid model ids can be located at the root-level, like <code>bert-base-uncased</code>, or namespaced under a
user or organization name, like <code>dbmdz/bert-base-german-cased</code>.</li>
<li>A path to a <em>directory</em> containing model weights saved using
<a href="/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel.save_pretrained">save_pretrained()</a>, e.g., <code>./my_model_directory/</code>.</li>
<li>A path or url to a <em>tensorflow index checkpoint file</em> (e.g, <code>./tf_model/model.ckpt.index</code>). In
this case, <code>from_tf</code> should be set to <code>True</code> and a configuration object should be provided as
<code>config</code> argument. This loading path is slower than converting the TensorFlow checkpoint in a
PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.</li>
</ul>`,name:"decoder_pretrained_model_name_or_path"},{anchor:"transformers.VisionEncoderDecoderModel.from_encoder_decoder_pretrained.model_args",description:`<strong>model_args</strong> (remaining positional arguments, <em>optional</em>) &#x2014;
All remaning positional arguments will be passed to the underlying model&#x2019;s <code>__init__</code> method.`,name:"model_args"},{anchor:"transformers.VisionEncoderDecoderModel.from_encoder_decoder_pretrained.kwargs",description:`<strong>kwargs</strong> (remaining dictionary of keyword arguments, <em>optional</em>) &#x2014;
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
<code>output_attentions=True</code>).</p>
<ul>
<li>To update the encoder configuration, use the prefix <em>encoder_</em> for each configuration parameter.</li>
<li>To update the decoder configuration, use the prefix <em>decoder_</em> for each configuration parameter.</li>
<li>To update the parent model configuration, do not use a prefix for each configuration parameter.</li>
</ul>
<p>Behaves differently depending on whether a <code>config</code> is provided or automatically loaded.`,name:"kwargs"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/vision_encoder_decoder/modeling_vision_encoder_decoder.py#L365"}}),Ne=new mn({props:{anchor:"transformers.VisionEncoderDecoderModel.from_encoder_decoder_pretrained.example",$$slots:{default:[eh]},$$scope:{ctx:P}}}),Io=new Y({}),So=new H({props:{name:"class transformers.TFVisionEncoderDecoderModel",anchor:"transformers.TFVisionEncoderDecoderModel",parameters:[{name:"*args",val:""},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.TFVisionEncoderDecoderModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderConfig">VisionEncoderDecoderConfig</a>) &#x2014; Model configuration class with all the parameters of the model.
Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the <a href="/docs/transformers/main/en/main_classes/model#transformers.TFPreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/vision_encoder_decoder/modeling_tf_vision_encoder_decoder.py#L177"}}),Ho=new H({props:{name:"call",anchor:"transformers.TFVisionEncoderDecoderModel.call",parameters:[{name:"pixel_values",val:" = None"},{name:"decoder_input_ids",val:" = None"},{name:"decoder_attention_mask",val:" = None"},{name:"encoder_outputs",val:" = None"},{name:"past_key_values",val:" = None"},{name:"decoder_inputs_embeds",val:" = None"},{name:"labels",val:" = None"},{name:"use_cache",val:" = None"},{name:"output_attentions",val:" = None"},{name:"output_hidden_states",val:" = None"},{name:"return_dict",val:" = None"},{name:"training",val:" = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.TFVisionEncoderDecoderModel.call.pixel_values",description:`<strong>pixel_values</strong> (<code>np.ndarray</code>, <code>tf.Tensor</code>, <code>List[tf.Tensor]</code> \`<code>Dict[str, tf.Tensor]</code> or <code>Dict[str, np.ndarray]</code> and each example must have the shape <code>(batch_size, num_channels, height, width)</code>) &#x2014;
Pixel values. Pixel values can be obtained using the vision&#x2019;s model&#x2019;s image processor. For example, using
<a href="/docs/transformers/main/en/model_doc/auto#transformers.AutoImageProcessor">AutoImageProcessor</a>. See <a href="/docs/transformers/main/en/model_doc/poolformer#transformers.PoolFormerFeatureExtractor.__call__">ViTImageProcessor.<strong>call</strong>()</a> for details.`,name:"pixel_values"},{anchor:"transformers.TFVisionEncoderDecoderModel.call.decoder_input_ids",description:`<strong>decoder_input_ids</strong> (<code>np.ndarray</code> or <code>tf.Tensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Indices of decoder input sequence tokens in the vocabulary.</p>
<p>Indices can be obtained using <a href="/docs/transformers/main/en/main_classes/tokenizer#transformers.PreTrainedTokenizer">PreTrainedTokenizer</a>. See <a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a></p>
<p>If <code>past_key_values</code> is used, optionally only the last <code>decoder_input_ids</code> have to be input (see
<code>past_key_values</code>).</p>
<p>Provide for sequence to sequence training to the decoder. Indices can be obtained using
<a href="/docs/transformers/main/en/main_classes/tokenizer#transformers.PreTrainedTokenizer">PreTrainedTokenizer</a>. See <a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and <a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for
details.`,name:"decoder_input_ids"},{anchor:"transformers.TFVisionEncoderDecoderModel.call.decoder_attention_mask",description:`<strong>decoder_attention_mask</strong> (<code>np.ndarray</code> or <code>tf.Tensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Default behavior: generate a tensor that ignores pad tokens in <code>decoder_input_ids</code>. Causal mask will also
be used by default.`,name:"decoder_attention_mask"},{anchor:"transformers.TFVisionEncoderDecoderModel.call.encoder_outputs",description:`<strong>encoder_outputs</strong> (<code>tuple(tuple(tf.Tensor)</code>, <em>optional</em>) &#x2014;
This tuple must consist of (<code>last_hidden_state</code>, <em>optional</em>: <code>hidden_states</code>, <em>optional</em>: <code>attentions</code>)
<code>last_hidden_state</code> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>) is a tensor of hidden-states at the output
of the last layer of the encoder. Used in the cross-attention of the decoder.`,name:"encoder_outputs"},{anchor:"transformers.TFVisionEncoderDecoderModel.call.past_key_values",description:`<strong>past_key_values</strong> (<code>tuple(tuple(tf.Tensor))</code> of length <code>config.n_layers</code> with each tuple having 4 tensors of shape <code>(batch_size, num_heads, sequence_length - 1, embed_size_per_head)</code>) &#x2014;
Contains precomputed key and value hidden states of the attention blocks. Can be used to speed up decoding.</p>
<p>If <code>past_key_values</code> are used, the user can optionally input only the last <code>decoder_input_ids</code> (those that
don&#x2019;t have their past key value states given to this model) of shape <code>(batch_size, 1)</code> instead of all
<code>decoder_input_ids</code> of shape <code>(batch_size, sequence_length)</code>.`,name:"past_key_values"},{anchor:"transformers.TFVisionEncoderDecoderModel.call.decoder_inputs_embeds",description:`<strong>decoder_inputs_embeds</strong> (<code>np.ndarray</code> or <code>tf.Tensor</code> of shape <code>(batch_size, target_sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>decoder_input_ids</code> you can choose to directly pass an embedded
representation. This is useful if you want more control over how to convert <code>decoder_input_ids</code> indices
into associated vectors than the model&#x2019;s internal embedding lookup matrix.`,name:"decoder_inputs_embeds"},{anchor:"transformers.TFVisionEncoderDecoderModel.call.labels",description:`<strong>labels</strong> (<code>np.ndarray</code> or <code>tf.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Labels for computing the masked language modeling loss for the decoder. Indices should be in <code>[-100, 0, ..., config.vocab_size]</code> (see <code>input_ids</code> docstring) Tokens with indices set to <code>-100</code> are ignored
(masked), the loss is only computed for the tokens with labels in <code>[0, ..., config.vocab_size]</code>`,name:"labels"},{anchor:"transformers.TFVisionEncoderDecoderModel.call.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding (see
<code>past_key_values</code>).`,name:"use_cache"},{anchor:"transformers.TFVisionEncoderDecoderModel.call.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.TFVisionEncoderDecoderModel.call.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.TFVisionEncoderDecoderModel.call.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
If set to <code>True</code>, the model will return a <code>~utils.Seq2SeqLMOutput</code> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.TFVisionEncoderDecoderModel.call.training",description:`<strong>training</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not to use the model in training mode (some modules like dropout modules have different
behaviors between training and evaluation).`,name:"training"},{anchor:"transformers.TFVisionEncoderDecoderModel.call.kwargs",description:`<strong>kwargs</strong> (<em>optional</em>) &#x2014; Remaining dictionary of keyword arguments. Keyword arguments come in two flavors:</p>
<ul>
<li>Without a prefix which will be input as <code>**encoder_kwargs</code> for the encoder forward function.</li>
<li>With a <em>decoder_</em> prefix which will be input as <code>**decoder_kwargs</code> for the decoder forward function.</li>
</ul>`,name:"kwargs"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/vision_encoder_decoder/modeling_tf_vision_encoder_decoder.py#L531",returnDescription:`
<p>A <a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_tf_outputs.TFSeq2SeqLMOutput"
>transformers.modeling_tf_outputs.TFSeq2SeqLMOutput</a> or a tuple of <code>tf.Tensor</code> (if
<code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various elements depending on the
configuration (<a
  href="/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderConfig"
>VisionEncoderDecoderConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>loss</strong> (<code>tf.Tensor</code> of shape <code>(n,)</code>, <em>optional</em>, where n is the number of non-masked labels, returned when <code>labels</code> is provided) \u2014 Language modeling loss.</p>
</li>
<li>
<p><strong>logits</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) \u2014 Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).</p>
</li>
<li>
<p><strong>past_key_values</strong> (<code>List[tf.Tensor]</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) \u2014 List of <code>tf.Tensor</code> of length <code>config.n_layers</code>, with each tensor of shape <code>(2, batch_size, num_heads, sequence_length, embed_size_per_head)</code>).</p>
<p>Contains pre-computed hidden-states (key and values in the attention blocks) of the decoder that can be
used (see <code>past_key_values</code> input) to speed up sequential decoding.</p>
</li>
<li>
<p><strong>decoder_hidden_states</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for the output of the embeddings + one for the output of each layer) of shape
<code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the decoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>decoder_attentions</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the decoder, after the attention softmax, used to compute the weighted average in the
self-attention heads.</p>
</li>
<li>
<p><strong>cross_attentions</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the decoder\u2019s cross-attention layer, after the attention softmax, used to compute the
weighted average in the cross-attention heads.</p>
</li>
<li>
<p><strong>encoder_last_hidden_state</strong> (<code>tf.Tensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) \u2014 Sequence of hidden-states at the output of the last layer of the encoder of the model.</p>
</li>
<li>
<p><strong>encoder_hidden_states</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for the output of the embeddings + one for the output of each layer) of shape
<code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the encoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>encoder_attentions</strong> (<code>tuple(tf.Tensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>tf.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the encoder, after the attention softmax, used to compute the weighted average in the
self-attention heads.</p>
</li>
</ul>
`,returnType:`
<p><a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_tf_outputs.TFSeq2SeqLMOutput"
>transformers.modeling_tf_outputs.TFSeq2SeqLMOutput</a> or <code>tuple(tf.Tensor)</code></p>
`}}),Be=new Oc({props:{$$slots:{default:[oh]},$$scope:{ctx:P}}}),Ge=new mn({props:{anchor:"transformers.TFVisionEncoderDecoderModel.call.example",$$slots:{default:[nh]},$$scope:{ctx:P}}}),Uo=new H({props:{name:"from_encoder_decoder_pretrained",anchor:"transformers.TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained",parameters:[{name:"encoder_pretrained_model_name_or_path",val:": str = None"},{name:"decoder_pretrained_model_name_or_path",val:": str = None"},{name:"*model_args",val:""},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained.encoder_pretrained_model_name_or_path",description:`<strong>encoder_pretrained_model_name_or_path</strong> (<code>str</code>, <em>optional</em>) &#x2014;
Information necessary to initiate the encoder. Can be either:</p>
<ul>
<li>A string, the <em>model id</em> of a pretrained model hosted inside a model repo on huggingface.co. An
example is <code>google/vit-base-patch16-224-in21k</code>.</li>
<li>A path to a <em>directory</em> containing model weights saved using
<a href="/docs/transformers/main/en/main_classes/model#transformers.TFPreTrainedModel.save_pretrained">save_pretrained()</a>, e.g., <code>./my_model_directory/</code>.</li>
<li>A path or url to a <em>pytorch index checkpoint file</em> (e.g, <code>./pt_model/</code>). In this case,
<code>encoder_from_pt</code> should be set to <code>True</code>.</li>
</ul>`,name:"encoder_pretrained_model_name_or_path"},{anchor:"transformers.TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained.decoder_pretrained_model_name_or_path",description:`<strong>decoder_pretrained_model_name_or_path</strong> (<code>str</code>, <em>optional</em>, defaults to <em>None</em>) &#x2014;
Information necessary to initiate the decoder. Can be either:</p>
<ul>
<li>A string, the <em>model id</em> of a pretrained model hosted inside a model repo on huggingface.co.
Valid model ids can be located at the root-level, like <code>bert-base-uncased</code>, or namespaced under a
user or organization name, like <code>dbmdz/bert-base-german-cased</code>.</li>
<li>A path to a <em>directory</em> containing model weights saved using
<a href="/docs/transformers/main/en/main_classes/model#transformers.TFPreTrainedModel.save_pretrained">save_pretrained()</a>, e.g., <code>./my_model_directory/</code>.</li>
<li>A path or url to a <em>pytorch checkpoint file</em> (e.g, <code>./pt_model/</code>). In this case,
<code>decoder_from_pt</code> should be set to <code>True</code>.</li>
</ul>`,name:"decoder_pretrained_model_name_or_path"},{anchor:"transformers.TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained.model_args",description:`<strong>model_args</strong> (remaining positional arguments, <em>optional</em>) &#x2014;
All remaning positional arguments will be passed to the underlying model&#x2019;s <code>__init__</code> method.`,name:"model_args"},{anchor:"transformers.TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained.kwargs",description:`<strong>kwargs</strong> (remaining dictionary of keyword arguments, <em>optional</em>) &#x2014;
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
<code>output_attentions=True</code>).</p>
<ul>
<li>To update the encoder configuration, use the prefix <em>encoder_</em> for each configuration parameter.</li>
<li>To update the decoder configuration, use the prefix <em>decoder_</em> for each configuration parameter.</li>
<li>To update the parent model configuration, do not use a prefix for each configuration parameter.</li>
</ul>
<p>Behaves differently depending on whether a <code>config</code> is provided or automatically loaded.`,name:"kwargs"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/vision_encoder_decoder/modeling_tf_vision_encoder_decoder.py#L365"}}),We=new mn({props:{anchor:"transformers.TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained.example",$$slots:{default:[th]},$$scope:{ctx:P}}}),Zo=new Y({}),Yo=new H({props:{name:"class transformers.FlaxVisionEncoderDecoderModel",anchor:"transformers.FlaxVisionEncoderDecoderModel",parameters:[{name:"config",val:": VisionEncoderDecoderConfig"},{name:"input_shape",val:": typing.Optional[typing.Tuple] = None"},{name:"seed",val:": int = 0"},{name:"dtype",val:": dtype = <class 'jax.numpy.float32'>"},{name:"_do_init",val:": bool = True"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.FlaxVisionEncoderDecoderModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderConfig">VisionEncoderDecoderConfig</a>) &#x2014; Model configuration class with all the parameters of the model.
Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the <a href="/docs/transformers/main/en/main_classes/model#transformers.FlaxPreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"},{anchor:"transformers.FlaxVisionEncoderDecoderModel.dtype",description:`<strong>dtype</strong> (<code>jax.numpy.dtype</code>, <em>optional</em>, defaults to <code>jax.numpy.float32</code>) &#x2014;
The data type of the computation. Can be one of <code>jax.numpy.float32</code>, <code>jax.numpy.float16</code> (on GPUs) and
<code>jax.numpy.bfloat16</code> (on TPUs).</p>
<p>This can be used to enable mixed-precision training or half-precision inference on GPUs or TPUs. If
specified all the computation will be performed with the given <code>dtype</code>.</p>
<p><strong>Note that this only specifies the dtype of the computation and does not influence the dtype of model
parameters.</strong></p>
<p>If you wish to change the dtype of the model parameters, see <a href="/docs/transformers/main/en/main_classes/model#transformers.FlaxPreTrainedModel.to_fp16">to_fp16()</a> and
<a href="/docs/transformers/main/en/main_classes/model#transformers.FlaxPreTrainedModel.to_bf16">to_bf16()</a>.`,name:"dtype"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/vision_encoder_decoder/modeling_flax_vision_encoder_decoder.py#L268"}}),tn=new H({props:{name:"__call__",anchor:"transformers.FlaxVisionEncoderDecoderModel.__call__",parameters:[{name:"pixel_values",val:": ndarray"},{name:"decoder_input_ids",val:": typing.Optional[jax._src.numpy.ndarray.ndarray] = None"},{name:"decoder_attention_mask",val:": typing.Optional[jax._src.numpy.ndarray.ndarray] = None"},{name:"decoder_position_ids",val:": typing.Optional[jax._src.numpy.ndarray.ndarray] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"},{name:"train",val:": bool = False"},{name:"params",val:": dict = None"},{name:"dropout_rng",val:": PRNGKey = None"}],parametersDescription:[{anchor:"transformers.FlaxVisionEncoderDecoderModel.__call__.pixel_values",description:`<strong>pixel_values</strong> (<code>jnp.ndarray</code> of shape <code>(batch_size, num_channels, height, width)</code>) &#x2014;
Pixel values. Pixel values can be obtained using the vision model&#x2019;s image processor. For example, using
<a href="/docs/transformers/main/en/model_doc/auto#transformers.AutoImageProcessor">AutoImageProcessor</a>. See <a href="/docs/transformers/main/en/model_doc/poolformer#transformers.PoolFormerFeatureExtractor.__call__">ViTImageProcessor.<strong>call</strong>()</a> for details.`,name:"pixel_values"},{anchor:"transformers.FlaxVisionEncoderDecoderModel.__call__.decoder_input_ids",description:`<strong>decoder_input_ids</strong> (<code>jnp.ndarray</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Indices of decoder input sequence tokens in the vocabulary.</p>
<p>Indices can be obtained using <a href="/docs/transformers/main/en/main_classes/tokenizer#transformers.PreTrainedTokenizer">PreTrainedTokenizer</a>. See <a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#decoder-input-ids">What are decoder input IDs?</a>`,name:"decoder_input_ids"},{anchor:"transformers.FlaxVisionEncoderDecoderModel.__call__.decoder_attention_mask",description:`<strong>decoder_attention_mask</strong> (<code>jnp.ndarray</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Default behavior: generate a tensor that ignores pad tokens in <code>decoder_input_ids</code>. Causal mask will also
be used by default.`,name:"decoder_attention_mask"},{anchor:"transformers.FlaxVisionEncoderDecoderModel.__call__.decoder_position_ids",description:`<strong>decoder_position_ids</strong> (<code>jnp.ndarray</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Indices of positions of each decoder input sequence tokens in the position embeddings. Selected in the
range <code>[0, config.decoder.max_position_embeddings - 1]</code>.`,name:"decoder_position_ids"},{anchor:"transformers.FlaxVisionEncoderDecoderModel.__call__.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.FlaxVisionEncoderDecoderModel.__call__.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.FlaxVisionEncoderDecoderModel.__call__.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
If set to <code>True</code>, the model will return a <code>~utils.FlaxSeq2SeqLMOutput</code> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/vision_encoder_decoder/modeling_flax_vision_encoder_decoder.py#L599",returnDescription:`
<p>A <a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_flax_outputs.FlaxSeq2SeqLMOutput"
>transformers.modeling_flax_outputs.FlaxSeq2SeqLMOutput</a> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderConfig"
>VisionEncoderDecoderConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>logits</strong> (<code>jnp.ndarray</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) \u2014 Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).</p>
</li>
<li>
<p><strong>past_key_values</strong> (<code>tuple(tuple(jnp.ndarray))</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) \u2014 Tuple of <code>tuple(jnp.ndarray)</code> of length <code>config.n_layers</code>, with each tuple having 2 tensors of shape
<code>(batch_size, num_heads, sequence_length, embed_size_per_head)</code>) and 2 additional tensors of shape
<code>(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)</code>.</p>
<p>Contains pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
blocks) that can be used (see <code>past_key_values</code> input) to speed up sequential decoding.</p>
</li>
<li>
<p><strong>decoder_hidden_states</strong> (<code>tuple(jnp.ndarray)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>jnp.ndarray</code> (one for the output of the embeddings + one for the output of each layer) of shape
<code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the decoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>decoder_attentions</strong> (<code>tuple(jnp.ndarray)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>jnp.ndarray</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the decoder, after the attention softmax, used to compute the weighted average in the
self-attention heads.</p>
</li>
<li>
<p><strong>cross_attentions</strong> (<code>tuple(jnp.ndarray)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>jnp.ndarray</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the decoder\u2019s cross-attention layer, after the attention softmax, used to compute the
weighted average in the cross-attention heads.</p>
</li>
<li>
<p><strong>encoder_last_hidden_state</strong> (<code>jnp.ndarray</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) \u2014 Sequence of hidden-states at the output of the last layer of the encoder of the model.</p>
</li>
<li>
<p><strong>encoder_hidden_states</strong> (<code>tuple(jnp.ndarray)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>jnp.ndarray</code> (one for the output of the embeddings + one for the output of each layer) of shape
<code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the encoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>encoder_attentions</strong> (<code>tuple(jnp.ndarray)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>jnp.ndarray</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the encoder, after the attention softmax, used to compute the weighted average in the
self-attention heads.</p>
</li>
</ul>
`,returnType:`
<p><a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_flax_outputs.FlaxSeq2SeqLMOutput"
>transformers.modeling_flax_outputs.FlaxSeq2SeqLMOutput</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),Ue=new Oc({props:{$$slots:{default:[rh]},$$scope:{ctx:P}}}),Ze=new mn({props:{anchor:"transformers.FlaxVisionEncoderDecoderModel.__call__.example",$$slots:{default:[ah]},$$scope:{ctx:P}}}),rn=new H({props:{name:"from_encoder_decoder_pretrained",anchor:"transformers.FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained",parameters:[{name:"encoder_pretrained_model_name_or_path",val:": typing.Union[str, os.PathLike, NoneType] = None"},{name:"decoder_pretrained_model_name_or_path",val:": typing.Union[str, os.PathLike, NoneType] = None"},{name:"*model_args",val:""},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained.encoder_pretrained_model_name_or_path",description:`<strong>encoder_pretrained_model_name_or_path</strong> (<code>Union[str, os.PathLike]</code>, <em>optional</em>) &#x2014;
Information necessary to initiate the encoder. Can be either:</p>
<ul>
<li>A string, the <em>model id</em> of a pretrained model hosted inside a model repo on huggingface.co. An
example is <code>google/vit-base-patch16-224-in21k</code>.</li>
<li>A path to a <em>directory</em> containing model weights saved using
<a href="/docs/transformers/main/en/main_classes/model#transformers.FlaxPreTrainedModel.save_pretrained">save_pretrained()</a>, e.g., <code>./my_model_directory/</code>.</li>
</ul>`,name:"encoder_pretrained_model_name_or_path"},{anchor:"transformers.FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained.decoder_pretrained_model_name_or_path",description:`<strong>decoder_pretrained_model_name_or_path</strong> (<code>Union[str, os.PathLike]</code>, <em>optional</em>, defaults to <code>None</code>) &#x2014;
Information necessary to initiate the decoder. Can be either:</p>
<ul>
<li>A string, the <em>model id</em> of a pretrained model hosted inside a model repo on huggingface.co.
Valid model ids can be located at the root-level, like <code>bert-base-uncased</code>, or namespaced under a
user or organization name, like <code>dbmdz/bert-base-german-cased</code>.</li>
<li>A path to a <em>directory</em> containing model weights saved using
<a href="/docs/transformers/main/en/main_classes/model#transformers.FlaxPreTrainedModel.save_pretrained">save_pretrained()</a>, e.g., <code>./my_model_directory/</code>.</li>
</ul>`,name:"decoder_pretrained_model_name_or_path"},{anchor:"transformers.FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained.model_args",description:`<strong>model_args</strong> (remaining positional arguments, <em>optional</em>) &#x2014;
All remaning positional arguments will be passed to the underlying model&#x2019;s <code>__init__</code> method.`,name:"model_args"},{anchor:"transformers.FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained.kwargs",description:`<strong>kwargs</strong> (remaining dictionary of keyword arguments, <em>optional</em>) &#x2014;
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
<code>output_attentions=True</code>).</p>
<ul>
<li>To update the encoder configuration, use the prefix <em>encoder_</em> for each configuration parameter.</li>
<li>To update the decoder configuration, use the prefix <em>decoder_</em> for each configuration parameter.</li>
<li>To update the parent model configuration, do not use a prefix for each configuration parameter.</li>
</ul>
<p>Behaves differently depending on whether a <code>config</code> is provided or automatically loaded.`,name:"kwargs"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/vision_encoder_decoder/modeling_flax_vision_encoder_decoder.py#L724"}}),Ye=new mn({props:{anchor:"transformers.FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained.example",$$slots:{default:[sh]},$$scope:{ctx:P}}}),{c(){h=a("meta"),$=c(),_=a("h1"),f=a("a"),v=a("span"),b(d.$$.fragment),u=c(),S=a("span"),qa=t("Vision Encoder Decoder Models"),Er=c(),te=a("h2"),Ee=a("a"),ft=a("span"),b(no.$$.fragment),Pa=c(),gt=a("span"),za=t("Overview"),kr=c(),x=a("p"),Fa=t("The "),fn=a("a"),Aa=t("VisionEncoderDecoderModel"),Ca=t(` can be used to initialize an image-to-text model with any
pretrained Transformer-based vision model as the encoder (`),ut=a("em"),Ia=t("e.g."),Sa=c(),gn=a("a"),La=t("ViT"),Oa=t(", "),un=a("a"),Na=t("BEiT"),Ra=t(", "),_n=a("a"),Ba=t("DeiT"),Ga=t(", "),vn=a("a"),Wa=t("Swin"),Ha=t(`)
and any pretrained language model as the decoder (`),_t=a("em"),Ua=t("e.g."),Za=c(),bn=a("a"),Ya=t("RoBERTa"),Ja=t(", "),wn=a("a"),Ka=t("GPT2"),Qa=t(", "),Tn=a("a"),Xa=t("BERT"),es=t(", "),yn=a("a"),os=t("DistilBERT"),ns=t(")."),$r=c(),ke=a("p"),ts=t(`The effectiveness of initializing image-to-text-sequence models with pretrained checkpoints has been shown in (for
example) `),to=a("a"),rs=t("TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models"),as=t(` by Minghao Li, Tengchao Lv, Lei Cui, Yijuan Lu, Dinei Florencio, Cha Zhang,
Zhoujun Li, Furu Wei.`),xr=c(),$e=a("p"),ss=t("After such a "),En=a("a"),is=t("VisionEncoderDecoderModel"),ds=t(` has been trained/fine-tuned, it can be saved/loaded just like any other models (see the examples below
for more information).`),jr=c(),J=a("p"),ls=t(`An example application is image captioning, in which the encoder is used to encode the image, after which an autoregressive language model generates
the caption. Another example is optical character recognition. Refer to `),kn=a("a"),cs=t("TrOCR"),ps=t(", which is an instance of "),$n=a("a"),ms=t("VisionEncoderDecoderModel"),hs=t("."),Mr=c(),re=a("h2"),xe=a("a"),vt=a("span"),b(ro.$$.fragment),fs=c(),ao=a("span"),gs=t("Randomly initializing "),bt=a("code"),us=t("VisionEncoderDecoderModel"),_s=t(" from model configurations."),Dr=c(),Z=a("p"),xn=a("a"),vs=t("VisionEncoderDecoderModel"),bs=t(" can be randomly initialized from an encoder and a decoder config. In the following example, we show how to do this using the default "),jn=a("a"),ws=t("ViTModel"),Ts=t(` configuration for the encoder
and the default `),wt=a("code"),ys=t("BertForCausalLM"),Es=t(" configuration for the decoder."),Vr=c(),b(so.$$.fragment),qr=c(),ae=a("h2"),je=a("a"),Tt=a("span"),b(io.$$.fragment),ks=c(),lo=a("span"),$s=t("Initialising "),yt=a("code"),xs=t("VisionEncoderDecoderModel"),js=t(" from a pretrained encoder and a pretrained decoder."),Pr=c(),M=a("p"),Mn=a("a"),Ms=t("VisionEncoderDecoderModel"),Ds=t(" can be initialized from a pretrained encoder checkpoint and a pretrained decoder checkpoint. Note that any pretrained Transformer-based vision model, "),Et=a("em"),Vs=t("e.g."),qs=c(),Dn=a("a"),Ps=t("Swin"),zs=t(", can serve as the encoder and both pretrained auto-encoding models, "),kt=a("em"),Fs=t("e.g."),As=t(" BERT, pretrained causal language models, "),$t=a("em"),Cs=t("e.g."),Is=t(" GPT2, as well as the pretrained decoder part of sequence-to-sequence models, "),xt=a("em"),Ss=t("e.g."),Ls=t(` decoder of BART, can be used as the decoder.
Depending on which architecture you choose as the decoder, the cross-attention layers might be randomly initialized.
Initializing `),Vn=a("a"),Os=t("VisionEncoderDecoderModel"),Ns=t(" from a pretrained encoder and decoder checkpoint requires the model to be fine-tuned on a downstream task, as has been shown in "),Me=a("a"),Rs=t("the "),jt=a("em"),Bs=t("Warm-starting-encoder-decoder blog post"),Gs=t(`.
To do so, the `),Mt=a("code"),Ws=t("VisionEncoderDecoderModel"),Hs=t(" class provides a "),qn=a("a"),Us=t("VisionEncoderDecoderModel.from_encoder_decoder_pretrained()"),Zs=t(" method."),zr=c(),b(co.$$.fragment),Fr=c(),se=a("h2"),De=a("a"),Dt=a("span"),b(po.$$.fragment),Ys=c(),mo=a("span"),Js=t("Loading an existing "),Vt=a("code"),Ks=t("VisionEncoderDecoderModel"),Qs=t(" checkpoint and perform inference."),Ar=c(),L=a("p"),Xs=t("To load fine-tuned checkpoints of the "),qt=a("code"),ei=t("VisionEncoderDecoderModel"),oi=t(" class, "),Pn=a("a"),ni=t("VisionEncoderDecoderModel"),ti=t(" provides the "),Pt=a("code"),ri=t("from_pretrained(...)"),ai=t(" method just like any other model architecture in Transformers."),Cr=c(),Ve=a("p"),si=t("To perform inference, one uses the "),zt=a("code"),ii=t("generate"),di=t(" method, which allows to autoregressively generate text. This method supports various forms of decoding, such as greedy, beam search and multinomial sampling."),Ir=c(),b(ho.$$.fragment),Sr=c(),ie=a("h2"),qe=a("a"),Ft=a("span"),b(fo.$$.fragment),li=c(),go=a("span"),ci=t("Loading a PyTorch checkpoint into "),At=a("code"),pi=t("TFVisionEncoderDecoderModel"),mi=t("."),Lr=c(),de=a("p"),Ct=a("code"),hi=t("TFVisionEncoderDecoderModel.from_pretrained()"),fi=t(` currently doesn\u2019t support initializing the model from a
PyTorch checkpoint. Passing `),It=a("code"),gi=t("from_pt=True"),ui=t(` to this method will throw an exception. If there are only PyTorch
checkpoints for a particular vision encoder-decoder model, a workaround is:`),Or=c(),b(uo.$$.fragment),Nr=c(),le=a("h2"),Pe=a("a"),St=a("span"),b(_o.$$.fragment),_i=c(),Lt=a("span"),vi=t("Training"),Rr=c(),O=a("p"),bi=t(`Once the model is created, it can be fine-tuned similar to BART, T5 or any other encoder-decoder model on a dataset of (image, text) pairs.
As you can see, only 2 inputs are required for the model in order to compute a loss: `),Ot=a("code"),wi=t("pixel_values"),Ti=t(` (which are the
images) and `),Nt=a("code"),yi=t("labels"),Ei=t(" (which are the "),Rt=a("code"),ki=t("input_ids"),$i=t(" of the encoded target sequence)."),Br=c(),b(vo.$$.fragment),Gr=c(),K=a("p"),xi=t("This model was contributed by "),bo=a("a"),ji=t("nielsr"),Mi=t(`. This model\u2019s TensorFlow and Flax versions
were contributed by `),wo=a("a"),Di=t("ydshieh"),Vi=t("."),Wr=c(),ce=a("h2"),ze=a("a"),Bt=a("span"),b(To.$$.fragment),qi=c(),Gt=a("span"),Pi=t("VisionEncoderDecoderConfig"),Hr=c(),I=a("div"),b(yo.$$.fragment),zi=c(),Fe=a("p"),zn=a("a"),Fi=t("VisionEncoderDecoderConfig"),Ai=t(` is the configuration class to store the configuration of a
`),Fn=a("a"),Ci=t("VisionEncoderDecoderModel"),Ii=t(`. It is used to instantiate a Vision-Encoder-Text-Decoder model according to the
specified arguments, defining the encoder and decoder configs.`),Si=c(),pe=a("p"),Li=t("Configuration objects inherit from "),An=a("a"),Oi=t("PretrainedConfig"),Ni=t(` and can be used to control the model outputs. Read the
documentation from `),Cn=a("a"),Ri=t("PretrainedConfig"),Bi=t(" for more information."),Gi=c(),b(Ae.$$.fragment),Wi=c(),Ce=a("div"),b(Eo.$$.fragment),Hi=c(),ko=a("p"),Ui=t("Instantiate a "),In=a("a"),Zi=t("VisionEncoderDecoderConfig"),Yi=t(` (or a derived class) from a pre-trained encoder model
configuration and decoder model configuration.`),Ji=c(),Ie=a("div"),b($o.$$.fragment),Ki=c(),me=a("p"),Qi=t("Serializes this instance to a Python dictionary. Override the default "),Wt=a("em"),Xi=t("to_dict()"),ed=t(" from "),Ht=a("em"),od=t("PretrainedConfig"),nd=t("."),Ur=c(),he=a("h2"),Se=a("a"),Ut=a("span"),b(xo.$$.fragment),td=c(),Zt=a("span"),rd=t("VisionEncoderDecoderModel"),Zr=c(),D=a("div"),b(jo.$$.fragment),ad=c(),fe=a("p"),sd=t(`This class can be used to initialize an image-to-text-sequence model with any pretrained vision autoencoding model
as the encoder and any pretrained text autoregressive model as the decoder. The encoder is loaded via
`),Sn=a("a"),id=t("from_pretrained()"),dd=t(" function and the decoder is loaded via "),Ln=a("a"),ld=t("from_pretrained()"),cd=t(`
function. Cross-attention layers are automatically added to the decoder and should be fine-tuned on a downstream
generative task, like image captioning.`),pd=c(),Mo=a("p"),md=t(`The effectiveness of initializing sequence-to-sequence models with pretrained checkpoints for sequence generation
tasks was shown in `),Do=a("a"),hd=t(`Leveraging Pre-trained Checkpoints for Sequence Generation
Tasks`),fd=t(` by Sascha Rothe, Shashi Narayan, Aliaksei Severyn. Michael Matena, Yanqi
Zhou, Wei Li, Peter J. Liu.`),gd=c(),Vo=a("p"),ud=t("Additionally, in "),qo=a("a"),_d=t(`TrOCR: Transformer-based Optical Character Recognition with Pre-trained
Models`),vd=t(` it is shown how leveraging large pretrained vision models for optical
character recognition (OCR) yields a significant performance improvement.`),bd=c(),Yt=a("p"),wd=t(`After such a Vision-Encoder-Text-Decoder model has been trained/fine-tuned, it can be saved/loaded just like any
other models (see the examples for more information).`),Td=c(),Po=a("p"),yd=t("This model inherits from "),On=a("a"),Ed=t("PreTrainedModel"),kd=t(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),$d=c(),zo=a("p"),xd=t("This model is also a PyTorch "),Fo=a("a"),jd=t("torch.nn.Module"),Md=t(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Dd=c(),Q=a("p"),Nn=a("a"),Vd=t("VisionEncoderDecoderModel"),qd=t(` is a generic model class that will be instantiated as a transformer architecture with
one of the base vision model classes of the library as encoder and another one as decoder when created with the
:meth`),Jt=a("em"),Pd=t("~transformers.AutoModel.from_pretrained"),zd=t(` class method for the encoder and
:meth`),Kt=a("em"),Fd=t("~transformers.AutoModelForCausalLM.from_pretrained"),Ad=t(" class method for the decoder."),Cd=c(),N=a("div"),b(Ao.$$.fragment),Id=c(),ge=a("p"),Sd=t("The "),Rn=a("a"),Ld=t("VisionEncoderDecoderModel"),Od=t(" forward method, overrides the "),Qt=a("code"),Nd=t("__call__"),Rd=t(" special method."),Bd=c(),b(Le.$$.fragment),Gd=c(),b(Oe.$$.fragment),Wd=c(),R=a("div"),b(Co.$$.fragment),Hd=c(),Xt=a("p"),Ud=t(`Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.`),Zd=c(),ue=a("p"),Yd=t("The model is set in evaluation mode by default using "),er=a("code"),Jd=t("model.eval()"),Kd=t(` (Dropout modules are deactivated). To train
the model, you need to first set it back in training mode with `),or=a("code"),Qd=t("model.train()"),Xd=t("."),el=c(),b(Ne.$$.fragment),Yr=c(),_e=a("h2"),Re=a("a"),nr=a("span"),b(Io.$$.fragment),ol=c(),tr=a("span"),nl=t("TFVisionEncoderDecoderModel"),Jr=c(),V=a("div"),b(So.$$.fragment),tl=c(),ve=a("p"),rl=t(`This class can be used to initialize an image-to-text-sequence model with any pretrained vision autoencoding model
as the encoder and any pretrained text autoregressive model as the decoder. The encoder is loaded via
`),Bn=a("a"),al=t("from_pretrained()"),sl=t(" function and the decoder is loaded via "),Gn=a("a"),il=t("from_pretrained()"),dl=t(`
function. Cross-attention layers are automatically added to the decoder and should be fine-tuned on a downstream
generative task, like image captioning.`),ll=c(),Lo=a("p"),cl=t(`The effectiveness of initializing sequence-to-sequence models with pretrained checkpoints for sequence generation
tasks was shown in `),Oo=a("a"),pl=t(`Leveraging Pre-trained Checkpoints for Sequence Generation
Tasks`),ml=t(` by Sascha Rothe, Shashi Narayan, Aliaksei Severyn. Michael Matena, Yanqi
Zhou, Wei Li, Peter J. Liu.`),hl=c(),No=a("p"),fl=t("Additionally, in "),Ro=a("a"),gl=t(`TrOCR: Transformer-based Optical Character Recognition with Pre-trained
Models`),ul=t(` it is shown how leveraging large pretrained vision models for optical
character recognition (OCR) yields a significant performance improvement.`),_l=c(),rr=a("p"),vl=t(`After such a Vision-Encoder-Text-Decoder model has been trained/fine-tuned, it can be saved/loaded just like any
other models (see the examples for more information).`),bl=c(),Bo=a("p"),wl=t("This model inherits from "),Wn=a("a"),Tl=t("TFPreTrainedModel"),yl=t(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),El=c(),Go=a("p"),kl=t("This model is also a "),Wo=a("a"),$l=t("tf.keras.Model"),xl=t(` subclass. Use it
as a regular TF 2.0 Keras Model and refer to the TF 2.0 documentation for all matter related to general usage and
behavior.`),jl=c(),X=a("p"),Hn=a("a"),Ml=t("TFVisionEncoderDecoderModel"),Dl=t(` is a generic model class that will be instantiated as a transformer architecture
with one of the base vision model classes of the library as encoder and another one of the base model classes as
decoder when created with the `),Un=a("a"),Vl=t("from_pretrained()"),ql=t(` class method for the encoder and
`),Zn=a("a"),Pl=t("from_pretrained()"),zl=t(" class method for the decoder."),Fl=c(),B=a("div"),b(Ho.$$.fragment),Al=c(),be=a("p"),Cl=t("The "),Yn=a("a"),Il=t("TFVisionEncoderDecoderModel"),Sl=t(" forward method, overrides the "),ar=a("code"),Ll=t("__call__"),Ol=t(" special method."),Nl=c(),b(Be.$$.fragment),Rl=c(),b(Ge.$$.fragment),Bl=c(),ee=a("div"),b(Uo.$$.fragment),Gl=c(),sr=a("p"),Wl=t(`Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.`),Hl=c(),b(We.$$.fragment),Kr=c(),we=a("h2"),He=a("a"),ir=a("span"),b(Zo.$$.fragment),Ul=c(),dr=a("span"),Zl=t("FlaxVisionEncoderDecoderModel"),Qr=c(),q=a("div"),b(Yo.$$.fragment),Yl=c(),Te=a("p"),Jl=t(`This class can be used to initialize an image-to-text-sequence model with any pretrained vision autoencoding model
as the encoder and any pretrained text autoregressive model as the decoder. The encoder is loaded via
`),Jn=a("a"),Kl=t("from_pretrained()"),Ql=t(" function and the decoder is loaded via "),Kn=a("a"),Xl=t("from_pretrained()"),ec=t(`
function. Cross-attention layers are automatically added to the decoder and should be fine-tuned on a downstream
generative task, like image captioning.`),oc=c(),Jo=a("p"),nc=t(`The effectiveness of initializing sequence-to-sequence models with pretrained checkpoints for sequence generation
tasks was shown in `),Ko=a("a"),tc=t(`Leveraging Pre-trained Checkpoints for Sequence Generation
Tasks`),rc=t(` by Sascha Rothe, Shashi Narayan, Aliaksei Severyn. Michael Matena, Yanqi
Zhou, Wei Li, Peter J. Liu.`),ac=c(),Qo=a("p"),sc=t("Additionally, in "),Xo=a("a"),ic=t(`TrOCR: Transformer-based Optical Character Recognition with Pre-trained
Models`),dc=t(` it is shown how leveraging large pretrained vision models for optical
character recognition (OCR) yields a significant performance improvement.`),lc=c(),lr=a("p"),cc=t(`After such a Vision-Encoder-Text-Decoder model has been trained/fine-tuned, it can be saved/loaded just like any
other models (see the examples for more information).`),pc=c(),en=a("p"),mc=t("This model inherits from "),Qn=a("a"),hc=t("FlaxPreTrainedModel"),fc=t(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),gc=c(),on=a("p"),uc=t(`This model is also a Flax Linen
`),nn=a("a"),_c=t("flax.nn.Module"),vc=t(` subclass. Use it as a
regular Flax Module and refer to the Flax documentation for all matter related to general usage and behavior.`),bc=c(),oe=a("p"),Xn=a("a"),wc=t("FlaxVisionEncoderDecoderModel"),Tc=t(` 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`),cr=a("em"),yc=t("~transformers.FlaxAutoModel.from_pretrained"),Ec=t(` class method
for the encoder and :meth`),pr=a("em"),kc=t("~transformers.FlaxAutoModelForCausalLM.from_pretrained"),$c=t(" class method for the decoder."),xc=c(),G=a("div"),b(tn.$$.fragment),jc=c(),ye=a("p"),Mc=t("The "),et=a("a"),Dc=t("FlaxVisionEncoderDecoderModel"),Vc=t(" forward method, overrides the "),mr=a("code"),qc=t("__call__"),Pc=t(" special method."),zc=c(),b(Ue.$$.fragment),Fc=c(),b(Ze.$$.fragment),Ac=c(),ne=a("div"),b(rn.$$.fragment),Cc=c(),hr=a("p"),Ic=t(`Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.`),Sc=c(),b(Ye.$$.fragment),this.h()},l(o){const m=Ym('[data-svelte="svelte-1phssyn"]',document.head);h=s(m,"META",{name:!0,content:!0}),m.forEach(n),$=p(o),_=s(o,"H1",{class:!0});var an=i(_);f=s(an,"A",{id:!0,class:!0,href:!0});var fr=i(f);v=s(fr,"SPAN",{});var gr=i(v);w(d.$$.fragment,gr),gr.forEach(n),fr.forEach(n),u=p(an),S=s(an,"SPAN",{});var ur=i(S);qa=r(ur,"Vision Encoder Decoder Models"),ur.forEach(n),an.forEach(n),Er=p(o),te=s(o,"H2",{class:!0});var sn=i(te);Ee=s(sn,"A",{id:!0,class:!0,href:!0});var _r=i(Ee);ft=s(_r,"SPAN",{});var vr=i(ft);w(no.$$.fragment,vr),vr.forEach(n),_r.forEach(n),Pa=p(sn),gt=s(sn,"SPAN",{});var br=i(gt);za=r(br,"Overview"),br.forEach(n),sn.forEach(n),kr=p(o),x=s(o,"P",{});var j=i(x);Fa=r(j,"The "),fn=s(j,"A",{href:!0});var wr=i(fn);Aa=r(wr,"VisionEncoderDecoderModel"),wr.forEach(n),Ca=r(j,` can be used to initialize an image-to-text model with any
pretrained Transformer-based vision model as the encoder (`),ut=s(j,"EM",{});var Nc=i(ut);Ia=r(Nc,"e.g."),Nc.forEach(n),Sa=p(j),gn=s(j,"A",{href:!0});var Rc=i(gn);La=r(Rc,"ViT"),Rc.forEach(n),Oa=r(j,", "),un=s(j,"A",{href:!0});var Bc=i(un);Na=r(Bc,"BEiT"),Bc.forEach(n),Ra=r(j,", "),_n=s(j,"A",{href:!0});var Gc=i(_n);Ba=r(Gc,"DeiT"),Gc.forEach(n),Ga=r(j,", "),vn=s(j,"A",{href:!0});var Wc=i(vn);Wa=r(Wc,"Swin"),Wc.forEach(n),Ha=r(j,`)
and any pretrained language model as the decoder (`),_t=s(j,"EM",{});var Hc=i(_t);Ua=r(Hc,"e.g."),Hc.forEach(n),Za=p(j),bn=s(j,"A",{href:!0});var Uc=i(bn);Ya=r(Uc,"RoBERTa"),Uc.forEach(n),Ja=r(j,", "),wn=s(j,"A",{href:!0});var Zc=i(wn);Ka=r(Zc,"GPT2"),Zc.forEach(n),Qa=r(j,", "),Tn=s(j,"A",{href:!0});var Yc=i(Tn);Xa=r(Yc,"BERT"),Yc.forEach(n),es=r(j,", "),yn=s(j,"A",{href:!0});var Jc=i(yn);os=r(Jc,"DistilBERT"),Jc.forEach(n),ns=r(j,")."),j.forEach(n),$r=p(o),ke=s(o,"P",{});var ea=i(ke);ts=r(ea,`The effectiveness of initializing image-to-text-sequence models with pretrained checkpoints has been shown in (for
example) `),to=s(ea,"A",{href:!0,rel:!0});var Kc=i(to);rs=r(Kc,"TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models"),Kc.forEach(n),as=r(ea,` by Minghao Li, Tengchao Lv, Lei Cui, Yijuan Lu, Dinei Florencio, Cha Zhang,
Zhoujun Li, Furu Wei.`),ea.forEach(n),xr=p(o),$e=s(o,"P",{});var oa=i($e);ss=r(oa,"After such a "),En=s(oa,"A",{href:!0});var Qc=i(En);is=r(Qc,"VisionEncoderDecoderModel"),Qc.forEach(n),ds=r(oa,` has been trained/fine-tuned, it can be saved/loaded just like any other models (see the examples below
for more information).`),oa.forEach(n),jr=p(o),J=s(o,"P",{});var ot=i(J);ls=r(ot,`An example application is image captioning, in which the encoder is used to encode the image, after which an autoregressive language model generates
the caption. Another example is optical character recognition. Refer to `),kn=s(ot,"A",{href:!0});var Xc=i(kn);cs=r(Xc,"TrOCR"),Xc.forEach(n),ps=r(ot,", which is an instance of "),$n=s(ot,"A",{href:!0});var ep=i($n);ms=r(ep,"VisionEncoderDecoderModel"),ep.forEach(n),hs=r(ot,"."),ot.forEach(n),Mr=p(o),re=s(o,"H2",{class:!0});var na=i(re);xe=s(na,"A",{id:!0,class:!0,href:!0});var op=i(xe);vt=s(op,"SPAN",{});var np=i(vt);w(ro.$$.fragment,np),np.forEach(n),op.forEach(n),fs=p(na),ao=s(na,"SPAN",{});var ta=i(ao);gs=r(ta,"Randomly initializing "),bt=s(ta,"CODE",{});var tp=i(bt);us=r(tp,"VisionEncoderDecoderModel"),tp.forEach(n),_s=r(ta," from model configurations."),ta.forEach(n),na.forEach(n),Dr=p(o),Z=s(o,"P",{});var dn=i(Z);xn=s(dn,"A",{href:!0});var rp=i(xn);vs=r(rp,"VisionEncoderDecoderModel"),rp.forEach(n),bs=r(dn," can be randomly initialized from an encoder and a decoder config. In the following example, we show how to do this using the default "),jn=s(dn,"A",{href:!0});var ap=i(jn);ws=r(ap,"ViTModel"),ap.forEach(n),Ts=r(dn,` configuration for the encoder
and the default `),wt=s(dn,"CODE",{});var sp=i(wt);ys=r(sp,"BertForCausalLM"),sp.forEach(n),Es=r(dn," configuration for the decoder."),dn.forEach(n),Vr=p(o),w(so.$$.fragment,o),qr=p(o),ae=s(o,"H2",{class:!0});var ra=i(ae);je=s(ra,"A",{id:!0,class:!0,href:!0});var ip=i(je);Tt=s(ip,"SPAN",{});var dp=i(Tt);w(io.$$.fragment,dp),dp.forEach(n),ip.forEach(n),ks=p(ra),lo=s(ra,"SPAN",{});var aa=i(lo);$s=r(aa,"Initialising "),yt=s(aa,"CODE",{});var lp=i(yt);xs=r(lp,"VisionEncoderDecoderModel"),lp.forEach(n),js=r(aa," from a pretrained encoder and a pretrained decoder."),aa.forEach(n),ra.forEach(n),Pr=p(o),M=s(o,"P",{});var z=i(M);Mn=s(z,"A",{href:!0});var cp=i(Mn);Ms=r(cp,"VisionEncoderDecoderModel"),cp.forEach(n),Ds=r(z," can be initialized from a pretrained encoder checkpoint and a pretrained decoder checkpoint. Note that any pretrained Transformer-based vision model, "),Et=s(z,"EM",{});var pp=i(Et);Vs=r(pp,"e.g."),pp.forEach(n),qs=p(z),Dn=s(z,"A",{href:!0});var mp=i(Dn);Ps=r(mp,"Swin"),mp.forEach(n),zs=r(z,", can serve as the encoder and both pretrained auto-encoding models, "),kt=s(z,"EM",{});var hp=i(kt);Fs=r(hp,"e.g."),hp.forEach(n),As=r(z," BERT, pretrained causal language models, "),$t=s(z,"EM",{});var fp=i($t);Cs=r(fp,"e.g."),fp.forEach(n),Is=r(z," GPT2, as well as the pretrained decoder part of sequence-to-sequence models, "),xt=s(z,"EM",{});var gp=i(xt);Ss=r(gp,"e.g."),gp.forEach(n),Ls=r(z,` decoder of BART, can be used as the decoder.
Depending on which architecture you choose as the decoder, the cross-attention layers might be randomly initialized.
Initializing `),Vn=s(z,"A",{href:!0});var up=i(Vn);Os=r(up,"VisionEncoderDecoderModel"),up.forEach(n),Ns=r(z," from a pretrained encoder and decoder checkpoint requires the model to be fine-tuned on a downstream task, as has been shown in "),Me=s(z,"A",{href:!0,rel:!0});var Lc=i(Me);Rs=r(Lc,"the "),jt=s(Lc,"EM",{});var _p=i(jt);Bs=r(_p,"Warm-starting-encoder-decoder blog post"),_p.forEach(n),Lc.forEach(n),Gs=r(z,`.
To do so, the `),Mt=s(z,"CODE",{});var vp=i(Mt);Ws=r(vp,"VisionEncoderDecoderModel"),vp.forEach(n),Hs=r(z," class provides a "),qn=s(z,"A",{href:!0});var bp=i(qn);Us=r(bp,"VisionEncoderDecoderModel.from_encoder_decoder_pretrained()"),bp.forEach(n),Zs=r(z," method."),z.forEach(n),zr=p(o),w(co.$$.fragment,o),Fr=p(o),se=s(o,"H2",{class:!0});var sa=i(se);De=s(sa,"A",{id:!0,class:!0,href:!0});var wp=i(De);Dt=s(wp,"SPAN",{});var Tp=i(Dt);w(po.$$.fragment,Tp),Tp.forEach(n),wp.forEach(n),Ys=p(sa),mo=s(sa,"SPAN",{});var ia=i(mo);Js=r(ia,"Loading an existing "),Vt=s(ia,"CODE",{});var yp=i(Vt);Ks=r(yp,"VisionEncoderDecoderModel"),yp.forEach(n),Qs=r(ia," checkpoint and perform inference."),ia.forEach(n),sa.forEach(n),Ar=p(o),L=s(o,"P",{});var Je=i(L);Xs=r(Je,"To load fine-tuned checkpoints of the "),qt=s(Je,"CODE",{});var Ep=i(qt);ei=r(Ep,"VisionEncoderDecoderModel"),Ep.forEach(n),oi=r(Je," class, "),Pn=s(Je,"A",{href:!0});var kp=i(Pn);ni=r(kp,"VisionEncoderDecoderModel"),kp.forEach(n),ti=r(Je," provides the "),Pt=s(Je,"CODE",{});var $p=i(Pt);ri=r($p,"from_pretrained(...)"),$p.forEach(n),ai=r(Je," method just like any other model architecture in Transformers."),Je.forEach(n),Cr=p(o),Ve=s(o,"P",{});var da=i(Ve);si=r(da,"To perform inference, one uses the "),zt=s(da,"CODE",{});var xp=i(zt);ii=r(xp,"generate"),xp.forEach(n),di=r(da," method, which allows to autoregressively generate text. This method supports various forms of decoding, such as greedy, beam search and multinomial sampling."),da.forEach(n),Ir=p(o),w(ho.$$.fragment,o),Sr=p(o),ie=s(o,"H2",{class:!0});var la=i(ie);qe=s(la,"A",{id:!0,class:!0,href:!0});var jp=i(qe);Ft=s(jp,"SPAN",{});var Mp=i(Ft);w(fo.$$.fragment,Mp),Mp.forEach(n),jp.forEach(n),li=p(la),go=s(la,"SPAN",{});var ca=i(go);ci=r(ca,"Loading a PyTorch checkpoint into "),At=s(ca,"CODE",{});var Dp=i(At);pi=r(Dp,"TFVisionEncoderDecoderModel"),Dp.forEach(n),mi=r(ca,"."),ca.forEach(n),la.forEach(n),Lr=p(o),de=s(o,"P",{});var Tr=i(de);Ct=s(Tr,"CODE",{});var Vp=i(Ct);hi=r(Vp,"TFVisionEncoderDecoderModel.from_pretrained()"),Vp.forEach(n),fi=r(Tr,` currently doesn\u2019t support initializing the model from a
PyTorch checkpoint. Passing `),It=s(Tr,"CODE",{});var qp=i(It);gi=r(qp,"from_pt=True"),qp.forEach(n),ui=r(Tr,` to this method will throw an exception. If there are only PyTorch
checkpoints for a particular vision encoder-decoder model, a workaround is:`),Tr.forEach(n),Or=p(o),w(uo.$$.fragment,o),Nr=p(o),le=s(o,"H2",{class:!0});var pa=i(le);Pe=s(pa,"A",{id:!0,class:!0,href:!0});var Pp=i(Pe);St=s(Pp,"SPAN",{});var zp=i(St);w(_o.$$.fragment,zp),zp.forEach(n),Pp.forEach(n),_i=p(pa),Lt=s(pa,"SPAN",{});var Fp=i(Lt);vi=r(Fp,"Training"),Fp.forEach(n),pa.forEach(n),Rr=p(o),O=s(o,"P",{});var Ke=i(O);bi=r(Ke,`Once the model is created, it can be fine-tuned similar to BART, T5 or any other encoder-decoder model on a dataset of (image, text) pairs.
As you can see, only 2 inputs are required for the model in order to compute a loss: `),Ot=s(Ke,"CODE",{});var Ap=i(Ot);wi=r(Ap,"pixel_values"),Ap.forEach(n),Ti=r(Ke,` (which are the
images) and `),Nt=s(Ke,"CODE",{});var Cp=i(Nt);yi=r(Cp,"labels"),Cp.forEach(n),Ei=r(Ke," (which are the "),Rt=s(Ke,"CODE",{});var Ip=i(Rt);ki=r(Ip,"input_ids"),Ip.forEach(n),$i=r(Ke," of the encoded target sequence)."),Ke.forEach(n),Br=p(o),w(vo.$$.fragment,o),Gr=p(o),K=s(o,"P",{});var nt=i(K);xi=r(nt,"This model was contributed by "),bo=s(nt,"A",{href:!0,rel:!0});var Sp=i(bo);ji=r(Sp,"nielsr"),Sp.forEach(n),Mi=r(nt,`. This model\u2019s TensorFlow and Flax versions
were contributed by `),wo=s(nt,"A",{href:!0,rel:!0});var Lp=i(wo);Di=r(Lp,"ydshieh"),Lp.forEach(n),Vi=r(nt,"."),nt.forEach(n),Wr=p(o),ce=s(o,"H2",{class:!0});var ma=i(ce);ze=s(ma,"A",{id:!0,class:!0,href:!0});var Op=i(ze);Bt=s(Op,"SPAN",{});var Np=i(Bt);w(To.$$.fragment,Np),Np.forEach(n),Op.forEach(n),qi=p(ma),Gt=s(ma,"SPAN",{});var Rp=i(Gt);Pi=r(Rp,"VisionEncoderDecoderConfig"),Rp.forEach(n),ma.forEach(n),Hr=p(o),I=s(o,"DIV",{class:!0});var W=i(I);w(yo.$$.fragment,W),zi=p(W),Fe=s(W,"P",{});var yr=i(Fe);zn=s(yr,"A",{href:!0});var Bp=i(zn);Fi=r(Bp,"VisionEncoderDecoderConfig"),Bp.forEach(n),Ai=r(yr,` is the configuration class to store the configuration of a
`),Fn=s(yr,"A",{href:!0});var Gp=i(Fn);Ci=r(Gp,"VisionEncoderDecoderModel"),Gp.forEach(n),Ii=r(yr,`. It is used to instantiate a Vision-Encoder-Text-Decoder model according to the
specified arguments, defining the encoder and decoder configs.`),yr.forEach(n),Si=p(W),pe=s(W,"P",{});var tt=i(pe);Li=r(tt,"Configuration objects inherit from "),An=s(tt,"A",{href:!0});var Wp=i(An);Oi=r(Wp,"PretrainedConfig"),Wp.forEach(n),Ni=r(tt,` and can be used to control the model outputs. Read the
documentation from `),Cn=s(tt,"A",{href:!0});var Hp=i(Cn);Ri=r(Hp,"PretrainedConfig"),Hp.forEach(n),Bi=r(tt," for more information."),tt.forEach(n),Gi=p(W),w(Ae.$$.fragment,W),Wi=p(W),Ce=s(W,"DIV",{class:!0});var ha=i(Ce);w(Eo.$$.fragment,ha),Hi=p(ha),ko=s(ha,"P",{});var fa=i(ko);Ui=r(fa,"Instantiate a "),In=s(fa,"A",{href:!0});var Up=i(In);Zi=r(Up,"VisionEncoderDecoderConfig"),Up.forEach(n),Yi=r(fa,` (or a derived class) from a pre-trained encoder model
configuration and decoder model configuration.`),fa.forEach(n),ha.forEach(n),Ji=p(W),Ie=s(W,"DIV",{class:!0});var ga=i(Ie);w($o.$$.fragment,ga),Ki=p(ga),me=s(ga,"P",{});var rt=i(me);Qi=r(rt,"Serializes this instance to a Python dictionary. Override the default "),Wt=s(rt,"EM",{});var Zp=i(Wt);Xi=r(Zp,"to_dict()"),Zp.forEach(n),ed=r(rt," from "),Ht=s(rt,"EM",{});var Yp=i(Ht);od=r(Yp,"PretrainedConfig"),Yp.forEach(n),nd=r(rt,"."),rt.forEach(n),ga.forEach(n),W.forEach(n),Ur=p(o),he=s(o,"H2",{class:!0});var ua=i(he);Se=s(ua,"A",{id:!0,class:!0,href:!0});var Jp=i(Se);Ut=s(Jp,"SPAN",{});var Kp=i(Ut);w(xo.$$.fragment,Kp),Kp.forEach(n),Jp.forEach(n),td=p(ua),Zt=s(ua,"SPAN",{});var Qp=i(Zt);rd=r(Qp,"VisionEncoderDecoderModel"),Qp.forEach(n),ua.forEach(n),Zr=p(o),D=s(o,"DIV",{class:!0});var F=i(D);w(jo.$$.fragment,F),ad=p(F),fe=s(F,"P",{});var at=i(fe);sd=r(at,`This class can be used to initialize an image-to-text-sequence model with any pretrained vision autoencoding model
as the encoder and any pretrained text autoregressive model as the decoder. The encoder is loaded via
`),Sn=s(at,"A",{href:!0});var Xp=i(Sn);id=r(Xp,"from_pretrained()"),Xp.forEach(n),dd=r(at," function and the decoder is loaded via "),Ln=s(at,"A",{href:!0});var em=i(Ln);ld=r(em,"from_pretrained()"),em.forEach(n),cd=r(at,`
function. Cross-attention layers are automatically added to the decoder and should be fine-tuned on a downstream
generative task, like image captioning.`),at.forEach(n),pd=p(F),Mo=s(F,"P",{});var _a=i(Mo);md=r(_a,`The effectiveness of initializing sequence-to-sequence models with pretrained checkpoints for sequence generation
tasks was shown in `),Do=s(_a,"A",{href:!0,rel:!0});var om=i(Do);hd=r(om,`Leveraging Pre-trained Checkpoints for Sequence Generation
Tasks`),om.forEach(n),fd=r(_a,` by Sascha Rothe, Shashi Narayan, Aliaksei Severyn. Michael Matena, Yanqi
Zhou, Wei Li, Peter J. Liu.`),_a.forEach(n),gd=p(F),Vo=s(F,"P",{});var va=i(Vo);ud=r(va,"Additionally, in "),qo=s(va,"A",{href:!0,rel:!0});var nm=i(qo);_d=r(nm,`TrOCR: Transformer-based Optical Character Recognition with Pre-trained
Models`),nm.forEach(n),vd=r(va,` it is shown how leveraging large pretrained vision models for optical
character recognition (OCR) yields a significant performance improvement.`),va.forEach(n),bd=p(F),Yt=s(F,"P",{});var tm=i(Yt);wd=r(tm,`After such a Vision-Encoder-Text-Decoder model has been trained/fine-tuned, it can be saved/loaded just like any
other models (see the examples for more information).`),tm.forEach(n),Td=p(F),Po=s(F,"P",{});var ba=i(Po);yd=r(ba,"This model inherits from "),On=s(ba,"A",{href:!0});var rm=i(On);Ed=r(rm,"PreTrainedModel"),rm.forEach(n),kd=r(ba,`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),ba.forEach(n),$d=p(F),zo=s(F,"P",{});var wa=i(zo);xd=r(wa,"This model is also a PyTorch "),Fo=s(wa,"A",{href:!0,rel:!0});var am=i(Fo);jd=r(am,"torch.nn.Module"),am.forEach(n),Md=r(wa,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),wa.forEach(n),Dd=p(F),Q=s(F,"P",{});var ln=i(Q);Nn=s(ln,"A",{href:!0});var sm=i(Nn);Vd=r(sm,"VisionEncoderDecoderModel"),sm.forEach(n),qd=r(ln,` is a generic model class that will be instantiated as a transformer architecture with
one of the base vision model classes of the library as encoder and another one as decoder when created with the
:meth`),Jt=s(ln,"EM",{});var im=i(Jt);Pd=r(im,"~transformers.AutoModel.from_pretrained"),im.forEach(n),zd=r(ln,` class method for the encoder and
:meth`),Kt=s(ln,"EM",{});var dm=i(Kt);Fd=r(dm,"~transformers.AutoModelForCausalLM.from_pretrained"),dm.forEach(n),Ad=r(ln," class method for the decoder."),ln.forEach(n),Cd=p(F),N=s(F,"DIV",{class:!0});var Qe=i(N);w(Ao.$$.fragment,Qe),Id=p(Qe),ge=s(Qe,"P",{});var st=i(ge);Sd=r(st,"The "),Rn=s(st,"A",{href:!0});var lm=i(Rn);Ld=r(lm,"VisionEncoderDecoderModel"),lm.forEach(n),Od=r(st," forward method, overrides the "),Qt=s(st,"CODE",{});var cm=i(Qt);Nd=r(cm,"__call__"),cm.forEach(n),Rd=r(st," special method."),st.forEach(n),Bd=p(Qe),w(Le.$$.fragment,Qe),Gd=p(Qe),w(Oe.$$.fragment,Qe),Qe.forEach(n),Wd=p(F),R=s(F,"DIV",{class:!0});var Xe=i(R);w(Co.$$.fragment,Xe),Hd=p(Xe),Xt=s(Xe,"P",{});var pm=i(Xt);Ud=r(pm,`Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.`),pm.forEach(n),Zd=p(Xe),ue=s(Xe,"P",{});var it=i(ue);Yd=r(it,"The model is set in evaluation mode by default using "),er=s(it,"CODE",{});var mm=i(er);Jd=r(mm,"model.eval()"),mm.forEach(n),Kd=r(it,` (Dropout modules are deactivated). To train
the model, you need to first set it back in training mode with `),or=s(it,"CODE",{});var hm=i(or);Qd=r(hm,"model.train()"),hm.forEach(n),Xd=r(it,"."),it.forEach(n),el=p(Xe),w(Ne.$$.fragment,Xe),Xe.forEach(n),F.forEach(n),Yr=p(o),_e=s(o,"H2",{class:!0});var Ta=i(_e);Re=s(Ta,"A",{id:!0,class:!0,href:!0});var fm=i(Re);nr=s(fm,"SPAN",{});var gm=i(nr);w(Io.$$.fragment,gm),gm.forEach(n),fm.forEach(n),ol=p(Ta),tr=s(Ta,"SPAN",{});var um=i(tr);nl=r(um,"TFVisionEncoderDecoderModel"),um.forEach(n),Ta.forEach(n),Jr=p(o),V=s(o,"DIV",{class:!0});var A=i(V);w(So.$$.fragment,A),tl=p(A),ve=s(A,"P",{});var dt=i(ve);rl=r(dt,`This class can be used to initialize an image-to-text-sequence model with any pretrained vision autoencoding model
as the encoder and any pretrained text autoregressive model as the decoder. The encoder is loaded via
`),Bn=s(dt,"A",{href:!0});var _m=i(Bn);al=r(_m,"from_pretrained()"),_m.forEach(n),sl=r(dt," function and the decoder is loaded via "),Gn=s(dt,"A",{href:!0});var vm=i(Gn);il=r(vm,"from_pretrained()"),vm.forEach(n),dl=r(dt,`
function. Cross-attention layers are automatically added to the decoder and should be fine-tuned on a downstream
generative task, like image captioning.`),dt.forEach(n),ll=p(A),Lo=s(A,"P",{});var ya=i(Lo);cl=r(ya,`The effectiveness of initializing sequence-to-sequence models with pretrained checkpoints for sequence generation
tasks was shown in `),Oo=s(ya,"A",{href:!0,rel:!0});var bm=i(Oo);pl=r(bm,`Leveraging Pre-trained Checkpoints for Sequence Generation
Tasks`),bm.forEach(n),ml=r(ya,` by Sascha Rothe, Shashi Narayan, Aliaksei Severyn. Michael Matena, Yanqi
Zhou, Wei Li, Peter J. Liu.`),ya.forEach(n),hl=p(A),No=s(A,"P",{});var Ea=i(No);fl=r(Ea,"Additionally, in "),Ro=s(Ea,"A",{href:!0,rel:!0});var wm=i(Ro);gl=r(wm,`TrOCR: Transformer-based Optical Character Recognition with Pre-trained
Models`),wm.forEach(n),ul=r(Ea,` it is shown how leveraging large pretrained vision models for optical
character recognition (OCR) yields a significant performance improvement.`),Ea.forEach(n),_l=p(A),rr=s(A,"P",{});var Tm=i(rr);vl=r(Tm,`After such a Vision-Encoder-Text-Decoder model has been trained/fine-tuned, it can be saved/loaded just like any
other models (see the examples for more information).`),Tm.forEach(n),bl=p(A),Bo=s(A,"P",{});var ka=i(Bo);wl=r(ka,"This model inherits from "),Wn=s(ka,"A",{href:!0});var ym=i(Wn);Tl=r(ym,"TFPreTrainedModel"),ym.forEach(n),yl=r(ka,`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),ka.forEach(n),El=p(A),Go=s(A,"P",{});var $a=i(Go);kl=r($a,"This model is also a "),Wo=s($a,"A",{href:!0,rel:!0});var Em=i(Wo);$l=r(Em,"tf.keras.Model"),Em.forEach(n),xl=r($a,` subclass. Use it
as a regular TF 2.0 Keras Model and refer to the TF 2.0 documentation for all matter related to general usage and
behavior.`),$a.forEach(n),jl=p(A),X=s(A,"P",{});var cn=i(X);Hn=s(cn,"A",{href:!0});var km=i(Hn);Ml=r(km,"TFVisionEncoderDecoderModel"),km.forEach(n),Dl=r(cn,` is a generic model class that will be instantiated as a transformer architecture
with one of the base vision model classes of the library as encoder and another one of the base model classes as
decoder when created with the `),Un=s(cn,"A",{href:!0});var $m=i(Un);Vl=r($m,"from_pretrained()"),$m.forEach(n),ql=r(cn,` class method for the encoder and
`),Zn=s(cn,"A",{href:!0});var xm=i(Zn);Pl=r(xm,"from_pretrained()"),xm.forEach(n),zl=r(cn," class method for the decoder."),cn.forEach(n),Fl=p(A),B=s(A,"DIV",{class:!0});var eo=i(B);w(Ho.$$.fragment,eo),Al=p(eo),be=s(eo,"P",{});var lt=i(be);Cl=r(lt,"The "),Yn=s(lt,"A",{href:!0});var jm=i(Yn);Il=r(jm,"TFVisionEncoderDecoderModel"),jm.forEach(n),Sl=r(lt," forward method, overrides the "),ar=s(lt,"CODE",{});var Mm=i(ar);Ll=r(Mm,"__call__"),Mm.forEach(n),Ol=r(lt," special method."),lt.forEach(n),Nl=p(eo),w(Be.$$.fragment,eo),Rl=p(eo),w(Ge.$$.fragment,eo),eo.forEach(n),Bl=p(A),ee=s(A,"DIV",{class:!0});var ct=i(ee);w(Uo.$$.fragment,ct),Gl=p(ct),sr=s(ct,"P",{});var Dm=i(sr);Wl=r(Dm,`Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.`),Dm.forEach(n),Hl=p(ct),w(We.$$.fragment,ct),ct.forEach(n),A.forEach(n),Kr=p(o),we=s(o,"H2",{class:!0});var xa=i(we);He=s(xa,"A",{id:!0,class:!0,href:!0});var Vm=i(He);ir=s(Vm,"SPAN",{});var qm=i(ir);w(Zo.$$.fragment,qm),qm.forEach(n),Vm.forEach(n),Ul=p(xa),dr=s(xa,"SPAN",{});var Pm=i(dr);Zl=r(Pm,"FlaxVisionEncoderDecoderModel"),Pm.forEach(n),xa.forEach(n),Qr=p(o),q=s(o,"DIV",{class:!0});var C=i(q);w(Yo.$$.fragment,C),Yl=p(C),Te=s(C,"P",{});var pt=i(Te);Jl=r(pt,`This class can be used to initialize an image-to-text-sequence model with any pretrained vision autoencoding model
as the encoder and any pretrained text autoregressive model as the decoder. The encoder is loaded via
`),Jn=s(pt,"A",{href:!0});var zm=i(Jn);Kl=r(zm,"from_pretrained()"),zm.forEach(n),Ql=r(pt," function and the decoder is loaded via "),Kn=s(pt,"A",{href:!0});var Fm=i(Kn);Xl=r(Fm,"from_pretrained()"),Fm.forEach(n),ec=r(pt,`
function. Cross-attention layers are automatically added to the decoder and should be fine-tuned on a downstream
generative task, like image captioning.`),pt.forEach(n),oc=p(C),Jo=s(C,"P",{});var ja=i(Jo);nc=r(ja,`The effectiveness of initializing sequence-to-sequence models with pretrained checkpoints for sequence generation
tasks was shown in `),Ko=s(ja,"A",{href:!0,rel:!0});var Am=i(Ko);tc=r(Am,`Leveraging Pre-trained Checkpoints for Sequence Generation
Tasks`),Am.forEach(n),rc=r(ja,` by Sascha Rothe, Shashi Narayan, Aliaksei Severyn. Michael Matena, Yanqi
Zhou, Wei Li, Peter J. Liu.`),ja.forEach(n),ac=p(C),Qo=s(C,"P",{});var Ma=i(Qo);sc=r(Ma,"Additionally, in "),Xo=s(Ma,"A",{href:!0,rel:!0});var Cm=i(Xo);ic=r(Cm,`TrOCR: Transformer-based Optical Character Recognition with Pre-trained
Models`),Cm.forEach(n),dc=r(Ma,` it is shown how leveraging large pretrained vision models for optical
character recognition (OCR) yields a significant performance improvement.`),Ma.forEach(n),lc=p(C),lr=s(C,"P",{});var Im=i(lr);cc=r(Im,`After such a Vision-Encoder-Text-Decoder model has been trained/fine-tuned, it can be saved/loaded just like any
other models (see the examples for more information).`),Im.forEach(n),pc=p(C),en=s(C,"P",{});var Da=i(en);mc=r(Da,"This model inherits from "),Qn=s(Da,"A",{href:!0});var Sm=i(Qn);hc=r(Sm,"FlaxPreTrainedModel"),Sm.forEach(n),fc=r(Da,`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),Da.forEach(n),gc=p(C),on=s(C,"P",{});var Va=i(on);uc=r(Va,`This model is also a Flax Linen
`),nn=s(Va,"A",{href:!0,rel:!0});var Lm=i(nn);_c=r(Lm,"flax.nn.Module"),Lm.forEach(n),vc=r(Va,` subclass. Use it as a
regular Flax Module and refer to the Flax documentation for all matter related to general usage and behavior.`),Va.forEach(n),bc=p(C),oe=s(C,"P",{});var pn=i(oe);Xn=s(pn,"A",{href:!0});var Om=i(Xn);wc=r(Om,"FlaxVisionEncoderDecoderModel"),Om.forEach(n),Tc=r(pn,` 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`),cr=s(pn,"EM",{});var Nm=i(cr);yc=r(Nm,"~transformers.FlaxAutoModel.from_pretrained"),Nm.forEach(n),Ec=r(pn,` class method
for the encoder and :meth`),pr=s(pn,"EM",{});var Rm=i(pr);kc=r(Rm,"~transformers.FlaxAutoModelForCausalLM.from_pretrained"),Rm.forEach(n),$c=r(pn," class method for the decoder."),pn.forEach(n),xc=p(C),G=s(C,"DIV",{class:!0});var oo=i(G);w(tn.$$.fragment,oo),jc=p(oo),ye=s(oo,"P",{});var mt=i(ye);Mc=r(mt,"The "),et=s(mt,"A",{href:!0});var Bm=i(et);Dc=r(Bm,"FlaxVisionEncoderDecoderModel"),Bm.forEach(n),Vc=r(mt," forward method, overrides the "),mr=s(mt,"CODE",{});var Gm=i(mr);qc=r(Gm,"__call__"),Gm.forEach(n),Pc=r(mt," special method."),mt.forEach(n),zc=p(oo),w(Ue.$$.fragment,oo),Fc=p(oo),w(Ze.$$.fragment,oo),oo.forEach(n),Ac=p(C),ne=s(C,"DIV",{class:!0});var ht=i(ne);w(rn.$$.fragment,ht),Cc=p(ht),hr=s(ht,"P",{});var Wm=i(hr);Ic=r(Wm,`Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.`),Wm.forEach(n),Sc=p(ht),w(Ye.$$.fragment,ht),ht.forEach(n),C.forEach(n),this.h()},h(){l(h,"name","hf:doc:metadata"),l(h,"content",JSON.stringify(dh)),l(f,"id","vision-encoder-decoder-models"),l(f,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(f,"href","#vision-encoder-decoder-models"),l(_,"class","relative group"),l(Ee,"id","overview"),l(Ee,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(Ee,"href","#overview"),l(te,"class","relative group"),l(fn,"href","/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel"),l(gn,"href","vit"),l(un,"href","beit"),l(_n,"href","deit"),l(vn,"href","swin"),l(bn,"href","roberta"),l(wn,"href","gpt2"),l(Tn,"href","bert"),l(yn,"href","distilbert"),l(to,"href","https://arxiv.org/abs/2109.10282"),l(to,"rel","nofollow"),l(En,"href","/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel"),l(kn,"href","trocr"),l($n,"href","/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel"),l(xe,"id","randomly-initializing-visionencoderdecodermodel-from-model-configurations"),l(xe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(xe,"href","#randomly-initializing-visionencoderdecodermodel-from-model-configurations"),l(re,"class","relative group"),l(xn,"href","/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel"),l(jn,"href","/docs/transformers/main/en/model_doc/vit#transformers.ViTModel"),l(je,"id","initialising-visionencoderdecodermodel-from-a-pretrained-encoder-and-a-pretrained-decoder"),l(je,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(je,"href","#initialising-visionencoderdecodermodel-from-a-pretrained-encoder-and-a-pretrained-decoder"),l(ae,"class","relative group"),l(Mn,"href","/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel"),l(Dn,"href","swin"),l(Vn,"href","/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel"),l(Me,"href","https://huggingface.co/blog/warm-starting-encoder-decoder"),l(Me,"rel","nofollow"),l(qn,"href","/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel.from_encoder_decoder_pretrained"),l(De,"id","loading-an-existing-visionencoderdecodermodel-checkpoint-and-perform-inference"),l(De,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(De,"href","#loading-an-existing-visionencoderdecodermodel-checkpoint-and-perform-inference"),l(se,"class","relative group"),l(Pn,"href","/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel"),l(qe,"id","loading-a-pytorch-checkpoint-into-tfvisionencoderdecodermodel"),l(qe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(qe,"href","#loading-a-pytorch-checkpoint-into-tfvisionencoderdecodermodel"),l(ie,"class","relative group"),l(Pe,"id","training"),l(Pe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(Pe,"href","#training"),l(le,"class","relative group"),l(bo,"href","https://github.com/nielsrogge"),l(bo,"rel","nofollow"),l(wo,"href","https://github.com/ydshieh"),l(wo,"rel","nofollow"),l(ze,"id","transformers.VisionEncoderDecoderConfig"),l(ze,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(ze,"href","#transformers.VisionEncoderDecoderConfig"),l(ce,"class","relative group"),l(zn,"href","/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderConfig"),l(Fn,"href","/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel"),l(An,"href","/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig"),l(Cn,"href","/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig"),l(In,"href","/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderConfig"),l(Ce,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(Ie,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(I,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(Se,"id","transformers.VisionEncoderDecoderModel"),l(Se,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(Se,"href","#transformers.VisionEncoderDecoderModel"),l(he,"class","relative group"),l(Sn,"href","/docs/transformers/main/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained"),l(Ln,"href","/docs/transformers/main/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained"),l(Do,"href","https://arxiv.org/abs/1907.12461"),l(Do,"rel","nofollow"),l(qo,"href","https://arxiv.org/abs/2109.10282"),l(qo,"rel","nofollow"),l(On,"href","/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel"),l(Fo,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),l(Fo,"rel","nofollow"),l(Nn,"href","/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel"),l(Rn,"href","/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel"),l(N,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(R,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(D,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(Re,"id","transformers.TFVisionEncoderDecoderModel"),l(Re,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(Re,"href","#transformers.TFVisionEncoderDecoderModel"),l(_e,"class","relative group"),l(Bn,"href","/docs/transformers/main/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained"),l(Gn,"href","/docs/transformers/main/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained"),l(Oo,"href","https://arxiv.org/abs/1907.12461"),l(Oo,"rel","nofollow"),l(Ro,"href","https://arxiv.org/abs/2109.10282"),l(Ro,"rel","nofollow"),l(Wn,"href","/docs/transformers/main/en/main_classes/model#transformers.TFPreTrainedModel"),l(Wo,"href","https://www.tensorflow.org/api_docs/python/tf/keras/Model"),l(Wo,"rel","nofollow"),l(Hn,"href","/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.TFVisionEncoderDecoderModel"),l(Un,"href","/docs/transformers/main/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained"),l(Zn,"href","/docs/transformers/main/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained"),l(Yn,"href","/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.TFVisionEncoderDecoderModel"),l(B,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(ee,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(V,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(He,"id","transformers.FlaxVisionEncoderDecoderModel"),l(He,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(He,"href","#transformers.FlaxVisionEncoderDecoderModel"),l(we,"class","relative group"),l(Jn,"href","/docs/transformers/main/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained"),l(Kn,"href","/docs/transformers/main/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained"),l(Ko,"href","https://arxiv.org/abs/1907.12461"),l(Ko,"rel","nofollow"),l(Xo,"href","https://arxiv.org/abs/2109.10282"),l(Xo,"rel","nofollow"),l(Qn,"href","/docs/transformers/main/en/main_classes/model#transformers.FlaxPreTrainedModel"),l(nn,"href","https://flax.readthedocs.io/en/latest/_autosummary/flax.nn.module.html"),l(nn,"rel","nofollow"),l(Xn,"href","/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.FlaxVisionEncoderDecoderModel"),l(et,"href","/docs/transformers/main/en/model_doc/vision-encoder-decoder#transformers.FlaxVisionEncoderDecoderModel"),l(G,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(ne,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(q,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(o,m){e(document.head,h),g(o,$,m),g(o,_,m),e(_,f),e(f,v),T(d,v,null),e(_,u),e(_,S),e(S,qa),g(o,Er,m),g(o,te,m),e(te,Ee),e(Ee,ft),T(no,ft,null),e(te,Pa),e(te,gt),e(gt,za),g(o,kr,m),g(o,x,m),e(x,Fa),e(x,fn),e(fn,Aa),e(x,Ca),e(x,ut),e(ut,Ia),e(x,Sa),e(x,gn),e(gn,La),e(x,Oa),e(x,un),e(un,Na),e(x,Ra),e(x,_n),e(_n,Ba),e(x,Ga),e(x,vn),e(vn,Wa),e(x,Ha),e(x,_t),e(_t,Ua),e(x,Za),e(x,bn),e(bn,Ya),e(x,Ja),e(x,wn),e(wn,Ka),e(x,Qa),e(x,Tn),e(Tn,Xa),e(x,es),e(x,yn),e(yn,os),e(x,ns),g(o,$r,m),g(o,ke,m),e(ke,ts),e(ke,to),e(to,rs),e(ke,as),g(o,xr,m),g(o,$e,m),e($e,ss),e($e,En),e(En,is),e($e,ds),g(o,jr,m),g(o,J,m),e(J,ls),e(J,kn),e(kn,cs),e(J,ps),e(J,$n),e($n,ms),e(J,hs),g(o,Mr,m),g(o,re,m),e(re,xe),e(xe,vt),T(ro,vt,null),e(re,fs),e(re,ao),e(ao,gs),e(ao,bt),e(bt,us),e(ao,_s),g(o,Dr,m),g(o,Z,m),e(Z,xn),e(xn,vs),e(Z,bs),e(Z,jn),e(jn,ws),e(Z,Ts),e(Z,wt),e(wt,ys),e(Z,Es),g(o,Vr,m),T(so,o,m),g(o,qr,m),g(o,ae,m),e(ae,je),e(je,Tt),T(io,Tt,null),e(ae,ks),e(ae,lo),e(lo,$s),e(lo,yt),e(yt,xs),e(lo,js),g(o,Pr,m),g(o,M,m),e(M,Mn),e(Mn,Ms),e(M,Ds),e(M,Et),e(Et,Vs),e(M,qs),e(M,Dn),e(Dn,Ps),e(M,zs),e(M,kt),e(kt,Fs),e(M,As),e(M,$t),e($t,Cs),e(M,Is),e(M,xt),e(xt,Ss),e(M,Ls),e(M,Vn),e(Vn,Os),e(M,Ns),e(M,Me),e(Me,Rs),e(Me,jt),e(jt,Bs),e(M,Gs),e(M,Mt),e(Mt,Ws),e(M,Hs),e(M,qn),e(qn,Us),e(M,Zs),g(o,zr,m),T(co,o,m),g(o,Fr,m),g(o,se,m),e(se,De),e(De,Dt),T(po,Dt,null),e(se,Ys),e(se,mo),e(mo,Js),e(mo,Vt),e(Vt,Ks),e(mo,Qs),g(o,Ar,m),g(o,L,m),e(L,Xs),e(L,qt),e(qt,ei),e(L,oi),e(L,Pn),e(Pn,ni),e(L,ti),e(L,Pt),e(Pt,ri),e(L,ai),g(o,Cr,m),g(o,Ve,m),e(Ve,si),e(Ve,zt),e(zt,ii),e(Ve,di),g(o,Ir,m),T(ho,o,m),g(o,Sr,m),g(o,ie,m),e(ie,qe),e(qe,Ft),T(fo,Ft,null),e(ie,li),e(ie,go),e(go,ci),e(go,At),e(At,pi),e(go,mi),g(o,Lr,m),g(o,de,m),e(de,Ct),e(Ct,hi),e(de,fi),e(de,It),e(It,gi),e(de,ui),g(o,Or,m),T(uo,o,m),g(o,Nr,m),g(o,le,m),e(le,Pe),e(Pe,St),T(_o,St,null),e(le,_i),e(le,Lt),e(Lt,vi),g(o,Rr,m),g(o,O,m),e(O,bi),e(O,Ot),e(Ot,wi),e(O,Ti),e(O,Nt),e(Nt,yi),e(O,Ei),e(O,Rt),e(Rt,ki),e(O,$i),g(o,Br,m),T(vo,o,m),g(o,Gr,m),g(o,K,m),e(K,xi),e(K,bo),e(bo,ji),e(K,Mi),e(K,wo),e(wo,Di),e(K,Vi),g(o,Wr,m),g(o,ce,m),e(ce,ze),e(ze,Bt),T(To,Bt,null),e(ce,qi),e(ce,Gt),e(Gt,Pi),g(o,Hr,m),g(o,I,m),T(yo,I,null),e(I,zi),e(I,Fe),e(Fe,zn),e(zn,Fi),e(Fe,Ai),e(Fe,Fn),e(Fn,Ci),e(Fe,Ii),e(I,Si),e(I,pe),e(pe,Li),e(pe,An),e(An,Oi),e(pe,Ni),e(pe,Cn),e(Cn,Ri),e(pe,Bi),e(I,Gi),T(Ae,I,null),e(I,Wi),e(I,Ce),T(Eo,Ce,null),e(Ce,Hi),e(Ce,ko),e(ko,Ui),e(ko,In),e(In,Zi),e(ko,Yi),e(I,Ji),e(I,Ie),T($o,Ie,null),e(Ie,Ki),e(Ie,me),e(me,Qi),e(me,Wt),e(Wt,Xi),e(me,ed),e(me,Ht),e(Ht,od),e(me,nd),g(o,Ur,m),g(o,he,m),e(he,Se),e(Se,Ut),T(xo,Ut,null),e(he,td),e(he,Zt),e(Zt,rd),g(o,Zr,m),g(o,D,m),T(jo,D,null),e(D,ad),e(D,fe),e(fe,sd),e(fe,Sn),e(Sn,id),e(fe,dd),e(fe,Ln),e(Ln,ld),e(fe,cd),e(D,pd),e(D,Mo),e(Mo,md),e(Mo,Do),e(Do,hd),e(Mo,fd),e(D,gd),e(D,Vo),e(Vo,ud),e(Vo,qo),e(qo,_d),e(Vo,vd),e(D,bd),e(D,Yt),e(Yt,wd),e(D,Td),e(D,Po),e(Po,yd),e(Po,On),e(On,Ed),e(Po,kd),e(D,$d),e(D,zo),e(zo,xd),e(zo,Fo),e(Fo,jd),e(zo,Md),e(D,Dd),e(D,Q),e(Q,Nn),e(Nn,Vd),e(Q,qd),e(Q,Jt),e(Jt,Pd),e(Q,zd),e(Q,Kt),e(Kt,Fd),e(Q,Ad),e(D,Cd),e(D,N),T(Ao,N,null),e(N,Id),e(N,ge),e(ge,Sd),e(ge,Rn),e(Rn,Ld),e(ge,Od),e(ge,Qt),e(Qt,Nd),e(ge,Rd),e(N,Bd),T(Le,N,null),e(N,Gd),T(Oe,N,null),e(D,Wd),e(D,R),T(Co,R,null),e(R,Hd),e(R,Xt),e(Xt,Ud),e(R,Zd),e(R,ue),e(ue,Yd),e(ue,er),e(er,Jd),e(ue,Kd),e(ue,or),e(or,Qd),e(ue,Xd),e(R,el),T(Ne,R,null),g(o,Yr,m),g(o,_e,m),e(_e,Re),e(Re,nr),T(Io,nr,null),e(_e,ol),e(_e,tr),e(tr,nl),g(o,Jr,m),g(o,V,m),T(So,V,null),e(V,tl),e(V,ve),e(ve,rl),e(ve,Bn),e(Bn,al),e(ve,sl),e(ve,Gn),e(Gn,il),e(ve,dl),e(V,ll),e(V,Lo),e(Lo,cl),e(Lo,Oo),e(Oo,pl),e(Lo,ml),e(V,hl),e(V,No),e(No,fl),e(No,Ro),e(Ro,gl),e(No,ul),e(V,_l),e(V,rr),e(rr,vl),e(V,bl),e(V,Bo),e(Bo,wl),e(Bo,Wn),e(Wn,Tl),e(Bo,yl),e(V,El),e(V,Go),e(Go,kl),e(Go,Wo),e(Wo,$l),e(Go,xl),e(V,jl),e(V,X),e(X,Hn),e(Hn,Ml),e(X,Dl),e(X,Un),e(Un,Vl),e(X,ql),e(X,Zn),e(Zn,Pl),e(X,zl),e(V,Fl),e(V,B),T(Ho,B,null),e(B,Al),e(B,be),e(be,Cl),e(be,Yn),e(Yn,Il),e(be,Sl),e(be,ar),e(ar,Ll),e(be,Ol),e(B,Nl),T(Be,B,null),e(B,Rl),T(Ge,B,null),e(V,Bl),e(V,ee),T(Uo,ee,null),e(ee,Gl),e(ee,sr),e(sr,Wl),e(ee,Hl),T(We,ee,null),g(o,Kr,m),g(o,we,m),e(we,He),e(He,ir),T(Zo,ir,null),e(we,Ul),e(we,dr),e(dr,Zl),g(o,Qr,m),g(o,q,m),T(Yo,q,null),e(q,Yl),e(q,Te),e(Te,Jl),e(Te,Jn),e(Jn,Kl),e(Te,Ql),e(Te,Kn),e(Kn,Xl),e(Te,ec),e(q,oc),e(q,Jo),e(Jo,nc),e(Jo,Ko),e(Ko,tc),e(Jo,rc),e(q,ac),e(q,Qo),e(Qo,sc),e(Qo,Xo),e(Xo,ic),e(Qo,dc),e(q,lc),e(q,lr),e(lr,cc),e(q,pc),e(q,en),e(en,mc),e(en,Qn),e(Qn,hc),e(en,fc),e(q,gc),e(q,on),e(on,uc),e(on,nn),e(nn,_c),e(on,vc),e(q,bc),e(q,oe),e(oe,Xn),e(Xn,wc),e(oe,Tc),e(oe,cr),e(cr,yc),e(oe,Ec),e(oe,pr),e(pr,kc),e(oe,$c),e(q,xc),e(q,G),T(tn,G,null),e(G,jc),e(G,ye),e(ye,Mc),e(ye,et),e(et,Dc),e(ye,Vc),e(ye,mr),e(mr,qc),e(ye,Pc),e(G,zc),T(Ue,G,null),e(G,Fc),T(Ze,G,null),e(q,Ac),e(q,ne),T(rn,ne,null),e(ne,Cc),e(ne,hr),e(hr,Ic),e(ne,Sc),T(Ye,ne,null),Xr=!0},p(o,[m]){const an={};m&2&&(an.$$scope={dirty:m,ctx:o}),Ae.$set(an);const fr={};m&2&&(fr.$$scope={dirty:m,ctx:o}),Le.$set(fr);const gr={};m&2&&(gr.$$scope={dirty:m,ctx:o}),Oe.$set(gr);const ur={};m&2&&(ur.$$scope={dirty:m,ctx:o}),Ne.$set(ur);const sn={};m&2&&(sn.$$scope={dirty:m,ctx:o}),Be.$set(sn);const _r={};m&2&&(_r.$$scope={dirty:m,ctx:o}),Ge.$set(_r);const vr={};m&2&&(vr.$$scope={dirty:m,ctx:o}),We.$set(vr);const br={};m&2&&(br.$$scope={dirty:m,ctx:o}),Ue.$set(br);const j={};m&2&&(j.$$scope={dirty:m,ctx:o}),Ze.$set(j);const wr={};m&2&&(wr.$$scope={dirty:m,ctx:o}),Ye.$set(wr)},i(o){Xr||(y(d.$$.fragment,o),y(no.$$.fragment,o),y(ro.$$.fragment,o),y(so.$$.fragment,o),y(io.$$.fragment,o),y(co.$$.fragment,o),y(po.$$.fragment,o),y(ho.$$.fragment,o),y(fo.$$.fragment,o),y(uo.$$.fragment,o),y(_o.$$.fragment,o),y(vo.$$.fragment,o),y(To.$$.fragment,o),y(yo.$$.fragment,o),y(Ae.$$.fragment,o),y(Eo.$$.fragment,o),y($o.$$.fragment,o),y(xo.$$.fragment,o),y(jo.$$.fragment,o),y(Ao.$$.fragment,o),y(Le.$$.fragment,o),y(Oe.$$.fragment,o),y(Co.$$.fragment,o),y(Ne.$$.fragment,o),y(Io.$$.fragment,o),y(So.$$.fragment,o),y(Ho.$$.fragment,o),y(Be.$$.fragment,o),y(Ge.$$.fragment,o),y(Uo.$$.fragment,o),y(We.$$.fragment,o),y(Zo.$$.fragment,o),y(Yo.$$.fragment,o),y(tn.$$.fragment,o),y(Ue.$$.fragment,o),y(Ze.$$.fragment,o),y(rn.$$.fragment,o),y(Ye.$$.fragment,o),Xr=!0)},o(o){E(d.$$.fragment,o),E(no.$$.fragment,o),E(ro.$$.fragment,o),E(so.$$.fragment,o),E(io.$$.fragment,o),E(co.$$.fragment,o),E(po.$$.fragment,o),E(ho.$$.fragment,o),E(fo.$$.fragment,o),E(uo.$$.fragment,o),E(_o.$$.fragment,o),E(vo.$$.fragment,o),E(To.$$.fragment,o),E(yo.$$.fragment,o),E(Ae.$$.fragment,o),E(Eo.$$.fragment,o),E($o.$$.fragment,o),E(xo.$$.fragment,o),E(jo.$$.fragment,o),E(Ao.$$.fragment,o),E(Le.$$.fragment,o),E(Oe.$$.fragment,o),E(Co.$$.fragment,o),E(Ne.$$.fragment,o),E(Io.$$.fragment,o),E(So.$$.fragment,o),E(Ho.$$.fragment,o),E(Be.$$.fragment,o),E(Ge.$$.fragment,o),E(Uo.$$.fragment,o),E(We.$$.fragment,o),E(Zo.$$.fragment,o),E(Yo.$$.fragment,o),E(tn.$$.fragment,o),E(Ue.$$.fragment,o),E(Ze.$$.fragment,o),E(rn.$$.fragment,o),E(Ye.$$.fragment,o),Xr=!1},d(o){n(h),o&&n($),o&&n(_),k(d),o&&n(Er),o&&n(te),k(no),o&&n(kr),o&&n(x),o&&n($r),o&&n(ke),o&&n(xr),o&&n($e),o&&n(jr),o&&n(J),o&&n(Mr),o&&n(re),k(ro),o&&n(Dr),o&&n(Z),o&&n(Vr),k(so,o),o&&n(qr),o&&n(ae),k(io),o&&n(Pr),o&&n(M),o&&n(zr),k(co,o),o&&n(Fr),o&&n(se),k(po),o&&n(Ar),o&&n(L),o&&n(Cr),o&&n(Ve),o&&n(Ir),k(ho,o),o&&n(Sr),o&&n(ie),k(fo),o&&n(Lr),o&&n(de),o&&n(Or),k(uo,o),o&&n(Nr),o&&n(le),k(_o),o&&n(Rr),o&&n(O),o&&n(Br),k(vo,o),o&&n(Gr),o&&n(K),o&&n(Wr),o&&n(ce),k(To),o&&n(Hr),o&&n(I),k(yo),k(Ae),k(Eo),k($o),o&&n(Ur),o&&n(he),k(xo),o&&n(Zr),o&&n(D),k(jo),k(Ao),k(Le),k(Oe),k(Co),k(Ne),o&&n(Yr),o&&n(_e),k(Io),o&&n(Jr),o&&n(V),k(So),k(Ho),k(Be),k(Ge),k(Uo),k(We),o&&n(Kr),o&&n(we),k(Zo),o&&n(Qr),o&&n(q),k(Yo),k(tn),k(Ue),k(Ze),k(rn),k(Ye)}}}const dh={local:"vision-encoder-decoder-models",sections:[{local:"overview",title:"Overview"},{local:"randomly-initializing-visionencoderdecodermodel-from-model-configurations",title:"Randomly initializing `VisionEncoderDecoderModel` from model configurations."},{local:"initialising-visionencoderdecodermodel-from-a-pretrained-encoder-and-a-pretrained-decoder",title:"Initialising `VisionEncoderDecoderModel` from a pretrained encoder and a pretrained decoder."},{local:"loading-an-existing-visionencoderdecodermodel-checkpoint-and-perform-inference",title:"Loading an existing `VisionEncoderDecoderModel` checkpoint and perform inference."},{local:"loading-a-pytorch-checkpoint-into-tfvisionencoderdecodermodel",title:"Loading a PyTorch checkpoint into `TFVisionEncoderDecoderModel`."},{local:"training",title:"Training"},{local:"transformers.VisionEncoderDecoderConfig",title:"VisionEncoderDecoderConfig"},{local:"transformers.VisionEncoderDecoderModel",title:"VisionEncoderDecoderModel"},{local:"transformers.TFVisionEncoderDecoderModel",title:"TFVisionEncoderDecoderModel"},{local:"transformers.FlaxVisionEncoderDecoderModel",title:"FlaxVisionEncoderDecoderModel"}],title:"Vision Encoder Decoder Models"};function lh(P){return Jm(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class uh extends Hm{constructor(h){super();Um(this,h,lh,ih,Zm,{})}}export{uh as default,dh as metadata};
