import{S as el,i as tl,s as ol,e as n,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 s,b as d,G as e,g as m,y as b,q as y,o as k,B as S,v as sl,L as vi}from"../../chunks/vendor-hf-doc-builder.js";import{T as wi}from"../../chunks/Tip-hf-doc-builder.js";import{D as H}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 nl(F){let u,x,g,_,w;return{c(){u=n("p"),x=r("Although the recipe for forward pass needs to be defined within this function, one should call the "),g=n("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=s(f,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=a(f,"CODE",{});var C=i(g);_=s(C,"Module"),C.forEach(o),w=s(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(F){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=n("p"),x=r("Example:"),g=l(),T(_.$$.fragment)},l(h){u=a(h,"P",{});var f=i(u);x=s(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(F){let u,x,g,_,w;return{c(){u=n("p"),x=r("Although the recipe for forward pass needs to be defined within this function, one should call the "),g=n("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=s(f,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=a(f,"CODE",{});var C=i(g);_=s(C,"Module"),C.forEach(o),w=s(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(F){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=n("p"),x=r("Examples:"),g=l(),T(_.$$.fragment)},l(h){u=a(h,"P",{});var f=i(u);x=s(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(F){let u,x,g,_,w;return{c(){u=n("p"),x=r("Although the recipe for forward pass needs to be defined within this function, one should call the "),g=n("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=s(f,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=a(f,"CODE",{});var C=i(g);_=s(C,"Module"),C.forEach(o),w=s(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(F){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=n("p"),x=r("Example:"),g=l(),T(_.$$.fragment)},l(h){u=a(h,"P",{});var f=i(u);x=s(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(F){let u,x,g,_,w,h,f,C,Vr,rr,te,_e,uo,De,Zr,mo,Ur,sr,ge,Xr,Le,Yr,Jr,nr,Dt,Kr,ar,Lt,Qr,ir,Gt,fo,es,dr,Ht,ts,lr,we,Ge,os,Bt,rs,ss,ns,He,as,Be,is,ds,cr,O,ls,Ve,cs,hs,Ze,ps,us,Ue,ms,fs,hr,oe,Te,_o,Xe,_s,go,gs,pr,ve,wo,Vt,ws,Ts,To,Zt,vs,ur,re,be,vo,Ye,bs,bo,ys,mr,B,Je,ks,se,Ss,Ut,xs,$s,Ke,Es,Ms,zs,ne,Fs,Xt,Cs,qs,Yt,Ps,As,fr,ae,ye,yo,Qe,Rs,ko,Os,_r,z,et,Ns,So,Is,js,V,Ws,tt,Ds,Ls,ot,Gs,Hs,xo,Bs,Vs,Zs,ke,rt,Us,$o,Xs,Ys,X,st,Js,ie,Ks,Eo,Qs,en,Mo,tn,on,rn,q,sn,zo,nn,an,Fo,dn,ln,Co,cn,hn,qo,pn,un,gr,de,Se,Po,nt,mn,Ao,fn,wr,Z,at,_n,Ro,gn,wn,N,it,Tn,Oo,vn,bn,U,yn,No,kn,Sn,Io,xn,$n,jo,En,Mn,zn,Wo,Fn,Tr,le,xe,Do,dt,Cn,Lo,qn,vr,$,lt,Pn,Go,An,Rn,P,On,ct,Nn,In,ht,jn,Wn,pt,Dn,Ln,ut,Gn,Hn,Bn,mt,Vn,Jt,Zn,Un,Xn,ft,Yn,_t,Jn,Kn,Qn,I,gt,ea,ce,ta,Kt,oa,ra,Ho,sa,na,aa,$e,ia,Ee,br,he,Me,Bo,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,Fa,Ca,qa,j,Mt,Pa,pe,Aa,eo,Ra,Oa,Uo,Na,Ia,ja,ze,Wa,Fe,kr,ue,Ce,Xo,zt,Da,Yo,La,Sr,M,Ft,Ga,Jo,Ha,Ba,R,Va,Ct,Za,Ua,qt,Xa,Ya,Pt,Ja,Ka,At,Qa,ei,ti,Rt,oi,to,ri,si,ni,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 H({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_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.29.0/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.29.0/src/transformers/models/switch_transformers/configuration_switch_transformers.py#L27"}}),Qe=new fe({}),et=new H({props:{name:"class transformers.SwitchTransformersTop1Router",anchor:"transformers.SwitchTransformersTop1Router",parameters:[{name:"config",val:": SwitchTransformersConfig"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L131"}}),rt=new H({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.29.0/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>
`}}),st=new H({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.29.0/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>
`}}),nt=new fe({}),at=new H({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.29.0/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L304"}}),it=new H({props:{name:"forward",anchor:"transformers.SwitchTransformersSparseMLP.forward",parameters:[{name:"hidden_states",val:""}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L319"}}),dt=new fe({}),lt=new H({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.29.0/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.29.0/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L1338"}}),gt=new H({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.29.0/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for 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.29.0/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#decoder-input-ids">What are decoder input IDs?</a></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.29.0/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.29.0/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.29.0/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:[nl]},$$scope:{ctx:F}}}),Ee=new Ti({props:{anchor:"transformers.SwitchTransformersModel.forward.example",$$slots:{default:[al]},$$scope:{ctx:F}}}),wt=new fe({}),Tt=new H({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.29.0/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.29.0/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L1506"}}),Mt=new H({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.29.0/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for 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.29.0/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#decoder-input-ids">What are decoder input IDs?</a></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.29.0/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.29.0/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.29.0/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:F}}}),Fe=new Ti({props:{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.example",$$slots:{default:[dl]},$$scope:{ctx:F}}}),zt=new fe({}),Ft=new H({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.29.0/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.29.0/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L1823"}}),It=new H({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.29.0/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/v4.29.0/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for 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.29.0/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.29.0/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L1859",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.29.0/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:F}}}),Pe=new Ti({props:{anchor:"transformers.SwitchTransformersEncoderModel.forward.example",$$slots:{default:[cl]},$$scope:{ctx:F}}}),{c(){u=n("meta"),x=l(),g=n("h1"),_=n("a"),w=n("span"),T(h.$$.fragment),f=l(),C=n("span"),Vr=r("SwitchTransformers"),rr=l(),te=n("h2"),_e=n("a"),uo=n("span"),T(De.$$.fragment),Zr=l(),mo=n("span"),Ur=r("Overview"),sr=l(),ge=n("p"),Xr=r("The SwitchTransformers model was proposed in "),Le=n("a"),Yr=r("Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity"),Jr=r(" by William Fedus, Barret Zoph, Noam Shazeer."),nr=l(),Dt=n("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=n("p"),Qr=r("The abstract from the paper is the following:"),ir=l(),Gt=n("p"),fo=n("em"),es=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(),Ht=n("p"),ts=r("Tips:"),lr=l(),we=n("ul"),Ge=n("li"),os=r("SwitchTransformers uses the "),Bt=n("a"),rs=r("T5Tokenizer"),ss=r(", which can be loaded directly from each model\u2019s repository."),ns=l(),He=n("li"),as=r("The released weights are pretrained on English "),Be=n("a"),is=r("Masked Language Modeling"),ds=r(" task, and should be finetuned."),cr=l(),O=n("p"),ls=r("This model was contributed by "),Ve=n("a"),cs=r("Younes Belkada"),hs=r(" and "),Ze=n("a"),ps=r("Arthur Zucker"),us=r(` .
The original code can be found `),Ue=n("a"),ms=r("here"),fs=r("."),hr=l(),oe=n("h2"),Te=n("a"),_o=n("span"),T(Xe.$$.fragment),_s=l(),go=n("span"),gs=r("Resources"),pr=l(),ve=n("ul"),wo=n("li"),Vt=n("a"),ws=r("Translation task guide"),Ts=l(),To=n("li"),Zt=n("a"),vs=r("Summarization task guide"),ur=l(),re=n("h2"),be=n("a"),vo=n("span"),T(Ye.$$.fragment),bs=l(),bo=n("span"),ys=r("SwitchTransformersConfig"),mr=l(),B=n("div"),T(Je.$$.fragment),ks=l(),se=n("p"),Ss=r("This is the configuration class to store the configuration of a "),Ut=n("a"),xs=r("SwitchTransformersModel"),$s=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=n("a"),Es=r("google/switch-base-8"),Ms=r(" architecture."),zs=l(),ne=n("p"),Fs=r("Configuration objects inherit from "),Xt=n("a"),Cs=r("PretrainedConfig"),qs=r(` and can be used to control the model outputs. Read the
documentation from `),Yt=n("a"),Ps=r("PretrainedConfig"),As=r(" for more information."),fr=l(),ae=n("h2"),ye=n("a"),yo=n("span"),T(Qe.$$.fragment),Rs=l(),ko=n("span"),Os=r("SwitchTransformersTop1Router"),_r=l(),z=n("div"),T(et.$$.fragment),Ns=l(),So=n("p"),Is=r("Router using tokens choose top-1 experts assignment."),js=l(),V=n("p"),Ws=r("This router uses the same mechanism as in Switch Transformer ("),tt=n("a"),Ds=r("https://arxiv.org/abs/2101.03961"),Ls=r(`) and V-MoE
(`),ot=n("a"),Gs=r("https://arxiv.org/abs/2106.05974"),Hs=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=n("strong"),Bs=r(`There is no guarantee that each
token is processed by an expert`),Vs=r(", or that each expert receives at least one token."),Zs=l(),ke=n("div"),T(rt.$$.fragment),Us=l(),$o=n("p"),Xs=r("Computes router probabilities from input hidden states."),Ys=l(),X=n("div"),T(st.$$.fragment),Js=l(),ie=n("p"),Ks=r(`Generic forward function for every Router class. Each Router expects to have the same input hidden states
(`),Eo=n("code"),Qs=r("hidden_states"),en=r(") corresponding to the hidden states for each token, the "),Mo=n("code"),tn=r("expert_capacity"),on=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.`),rn=l(),q=n("p"),sn=r("Each Router works as the following: it expects the hidden states for each token, gets the "),zo=n("code"),nn=r("router_probs"),an=r(` and
`),Fo=n("code"),dn=r("router_logits"),ln=r(" from the "),Co=n("code"),cn=r("router_weights"),hn=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=n("code"),pn=r("_compute_routing_instructions"),un=r("."),gr=l(),de=n("h2"),Se=n("a"),Po=n("span"),T(nt.$$.fragment),mn=l(),Ao=n("span"),fn=r("SwitchTransformersSparseMLP"),wr=l(),Z=n("div"),T(at.$$.fragment),_n=l(),Ro=n("p"),gn=r("Implementation of the Switch Transformers Sparse MLP module."),wn=l(),N=n("div"),T(it.$$.fragment),Tn=l(),Oo=n("p"),vn=r("Hold on, this will be slightly tricky to understand In the correct order, a MoE layer does the following:"),bn=l(),U=n("p"),yn=r("1- Gets the "),No=n("code"),kn=r("router_mask"),Sn=r(" from the router. The shape of the mask is "),Io=n("code"),xn=r("(batch_size, sequence_length, num_expert)"),$n=r(`
and corresponds to the argmax of the `),jo=n("code"),En=r("router_probs"),Mn=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).`),zn=l(),Wo=n("p"),Fn=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=n("h2"),xe=n("a"),Do=n("span"),T(dt.$$.fragment),Cn=l(),Lo=n("span"),qn=r("SwitchTransformersModel"),vr=l(),$=n("div"),T(lt.$$.fragment),Pn=l(),Go=n("p"),An=r("The bare SWITCH_TRANSFORMERS Model transformer outputting raw hidden-states without any specific head on top."),Rn=l(),P=n("p"),On=r("The SWITCH_TRANSFORMERS model was proposed in "),ct=n("a"),Nn=r(`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),In=r(" by "),ht=n("a"),jn=r(`William
Fedus`),Wn=r(", "),pt=n("a"),Dn=r(`Barret
Zoph`),Ln=r(", and "),ut=n("a"),Gn=r(`Noam
Shazeer`),Hn=r(`. It\u2019s an encoder-decoder T5-like model
with sparse Feed Forward that stands for Mixture of Experts (MoE) architecture.`),Bn=l(),mt=n("p"),Vn=r("This model inherits from "),Jt=n("a"),Zn=r("PreTrainedModel"),Un=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.)`),Xn=l(),ft=n("p"),Yn=r("This model is also a PyTorch "),_t=n("a"),Jn=r("torch.nn.Module"),Kn=r(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Qn=l(),I=n("div"),T(gt.$$.fragment),ea=l(),ce=n("p"),ta=r("The "),Kt=n("a"),oa=r("SwitchTransformersModel"),ra=r(" forward method, overrides the "),Ho=n("code"),sa=r("__call__"),na=r(" special method."),aa=l(),T($e.$$.fragment),ia=l(),T(Ee.$$.fragment),br=l(),he=n("h2"),Me=n("a"),Bo=n("span"),T(wt.$$.fragment),da=l(),Vo=n("span"),la=r("SwitchTransformersForConditionalGeneration"),yr=l(),E=n("div"),T(Tt.$$.fragment),ca=l(),vt=n("p"),ha=r("SWITCH_TRANSFORMERS Model with a "),Zo=n("code"),pa=r("language modeling"),ua=r(" head on top."),ma=l(),A=n("p"),fa=r("The SWITCH_TRANSFORMERS model was proposed in "),bt=n("a"),_a=r(`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),ga=r(" by "),yt=n("a"),wa=r(`William
Fedus`),Ta=r(", "),kt=n("a"),va=r(`Barret
Zoph`),ba=r(", and "),St=n("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=n("p"),xa=r("This model inherits from "),Qt=n("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=n("p"),za=r("This model is also a PyTorch "),Et=n("a"),Fa=r("torch.nn.Module"),Ca=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=n("div"),T(Mt.$$.fragment),Pa=l(),pe=n("p"),Aa=r("The "),eo=n("a"),Ra=r("SwitchTransformersForConditionalGeneration"),Oa=r(" forward method, overrides the "),Uo=n("code"),Na=r("__call__"),Ia=r(" special method."),ja=l(),T(ze.$$.fragment),Wa=l(),T(Fe.$$.fragment),kr=l(),ue=n("h2"),Ce=n("a"),Xo=n("span"),T(zt.$$.fragment),Da=l(),Yo=n("span"),La=r("SwitchTransformersEncoderModel"),Sr=l(),M=n("div"),T(Ft.$$.fragment),Ga=l(),Jo=n("p"),Ha=r("The bare SWITCH_TRANSFORMERS Model transformer outputting encoder\u2019s raw hidden-states without any specific head on top."),Ba=l(),R=n("p"),Va=r("The SWITCH_TRANSFORMERS model was proposed in "),Ct=n("a"),Za=r(`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),Ua=r(" by "),qt=n("a"),Xa=r(`William
Fedus`),Ya=r(", "),Pt=n("a"),Ja=r(`Barret
Zoph`),Ka=r(", and "),At=n("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=n("p"),oi=r("This model inherits from "),to=n("a"),ri=r("PreTrainedModel"),si=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.)`),ni=l(),Ot=n("p"),ai=r("This model is also a PyTorch "),Nt=n("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=n("div"),T(It.$$.fragment),ci=l(),me=n("p"),hi=r("The "),oo=n("a"),pi=r("SwitchTransformersEncoderModel"),ui=r(" forward method, overrides the "),Ko=n("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),C=a(jt,"SPAN",{});var tr=i(C);Vr=s(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=s(ki,"Overview"),ki.forEach(o),Wt.forEach(o),sr=c(t),ge=a(t,"P",{});var $r=i(ge);Xr=s($r,"The SwitchTransformers model was proposed in "),Le=a($r,"A",{href:!0,rel:!0});var Si=i(Le);Yr=s(Si,"Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity"),Si.forEach(o),Jr=s($r," by William Fedus, Barret Zoph, Noam Shazeer."),$r.forEach(o),nr=c(t),Dt=a(t,"P",{});var xi=i(Dt);Kr=s(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=s($i,"The abstract from the paper is the following:"),$i.forEach(o),ir=c(t),Gt=a(t,"P",{});var Ei=i(Gt);fo=a(Ei,"EM",{});var Mi=i(fo);es=s(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),Ht=a(t,"P",{});var zi=i(Ht);ts=s(zi,"Tips:"),zi.forEach(o),lr=c(t),we=a(t,"UL",{});var Er=i(we);Ge=a(Er,"LI",{});var Mr=i(Ge);os=s(Mr,"SwitchTransformers uses the "),Bt=a(Mr,"A",{href:!0});var Fi=i(Bt);rs=s(Fi,"T5Tokenizer"),Fi.forEach(o),ss=s(Mr,", which can be loaded directly from each model\u2019s repository."),Mr.forEach(o),ns=c(Er),He=a(Er,"LI",{});var zr=i(He);as=s(zr,"The released weights are pretrained on English "),Be=a(zr,"A",{href:!0,rel:!0});var Ci=i(Be);is=s(Ci,"Masked Language Modeling"),Ci.forEach(o),ds=s(zr," task, and should be finetuned."),zr.forEach(o),Er.forEach(o),cr=c(t),O=a(t,"P",{});var Ae=i(O);ls=s(Ae,"This model was contributed by "),Ve=a(Ae,"A",{href:!0,rel:!0});var qi=i(Ve);cs=s(qi,"Younes Belkada"),qi.forEach(o),hs=s(Ae," and "),Ze=a(Ae,"A",{href:!0,rel:!0});var Pi=i(Ze);ps=s(Pi,"Arthur Zucker"),Pi.forEach(o),us=s(Ae,` .
The original code can be found `),Ue=a(Ae,"A",{href:!0,rel:!0});var Ai=i(Ue);ms=s(Ai,"here"),Ai.forEach(o),fs=s(Ae,"."),Ae.forEach(o),hr=c(t),oe=a(t,"H2",{class:!0});var Fr=i(oe);Te=a(Fr,"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),_s=c(Fr),go=a(Fr,"SPAN",{});var Ni=i(go);gs=s(Ni,"Resources"),Ni.forEach(o),Fr.forEach(o),pr=c(t),ve=a(t,"UL",{});var Cr=i(ve);wo=a(Cr,"LI",{});var Ii=i(wo);Vt=a(Ii,"A",{href:!0});var ji=i(Vt);ws=s(ji,"Translation task guide"),ji.forEach(o),Ii.forEach(o),Ts=c(Cr),To=a(Cr,"LI",{});var Wi=i(To);Zt=a(Wi,"A",{href:!0});var Di=i(Zt);vs=s(Di,"Summarization task guide"),Di.forEach(o),Wi.forEach(o),Cr.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 Gi=i(vo);v(Ye.$$.fragment,Gi),Gi.forEach(o),Li.forEach(o),bs=c(qr),bo=a(qr,"SPAN",{});var Hi=i(bo);ys=s(Hi,"SwitchTransformersConfig"),Hi.forEach(o),qr.forEach(o),mr=c(t),B=a(t,"DIV",{class:!0});var ro=i(B);v(Je.$$.fragment,ro),ks=c(ro),se=a(ro,"P",{});var so=i(se);Ss=s(so,"This is the configuration class to store the configuration of a "),Ut=a(so,"A",{href:!0});var Bi=i(Ut);xs=s(Bi,"SwitchTransformersModel"),Bi.forEach(o),$s=s(so,`. 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(so,"A",{href:!0,rel:!0});var Vi=i(Ke);Es=s(Vi,"google/switch-base-8"),Vi.forEach(o),Ms=s(so," architecture."),so.forEach(o),zs=c(ro),ne=a(ro,"P",{});var no=i(ne);Fs=s(no,"Configuration objects inherit from "),Xt=a(no,"A",{href:!0});var Zi=i(Xt);Cs=s(Zi,"PretrainedConfig"),Zi.forEach(o),qs=s(no,` and can be used to control the model outputs. Read the
documentation from `),Yt=a(no,"A",{href:!0});var Ui=i(Yt);Ps=s(Ui,"PretrainedConfig"),Ui.forEach(o),As=s(no," for more information."),no.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),Rs=c(Pr),ko=a(Pr,"SPAN",{});var Ji=i(ko);Os=s(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),Ns=c(Y),So=a(Y,"P",{});var Ki=i(So);Is=s(Ki,"Router using tokens choose top-1 experts assignment."),Ki.forEach(o),js=c(Y),V=a(Y,"P",{});var Re=i(V);Ws=s(Re,"This router uses the same mechanism as in Switch Transformer ("),tt=a(Re,"A",{href:!0,rel:!0});var Qi=i(tt);Ds=s(Qi,"https://arxiv.org/abs/2101.03961"),Qi.forEach(o),Ls=s(Re,`) and V-MoE
(`),ot=a(Re,"A",{href:!0,rel:!0});var ed=i(ot);Gs=s(ed,"https://arxiv.org/abs/2106.05974"),ed.forEach(o),Hs=s(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);Bs=s(td,`There is no guarantee that each
token is processed by an expert`),td.forEach(o),Vs=s(Re,", or that each expert receives at least one token."),Re.forEach(o),Zs=c(Y),ke=a(Y,"DIV",{class:!0});var Ar=i(ke);v(rt.$$.fragment,Ar),Us=c(Ar),$o=a(Ar,"P",{});var od=i($o);Xs=s(od,"Computes router probabilities from input hidden states."),od.forEach(o),Ar.forEach(o),Ys=c(Y),X=a(Y,"DIV",{class:!0});var ao=i(X);v(st.$$.fragment,ao),Js=c(ao),ie=a(ao,"P",{});var io=i(ie);Ks=s(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);Qs=s(rd,"hidden_states"),rd.forEach(o),en=s(io,") corresponding to the hidden states for each token, the "),Mo=a(io,"CODE",{});var sd=i(Mo);tn=s(sd,"expert_capacity"),sd.forEach(o),on=s(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),rn=c(ao),q=a(ao,"P",{});var J=i(q);sn=s(J,"Each Router works as the following: it expects the hidden states for each token, gets the "),zo=a(J,"CODE",{});var nd=i(zo);nn=s(nd,"router_probs"),nd.forEach(o),an=s(J,` and
`),Fo=a(J,"CODE",{});var ad=i(Fo);dn=s(ad,"router_logits"),ad.forEach(o),ln=s(J," from the "),Co=a(J,"CODE",{});var id=i(Co);cn=s(id,"router_weights"),id.forEach(o),hn=s(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);pn=s(dd,"_compute_routing_instructions"),dd.forEach(o),un=s(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(nt.$$.fragment,cd),cd.forEach(o),ld.forEach(o),mn=c(Rr),Ao=a(Rr,"SPAN",{});var hd=i(Ao);fn=s(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),_n=c(lo),Ro=a(lo,"P",{});var pd=i(Ro);gn=s(pd,"Implementation of the Switch Transformers Sparse MLP module."),pd.forEach(o),wn=c(lo),N=a(lo,"DIV",{class:!0});var Oe=i(N);v(it.$$.fragment,Oe),Tn=c(Oe),Oo=a(Oe,"P",{});var ud=i(Oo);vn=s(ud,"Hold on, this will be slightly tricky to understand In the correct order, a MoE layer does the following:"),ud.forEach(o),bn=c(Oe),U=a(Oe,"P",{});var Ne=i(U);yn=s(Ne,"1- Gets the "),No=a(Ne,"CODE",{});var md=i(No);kn=s(md,"router_mask"),md.forEach(o),Sn=s(Ne," from the router. The shape of the mask is "),Io=a(Ne,"CODE",{});var fd=i(Io);xn=s(fd,"(batch_size, sequence_length, num_expert)"),fd.forEach(o),$n=s(Ne,`
and corresponds to the argmax of the `),jo=a(Ne,"CODE",{});var _d=i(jo);En=s(_d,"router_probs"),_d.forEach(o),Mn=s(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),zn=c(Oe),Wo=a(Oe,"P",{});var gd=i(Wo);Fn=s(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),Cn=c(Or),Lo=a(Or,"SPAN",{});var vd=i(Lo);qn=s(vd,"SwitchTransformersModel"),vd.forEach(o),Or.forEach(o),vr=c(t),$=a(t,"DIV",{class:!0});var D=i($);v(lt.$$.fragment,D),Pn=c(D),Go=a(D,"P",{});var bd=i(Go);An=s(bd,"The bare SWITCH_TRANSFORMERS Model transformer outputting raw hidden-states without any specific head on top."),bd.forEach(o),Rn=c(D),P=a(D,"P",{});var K=i(P);On=s(K,"The SWITCH_TRANSFORMERS model was proposed in "),ct=a(K,"A",{href:!0,rel:!0});var yd=i(ct);Nn=s(yd,`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),yd.forEach(o),In=s(K," by "),ht=a(K,"A",{href:!0,rel:!0});var kd=i(ht);jn=s(kd,`William
Fedus`),kd.forEach(o),Wn=s(K,", "),pt=a(K,"A",{href:!0,rel:!0});var Sd=i(pt);Dn=s(Sd,`Barret
Zoph`),Sd.forEach(o),Ln=s(K,", and "),ut=a(K,"A",{href:!0,rel:!0});var xd=i(ut);Gn=s(xd,`Noam
Shazeer`),xd.forEach(o),Hn=s(K,`. It\u2019s an encoder-decoder T5-like model
with sparse Feed Forward that stands for Mixture of Experts (MoE) architecture.`),K.forEach(o),Bn=c(D),mt=a(D,"P",{});var Nr=i(mt);Vn=s(Nr,"This model inherits from "),Jt=a(Nr,"A",{href:!0});var $d=i(Jt);Zn=s($d,"PreTrainedModel"),$d.forEach(o),Un=s(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),Xn=c(D),ft=a(D,"P",{});var Ir=i(ft);Yn=s(Ir,"This model is also a PyTorch "),_t=a(Ir,"A",{href:!0,rel:!0});var Ed=i(_t);Jn=s(Ed,"torch.nn.Module"),Ed.forEach(o),Kn=s(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),Qn=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=s(co,"The "),Kt=a(co,"A",{href:!0});var Md=i(Kt);oa=s(Md,"SwitchTransformersModel"),Md.forEach(o),ra=s(co," forward method, overrides the "),Ho=a(co,"CODE",{});var zd=i(Ho);sa=s(zd,"__call__"),zd.forEach(o),na=s(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 Fd=i(Me);Bo=a(Fd,"SPAN",{});var Cd=i(Bo);v(wt.$$.fragment,Cd),Cd.forEach(o),Fd.forEach(o),da=c(jr),Vo=a(jr,"SPAN",{});var qd=i(Vo);la=s(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=s(Wr,"SWITCH_TRANSFORMERS Model with a "),Zo=a(Wr,"CODE",{});var Pd=i(Zo);pa=s(Pd,"language modeling"),Pd.forEach(o),ua=s(Wr," head on top."),Wr.forEach(o),ma=c(L),A=a(L,"P",{});var Q=i(A);fa=s(Q,"The SWITCH_TRANSFORMERS model was proposed in "),bt=a(Q,"A",{href:!0,rel:!0});var Ad=i(bt);_a=s(Ad,`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),Ad.forEach(o),ga=s(Q," by "),yt=a(Q,"A",{href:!0,rel:!0});var Rd=i(yt);wa=s(Rd,`William
Fedus`),Rd.forEach(o),Ta=s(Q,", "),kt=a(Q,"A",{href:!0,rel:!0});var Od=i(kt);va=s(Od,`Barret
Zoph`),Od.forEach(o),ba=s(Q,", and "),St=a(Q,"A",{href:!0,rel:!0});var Nd=i(St);ya=s(Nd,`Noam
Shazeer`),Nd.forEach(o),ka=s(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=s(Dr,"This model inherits from "),Qt=a(Dr,"A",{href:!0});var Id=i(Qt);$a=s(Id,"PreTrainedModel"),Id.forEach(o),Ea=s(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=s(Lr,"This model is also a PyTorch "),Et=a(Lr,"A",{href:!0,rel:!0});var jd=i(Et);Fa=s(jd,"torch.nn.Module"),jd.forEach(o),Ca=s(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=s(ho,"The "),eo=a(ho,"A",{href:!0});var Wd=i(eo);Ra=s(Wd,"SwitchTransformersForConditionalGeneration"),Wd.forEach(o),Oa=s(ho," forward method, overrides the "),Uo=a(ho,"CODE",{});var Dd=i(Uo);Na=s(Dd,"__call__"),Dd.forEach(o),Ia=s(ho," special method."),ho.forEach(o),ja=c(je),v(ze.$$.fragment,je),Wa=c(je),v(Fe.$$.fragment,je),je.forEach(o),L.forEach(o),kr=c(t),ue=a(t,"H2",{class:!0});var Gr=i(ue);Ce=a(Gr,"A",{id:!0,class:!0,href:!0});var Ld=i(Ce);Xo=a(Ld,"SPAN",{});var Gd=i(Xo);v(zt.$$.fragment,Gd),Gd.forEach(o),Ld.forEach(o),Da=c(Gr),Yo=a(Gr,"SPAN",{});var Hd=i(Yo);La=s(Hd,"SwitchTransformersEncoderModel"),Hd.forEach(o),Gr.forEach(o),Sr=c(t),M=a(t,"DIV",{class:!0});var G=i(M);v(Ft.$$.fragment,G),Ga=c(G),Jo=a(G,"P",{});var Bd=i(Jo);Ha=s(Bd,"The bare SWITCH_TRANSFORMERS Model transformer outputting encoder\u2019s raw hidden-states without any specific head on top."),Bd.forEach(o),Ba=c(G),R=a(G,"P",{});var ee=i(R);Va=s(ee,"The SWITCH_TRANSFORMERS model was proposed in "),Ct=a(ee,"A",{href:!0,rel:!0});var Vd=i(Ct);Za=s(Vd,`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),Vd.forEach(o),Ua=s(ee," by "),qt=a(ee,"A",{href:!0,rel:!0});var Zd=i(qt);Xa=s(Zd,`William
Fedus`),Zd.forEach(o),Ya=s(ee,", "),Pt=a(ee,"A",{href:!0,rel:!0});var Ud=i(Pt);Ja=s(Ud,`Barret
Zoph`),Ud.forEach(o),Ka=s(ee,", and "),At=a(ee,"A",{href:!0,rel:!0});var Xd=i(At);Qa=s(Xd,`Noam
Shazeer`),Xd.forEach(o),ei=s(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(G),Rt=a(G,"P",{});var Hr=i(Rt);oi=s(Hr,"This model inherits from "),to=a(Hr,"A",{href:!0});var Yd=i(to);ri=s(Yd,"PreTrainedModel"),Yd.forEach(o),si=s(Hr,`. 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.)`),Hr.forEach(o),ni=c(G),Ot=a(G,"P",{});var Br=i(Ot);ai=s(Br,"This model is also a PyTorch "),Nt=a(Br,"A",{href:!0,rel:!0});var Jd=i(Nt);ii=s(Jd,"torch.nn.Module"),Jd.forEach(o),di=s(Br,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Br.forEach(o),li=c(G),W=a(G,"DIV",{class:!0});var We=i(W);v(It.$$.fragment,We),ci=c(We),me=a(We,"P",{});var po=i(me);hi=s(po,"The "),oo=a(po,"A",{href:!0});var Kd=i(oo);pi=s(Kd,"SwitchTransformersEncoderModel"),Kd.forEach(o),ui=s(po," forward method, overrides the "),Ko=a(po,"CODE",{});var Qd=i(Ko);mi=s(Qd,"__call__"),Qd.forEach(o),fi=s(po," special method."),po.forEach(o),_i=c(We),v(qe.$$.fragment,We),gi=c(We),v(Pe.$$.fragment,We),We.forEach(o),G.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(Bt,"href","/docs/transformers/v4.29.0/en/model_doc/t5#transformers.T5Tokenizer"),d(Be,"href","https://moon-ci-docs.huggingface.co/docs/transformers/pr_19323/en/glossary#general-terms"),d(Be,"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.29.0/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.29.0/en/main_classes/configuration#transformers.PretrainedConfig"),d(Yt,"href","/docs/transformers/v4.29.0/en/main_classes/configuration#transformers.PretrainedConfig"),d(B,"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.29.0/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.29.0/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.29.0/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.29.0/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(Ce,"id","transformers.SwitchTransformersEncoderModel"),d(Ce,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(Ce,"href","#transformers.SwitchTransformersEncoderModel"),d(ue,"class","relative group"),d(Ct,"href","https://arxiv.org/abs/2101.03961"),d(Ct,"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.29.0/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.29.0/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,C),e(C,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,sr,p),m(t,ge,p),e(ge,Xr),e(ge,Le),e(Le,Yr),e(ge,Jr),m(t,nr,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,Gt,p),e(Gt,fo),e(fo,es),m(t,dr,p),m(t,Ht,p),e(Ht,ts),m(t,lr,p),m(t,we,p),e(we,Ge),e(Ge,os),e(Ge,Bt),e(Bt,rs),e(Ge,ss),e(we,ns),e(we,He),e(He,as),e(He,Be),e(Be,is),e(He,ds),m(t,cr,p),m(t,O,p),e(O,ls),e(O,Ve),e(Ve,cs),e(O,hs),e(O,Ze),e(Ze,ps),e(O,us),e(O,Ue),e(Ue,ms),e(O,fs),m(t,hr,p),m(t,oe,p),e(oe,Te),e(Te,_o),b(Xe,_o,null),e(oe,_s),e(oe,go),e(go,gs),m(t,pr,p),m(t,ve,p),e(ve,wo),e(wo,Vt),e(Vt,ws),e(ve,Ts),e(ve,To),e(To,Zt),e(Zt,vs),m(t,ur,p),m(t,re,p),e(re,be),e(be,vo),b(Ye,vo,null),e(re,bs),e(re,bo),e(bo,ys),m(t,mr,p),m(t,B,p),b(Je,B,null),e(B,ks),e(B,se),e(se,Ss),e(se,Ut),e(Ut,xs),e(se,$s),e(se,Ke),e(Ke,Es),e(se,Ms),e(B,zs),e(B,ne),e(ne,Fs),e(ne,Xt),e(Xt,Cs),e(ne,qs),e(ne,Yt),e(Yt,Ps),e(ne,As),m(t,fr,p),m(t,ae,p),e(ae,ye),e(ye,yo),b(Qe,yo,null),e(ae,Rs),e(ae,ko),e(ko,Os),m(t,_r,p),m(t,z,p),b(et,z,null),e(z,Ns),e(z,So),e(So,Is),e(z,js),e(z,V),e(V,Ws),e(V,tt),e(tt,Ds),e(V,Ls),e(V,ot),e(ot,Gs),e(V,Hs),e(V,xo),e(xo,Bs),e(V,Vs),e(z,Zs),e(z,ke),b(rt,ke,null),e(ke,Us),e(ke,$o),e($o,Xs),e(z,Ys),e(z,X),b(st,X,null),e(X,Js),e(X,ie),e(ie,Ks),e(ie,Eo),e(Eo,Qs),e(ie,en),e(ie,Mo),e(Mo,tn),e(ie,on),e(X,rn),e(X,q),e(q,sn),e(q,zo),e(zo,nn),e(q,an),e(q,Fo),e(Fo,dn),e(q,ln),e(q,Co),e(Co,cn),e(q,hn),e(q,qo),e(qo,pn),e(q,un),m(t,gr,p),m(t,de,p),e(de,Se),e(Se,Po),b(nt,Po,null),e(de,mn),e(de,Ao),e(Ao,fn),m(t,wr,p),m(t,Z,p),b(at,Z,null),e(Z,_n),e(Z,Ro),e(Ro,gn),e(Z,wn),e(Z,N),b(it,N,null),e(N,Tn),e(N,Oo),e(Oo,vn),e(N,bn),e(N,U),e(U,yn),e(U,No),e(No,kn),e(U,Sn),e(U,Io),e(Io,xn),e(U,$n),e(U,jo),e(jo,En),e(U,Mn),e(N,zn),e(N,Wo),e(Wo,Fn),m(t,Tr,p),m(t,le,p),e(le,xe),e(xe,Do),b(dt,Do,null),e(le,Cn),e(le,Lo),e(Lo,qn),m(t,vr,p),m(t,$,p),b(lt,$,null),e($,Pn),e($,Go),e(Go,An),e($,Rn),e($,P),e(P,On),e(P,ct),e(ct,Nn),e(P,In),e(P,ht),e(ht,jn),e(P,Wn),e(P,pt),e(pt,Dn),e(P,Ln),e(P,ut),e(ut,Gn),e(P,Hn),e($,Bn),e($,mt),e(mt,Vn),e(mt,Jt),e(Jt,Zn),e(mt,Un),e($,Xn),e($,ft),e(ft,Yn),e(ft,_t),e(_t,Jn),e(ft,Kn),e($,Qn),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,Ho),e(Ho,sa),e(ce,na),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,Bo),b(wt,Bo,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,Fa),e($t,Ca),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(Fe,j,null),m(t,kr,p),m(t,ue,p),e(ue,Ce),e(Ce,Xo),b(zt,Xo,null),e(ue,Da),e(ue,Yo),e(Yo,La),m(t,Sr,p),m(t,M,p),b(Ft,M,null),e(M,Ga),e(M,Jo),e(Jo,Ha),e(M,Ba),e(M,R),e(R,Va),e(R,Ct),e(Ct,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,si),e(M,ni),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}),Fe.$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(st.$$.fragment,t),y(nt.$$.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(Fe.$$.fragment,t),y(zt.$$.fragment,t),y(Ft.$$.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(st.$$.fragment,t),k(nt.$$.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(Fe.$$.fragment,t),k(zt.$$.fragment,t),k(Ft.$$.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(sr),t&&o(ge),t&&o(nr),t&&o(Dt),t&&o(ar),t&&o(Lt),t&&o(ir),t&&o(Gt),t&&o(dr),t&&o(Ht),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(B),S(Je),t&&o(fr),t&&o(ae),S(Qe),t&&o(_r),t&&o(z),S(et),S(rt),S(st),t&&o(gr),t&&o(de),S(nt),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(Fe),t&&o(kr),t&&o(ue),S(zt),t&&o(Sr),t&&o(M),S(Ft),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(F){return sl(()=>{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};
