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