import{S as Wm,i as Hm,s as Zm,e as a,k as c,w as b,t as n,M as Ym,c as s,d as t,m as p,a as d,x as w,h as r,b as l,G as e,g,y,q as T,o as E,B as k,v as Jm,L as mt}from"../../chunks/vendor-hf-doc-builder.js";import{T as Oc}from"../../chunks/Tip-hf-doc-builder.js";import{D as W}from"../../chunks/Docstring-hf-doc-builder.js";import{C as H}from"../../chunks/CodeBlock-hf-doc-builder.js";import{I as Y}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{E as pt}from"../../chunks/ExampleCodeBlock-hf-doc-builder.js";function Km(P){let h,$,_,f,v;return f=new H({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"),$=n("Examples:"),_=c(),b(f.$$.fragment)},l(i){h=s(i,"P",{});var u=d(h);$=r(u,"Examples:"),u.forEach(t),_=p(i),w(f.$$.fragment,i)},m(i,u){g(i,h,u),e(h,$),g(i,_,u),y(f,i,u),v=!0},p:mt,i(i){v||(T(f.$$.fragment,i),v=!0)},o(i){E(f.$$.fragment,i),v=!1},d(i){i&&t(h),i&&t(_),k(f,i)}}}function Qm(P){let h,$,_,f,v;return{c(){h=a("p"),$=n("Although the recipe for forward pass needs to be defined within this function, one should call the "),_=a("code"),f=n("Module"),v=n(`
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(i){h=s(i,"P",{});var u=d(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=d(_);f=r(S,"Module"),S.forEach(t),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(t)},m(i,u){g(i,h,u),e(h,$),e(h,_),e(_,f),e(h,v)},d(i){i&&t(h)}}}function Xm(P){let h,$,_,f,v;return f=new H({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"),$=n("Examples:"),_=c(),b(f.$$.fragment)},l(i){h=s(i,"P",{});var u=d(h);$=r(u,"Examples:"),u.forEach(t),_=p(i),w(f.$$.fragment,i)},m(i,u){g(i,h,u),e(h,$),g(i,_,u),y(f,i,u),v=!0},p:mt,i(i){v||(T(f.$$.fragment,i),v=!0)},o(i){E(f.$$.fragment,i),v=!1},d(i){i&&t(h),i&&t(_),k(f,i)}}}function eh(P){let h,$,_,f,v;return f=new H({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"),$=n("Example:"),_=c(),b(f.$$.fragment)},l(i){h=s(i,"P",{});var u=d(h);$=r(u,"Example:"),u.forEach(t),_=p(i),w(f.$$.fragment,i)},m(i,u){g(i,h,u),e(h,$),g(i,_,u),y(f,i,u),v=!0},p:mt,i(i){v||(T(f.$$.fragment,i),v=!0)},o(i){E(f.$$.fragment,i),v=!1},d(i){i&&t(h),i&&t(_),k(f,i)}}}function oh(P){let h,$,_,f,v;return{c(){h=a("p"),$=n("Although the recipe for forward pass needs to be defined within this function, one should call the "),_=a("code"),f=n("Module"),v=n(`
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(i){h=s(i,"P",{});var u=d(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=d(_);f=r(S,"Module"),S.forEach(t),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(t)},m(i,u){g(i,h,u),e(h,$),e(h,_),e(_,f),e(h,v)},d(i){i&&t(h)}}}function th(P){let h,$,_,f,v;return f=new H({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"),$=n("Examples:"),_=c(),b(f.$$.fragment)},l(i){h=s(i,"P",{});var u=d(h);$=r(u,"Examples:"),u.forEach(t),_=p(i),w(f.$$.fragment,i)},m(i,u){g(i,h,u),e(h,$),g(i,_,u),y(f,i,u),v=!0},p:mt,i(i){v||(T(f.$$.fragment,i),v=!0)},o(i){E(f.$$.fragment,i),v=!1},d(i){i&&t(h),i&&t(_),k(f,i)}}}function nh(P){let h,$,_,f,v;return f=new H({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"),$=n("Example:"),_=c(),b(f.$$.fragment)},l(i){h=s(i,"P",{});var u=d(h);$=r(u,"Example:"),u.forEach(t),_=p(i),w(f.$$.fragment,i)},m(i,u){g(i,h,u),e(h,$),g(i,_,u),y(f,i,u),v=!0},p:mt,i(i){v||(T(f.$$.fragment,i),v=!0)},o(i){E(f.$$.fragment,i),v=!1},d(i){i&&t(h),i&&t(_),k(f,i)}}}function rh(P){let h,$,_,f,v;return{c(){h=a("p"),$=n("Although the recipe for forward pass needs to be defined within this function, one should call the "),_=a("code"),f=n("Module"),v=n(`
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(i){h=s(i,"P",{});var u=d(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=d(_);f=r(S,"Module"),S.forEach(t),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(t)},m(i,u){g(i,h,u),e(h,$),e(h,_),e(_,f),e(h,v)},d(i){i&&t(h)}}}function ah(P){let h,$,_,f,v;return f=new H({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"),$=n("Examples:"),_=c(),b(f.$$.fragment)},l(i){h=s(i,"P",{});var u=d(h);$=r(u,"Examples:"),u.forEach(t),_=p(i),w(f.$$.fragment,i)},m(i,u){g(i,h,u),e(h,$),g(i,_,u),y(f,i,u),v=!0},p:mt,i(i){v||(T(f.$$.fragment,i),v=!0)},o(i){E(f.$$.fragment,i),v=!1},d(i){i&&t(h),i&&t(_),k(f,i)}}}function sh(P){let h,$,_,f,v;return f=new H({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"),$=n("Example:"),_=c(),b(f.$$.fragment)},l(i){h=s(i,"P",{});var u=d(h);$=r(u,"Example:"),u.forEach(t),_=p(i),w(f.$$.fragment,i)},m(i,u){g(i,h,u),e(h,$),g(i,_,u),y(f,i,u),v=!0},p:mt,i(i){v||(T(f.$$.fragment,i),v=!0)},o(i){E(f.$$.fragment,i),v=!1},d(i){i&&t(h),i&&t(_),k(f,i)}}}function dh(P){let h,$,_,f,v,i,u,S,qa,Er,ne,Ee,fn,to,Pa,gn,za,kr,x,Fa,ht,Aa,Ca,un,Ia,Sa,ft,La,Oa,gt,Na,Ra,ut,Ba,Ga,_t,Ua,Wa,_n,Ha,Za,vt,Ya,Ja,bt,Ka,Qa,wt,Xa,es,yt,os,ts,$r,ke,ns,no,rs,as,xr,$e,ss,Tt,ds,is,jr,J,ls,Et,cs,ps,kt,ms,hs,Mr,re,xe,vn,ro,fs,ao,gs,bn,us,_s,Dr,Z,$t,vs,bs,xt,ws,ys,wn,Ts,Es,Vr,so,qr,ae,je,yn,io,ks,lo,$s,Tn,xs,js,Pr,M,jt,Ms,Ds,En,Vs,qs,Mt,Ps,zs,kn,Fs,As,$n,Cs,Is,xn,Ss,Ls,Dt,Os,Ns,Me,Rs,jn,Bs,Gs,Mn,Us,Ws,Vt,Hs,Zs,zr,co,Fr,se,De,Dn,po,Ys,mo,Js,Vn,Ks,Qs,Ar,L,Xs,qn,ed,od,qt,td,nd,Pn,rd,ad,Cr,Ve,sd,zn,dd,id,Ir,ho,Sr,de,qe,Fn,fo,ld,go,cd,An,pd,md,Lr,ie,Cn,hd,fd,In,gd,ud,Or,uo,Nr,le,Pe,Sn,_o,_d,Ln,vd,Rr,O,bd,On,wd,yd,Nn,Td,Ed,Rn,kd,$d,Br,vo,Gr,K,xd,bo,jd,Md,wo,Dd,Vd,Ur,ce,ze,Bn,yo,qd,Gn,Pd,Wr,I,To,zd,Fe,Pt,Fd,Ad,zt,Cd,Id,Sd,pe,Ld,Ft,Od,Nd,At,Rd,Bd,Gd,Ae,Ud,Ce,Eo,Wd,ko,Hd,Ct,Zd,Yd,Jd,Ie,$o,Kd,me,Qd,Un,Xd,ei,Wn,oi,ti,Hr,he,Se,Hn,xo,ni,Zn,ri,Zr,D,jo,ai,fe,si,It,di,ii,St,li,ci,pi,Mo,mi,Do,hi,fi,gi,Vo,ui,qo,_i,vi,bi,Yn,wi,yi,Po,Ti,Lt,Ei,ki,$i,zo,xi,Fo,ji,Mi,Di,Q,Ot,Vi,qi,Jn,Pi,zi,Kn,Fi,Ai,Ci,N,Ao,Ii,ge,Si,Nt,Li,Oi,Qn,Ni,Ri,Bi,Le,Gi,Oe,Ui,R,Co,Wi,Xn,Hi,Zi,ue,Yi,er,Ji,Ki,or,Qi,Xi,el,Ne,Yr,_e,Re,tr,Io,ol,nr,tl,Jr,V,So,nl,ve,rl,Rt,al,sl,Bt,dl,il,ll,Lo,cl,Oo,pl,ml,hl,No,fl,Ro,gl,ul,_l,rr,vl,bl,Bo,wl,Gt,yl,Tl,El,Go,kl,Uo,$l,xl,jl,X,Ut,Ml,Dl,Wt,Vl,ql,Ht,Pl,zl,Fl,B,Wo,Al,be,Cl,Zt,Il,Sl,ar,Ll,Ol,Nl,Be,Rl,Ge,Bl,ee,Ho,Gl,sr,Ul,Wl,Ue,Kr,we,We,dr,Zo,Hl,ir,Zl,Qr,q,Yo,Yl,ye,Jl,Yt,Kl,Ql,Jt,Xl,ec,oc,Jo,tc,Ko,nc,rc,ac,Qo,sc,Xo,dc,ic,lc,lr,cc,pc,et,mc,Kt,hc,fc,gc,ot,uc,tt,_c,vc,bc,oe,Qt,wc,yc,cr,Tc,Ec,pr,kc,$c,xc,G,nt,jc,Te,Mc,Xt,Dc,Vc,mr,qc,Pc,zc,He,Fc,Ze,Ac,te,rt,Cc,hr,Ic,Sc,Ye,Xr;return i=new Y({}),to=new Y({}),ro=new Y({}),so=new H({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 H({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 H({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 H({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 H({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`}}),yo=new Y({}),To=new W({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/v4.29.0/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/v4.29.0/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/v4.29.0/src/transformers/models/vision_encoder_decoder/configuration_vision_encoder_decoder.py#L34"}}),Ae=new pt({props:{anchor:"transformers.VisionEncoderDecoderConfig.example",$$slots:{default:[Km]},$$scope:{ctx:P}}}),Eo=new W({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/v4.29.0/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/v4.29.0/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderConfig"
>VisionEncoderDecoderConfig</a></p>
`}}),$o=new W({props:{name:"to_dict",anchor:"transformers.VisionEncoderDecoderConfig.to_dict",parameters:[],source:"https://github.com/huggingface/transformers/blob/v4.29.0/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 W({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/v4.29.0/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/v4.29.0/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/v4.29.0/src/transformers/models/vision_encoder_decoder/modeling_vision_encoder_decoder.py#L151"}}),Ao=new W({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/v4.29.0/en/model_doc/auto#transformers.AutoImageProcessor">AutoImageProcessor</a>). See <a href="/docs/transformers/v4.29.0/en/model_doc/dpt#transformers.DPTFeatureExtractor.__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/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizer">PreTrainedTokenizer</a>. See <a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.__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/v4.29.0/src/transformers/models/vision_encoder_decoder/modeling_vision_encoder_decoder.py#L519",returnDescription:`
<p>A <a
  href="/docs/transformers/v4.29.0/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/v4.29.0/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/v4.29.0/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 pt({props:{anchor:"transformers.VisionEncoderDecoderModel.forward.example",$$slots:{default:[Xm]},$$scope:{ctx:P}}}),Co=new W({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/v4.29.0/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/v4.29.0/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/v4.29.0/src/transformers/models/vision_encoder_decoder/modeling_vision_encoder_decoder.py#L365"}}),Ne=new pt({props:{anchor:"transformers.VisionEncoderDecoderModel.from_encoder_decoder_pretrained.example",$$slots:{default:[eh]},$$scope:{ctx:P}}}),Io=new Y({}),So=new W({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/v4.29.0/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/v4.29.0/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/v4.29.0/src/transformers/models/vision_encoder_decoder/modeling_tf_vision_encoder_decoder.py#L175"}}),Wo=new W({props:{name:"call",anchor:"transformers.TFVisionEncoderDecoderModel.call",parameters:[{name:"pixel_values",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"decoder_input_ids",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"decoder_attention_mask",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"encoder_outputs",val:": typing.Union[typing.Tuple, transformers.modeling_tf_outputs.TFBaseModelOutput, NoneType] = None"},{name:"past_key_values",val:": typing.Union[typing.Tuple[typing.Tuple[typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor]]], NoneType] = None"},{name:"decoder_inputs_embeds",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = None"},{name:"labels",val:": typing.Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor, NoneType] = 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:"training",val:": bool = 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/v4.29.0/en/model_doc/auto#transformers.AutoImageProcessor">AutoImageProcessor</a>. See <a href="/docs/transformers/v4.29.0/en/model_doc/dpt#transformers.DPTFeatureExtractor.__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/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizer">PreTrainedTokenizer</a>. See <a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.__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/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizer">PreTrainedTokenizer</a>. See <a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and <a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.__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/v4.29.0/src/transformers/models/vision_encoder_decoder/modeling_tf_vision_encoder_decoder.py#L488",returnDescription:`
<p>A <a
  href="/docs/transformers/v4.29.0/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/v4.29.0/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/v4.29.0/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 pt({props:{anchor:"transformers.TFVisionEncoderDecoderModel.call.example",$$slots:{default:[th]},$$scope:{ctx:P}}}),Ho=new W({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/v4.29.0/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/v4.29.0/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/v4.29.0/src/transformers/models/vision_encoder_decoder/modeling_tf_vision_encoder_decoder.py#L340"}}),Ue=new pt({props:{anchor:"transformers.TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained.example",$$slots:{default:[nh]},$$scope:{ctx:P}}}),Zo=new Y({}),Yo=new W({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/v4.29.0/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/v4.29.0/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/v4.29.0/en/main_classes/model#transformers.FlaxPreTrainedModel.to_fp16">to_fp16()</a> and
<a href="/docs/transformers/v4.29.0/en/main_classes/model#transformers.FlaxPreTrainedModel.to_bf16">to_bf16()</a>.`,name:"dtype"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/vision_encoder_decoder/modeling_flax_vision_encoder_decoder.py#L268"}}),nt=new W({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/v4.29.0/en/model_doc/auto#transformers.AutoImageProcessor">AutoImageProcessor</a>. See <a href="/docs/transformers/v4.29.0/en/model_doc/dpt#transformers.DPTFeatureExtractor.__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/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizer">PreTrainedTokenizer</a>. See <a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.__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/v4.29.0/src/transformers/models/vision_encoder_decoder/modeling_flax_vision_encoder_decoder.py#L598",returnDescription:`
<p>A <a
  href="/docs/transformers/v4.29.0/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/v4.29.0/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/v4.29.0/en/main_classes/output#transformers.modeling_flax_outputs.FlaxSeq2SeqLMOutput"
>transformers.modeling_flax_outputs.FlaxSeq2SeqLMOutput</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),He=new Oc({props:{$$slots:{default:[rh]},$$scope:{ctx:P}}}),Ze=new pt({props:{anchor:"transformers.FlaxVisionEncoderDecoderModel.__call__.example",$$slots:{default:[ah]},$$scope:{ctx:P}}}),rt=new W({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/v4.29.0/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/v4.29.0/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/v4.29.0/src/transformers/models/vision_encoder_decoder/modeling_flax_vision_encoder_decoder.py#L723"}}),Ye=new pt({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(i.$$.fragment),u=c(),S=a("span"),qa=n("Vision Encoder Decoder Models"),Er=c(),ne=a("h2"),Ee=a("a"),fn=a("span"),b(to.$$.fragment),Pa=c(),gn=a("span"),za=n("Overview"),kr=c(),x=a("p"),Fa=n("The "),ht=a("a"),Aa=n("VisionEncoderDecoderModel"),Ca=n(` can be used to initialize an image-to-text model with any
pretrained Transformer-based vision model as the encoder (`),un=a("em"),Ia=n("e.g."),Sa=c(),ft=a("a"),La=n("ViT"),Oa=n(", "),gt=a("a"),Na=n("BEiT"),Ra=n(", "),ut=a("a"),Ba=n("DeiT"),Ga=n(", "),_t=a("a"),Ua=n("Swin"),Wa=n(`)
and any pretrained language model as the decoder (`),_n=a("em"),Ha=n("e.g."),Za=c(),vt=a("a"),Ya=n("RoBERTa"),Ja=n(", "),bt=a("a"),Ka=n("GPT2"),Qa=n(", "),wt=a("a"),Xa=n("BERT"),es=n(", "),yt=a("a"),os=n("DistilBERT"),ts=n(")."),$r=c(),ke=a("p"),ns=n(`The effectiveness of initializing image-to-text-sequence models with pretrained checkpoints has been shown in (for
example) `),no=a("a"),rs=n("TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models"),as=n(` by Minghao Li, Tengchao Lv, Lei Cui, Yijuan Lu, Dinei Florencio, Cha Zhang,
Zhoujun Li, Furu Wei.`),xr=c(),$e=a("p"),ss=n("After such a "),Tt=a("a"),ds=n("VisionEncoderDecoderModel"),is=n(` 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=n(`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 `),Et=a("a"),cs=n("TrOCR"),ps=n(", which is an instance of "),kt=a("a"),ms=n("VisionEncoderDecoderModel"),hs=n("."),Mr=c(),re=a("h2"),xe=a("a"),vn=a("span"),b(ro.$$.fragment),fs=c(),ao=a("span"),gs=n("Randomly initializing "),bn=a("code"),us=n("VisionEncoderDecoderModel"),_s=n(" from model configurations."),Dr=c(),Z=a("p"),$t=a("a"),vs=n("VisionEncoderDecoderModel"),bs=n(" can be randomly initialized from an encoder and a decoder config. In the following example, we show how to do this using the default "),xt=a("a"),ws=n("ViTModel"),ys=n(` configuration for the encoder
and the default `),wn=a("code"),Ts=n("BertForCausalLM"),Es=n(" configuration for the decoder."),Vr=c(),b(so.$$.fragment),qr=c(),ae=a("h2"),je=a("a"),yn=a("span"),b(io.$$.fragment),ks=c(),lo=a("span"),$s=n("Initialising "),Tn=a("code"),xs=n("VisionEncoderDecoderModel"),js=n(" from a pretrained encoder and a pretrained decoder."),Pr=c(),M=a("p"),jt=a("a"),Ms=n("VisionEncoderDecoderModel"),Ds=n(" can be initialized from a pretrained encoder checkpoint and a pretrained decoder checkpoint. Note that any pretrained Transformer-based vision model, "),En=a("em"),Vs=n("e.g."),qs=c(),Mt=a("a"),Ps=n("Swin"),zs=n(", can serve as the encoder and both pretrained auto-encoding models, "),kn=a("em"),Fs=n("e.g."),As=n(" BERT, pretrained causal language models, "),$n=a("em"),Cs=n("e.g."),Is=n(" GPT2, as well as the pretrained decoder part of sequence-to-sequence models, "),xn=a("em"),Ss=n("e.g."),Ls=n(` 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 `),Dt=a("a"),Os=n("VisionEncoderDecoderModel"),Ns=n(" 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=n("the "),jn=a("em"),Bs=n("Warm-starting-encoder-decoder blog post"),Gs=n(`.
To do so, the `),Mn=a("code"),Us=n("VisionEncoderDecoderModel"),Ws=n(" class provides a "),Vt=a("a"),Hs=n("VisionEncoderDecoderModel.from_encoder_decoder_pretrained()"),Zs=n(" method."),zr=c(),b(co.$$.fragment),Fr=c(),se=a("h2"),De=a("a"),Dn=a("span"),b(po.$$.fragment),Ys=c(),mo=a("span"),Js=n("Loading an existing "),Vn=a("code"),Ks=n("VisionEncoderDecoderModel"),Qs=n(" checkpoint and perform inference."),Ar=c(),L=a("p"),Xs=n("To load fine-tuned checkpoints of the "),qn=a("code"),ed=n("VisionEncoderDecoderModel"),od=n(" class, "),qt=a("a"),td=n("VisionEncoderDecoderModel"),nd=n(" provides the "),Pn=a("code"),rd=n("from_pretrained(...)"),ad=n(" method just like any other model architecture in Transformers."),Cr=c(),Ve=a("p"),sd=n("To perform inference, one uses the "),zn=a("code"),dd=n("generate"),id=n(" 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(),de=a("h2"),qe=a("a"),Fn=a("span"),b(fo.$$.fragment),ld=c(),go=a("span"),cd=n("Loading a PyTorch checkpoint into "),An=a("code"),pd=n("TFVisionEncoderDecoderModel"),md=n("."),Lr=c(),ie=a("p"),Cn=a("code"),hd=n("TFVisionEncoderDecoderModel.from_pretrained()"),fd=n(` currently doesn\u2019t support initializing the model from a
PyTorch checkpoint. Passing `),In=a("code"),gd=n("from_pt=True"),ud=n(` 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"),Sn=a("span"),b(_o.$$.fragment),_d=c(),Ln=a("span"),vd=n("Training"),Rr=c(),O=a("p"),bd=n(`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: `),On=a("code"),wd=n("pixel_values"),yd=n(` (which are the
images) and `),Nn=a("code"),Td=n("labels"),Ed=n(" (which are the "),Rn=a("code"),kd=n("input_ids"),$d=n(" of the encoded target sequence)."),Br=c(),b(vo.$$.fragment),Gr=c(),K=a("p"),xd=n("This model was contributed by "),bo=a("a"),jd=n("nielsr"),Md=n(`. This model\u2019s TensorFlow and Flax versions
were contributed by `),wo=a("a"),Dd=n("ydshieh"),Vd=n("."),Ur=c(),ce=a("h2"),ze=a("a"),Bn=a("span"),b(yo.$$.fragment),qd=c(),Gn=a("span"),Pd=n("VisionEncoderDecoderConfig"),Wr=c(),I=a("div"),b(To.$$.fragment),zd=c(),Fe=a("p"),Pt=a("a"),Fd=n("VisionEncoderDecoderConfig"),Ad=n(` is the configuration class to store the configuration of a
`),zt=a("a"),Cd=n("VisionEncoderDecoderModel"),Id=n(`. It is used to instantiate a Vision-Encoder-Text-Decoder model according to the
specified arguments, defining the encoder and decoder configs.`),Sd=c(),pe=a("p"),Ld=n("Configuration objects inherit from "),Ft=a("a"),Od=n("PretrainedConfig"),Nd=n(` and can be used to control the model outputs. Read the
documentation from `),At=a("a"),Rd=n("PretrainedConfig"),Bd=n(" for more information."),Gd=c(),b(Ae.$$.fragment),Ud=c(),Ce=a("div"),b(Eo.$$.fragment),Wd=c(),ko=a("p"),Hd=n("Instantiate a "),Ct=a("a"),Zd=n("VisionEncoderDecoderConfig"),Yd=n(` (or a derived class) from a pre-trained encoder model
configuration and decoder model configuration.`),Jd=c(),Ie=a("div"),b($o.$$.fragment),Kd=c(),me=a("p"),Qd=n("Serializes this instance to a Python dictionary. Override the default "),Un=a("em"),Xd=n("to_dict()"),ei=n(" from "),Wn=a("em"),oi=n("PretrainedConfig"),ti=n("."),Hr=c(),he=a("h2"),Se=a("a"),Hn=a("span"),b(xo.$$.fragment),ni=c(),Zn=a("span"),ri=n("VisionEncoderDecoderModel"),Zr=c(),D=a("div"),b(jo.$$.fragment),ai=c(),fe=a("p"),si=n(`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
`),It=a("a"),di=n("from_pretrained()"),ii=n(" function and the decoder is loaded via "),St=a("a"),li=n("from_pretrained()"),ci=n(`
function. Cross-attention layers are automatically added to the decoder and should be fine-tuned on a downstream
generative task, like image captioning.`),pi=c(),Mo=a("p"),mi=n(`The effectiveness of initializing sequence-to-sequence models with pretrained checkpoints for sequence generation
tasks was shown in `),Do=a("a"),hi=n(`Leveraging Pre-trained Checkpoints for Sequence Generation
Tasks`),fi=n(` by Sascha Rothe, Shashi Narayan, Aliaksei Severyn. Michael Matena, Yanqi
Zhou, Wei Li, Peter J. Liu.`),gi=c(),Vo=a("p"),ui=n("Additionally, in "),qo=a("a"),_i=n(`TrOCR: Transformer-based Optical Character Recognition with Pre-trained
Models`),vi=n(` it is shown how leveraging large pretrained vision models for optical
character recognition (OCR) yields a significant performance improvement.`),bi=c(),Yn=a("p"),wi=n(`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).`),yi=c(),Po=a("p"),Ti=n("This model inherits from "),Lt=a("a"),Ei=n("PreTrainedModel"),ki=n(`. 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.)`),$i=c(),zo=a("p"),xi=n("This model is also a PyTorch "),Fo=a("a"),ji=n("torch.nn.Module"),Mi=n(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Di=c(),Q=a("p"),Ot=a("a"),Vi=n("VisionEncoderDecoderModel"),qi=n(` 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`),Jn=a("em"),Pi=n("~transformers.AutoModel.from_pretrained"),zi=n(` class method for the encoder and
:meth`),Kn=a("em"),Fi=n("~transformers.AutoModelForCausalLM.from_pretrained"),Ai=n(" class method for the decoder."),Ci=c(),N=a("div"),b(Ao.$$.fragment),Ii=c(),ge=a("p"),Si=n("The "),Nt=a("a"),Li=n("VisionEncoderDecoderModel"),Oi=n(" forward method, overrides the "),Qn=a("code"),Ni=n("__call__"),Ri=n(" special method."),Bi=c(),b(Le.$$.fragment),Gi=c(),b(Oe.$$.fragment),Ui=c(),R=a("div"),b(Co.$$.fragment),Wi=c(),Xn=a("p"),Hi=n(`Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.`),Zi=c(),ue=a("p"),Yi=n("The model is set in evaluation mode by default using "),er=a("code"),Ji=n("model.eval()"),Ki=n(` (Dropout modules are deactivated). To train
the model, you need to first set it back in training mode with `),or=a("code"),Qi=n("model.train()"),Xi=n("."),el=c(),b(Ne.$$.fragment),Yr=c(),_e=a("h2"),Re=a("a"),tr=a("span"),b(Io.$$.fragment),ol=c(),nr=a("span"),tl=n("TFVisionEncoderDecoderModel"),Jr=c(),V=a("div"),b(So.$$.fragment),nl=c(),ve=a("p"),rl=n(`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
`),Rt=a("a"),al=n("from_pretrained()"),sl=n(" function and the decoder is loaded via "),Bt=a("a"),dl=n("from_pretrained()"),il=n(`
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=n(`The effectiveness of initializing sequence-to-sequence models with pretrained checkpoints for sequence generation
tasks was shown in `),Oo=a("a"),pl=n(`Leveraging Pre-trained Checkpoints for Sequence Generation
Tasks`),ml=n(` by Sascha Rothe, Shashi Narayan, Aliaksei Severyn. Michael Matena, Yanqi
Zhou, Wei Li, Peter J. Liu.`),hl=c(),No=a("p"),fl=n("Additionally, in "),Ro=a("a"),gl=n(`TrOCR: Transformer-based Optical Character Recognition with Pre-trained
Models`),ul=n(` 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=n(`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=n("This model inherits from "),Gt=a("a"),yl=n("TFPreTrainedModel"),Tl=n(`. 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=n("This model is also a "),Uo=a("a"),$l=n("tf.keras.Model"),xl=n(` 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"),Ut=a("a"),Ml=n("TFVisionEncoderDecoderModel"),Dl=n(` 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 `),Wt=a("a"),Vl=n("from_pretrained()"),ql=n(` class method for the encoder and
`),Ht=a("a"),Pl=n("from_pretrained()"),zl=n(" class method for the decoder."),Fl=c(),B=a("div"),b(Wo.$$.fragment),Al=c(),be=a("p"),Cl=n("The "),Zt=a("a"),Il=n("TFVisionEncoderDecoderModel"),Sl=n(" forward method, overrides the "),ar=a("code"),Ll=n("__call__"),Ol=n(" special method."),Nl=c(),b(Be.$$.fragment),Rl=c(),b(Ge.$$.fragment),Bl=c(),ee=a("div"),b(Ho.$$.fragment),Gl=c(),sr=a("p"),Ul=n(`Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.`),Wl=c(),b(Ue.$$.fragment),Kr=c(),we=a("h2"),We=a("a"),dr=a("span"),b(Zo.$$.fragment),Hl=c(),ir=a("span"),Zl=n("FlaxVisionEncoderDecoderModel"),Qr=c(),q=a("div"),b(Yo.$$.fragment),Yl=c(),ye=a("p"),Jl=n(`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
`),Yt=a("a"),Kl=n("from_pretrained()"),Ql=n(" function and the decoder is loaded via "),Jt=a("a"),Xl=n("from_pretrained()"),ec=n(`
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"),tc=n(`The effectiveness of initializing sequence-to-sequence models with pretrained checkpoints for sequence generation
tasks was shown in `),Ko=a("a"),nc=n(`Leveraging Pre-trained Checkpoints for Sequence Generation
Tasks`),rc=n(` by Sascha Rothe, Shashi Narayan, Aliaksei Severyn. Michael Matena, Yanqi
Zhou, Wei Li, Peter J. Liu.`),ac=c(),Qo=a("p"),sc=n("Additionally, in "),Xo=a("a"),dc=n(`TrOCR: Transformer-based Optical Character Recognition with Pre-trained
Models`),ic=n(` 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=n(`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(),et=a("p"),mc=n("This model inherits from "),Kt=a("a"),hc=n("FlaxPreTrainedModel"),fc=n(`. 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(),ot=a("p"),uc=n(`This model is also a Flax Linen
`),tt=a("a"),_c=n("flax.nn.Module"),vc=n(` 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"),Qt=a("a"),wc=n("FlaxVisionEncoderDecoderModel"),yc=n(` 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"),Tc=n("~transformers.FlaxAutoModel.from_pretrained"),Ec=n(` class method
for the encoder and :meth`),pr=a("em"),kc=n("~transformers.FlaxAutoModelForCausalLM.from_pretrained"),$c=n(" class method for the decoder."),xc=c(),G=a("div"),b(nt.$$.fragment),jc=c(),Te=a("p"),Mc=n("The "),Xt=a("a"),Dc=n("FlaxVisionEncoderDecoderModel"),Vc=n(" forward method, overrides the "),mr=a("code"),qc=n("__call__"),Pc=n(" special method."),zc=c(),b(He.$$.fragment),Fc=c(),b(Ze.$$.fragment),Ac=c(),te=a("div"),b(rt.$$.fragment),Cc=c(),hr=a("p"),Ic=n(`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(t),$=p(o),_=s(o,"H1",{class:!0});var at=d(_);f=s(at,"A",{id:!0,class:!0,href:!0});var fr=d(f);v=s(fr,"SPAN",{});var gr=d(v);w(i.$$.fragment,gr),gr.forEach(t),fr.forEach(t),u=p(at),S=s(at,"SPAN",{});var ur=d(S);qa=r(ur,"Vision Encoder Decoder Models"),ur.forEach(t),at.forEach(t),Er=p(o),ne=s(o,"H2",{class:!0});var st=d(ne);Ee=s(st,"A",{id:!0,class:!0,href:!0});var _r=d(Ee);fn=s(_r,"SPAN",{});var vr=d(fn);w(to.$$.fragment,vr),vr.forEach(t),_r.forEach(t),Pa=p(st),gn=s(st,"SPAN",{});var br=d(gn);za=r(br,"Overview"),br.forEach(t),st.forEach(t),kr=p(o),x=s(o,"P",{});var j=d(x);Fa=r(j,"The "),ht=s(j,"A",{href:!0});var wr=d(ht);Aa=r(wr,"VisionEncoderDecoderModel"),wr.forEach(t),Ca=r(j,` can be used to initialize an image-to-text model with any
pretrained Transformer-based vision model as the encoder (`),un=s(j,"EM",{});var Nc=d(un);Ia=r(Nc,"e.g."),Nc.forEach(t),Sa=p(j),ft=s(j,"A",{href:!0});var Rc=d(ft);La=r(Rc,"ViT"),Rc.forEach(t),Oa=r(j,", "),gt=s(j,"A",{href:!0});var Bc=d(gt);Na=r(Bc,"BEiT"),Bc.forEach(t),Ra=r(j,", "),ut=s(j,"A",{href:!0});var Gc=d(ut);Ba=r(Gc,"DeiT"),Gc.forEach(t),Ga=r(j,", "),_t=s(j,"A",{href:!0});var Uc=d(_t);Ua=r(Uc,"Swin"),Uc.forEach(t),Wa=r(j,`)
and any pretrained language model as the decoder (`),_n=s(j,"EM",{});var Wc=d(_n);Ha=r(Wc,"e.g."),Wc.forEach(t),Za=p(j),vt=s(j,"A",{href:!0});var Hc=d(vt);Ya=r(Hc,"RoBERTa"),Hc.forEach(t),Ja=r(j,", "),bt=s(j,"A",{href:!0});var Zc=d(bt);Ka=r(Zc,"GPT2"),Zc.forEach(t),Qa=r(j,", "),wt=s(j,"A",{href:!0});var Yc=d(wt);Xa=r(Yc,"BERT"),Yc.forEach(t),es=r(j,", "),yt=s(j,"A",{href:!0});var Jc=d(yt);os=r(Jc,"DistilBERT"),Jc.forEach(t),ts=r(j,")."),j.forEach(t),$r=p(o),ke=s(o,"P",{});var ea=d(ke);ns=r(ea,`The effectiveness of initializing image-to-text-sequence models with pretrained checkpoints has been shown in (for
example) `),no=s(ea,"A",{href:!0,rel:!0});var Kc=d(no);rs=r(Kc,"TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models"),Kc.forEach(t),as=r(ea,` by Minghao Li, Tengchao Lv, Lei Cui, Yijuan Lu, Dinei Florencio, Cha Zhang,
Zhoujun Li, Furu Wei.`),ea.forEach(t),xr=p(o),$e=s(o,"P",{});var oa=d($e);ss=r(oa,"After such a "),Tt=s(oa,"A",{href:!0});var Qc=d(Tt);ds=r(Qc,"VisionEncoderDecoderModel"),Qc.forEach(t),is=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(t),jr=p(o),J=s(o,"P",{});var en=d(J);ls=r(en,`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 `),Et=s(en,"A",{href:!0});var Xc=d(Et);cs=r(Xc,"TrOCR"),Xc.forEach(t),ps=r(en,", which is an instance of "),kt=s(en,"A",{href:!0});var ep=d(kt);ms=r(ep,"VisionEncoderDecoderModel"),ep.forEach(t),hs=r(en,"."),en.forEach(t),Mr=p(o),re=s(o,"H2",{class:!0});var ta=d(re);xe=s(ta,"A",{id:!0,class:!0,href:!0});var op=d(xe);vn=s(op,"SPAN",{});var tp=d(vn);w(ro.$$.fragment,tp),tp.forEach(t),op.forEach(t),fs=p(ta),ao=s(ta,"SPAN",{});var na=d(ao);gs=r(na,"Randomly initializing "),bn=s(na,"CODE",{});var np=d(bn);us=r(np,"VisionEncoderDecoderModel"),np.forEach(t),_s=r(na," from model configurations."),na.forEach(t),ta.forEach(t),Dr=p(o),Z=s(o,"P",{});var dt=d(Z);$t=s(dt,"A",{href:!0});var rp=d($t);vs=r(rp,"VisionEncoderDecoderModel"),rp.forEach(t),bs=r(dt," can be randomly initialized from an encoder and a decoder config. In the following example, we show how to do this using the default "),xt=s(dt,"A",{href:!0});var ap=d(xt);ws=r(ap,"ViTModel"),ap.forEach(t),ys=r(dt,` configuration for the encoder
and the default `),wn=s(dt,"CODE",{});var sp=d(wn);Ts=r(sp,"BertForCausalLM"),sp.forEach(t),Es=r(dt," configuration for the decoder."),dt.forEach(t),Vr=p(o),w(so.$$.fragment,o),qr=p(o),ae=s(o,"H2",{class:!0});var ra=d(ae);je=s(ra,"A",{id:!0,class:!0,href:!0});var dp=d(je);yn=s(dp,"SPAN",{});var ip=d(yn);w(io.$$.fragment,ip),ip.forEach(t),dp.forEach(t),ks=p(ra),lo=s(ra,"SPAN",{});var aa=d(lo);$s=r(aa,"Initialising "),Tn=s(aa,"CODE",{});var lp=d(Tn);xs=r(lp,"VisionEncoderDecoderModel"),lp.forEach(t),js=r(aa," from a pretrained encoder and a pretrained decoder."),aa.forEach(t),ra.forEach(t),Pr=p(o),M=s(o,"P",{});var z=d(M);jt=s(z,"A",{href:!0});var cp=d(jt);Ms=r(cp,"VisionEncoderDecoderModel"),cp.forEach(t),Ds=r(z," can be initialized from a pretrained encoder checkpoint and a pretrained decoder checkpoint. Note that any pretrained Transformer-based vision model, "),En=s(z,"EM",{});var pp=d(En);Vs=r(pp,"e.g."),pp.forEach(t),qs=p(z),Mt=s(z,"A",{href:!0});var mp=d(Mt);Ps=r(mp,"Swin"),mp.forEach(t),zs=r(z,", can serve as the encoder and both pretrained auto-encoding models, "),kn=s(z,"EM",{});var hp=d(kn);Fs=r(hp,"e.g."),hp.forEach(t),As=r(z," BERT, pretrained causal language models, "),$n=s(z,"EM",{});var fp=d($n);Cs=r(fp,"e.g."),fp.forEach(t),Is=r(z," GPT2, as well as the pretrained decoder part of sequence-to-sequence models, "),xn=s(z,"EM",{});var gp=d(xn);Ss=r(gp,"e.g."),gp.forEach(t),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 `),Dt=s(z,"A",{href:!0});var up=d(Dt);Os=r(up,"VisionEncoderDecoderModel"),up.forEach(t),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=d(Me);Rs=r(Lc,"the "),jn=s(Lc,"EM",{});var _p=d(jn);Bs=r(_p,"Warm-starting-encoder-decoder blog post"),_p.forEach(t),Lc.forEach(t),Gs=r(z,`.
To do so, the `),Mn=s(z,"CODE",{});var vp=d(Mn);Us=r(vp,"VisionEncoderDecoderModel"),vp.forEach(t),Ws=r(z," class provides a "),Vt=s(z,"A",{href:!0});var bp=d(Vt);Hs=r(bp,"VisionEncoderDecoderModel.from_encoder_decoder_pretrained()"),bp.forEach(t),Zs=r(z," method."),z.forEach(t),zr=p(o),w(co.$$.fragment,o),Fr=p(o),se=s(o,"H2",{class:!0});var sa=d(se);De=s(sa,"A",{id:!0,class:!0,href:!0});var wp=d(De);Dn=s(wp,"SPAN",{});var yp=d(Dn);w(po.$$.fragment,yp),yp.forEach(t),wp.forEach(t),Ys=p(sa),mo=s(sa,"SPAN",{});var da=d(mo);Js=r(da,"Loading an existing "),Vn=s(da,"CODE",{});var Tp=d(Vn);Ks=r(Tp,"VisionEncoderDecoderModel"),Tp.forEach(t),Qs=r(da," checkpoint and perform inference."),da.forEach(t),sa.forEach(t),Ar=p(o),L=s(o,"P",{});var Je=d(L);Xs=r(Je,"To load fine-tuned checkpoints of the "),qn=s(Je,"CODE",{});var Ep=d(qn);ed=r(Ep,"VisionEncoderDecoderModel"),Ep.forEach(t),od=r(Je," class, "),qt=s(Je,"A",{href:!0});var kp=d(qt);td=r(kp,"VisionEncoderDecoderModel"),kp.forEach(t),nd=r(Je," provides the "),Pn=s(Je,"CODE",{});var $p=d(Pn);rd=r($p,"from_pretrained(...)"),$p.forEach(t),ad=r(Je," method just like any other model architecture in Transformers."),Je.forEach(t),Cr=p(o),Ve=s(o,"P",{});var ia=d(Ve);sd=r(ia,"To perform inference, one uses the "),zn=s(ia,"CODE",{});var xp=d(zn);dd=r(xp,"generate"),xp.forEach(t),id=r(ia," method, which allows to autoregressively generate text. This method supports various forms of decoding, such as greedy, beam search and multinomial sampling."),ia.forEach(t),Ir=p(o),w(ho.$$.fragment,o),Sr=p(o),de=s(o,"H2",{class:!0});var la=d(de);qe=s(la,"A",{id:!0,class:!0,href:!0});var jp=d(qe);Fn=s(jp,"SPAN",{});var Mp=d(Fn);w(fo.$$.fragment,Mp),Mp.forEach(t),jp.forEach(t),ld=p(la),go=s(la,"SPAN",{});var ca=d(go);cd=r(ca,"Loading a PyTorch checkpoint into "),An=s(ca,"CODE",{});var Dp=d(An);pd=r(Dp,"TFVisionEncoderDecoderModel"),Dp.forEach(t),md=r(ca,"."),ca.forEach(t),la.forEach(t),Lr=p(o),ie=s(o,"P",{});var yr=d(ie);Cn=s(yr,"CODE",{});var Vp=d(Cn);hd=r(Vp,"TFVisionEncoderDecoderModel.from_pretrained()"),Vp.forEach(t),fd=r(yr,` currently doesn\u2019t support initializing the model from a
PyTorch checkpoint. Passing `),In=s(yr,"CODE",{});var qp=d(In);gd=r(qp,"from_pt=True"),qp.forEach(t),ud=r(yr,` to this method will throw an exception. If there are only PyTorch
checkpoints for a particular vision encoder-decoder model, a workaround is:`),yr.forEach(t),Or=p(o),w(uo.$$.fragment,o),Nr=p(o),le=s(o,"H2",{class:!0});var pa=d(le);Pe=s(pa,"A",{id:!0,class:!0,href:!0});var Pp=d(Pe);Sn=s(Pp,"SPAN",{});var zp=d(Sn);w(_o.$$.fragment,zp),zp.forEach(t),Pp.forEach(t),_d=p(pa),Ln=s(pa,"SPAN",{});var Fp=d(Ln);vd=r(Fp,"Training"),Fp.forEach(t),pa.forEach(t),Rr=p(o),O=s(o,"P",{});var Ke=d(O);bd=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: `),On=s(Ke,"CODE",{});var Ap=d(On);wd=r(Ap,"pixel_values"),Ap.forEach(t),yd=r(Ke,` (which are the
images) and `),Nn=s(Ke,"CODE",{});var Cp=d(Nn);Td=r(Cp,"labels"),Cp.forEach(t),Ed=r(Ke," (which are the "),Rn=s(Ke,"CODE",{});var Ip=d(Rn);kd=r(Ip,"input_ids"),Ip.forEach(t),$d=r(Ke," of the encoded target sequence)."),Ke.forEach(t),Br=p(o),w(vo.$$.fragment,o),Gr=p(o),K=s(o,"P",{});var on=d(K);xd=r(on,"This model was contributed by "),bo=s(on,"A",{href:!0,rel:!0});var Sp=d(bo);jd=r(Sp,"nielsr"),Sp.forEach(t),Md=r(on,`. This model\u2019s TensorFlow and Flax versions
were contributed by `),wo=s(on,"A",{href:!0,rel:!0});var Lp=d(wo);Dd=r(Lp,"ydshieh"),Lp.forEach(t),Vd=r(on,"."),on.forEach(t),Ur=p(o),ce=s(o,"H2",{class:!0});var ma=d(ce);ze=s(ma,"A",{id:!0,class:!0,href:!0});var Op=d(ze);Bn=s(Op,"SPAN",{});var Np=d(Bn);w(yo.$$.fragment,Np),Np.forEach(t),Op.forEach(t),qd=p(ma),Gn=s(ma,"SPAN",{});var Rp=d(Gn);Pd=r(Rp,"VisionEncoderDecoderConfig"),Rp.forEach(t),ma.forEach(t),Wr=p(o),I=s(o,"DIV",{class:!0});var U=d(I);w(To.$$.fragment,U),zd=p(U),Fe=s(U,"P",{});var Tr=d(Fe);Pt=s(Tr,"A",{href:!0});var Bp=d(Pt);Fd=r(Bp,"VisionEncoderDecoderConfig"),Bp.forEach(t),Ad=r(Tr,` is the configuration class to store the configuration of a
`),zt=s(Tr,"A",{href:!0});var Gp=d(zt);Cd=r(Gp,"VisionEncoderDecoderModel"),Gp.forEach(t),Id=r(Tr,`. It is used to instantiate a Vision-Encoder-Text-Decoder model according to the
specified arguments, defining the encoder and decoder configs.`),Tr.forEach(t),Sd=p(U),pe=s(U,"P",{});var tn=d(pe);Ld=r(tn,"Configuration objects inherit from "),Ft=s(tn,"A",{href:!0});var Up=d(Ft);Od=r(Up,"PretrainedConfig"),Up.forEach(t),Nd=r(tn,` and can be used to control the model outputs. Read the
documentation from `),At=s(tn,"A",{href:!0});var Wp=d(At);Rd=r(Wp,"PretrainedConfig"),Wp.forEach(t),Bd=r(tn," for more information."),tn.forEach(t),Gd=p(U),w(Ae.$$.fragment,U),Ud=p(U),Ce=s(U,"DIV",{class:!0});var ha=d(Ce);w(Eo.$$.fragment,ha),Wd=p(ha),ko=s(ha,"P",{});var fa=d(ko);Hd=r(fa,"Instantiate a "),Ct=s(fa,"A",{href:!0});var Hp=d(Ct);Zd=r(Hp,"VisionEncoderDecoderConfig"),Hp.forEach(t),Yd=r(fa,` (or a derived class) from a pre-trained encoder model
configuration and decoder model configuration.`),fa.forEach(t),ha.forEach(t),Jd=p(U),Ie=s(U,"DIV",{class:!0});var ga=d(Ie);w($o.$$.fragment,ga),Kd=p(ga),me=s(ga,"P",{});var nn=d(me);Qd=r(nn,"Serializes this instance to a Python dictionary. Override the default "),Un=s(nn,"EM",{});var Zp=d(Un);Xd=r(Zp,"to_dict()"),Zp.forEach(t),ei=r(nn," from "),Wn=s(nn,"EM",{});var Yp=d(Wn);oi=r(Yp,"PretrainedConfig"),Yp.forEach(t),ti=r(nn,"."),nn.forEach(t),ga.forEach(t),U.forEach(t),Hr=p(o),he=s(o,"H2",{class:!0});var ua=d(he);Se=s(ua,"A",{id:!0,class:!0,href:!0});var Jp=d(Se);Hn=s(Jp,"SPAN",{});var Kp=d(Hn);w(xo.$$.fragment,Kp),Kp.forEach(t),Jp.forEach(t),ni=p(ua),Zn=s(ua,"SPAN",{});var Qp=d(Zn);ri=r(Qp,"VisionEncoderDecoderModel"),Qp.forEach(t),ua.forEach(t),Zr=p(o),D=s(o,"DIV",{class:!0});var F=d(D);w(jo.$$.fragment,F),ai=p(F),fe=s(F,"P",{});var rn=d(fe);si=r(rn,`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
`),It=s(rn,"A",{href:!0});var Xp=d(It);di=r(Xp,"from_pretrained()"),Xp.forEach(t),ii=r(rn," function and the decoder is loaded via "),St=s(rn,"A",{href:!0});var em=d(St);li=r(em,"from_pretrained()"),em.forEach(t),ci=r(rn,`
function. Cross-attention layers are automatically added to the decoder and should be fine-tuned on a downstream
generative task, like image captioning.`),rn.forEach(t),pi=p(F),Mo=s(F,"P",{});var _a=d(Mo);mi=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=d(Do);hi=r(om,`Leveraging Pre-trained Checkpoints for Sequence Generation
Tasks`),om.forEach(t),fi=r(_a,` by Sascha Rothe, Shashi Narayan, Aliaksei Severyn. Michael Matena, Yanqi
Zhou, Wei Li, Peter J. Liu.`),_a.forEach(t),gi=p(F),Vo=s(F,"P",{});var va=d(Vo);ui=r(va,"Additionally, in "),qo=s(va,"A",{href:!0,rel:!0});var tm=d(qo);_i=r(tm,`TrOCR: Transformer-based Optical Character Recognition with Pre-trained
Models`),tm.forEach(t),vi=r(va,` it is shown how leveraging large pretrained vision models for optical
character recognition (OCR) yields a significant performance improvement.`),va.forEach(t),bi=p(F),Yn=s(F,"P",{});var nm=d(Yn);wi=r(nm,`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).`),nm.forEach(t),yi=p(F),Po=s(F,"P",{});var ba=d(Po);Ti=r(ba,"This model inherits from "),Lt=s(ba,"A",{href:!0});var rm=d(Lt);Ei=r(rm,"PreTrainedModel"),rm.forEach(t),ki=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(t),$i=p(F),zo=s(F,"P",{});var wa=d(zo);xi=r(wa,"This model is also a PyTorch "),Fo=s(wa,"A",{href:!0,rel:!0});var am=d(Fo);ji=r(am,"torch.nn.Module"),am.forEach(t),Mi=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(t),Di=p(F),Q=s(F,"P",{});var it=d(Q);Ot=s(it,"A",{href:!0});var sm=d(Ot);Vi=r(sm,"VisionEncoderDecoderModel"),sm.forEach(t),qi=r(it,` 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`),Jn=s(it,"EM",{});var dm=d(Jn);Pi=r(dm,"~transformers.AutoModel.from_pretrained"),dm.forEach(t),zi=r(it,` class method for the encoder and
:meth`),Kn=s(it,"EM",{});var im=d(Kn);Fi=r(im,"~transformers.AutoModelForCausalLM.from_pretrained"),im.forEach(t),Ai=r(it," class method for the decoder."),it.forEach(t),Ci=p(F),N=s(F,"DIV",{class:!0});var Qe=d(N);w(Ao.$$.fragment,Qe),Ii=p(Qe),ge=s(Qe,"P",{});var an=d(ge);Si=r(an,"The "),Nt=s(an,"A",{href:!0});var lm=d(Nt);Li=r(lm,"VisionEncoderDecoderModel"),lm.forEach(t),Oi=r(an," forward method, overrides the "),Qn=s(an,"CODE",{});var cm=d(Qn);Ni=r(cm,"__call__"),cm.forEach(t),Ri=r(an," special method."),an.forEach(t),Bi=p(Qe),w(Le.$$.fragment,Qe),Gi=p(Qe),w(Oe.$$.fragment,Qe),Qe.forEach(t),Ui=p(F),R=s(F,"DIV",{class:!0});var Xe=d(R);w(Co.$$.fragment,Xe),Wi=p(Xe),Xn=s(Xe,"P",{});var pm=d(Xn);Hi=r(pm,`Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.`),pm.forEach(t),Zi=p(Xe),ue=s(Xe,"P",{});var sn=d(ue);Yi=r(sn,"The model is set in evaluation mode by default using "),er=s(sn,"CODE",{});var mm=d(er);Ji=r(mm,"model.eval()"),mm.forEach(t),Ki=r(sn,` (Dropout modules are deactivated). To train
the model, you need to first set it back in training mode with `),or=s(sn,"CODE",{});var hm=d(or);Qi=r(hm,"model.train()"),hm.forEach(t),Xi=r(sn,"."),sn.forEach(t),el=p(Xe),w(Ne.$$.fragment,Xe),Xe.forEach(t),F.forEach(t),Yr=p(o),_e=s(o,"H2",{class:!0});var ya=d(_e);Re=s(ya,"A",{id:!0,class:!0,href:!0});var fm=d(Re);tr=s(fm,"SPAN",{});var gm=d(tr);w(Io.$$.fragment,gm),gm.forEach(t),fm.forEach(t),ol=p(ya),nr=s(ya,"SPAN",{});var um=d(nr);tl=r(um,"TFVisionEncoderDecoderModel"),um.forEach(t),ya.forEach(t),Jr=p(o),V=s(o,"DIV",{class:!0});var A=d(V);w(So.$$.fragment,A),nl=p(A),ve=s(A,"P",{});var dn=d(ve);rl=r(dn,`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
`),Rt=s(dn,"A",{href:!0});var _m=d(Rt);al=r(_m,"from_pretrained()"),_m.forEach(t),sl=r(dn," function and the decoder is loaded via "),Bt=s(dn,"A",{href:!0});var vm=d(Bt);dl=r(vm,"from_pretrained()"),vm.forEach(t),il=r(dn,`
function. Cross-attention layers are automatically added to the decoder and should be fine-tuned on a downstream
generative task, like image captioning.`),dn.forEach(t),ll=p(A),Lo=s(A,"P",{});var Ta=d(Lo);cl=r(Ta,`The effectiveness of initializing sequence-to-sequence models with pretrained checkpoints for sequence generation
tasks was shown in `),Oo=s(Ta,"A",{href:!0,rel:!0});var bm=d(Oo);pl=r(bm,`Leveraging Pre-trained Checkpoints for Sequence Generation
Tasks`),bm.forEach(t),ml=r(Ta,` by Sascha Rothe, Shashi Narayan, Aliaksei Severyn. Michael Matena, Yanqi
Zhou, Wei Li, Peter J. Liu.`),Ta.forEach(t),hl=p(A),No=s(A,"P",{});var Ea=d(No);fl=r(Ea,"Additionally, in "),Ro=s(Ea,"A",{href:!0,rel:!0});var wm=d(Ro);gl=r(wm,`TrOCR: Transformer-based Optical Character Recognition with Pre-trained
Models`),wm.forEach(t),ul=r(Ea,` it is shown how leveraging large pretrained vision models for optical
character recognition (OCR) yields a significant performance improvement.`),Ea.forEach(t),_l=p(A),rr=s(A,"P",{});var ym=d(rr);vl=r(ym,`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).`),ym.forEach(t),bl=p(A),Bo=s(A,"P",{});var ka=d(Bo);wl=r(ka,"This model inherits from "),Gt=s(ka,"A",{href:!0});var Tm=d(Gt);yl=r(Tm,"TFPreTrainedModel"),Tm.forEach(t),Tl=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(t),El=p(A),Go=s(A,"P",{});var $a=d(Go);kl=r($a,"This model is also a "),Uo=s($a,"A",{href:!0,rel:!0});var Em=d(Uo);$l=r(Em,"tf.keras.Model"),Em.forEach(t),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(t),jl=p(A),X=s(A,"P",{});var lt=d(X);Ut=s(lt,"A",{href:!0});var km=d(Ut);Ml=r(km,"TFVisionEncoderDecoderModel"),km.forEach(t),Dl=r(lt,` 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 `),Wt=s(lt,"A",{href:!0});var $m=d(Wt);Vl=r($m,"from_pretrained()"),$m.forEach(t),ql=r(lt,` class method for the encoder and
`),Ht=s(lt,"A",{href:!0});var xm=d(Ht);Pl=r(xm,"from_pretrained()"),xm.forEach(t),zl=r(lt," class method for the decoder."),lt.forEach(t),Fl=p(A),B=s(A,"DIV",{class:!0});var eo=d(B);w(Wo.$$.fragment,eo),Al=p(eo),be=s(eo,"P",{});var ln=d(be);Cl=r(ln,"The "),Zt=s(ln,"A",{href:!0});var jm=d(Zt);Il=r(jm,"TFVisionEncoderDecoderModel"),jm.forEach(t),Sl=r(ln," forward method, overrides the "),ar=s(ln,"CODE",{});var Mm=d(ar);Ll=r(Mm,"__call__"),Mm.forEach(t),Ol=r(ln," special method."),ln.forEach(t),Nl=p(eo),w(Be.$$.fragment,eo),Rl=p(eo),w(Ge.$$.fragment,eo),eo.forEach(t),Bl=p(A),ee=s(A,"DIV",{class:!0});var cn=d(ee);w(Ho.$$.fragment,cn),Gl=p(cn),sr=s(cn,"P",{});var Dm=d(sr);Ul=r(Dm,`Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.`),Dm.forEach(t),Wl=p(cn),w(Ue.$$.fragment,cn),cn.forEach(t),A.forEach(t),Kr=p(o),we=s(o,"H2",{class:!0});var xa=d(we);We=s(xa,"A",{id:!0,class:!0,href:!0});var Vm=d(We);dr=s(Vm,"SPAN",{});var qm=d(dr);w(Zo.$$.fragment,qm),qm.forEach(t),Vm.forEach(t),Hl=p(xa),ir=s(xa,"SPAN",{});var Pm=d(ir);Zl=r(Pm,"FlaxVisionEncoderDecoderModel"),Pm.forEach(t),xa.forEach(t),Qr=p(o),q=s(o,"DIV",{class:!0});var C=d(q);w(Yo.$$.fragment,C),Yl=p(C),ye=s(C,"P",{});var pn=d(ye);Jl=r(pn,`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
`),Yt=s(pn,"A",{href:!0});var zm=d(Yt);Kl=r(zm,"from_pretrained()"),zm.forEach(t),Ql=r(pn," function and the decoder is loaded via "),Jt=s(pn,"A",{href:!0});var Fm=d(Jt);Xl=r(Fm,"from_pretrained()"),Fm.forEach(t),ec=r(pn,`
function. Cross-attention layers are automatically added to the decoder and should be fine-tuned on a downstream
generative task, like image captioning.`),pn.forEach(t),oc=p(C),Jo=s(C,"P",{});var ja=d(Jo);tc=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=d(Ko);nc=r(Am,`Leveraging Pre-trained Checkpoints for Sequence Generation
Tasks`),Am.forEach(t),rc=r(ja,` by Sascha Rothe, Shashi Narayan, Aliaksei Severyn. Michael Matena, Yanqi
Zhou, Wei Li, Peter J. Liu.`),ja.forEach(t),ac=p(C),Qo=s(C,"P",{});var Ma=d(Qo);sc=r(Ma,"Additionally, in "),Xo=s(Ma,"A",{href:!0,rel:!0});var Cm=d(Xo);dc=r(Cm,`TrOCR: Transformer-based Optical Character Recognition with Pre-trained
Models`),Cm.forEach(t),ic=r(Ma,` it is shown how leveraging large pretrained vision models for optical
character recognition (OCR) yields a significant performance improvement.`),Ma.forEach(t),lc=p(C),lr=s(C,"P",{});var Im=d(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(t),pc=p(C),et=s(C,"P",{});var Da=d(et);mc=r(Da,"This model inherits from "),Kt=s(Da,"A",{href:!0});var Sm=d(Kt);hc=r(Sm,"FlaxPreTrainedModel"),Sm.forEach(t),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(t),gc=p(C),ot=s(C,"P",{});var Va=d(ot);uc=r(Va,`This model is also a Flax Linen
`),tt=s(Va,"A",{href:!0,rel:!0});var Lm=d(tt);_c=r(Lm,"flax.nn.Module"),Lm.forEach(t),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(t),bc=p(C),oe=s(C,"P",{});var ct=d(oe);Qt=s(ct,"A",{href:!0});var Om=d(Qt);wc=r(Om,"FlaxVisionEncoderDecoderModel"),Om.forEach(t),yc=r(ct,` 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(ct,"EM",{});var Nm=d(cr);Tc=r(Nm,"~transformers.FlaxAutoModel.from_pretrained"),Nm.forEach(t),Ec=r(ct,` class method
for the encoder and :meth`),pr=s(ct,"EM",{});var Rm=d(pr);kc=r(Rm,"~transformers.FlaxAutoModelForCausalLM.from_pretrained"),Rm.forEach(t),$c=r(ct," class method for the decoder."),ct.forEach(t),xc=p(C),G=s(C,"DIV",{class:!0});var oo=d(G);w(nt.$$.fragment,oo),jc=p(oo),Te=s(oo,"P",{});var mn=d(Te);Mc=r(mn,"The "),Xt=s(mn,"A",{href:!0});var Bm=d(Xt);Dc=r(Bm,"FlaxVisionEncoderDecoderModel"),Bm.forEach(t),Vc=r(mn," forward method, overrides the "),mr=s(mn,"CODE",{});var Gm=d(mr);qc=r(Gm,"__call__"),Gm.forEach(t),Pc=r(mn," special method."),mn.forEach(t),zc=p(oo),w(He.$$.fragment,oo),Fc=p(oo),w(Ze.$$.fragment,oo),oo.forEach(t),Ac=p(C),te=s(C,"DIV",{class:!0});var hn=d(te);w(rt.$$.fragment,hn),Cc=p(hn),hr=s(hn,"P",{});var Um=d(hr);Ic=r(Um,`Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.`),Um.forEach(t),Sc=p(hn),w(Ye.$$.fragment,hn),hn.forEach(t),C.forEach(t),this.h()},h(){l(h,"name","hf:doc:metadata"),l(h,"content",JSON.stringify(ih)),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(ne,"class","relative group"),l(ht,"href","/docs/transformers/v4.29.0/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel"),l(ft,"href","vit"),l(gt,"href","beit"),l(ut,"href","deit"),l(_t,"href","swin"),l(vt,"href","roberta"),l(bt,"href","gpt2"),l(wt,"href","bert"),l(yt,"href","distilbert"),l(no,"href","https://arxiv.org/abs/2109.10282"),l(no,"rel","nofollow"),l(Tt,"href","/docs/transformers/v4.29.0/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel"),l(Et,"href","trocr"),l(kt,"href","/docs/transformers/v4.29.0/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($t,"href","/docs/transformers/v4.29.0/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel"),l(xt,"href","/docs/transformers/v4.29.0/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(jt,"href","/docs/transformers/v4.29.0/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel"),l(Mt,"href","swin"),l(Dt,"href","/docs/transformers/v4.29.0/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel"),l(Me,"href","https://huggingface.co/blog/warm-starting-encoder-decoder"),l(Me,"rel","nofollow"),l(Vt,"href","/docs/transformers/v4.29.0/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(qt,"href","/docs/transformers/v4.29.0/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(de,"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(Pt,"href","/docs/transformers/v4.29.0/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderConfig"),l(zt,"href","/docs/transformers/v4.29.0/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel"),l(Ft,"href","/docs/transformers/v4.29.0/en/main_classes/configuration#transformers.PretrainedConfig"),l(At,"href","/docs/transformers/v4.29.0/en/main_classes/configuration#transformers.PretrainedConfig"),l(Ct,"href","/docs/transformers/v4.29.0/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(It,"href","/docs/transformers/v4.29.0/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained"),l(St,"href","/docs/transformers/v4.29.0/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(Lt,"href","/docs/transformers/v4.29.0/en/main_classes/model#transformers.PreTrainedModel"),l(Fo,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),l(Fo,"rel","nofollow"),l(Ot,"href","/docs/transformers/v4.29.0/en/model_doc/vision-encoder-decoder#transformers.VisionEncoderDecoderModel"),l(Nt,"href","/docs/transformers/v4.29.0/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(Rt,"href","/docs/transformers/v4.29.0/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained"),l(Bt,"href","/docs/transformers/v4.29.0/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(Gt,"href","/docs/transformers/v4.29.0/en/main_classes/model#transformers.TFPreTrainedModel"),l(Uo,"href","https://www.tensorflow.org/api_docs/python/tf/keras/Model"),l(Uo,"rel","nofollow"),l(Ut,"href","/docs/transformers/v4.29.0/en/model_doc/vision-encoder-decoder#transformers.TFVisionEncoderDecoderModel"),l(Wt,"href","/docs/transformers/v4.29.0/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained"),l(Ht,"href","/docs/transformers/v4.29.0/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained"),l(Zt,"href","/docs/transformers/v4.29.0/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(We,"id","transformers.FlaxVisionEncoderDecoderModel"),l(We,"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(We,"href","#transformers.FlaxVisionEncoderDecoderModel"),l(we,"class","relative group"),l(Yt,"href","/docs/transformers/v4.29.0/en/model_doc/auto#transformers.FlaxAutoModelForVision2Seq.from_pretrained"),l(Jt,"href","/docs/transformers/v4.29.0/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(Kt,"href","/docs/transformers/v4.29.0/en/main_classes/model#transformers.FlaxPreTrainedModel"),l(tt,"href","https://flax.readthedocs.io/en/latest/_autosummary/flax.nn.module.html"),l(tt,"rel","nofollow"),l(Qt,"href","/docs/transformers/v4.29.0/en/model_doc/vision-encoder-decoder#transformers.FlaxVisionEncoderDecoderModel"),l(Xt,"href","/docs/transformers/v4.29.0/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(te,"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),y(i,v,null),e(_,u),e(_,S),e(S,qa),g(o,Er,m),g(o,ne,m),e(ne,Ee),e(Ee,fn),y(to,fn,null),e(ne,Pa),e(ne,gn),e(gn,za),g(o,kr,m),g(o,x,m),e(x,Fa),e(x,ht),e(ht,Aa),e(x,Ca),e(x,un),e(un,Ia),e(x,Sa),e(x,ft),e(ft,La),e(x,Oa),e(x,gt),e(gt,Na),e(x,Ra),e(x,ut),e(ut,Ba),e(x,Ga),e(x,_t),e(_t,Ua),e(x,Wa),e(x,_n),e(_n,Ha),e(x,Za),e(x,vt),e(vt,Ya),e(x,Ja),e(x,bt),e(bt,Ka),e(x,Qa),e(x,wt),e(wt,Xa),e(x,es),e(x,yt),e(yt,os),e(x,ts),g(o,$r,m),g(o,ke,m),e(ke,ns),e(ke,no),e(no,rs),e(ke,as),g(o,xr,m),g(o,$e,m),e($e,ss),e($e,Tt),e(Tt,ds),e($e,is),g(o,jr,m),g(o,J,m),e(J,ls),e(J,Et),e(Et,cs),e(J,ps),e(J,kt),e(kt,ms),e(J,hs),g(o,Mr,m),g(o,re,m),e(re,xe),e(xe,vn),y(ro,vn,null),e(re,fs),e(re,ao),e(ao,gs),e(ao,bn),e(bn,us),e(ao,_s),g(o,Dr,m),g(o,Z,m),e(Z,$t),e($t,vs),e(Z,bs),e(Z,xt),e(xt,ws),e(Z,ys),e(Z,wn),e(wn,Ts),e(Z,Es),g(o,Vr,m),y(so,o,m),g(o,qr,m),g(o,ae,m),e(ae,je),e(je,yn),y(io,yn,null),e(ae,ks),e(ae,lo),e(lo,$s),e(lo,Tn),e(Tn,xs),e(lo,js),g(o,Pr,m),g(o,M,m),e(M,jt),e(jt,Ms),e(M,Ds),e(M,En),e(En,Vs),e(M,qs),e(M,Mt),e(Mt,Ps),e(M,zs),e(M,kn),e(kn,Fs),e(M,As),e(M,$n),e($n,Cs),e(M,Is),e(M,xn),e(xn,Ss),e(M,Ls),e(M,Dt),e(Dt,Os),e(M,Ns),e(M,Me),e(Me,Rs),e(Me,jn),e(jn,Bs),e(M,Gs),e(M,Mn),e(Mn,Us),e(M,Ws),e(M,Vt),e(Vt,Hs),e(M,Zs),g(o,zr,m),y(co,o,m),g(o,Fr,m),g(o,se,m),e(se,De),e(De,Dn),y(po,Dn,null),e(se,Ys),e(se,mo),e(mo,Js),e(mo,Vn),e(Vn,Ks),e(mo,Qs),g(o,Ar,m),g(o,L,m),e(L,Xs),e(L,qn),e(qn,ed),e(L,od),e(L,qt),e(qt,td),e(L,nd),e(L,Pn),e(Pn,rd),e(L,ad),g(o,Cr,m),g(o,Ve,m),e(Ve,sd),e(Ve,zn),e(zn,dd),e(Ve,id),g(o,Ir,m),y(ho,o,m),g(o,Sr,m),g(o,de,m),e(de,qe),e(qe,Fn),y(fo,Fn,null),e(de,ld),e(de,go),e(go,cd),e(go,An),e(An,pd),e(go,md),g(o,Lr,m),g(o,ie,m),e(ie,Cn),e(Cn,hd),e(ie,fd),e(ie,In),e(In,gd),e(ie,ud),g(o,Or,m),y(uo,o,m),g(o,Nr,m),g(o,le,m),e(le,Pe),e(Pe,Sn),y(_o,Sn,null),e(le,_d),e(le,Ln),e(Ln,vd),g(o,Rr,m),g(o,O,m),e(O,bd),e(O,On),e(On,wd),e(O,yd),e(O,Nn),e(Nn,Td),e(O,Ed),e(O,Rn),e(Rn,kd),e(O,$d),g(o,Br,m),y(vo,o,m),g(o,Gr,m),g(o,K,m),e(K,xd),e(K,bo),e(bo,jd),e(K,Md),e(K,wo),e(wo,Dd),e(K,Vd),g(o,Ur,m),g(o,ce,m),e(ce,ze),e(ze,Bn),y(yo,Bn,null),e(ce,qd),e(ce,Gn),e(Gn,Pd),g(o,Wr,m),g(o,I,m),y(To,I,null),e(I,zd),e(I,Fe),e(Fe,Pt),e(Pt,Fd),e(Fe,Ad),e(Fe,zt),e(zt,Cd),e(Fe,Id),e(I,Sd),e(I,pe),e(pe,Ld),e(pe,Ft),e(Ft,Od),e(pe,Nd),e(pe,At),e(At,Rd),e(pe,Bd),e(I,Gd),y(Ae,I,null),e(I,Ud),e(I,Ce),y(Eo,Ce,null),e(Ce,Wd),e(Ce,ko),e(ko,Hd),e(ko,Ct),e(Ct,Zd),e(ko,Yd),e(I,Jd),e(I,Ie),y($o,Ie,null),e(Ie,Kd),e(Ie,me),e(me,Qd),e(me,Un),e(Un,Xd),e(me,ei),e(me,Wn),e(Wn,oi),e(me,ti),g(o,Hr,m),g(o,he,m),e(he,Se),e(Se,Hn),y(xo,Hn,null),e(he,ni),e(he,Zn),e(Zn,ri),g(o,Zr,m),g(o,D,m),y(jo,D,null),e(D,ai),e(D,fe),e(fe,si),e(fe,It),e(It,di),e(fe,ii),e(fe,St),e(St,li),e(fe,ci),e(D,pi),e(D,Mo),e(Mo,mi),e(Mo,Do),e(Do,hi),e(Mo,fi),e(D,gi),e(D,Vo),e(Vo,ui),e(Vo,qo),e(qo,_i),e(Vo,vi),e(D,bi),e(D,Yn),e(Yn,wi),e(D,yi),e(D,Po),e(Po,Ti),e(Po,Lt),e(Lt,Ei),e(Po,ki),e(D,$i),e(D,zo),e(zo,xi),e(zo,Fo),e(Fo,ji),e(zo,Mi),e(D,Di),e(D,Q),e(Q,Ot),e(Ot,Vi),e(Q,qi),e(Q,Jn),e(Jn,Pi),e(Q,zi),e(Q,Kn),e(Kn,Fi),e(Q,Ai),e(D,Ci),e(D,N),y(Ao,N,null),e(N,Ii),e(N,ge),e(ge,Si),e(ge,Nt),e(Nt,Li),e(ge,Oi),e(ge,Qn),e(Qn,Ni),e(ge,Ri),e(N,Bi),y(Le,N,null),e(N,Gi),y(Oe,N,null),e(D,Ui),e(D,R),y(Co,R,null),e(R,Wi),e(R,Xn),e(Xn,Hi),e(R,Zi),e(R,ue),e(ue,Yi),e(ue,er),e(er,Ji),e(ue,Ki),e(ue,or),e(or,Qi),e(ue,Xi),e(R,el),y(Ne,R,null),g(o,Yr,m),g(o,_e,m),e(_e,Re),e(Re,tr),y(Io,tr,null),e(_e,ol),e(_e,nr),e(nr,tl),g(o,Jr,m),g(o,V,m),y(So,V,null),e(V,nl),e(V,ve),e(ve,rl),e(ve,Rt),e(Rt,al),e(ve,sl),e(ve,Bt),e(Bt,dl),e(ve,il),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,Gt),e(Gt,yl),e(Bo,Tl),e(V,El),e(V,Go),e(Go,kl),e(Go,Uo),e(Uo,$l),e(Go,xl),e(V,jl),e(V,X),e(X,Ut),e(Ut,Ml),e(X,Dl),e(X,Wt),e(Wt,Vl),e(X,ql),e(X,Ht),e(Ht,Pl),e(X,zl),e(V,Fl),e(V,B),y(Wo,B,null),e(B,Al),e(B,be),e(be,Cl),e(be,Zt),e(Zt,Il),e(be,Sl),e(be,ar),e(ar,Ll),e(be,Ol),e(B,Nl),y(Be,B,null),e(B,Rl),y(Ge,B,null),e(V,Bl),e(V,ee),y(Ho,ee,null),e(ee,Gl),e(ee,sr),e(sr,Ul),e(ee,Wl),y(Ue,ee,null),g(o,Kr,m),g(o,we,m),e(we,We),e(We,dr),y(Zo,dr,null),e(we,Hl),e(we,ir),e(ir,Zl),g(o,Qr,m),g(o,q,m),y(Yo,q,null),e(q,Yl),e(q,ye),e(ye,Jl),e(ye,Yt),e(Yt,Kl),e(ye,Ql),e(ye,Jt),e(Jt,Xl),e(ye,ec),e(q,oc),e(q,Jo),e(Jo,tc),e(Jo,Ko),e(Ko,nc),e(Jo,rc),e(q,ac),e(q,Qo),e(Qo,sc),e(Qo,Xo),e(Xo,dc),e(Qo,ic),e(q,lc),e(q,lr),e(lr,cc),e(q,pc),e(q,et),e(et,mc),e(et,Kt),e(Kt,hc),e(et,fc),e(q,gc),e(q,ot),e(ot,uc),e(ot,tt),e(tt,_c),e(ot,vc),e(q,bc),e(q,oe),e(oe,Qt),e(Qt,wc),e(oe,yc),e(oe,cr),e(cr,Tc),e(oe,Ec),e(oe,pr),e(pr,kc),e(oe,$c),e(q,xc),e(q,G),y(nt,G,null),e(G,jc),e(G,Te),e(Te,Mc),e(Te,Xt),e(Xt,Dc),e(Te,Vc),e(Te,mr),e(mr,qc),e(Te,Pc),e(G,zc),y(He,G,null),e(G,Fc),y(Ze,G,null),e(q,Ac),e(q,te),y(rt,te,null),e(te,Cc),e(te,hr),e(hr,Ic),e(te,Sc),y(Ye,te,null),Xr=!0},p(o,[m]){const at={};m&2&&(at.$$scope={dirty:m,ctx:o}),Ae.$set(at);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 st={};m&2&&(st.$$scope={dirty:m,ctx:o}),Be.$set(st);const _r={};m&2&&(_r.$$scope={dirty:m,ctx:o}),Ge.$set(_r);const vr={};m&2&&(vr.$$scope={dirty:m,ctx:o}),Ue.$set(vr);const br={};m&2&&(br.$$scope={dirty:m,ctx:o}),He.$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||(T(i.$$.fragment,o),T(to.$$.fragment,o),T(ro.$$.fragment,o),T(so.$$.fragment,o),T(io.$$.fragment,o),T(co.$$.fragment,o),T(po.$$.fragment,o),T(ho.$$.fragment,o),T(fo.$$.fragment,o),T(uo.$$.fragment,o),T(_o.$$.fragment,o),T(vo.$$.fragment,o),T(yo.$$.fragment,o),T(To.$$.fragment,o),T(Ae.$$.fragment,o),T(Eo.$$.fragment,o),T($o.$$.fragment,o),T(xo.$$.fragment,o),T(jo.$$.fragment,o),T(Ao.$$.fragment,o),T(Le.$$.fragment,o),T(Oe.$$.fragment,o),T(Co.$$.fragment,o),T(Ne.$$.fragment,o),T(Io.$$.fragment,o),T(So.$$.fragment,o),T(Wo.$$.fragment,o),T(Be.$$.fragment,o),T(Ge.$$.fragment,o),T(Ho.$$.fragment,o),T(Ue.$$.fragment,o),T(Zo.$$.fragment,o),T(Yo.$$.fragment,o),T(nt.$$.fragment,o),T(He.$$.fragment,o),T(Ze.$$.fragment,o),T(rt.$$.fragment,o),T(Ye.$$.fragment,o),Xr=!0)},o(o){E(i.$$.fragment,o),E(to.$$.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(yo.$$.fragment,o),E(To.$$.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(Wo.$$.fragment,o),E(Be.$$.fragment,o),E(Ge.$$.fragment,o),E(Ho.$$.fragment,o),E(Ue.$$.fragment,o),E(Zo.$$.fragment,o),E(Yo.$$.fragment,o),E(nt.$$.fragment,o),E(He.$$.fragment,o),E(Ze.$$.fragment,o),E(rt.$$.fragment,o),E(Ye.$$.fragment,o),Xr=!1},d(o){t(h),o&&t($),o&&t(_),k(i),o&&t(Er),o&&t(ne),k(to),o&&t(kr),o&&t(x),o&&t($r),o&&t(ke),o&&t(xr),o&&t($e),o&&t(jr),o&&t(J),o&&t(Mr),o&&t(re),k(ro),o&&t(Dr),o&&t(Z),o&&t(Vr),k(so,o),o&&t(qr),o&&t(ae),k(io),o&&t(Pr),o&&t(M),o&&t(zr),k(co,o),o&&t(Fr),o&&t(se),k(po),o&&t(Ar),o&&t(L),o&&t(Cr),o&&t(Ve),o&&t(Ir),k(ho,o),o&&t(Sr),o&&t(de),k(fo),o&&t(Lr),o&&t(ie),o&&t(Or),k(uo,o),o&&t(Nr),o&&t(le),k(_o),o&&t(Rr),o&&t(O),o&&t(Br),k(vo,o),o&&t(Gr),o&&t(K),o&&t(Ur),o&&t(ce),k(yo),o&&t(Wr),o&&t(I),k(To),k(Ae),k(Eo),k($o),o&&t(Hr),o&&t(he),k(xo),o&&t(Zr),o&&t(D),k(jo),k(Ao),k(Le),k(Oe),k(Co),k(Ne),o&&t(Yr),o&&t(_e),k(Io),o&&t(Jr),o&&t(V),k(So),k(Wo),k(Be),k(Ge),k(Ho),k(Ue),o&&t(Kr),o&&t(we),k(Zo),o&&t(Qr),o&&t(q),k(Yo),k(nt),k(He),k(Ze),k(rt),k(Ye)}}}const ih={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 Wm{constructor(h){super();Hm(this,h,lh,dh,Zm,{})}}export{uh as default,ih as metadata};
