import{s as Bo,o as Io,n as Qe}from"../chunks/scheduler.9bc65507.js";import{S as Ho,i as Eo,g as d,s as n,r as u,A as Vo,h as c,f as o,c as a,j as F,u as f,x as m,k as Z,y as l,a as s,v as g,d as _,t as b,w as M}from"../chunks/index.707bf1b6.js";import{T as lo}from"../chunks/Tip.c2ecdbf4.js";import{D as R}from"../chunks/Docstring.17db21ae.js";import{C as et}from"../chunks/CodeBlock.54a9f38d.js";import{E as io}from"../chunks/ExampleCodeBlock.4f515aa9.js";import{H as G}from"../chunks/Heading.342b1fa6.js";function Xo(x){let r,y="Example:",p,h,T;return h=new et({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyME5sbGJNb2VNb2RlbCUyQyUyME5sbGJNb2VDb25maWclMEElMEElMjMlMjBJbml0aWFsaXppbmclMjBhJTIwTmxsYk1vZSUyMGZhY2Vib29rJTJGbmxsYi1tb2UtNTRiJTIwc3R5bGUlMjBjb25maWd1cmF0aW9uJTBBY29uZmlndXJhdGlvbiUyMCUzRCUyME5sbGJNb2VDb25maWcoKSUwQSUwQSUyMyUyMEluaXRpYWxpemluZyUyMGElMjBtb2RlbCUyMGZyb20lMjB0aGUlMjBmYWNlYm9vayUyRm5sbGItbW9lLTU0YiUyMHN0eWxlJTIwY29uZmlndXJhdGlvbiUwQW1vZGVsJTIwJTNEJTIwTmxsYk1vZU1vZGVsKGNvbmZpZ3VyYXRpb24pJTBBJTBBJTIzJTIwQWNjZXNzaW5nJTIwdGhlJTIwbW9kZWwlMjBjb25maWd1cmF0aW9uJTBBY29uZmlndXJhdGlvbiUyMCUzRCUyMG1vZGVsLmNvbmZpZw==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> NllbMoeModel, NllbMoeConfig

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a NllbMoe facebook/nllb-moe-54b style configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = NllbMoeConfig()

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a model from the facebook/nllb-moe-54b style configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = NllbMoeModel(configuration)

<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>configuration = model.config`,wrap:!1}}),{c(){r=d("p"),r.textContent=y,p=n(),u(h.$$.fragment)},l(i){r=c(i,"P",{"data-svelte-h":!0}),m(r)!=="svelte-11lpom8"&&(r.textContent=y),p=a(i),f(h.$$.fragment,i)},m(i,v){s(i,r,v),s(i,p,v),g(h,i,v),T=!0},p:Qe,i(i){T||(_(h.$$.fragment,i),T=!0)},o(i){b(h.$$.fragment,i),T=!1},d(i){i&&(o(r),o(p)),M(h,i)}}}function So(x){let r,y=`Although the recipe for forward pass needs to be defined within this function, one should call the <code>Module</code>
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`;return{c(){r=d("p"),r.innerHTML=y},l(p){r=c(p,"P",{"data-svelte-h":!0}),m(r)!=="svelte-fincs2"&&(r.innerHTML=y)},m(p,h){s(p,r,h)},p:Qe,d(p){p&&o(r)}}}function Po(x){let r,y=`Although the recipe for forward pass needs to be defined within this function, one should call the <code>Module</code>
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`;return{c(){r=d("p"),r.innerHTML=y},l(p){r=c(p,"P",{"data-svelte-h":!0}),m(r)!=="svelte-fincs2"&&(r.innerHTML=y)},m(p,h){s(p,r,h)},p:Qe,d(p){p&&o(r)}}}function Yo(x){let r,y="Example:",p,h,T;return h=new et({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBObGxiTW9lTW9kZWwlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJoZi1pbnRlcm5hbC10ZXN0aW5nJTJGcmFuZG9tLW5sbGItbW9lLTItZXhwZXJ0cyUyMiklMEFtb2RlbCUyMCUzRCUyMFN3aXRjaFRyYW5zZm9ybWVyc01vZGVsLmZyb21fcHJldHJhaW5lZCglMjJoZi1pbnRlcm5hbC10ZXN0aW5nJTJGcmFuZG9tLW5sbGItbW9lLTItZXhwZXJ0cyUyMiklMEElMEFpbnB1dF9pZHMlMjAlM0QlMjB0b2tlbml6ZXIoJTBBJTIwJTIwJTIwJTIwJTIyU3R1ZGllcyUyMGhhdmUlMjBiZWVuJTIwc2hvd24lMjB0aGF0JTIwb3duaW5nJTIwYSUyMGRvZyUyMGlzJTIwZ29vZCUyMGZvciUyMHlvdSUyMiUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIlMEEpLmlucHV0X2lkcyUyMCUyMCUyMyUyMEJhdGNoJTIwc2l6ZSUyMDElMEFkZWNvZGVyX2lucHV0X2lkcyUyMCUzRCUyMHRva2VuaXplciglMjJTdHVkaWVzJTIwc2hvdyUyMHRoYXQlMjIlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKS5pbnB1dF9pZHMlMjAlMjAlMjMlMjBCYXRjaCUyMHNpemUlMjAxJTBBJTBBJTIzJTIwcHJlcHJvY2VzcyUzQSUyMFByZXBlbmQlMjBkZWNvZGVyX2lucHV0X2lkcyUyMHdpdGglMjBzdGFydCUyMHRva2VuJTIwd2hpY2glMjBpcyUyMHBhZCUyMHRva2VuJTIwZm9yJTIwTmxsYk1vZU1vZGVsJTBBZGVjb2Rlcl9pbnB1dF9pZHMlMjAlM0QlMjBtb2RlbC5fc2hpZnRfcmlnaHQoZGVjb2Rlcl9pbnB1dF9pZHMpJTBBJTBBJTIzJTIwZm9yd2FyZCUyMHBhc3MlMEFvdXRwdXRzJTIwJTNEJTIwbW9kZWwoaW5wdXRfaWRzJTNEaW5wdXRfaWRzJTJDJTIwZGVjb2Rlcl9pbnB1dF9pZHMlM0RkZWNvZGVyX2lucHV0X2lkcyklMEFsYXN0X2hpZGRlbl9zdGF0ZXMlMjAlM0QlMjBvdXRwdXRzLmxhc3RfaGlkZGVuX3N0YXRl",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, NllbMoeModel

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;hf-internal-testing/random-nllb-moe-2-experts&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = SwitchTransformersModel.from_pretrained(<span class="hljs-string">&quot;hf-internal-testing/random-nllb-moe-2-experts&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>input_ids = tokenizer(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;Studies have been shown that owning a dog is good for you&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>
<span class="hljs-meta">... </span>).input_ids  <span class="hljs-comment"># Batch size 1</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>decoder_input_ids = tokenizer(<span class="hljs-string">&quot;Studies show that&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).input_ids  <span class="hljs-comment"># Batch size 1</span>

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># preprocess: Prepend decoder_input_ids with start token which is pad token for NllbMoeModel</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>decoder_input_ids = model._shift_right(decoder_input_ids)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># forward pass</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(input_ids=input_ids, decoder_input_ids=decoder_input_ids)
<span class="hljs-meta">&gt;&gt;&gt; </span>last_hidden_states = outputs.last_hidden_state`,wrap:!1}}),{c(){r=d("p"),r.textContent=y,p=n(),u(h.$$.fragment)},l(i){r=c(i,"P",{"data-svelte-h":!0}),m(r)!=="svelte-11lpom8"&&(r.textContent=y),p=a(i),f(h.$$.fragment,i)},m(i,v){s(i,r,v),s(i,p,v),g(h,i,v),T=!0},p:Qe,i(i){T||(_(h.$$.fragment,i),T=!0)},o(i){b(h.$$.fragment,i),T=!1},d(i){i&&(o(r),o(p)),M(h,i)}}}function Ao(x){let r,y=`Although the recipe for forward pass needs to be defined within this function, one should call the <code>Module</code>
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`;return{c(){r=d("p"),r.innerHTML=y},l(p){r=c(p,"P",{"data-svelte-h":!0}),m(r)!=="svelte-fincs2"&&(r.innerHTML=y)},m(p,h){s(p,r,h)},p:Qe,d(p){p&&o(r)}}}function Do(x){let r,y="Translation example:",p,h,T;return h=new et({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBObGxiTW9lRm9yQ29uZGl0aW9uYWxHZW5lcmF0aW9uJTBBJTBBbW9kZWwlMjAlM0QlMjBObGxiTW9lRm9yQ29uZGl0aW9uYWxHZW5lcmF0aW9uLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItbW9lLTU0YiUyMiklMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItbW9lLTU0YiUyMiklMEElMEF0ZXh0X3RvX3RyYW5zbGF0ZSUyMCUzRCUyMCUyMkxpZmUlMjBpcyUyMGxpa2UlMjBhJTIwYm94JTIwb2YlMjBjaG9jb2xhdGVzJTIyJTBBbW9kZWxfaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHRleHRfdG9fdHJhbnNsYXRlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEElMEElMjMlMjB0cmFuc2xhdGUlMjB0byUyMEZyZW5jaCUwQWdlbl90b2tlbnMlMjAlM0QlMjBtb2RlbC5nZW5lcmF0ZSgqKm1vZGVsX2lucHV0cyUyQyUyMGZvcmNlZF9ib3NfdG9rZW5faWQlM0R0b2tlbml6ZXIuZ2V0X2xhbmdfaWQoJTIyZW5nX0xhdG4lMjIpKSUwQXByaW50KHRva2VuaXplci5iYXRjaF9kZWNvZGUoZ2VuX3Rva2VucyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, NllbMoeForConditionalGeneration

<span class="hljs-meta">&gt;&gt;&gt; </span>model = NllbMoeForConditionalGeneration.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-moe-54b&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-moe-54b&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>text_to_translate = <span class="hljs-string">&quot;Life is like a box of chocolates&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model_inputs = tokenizer(text_to_translate, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># translate to French</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>gen_tokens = model.generate(**model_inputs, forced_bos_token_id=tokenizer.get_lang_id(<span class="hljs-string">&quot;eng_Latn&quot;</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(tokenizer.batch_decode(gen_tokens, skip_special_tokens=<span class="hljs-literal">True</span>))`,wrap:!1}}),{c(){r=d("p"),r.textContent=y,p=n(),u(h.$$.fragment)},l(i){r=c(i,"P",{"data-svelte-h":!0}),m(r)!=="svelte-g2jatv"&&(r.textContent=y),p=a(i),f(h.$$.fragment,i)},m(i,v){s(i,r,v),s(i,p,v),g(h,i,v),T=!0},p:Qe,i(i){T||(_(h.$$.fragment,i),T=!0)},o(i){b(h.$$.fragment,i),T=!1},d(i){i&&(o(r),o(p)),M(h,i)}}}function Oo(x){let r,y,p,h,T,i,v,tt,Q,co=`The NLLB model was presented in <a href="https://arxiv.org/abs/2207.04672" rel="nofollow">No Language Left Behind: Scaling Human-Centered Machine Translation</a> by Marta R. Costa-jussà, James Cross, Onur Çelebi,
Maha Elbayad, Kenneth Heafield, Kevin Heffernan, Elahe Kalbassi, Janice Lam, Daniel Licht, Jean Maillard, Anna Sun, Skyler Wang, Guillaume Wenzek, Al Youngblood, Bapi Akula,
Loic Barrault, Gabriel Mejia Gonzalez, Prangthip Hansanti, John Hoffman, Semarley Jarrett, Kaushik Ram Sadagopan, Dirk Rowe, Shannon Spruit, Chau Tran, Pierre Andrews,
Necip Fazil Ayan, Shruti Bhosale, Sergey Edunov, Angela Fan, Cynthia Gao, Vedanuj Goswami, Francisco Guzmán, Philipp Koehn, Alexandre Mourachko, Christophe Ropers,
Safiyyah Saleem, Holger Schwenk, and Jeff Wang.`,ot,K,po="The abstract of the paper is the following:",nt,ee,mo=`<em>Driven by the goal of eradicating language barriers on a global scale, machine translation has solidified itself as a key focus of artificial intelligence research today.
However, such efforts have coalesced around a small subset of languages, leaving behind the vast majority of mostly low-resource languages. What does it take to break the
200 language barrier while ensuring safe, high quality results, all while keeping ethical considerations in mind? In No Language Left Behind, we took on this challenge by
first contextualizing the need for low-resource language translation support through exploratory interviews with native speakers. Then, we created datasets and models aimed
at narrowing the performance gap between low and high-resource languages. More specifically, we developed a conditional compute model based on Sparsely Gated Mixture of
Experts that is trained on data obtained with novel and effective data mining techniques tailored for low-resource languages. We propose multiple architectural and training
improvements to counteract overfitting while training on thousands of tasks. Critically, we evaluated the performance of over 40,000 different translation directions using
a human-translated benchmark, Flores-200, and combined human evaluation with a novel toxicity benchmark covering all languages in Flores-200 to assess translation safety.
Our model achieves an improvement of 44% BLEU relative to the previous state-of-the-art, laying important groundwork towards realizing a universal translation system.</em>`,at,te,ho=`This model was contributed by <a href="https://huggingface.co/ArthurZ" rel="nofollow">Arthur Zucker</a>.
The original code can be found <a href="https://github.com/facebookresearch/fairseq" rel="nofollow">here</a>.`,st,oe,rt,ne,uo="<li>M2M100ForConditionalGeneration is the base model for both NLLB and NLLB MoE</li> <li>The NLLB-MoE is very similar to the NLLB model, but it’s feed forward layer is based on the implementation of SwitchTransformers.</li> <li>The tokenizer is the same as the NLLB models.</li>",lt,ae,it,se,fo=`The biggest difference is the way the tokens are routed. NLLB-MoE uses a <code>top-2-gate</code> which means that for each input, only the top two experts are selected based on the
highest predicted probabilities from the gating network, and the remaining experts are ignored. In <code>SwitchTransformers</code>, only the top-1 probabilities are computed,
which means that tokens have less probability of being forwarded. Moreover, if a token is not routed to any expert, <code>SwitchTransformers</code> still adds its unmodified hidden
states (kind of like a residual connection) while they are masked in <code>NLLB</code>’s top-2 routing mechanism.`,dt,re,ct,le,go="The available checkpoints require around 350GB of storage. Make sure to use <code>accelerate</code> if you do not have enough RAM on your machine.",pt,ie,_o=`While generating the target text set the <code>forced_bos_token_id</code> to the target language id. The following
example shows how to translate English to French using the <em>facebook/nllb-200-distilled-600M</em> model.`,mt,de,bo=`Note that we’re using the BCP-47 code for French <code>fra_Latn</code>. See <a href="https://github.com/facebookresearch/flores/blob/main/flores200/README.md#languages-in-flores-200" rel="nofollow">here</a>
for the list of all BCP-47 in the Flores 200 dataset.`,ht,ce,ut,pe,ft,me,Mo=`English (<code>eng_Latn</code>) is set as the default language from which to translate. In order to specify that you’d like to translate from a different language,
you should specify the BCP-47 code in the <code>src_lang</code> keyword argument of the tokenizer initialization.`,gt,he,yo="See example below for a translation from romanian to german:",_t,ue,bt,fe,Mt,ge,To='<li><a href="../tasks/translation">Translation task guide</a></li> <li><a href="../tasks/summarization">Summarization task guide</a></li>',yt,_e,Tt,N,be,Jt,Ze,vo=`This is the configuration class to store the configuration of a <a href="/docs/transformers/main/en/model_doc/nllb-moe#transformers.NllbMoeModel">NllbMoeModel</a>. It is used to instantiate an
NLLB-MoE model according to the specified arguments, defining the model architecture. Instantiating a configuration
with the defaults will yield a similar configuration to that of the NLLB-MoE
<a href="https://huggingface.co/facebook/nllb-moe-54b" rel="nofollow">facebook/nllb-moe-54b</a> architecture.`,Ft,Ge,wo=`Configuration objects inherit from <a href="/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig">PretrainedConfig</a> and can be used to control the model outputs. Read the
documentation from <a href="/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig">PretrainedConfig</a> for more information.`,Zt,I,vt,Me,wt,w,ye,Gt,qe,ko="Router using tokens choose top-2 experts assignment.",qt,Le,$o=`This router uses the same mechanism as in NLLB-MoE from the fairseq repository. Items are sorted by router_probs
and then routed to their choice of expert until the expert’s expert_capacity is reached. <strong>There is no guarantee
that each token is processed by an expert</strong>, or that each expert receives at least one token.`,Lt,We,xo="The router combining weights are also returned to make sure that the states that are not updated will be masked.",Wt,H,Te,Rt,Re,No=`Computes the <code>dispatch_mask</code> and the <code>dispatch_weights</code> for each experts. The masks are adapted to the expert
capacity.`,Bt,E,ve,It,Be,Co=`The hidden states are reshaped to simplify the computation of the router probabilities (combining weights for
each experts.)`,kt,we,$t,q,ke,Ht,Ie,jo="Implementation of the NLLB-MoE sparse MLP module.",Et,z,$e,Vt,He,zo=`The goal of this forward pass is to have the same number of operation as the equivalent <code>NllbMoeDenseActDense</code>
(mlp) layer. This means that all of the hidden states should be processed at most twice ( since we are using a
top_2 gating mecanism). This means that we keep the complexity to O(batch_size x sequence_length x hidden_dim)
instead of O(num_experts x batch_size x sequence_length x hidden_dim).`,Xt,Ee,Uo=`1- Get the <code>router_probs</code> from the <code>router</code>. The shape of the <code>router_mask</code> is <code>(batch_size X sequence_length, num_expert)</code> and corresponds to the boolean version of the <code>router_probs</code>. The inputs are masked using the
<code>router_mask</code>.`,St,Ve,Jo=`2- Dispatch the hidden_states to its associated experts. The router probabilities are used to weight the
contribution of each experts when updating the masked hidden states.`,xt,xe,Nt,C,Ne,Pt,Xe,Fo=`The bare NllbMoe Model outputting raw hidden-states without any specific head on top.
This model inherits from <a href="/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>. 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.)`,Yt,Se,Zo=`This model is also a PyTorch <a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module" rel="nofollow">torch.nn.Module</a> subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`,At,k,Ce,Dt,Pe,Go='The <a href="/docs/transformers/main/en/model_doc/nllb-moe#transformers.NllbMoeModel">NllbMoeModel</a> forward method, overrides the <code>__call__</code> special method.',Ot,V,Qt,Ye,qo='The <a href="/docs/transformers/main/en/model_doc/nllb-moe#transformers.NllbMoeModel">NllbMoeModel</a> forward method, overrides the <code>__call__</code> special method.',Kt,X,eo,S,Ct,je,jt,j,ze,to,Ae,Lo=`The NllbMoe Model with a language modeling head. Can be used for summarization.
This model inherits from <a href="/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>. 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.)`,oo,De,Wo=`This model is also a PyTorch <a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module" rel="nofollow">torch.nn.Module</a> subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`,no,U,Ue,ao,Oe,Ro='The <a href="/docs/transformers/main/en/model_doc/nllb-moe#transformers.NllbMoeForConditionalGeneration">NllbMoeForConditionalGeneration</a> forward method, overrides the <code>__call__</code> special method.',so,P,ro,Y,zt,Ke,Ut;return T=new G({props:{title:"NLLB-MOE",local:"nllb-moe",headingTag:"h1"}}),v=new G({props:{title:"Overview",local:"overview",headingTag:"h2"}}),oe=new G({props:{title:"Usage tips",local:"usage-tips",headingTag:"h2"}}),ae=new G({props:{title:"Implementation differences with SwitchTransformers",local:"implementation-differences-with-switchtransformers",headingTag:"h2"}}),re=new G({props:{title:"Generating with NLLB-MoE",local:"generating-with-nllb-moe",headingTag:"h2"}}),ce=new et({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcTJTZXFMTSUyQyUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItbW9lLTU0YiUyMiklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvclNlcTJTZXFMTS5mcm9tX3ByZXRyYWluZWQoJTIyZmFjZWJvb2slMkZubGxiLW1vZS01NGIlMjIpJTBBJTBBYXJ0aWNsZSUyMCUzRCUyMCUyMlByZXZpb3VzbHklMkMlMjBSaW5nJ3MlMjBDRU8lMkMlMjBKYW1pZSUyMFNpbWlub2ZmJTJDJTIwcmVtYXJrZWQlMjB0aGUlMjBjb21wYW55JTIwc3RhcnRlZCUyMHdoZW4lMjBoaXMlMjBkb29yYmVsbCUyMHdhc24ndCUyMGF1ZGlibGUlMjBmcm9tJTIwaGlzJTIwc2hvcCUyMGluJTIwaGlzJTIwZ2FyYWdlLiUyMiUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplcihhcnRpY2xlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEElMEF0cmFuc2xhdGVkX3Rva2VucyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCUwQSUyMCUyMCUyMCUyMCoqaW5wdXRzJTJDJTIwZm9yY2VkX2Jvc190b2tlbl9pZCUzRHRva2VuaXplci5sYW5nX2NvZGVfdG9faWQlNUIlMjJmcmFfTGF0biUyMiU1RCUyQyUyMG1heF9sZW5ndGglM0Q1MCUwQSklMEF0b2tlbml6ZXIuYmF0Y2hfZGVjb2RlKHRyYW5zbGF0ZWRfdG9rZW5zJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUpJTVCMCU1RA==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSeq2SeqLM, AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-moe-54b&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSeq2SeqLM.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-moe-54b&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>article = <span class="hljs-string">&quot;Previously, Ring&#x27;s CEO, Jamie Siminoff, remarked the company started when his doorbell wasn&#x27;t audible from his shop in his garage.&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(article, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>translated_tokens = model.generate(
<span class="hljs-meta">... </span>    **inputs, forced_bos_token_id=tokenizer.lang_code_to_id[<span class="hljs-string">&quot;fra_Latn&quot;</span>], max_length=<span class="hljs-number">50</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.batch_decode(translated_tokens, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]
<span class="hljs-string">&quot;Auparavant, le PDG de Ring, Jamie Siminoff, a fait remarquer que la société avait commencé lorsque sa sonnette n&#x27;était pas audible depuis son magasin dans son garage.&quot;</span>`,wrap:!1}}),pe=new G({props:{title:"Generating from any other language than English",local:"generating-from-any-other-language-than-english",headingTag:"h3"}}),ue=new et({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcTJTZXFMTSUyQyUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItbW9lLTU0YiUyMiUyQyUyMHNyY19sYW5nJTNEJTIycm9uX0xhdG4lMjIpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JTZXEyU2VxTE0uZnJvbV9wcmV0cmFpbmVkKCUyMmZhY2Vib29rJTJGbmxsYi1tb2UtNTRiJTIyKSUwQSUwQWFydGljbGUlMjAlM0QlMjAlMjIlQzUlOUVlZnVsJTIwT05VJTIwc3B1bmUlMjBjJUM0JTgzJTIwbnUlMjBleGlzdCVDNCU4MyUyMG8lMjBzb2x1JUM1JUEzaWUlMjBtaWxpdGFyJUM0JTgzJTIwJUMzJUFFbiUyMFNpcmlhJTIyJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKGFydGljbGUlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQSUwQXRyYW5zbGF0ZWRfdG9rZW5zJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoJTBBJTIwJTIwJTIwJTIwKippbnB1dHMlMkMlMjBmb3JjZWRfYm9zX3Rva2VuX2lkJTNEdG9rZW5pemVyLmxhbmdfY29kZV90b19pZCU1QiUyMmRldV9MYXRuJTIyJTVEJTJDJTIwbWF4X2xlbmd0aCUzRDMwJTBBKSUwQXRva2VuaXplci5iYXRjaF9kZWNvZGUodHJhbnNsYXRlZF90b2tlbnMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSklNUIwJTVE",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSeq2SeqLM, AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-moe-54b&quot;</span>, src_lang=<span class="hljs-string">&quot;ron_Latn&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSeq2SeqLM.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-moe-54b&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>article = <span class="hljs-string">&quot;Şeful ONU spune că nu există o soluţie militară în Siria&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(article, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>translated_tokens = model.generate(
<span class="hljs-meta">... </span>    **inputs, forced_bos_token_id=tokenizer.lang_code_to_id[<span class="hljs-string">&quot;deu_Latn&quot;</span>], max_length=<span class="hljs-number">30</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.batch_decode(translated_tokens, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]`,wrap:!1}}),fe=new G({props:{title:"Resources",local:"resources",headingTag:"h2"}}),_e=new G({props:{title:"NllbMoeConfig",local:"transformers.NllbMoeConfig",headingTag:"h2"}}),be=new R({props:{name:"class transformers.NllbMoeConfig",anchor:"transformers.NllbMoeConfig",parameters:[{name:"vocab_size",val:" = 128112"},{name:"max_position_embeddings",val:" = 1024"},{name:"encoder_layers",val:" = 12"},{name:"encoder_ffn_dim",val:" = 4096"},{name:"encoder_attention_heads",val:" = 16"},{name:"decoder_layers",val:" = 12"},{name:"decoder_ffn_dim",val:" = 4096"},{name:"decoder_attention_heads",val:" = 16"},{name:"encoder_layerdrop",val:" = 0.05"},{name:"decoder_layerdrop",val:" = 0.05"},{name:"use_cache",val:" = True"},{name:"is_encoder_decoder",val:" = True"},{name:"activation_function",val:" = 'relu'"},{name:"d_model",val:" = 1024"},{name:"dropout",val:" = 0.1"},{name:"attention_dropout",val:" = 0.1"},{name:"activation_dropout",val:" = 0.0"},{name:"init_std",val:" = 0.02"},{name:"decoder_start_token_id",val:" = 2"},{name:"scale_embedding",val:" = True"},{name:"router_bias",val:" = False"},{name:"router_dtype",val:" = 'float32'"},{name:"router_ignore_padding_tokens",val:" = False"},{name:"num_experts",val:" = 128"},{name:"expert_capacity",val:" = 64"},{name:"encoder_sparse_step",val:" = 4"},{name:"decoder_sparse_step",val:" = 4"},{name:"router_z_loss_coef",val:" = 0.001"},{name:"router_aux_loss_coef",val:" = 0.001"},{name:"second_expert_policy",val:" = 'all'"},{name:"normalize_router_prob_before_dropping",val:" = False"},{name:"batch_prioritized_routing",val:" = False"},{name:"moe_eval_capacity_token_fraction",val:" = 1.0"},{name:"moe_token_dropout",val:" = 0.2"},{name:"pad_token_id",val:" = 1"},{name:"bos_token_id",val:" = 0"},{name:"eos_token_id",val:" = 2"},{name:"output_router_logits",val:" = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.NllbMoeConfig.vocab_size",description:`<strong>vocab_size</strong> (<code>int</code>, <em>optional</em>, defaults to 50265) &#x2014;
Vocabulary size of the NllbMoe model. Defines the number of different tokens that can be represented by the
<code>inputs_ids</code> passed when calling <a href="/docs/transformers/main/en/model_doc/nllb-moe#transformers.NllbMoeModel">NllbMoeModel</a> or`,name:"vocab_size"},{anchor:"transformers.NllbMoeConfig.d_model",description:`<strong>d_model</strong> (<code>int</code>, <em>optional</em>, defaults to 1024) &#x2014;
Dimensionality of the layers and the pooler layer.`,name:"d_model"},{anchor:"transformers.NllbMoeConfig.encoder_layers",description:`<strong>encoder_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 12) &#x2014;
Number of encoder layers.`,name:"encoder_layers"},{anchor:"transformers.NllbMoeConfig.decoder_layers",description:`<strong>decoder_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 12) &#x2014;
Number of decoder layers.`,name:"decoder_layers"},{anchor:"transformers.NllbMoeConfig.encoder_attention_heads",description:`<strong>encoder_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to 16) &#x2014;
Number of attention heads for each attention layer in the Transformer encoder.`,name:"encoder_attention_heads"},{anchor:"transformers.NllbMoeConfig.decoder_attention_heads",description:`<strong>decoder_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to 16) &#x2014;
Number of attention heads for each attention layer in the Transformer decoder.`,name:"decoder_attention_heads"},{anchor:"transformers.NllbMoeConfig.decoder_ffn_dim",description:`<strong>decoder_ffn_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 4096) &#x2014;
Dimensionality of the &#x201C;intermediate&#x201D; (often named feed-forward) layer in decoder.`,name:"decoder_ffn_dim"},{anchor:"transformers.NllbMoeConfig.encoder_ffn_dim",description:`<strong>encoder_ffn_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 4096) &#x2014;
Dimensionality of the &#x201C;intermediate&#x201D; (often named feed-forward) layer in encoder.`,name:"encoder_ffn_dim"},{anchor:"transformers.NllbMoeConfig.activation_function",description:`<strong>activation_function</strong> (<code>str</code> or <code>function</code>, <em>optional</em>, defaults to <code>&quot;gelu&quot;</code>) &#x2014;
The non-linear activation function (function or string) in the encoder and pooler. If string, <code>&quot;gelu&quot;</code>,
<code>&quot;relu&quot;</code>, <code>&quot;silu&quot;</code> and <code>&quot;gelu_new&quot;</code> are supported.`,name:"activation_function"},{anchor:"transformers.NllbMoeConfig.dropout",description:`<strong>dropout</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.`,name:"dropout"},{anchor:"transformers.NllbMoeConfig.attention_dropout",description:`<strong>attention_dropout</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
The dropout ratio for the attention probabilities.`,name:"attention_dropout"},{anchor:"transformers.NllbMoeConfig.activation_dropout",description:`<strong>activation_dropout</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
The dropout ratio for activations inside the fully connected layer.`,name:"activation_dropout"},{anchor:"transformers.NllbMoeConfig.classifier_dropout",description:`<strong>classifier_dropout</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
The dropout ratio for classifier.`,name:"classifier_dropout"},{anchor:"transformers.NllbMoeConfig.max_position_embeddings",description:`<strong>max_position_embeddings</strong> (<code>int</code>, <em>optional</em>, defaults to 1024) &#x2014;
The maximum sequence length that this model might ever be used with. Typically set this to something large
just in case (e.g., 512 or 1024 or 2048).`,name:"max_position_embeddings"},{anchor:"transformers.NllbMoeConfig.init_std",description:`<strong>init_std</strong> (<code>float</code>, <em>optional</em>, defaults to 0.02) &#x2014;
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.`,name:"init_std"},{anchor:"transformers.NllbMoeConfig.encoder_layerdrop",description:`<strong>encoder_layerdrop</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
The LayerDrop probability for the encoder. See the [LayerDrop paper](see <a href="https://arxiv.org/abs/1909.11556" rel="nofollow">https://arxiv.org/abs/1909.11556</a>)
for more details.`,name:"encoder_layerdrop"},{anchor:"transformers.NllbMoeConfig.decoder_layerdrop",description:`<strong>decoder_layerdrop</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
The LayerDrop probability for the decoder. See the [LayerDrop paper](see <a href="https://arxiv.org/abs/1909.11556" rel="nofollow">https://arxiv.org/abs/1909.11556</a>)
for more details.`,name:"decoder_layerdrop"},{anchor:"transformers.NllbMoeConfig.second_expert_policy",description:`<strong>second_expert_policy</strong> ( <code>str</code>, <em>optional</em>, default to <code>&quot;all&quot;</code>) &#x2014;
The policy used for the sampling the probability of being sampled to a second expert for each token.`,name:"second_expert_policy"},{anchor:"transformers.NllbMoeConfig.normalize_router_prob_before_dropping",description:`<strong>normalize_router_prob_before_dropping</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to normalize the router probabilities before applying a mask based on the experts capacity
(capacity dropping).`,name:"normalize_router_prob_before_dropping"},{anchor:"transformers.NllbMoeConfig.batch_prioritized_routing",description:`<strong>batch_prioritized_routing</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to orders the tokens by their router probabilities before capacity dropping. This means that
the tokens that have the highest probabilities will be routed before other tokens that might be further in
the sequence.`,name:"batch_prioritized_routing"},{anchor:"transformers.NllbMoeConfig.moe_eval_capacity_token_fraction",description:`<strong>moe_eval_capacity_token_fraction</strong> (<code>float</code>, <em>optional</em>, defaults to 1.0) &#x2014;
Fraction of tokens as capacity during validation, if set to negative, uses the same as training. Should be
in range: (0.0, 1.0].`,name:"moe_eval_capacity_token_fraction"},{anchor:"transformers.NllbMoeConfig.num_experts",description:`<strong>num_experts</strong> (<code>int</code>, <em>optional</em>, defaults to 128) &#x2014;
Number of experts for each NllbMoeSparseMlp layer.`,name:"num_experts"},{anchor:"transformers.NllbMoeConfig.expert_capacity",description:`<strong>expert_capacity</strong> (<code>int</code>, <em>optional</em>, defaults to 64) &#x2014;
Number of tokens that can be stored in each expert.`,name:"expert_capacity"},{anchor:"transformers.NllbMoeConfig.encoder_sparse_step",description:`<strong>encoder_sparse_step</strong> (<code>int</code>, <em>optional</em>, defaults to 4) &#x2014;
Frequency of the sparse layers in the encoder. 4 means that one out of 4 layers will be sparse.`,name:"encoder_sparse_step"},{anchor:"transformers.NllbMoeConfig.decoder_sparse_step",description:`<strong>decoder_sparse_step</strong> (<code>int</code>, <em>optional</em>, defaults to 4) &#x2014;
Frequency of the sparse layers in the decoder. 4 means that one out of 4 layers will be sparse.`,name:"decoder_sparse_step"},{anchor:"transformers.NllbMoeConfig.router_dtype",description:`<strong>router_dtype</strong> (<code>str</code>, <em>optional</em>, default to <code>&quot;float32&quot;</code>) &#x2014;
The <code>dtype</code> used for the routers. It is preferable to keep the <code>dtype</code> to <code>&quot;float32&quot;</code> as specified in the
<em>selective precision</em> discussion in <a href="https://arxiv.org/abs/2101.03961" rel="nofollow">the paper</a>.`,name:"router_dtype"},{anchor:"transformers.NllbMoeConfig.router_ignore_padding_tokens",description:`<strong>router_ignore_padding_tokens</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to ignore padding tokens when routing. if <code>False</code>, the padding tokens are not routed to any
experts.`,name:"router_ignore_padding_tokens"},{anchor:"transformers.NllbMoeConfig.router_bias",description:`<strong>router_bias</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not the classifier of the router should have a bias.`,name:"router_bias"},{anchor:"transformers.NllbMoeConfig.moe_token_dropout",description:`<strong>moe_token_dropout</strong> (<code>float</code>, <em>optional</em>, defualt ot 0.2) &#x2014;
Masking rate for MoE expert output masking (EOM), which is implemented via a Dropout2d on the expert
outputs.`,name:"moe_token_dropout"},{anchor:"transformers.NllbMoeConfig.output_router_logits",description:`<strong>output_router_logits</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not to return the router logits. Only set to <code>True</code> to get the auxiliary loss when training.`,name:"output_router_logits"},{anchor:"transformers.NllbMoeConfig.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not the model should return the last key/values attentions (not used by all models).`,name:"use_cache"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb_moe/configuration_nllb_moe.py#L27"}}),I=new io({props:{anchor:"transformers.NllbMoeConfig.example",$$slots:{default:[Xo]},$$scope:{ctx:x}}}),Me=new G({props:{title:"NllbMoeTop2Router",local:"transformers.NllbMoeTop2Router",headingTag:"h2"}}),ye=new R({props:{name:"class transformers.NllbMoeTop2Router",anchor:"transformers.NllbMoeTop2Router",parameters:[{name:"config",val:": NllbMoeConfig"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb_moe/modeling_nllb_moe.py#L217"}}),Te=new R({props:{name:"route_tokens",anchor:"transformers.NllbMoeTop2Router.route_tokens",parameters:[{name:"router_logits",val:": Tensor"},{name:"input_dtype",val:": dtype = torch.float32"},{name:"padding_mask",val:": Optional = None"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb_moe/modeling_nllb_moe.py#L258"}}),ve=new R({props:{name:"forward",anchor:"transformers.NllbMoeTop2Router.forward",parameters:[{name:"hidden_states",val:": Tensor"},{name:"padding_mask",val:": Optional = None"}],parametersDescription:[{anchor:"transformers.NllbMoeTop2Router.forward.hidden_states",description:`<strong>hidden_states</strong> (<code>torch.Tensor</code>) &#x2014;
(batch_size, sequence_length, hidden_dim) from which router probabilities are computed.`,name:"hidden_states"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb_moe/modeling_nllb_moe.py#L343",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>Index tensor of shape [batch_size, sequence_length] corresponding to the expert selected for each token
using the top1 probabilities of the router.
router_probabilities (<code>torch.Tensor</code> of shape (batch_size, sequence_length, nump_experts)):
Tensor of shape (batch_size, sequence_length, num_experts) corresponding to the probabilities for each
token and expert. Used for routing tokens to experts.
router_logits (<code>torch.Tensor</code> of shape (batch_size, sequence_length))):
Logits tensor of shape (batch_size, sequence_length, num_experts) corresponding to raw router logits.
This is used later for computing router z-loss.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p>top_1_mask (<code>torch.Tensor</code> of shape (batch_size, sequence_length))</p>
`}}),we=new G({props:{title:"NllbMoeSparseMLP",local:"transformers.NllbMoeSparseMLP",headingTag:"h2"}}),ke=new R({props:{name:"class transformers.NllbMoeSparseMLP",anchor:"transformers.NllbMoeSparseMLP",parameters:[{name:"config",val:": NllbMoeConfig"},{name:"ffn_dim",val:": int"},{name:"expert_class",val:": Module = <class 'transformers.models.nllb_moe.modeling_nllb_moe.NllbMoeDenseActDense'>"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb_moe/modeling_nllb_moe.py#L394"}}),$e=new R({props:{name:"forward",anchor:"transformers.NllbMoeSparseMLP.forward",parameters:[{name:"hidden_states",val:": Tensor"},{name:"padding_mask",val:": Optional = False"}],parametersDescription:[{anchor:"transformers.NllbMoeSparseMLP.forward.hidden_states",description:`<strong>hidden_states</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length, hidden_dim)</code>) &#x2014;
The hidden states`,name:"hidden_states"},{anchor:"transformers.NllbMoeSparseMLP.forward.padding_mask",description:`<strong>padding_mask</strong> (<code>torch.Tensor</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Attention mask. Can be in the causal form or not.`,name:"padding_mask"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb_moe/modeling_nllb_moe.py#L410",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>Updated hidden states
router_logits (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length, num_experts)</code>):
Needed for computing the loss</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p>hidden_states (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length, hidden_dim)</code>)</p>
`}}),xe=new G({props:{title:"NllbMoeModel",local:"transformers.NllbMoeModel",headingTag:"h2"}}),Ne=new R({props:{name:"class transformers.NllbMoeModel",anchor:"transformers.NllbMoeModel",parameters:[{name:"config",val:": NllbMoeConfig"}],parametersDescription:[{anchor:"transformers.NllbMoeModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/main/en/model_doc/nllb-moe#transformers.NllbMoeConfig">NllbMoeConfig</a>) &#x2014;
Model configuration class with all the parameters of the model. Initializing with a config file does not
load the weights associated with the model, only the configuration. Check out the
<a href="/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb_moe/modeling_nllb_moe.py#L1452"}}),Ce=new R({props:{name:"forward",anchor:"transformers.NllbMoeModel.forward",parameters:[{name:"input_ids",val:": Optional = None"},{name:"attention_mask",val:": Optional = None"},{name:"decoder_input_ids",val:": Optional = None"},{name:"decoder_attention_mask",val:": Optional = None"},{name:"head_mask",val:": Optional = None"},{name:"decoder_head_mask",val:": Optional = None"},{name:"cross_attn_head_mask",val:": Optional = None"},{name:"encoder_outputs",val:": Optional = None"},{name:"past_key_values",val:": Optional = None"},{name:"inputs_embeds",val:": Optional = None"},{name:"decoder_inputs_embeds",val:": Optional = None"},{name:"use_cache",val:": Optional = None"},{name:"output_attentions",val:": Optional = None"},{name:"output_hidden_states",val:": Optional = None"},{name:"output_router_logits",val:": Optional = None"},{name:"return_dict",val:": Optional = None"}],parametersDescription:[{anchor:"transformers.NllbMoeModel.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
it.`,name:"input_ids"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb_moe/modeling_nllb_moe.py#L1490",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A <code>transformers.modeling_outputs.Seq2SeqMoEModelOutput</code> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/main/en/model_doc/nllb-moe#transformers.NllbMoeConfig"
>NllbMoeConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>) — Sequence of hidden-states at the output of the last layer of the decoder of the model.</p>
<p>If <code>past_key_values</code> is used only the last hidden-state of the sequences of shape <code>(batch_size, 1, hidden_size)</code> is output.</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>) — 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>) — 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 optional 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>) — 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>decoder_router_logits</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_router_logits=True</code> is passed or when <code>config.add_router_probs=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, sequence_length, num_experts)</code>.</p>
<p>Router logits of the decoder model, useful to compute the auxiliary loss for Mixture of Experts models.</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>) — 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’s 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>) — 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>) — 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 optional 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>) — 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>
<li>
<p><strong>encoder_router_logits</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_router_logits=True</code> is passed or when <code>config.add_router_probs=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, sequence_length, num_experts)</code>.</p>
<p>Router logits of the encoder model, useful to compute the auxiliary loss and the z_loss for the sparse
modules.</p>
</li>
</ul>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>transformers.modeling_outputs.Seq2SeqMoEModelOutput</code> or <code>tuple(torch.FloatTensor)</code></p>
`}}),V=new lo({props:{$$slots:{default:[So]},$$scope:{ctx:x}}}),X=new lo({props:{$$slots:{default:[Po]},$$scope:{ctx:x}}}),S=new io({props:{anchor:"transformers.NllbMoeModel.forward.example",$$slots:{default:[Yo]},$$scope:{ctx:x}}}),je=new G({props:{title:"NllbMoeForConditionalGeneration",local:"transformers.NllbMoeForConditionalGeneration",headingTag:"h2"}}),ze=new R({props:{name:"class transformers.NllbMoeForConditionalGeneration",anchor:"transformers.NllbMoeForConditionalGeneration",parameters:[{name:"config",val:": NllbMoeConfig"}],parametersDescription:[{anchor:"transformers.NllbMoeForConditionalGeneration.config",description:`<strong>config</strong> (<a href="/docs/transformers/main/en/model_doc/nllb-moe#transformers.NllbMoeConfig">NllbMoeConfig</a>) &#x2014;
Model configuration class with all the parameters of the model. Initializing with a config file does not
load the weights associated with the model, only the configuration. Check out the
<a href="/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb_moe/modeling_nllb_moe.py#L1590"}}),Ue=new R({props:{name:"forward",anchor:"transformers.NllbMoeForConditionalGeneration.forward",parameters:[{name:"input_ids",val:": Optional = None"},{name:"attention_mask",val:": Optional = None"},{name:"decoder_input_ids",val:": Optional = None"},{name:"decoder_attention_mask",val:": Optional = None"},{name:"head_mask",val:": Optional = None"},{name:"decoder_head_mask",val:": Optional = None"},{name:"cross_attn_head_mask",val:": Optional = None"},{name:"encoder_outputs",val:": Optional = None"},{name:"past_key_values",val:": Optional = None"},{name:"inputs_embeds",val:": Optional = None"},{name:"decoder_inputs_embeds",val:": Optional = None"},{name:"labels",val:": Optional = None"},{name:"use_cache",val:": Optional = None"},{name:"output_attentions",val:": Optional = None"},{name:"output_hidden_states",val:": Optional = None"},{name:"output_router_logits",val:": Optional = None"},{name:"return_dict",val:": Optional = None"}],parametersDescription:[{anchor:"transformers.NllbMoeForConditionalGeneration.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
it.</p>
<p>Indices can be obtained using <a href="/docs/transformers/main/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/main/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/main/en/model_doc/fastspeech2_conformer#transformers.FastSpeech2ConformerTokenizer.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a>`,name:"input_ids"},{anchor:"transformers.NllbMoeForConditionalGeneration.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.NllbMoeForConditionalGeneration.forward.decoder_input_ids",description:`<strong>decoder_input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Indices of decoder input sequence tokens in the vocabulary.</p>
<p>Indices can be obtained using <a href="/docs/transformers/main/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/main/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/main/en/model_doc/fastspeech2_conformer#transformers.FastSpeech2ConformerTokenizer.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#decoder-input-ids">What are decoder input IDs?</a></p>
<p>NllbMoe uses the <code>eos_token_id</code> as the starting token for <code>decoder_input_ids</code> generation. 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>).`,name:"decoder_input_ids"},{anchor:"transformers.NllbMoeForConditionalGeneration.forward.decoder_attention_mask",description:`<strong>decoder_attention_mask</strong> (<code>torch.LongTensor</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.NllbMoeForConditionalGeneration.forward.head_mask",description:`<strong>head_mask</strong> (<code>torch.Tensor</code> of shape <code>(encoder_layers, encoder_attention_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the attention modules in the encoder. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 indicates the head is <strong>not masked</strong>,</li>
<li>0 indicates the head is <strong>masked</strong>.</li>
</ul>`,name:"head_mask"},{anchor:"transformers.NllbMoeForConditionalGeneration.forward.decoder_head_mask",description:`<strong>decoder_head_mask</strong> (<code>torch.Tensor</code> of shape <code>(decoder_layers, decoder_attention_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the attention modules in the decoder. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 indicates the head is <strong>not masked</strong>,</li>
<li>0 indicates the head is <strong>masked</strong>.</li>
</ul>`,name:"decoder_head_mask"},{anchor:"transformers.NllbMoeForConditionalGeneration.forward.cross_attn_head_mask",description:`<strong>cross_attn_head_mask</strong> (<code>torch.Tensor</code> of shape <code>(decoder_layers, decoder_attention_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the cross-attention modules in the decoder. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 indicates the head is <strong>not masked</strong>,</li>
<li>0 indicates the head is <strong>masked</strong>.</li>
</ul>`,name:"cross_attn_head_mask"},{anchor:"transformers.NllbMoeForConditionalGeneration.forward.encoder_outputs",description:`<strong>encoder_outputs</strong> (<code>tuple(tuple(torch.FloatTensor)</code>, <em>optional</em>) &#x2014;
Tuple consists of (<code>last_hidden_state</code>, <em>optional</em>: <code>hidden_states</code>, <em>optional</em>: <code>attentions</code>)
<code>last_hidden_state</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) is a sequence 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.NllbMoeForConditionalGeneration.forward.past_key_values",description:`<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>) &#x2014;
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>
<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.NllbMoeForConditionalGeneration.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>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>input_ids</code> indices into associated vectors
than the model&#x2019;s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.NllbMoeForConditionalGeneration.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. If <code>past_key_values</code> is used, optionally only the last <code>decoder_inputs_embeds</code> have to be
input (see <code>past_key_values</code>). 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.</p>
<p>If <code>decoder_input_ids</code> and <code>decoder_inputs_embeds</code> are both unset, <code>decoder_inputs_embeds</code> takes the value
of <code>inputs_embeds</code>.`,name:"decoder_inputs_embeds"},{anchor:"transformers.NllbMoeForConditionalGeneration.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.NllbMoeForConditionalGeneration.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.NllbMoeForConditionalGeneration.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.NllbMoeForConditionalGeneration.forward.output_router_logits",description:`<strong>output_router_logits</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the logits of all the routers. They are useful for computing the router loss, and
should not be returned during inference.`,name:"output_router_logits"},{anchor:"transformers.NllbMoeForConditionalGeneration.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/main/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.NllbMoeForConditionalGeneration.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. Indices should either be in <code>[0, ..., config.vocab_size]</code> or -100 (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"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb_moe/modeling_nllb_moe.py#L1619",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A <code>transformers.modeling_outputs.Seq2SeqMoEOutput</code> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/main/en/model_doc/nllb-moe#transformers.NllbMoeConfig"
>NllbMoeConfig</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) — 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>) — 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>) — 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>) — 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>) — 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>decoder_router_logits</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_router_logits=True</code> is passed or when <code>config.add_router_probs=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, sequence_length, num_experts)</code>.</p>
<p>Router logits of the decoder model, useful to compute the auxiliary loss for Mixture of Experts models.</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>) — 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’s 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>) — 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>) — 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>) — 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>
<li>
<p><strong>encoder_router_logits</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_router_logits=True</code> is passed or when <code>config.add_router_probs=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, sequence_length, num_experts)</code>.</p>
<p>Router logits of the encoder model, useful to compute the auxiliary loss and z_loss for Mixture of Experts
models.</p>
</li>
</ul>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>transformers.modeling_outputs.Seq2SeqMoEOutput</code> or <code>tuple(torch.FloatTensor)</code></p>
`}}),P=new lo({props:{$$slots:{default:[Ao]},$$scope:{ctx:x}}}),Y=new io({props:{anchor:"transformers.NllbMoeForConditionalGeneration.forward.example",$$slots:{default:[Do]},$$scope:{ctx:x}}}),{c(){r=d("meta"),y=n(),p=d("p"),h=n(),u(T.$$.fragment),i=n(),u(v.$$.fragment),tt=n(),Q=d("p"),Q.innerHTML=co,ot=n(),K=d("p"),K.textContent=po,nt=n(),ee=d("p"),ee.innerHTML=mo,at=n(),te=d("p"),te.innerHTML=ho,st=n(),u(oe.$$.fragment),rt=n(),ne=d("ul"),ne.innerHTML=uo,lt=n(),u(ae.$$.fragment),it=n(),se=d("p"),se.innerHTML=fo,dt=n(),u(re.$$.fragment),ct=n(),le=d("p"),le.innerHTML=go,pt=n(),ie=d("p"),ie.innerHTML=_o,mt=n(),de=d("p"),de.innerHTML=bo,ht=n(),u(ce.$$.fragment),ut=n(),u(pe.$$.fragment),ft=n(),me=d("p"),me.innerHTML=Mo,gt=n(),he=d("p"),he.textContent=yo,_t=n(),u(ue.$$.fragment),bt=n(),u(fe.$$.fragment),Mt=n(),ge=d("ul"),ge.innerHTML=To,yt=n(),u(_e.$$.fragment),Tt=n(),N=d("div"),u(be.$$.fragment),Jt=n(),Ze=d("p"),Ze.innerHTML=vo,Ft=n(),Ge=d("p"),Ge.innerHTML=wo,Zt=n(),u(I.$$.fragment),vt=n(),u(Me.$$.fragment),wt=n(),w=d("div"),u(ye.$$.fragment),Gt=n(),qe=d("p"),qe.textContent=ko,qt=n(),Le=d("p"),Le.innerHTML=$o,Lt=n(),We=d("p"),We.textContent=xo,Wt=n(),H=d("div"),u(Te.$$.fragment),Rt=n(),Re=d("p"),Re.innerHTML=No,Bt=n(),E=d("div"),u(ve.$$.fragment),It=n(),Be=d("p"),Be.textContent=Co,kt=n(),u(we.$$.fragment),$t=n(),q=d("div"),u(ke.$$.fragment),Ht=n(),Ie=d("p"),Ie.textContent=jo,Et=n(),z=d("div"),u($e.$$.fragment),Vt=n(),He=d("p"),He.innerHTML=zo,Xt=n(),Ee=d("p"),Ee.innerHTML=Uo,St=n(),Ve=d("p"),Ve.textContent=Jo,xt=n(),u(xe.$$.fragment),Nt=n(),C=d("div"),u(Ne.$$.fragment),Pt=n(),Xe=d("p"),Xe.innerHTML=Fo,Yt=n(),Se=d("p"),Se.innerHTML=Zo,At=n(),k=d("div"),u(Ce.$$.fragment),Dt=n(),Pe=d("p"),Pe.innerHTML=Go,Ot=n(),u(V.$$.fragment),Qt=n(),Ye=d("p"),Ye.innerHTML=qo,Kt=n(),u(X.$$.fragment),eo=n(),u(S.$$.fragment),Ct=n(),u(je.$$.fragment),jt=n(),j=d("div"),u(ze.$$.fragment),to=n(),Ae=d("p"),Ae.innerHTML=Lo,oo=n(),De=d("p"),De.innerHTML=Wo,no=n(),U=d("div"),u(Ue.$$.fragment),ao=n(),Oe=d("p"),Oe.innerHTML=Ro,so=n(),u(P.$$.fragment),ro=n(),u(Y.$$.fragment),zt=n(),Ke=d("p"),this.h()},l(e){const t=Vo("svelte-u9bgzb",document.head);r=c(t,"META",{name:!0,content:!0}),t.forEach(o),y=a(e),p=c(e,"P",{}),F(p).forEach(o),h=a(e),f(T.$$.fragment,e),i=a(e),f(v.$$.fragment,e),tt=a(e),Q=c(e,"P",{"data-svelte-h":!0}),m(Q)!=="svelte-12x4cpm"&&(Q.innerHTML=co),ot=a(e),K=c(e,"P",{"data-svelte-h":!0}),m(K)!=="svelte-wu27l3"&&(K.textContent=po),nt=a(e),ee=c(e,"P",{"data-svelte-h":!0}),m(ee)!=="svelte-1j7uypk"&&(ee.innerHTML=mo),at=a(e),te=c(e,"P",{"data-svelte-h":!0}),m(te)!=="svelte-10n1tet"&&(te.innerHTML=ho),st=a(e),f(oe.$$.fragment,e),rt=a(e),ne=c(e,"UL",{"data-svelte-h":!0}),m(ne)!=="svelte-1d7jqov"&&(ne.innerHTML=uo),lt=a(e),f(ae.$$.fragment,e),it=a(e),se=c(e,"P",{"data-svelte-h":!0}),m(se)!=="svelte-udi8rb"&&(se.innerHTML=fo),dt=a(e),f(re.$$.fragment,e),ct=a(e),le=c(e,"P",{"data-svelte-h":!0}),m(le)!=="svelte-19ah26a"&&(le.innerHTML=go),pt=a(e),ie=c(e,"P",{"data-svelte-h":!0}),m(ie)!=="svelte-gz9jek"&&(ie.innerHTML=_o),mt=a(e),de=c(e,"P",{"data-svelte-h":!0}),m(de)!=="svelte-c2ujwv"&&(de.innerHTML=bo),ht=a(e),f(ce.$$.fragment,e),ut=a(e),f(pe.$$.fragment,e),ft=a(e),me=c(e,"P",{"data-svelte-h":!0}),m(me)!=="svelte-ets0jr"&&(me.innerHTML=Mo),gt=a(e),he=c(e,"P",{"data-svelte-h":!0}),m(he)!=="svelte-14hvt1f"&&(he.textContent=yo),_t=a(e),f(ue.$$.fragment,e),bt=a(e),f(fe.$$.fragment,e),Mt=a(e),ge=c(e,"UL",{"data-svelte-h":!0}),m(ge)!=="svelte-6ej6p2"&&(ge.innerHTML=To),yt=a(e),f(_e.$$.fragment,e),Tt=a(e),N=c(e,"DIV",{class:!0});var L=F(N);f(be.$$.fragment,L),Jt=a(L),Ze=c(L,"P",{"data-svelte-h":!0}),m(Ze)!=="svelte-1l2hikf"&&(Ze.innerHTML=vo),Ft=a(L),Ge=c(L,"P",{"data-svelte-h":!0}),m(Ge)!=="svelte-o55m63"&&(Ge.innerHTML=wo),Zt=a(L),f(I.$$.fragment,L),L.forEach(o),vt=a(e),f(Me.$$.fragment,e),wt=a(e),w=c(e,"DIV",{class:!0});var $=F(w);f(ye.$$.fragment,$),Gt=a($),qe=c($,"P",{"data-svelte-h":!0}),m(qe)!=="svelte-1j1lh5i"&&(qe.textContent=ko),qt=a($),Le=c($,"P",{"data-svelte-h":!0}),m(Le)!=="svelte-ov8d9x"&&(Le.innerHTML=$o),Lt=a($),We=c($,"P",{"data-svelte-h":!0}),m(We)!=="svelte-1wf6mr8"&&(We.textContent=xo),Wt=a($),H=c($,"DIV",{class:!0});var Je=F(H);f(Te.$$.fragment,Je),Rt=a(Je),Re=c(Je,"P",{"data-svelte-h":!0}),m(Re)!=="svelte-xjs57s"&&(Re.innerHTML=No),Je.forEach(o),Bt=a($),E=c($,"DIV",{class:!0});var Fe=F(E);f(ve.$$.fragment,Fe),It=a(Fe),Be=c(Fe,"P",{"data-svelte-h":!0}),m(Be)!=="svelte-19860ws"&&(Be.textContent=Co),Fe.forEach(o),$.forEach(o),kt=a(e),f(we.$$.fragment,e),$t=a(e),q=c(e,"DIV",{class:!0});var B=F(q);f(ke.$$.fragment,B),Ht=a(B),Ie=c(B,"P",{"data-svelte-h":!0}),m(Ie)!=="svelte-35dv9n"&&(Ie.textContent=jo),Et=a(B),z=c(B,"DIV",{class:!0});var W=F(z);f($e.$$.fragment,W),Vt=a(W),He=c(W,"P",{"data-svelte-h":!0}),m(He)!=="svelte-znv5vs"&&(He.innerHTML=zo),Xt=a(W),Ee=c(W,"P",{"data-svelte-h":!0}),m(Ee)!=="svelte-bpke9a"&&(Ee.innerHTML=Uo),St=a(W),Ve=c(W,"P",{"data-svelte-h":!0}),m(Ve)!=="svelte-t4vd7i"&&(Ve.textContent=Jo),W.forEach(o),B.forEach(o),xt=a(e),f(xe.$$.fragment,e),Nt=a(e),C=c(e,"DIV",{class:!0});var A=F(C);f(Ne.$$.fragment,A),Pt=a(A),Xe=c(A,"P",{"data-svelte-h":!0}),m(Xe)!=="svelte-s8v7kl"&&(Xe.innerHTML=Fo),Yt=a(A),Se=c(A,"P",{"data-svelte-h":!0}),m(Se)!=="svelte-hswkmf"&&(Se.innerHTML=Zo),At=a(A),k=c(A,"DIV",{class:!0});var J=F(k);f(Ce.$$.fragment,J),Dt=a(J),Pe=c(J,"P",{"data-svelte-h":!0}),m(Pe)!=="svelte-1ugew6t"&&(Pe.innerHTML=Go),Ot=a(J),f(V.$$.fragment,J),Qt=a(J),Ye=c(J,"P",{"data-svelte-h":!0}),m(Ye)!=="svelte-1ugew6t"&&(Ye.innerHTML=qo),Kt=a(J),f(X.$$.fragment,J),eo=a(J),f(S.$$.fragment,J),J.forEach(o),A.forEach(o),Ct=a(e),f(je.$$.fragment,e),jt=a(e),j=c(e,"DIV",{class:!0});var D=F(j);f(ze.$$.fragment,D),to=a(D),Ae=c(D,"P",{"data-svelte-h":!0}),m(Ae)!=="svelte-2fq6bb"&&(Ae.innerHTML=Lo),oo=a(D),De=c(D,"P",{"data-svelte-h":!0}),m(De)!=="svelte-hswkmf"&&(De.innerHTML=Wo),no=a(D),U=c(D,"DIV",{class:!0});var O=F(U);f(Ue.$$.fragment,O),ao=a(O),Oe=c(O,"P",{"data-svelte-h":!0}),m(Oe)!=="svelte-zf431p"&&(Oe.innerHTML=Ro),so=a(O),f(P.$$.fragment,O),ro=a(O),f(Y.$$.fragment,O),O.forEach(o),D.forEach(o),zt=a(e),Ke=c(e,"P",{}),F(Ke).forEach(o),this.h()},h(){Z(r,"name","hf:doc:metadata"),Z(r,"content",Qo),Z(N,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(H,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(E,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(w,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(z,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(q,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(k,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(C,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(U,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(j,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,t){l(document.head,r),s(e,y,t),s(e,p,t),s(e,h,t),g(T,e,t),s(e,i,t),g(v,e,t),s(e,tt,t),s(e,Q,t),s(e,ot,t),s(e,K,t),s(e,nt,t),s(e,ee,t),s(e,at,t),s(e,te,t),s(e,st,t),g(oe,e,t),s(e,rt,t),s(e,ne,t),s(e,lt,t),g(ae,e,t),s(e,it,t),s(e,se,t),s(e,dt,t),g(re,e,t),s(e,ct,t),s(e,le,t),s(e,pt,t),s(e,ie,t),s(e,mt,t),s(e,de,t),s(e,ht,t),g(ce,e,t),s(e,ut,t),g(pe,e,t),s(e,ft,t),s(e,me,t),s(e,gt,t),s(e,he,t),s(e,_t,t),g(ue,e,t),s(e,bt,t),g(fe,e,t),s(e,Mt,t),s(e,ge,t),s(e,yt,t),g(_e,e,t),s(e,Tt,t),s(e,N,t),g(be,N,null),l(N,Jt),l(N,Ze),l(N,Ft),l(N,Ge),l(N,Zt),g(I,N,null),s(e,vt,t),g(Me,e,t),s(e,wt,t),s(e,w,t),g(ye,w,null),l(w,Gt),l(w,qe),l(w,qt),l(w,Le),l(w,Lt),l(w,We),l(w,Wt),l(w,H),g(Te,H,null),l(H,Rt),l(H,Re),l(w,Bt),l(w,E),g(ve,E,null),l(E,It),l(E,Be),s(e,kt,t),g(we,e,t),s(e,$t,t),s(e,q,t),g(ke,q,null),l(q,Ht),l(q,Ie),l(q,Et),l(q,z),g($e,z,null),l(z,Vt),l(z,He),l(z,Xt),l(z,Ee),l(z,St),l(z,Ve),s(e,xt,t),g(xe,e,t),s(e,Nt,t),s(e,C,t),g(Ne,C,null),l(C,Pt),l(C,Xe),l(C,Yt),l(C,Se),l(C,At),l(C,k),g(Ce,k,null),l(k,Dt),l(k,Pe),l(k,Ot),g(V,k,null),l(k,Qt),l(k,Ye),l(k,Kt),g(X,k,null),l(k,eo),g(S,k,null),s(e,Ct,t),g(je,e,t),s(e,jt,t),s(e,j,t),g(ze,j,null),l(j,to),l(j,Ae),l(j,oo),l(j,De),l(j,no),l(j,U),g(Ue,U,null),l(U,ao),l(U,Oe),l(U,so),g(P,U,null),l(U,ro),g(Y,U,null),s(e,zt,t),s(e,Ke,t),Ut=!0},p(e,[t]){const L={};t&2&&(L.$$scope={dirty:t,ctx:e}),I.$set(L);const $={};t&2&&($.$$scope={dirty:t,ctx:e}),V.$set($);const Je={};t&2&&(Je.$$scope={dirty:t,ctx:e}),X.$set(Je);const Fe={};t&2&&(Fe.$$scope={dirty:t,ctx:e}),S.$set(Fe);const B={};t&2&&(B.$$scope={dirty:t,ctx:e}),P.$set(B);const W={};t&2&&(W.$$scope={dirty:t,ctx:e}),Y.$set(W)},i(e){Ut||(_(T.$$.fragment,e),_(v.$$.fragment,e),_(oe.$$.fragment,e),_(ae.$$.fragment,e),_(re.$$.fragment,e),_(ce.$$.fragment,e),_(pe.$$.fragment,e),_(ue.$$.fragment,e),_(fe.$$.fragment,e),_(_e.$$.fragment,e),_(be.$$.fragment,e),_(I.$$.fragment,e),_(Me.$$.fragment,e),_(ye.$$.fragment,e),_(Te.$$.fragment,e),_(ve.$$.fragment,e),_(we.$$.fragment,e),_(ke.$$.fragment,e),_($e.$$.fragment,e),_(xe.$$.fragment,e),_(Ne.$$.fragment,e),_(Ce.$$.fragment,e),_(V.$$.fragment,e),_(X.$$.fragment,e),_(S.$$.fragment,e),_(je.$$.fragment,e),_(ze.$$.fragment,e),_(Ue.$$.fragment,e),_(P.$$.fragment,e),_(Y.$$.fragment,e),Ut=!0)},o(e){b(T.$$.fragment,e),b(v.$$.fragment,e),b(oe.$$.fragment,e),b(ae.$$.fragment,e),b(re.$$.fragment,e),b(ce.$$.fragment,e),b(pe.$$.fragment,e),b(ue.$$.fragment,e),b(fe.$$.fragment,e),b(_e.$$.fragment,e),b(be.$$.fragment,e),b(I.$$.fragment,e),b(Me.$$.fragment,e),b(ye.$$.fragment,e),b(Te.$$.fragment,e),b(ve.$$.fragment,e),b(we.$$.fragment,e),b(ke.$$.fragment,e),b($e.$$.fragment,e),b(xe.$$.fragment,e),b(Ne.$$.fragment,e),b(Ce.$$.fragment,e),b(V.$$.fragment,e),b(X.$$.fragment,e),b(S.$$.fragment,e),b(je.$$.fragment,e),b(ze.$$.fragment,e),b(Ue.$$.fragment,e),b(P.$$.fragment,e),b(Y.$$.fragment,e),Ut=!1},d(e){e&&(o(y),o(p),o(h),o(i),o(tt),o(Q),o(ot),o(K),o(nt),o(ee),o(at),o(te),o(st),o(rt),o(ne),o(lt),o(it),o(se),o(dt),o(ct),o(le),o(pt),o(ie),o(mt),o(de),o(ht),o(ut),o(ft),o(me),o(gt),o(he),o(_t),o(bt),o(Mt),o(ge),o(yt),o(Tt),o(N),o(vt),o(wt),o(w),o(kt),o($t),o(q),o(xt),o(Nt),o(C),o(Ct),o(jt),o(j),o(zt),o(Ke)),o(r),M(T,e),M(v,e),M(oe,e),M(ae,e),M(re,e),M(ce,e),M(pe,e),M(ue,e),M(fe,e),M(_e,e),M(be),M(I),M(Me,e),M(ye),M(Te),M(ve),M(we,e),M(ke),M($e),M(xe,e),M(Ne),M(Ce),M(V),M(X),M(S),M(je,e),M(ze),M(Ue),M(P),M(Y)}}}const Qo='{"title":"NLLB-MOE","local":"nllb-moe","sections":[{"title":"Overview","local":"overview","sections":[],"depth":2},{"title":"Usage tips","local":"usage-tips","sections":[],"depth":2},{"title":"Implementation differences with SwitchTransformers","local":"implementation-differences-with-switchtransformers","sections":[],"depth":2},{"title":"Generating with NLLB-MoE","local":"generating-with-nllb-moe","sections":[{"title":"Generating from any other language than English","local":"generating-from-any-other-language-than-english","sections":[],"depth":3}],"depth":2},{"title":"Resources","local":"resources","sections":[],"depth":2},{"title":"NllbMoeConfig","local":"transformers.NllbMoeConfig","sections":[],"depth":2},{"title":"NllbMoeTop2Router","local":"transformers.NllbMoeTop2Router","sections":[],"depth":2},{"title":"NllbMoeSparseMLP","local":"transformers.NllbMoeSparseMLP","sections":[],"depth":2},{"title":"NllbMoeModel","local":"transformers.NllbMoeModel","sections":[],"depth":2},{"title":"NllbMoeForConditionalGeneration","local":"transformers.NllbMoeForConditionalGeneration","sections":[],"depth":2}],"depth":1}';function Ko(x){return Io(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ln extends Ho{constructor(r){super(),Eo(this,r,Ko,Oo,Bo,{})}}export{ln as component};
