import{S as el,i as tl,s as ol,e as s,k as l,w as T,t as r,M as rl,c as a,d as o,m as c,a as i,x as v,h as n,b as d,G as e,g as m,y as b,q as y,o as k,B as S,v as nl,L as vi}from"../../chunks/vendor-hf-doc-builder.js";import{T as wi}from"../../chunks/Tip-hf-doc-builder.js";import{D as G}from"../../chunks/Docstring-hf-doc-builder.js";import{C as bi}from"../../chunks/CodeBlock-hf-doc-builder.js";import{I as fe}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{E as Ti}from"../../chunks/ExampleCodeBlock-hf-doc-builder.js";function sl(C){let u,x,g,_,w;return{c(){u=s("p"),x=r("Although the recipe for forward pass needs to be defined within this function, one should call the "),g=s("code"),_=r("Module"),w=r(`
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(h){u=a(h,"P",{});var f=i(u);x=n(f,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=a(f,"CODE",{});var F=i(g);_=n(F,"Module"),F.forEach(o),w=n(f,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),f.forEach(o)},m(h,f){m(h,u,f),e(u,x),e(u,g),e(g,_),e(u,w)},d(h){h&&o(u)}}}function al(C){let u,x,g,_,w;return _=new bi({props:{code:`from transformers import AutoTokenizer, SwitchTransformersModel

tokenizer = AutoTokenizer.from_pretrained("google/switch-base-8")
model = SwitchTransformersModel.from_pretrained("google/switch-base-8")

input_ids = tokenizer(
    "Studies have been shown that owning a dog is good for you", return_tensors="pt"
).input_ids  # Batch size 1
decoder_input_ids = tokenizer("Studies show that", return_tensors="pt").input_ids  # Batch size 1

# preprocess: Prepend decoder_input_ids with start token which is pad token for SwitchTransformersModel.
# This is not needed for torch's SwitchTransformersForConditionalGeneration as it does this internally using labels arg.
decoder_input_ids = model._shift_right(decoder_input_ids)

# forward pass
outputs = model(input_ids=input_ids, decoder_input_ids=decoder_input_ids)
last_hidden_states = outputs.last_hidden_state`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, SwitchTransformersModel

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;google/switch-base-8&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = SwitchTransformersModel.from_pretrained(<span class="hljs-string">&quot;google/switch-base-8&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 SwitchTransformersModel.</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># This is not needed for torch&#x27;s SwitchTransformersForConditionalGeneration as it does this internally using labels arg.</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`}}),{c(){u=s("p"),x=r("Example:"),g=l(),T(_.$$.fragment)},l(h){u=a(h,"P",{});var f=i(u);x=n(f,"Example:"),f.forEach(o),g=c(h),v(_.$$.fragment,h)},m(h,f){m(h,u,f),e(u,x),m(h,g,f),b(_,h,f),w=!0},p:vi,i(h){w||(y(_.$$.fragment,h),w=!0)},o(h){k(_.$$.fragment,h),w=!1},d(h){h&&o(u),h&&o(g),S(_,h)}}}function il(C){let u,x,g,_,w;return{c(){u=s("p"),x=r("Although the recipe for forward pass needs to be defined within this function, one should call the "),g=s("code"),_=r("Module"),w=r(`
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(h){u=a(h,"P",{});var f=i(u);x=n(f,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=a(f,"CODE",{});var F=i(g);_=n(F,"Module"),F.forEach(o),w=n(f,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),f.forEach(o)},m(h,f){m(h,u,f),e(u,x),e(u,g),e(g,_),e(u,w)},d(h){h&&o(u)}}}function dl(C){let u,x,g,_,w;return _=new bi({props:{code:`from transformers import AutoTokenizer, SwitchTransformersForConditionalGeneration

tokenizer = AutoTokenizer.from_pretrained("google/switch-base-8")
model = SwitchTransformersForConditionalGeneration.from_pretrained("google/switch-base-8")

# training
input_ids = tokenizer("The <extra_id_0> walks in <extra_id_1> park", return_tensors="pt").input_ids
labels = tokenizer("<extra_id_0> cute dog <extra_id_1> the <extra_id_2>", return_tensors="pt").input_ids
outputs = model(input_ids=input_ids, labels=labels)
loss = outputs.loss
logits = outputs.logits

# inference
input_ids = tokenizer(
    "summarize: studies have shown that owning a dog is good for you", return_tensors="pt"
).input_ids  # Batch size 1
outputs = model.generate(input_ids)
# . To, let\u2019s say you have a dog. To summarize:
# Since the model has been trained on MLM, this will output gibberish`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, SwitchTransformersForConditionalGeneration

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;google/switch-base-8&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = SwitchTransformersForConditionalGeneration.from_pretrained(<span class="hljs-string">&quot;google/switch-base-8&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># training</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>input_ids = tokenizer(<span class="hljs-string">&quot;The &lt;extra_id_0&gt; walks in &lt;extra_id_1&gt; park&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).input_ids
<span class="hljs-meta">&gt;&gt;&gt; </span>labels = tokenizer(<span class="hljs-string">&quot;&lt;extra_id_0&gt; cute dog &lt;extra_id_1&gt; the &lt;extra_id_2&gt;&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).input_ids
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(input_ids=input_ids, labels=labels)
<span class="hljs-meta">&gt;&gt;&gt; </span>loss = outputs.loss
<span class="hljs-meta">&gt;&gt;&gt; </span>logits = outputs.logits

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># inference</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>input_ids = tokenizer(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;summarize: studies have 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>outputs = model.generate(input_ids)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># . To, let\u2019s say you have a dog. To summarize:</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Since the model has been trained on MLM, this will output gibberish</span>`}}),{c(){u=s("p"),x=r("Examples:"),g=l(),T(_.$$.fragment)},l(h){u=a(h,"P",{});var f=i(u);x=n(f,"Examples:"),f.forEach(o),g=c(h),v(_.$$.fragment,h)},m(h,f){m(h,u,f),e(u,x),m(h,g,f),b(_,h,f),w=!0},p:vi,i(h){w||(y(_.$$.fragment,h),w=!0)},o(h){k(_.$$.fragment,h),w=!1},d(h){h&&o(u),h&&o(g),S(_,h)}}}function ll(C){let u,x,g,_,w;return{c(){u=s("p"),x=r("Although the recipe for forward pass needs to be defined within this function, one should call the "),g=s("code"),_=r("Module"),w=r(`
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(h){u=a(h,"P",{});var f=i(u);x=n(f,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=a(f,"CODE",{});var F=i(g);_=n(F,"Module"),F.forEach(o),w=n(f,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),f.forEach(o)},m(h,f){m(h,u,f),e(u,x),e(u,g),e(g,_),e(u,w)},d(h){h&&o(u)}}}function cl(C){let u,x,g,_,w;return _=new bi({props:{code:`from transformers import AutoTokenizer, SwitchTransformersEncoderModel

tokenizer = AutoTokenizer.from_pretrained("google/switch-base-8")
model = SwitchTransformersEncoderModel.from_pretrained("google/switch-base-8")
input_ids = tokenizer(
    "Studies have been shown that owning a dog is good for you", return_tensors="pt"
).input_ids  # Batch size 1
outputs = model(input_ids=input_ids)
last_hidden_states = outputs.last_hidden_state`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, SwitchTransformersEncoderModel

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;google/switch-base-8&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = SwitchTransformersEncoderModel.from_pretrained(<span class="hljs-string">&quot;google/switch-base-8&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>outputs = model(input_ids=input_ids)
<span class="hljs-meta">&gt;&gt;&gt; </span>last_hidden_states = outputs.last_hidden_state`}}),{c(){u=s("p"),x=r("Example:"),g=l(),T(_.$$.fragment)},l(h){u=a(h,"P",{});var f=i(u);x=n(f,"Example:"),f.forEach(o),g=c(h),v(_.$$.fragment,h)},m(h,f){m(h,u,f),e(u,x),m(h,g,f),b(_,h,f),w=!0},p:vi,i(h){w||(y(_.$$.fragment,h),w=!0)},o(h){k(_.$$.fragment,h),w=!1},d(h){h&&o(u),h&&o(g),S(_,h)}}}function hl(C){let u,x,g,_,w,h,f,F,Vr,rr,te,_e,uo,De,Zr,mo,Ur,nr,ge,Xr,Le,Yr,Jr,sr,Dt,Kr,ar,Lt,Qr,ir,Bt,fo,en,dr,Gt,tn,lr,we,Be,on,Ht,rn,nn,sn,Ge,an,He,dn,ln,cr,O,cn,Ve,hn,pn,Ze,un,mn,Ue,fn,_n,hr,oe,Te,_o,Xe,gn,go,wn,pr,ve,wo,Vt,Tn,vn,To,Zt,bn,ur,re,be,vo,Ye,yn,bo,kn,mr,H,Je,Sn,ne,xn,Ut,$n,En,Ke,Mn,zn,Cn,se,Fn,Xt,qn,Pn,Yt,An,Rn,fr,ae,ye,yo,Qe,On,ko,Nn,_r,z,et,In,So,jn,Wn,V,Dn,tt,Ln,Bn,ot,Gn,Hn,xo,Vn,Zn,Un,ke,rt,Xn,$o,Yn,Jn,X,nt,Kn,ie,Qn,Eo,es,ts,Mo,os,rs,ns,q,ss,zo,as,is,Co,ds,ls,Fo,cs,hs,qo,ps,us,gr,de,Se,Po,st,ms,Ao,fs,wr,Z,at,_s,Ro,gs,ws,N,it,Ts,Oo,vs,bs,U,ys,No,ks,Ss,Io,xs,$s,jo,Es,Ms,zs,Wo,Cs,Tr,le,xe,Do,dt,Fs,Lo,qs,vr,$,lt,Ps,Bo,As,Rs,P,Os,ct,Ns,Is,ht,js,Ws,pt,Ds,Ls,ut,Bs,Gs,Hs,mt,Vs,Jt,Zs,Us,Xs,ft,Ys,_t,Js,Ks,Qs,I,gt,ea,ce,ta,Kt,oa,ra,Go,na,sa,aa,$e,ia,Ee,br,he,Me,Ho,wt,da,Vo,la,yr,E,Tt,ca,vt,ha,Zo,pa,ua,ma,A,fa,bt,_a,ga,yt,wa,Ta,kt,va,ba,St,ya,ka,Sa,xt,xa,Qt,$a,Ea,Ma,$t,za,Et,Ca,Fa,qa,j,Mt,Pa,pe,Aa,eo,Ra,Oa,Uo,Na,Ia,ja,ze,Wa,Ce,kr,ue,Fe,Xo,zt,Da,Yo,La,Sr,M,Ct,Ba,Jo,Ga,Ha,R,Va,Ft,Za,Ua,qt,Xa,Ya,Pt,Ja,Ka,At,Qa,ei,ti,Rt,oi,to,ri,ni,si,Ot,ai,Nt,ii,di,li,W,It,ci,me,hi,oo,pi,ui,Ko,mi,fi,_i,qe,gi,Pe,xr;return h=new fe({}),De=new fe({}),Xe=new fe({}),Ye=new fe({}),Je=new G({props:{name:"class transformers.SwitchTransformersConfig",anchor:"transformers.SwitchTransformersConfig",parameters:[{name:"vocab_size",val:" = 32128"},{name:"d_model",val:" = 768"},{name:"d_kv",val:" = 64"},{name:"d_ff",val:" = 2048"},{name:"expert_capacity",val:" = 64"},{name:"num_layers",val:" = 12"},{name:"num_sparse_encoder_layers",val:" = 3"},{name:"num_decoder_layers",val:" = 12"},{name:"num_sparse_decoder_layers",val:" = 3"},{name:"num_heads",val:" = 12"},{name:"num_experts",val:" = 8"},{name:"router_type",val:" = 'tokens_masked'"},{name:"router_bias",val:" = False"},{name:"router_jitter_noise",val:" = 0.01"},{name:"router_dtype",val:" = 'float32'"},{name:"router_ignore_padding_tokens",val:" = False"},{name:"relative_attention_num_buckets",val:" = 32"},{name:"relative_attention_max_distance",val:" = 128"},{name:"dropout_rate",val:" = 0.1"},{name:"layer_norm_epsilon",val:" = 1e-06"},{name:"router_z_loss_coef",val:" = 0.001"},{name:"router_aux_loss_coef",val:" = 0.001"},{name:"initializer_factor",val:" = 1.0"},{name:"feed_forward_proj",val:" = 'relu'"},{name:"is_encoder_decoder",val:" = True"},{name:"add_router_probs",val:" = False"},{name:"use_cache",val:" = True"},{name:"pad_token_id",val:" = 0"},{name:"eos_token_id",val:" = 1"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.SwitchTransformersConfig.vocab_size",description:`<strong>vocab_size</strong> (<code>int</code>, <em>optional</em>, defaults to 32128) &#x2014;
Vocabulary size of the SwitchTransformers model. Defines the number of different tokens that can be
represented by the <code>inputs_ids</code> passed when calling <a href="/docs/transformers/v4.27.1/en/model_doc/switch_transformers#transformers.SwitchTransformersModel">SwitchTransformersModel</a>.`,name:"vocab_size"},{anchor:"transformers.SwitchTransformersConfig.d_model",description:`<strong>d_model</strong> (<code>int</code>, <em>optional</em>, defaults to 512) &#x2014;
Size of the encoder layers and the pooler layer.`,name:"d_model"},{anchor:"transformers.SwitchTransformersConfig.d_kv",description:`<strong>d_kv</strong> (<code>int</code>, <em>optional</em>, defaults to 64) &#x2014;
Size of the key, query, value projections per attention head. <code>d_kv</code> has to be equal to <code>d_model // num_heads</code>.`,name:"d_kv"},{anchor:"transformers.SwitchTransformersConfig.d_ff",description:`<strong>d_ff</strong> (<code>int</code>, <em>optional</em>, defaults to 2048) &#x2014;
Size of the intermediate feed forward layer in each <code>SwitchTransformersBlock</code>.`,name:"d_ff"},{anchor:"transformers.SwitchTransformersConfig.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. If set to 1, the model will behave like a regular
Transformer.`,name:"expert_capacity"},{anchor:"transformers.SwitchTransformersConfig.num_layers",description:`<strong>num_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 12) &#x2014;
Number of dense hidden layers in the Transformer encoder layer.`,name:"num_layers"},{anchor:"transformers.SwitchTransformersConfig.num_sparse_encoder_layers",description:`<strong>num_sparse_encoder_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 6) &#x2014;
Number of sparse (MoE) dense hidden layers in the Transformer encoder layer.`,name:"num_sparse_encoder_layers"},{anchor:"transformers.SwitchTransformersConfig.num_decoder_layers",description:`<strong>num_decoder_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 12) &#x2014;
Number of hidden layers in the Transformer decoder. Will use the same value as <code>num_layers</code> if not set.`,name:"num_decoder_layers"},{anchor:"transformers.SwitchTransformersConfig.num_sparse_decoder_layers",description:`<strong>num_sparse_decoder_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 12) &#x2014;
Number of sparse (MoE) dense hidden layers in the Transformer decoder layer.`,name:"num_sparse_decoder_layers"},{anchor:"transformers.SwitchTransformersConfig.num_heads",description:`<strong>num_heads</strong> (<code>int</code>, <em>optional</em>, defaults to 8) &#x2014;
Number of attention heads for each attention layer in the Transformer encoder.`,name:"num_heads"},{anchor:"transformers.SwitchTransformersConfig.num_experts",description:`<strong>num_experts</strong> (<code>int</code>, <em>optional</em>, defaults to 8) &#x2014;
Number of experts for each SwitchTransformer layer.`,name:"num_experts"},{anchor:"transformers.SwitchTransformersConfig.router_type",description:"<strong>router_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;tokens_masked&quot;</code>) &#x2014;\nRouter type - choose between <code>&quot;tokens_masked&quot;, </code>&#x201C;tokens_scatter&#x201D;<code>and</code>&#x201C;experts_masked&#x201D;`.",name:"router_type"},{anchor:"transformers.SwitchTransformersConfig.router_bias",description:`<strong>router_bias</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to add a bias to the router.`,name:"router_bias"},{anchor:"transformers.SwitchTransformersConfig.router_jitter_noise",description:`<strong>router_jitter_noise</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
Amount of noise to add to the router.`,name:"router_jitter_noise"},{anchor:"transformers.SwitchTransformersConfig.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.SwitchTransformersConfig.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.`,name:"router_ignore_padding_tokens"},{anchor:"transformers.SwitchTransformersConfig.relative_attention_num_buckets",description:`<strong>relative_attention_num_buckets</strong> (<code>int</code>, <em>optional</em>, defaults to 32) &#x2014;
The number of buckets to use for each attention layer.`,name:"relative_attention_num_buckets"},{anchor:"transformers.SwitchTransformersConfig.relative_attention_max_distance",description:`<strong>relative_attention_max_distance</strong> (<code>int</code>, <em>optional</em>, defaults to 128) &#x2014;
The maximum distance of the longer sequences for the bucket separation.`,name:"relative_attention_max_distance"},{anchor:"transformers.SwitchTransformersConfig.dropout_rate",description:`<strong>dropout_rate</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
The ratio for all dropout layers.`,name:"dropout_rate"},{anchor:"transformers.SwitchTransformersConfig.layer_norm_eps",description:`<strong>layer_norm_eps</strong> (<code>float</code>, <em>optional</em>, defaults to 1e-6) &#x2014;
The epsilon used by the layer normalization layers.`,name:"layer_norm_eps"},{anchor:"transformers.SwitchTransformersConfig.router_z_loss_coef",description:`<strong>router_z_loss_coef</strong> (<code>float</code>, <em>optional</em>, defaults to 0.001) &#x2014;
The z loss factor for the total loss.`,name:"router_z_loss_coef"},{anchor:"transformers.SwitchTransformersConfig.router_aux_loss_coef",description:`<strong>router_aux_loss_coef</strong> (<code>float</code>, <em>optional</em>, defaults to 0.001) &#x2014;
The aux loss factor for the total loss.`,name:"router_aux_loss_coef"},{anchor:"transformers.SwitchTransformersConfig.initializer_factor",description:`<strong>initializer_factor</strong> (<code>float</code>, <em>optional</em>, defaults to 1) &#x2014;
A factor for initializing all weight matrices (should be kept to 1, used internally for initialization
testing).`,name:"initializer_factor"},{anchor:"transformers.SwitchTransformersConfig.feed_forward_proj",description:`<strong>feed_forward_proj</strong> (<code>string</code>, <em>optional</em>, defaults to <code>&quot;relu&quot;</code>) &#x2014;
Type of feed forward layer to be used. Should be one of <code>&quot;relu&quot;</code> or <code>&quot;gated-gelu&quot;</code>. SwitchTransformersv1.1
uses the <code>&quot;gated-gelu&quot;</code> feed forward projection. Original SwitchTransformers uses <code>&quot;relu&quot;</code>.`,name:"feed_forward_proj"},{anchor:"transformers.SwitchTransformersConfig.add_router_probs",description:`<strong>add_router_probs</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to output router probabilities to compute router auxiliary loss.`,name:"add_router_probs"},{anchor:"transformers.SwitchTransformersConfig.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/v4.27.1/src/transformers/models/switch_transformers/configuration_switch_transformers.py#L27"}}),Qe=new fe({}),et=new G({props:{name:"class transformers.SwitchTransformersTop1Router",anchor:"transformers.SwitchTransformersTop1Router",parameters:[{name:"config",val:": SwitchTransformersConfig"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L131"}}),rt=new G({props:{name:"_compute_router_probabilities",anchor:"transformers.SwitchTransformersTop1Router._compute_router_probabilities",parameters:[{name:"hidden_states",val:": Tensor"}],parametersDescription:[{anchor:"transformers.SwitchTransformersTop1Router._compute_router_probabilities.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/v4.27.1/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L151",returnDescription:`
<p>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>):
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:`
<p>router_probabilities (<code>torch.Tensor</code>)</p>
`}}),nt=new G({props:{name:"forward",anchor:"transformers.SwitchTransformersTop1Router.forward",parameters:[{name:"hidden_states",val:": Tensor"}],parametersDescription:[{anchor:"transformers.SwitchTransformersTop1Router.forward.hidden_states",description:`<strong>hidden_states</strong> (<code>torch.Tensor</code>)  &#x2014;
[num_groups, tokens_per_group, hidden_dim] inputs to send to experts.`,name:"hidden_states"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L201",returnDescription:`
<p>Tuple[<code>torch.Tensor</code>, <code>torch.Tensor</code>, <code>torch.Tensor</code>] Tuple containing the expert index, the router probs
and the router logits. The router probabilities and logits are required to compute the loss.</p>
`}}),st=new fe({}),at=new G({props:{name:"class transformers.SwitchTransformersSparseMLP",anchor:"transformers.SwitchTransformersSparseMLP",parameters:[{name:"config",val:": SwitchTransformersConfig"},{name:"expert_class",val:": Module = <class 'transformers.models.switch_transformers.modeling_switch_transformers.SwitchTransformersDenseActDense'>"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L304"}}),it=new G({props:{name:"forward",anchor:"transformers.SwitchTransformersSparseMLP.forward",parameters:[{name:"hidden_states",val:""}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L319"}}),dt=new fe({}),lt=new G({props:{name:"class transformers.SwitchTransformersModel",anchor:"transformers.SwitchTransformersModel",parameters:[{name:"config",val:": SwitchTransformersConfig"}],parametersDescription:[{anchor:"transformers.SwitchTransformersModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.27.1/en/model_doc/switch_transformers#transformers.SwitchTransformersConfig">SwitchTransformersConfig</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.27.1/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.27.1/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L1338"}}),gt=new G({props:{name:"forward",anchor:"transformers.SwitchTransformersModel.forward",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"attention_mask",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:"head_mask",val:": typing.Optional[torch.FloatTensor] = None"},{name:"decoder_head_mask",val:": typing.Optional[torch.FloatTensor] = None"},{name:"cross_attn_head_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"encoder_outputs",val:": typing.Optional[typing.Tuple[typing.Tuple[torch.FloatTensor]]] = None"},{name:"past_key_values",val:": typing.Optional[typing.Tuple[typing.Tuple[torch.FloatTensor]]] = None"},{name:"inputs_embeds",val:": typing.Optional[torch.Tensor] = None"},{name:"decoder_inputs_embeds",val:": typing.Optional[torch.Tensor] = 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:"output_router_logits",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"}],parametersDescription:[{anchor:"transformers.SwitchTransformersModel.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. SWITCH_TRANSFORMERS is a model with relative position
embeddings so you should be able to pad the inputs on both the right and the left.</p>
<p>Indices can be obtained using <a href="/docs/transformers/v4.27.1/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.27.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.27.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for detail.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a></p>
<p>To know more on how to prepare <code>input_ids</code> for pretraining take a look a <a href="./switch_transformers#training">SWITCH_TRANSFORMERS
Training</a>.`,name:"input_ids"},{anchor:"transformers.SwitchTransformersModel.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.FloatTensor</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.SwitchTransformersModel.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.27.1/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.27.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.27.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#decoder-input-ids">What are decoder input IDs?</a></p>
<p>SWITCH_TRANSFORMERS uses the <code>pad_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>).</p>
<p>To know more on how to prepare <code>decoder_input_ids</code> for pretraining take a look at <a href="./switch_transformers#training">SWITCH_TRANSFORMERS
Training</a>.`,name:"decoder_input_ids"},{anchor:"transformers.SwitchTransformersModel.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.SwitchTransformersModel.forward.head_mask",description:`<strong>head_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(num_heads,)</code> or <code>(num_layers, num_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the self-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.SwitchTransformersModel.forward.decoder_head_mask",description:`<strong>decoder_head_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(num_heads,)</code> or <code>(num_layers, num_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the self-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.SwitchTransformersModel.forward.cross_attn_head_mask",description:`<strong>cross_attn_head_mask</strong> (<code>torch.Tensor</code> of shape <code>(num_heads,)</code> or <code>(num_layers, num_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.SwitchTransformersModel.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>, <code>optional</code>: <em>hidden_states</em>, <code>optional</code>: <em>attentions</em>)
<code>last_hidden_state</code> of shape <code>(batch_size, sequence_length, hidden_size)</code> 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.SwitchTransformersModel.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.SwitchTransformersModel.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.SwitchTransformersModel.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.SwitchTransformersModel.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.SwitchTransformersModel.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.SwitchTransformersModel.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.SwitchTransformersModel.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.SwitchTransformersModel.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/v4.27.1/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L1384",returnDescription:`
<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/v4.27.1/en/model_doc/switch_transformers#transformers.SwitchTransformersConfig"
>SwitchTransformersConfig</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>) \u2014 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>) \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 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>) \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>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>) \u2014 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>) \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 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>) \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>
<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>) \u2014 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:`
<p><code>transformers.modeling_outputs.Seq2SeqMoEModelOutput</code> or <code>tuple(torch.FloatTensor)</code></p>
`}}),$e=new wi({props:{$$slots:{default:[sl]},$$scope:{ctx:C}}}),Ee=new Ti({props:{anchor:"transformers.SwitchTransformersModel.forward.example",$$slots:{default:[al]},$$scope:{ctx:C}}}),wt=new fe({}),Tt=new G({props:{name:"class transformers.SwitchTransformersForConditionalGeneration",anchor:"transformers.SwitchTransformersForConditionalGeneration",parameters:[{name:"config",val:": SwitchTransformersConfig"}],parametersDescription:[{anchor:"transformers.SwitchTransformersForConditionalGeneration.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.27.1/en/model_doc/switch_transformers#transformers.SwitchTransformersConfig">SwitchTransformersConfig</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.27.1/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.27.1/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L1506"}}),Mt=new G({props:{name:"forward",anchor:"transformers.SwitchTransformersForConditionalGeneration.forward",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"attention_mask",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:"head_mask",val:": typing.Optional[torch.FloatTensor] = None"},{name:"decoder_head_mask",val:": typing.Optional[torch.FloatTensor] = None"},{name:"cross_attn_head_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"encoder_outputs",val:": typing.Optional[typing.Tuple[typing.Tuple[torch.Tensor]]] = None"},{name:"past_key_values",val:": typing.Optional[typing.Tuple[typing.Tuple[torch.Tensor]]] = None"},{name:"inputs_embeds",val:": typing.Optional[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:"output_router_logits",val:": typing.Optional[bool] = True"},{name:"return_dict",val:": typing.Optional[bool] = None"}],parametersDescription:[{anchor:"transformers.SwitchTransformersForConditionalGeneration.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. SWITCH_TRANSFORMERS is a model with relative position
embeddings so you should be able to pad the inputs on both the right and the left.</p>
<p>Indices can be obtained using <a href="/docs/transformers/v4.27.1/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.27.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.27.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for detail.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a></p>
<p>To know more on how to prepare <code>input_ids</code> for pretraining take a look a <a href="./switch_transformers#training">SWITCH_TRANSFORMERS
Training</a>.`,name:"input_ids"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.FloatTensor</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.SwitchTransformersForConditionalGeneration.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.27.1/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.27.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.27.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#decoder-input-ids">What are decoder input IDs?</a></p>
<p>SWITCH_TRANSFORMERS uses the <code>pad_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>).</p>
<p>To know more on how to prepare <code>decoder_input_ids</code> for pretraining take a look at <a href="./switch_transformers#training">SWITCH_TRANSFORMERS
Training</a>.`,name:"decoder_input_ids"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.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.SwitchTransformersForConditionalGeneration.forward.head_mask",description:`<strong>head_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(num_heads,)</code> or <code>(num_layers, num_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the self-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.SwitchTransformersForConditionalGeneration.forward.decoder_head_mask",description:`<strong>decoder_head_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(num_heads,)</code> or <code>(num_layers, num_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the self-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.SwitchTransformersForConditionalGeneration.forward.cross_attn_head_mask",description:`<strong>cross_attn_head_mask</strong> (<code>torch.Tensor</code> of shape <code>(num_heads,)</code> or <code>(num_layers, num_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.SwitchTransformersForConditionalGeneration.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>, <code>optional</code>: <em>hidden_states</em>, <code>optional</code>: <em>attentions</em>)
<code>last_hidden_state</code> of shape <code>(batch_size, sequence_length, hidden_size)</code> 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.SwitchTransformersForConditionalGeneration.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.SwitchTransformersForConditionalGeneration.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.SwitchTransformersForConditionalGeneration.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.SwitchTransformersForConditionalGeneration.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.SwitchTransformersForConditionalGeneration.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.SwitchTransformersForConditionalGeneration.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.SwitchTransformersForConditionalGeneration.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.SwitchTransformersForConditionalGeneration.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/v4.27.1/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.labels",description:`<strong>labels</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size,)</code>, <em>optional</em>) &#x2014;
Labels for computing the sequence classification/regression loss. Indices should be in <code>[-100, 0, ..., config.vocab_size - 1]</code>. All labels set to <code>-100</code> are ignored (masked), the loss is only computed for
labels in <code>[0, ..., config.vocab_size]</code>`,name:"labels"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L1562",returnDescription:`
<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/v4.27.1/en/model_doc/switch_transformers#transformers.SwitchTransformersConfig"
>SwitchTransformersConfig</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>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>) \u2014 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>) \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>
<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>) \u2014 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:`
<p><code>transformers.modeling_outputs.Seq2SeqMoEOutput</code> or <code>tuple(torch.FloatTensor)</code></p>
`}}),ze=new wi({props:{$$slots:{default:[il]},$$scope:{ctx:C}}}),Ce=new Ti({props:{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.example",$$slots:{default:[dl]},$$scope:{ctx:C}}}),zt=new fe({}),Ct=new G({props:{name:"class transformers.SwitchTransformersEncoderModel",anchor:"transformers.SwitchTransformersEncoderModel",parameters:[{name:"config",val:": SwitchTransformersConfig"}],parametersDescription:[{anchor:"transformers.SwitchTransformersEncoderModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.27.1/en/model_doc/switch_transformers#transformers.SwitchTransformersConfig">SwitchTransformersConfig</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.27.1/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.27.1/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L1821"}}),It=new G({props:{name:"forward",anchor:"transformers.SwitchTransformersEncoderModel.forward",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.FloatTensor] = None"},{name:"head_mask",val:": typing.Optional[torch.FloatTensor] = None"},{name:"inputs_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"output_router_logits",val:": typing.Optional[bool] = True"},{name:"return_dict",val:": typing.Optional[bool] = None"}],parametersDescription:[{anchor:"transformers.SwitchTransformersEncoderModel.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. SWITCH_TRANSFORMERS is a model with relative position
embeddings so you should be able to pad the inputs on both the right and the left.</p>
<p>Indices can be obtained using <a href="/docs/transformers/v4.27.1/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.27.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.27.1/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for detail.</p>
<p>To know more on how to prepare <code>input_ids</code> for pretraining take a look a <a href="./switch_transformers#training">SWITCH_TRANSFORMERS
Training</a>.`,name:"input_ids"},{anchor:"transformers.SwitchTransformersEncoderModel.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.FloatTensor</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.SwitchTransformersEncoderModel.forward.head_mask",description:`<strong>head_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(num_heads,)</code> or <code>(num_layers, num_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the self-attention modules. 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.SwitchTransformersEncoderModel.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.SwitchTransformersEncoderModel.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.SwitchTransformersEncoderModel.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.SwitchTransformersEncoderModel.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.SwitchTransformersEncoderModel.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/v4.27.1/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/transformers/blob/v4.27.1/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L1857",returnDescription:`
<p>A <code>transformers.modeling_outputs.MoEModelOutput</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/v4.27.1/en/model_doc/switch_transformers#transformers.SwitchTransformersConfig"
>SwitchTransformersConfig</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>) \u2014 Sequence of hidden-states at the output of the last layer of the model.</p>
</li>
<li>
<p><strong>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 model at the output of each layer plus the optional initial embedding outputs.</p>
</li>
<li>
<p><strong>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 after the attention softmax, used to compute the weighted average in the self-attention
heads.</p>
</li>
<li>
<p><strong>router_probs</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_router_probs=True</code> and <code>config.add_router_probs=True</code> is passed or when <code>config.output_router_probs=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, sequence_length, num_experts)</code>.</p>
<p>Raw router probabilities that are computed by MoE routers, these terms are used to compute the auxiliary
loss and the z_loss for Mixture of Experts models.</p>
</li>
</ul>
`,returnType:`
<p><code>transformers.modeling_outputs.MoEModelOutput</code> or <code>tuple(torch.FloatTensor)</code></p>
`}}),qe=new wi({props:{$$slots:{default:[ll]},$$scope:{ctx:C}}}),Pe=new Ti({props:{anchor:"transformers.SwitchTransformersEncoderModel.forward.example",$$slots:{default:[cl]},$$scope:{ctx:C}}}),{c(){u=s("meta"),x=l(),g=s("h1"),_=s("a"),w=s("span"),T(h.$$.fragment),f=l(),F=s("span"),Vr=r("SwitchTransformers"),rr=l(),te=s("h2"),_e=s("a"),uo=s("span"),T(De.$$.fragment),Zr=l(),mo=s("span"),Ur=r("Overview"),nr=l(),ge=s("p"),Xr=r("The SwitchTransformers model was proposed in "),Le=s("a"),Yr=r("Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity"),Jr=r(" by William Fedus, Barret Zoph, Noam Shazeer."),sr=l(),Dt=s("p"),Kr=r(`The Switch Transformer model uses a sparse T5 encoder-decoder architecture, where the MLP are replaced by a Mixture of Experts (MoE). A routing mechanism (top 1 in this case) associates each token to one of the expert, where each expert is a dense MLP. While switch transformers have a lot more weights than their equivalent dense models, the sparsity allows better scaling and better finetuning performance at scale.
During a forward pass, only a fraction of the weights are used. The routing mechanism allows the model to select relevant weights on the fly which increases the model capacity without increasing the number of operations.`),ar=l(),Lt=s("p"),Qr=r("The abstract from the paper is the following:"),ir=l(),Bt=s("p"),fo=s("em"),en=r("In deep learning, models typically reuse the same parameters for all inputs. Mixture of Experts (MoE) defies this and instead selects different parameters for each incoming example. The result is a sparsely-activated model \u2014 with outrageous numbers of parameters \u2014 but a constant computational cost. However, despite several notable successes of MoE, widespread adoption has been hindered by complexity, communication costs and training instability \u2014 we address these with the Switch Transformer. We simplify the MoE routing algorithm and design intuitive improved models with reduced communication and computational costs. Our proposed training techniques help wrangle the instabilities and we show large sparse models may be trained, for the first time, with lower precision (bfloat16) formats. We design models based off T5-Base and T5-Large to obtain up to 7x increases in pre-training speed with the same computational resources. These improvements extend into multilingual settings where we measure gains over the mT5-Base version across all 101 languages. Finally, we advance the current scale of language models by pre-training up to trillion parameter models on the \u201CColossal Clean Crawled Corpus\u201D and achieve a 4x speedup over the T5-XXL model."),dr=l(),Gt=s("p"),tn=r("Tips:"),lr=l(),we=s("ul"),Be=s("li"),on=r("SwitchTransformers uses the "),Ht=s("a"),rn=r("T5Tokenizer"),nn=r(", which can be loaded directly from each model\u2019s repository."),sn=l(),Ge=s("li"),an=r("The released weights are pretrained on English "),He=s("a"),dn=r("Masked Language Modeling"),ln=r(" task, and should be finetuned."),cr=l(),O=s("p"),cn=r("This model was contributed by "),Ve=s("a"),hn=r("Younes Belkada"),pn=r(" and "),Ze=s("a"),un=r("Arthur Zucker"),mn=r(` .
The original code can be found `),Ue=s("a"),fn=r("here"),_n=r("."),hr=l(),oe=s("h2"),Te=s("a"),_o=s("span"),T(Xe.$$.fragment),gn=l(),go=s("span"),wn=r("Resources"),pr=l(),ve=s("ul"),wo=s("li"),Vt=s("a"),Tn=r("Translation task guide"),vn=l(),To=s("li"),Zt=s("a"),bn=r("Summarization task guide"),ur=l(),re=s("h2"),be=s("a"),vo=s("span"),T(Ye.$$.fragment),yn=l(),bo=s("span"),kn=r("SwitchTransformersConfig"),mr=l(),H=s("div"),T(Je.$$.fragment),Sn=l(),ne=s("p"),xn=r("This is the configuration class to store the configuration of a "),Ut=s("a"),$n=r("SwitchTransformersModel"),En=r(`. It is used to
instantiate a SwitchTransformers 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
SwitchTransformers `),Ke=s("a"),Mn=r("google/switch-base-8"),zn=r(" architecture."),Cn=l(),se=s("p"),Fn=r("Configuration objects inherit from "),Xt=s("a"),qn=r("PretrainedConfig"),Pn=r(` and can be used to control the model outputs. Read the
documentation from `),Yt=s("a"),An=r("PretrainedConfig"),Rn=r(" for more information."),fr=l(),ae=s("h2"),ye=s("a"),yo=s("span"),T(Qe.$$.fragment),On=l(),ko=s("span"),Nn=r("SwitchTransformersTop1Router"),_r=l(),z=s("div"),T(et.$$.fragment),In=l(),So=s("p"),jn=r("Router using tokens choose top-1 experts assignment."),Wn=l(),V=s("p"),Dn=r("This router uses the same mechanism as in Switch Transformer ("),tt=s("a"),Ln=r("https://arxiv.org/abs/2101.03961"),Bn=r(`) and V-MoE
(`),ot=s("a"),Gn=r("https://arxiv.org/abs/2106.05974"),Hn=r(`): tokens choose their top experts. Items are sorted by router_probs and then
routed to their choice of expert until the expert\u2019s expert_capacity is reached. `),xo=s("strong"),Vn=r(`There is no guarantee that each
token is processed by an expert`),Zn=r(", or that each expert receives at least one token."),Un=l(),ke=s("div"),T(rt.$$.fragment),Xn=l(),$o=s("p"),Yn=r("Computes router probabilities from input hidden states."),Jn=l(),X=s("div"),T(nt.$$.fragment),Kn=l(),ie=s("p"),Qn=r(`Generic forward function for every Router class. Each Router expects to have the same input hidden states
(`),Eo=s("code"),es=r("hidden_states"),ts=r(") corresponding to the hidden states for each token, the "),Mo=s("code"),os=r("expert_capacity"),rs=r(` corresponding to the
number of tokens the Router will send to each expert, some Routers can send up to few tokens to each expert.`),ns=l(),q=s("p"),ss=r("Each Router works as the following: it expects the hidden states for each token, gets the "),zo=s("code"),as=r("router_probs"),is=r(` and
`),Co=s("code"),ds=r("router_logits"),ls=r(" from the "),Fo=s("code"),cs=r("router_weights"),hs=r(`. This will assign for each token, the raw probability to be assigned
to an expert. Then each Router class will have to define its own `),qo=s("code"),ps=r("_compute_routing_instructions"),us=r("."),gr=l(),de=s("h2"),Se=s("a"),Po=s("span"),T(st.$$.fragment),ms=l(),Ao=s("span"),fs=r("SwitchTransformersSparseMLP"),wr=l(),Z=s("div"),T(at.$$.fragment),_s=l(),Ro=s("p"),gs=r("Implementation of the Switch Transformers Sparse MLP module."),ws=l(),N=s("div"),T(it.$$.fragment),Ts=l(),Oo=s("p"),vs=r("Hold on, this will be slightly tricky to understand In the correct order, a MoE layer does the following:"),bs=l(),U=s("p"),ys=r("1- Gets the "),No=s("code"),ks=r("router_mask"),Ss=r(" from the router. The shape of the mask is "),Io=s("code"),xs=r("(batch_size, sequence_length, num_expert)"),$s=r(`
and corresponds to the argmax of the `),jo=s("code"),Es=r("router_probs"),Ms=r(`. The probabilities are needed in the computation of the
hidden states : they are broadcasted to the hidden states values (can be interpreted as a scaling factor).`),zs=l(),Wo=s("p"),Cs=r(`2- Dispatch the tokens to its associated experts. We do a classic for loop over the experts and assign for each
expert the corresponding hidden states.`),Tr=l(),le=s("h2"),xe=s("a"),Do=s("span"),T(dt.$$.fragment),Fs=l(),Lo=s("span"),qs=r("SwitchTransformersModel"),vr=l(),$=s("div"),T(lt.$$.fragment),Ps=l(),Bo=s("p"),As=r("The bare SWITCH_TRANSFORMERS Model transformer outputting raw hidden-states without any specific head on top."),Rs=l(),P=s("p"),Os=r("The SWITCH_TRANSFORMERS model was proposed in "),ct=s("a"),Ns=r(`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),Is=r(" by "),ht=s("a"),js=r(`William
Fedus`),Ws=r(", "),pt=s("a"),Ds=r(`Barret
Zoph`),Ls=r(", and "),ut=s("a"),Bs=r(`Noam
Shazeer`),Gs=r(`. It\u2019s an encoder-decoder T5-like model
with sparse Feed Forward that stands for Mixture of Experts (MoE) architecture.`),Hs=l(),mt=s("p"),Vs=r("This model inherits from "),Jt=s("a"),Zs=r("PreTrainedModel"),Us=r(`. 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.)`),Xs=l(),ft=s("p"),Ys=r("This model is also a PyTorch "),_t=s("a"),Js=r("torch.nn.Module"),Ks=r(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Qs=l(),I=s("div"),T(gt.$$.fragment),ea=l(),ce=s("p"),ta=r("The "),Kt=s("a"),oa=r("SwitchTransformersModel"),ra=r(" forward method, overrides the "),Go=s("code"),na=r("__call__"),sa=r(" special method."),aa=l(),T($e.$$.fragment),ia=l(),T(Ee.$$.fragment),br=l(),he=s("h2"),Me=s("a"),Ho=s("span"),T(wt.$$.fragment),da=l(),Vo=s("span"),la=r("SwitchTransformersForConditionalGeneration"),yr=l(),E=s("div"),T(Tt.$$.fragment),ca=l(),vt=s("p"),ha=r("SWITCH_TRANSFORMERS Model with a "),Zo=s("code"),pa=r("language modeling"),ua=r(" head on top."),ma=l(),A=s("p"),fa=r("The SWITCH_TRANSFORMERS model was proposed in "),bt=s("a"),_a=r(`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),ga=r(" by "),yt=s("a"),wa=r(`William
Fedus`),Ta=r(", "),kt=s("a"),va=r(`Barret
Zoph`),ba=r(", and "),St=s("a"),ya=r(`Noam
Shazeer`),ka=r(`. It\u2019s an encoder-decoder T5-like model
with sparse Feed Forward that stands for Mixture of Experts (MoE) architecture.`),Sa=l(),xt=s("p"),xa=r("This model inherits from "),Qt=s("a"),$a=r("PreTrainedModel"),Ea=r(`. 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.)`),Ma=l(),$t=s("p"),za=r("This model is also a PyTorch "),Et=s("a"),Ca=r("torch.nn.Module"),Fa=r(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),qa=l(),j=s("div"),T(Mt.$$.fragment),Pa=l(),pe=s("p"),Aa=r("The "),eo=s("a"),Ra=r("SwitchTransformersForConditionalGeneration"),Oa=r(" forward method, overrides the "),Uo=s("code"),Na=r("__call__"),Ia=r(" special method."),ja=l(),T(ze.$$.fragment),Wa=l(),T(Ce.$$.fragment),kr=l(),ue=s("h2"),Fe=s("a"),Xo=s("span"),T(zt.$$.fragment),Da=l(),Yo=s("span"),La=r("SwitchTransformersEncoderModel"),Sr=l(),M=s("div"),T(Ct.$$.fragment),Ba=l(),Jo=s("p"),Ga=r("The bare SWITCH_TRANSFORMERS Model transformer outputting encoder\u2019s raw hidden-states without any specific head on top."),Ha=l(),R=s("p"),Va=r("The SWITCH_TRANSFORMERS model was proposed in "),Ft=s("a"),Za=r(`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),Ua=r(" by "),qt=s("a"),Xa=r(`William
Fedus`),Ya=r(", "),Pt=s("a"),Ja=r(`Barret
Zoph`),Ka=r(", and "),At=s("a"),Qa=r(`Noam
Shazeer`),ei=r(`. It\u2019s an encoder-decoder T5-like model
with sparse Feed Forward that stands for Mixture of Experts (MoE) architecture.`),ti=l(),Rt=s("p"),oi=r("This model inherits from "),to=s("a"),ri=r("PreTrainedModel"),ni=r(`. 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.)`),si=l(),Ot=s("p"),ai=r("This model is also a PyTorch "),Nt=s("a"),ii=r("torch.nn.Module"),di=r(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),li=l(),W=s("div"),T(It.$$.fragment),ci=l(),me=s("p"),hi=r("The "),oo=s("a"),pi=r("SwitchTransformersEncoderModel"),ui=r(" forward method, overrides the "),Ko=s("code"),mi=r("__call__"),fi=r(" special method."),_i=l(),T(qe.$$.fragment),gi=l(),T(Pe.$$.fragment),this.h()},l(t){const p=rl('[data-svelte="svelte-1phssyn"]',document.head);u=a(p,"META",{name:!0,content:!0}),p.forEach(o),x=c(t),g=a(t,"H1",{class:!0});var jt=i(g);_=a(jt,"A",{id:!0,class:!0,href:!0});var Qo=i(_);w=a(Qo,"SPAN",{});var er=i(w);v(h.$$.fragment,er),er.forEach(o),Qo.forEach(o),f=c(jt),F=a(jt,"SPAN",{});var tr=i(F);Vr=n(tr,"SwitchTransformers"),tr.forEach(o),jt.forEach(o),rr=c(t),te=a(t,"H2",{class:!0});var Wt=i(te);_e=a(Wt,"A",{id:!0,class:!0,href:!0});var or=i(_e);uo=a(or,"SPAN",{});var yi=i(uo);v(De.$$.fragment,yi),yi.forEach(o),or.forEach(o),Zr=c(Wt),mo=a(Wt,"SPAN",{});var ki=i(mo);Ur=n(ki,"Overview"),ki.forEach(o),Wt.forEach(o),nr=c(t),ge=a(t,"P",{});var $r=i(ge);Xr=n($r,"The SwitchTransformers model was proposed in "),Le=a($r,"A",{href:!0,rel:!0});var Si=i(Le);Yr=n(Si,"Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity"),Si.forEach(o),Jr=n($r," by William Fedus, Barret Zoph, Noam Shazeer."),$r.forEach(o),sr=c(t),Dt=a(t,"P",{});var xi=i(Dt);Kr=n(xi,`The Switch Transformer model uses a sparse T5 encoder-decoder architecture, where the MLP are replaced by a Mixture of Experts (MoE). A routing mechanism (top 1 in this case) associates each token to one of the expert, where each expert is a dense MLP. While switch transformers have a lot more weights than their equivalent dense models, the sparsity allows better scaling and better finetuning performance at scale.
During a forward pass, only a fraction of the weights are used. The routing mechanism allows the model to select relevant weights on the fly which increases the model capacity without increasing the number of operations.`),xi.forEach(o),ar=c(t),Lt=a(t,"P",{});var $i=i(Lt);Qr=n($i,"The abstract from the paper is the following:"),$i.forEach(o),ir=c(t),Bt=a(t,"P",{});var Ei=i(Bt);fo=a(Ei,"EM",{});var Mi=i(fo);en=n(Mi,"In deep learning, models typically reuse the same parameters for all inputs. Mixture of Experts (MoE) defies this and instead selects different parameters for each incoming example. The result is a sparsely-activated model \u2014 with outrageous numbers of parameters \u2014 but a constant computational cost. However, despite several notable successes of MoE, widespread adoption has been hindered by complexity, communication costs and training instability \u2014 we address these with the Switch Transformer. We simplify the MoE routing algorithm and design intuitive improved models with reduced communication and computational costs. Our proposed training techniques help wrangle the instabilities and we show large sparse models may be trained, for the first time, with lower precision (bfloat16) formats. We design models based off T5-Base and T5-Large to obtain up to 7x increases in pre-training speed with the same computational resources. These improvements extend into multilingual settings where we measure gains over the mT5-Base version across all 101 languages. Finally, we advance the current scale of language models by pre-training up to trillion parameter models on the \u201CColossal Clean Crawled Corpus\u201D and achieve a 4x speedup over the T5-XXL model."),Mi.forEach(o),Ei.forEach(o),dr=c(t),Gt=a(t,"P",{});var zi=i(Gt);tn=n(zi,"Tips:"),zi.forEach(o),lr=c(t),we=a(t,"UL",{});var Er=i(we);Be=a(Er,"LI",{});var Mr=i(Be);on=n(Mr,"SwitchTransformers uses the "),Ht=a(Mr,"A",{href:!0});var Ci=i(Ht);rn=n(Ci,"T5Tokenizer"),Ci.forEach(o),nn=n(Mr,", which can be loaded directly from each model\u2019s repository."),Mr.forEach(o),sn=c(Er),Ge=a(Er,"LI",{});var zr=i(Ge);an=n(zr,"The released weights are pretrained on English "),He=a(zr,"A",{href:!0,rel:!0});var Fi=i(He);dn=n(Fi,"Masked Language Modeling"),Fi.forEach(o),ln=n(zr," task, and should be finetuned."),zr.forEach(o),Er.forEach(o),cr=c(t),O=a(t,"P",{});var Ae=i(O);cn=n(Ae,"This model was contributed by "),Ve=a(Ae,"A",{href:!0,rel:!0});var qi=i(Ve);hn=n(qi,"Younes Belkada"),qi.forEach(o),pn=n(Ae," and "),Ze=a(Ae,"A",{href:!0,rel:!0});var Pi=i(Ze);un=n(Pi,"Arthur Zucker"),Pi.forEach(o),mn=n(Ae,` .
The original code can be found `),Ue=a(Ae,"A",{href:!0,rel:!0});var Ai=i(Ue);fn=n(Ai,"here"),Ai.forEach(o),_n=n(Ae,"."),Ae.forEach(o),hr=c(t),oe=a(t,"H2",{class:!0});var Cr=i(oe);Te=a(Cr,"A",{id:!0,class:!0,href:!0});var Ri=i(Te);_o=a(Ri,"SPAN",{});var Oi=i(_o);v(Xe.$$.fragment,Oi),Oi.forEach(o),Ri.forEach(o),gn=c(Cr),go=a(Cr,"SPAN",{});var Ni=i(go);wn=n(Ni,"Resources"),Ni.forEach(o),Cr.forEach(o),pr=c(t),ve=a(t,"UL",{});var Fr=i(ve);wo=a(Fr,"LI",{});var Ii=i(wo);Vt=a(Ii,"A",{href:!0});var ji=i(Vt);Tn=n(ji,"Translation task guide"),ji.forEach(o),Ii.forEach(o),vn=c(Fr),To=a(Fr,"LI",{});var Wi=i(To);Zt=a(Wi,"A",{href:!0});var Di=i(Zt);bn=n(Di,"Summarization task guide"),Di.forEach(o),Wi.forEach(o),Fr.forEach(o),ur=c(t),re=a(t,"H2",{class:!0});var qr=i(re);be=a(qr,"A",{id:!0,class:!0,href:!0});var Li=i(be);vo=a(Li,"SPAN",{});var Bi=i(vo);v(Ye.$$.fragment,Bi),Bi.forEach(o),Li.forEach(o),yn=c(qr),bo=a(qr,"SPAN",{});var Gi=i(bo);kn=n(Gi,"SwitchTransformersConfig"),Gi.forEach(o),qr.forEach(o),mr=c(t),H=a(t,"DIV",{class:!0});var ro=i(H);v(Je.$$.fragment,ro),Sn=c(ro),ne=a(ro,"P",{});var no=i(ne);xn=n(no,"This is the configuration class to store the configuration of a "),Ut=a(no,"A",{href:!0});var Hi=i(Ut);$n=n(Hi,"SwitchTransformersModel"),Hi.forEach(o),En=n(no,`. It is used to
instantiate a SwitchTransformers 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
SwitchTransformers `),Ke=a(no,"A",{href:!0,rel:!0});var Vi=i(Ke);Mn=n(Vi,"google/switch-base-8"),Vi.forEach(o),zn=n(no," architecture."),no.forEach(o),Cn=c(ro),se=a(ro,"P",{});var so=i(se);Fn=n(so,"Configuration objects inherit from "),Xt=a(so,"A",{href:!0});var Zi=i(Xt);qn=n(Zi,"PretrainedConfig"),Zi.forEach(o),Pn=n(so,` and can be used to control the model outputs. Read the
documentation from `),Yt=a(so,"A",{href:!0});var Ui=i(Yt);An=n(Ui,"PretrainedConfig"),Ui.forEach(o),Rn=n(so," for more information."),so.forEach(o),ro.forEach(o),fr=c(t),ae=a(t,"H2",{class:!0});var Pr=i(ae);ye=a(Pr,"A",{id:!0,class:!0,href:!0});var Xi=i(ye);yo=a(Xi,"SPAN",{});var Yi=i(yo);v(Qe.$$.fragment,Yi),Yi.forEach(o),Xi.forEach(o),On=c(Pr),ko=a(Pr,"SPAN",{});var Ji=i(ko);Nn=n(Ji,"SwitchTransformersTop1Router"),Ji.forEach(o),Pr.forEach(o),_r=c(t),z=a(t,"DIV",{class:!0});var Y=i(z);v(et.$$.fragment,Y),In=c(Y),So=a(Y,"P",{});var Ki=i(So);jn=n(Ki,"Router using tokens choose top-1 experts assignment."),Ki.forEach(o),Wn=c(Y),V=a(Y,"P",{});var Re=i(V);Dn=n(Re,"This router uses the same mechanism as in Switch Transformer ("),tt=a(Re,"A",{href:!0,rel:!0});var Qi=i(tt);Ln=n(Qi,"https://arxiv.org/abs/2101.03961"),Qi.forEach(o),Bn=n(Re,`) and V-MoE
(`),ot=a(Re,"A",{href:!0,rel:!0});var ed=i(ot);Gn=n(ed,"https://arxiv.org/abs/2106.05974"),ed.forEach(o),Hn=n(Re,`): tokens choose their top experts. Items are sorted by router_probs and then
routed to their choice of expert until the expert\u2019s expert_capacity is reached. `),xo=a(Re,"STRONG",{});var td=i(xo);Vn=n(td,`There is no guarantee that each
token is processed by an expert`),td.forEach(o),Zn=n(Re,", or that each expert receives at least one token."),Re.forEach(o),Un=c(Y),ke=a(Y,"DIV",{class:!0});var Ar=i(ke);v(rt.$$.fragment,Ar),Xn=c(Ar),$o=a(Ar,"P",{});var od=i($o);Yn=n(od,"Computes router probabilities from input hidden states."),od.forEach(o),Ar.forEach(o),Jn=c(Y),X=a(Y,"DIV",{class:!0});var ao=i(X);v(nt.$$.fragment,ao),Kn=c(ao),ie=a(ao,"P",{});var io=i(ie);Qn=n(io,`Generic forward function for every Router class. Each Router expects to have the same input hidden states
(`),Eo=a(io,"CODE",{});var rd=i(Eo);es=n(rd,"hidden_states"),rd.forEach(o),ts=n(io,") corresponding to the hidden states for each token, the "),Mo=a(io,"CODE",{});var nd=i(Mo);os=n(nd,"expert_capacity"),nd.forEach(o),rs=n(io,` corresponding to the
number of tokens the Router will send to each expert, some Routers can send up to few tokens to each expert.`),io.forEach(o),ns=c(ao),q=a(ao,"P",{});var J=i(q);ss=n(J,"Each Router works as the following: it expects the hidden states for each token, gets the "),zo=a(J,"CODE",{});var sd=i(zo);as=n(sd,"router_probs"),sd.forEach(o),is=n(J,` and
`),Co=a(J,"CODE",{});var ad=i(Co);ds=n(ad,"router_logits"),ad.forEach(o),ls=n(J," from the "),Fo=a(J,"CODE",{});var id=i(Fo);cs=n(id,"router_weights"),id.forEach(o),hs=n(J,`. This will assign for each token, the raw probability to be assigned
to an expert. Then each Router class will have to define its own `),qo=a(J,"CODE",{});var dd=i(qo);ps=n(dd,"_compute_routing_instructions"),dd.forEach(o),us=n(J,"."),J.forEach(o),ao.forEach(o),Y.forEach(o),gr=c(t),de=a(t,"H2",{class:!0});var Rr=i(de);Se=a(Rr,"A",{id:!0,class:!0,href:!0});var ld=i(Se);Po=a(ld,"SPAN",{});var cd=i(Po);v(st.$$.fragment,cd),cd.forEach(o),ld.forEach(o),ms=c(Rr),Ao=a(Rr,"SPAN",{});var hd=i(Ao);fs=n(hd,"SwitchTransformersSparseMLP"),hd.forEach(o),Rr.forEach(o),wr=c(t),Z=a(t,"DIV",{class:!0});var lo=i(Z);v(at.$$.fragment,lo),_s=c(lo),Ro=a(lo,"P",{});var pd=i(Ro);gs=n(pd,"Implementation of the Switch Transformers Sparse MLP module."),pd.forEach(o),ws=c(lo),N=a(lo,"DIV",{class:!0});var Oe=i(N);v(it.$$.fragment,Oe),Ts=c(Oe),Oo=a(Oe,"P",{});var ud=i(Oo);vs=n(ud,"Hold on, this will be slightly tricky to understand In the correct order, a MoE layer does the following:"),ud.forEach(o),bs=c(Oe),U=a(Oe,"P",{});var Ne=i(U);ys=n(Ne,"1- Gets the "),No=a(Ne,"CODE",{});var md=i(No);ks=n(md,"router_mask"),md.forEach(o),Ss=n(Ne," from the router. The shape of the mask is "),Io=a(Ne,"CODE",{});var fd=i(Io);xs=n(fd,"(batch_size, sequence_length, num_expert)"),fd.forEach(o),$s=n(Ne,`
and corresponds to the argmax of the `),jo=a(Ne,"CODE",{});var _d=i(jo);Es=n(_d,"router_probs"),_d.forEach(o),Ms=n(Ne,`. The probabilities are needed in the computation of the
hidden states : they are broadcasted to the hidden states values (can be interpreted as a scaling factor).`),Ne.forEach(o),zs=c(Oe),Wo=a(Oe,"P",{});var gd=i(Wo);Cs=n(gd,`2- Dispatch the tokens to its associated experts. We do a classic for loop over the experts and assign for each
expert the corresponding hidden states.`),gd.forEach(o),Oe.forEach(o),lo.forEach(o),Tr=c(t),le=a(t,"H2",{class:!0});var Or=i(le);xe=a(Or,"A",{id:!0,class:!0,href:!0});var wd=i(xe);Do=a(wd,"SPAN",{});var Td=i(Do);v(dt.$$.fragment,Td),Td.forEach(o),wd.forEach(o),Fs=c(Or),Lo=a(Or,"SPAN",{});var vd=i(Lo);qs=n(vd,"SwitchTransformersModel"),vd.forEach(o),Or.forEach(o),vr=c(t),$=a(t,"DIV",{class:!0});var D=i($);v(lt.$$.fragment,D),Ps=c(D),Bo=a(D,"P",{});var bd=i(Bo);As=n(bd,"The bare SWITCH_TRANSFORMERS Model transformer outputting raw hidden-states without any specific head on top."),bd.forEach(o),Rs=c(D),P=a(D,"P",{});var K=i(P);Os=n(K,"The SWITCH_TRANSFORMERS model was proposed in "),ct=a(K,"A",{href:!0,rel:!0});var yd=i(ct);Ns=n(yd,`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),yd.forEach(o),Is=n(K," by "),ht=a(K,"A",{href:!0,rel:!0});var kd=i(ht);js=n(kd,`William
Fedus`),kd.forEach(o),Ws=n(K,", "),pt=a(K,"A",{href:!0,rel:!0});var Sd=i(pt);Ds=n(Sd,`Barret
Zoph`),Sd.forEach(o),Ls=n(K,", and "),ut=a(K,"A",{href:!0,rel:!0});var xd=i(ut);Bs=n(xd,`Noam
Shazeer`),xd.forEach(o),Gs=n(K,`. It\u2019s an encoder-decoder T5-like model
with sparse Feed Forward that stands for Mixture of Experts (MoE) architecture.`),K.forEach(o),Hs=c(D),mt=a(D,"P",{});var Nr=i(mt);Vs=n(Nr,"This model inherits from "),Jt=a(Nr,"A",{href:!0});var $d=i(Jt);Zs=n($d,"PreTrainedModel"),$d.forEach(o),Us=n(Nr,`. 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.)`),Nr.forEach(o),Xs=c(D),ft=a(D,"P",{});var Ir=i(ft);Ys=n(Ir,"This model is also a PyTorch "),_t=a(Ir,"A",{href:!0,rel:!0});var Ed=i(_t);Js=n(Ed,"torch.nn.Module"),Ed.forEach(o),Ks=n(Ir,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Ir.forEach(o),Qs=c(D),I=a(D,"DIV",{class:!0});var Ie=i(I);v(gt.$$.fragment,Ie),ea=c(Ie),ce=a(Ie,"P",{});var co=i(ce);ta=n(co,"The "),Kt=a(co,"A",{href:!0});var Md=i(Kt);oa=n(Md,"SwitchTransformersModel"),Md.forEach(o),ra=n(co," forward method, overrides the "),Go=a(co,"CODE",{});var zd=i(Go);na=n(zd,"__call__"),zd.forEach(o),sa=n(co," special method."),co.forEach(o),aa=c(Ie),v($e.$$.fragment,Ie),ia=c(Ie),v(Ee.$$.fragment,Ie),Ie.forEach(o),D.forEach(o),br=c(t),he=a(t,"H2",{class:!0});var jr=i(he);Me=a(jr,"A",{id:!0,class:!0,href:!0});var Cd=i(Me);Ho=a(Cd,"SPAN",{});var Fd=i(Ho);v(wt.$$.fragment,Fd),Fd.forEach(o),Cd.forEach(o),da=c(jr),Vo=a(jr,"SPAN",{});var qd=i(Vo);la=n(qd,"SwitchTransformersForConditionalGeneration"),qd.forEach(o),jr.forEach(o),yr=c(t),E=a(t,"DIV",{class:!0});var L=i(E);v(Tt.$$.fragment,L),ca=c(L),vt=a(L,"P",{});var Wr=i(vt);ha=n(Wr,"SWITCH_TRANSFORMERS Model with a "),Zo=a(Wr,"CODE",{});var Pd=i(Zo);pa=n(Pd,"language modeling"),Pd.forEach(o),ua=n(Wr," head on top."),Wr.forEach(o),ma=c(L),A=a(L,"P",{});var Q=i(A);fa=n(Q,"The SWITCH_TRANSFORMERS model was proposed in "),bt=a(Q,"A",{href:!0,rel:!0});var Ad=i(bt);_a=n(Ad,`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),Ad.forEach(o),ga=n(Q," by "),yt=a(Q,"A",{href:!0,rel:!0});var Rd=i(yt);wa=n(Rd,`William
Fedus`),Rd.forEach(o),Ta=n(Q,", "),kt=a(Q,"A",{href:!0,rel:!0});var Od=i(kt);va=n(Od,`Barret
Zoph`),Od.forEach(o),ba=n(Q,", and "),St=a(Q,"A",{href:!0,rel:!0});var Nd=i(St);ya=n(Nd,`Noam
Shazeer`),Nd.forEach(o),ka=n(Q,`. It\u2019s an encoder-decoder T5-like model
with sparse Feed Forward that stands for Mixture of Experts (MoE) architecture.`),Q.forEach(o),Sa=c(L),xt=a(L,"P",{});var Dr=i(xt);xa=n(Dr,"This model inherits from "),Qt=a(Dr,"A",{href:!0});var Id=i(Qt);$a=n(Id,"PreTrainedModel"),Id.forEach(o),Ea=n(Dr,`. 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.)`),Dr.forEach(o),Ma=c(L),$t=a(L,"P",{});var Lr=i($t);za=n(Lr,"This model is also a PyTorch "),Et=a(Lr,"A",{href:!0,rel:!0});var jd=i(Et);Ca=n(jd,"torch.nn.Module"),jd.forEach(o),Fa=n(Lr,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Lr.forEach(o),qa=c(L),j=a(L,"DIV",{class:!0});var je=i(j);v(Mt.$$.fragment,je),Pa=c(je),pe=a(je,"P",{});var ho=i(pe);Aa=n(ho,"The "),eo=a(ho,"A",{href:!0});var Wd=i(eo);Ra=n(Wd,"SwitchTransformersForConditionalGeneration"),Wd.forEach(o),Oa=n(ho," forward method, overrides the "),Uo=a(ho,"CODE",{});var Dd=i(Uo);Na=n(Dd,"__call__"),Dd.forEach(o),Ia=n(ho," special method."),ho.forEach(o),ja=c(je),v(ze.$$.fragment,je),Wa=c(je),v(Ce.$$.fragment,je),je.forEach(o),L.forEach(o),kr=c(t),ue=a(t,"H2",{class:!0});var Br=i(ue);Fe=a(Br,"A",{id:!0,class:!0,href:!0});var Ld=i(Fe);Xo=a(Ld,"SPAN",{});var Bd=i(Xo);v(zt.$$.fragment,Bd),Bd.forEach(o),Ld.forEach(o),Da=c(Br),Yo=a(Br,"SPAN",{});var Gd=i(Yo);La=n(Gd,"SwitchTransformersEncoderModel"),Gd.forEach(o),Br.forEach(o),Sr=c(t),M=a(t,"DIV",{class:!0});var B=i(M);v(Ct.$$.fragment,B),Ba=c(B),Jo=a(B,"P",{});var Hd=i(Jo);Ga=n(Hd,"The bare SWITCH_TRANSFORMERS Model transformer outputting encoder\u2019s raw hidden-states without any specific head on top."),Hd.forEach(o),Ha=c(B),R=a(B,"P",{});var ee=i(R);Va=n(ee,"The SWITCH_TRANSFORMERS model was proposed in "),Ft=a(ee,"A",{href:!0,rel:!0});var Vd=i(Ft);Za=n(Vd,`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),Vd.forEach(o),Ua=n(ee," by "),qt=a(ee,"A",{href:!0,rel:!0});var Zd=i(qt);Xa=n(Zd,`William
Fedus`),Zd.forEach(o),Ya=n(ee,", "),Pt=a(ee,"A",{href:!0,rel:!0});var Ud=i(Pt);Ja=n(Ud,`Barret
Zoph`),Ud.forEach(o),Ka=n(ee,", and "),At=a(ee,"A",{href:!0,rel:!0});var Xd=i(At);Qa=n(Xd,`Noam
Shazeer`),Xd.forEach(o),ei=n(ee,`. It\u2019s an encoder-decoder T5-like model
with sparse Feed Forward that stands for Mixture of Experts (MoE) architecture.`),ee.forEach(o),ti=c(B),Rt=a(B,"P",{});var Gr=i(Rt);oi=n(Gr,"This model inherits from "),to=a(Gr,"A",{href:!0});var Yd=i(to);ri=n(Yd,"PreTrainedModel"),Yd.forEach(o),ni=n(Gr,`. 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.)`),Gr.forEach(o),si=c(B),Ot=a(B,"P",{});var Hr=i(Ot);ai=n(Hr,"This model is also a PyTorch "),Nt=a(Hr,"A",{href:!0,rel:!0});var Jd=i(Nt);ii=n(Jd,"torch.nn.Module"),Jd.forEach(o),di=n(Hr,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Hr.forEach(o),li=c(B),W=a(B,"DIV",{class:!0});var We=i(W);v(It.$$.fragment,We),ci=c(We),me=a(We,"P",{});var po=i(me);hi=n(po,"The "),oo=a(po,"A",{href:!0});var Kd=i(oo);pi=n(Kd,"SwitchTransformersEncoderModel"),Kd.forEach(o),ui=n(po," forward method, overrides the "),Ko=a(po,"CODE",{});var Qd=i(Ko);mi=n(Qd,"__call__"),Qd.forEach(o),fi=n(po," special method."),po.forEach(o),_i=c(We),v(qe.$$.fragment,We),gi=c(We),v(Pe.$$.fragment,We),We.forEach(o),B.forEach(o),this.h()},h(){d(u,"name","hf:doc:metadata"),d(u,"content",JSON.stringify(pl)),d(_,"id","switchtransformers"),d(_,"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"),d(_,"href","#switchtransformers"),d(g,"class","relative group"),d(_e,"id","overview"),d(_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"),d(_e,"href","#overview"),d(te,"class","relative group"),d(Le,"href","https://arxiv.org/abs/2101.03961"),d(Le,"rel","nofollow"),d(Ht,"href","/docs/transformers/v4.27.1/en/model_doc/mt5#transformers.T5Tokenizer"),d(He,"href","https://moon-ci-docs.huggingface.co/docs/transformers/pr_19323/en/glossary#general-terms"),d(He,"rel","nofollow"),d(Ve,"href","https://huggingface.co/ybelkada"),d(Ve,"rel","nofollow"),d(Ze,"href","https://huggingface.co/ArtZucker"),d(Ze,"rel","nofollow"),d(Ue,"href","https://github.com/google/flaxformer/tree/main/flaxformer/architectures/moe"),d(Ue,"rel","nofollow"),d(Te,"id","resources"),d(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"),d(Te,"href","#resources"),d(oe,"class","relative group"),d(Vt,"href","./tasks/translation"),d(Zt,"href","./tasks/summarization"),d(be,"id","transformers.SwitchTransformersConfig"),d(be,"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"),d(be,"href","#transformers.SwitchTransformersConfig"),d(re,"class","relative group"),d(Ut,"href","/docs/transformers/v4.27.1/en/model_doc/switch_transformers#transformers.SwitchTransformersModel"),d(Ke,"href","https://huggingface.co/google/switch-base-8"),d(Ke,"rel","nofollow"),d(Xt,"href","/docs/transformers/v4.27.1/en/main_classes/configuration#transformers.PretrainedConfig"),d(Yt,"href","/docs/transformers/v4.27.1/en/main_classes/configuration#transformers.PretrainedConfig"),d(H,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(ye,"id","transformers.SwitchTransformersTop1Router"),d(ye,"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"),d(ye,"href","#transformers.SwitchTransformersTop1Router"),d(ae,"class","relative group"),d(tt,"href","https://arxiv.org/abs/2101.03961"),d(tt,"rel","nofollow"),d(ot,"href","https://arxiv.org/abs/2106.05974"),d(ot,"rel","nofollow"),d(ke,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(X,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(z,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(Se,"id","transformers.SwitchTransformersSparseMLP"),d(Se,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(Se,"href","#transformers.SwitchTransformersSparseMLP"),d(de,"class","relative group"),d(N,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(Z,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(xe,"id","transformers.SwitchTransformersModel"),d(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"),d(xe,"href","#transformers.SwitchTransformersModel"),d(le,"class","relative group"),d(ct,"href","https://arxiv.org/abs/2101.03961"),d(ct,"rel","nofollow"),d(ht,"href","https://arxiv.org/search/cs?searchtype=author&query=Fedus%2C+W"),d(ht,"rel","nofollow"),d(pt,"href","https://arxiv.org/search/cs?searchtype=author&query=Zoph%2C+B"),d(pt,"rel","nofollow"),d(ut,"href","https://arxiv.org/search/cs?searchtype=author&query=Shazeer%2C+N"),d(ut,"rel","nofollow"),d(Jt,"href","/docs/transformers/v4.27.1/en/main_classes/model#transformers.PreTrainedModel"),d(_t,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),d(_t,"rel","nofollow"),d(Kt,"href","/docs/transformers/v4.27.1/en/model_doc/switch_transformers#transformers.SwitchTransformersModel"),d(I,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d($,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(Me,"id","transformers.SwitchTransformersForConditionalGeneration"),d(Me,"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"),d(Me,"href","#transformers.SwitchTransformersForConditionalGeneration"),d(he,"class","relative group"),d(bt,"href","https://arxiv.org/abs/2101.03961"),d(bt,"rel","nofollow"),d(yt,"href","https://arxiv.org/search/cs?searchtype=author&query=Fedus%2C+W"),d(yt,"rel","nofollow"),d(kt,"href","https://arxiv.org/search/cs?searchtype=author&query=Zoph%2C+B"),d(kt,"rel","nofollow"),d(St,"href","https://arxiv.org/search/cs?searchtype=author&query=Shazeer%2C+N"),d(St,"rel","nofollow"),d(Qt,"href","/docs/transformers/v4.27.1/en/main_classes/model#transformers.PreTrainedModel"),d(Et,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),d(Et,"rel","nofollow"),d(eo,"href","/docs/transformers/v4.27.1/en/model_doc/switch_transformers#transformers.SwitchTransformersForConditionalGeneration"),d(j,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(E,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(Fe,"id","transformers.SwitchTransformersEncoderModel"),d(Fe,"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"),d(Fe,"href","#transformers.SwitchTransformersEncoderModel"),d(ue,"class","relative group"),d(Ft,"href","https://arxiv.org/abs/2101.03961"),d(Ft,"rel","nofollow"),d(qt,"href","https://arxiv.org/search/cs?searchtype=author&query=Fedus%2C+W"),d(qt,"rel","nofollow"),d(Pt,"href","https://arxiv.org/search/cs?searchtype=author&query=Zoph%2C+B"),d(Pt,"rel","nofollow"),d(At,"href","https://arxiv.org/search/cs?searchtype=author&query=Shazeer%2C+N"),d(At,"rel","nofollow"),d(to,"href","/docs/transformers/v4.27.1/en/main_classes/model#transformers.PreTrainedModel"),d(Nt,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),d(Nt,"rel","nofollow"),d(oo,"href","/docs/transformers/v4.27.1/en/model_doc/switch_transformers#transformers.SwitchTransformersEncoderModel"),d(W,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(M,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(t,p){e(document.head,u),m(t,x,p),m(t,g,p),e(g,_),e(_,w),b(h,w,null),e(g,f),e(g,F),e(F,Vr),m(t,rr,p),m(t,te,p),e(te,_e),e(_e,uo),b(De,uo,null),e(te,Zr),e(te,mo),e(mo,Ur),m(t,nr,p),m(t,ge,p),e(ge,Xr),e(ge,Le),e(Le,Yr),e(ge,Jr),m(t,sr,p),m(t,Dt,p),e(Dt,Kr),m(t,ar,p),m(t,Lt,p),e(Lt,Qr),m(t,ir,p),m(t,Bt,p),e(Bt,fo),e(fo,en),m(t,dr,p),m(t,Gt,p),e(Gt,tn),m(t,lr,p),m(t,we,p),e(we,Be),e(Be,on),e(Be,Ht),e(Ht,rn),e(Be,nn),e(we,sn),e(we,Ge),e(Ge,an),e(Ge,He),e(He,dn),e(Ge,ln),m(t,cr,p),m(t,O,p),e(O,cn),e(O,Ve),e(Ve,hn),e(O,pn),e(O,Ze),e(Ze,un),e(O,mn),e(O,Ue),e(Ue,fn),e(O,_n),m(t,hr,p),m(t,oe,p),e(oe,Te),e(Te,_o),b(Xe,_o,null),e(oe,gn),e(oe,go),e(go,wn),m(t,pr,p),m(t,ve,p),e(ve,wo),e(wo,Vt),e(Vt,Tn),e(ve,vn),e(ve,To),e(To,Zt),e(Zt,bn),m(t,ur,p),m(t,re,p),e(re,be),e(be,vo),b(Ye,vo,null),e(re,yn),e(re,bo),e(bo,kn),m(t,mr,p),m(t,H,p),b(Je,H,null),e(H,Sn),e(H,ne),e(ne,xn),e(ne,Ut),e(Ut,$n),e(ne,En),e(ne,Ke),e(Ke,Mn),e(ne,zn),e(H,Cn),e(H,se),e(se,Fn),e(se,Xt),e(Xt,qn),e(se,Pn),e(se,Yt),e(Yt,An),e(se,Rn),m(t,fr,p),m(t,ae,p),e(ae,ye),e(ye,yo),b(Qe,yo,null),e(ae,On),e(ae,ko),e(ko,Nn),m(t,_r,p),m(t,z,p),b(et,z,null),e(z,In),e(z,So),e(So,jn),e(z,Wn),e(z,V),e(V,Dn),e(V,tt),e(tt,Ln),e(V,Bn),e(V,ot),e(ot,Gn),e(V,Hn),e(V,xo),e(xo,Vn),e(V,Zn),e(z,Un),e(z,ke),b(rt,ke,null),e(ke,Xn),e(ke,$o),e($o,Yn),e(z,Jn),e(z,X),b(nt,X,null),e(X,Kn),e(X,ie),e(ie,Qn),e(ie,Eo),e(Eo,es),e(ie,ts),e(ie,Mo),e(Mo,os),e(ie,rs),e(X,ns),e(X,q),e(q,ss),e(q,zo),e(zo,as),e(q,is),e(q,Co),e(Co,ds),e(q,ls),e(q,Fo),e(Fo,cs),e(q,hs),e(q,qo),e(qo,ps),e(q,us),m(t,gr,p),m(t,de,p),e(de,Se),e(Se,Po),b(st,Po,null),e(de,ms),e(de,Ao),e(Ao,fs),m(t,wr,p),m(t,Z,p),b(at,Z,null),e(Z,_s),e(Z,Ro),e(Ro,gs),e(Z,ws),e(Z,N),b(it,N,null),e(N,Ts),e(N,Oo),e(Oo,vs),e(N,bs),e(N,U),e(U,ys),e(U,No),e(No,ks),e(U,Ss),e(U,Io),e(Io,xs),e(U,$s),e(U,jo),e(jo,Es),e(U,Ms),e(N,zs),e(N,Wo),e(Wo,Cs),m(t,Tr,p),m(t,le,p),e(le,xe),e(xe,Do),b(dt,Do,null),e(le,Fs),e(le,Lo),e(Lo,qs),m(t,vr,p),m(t,$,p),b(lt,$,null),e($,Ps),e($,Bo),e(Bo,As),e($,Rs),e($,P),e(P,Os),e(P,ct),e(ct,Ns),e(P,Is),e(P,ht),e(ht,js),e(P,Ws),e(P,pt),e(pt,Ds),e(P,Ls),e(P,ut),e(ut,Bs),e(P,Gs),e($,Hs),e($,mt),e(mt,Vs),e(mt,Jt),e(Jt,Zs),e(mt,Us),e($,Xs),e($,ft),e(ft,Ys),e(ft,_t),e(_t,Js),e(ft,Ks),e($,Qs),e($,I),b(gt,I,null),e(I,ea),e(I,ce),e(ce,ta),e(ce,Kt),e(Kt,oa),e(ce,ra),e(ce,Go),e(Go,na),e(ce,sa),e(I,aa),b($e,I,null),e(I,ia),b(Ee,I,null),m(t,br,p),m(t,he,p),e(he,Me),e(Me,Ho),b(wt,Ho,null),e(he,da),e(he,Vo),e(Vo,la),m(t,yr,p),m(t,E,p),b(Tt,E,null),e(E,ca),e(E,vt),e(vt,ha),e(vt,Zo),e(Zo,pa),e(vt,ua),e(E,ma),e(E,A),e(A,fa),e(A,bt),e(bt,_a),e(A,ga),e(A,yt),e(yt,wa),e(A,Ta),e(A,kt),e(kt,va),e(A,ba),e(A,St),e(St,ya),e(A,ka),e(E,Sa),e(E,xt),e(xt,xa),e(xt,Qt),e(Qt,$a),e(xt,Ea),e(E,Ma),e(E,$t),e($t,za),e($t,Et),e(Et,Ca),e($t,Fa),e(E,qa),e(E,j),b(Mt,j,null),e(j,Pa),e(j,pe),e(pe,Aa),e(pe,eo),e(eo,Ra),e(pe,Oa),e(pe,Uo),e(Uo,Na),e(pe,Ia),e(j,ja),b(ze,j,null),e(j,Wa),b(Ce,j,null),m(t,kr,p),m(t,ue,p),e(ue,Fe),e(Fe,Xo),b(zt,Xo,null),e(ue,Da),e(ue,Yo),e(Yo,La),m(t,Sr,p),m(t,M,p),b(Ct,M,null),e(M,Ba),e(M,Jo),e(Jo,Ga),e(M,Ha),e(M,R),e(R,Va),e(R,Ft),e(Ft,Za),e(R,Ua),e(R,qt),e(qt,Xa),e(R,Ya),e(R,Pt),e(Pt,Ja),e(R,Ka),e(R,At),e(At,Qa),e(R,ei),e(M,ti),e(M,Rt),e(Rt,oi),e(Rt,to),e(to,ri),e(Rt,ni),e(M,si),e(M,Ot),e(Ot,ai),e(Ot,Nt),e(Nt,ii),e(Ot,di),e(M,li),e(M,W),b(It,W,null),e(W,ci),e(W,me),e(me,hi),e(me,oo),e(oo,pi),e(me,ui),e(me,Ko),e(Ko,mi),e(me,fi),e(W,_i),b(qe,W,null),e(W,gi),b(Pe,W,null),xr=!0},p(t,[p]){const jt={};p&2&&(jt.$$scope={dirty:p,ctx:t}),$e.$set(jt);const Qo={};p&2&&(Qo.$$scope={dirty:p,ctx:t}),Ee.$set(Qo);const er={};p&2&&(er.$$scope={dirty:p,ctx:t}),ze.$set(er);const tr={};p&2&&(tr.$$scope={dirty:p,ctx:t}),Ce.$set(tr);const Wt={};p&2&&(Wt.$$scope={dirty:p,ctx:t}),qe.$set(Wt);const or={};p&2&&(or.$$scope={dirty:p,ctx:t}),Pe.$set(or)},i(t){xr||(y(h.$$.fragment,t),y(De.$$.fragment,t),y(Xe.$$.fragment,t),y(Ye.$$.fragment,t),y(Je.$$.fragment,t),y(Qe.$$.fragment,t),y(et.$$.fragment,t),y(rt.$$.fragment,t),y(nt.$$.fragment,t),y(st.$$.fragment,t),y(at.$$.fragment,t),y(it.$$.fragment,t),y(dt.$$.fragment,t),y(lt.$$.fragment,t),y(gt.$$.fragment,t),y($e.$$.fragment,t),y(Ee.$$.fragment,t),y(wt.$$.fragment,t),y(Tt.$$.fragment,t),y(Mt.$$.fragment,t),y(ze.$$.fragment,t),y(Ce.$$.fragment,t),y(zt.$$.fragment,t),y(Ct.$$.fragment,t),y(It.$$.fragment,t),y(qe.$$.fragment,t),y(Pe.$$.fragment,t),xr=!0)},o(t){k(h.$$.fragment,t),k(De.$$.fragment,t),k(Xe.$$.fragment,t),k(Ye.$$.fragment,t),k(Je.$$.fragment,t),k(Qe.$$.fragment,t),k(et.$$.fragment,t),k(rt.$$.fragment,t),k(nt.$$.fragment,t),k(st.$$.fragment,t),k(at.$$.fragment,t),k(it.$$.fragment,t),k(dt.$$.fragment,t),k(lt.$$.fragment,t),k(gt.$$.fragment,t),k($e.$$.fragment,t),k(Ee.$$.fragment,t),k(wt.$$.fragment,t),k(Tt.$$.fragment,t),k(Mt.$$.fragment,t),k(ze.$$.fragment,t),k(Ce.$$.fragment,t),k(zt.$$.fragment,t),k(Ct.$$.fragment,t),k(It.$$.fragment,t),k(qe.$$.fragment,t),k(Pe.$$.fragment,t),xr=!1},d(t){o(u),t&&o(x),t&&o(g),S(h),t&&o(rr),t&&o(te),S(De),t&&o(nr),t&&o(ge),t&&o(sr),t&&o(Dt),t&&o(ar),t&&o(Lt),t&&o(ir),t&&o(Bt),t&&o(dr),t&&o(Gt),t&&o(lr),t&&o(we),t&&o(cr),t&&o(O),t&&o(hr),t&&o(oe),S(Xe),t&&o(pr),t&&o(ve),t&&o(ur),t&&o(re),S(Ye),t&&o(mr),t&&o(H),S(Je),t&&o(fr),t&&o(ae),S(Qe),t&&o(_r),t&&o(z),S(et),S(rt),S(nt),t&&o(gr),t&&o(de),S(st),t&&o(wr),t&&o(Z),S(at),S(it),t&&o(Tr),t&&o(le),S(dt),t&&o(vr),t&&o($),S(lt),S(gt),S($e),S(Ee),t&&o(br),t&&o(he),S(wt),t&&o(yr),t&&o(E),S(Tt),S(Mt),S(ze),S(Ce),t&&o(kr),t&&o(ue),S(zt),t&&o(Sr),t&&o(M),S(Ct),S(It),S(qe),S(Pe)}}}const pl={local:"switchtransformers",sections:[{local:"overview",title:"Overview"},{local:"resources",title:"Resources"},{local:"transformers.SwitchTransformersConfig",title:"SwitchTransformersConfig"},{local:"transformers.SwitchTransformersTop1Router",title:"SwitchTransformersTop1Router"},{local:"transformers.SwitchTransformersSparseMLP",title:"SwitchTransformersSparseMLP"},{local:"transformers.SwitchTransformersModel",title:"SwitchTransformersModel"},{local:"transformers.SwitchTransformersForConditionalGeneration",title:"SwitchTransformersForConditionalGeneration"},{local:"transformers.SwitchTransformersEncoderModel",title:"SwitchTransformersEncoderModel"}],title:"SwitchTransformers"};function ul(C){return nl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class vl extends el{constructor(u){super();tl(this,u,ul,hl,ol,{})}}export{vl as default,pl as metadata};
