import{S as el,i as tl,s as ol,e as s,k as l,w as T,t as r,M as rl,c as a,d as o,m as c,a as i,x as y,h as n,b as d,G as e,g as u,y as b,q as v,o as M,B as k,v as nl,L as yi}from"../../chunks/vendor-hf-doc-builder.js";import{T as wi}from"../../chunks/Tip-hf-doc-builder.js";import{D as B}from"../../chunks/Docstring-hf-doc-builder.js";import{C as bi}from"../../chunks/CodeBlock-hf-doc-builder.js";import{I as fe}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{E as Ti}from"../../chunks/ExampleCodeBlock-hf-doc-builder.js";function sl(C){let m,S,g,_,w;return{c(){m=s("p"),S=r("Although the recipe for forward pass needs to be defined within this function, one should call the "),g=s("code"),_=r("Module"),w=r(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(h){m=a(h,"P",{});var f=i(m);S=n(f,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=a(f,"CODE",{});var F=i(g);_=n(F,"Module"),F.forEach(o),w=n(f,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),f.forEach(o)},m(h,f){u(h,m,f),e(m,S),e(m,g),e(g,_),e(m,w)},d(h){h&&o(m)}}}function al(C){let m,S,g,_,w;return _=new bi({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBTd2l0Y2hUcmFuc2Zvcm1lcnNNb2RlbCUwQSUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKCUyMmdvb2dsZSUyRnN3aXRjaC1iYXNlLTglMjIpJTBBbW9kZWwlMjAlM0QlMjBTd2l0Y2hUcmFuc2Zvcm1lcnNNb2RlbC5mcm9tX3ByZXRyYWluZWQoJTIyZ29vZ2xlJTJGc3dpdGNoLWJhc2UtOCUyMiklMEElMEFpbnB1dF9pZHMlMjAlM0QlMjB0b2tlbml6ZXIoJTBBJTIwJTIwJTIwJTIwJTIyU3R1ZGllcyUyMGhhdmUlMjBiZWVuJTIwc2hvd24lMjB0aGF0JTIwb3duaW5nJTIwYSUyMGRvZyUyMGlzJTIwZ29vZCUyMGZvciUyMHlvdSUyMiUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIlMEEpLmlucHV0X2lkcyUyMCUyMCUyMyUyMEJhdGNoJTIwc2l6ZSUyMDElMEFkZWNvZGVyX2lucHV0X2lkcyUyMCUzRCUyMHRva2VuaXplciglMjJTdHVkaWVzJTIwc2hvdyUyMHRoYXQlMjIlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKS5pbnB1dF9pZHMlMjAlMjAlMjMlMjBCYXRjaCUyMHNpemUlMjAxJTBBJTBBJTIzJTIwcHJlcHJvY2VzcyUzQSUyMFByZXBlbmQlMjBkZWNvZGVyX2lucHV0X2lkcyUyMHdpdGglMjBzdGFydCUyMHRva2VuJTIwd2hpY2glMjBpcyUyMHBhZCUyMHRva2VuJTIwZm9yJTIwU3dpdGNoVHJhbnNmb3JtZXJzTW9kZWwuJTBBJTIzJTIwVGhpcyUyMGlzJTIwbm90JTIwbmVlZGVkJTIwZm9yJTIwdG9yY2gncyUyMFN3aXRjaFRyYW5zZm9ybWVyc0ZvckNvbmRpdGlvbmFsR2VuZXJhdGlvbiUyMGFzJTIwaXQlMjBkb2VzJTIwdGhpcyUyMGludGVybmFsbHklMjB1c2luZyUyMGxhYmVscyUyMGFyZy4lMEFkZWNvZGVyX2lucHV0X2lkcyUyMCUzRCUyMG1vZGVsLl9zaGlmdF9yaWdodChkZWNvZGVyX2lucHV0X2lkcyklMEElMEElMjMlMjBmb3J3YXJkJTIwcGFzcyUwQW91dHB1dHMlMjAlM0QlMjBtb2RlbChpbnB1dF9pZHMlM0RpbnB1dF9pZHMlMkMlMjBkZWNvZGVyX2lucHV0X2lkcyUzRGRlY29kZXJfaW5wdXRfaWRzKSUwQWxhc3RfaGlkZGVuX3N0YXRlcyUyMCUzRCUyMG91dHB1dHMubGFzdF9oaWRkZW5fc3RhdGU=",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(){m=s("p"),S=r("Example:"),g=l(),T(_.$$.fragment)},l(h){m=a(h,"P",{});var f=i(m);S=n(f,"Example:"),f.forEach(o),g=c(h),y(_.$$.fragment,h)},m(h,f){u(h,m,f),e(m,S),u(h,g,f),b(_,h,f),w=!0},p:yi,i(h){w||(v(_.$$.fragment,h),w=!0)},o(h){M(_.$$.fragment,h),w=!1},d(h){h&&o(m),h&&o(g),k(_,h)}}}function il(C){let m,S,g,_,w;return{c(){m=s("p"),S=r("Although the recipe for forward pass needs to be defined within this function, one should call the "),g=s("code"),_=r("Module"),w=r(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(h){m=a(h,"P",{});var f=i(m);S=n(f,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=a(f,"CODE",{});var F=i(g);_=n(F,"Module"),F.forEach(o),w=n(f,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),f.forEach(o)},m(h,f){u(h,m,f),e(m,S),e(m,g),e(g,_),e(m,w)},d(h){h&&o(m)}}}function dl(C){let m,S,g,_,w;return _=new bi({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBTd2l0Y2hUcmFuc2Zvcm1lcnNGb3JDb25kaXRpb25hbEdlbmVyYXRpb24lMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJnb29nbGUlMkZzd2l0Y2gtYmFzZS04JTIyKSUwQW1vZGVsJTIwJTNEJTIwU3dpdGNoVHJhbnNmb3JtZXJzRm9yQ29uZGl0aW9uYWxHZW5lcmF0aW9uLmZyb21fcHJldHJhaW5lZCglMjJnb29nbGUlMkZzd2l0Y2gtYmFzZS04JTIyKSUwQSUwQSUyMyUyMHRyYWluaW5nJTBBaW5wdXRfaWRzJTIwJTNEJTIwdG9rZW5pemVyKCUyMlRoZSUyMCUzQ2V4dHJhX2lkXzAlM0UlMjB3YWxrcyUyMGluJTIwJTNDZXh0cmFfaWRfMSUzRSUyMHBhcmslMjIlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKS5pbnB1dF9pZHMlMEFsYWJlbHMlMjAlM0QlMjB0b2tlbml6ZXIoJTIyJTNDZXh0cmFfaWRfMCUzRSUyMGN1dGUlMjBkb2clMjAlM0NleHRyYV9pZF8xJTNFJTIwdGhlJTIwJTNDZXh0cmFfaWRfMiUzRSUyMiUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpLmlucHV0X2lkcyUwQW91dHB1dHMlMjAlM0QlMjBtb2RlbChpbnB1dF9pZHMlM0RpbnB1dF9pZHMlMkMlMjBsYWJlbHMlM0RsYWJlbHMpJTBBbG9zcyUyMCUzRCUyMG91dHB1dHMubG9zcyUwQWxvZ2l0cyUyMCUzRCUyMG91dHB1dHMubG9naXRzJTBBJTBBJTIzJTIwaW5mZXJlbmNlJTBBaW5wdXRfaWRzJTIwJTNEJTIwdG9rZW5pemVyKCUwQSUyMCUyMCUyMCUyMCUyMnN1bW1hcml6ZSUzQSUyMHN0dWRpZXMlMjBoYXZlJTIwc2hvd24lMjB0aGF0JTIwb3duaW5nJTIwYSUyMGRvZyUyMGlzJTIwZ29vZCUyMGZvciUyMHlvdSUyMiUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIlMEEpLmlucHV0X2lkcyUyMCUyMCUyMyUyMEJhdGNoJTIwc2l6ZSUyMDElMEFvdXRwdXRzJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoaW5wdXRfaWRzKSUwQSUyMyUyMC4lMjBUbyUyQyUyMGxldCVFMiU4MCU5OXMlMjBzYXklMjB5b3UlMjBoYXZlJTIwYSUyMGRvZy4lMjBUbyUyMHN1bW1hcml6ZSUzQSUwQSUyMyUyMFNpbmNlJTIwdGhlJTIwbW9kZWwlMjBoYXMlMjBiZWVuJTIwdHJhaW5lZCUyMG9uJTIwTUxNJTJDJTIwdGhpcyUyMHdpbGwlMjBvdXRwdXQlMjBnaWJiZXJpc2g=",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(){m=s("p"),S=r("Examples:"),g=l(),T(_.$$.fragment)},l(h){m=a(h,"P",{});var f=i(m);S=n(f,"Examples:"),f.forEach(o),g=c(h),y(_.$$.fragment,h)},m(h,f){u(h,m,f),e(m,S),u(h,g,f),b(_,h,f),w=!0},p:yi,i(h){w||(v(_.$$.fragment,h),w=!0)},o(h){M(_.$$.fragment,h),w=!1},d(h){h&&o(m),h&&o(g),k(_,h)}}}function ll(C){let m,S,g,_,w;return{c(){m=s("p"),S=r("Although the recipe for forward pass needs to be defined within this function, one should call the "),g=s("code"),_=r("Module"),w=r(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(h){m=a(h,"P",{});var f=i(m);S=n(f,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=a(f,"CODE",{});var F=i(g);_=n(F,"Module"),F.forEach(o),w=n(f,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),f.forEach(o)},m(h,f){u(h,m,f),e(m,S),e(m,g),e(g,_),e(m,w)},d(h){h&&o(m)}}}function cl(C){let m,S,g,_,w;return _=new bi({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBTd2l0Y2hUcmFuc2Zvcm1lcnNFbmNvZGVyTW9kZWwlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJnb29nbGUlMkZzd2l0Y2gtYmFzZS04JTIyKSUwQW1vZGVsJTIwJTNEJTIwU3dpdGNoVHJhbnNmb3JtZXJzRW5jb2Rlck1vZGVsLmZyb21fcHJldHJhaW5lZCglMjJnb29nbGUlMkZzd2l0Y2gtYmFzZS04JTIyKSUwQWlucHV0X2lkcyUyMCUzRCUyMHRva2VuaXplciglMEElMjAlMjAlMjAlMjAlMjJTdHVkaWVzJTIwaGF2ZSUyMGJlZW4lMjBzaG93biUyMHRoYXQlMjBvd25pbmclMjBhJTIwZG9nJTIwaXMlMjBnb29kJTIwZm9yJTIweW91JTIyJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiUwQSkuaW5wdXRfaWRzJTIwJTIwJTIzJTIwQmF0Y2glMjBzaXplJTIwMSUwQW91dHB1dHMlMjAlM0QlMjBtb2RlbChpbnB1dF9pZHMlM0RpbnB1dF9pZHMpJTBBbGFzdF9oaWRkZW5fc3RhdGVzJTIwJTNEJTIwb3V0cHV0cy5sYXN0X2hpZGRlbl9zdGF0ZQ==",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(){m=s("p"),S=r("Example:"),g=l(),T(_.$$.fragment)},l(h){m=a(h,"P",{});var f=i(m);S=n(f,"Example:"),f.forEach(o),g=c(h),y(_.$$.fragment,h)},m(h,f){u(h,m,f),e(m,S),u(h,g,f),b(_,h,f),w=!0},p:yi,i(h){w||(v(_.$$.fragment,h),w=!0)},o(h){M(_.$$.fragment,h),w=!1},d(h){h&&o(m),h&&o(g),k(_,h)}}}function hl(C){let m,S,g,_,w,h,f,F,Or,rr,te,_e,mo,Ae,Vr,uo,Xr,nr,ge,Lr,Pe,Dr,Yr,sr,At,Qr,ar,Pt,Kr,ir,Gt,fo,en,dr,Bt,tn,lr,we,Ge,on,Ht,rn,nn,sn,Be,an,He,dn,ln,cr,j,cn,Oe,hn,pn,Ve,mn,un,Xe,fn,_n,hr,oe,Te,_o,Le,gn,go,wn,pr,ye,wo,Ot,Tn,yn,To,Vt,bn,mr,re,be,yo,De,vn,bo,Mn,ur,H,Ye,kn,ne,Sn,Xt,En,xn,Qe,$n,zn,Cn,se,Fn,Lt,Rn,In,Dt,Un,Jn,fr,ae,ve,vo,Ke,jn,Mo,qn,_r,z,et,Wn,ko,Nn,Zn,O,An,tt,Pn,Gn,ot,Bn,Hn,So,On,Vn,Xn,Me,rt,Ln,Eo,Dn,Yn,L,nt,Qn,ie,Kn,xo,es,ts,$o,os,rs,ns,R,ss,zo,as,is,Co,ds,ls,Fo,cs,hs,Ro,ps,ms,gr,de,ke,Io,st,us,Uo,fs,wr,V,at,_s,Jo,gs,ws,q,it,Ts,jo,ys,bs,X,vs,qo,Ms,ks,Wo,Ss,Es,No,xs,$s,zs,Zo,Cs,Tr,le,Se,Ao,dt,Fs,Po,Rs,yr,E,lt,Is,Go,Us,Js,I,js,ct,qs,Ws,ht,Ns,Zs,pt,As,Ps,mt,Gs,Bs,Hs,ut,Os,Yt,Vs,Xs,Ls,ft,Ds,_t,Ys,Qs,Ks,W,gt,ea,ce,ta,Qt,oa,ra,Bo,na,sa,aa,Ee,ia,xe,br,he,$e,Ho,wt,da,Oo,la,vr,x,Tt,ca,yt,ha,Vo,pa,ma,ua,U,fa,bt,_a,ga,vt,wa,Ta,Mt,ya,ba,kt,va,Ma,ka,St,Sa,Kt,Ea,xa,$a,Et,za,xt,Ca,Fa,Ra,N,$t,Ia,pe,Ua,eo,Ja,ja,Xo,qa,Wa,Na,ze,Za,Ce,Mr,me,Fe,Lo,zt,Aa,Do,Pa,kr,$,Ct,Ga,Yo,Ba,Ha,J,Oa,Ft,Va,Xa,Rt,La,Da,It,Ya,Qa,Ut,Ka,ei,ti,Jt,oi,to,ri,ni,si,jt,ai,qt,ii,di,li,Z,Wt,ci,ue,hi,oo,pi,mi,Qo,ui,fi,_i,Re,gi,Ie,Sr;return h=new fe({}),Ae=new fe({}),Le=new fe({}),De=new fe({}),Ye=new B({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:"dense_act_fn",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/main/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/main/src/transformers/models/switch_transformers/configuration_switch_transformers.py#L27"}}),Ke=new fe({}),et=new B({props:{name:"class transformers.SwitchTransformersTop1Router",anchor:"transformers.SwitchTransformersTop1Router",parameters:[{name:"config",val:": SwitchTransformersConfig"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L131"}}),rt=new B({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/main/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L151",returnDescription:`
<p>Tensor of shape (batch_size, sequence_length, num_experts) corresponding to the probabilities for each
token and expert. Used for routing tokens to experts.
router_logits (<code>torch.Tensor</code>):
Logits tensor of shape (batch_size, sequence_length, num_experts) corresponding to raw router logits.
This is used later for computing router z-loss.</p>
`,returnType:`
<p>router_probabilities (<code>torch.Tensor</code>)</p>
`}}),nt=new B({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/main/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L201",returnDescription:`
<p>Tuple[<code>torch.Tensor</code>, <code>torch.Tensor</code>, <code>torch.Tensor</code>] Tuple containing the expert index, the router probs
and the router logits. The router probabilities and logits are required to compute the loss.</p>
`}}),st=new fe({}),at=new B({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/main/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L285"}}),it=new B({props:{name:"forward",anchor:"transformers.SwitchTransformersSparseMLP.forward",parameters:[{name:"hidden_states",val:""}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L300"}}),dt=new fe({}),lt=new B({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/main/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/main/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L1310"}}),gt=new B({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/main/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for detail.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a></p>
<p>To know more on how to prepare <code>input_ids</code> for pretraining take a look a <a href="./switch_transformers#training">SWITCH_TRANSFORMERS
Training</a>.`,name:"input_ids"},{anchor:"transformers.SwitchTransformersModel.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.SwitchTransformersModel.forward.decoder_input_ids",description:`<strong>decoder_input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Indices of decoder input sequence tokens in the vocabulary.</p>
<p>Indices can be obtained using <a href="/docs/transformers/main/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#decoder-input-ids">What are decoder input IDs?</a></p>
<p>SWITCH_TRANSFORMERS uses the <code>pad_token_id</code> as the starting token for <code>decoder_input_ids</code> generation. If
<code>past_key_values</code> is used, optionally only the last <code>decoder_input_ids</code> have to be input (see
<code>past_key_values</code>).</p>
<p>To know more on how to prepare <code>decoder_input_ids</code> for pretraining take a look at <a href="./switch_transformers#training">SWITCH_TRANSFORMERS
Training</a>.`,name:"decoder_input_ids"},{anchor:"transformers.SwitchTransformersModel.forward.decoder_attention_mask",description:`<strong>decoder_attention_mask</strong> (<code>torch.BoolTensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Default behavior: generate a tensor that ignores pad tokens in <code>decoder_input_ids</code>. Causal mask will also
be used by default.`,name:"decoder_attention_mask"},{anchor:"transformers.SwitchTransformersModel.forward.head_mask",description:`<strong>head_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(num_heads,)</code> or <code>(num_layers, num_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the self-attention modules in the encoder. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 indicates the head is <strong>not masked</strong>,</li>
<li>0 indicates the head is <strong>masked</strong>.</li>
</ul>`,name:"head_mask"},{anchor:"transformers.SwitchTransformersModel.forward.decoder_head_mask",description:`<strong>decoder_head_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(num_heads,)</code> or <code>(num_layers, num_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the self-attention modules in the decoder. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 indicates the head is <strong>not masked</strong>,</li>
<li>0 indicates the head is <strong>masked</strong>.</li>
</ul>`,name:"decoder_head_mask"},{anchor:"transformers.SwitchTransformersModel.forward.cross_attn_head_mask",description:`<strong>cross_attn_head_mask</strong> (<code>torch.Tensor</code> of shape <code>(num_heads,)</code> or <code>(num_layers, num_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the cross-attention modules in the decoder. Mask values selected in
<code>[0, 1]</code>:</p>
<ul>
<li>1 indicates the head is <strong>not masked</strong>,</li>
<li>0 indicates the head is <strong>masked</strong>.</li>
</ul>`,name:"cross_attn_head_mask"},{anchor:"transformers.SwitchTransformersModel.forward.encoder_outputs",description:`<strong>encoder_outputs</strong> (<code>tuple(tuple(torch.FloatTensor)</code>, <em>optional</em>) &#x2014;
Tuple consists of (<code>last_hidden_state</code>, <code>optional</code>: <em>hidden_states</em>, <code>optional</code>: <em>attentions</em>)
<code>last_hidden_state</code> of shape <code>(batch_size, sequence_length, hidden_size)</code> is a sequence of hidden states at
the output of the last layer of the encoder. Used in the cross-attention of the decoder.`,name:"encoder_outputs"},{anchor:"transformers.SwitchTransformersModel.forward.past_key_values",description:`<strong>past_key_values</strong> (<code>tuple(tuple(torch.FloatTensor))</code> of length <code>config.n_layers</code> with each tuple having 4 tensors of shape <code>(batch_size, num_heads, sequence_length - 1, embed_size_per_head)</code>) &#x2014;
Contains precomputed key and value hidden states of the attention blocks. Can be used to speed up decoding.</p>
<p>If <code>past_key_values</code> are used, the user can optionally input only the last <code>decoder_input_ids</code> (those that
don&#x2019;t have their past key value states given to this model) of shape <code>(batch_size, 1)</code> instead of all
<code>decoder_input_ids</code> of shape <code>(batch_size, sequence_length)</code>.`,name:"past_key_values"},{anchor:"transformers.SwitchTransformersModel.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>input_ids</code> you can choose to directly pass an embedded representation. This
is useful if you want more control over how to convert <code>input_ids</code> indices into associated vectors than the
model&#x2019;s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.SwitchTransformersModel.forward.decoder_inputs_embeds",description:`<strong>decoder_inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, target_sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>decoder_input_ids</code> you can choose to directly pass an embedded
representation. If <code>past_key_values</code> is used, optionally only the last <code>decoder_inputs_embeds</code> have to be
input (see <code>past_key_values</code>). This is useful if you want more control over how to convert
<code>decoder_input_ids</code> indices into associated vectors than the model&#x2019;s internal embedding lookup matrix.</p>
<p>If <code>decoder_input_ids</code> and <code>decoder_inputs_embeds</code> are both unset, <code>decoder_inputs_embeds</code> takes the value
of <code>inputs_embeds</code>.`,name:"decoder_inputs_embeds"},{anchor:"transformers.SwitchTransformersModel.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding (see
<code>past_key_values</code>).`,name:"use_cache"},{anchor:"transformers.SwitchTransformersModel.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.SwitchTransformersModel.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.SwitchTransformersModel.forward.output_router_logits",description:`<strong>output_router_logits</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the logits of all the routers. They are useful for computing the router loss, and
should not be returned during inference.`,name:"output_router_logits"},{anchor:"transformers.SwitchTransformersModel.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/main/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L1356",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/main/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>
`}}),Ee=new wi({props:{$$slots:{default:[sl]},$$scope:{ctx:C}}}),xe=new Ti({props:{anchor:"transformers.SwitchTransformersModel.forward.example",$$slots:{default:[al]},$$scope:{ctx:C}}}),wt=new fe({}),Tt=new B({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/main/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/main/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L1478"}}),$t=new B({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/main/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for detail.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a></p>
<p>To know more on how to prepare <code>input_ids</code> for pretraining take a look a <a href="./switch_transformers#training">SWITCH_TRANSFORMERS
Training</a>.`,name:"input_ids"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.decoder_input_ids",description:`<strong>decoder_input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Indices of decoder input sequence tokens in the vocabulary.</p>
<p>Indices can be obtained using <a href="/docs/transformers/main/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#decoder-input-ids">What are decoder input IDs?</a></p>
<p>SWITCH_TRANSFORMERS uses the <code>pad_token_id</code> as the starting token for <code>decoder_input_ids</code> generation. If
<code>past_key_values</code> is used, optionally only the last <code>decoder_input_ids</code> have to be input (see
<code>past_key_values</code>).</p>
<p>To know more on how to prepare <code>decoder_input_ids</code> for pretraining take a look at <a href="./switch_transformers#training">SWITCH_TRANSFORMERS
Training</a>.`,name:"decoder_input_ids"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.decoder_attention_mask",description:`<strong>decoder_attention_mask</strong> (<code>torch.BoolTensor</code> of shape <code>(batch_size, target_sequence_length)</code>, <em>optional</em>) &#x2014;
Default behavior: generate a tensor that ignores pad tokens in <code>decoder_input_ids</code>. Causal mask will also
be used by default.`,name:"decoder_attention_mask"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.head_mask",description:`<strong>head_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(num_heads,)</code> or <code>(num_layers, num_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the self-attention modules in the encoder. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 indicates the head is <strong>not masked</strong>,</li>
<li>0 indicates the head is <strong>masked</strong>.</li>
</ul>`,name:"head_mask"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.decoder_head_mask",description:`<strong>decoder_head_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(num_heads,)</code> or <code>(num_layers, num_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the self-attention modules in the decoder. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 indicates the head is <strong>not masked</strong>,</li>
<li>0 indicates the head is <strong>masked</strong>.</li>
</ul>`,name:"decoder_head_mask"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.cross_attn_head_mask",description:`<strong>cross_attn_head_mask</strong> (<code>torch.Tensor</code> of shape <code>(num_heads,)</code> or <code>(num_layers, num_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the cross-attention modules in the decoder. Mask values selected in
<code>[0, 1]</code>:</p>
<ul>
<li>1 indicates the head is <strong>not masked</strong>,</li>
<li>0 indicates the head is <strong>masked</strong>.</li>
</ul>`,name:"cross_attn_head_mask"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.encoder_outputs",description:`<strong>encoder_outputs</strong> (<code>tuple(tuple(torch.FloatTensor)</code>, <em>optional</em>) &#x2014;
Tuple consists of (<code>last_hidden_state</code>, <code>optional</code>: <em>hidden_states</em>, <code>optional</code>: <em>attentions</em>)
<code>last_hidden_state</code> of shape <code>(batch_size, sequence_length, hidden_size)</code> is a sequence of hidden states at
the output of the last layer of the encoder. Used in the cross-attention of the decoder.`,name:"encoder_outputs"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.past_key_values",description:`<strong>past_key_values</strong> (<code>tuple(tuple(torch.FloatTensor))</code> of length <code>config.n_layers</code> with each tuple having 4 tensors of shape <code>(batch_size, num_heads, sequence_length - 1, embed_size_per_head)</code>) &#x2014;
Contains precomputed key and value hidden states of the attention blocks. Can be used to speed up decoding.</p>
<p>If <code>past_key_values</code> are used, the user can optionally input only the last <code>decoder_input_ids</code> (those that
don&#x2019;t have their past key value states given to this model) of shape <code>(batch_size, 1)</code> instead of all
<code>decoder_input_ids</code> of shape <code>(batch_size, sequence_length)</code>.`,name:"past_key_values"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>input_ids</code> you can choose to directly pass an embedded representation. This
is useful if you want more control over how to convert <code>input_ids</code> indices into associated vectors than the
model&#x2019;s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.decoder_inputs_embeds",description:`<strong>decoder_inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, target_sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>decoder_input_ids</code> you can choose to directly pass an embedded
representation. If <code>past_key_values</code> is used, optionally only the last <code>decoder_inputs_embeds</code> have to be
input (see <code>past_key_values</code>). This is useful if you want more control over how to convert
<code>decoder_input_ids</code> indices into associated vectors than the model&#x2019;s internal embedding lookup matrix.</p>
<p>If <code>decoder_input_ids</code> and <code>decoder_inputs_embeds</code> are both unset, <code>decoder_inputs_embeds</code> takes the value
of <code>inputs_embeds</code>.`,name:"decoder_inputs_embeds"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding (see
<code>past_key_values</code>).`,name:"use_cache"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.output_router_logits",description:`<strong>output_router_logits</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the logits of all the routers. They are useful for computing the router loss, and
should not be returned during inference.`,name:"output_router_logits"},{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/main/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/main/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L1530",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/main/en/model_doc/switch_transformers#transformers.SwitchTransformersConfig"
>SwitchTransformersConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>loss</strong> (<code>torch.FloatTensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) \u2014 Language modeling loss.</p>
</li>
<li>
<p><strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) \u2014 Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).</p>
</li>
<li>
<p><strong>past_key_values</strong> (<code>tuple(tuple(torch.FloatTensor))</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) \u2014 Tuple of <code>tuple(torch.FloatTensor)</code> of length <code>config.n_layers</code>, with each tuple having 2 tensors of shape
<code>(batch_size, num_heads, sequence_length, embed_size_per_head)</code>) and 2 additional tensors of shape
<code>(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)</code>.</p>
<p>Contains pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
blocks) that can be used (see <code>past_key_values</code> input) to speed up sequential decoding.</p>
</li>
<li>
<p><strong>decoder_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the decoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>decoder_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the decoder, after the attention softmax, used to compute the weighted average in the
self-attention heads.</p>
</li>
<li>
<p><strong>decoder_router_logits</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_router_logits=True</code> is passed or when <code>config.add_router_probs=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, sequence_length, num_experts)</code>.</p>
<p>Router logits of the decoder model, useful to compute the auxiliary loss for Mixture of Experts models.</p>
</li>
<li>
<p><strong>cross_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the decoder\u2019s cross-attention layer, after the attention softmax, used to compute the
weighted average in the cross-attention heads.</p>
</li>
<li>
<p><strong>encoder_last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) \u2014 Sequence of hidden-states at the output of the last layer of the encoder of the model.</p>
</li>
<li>
<p><strong>encoder_hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the encoder at the output of each layer plus the initial embedding outputs.</p>
</li>
<li>
<p><strong>encoder_attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights of the encoder, after the attention softmax, used to compute the weighted average in the
self-attention heads.</p>
</li>
<li>
<p><strong>encoder_router_logits</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_router_logits=True</code> is passed or when <code>config.add_router_probs=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, sequence_length, num_experts)</code>.</p>
<p>Router logits of the encoder model, useful to compute the auxiliary loss and z_loss for Mixture of Experts
models.</p>
</li>
</ul>
`,returnType:`
<p><code>transformers.modeling_outputs.Seq2SeqMoEOutput</code> or <code>tuple(torch.FloatTensor)</code></p>
`}}),ze=new wi({props:{$$slots:{default:[il]},$$scope:{ctx:C}}}),Ce=new Ti({props:{anchor:"transformers.SwitchTransformersForConditionalGeneration.forward.example",$$slots:{default:[dl]},$$scope:{ctx:C}}}),zt=new fe({}),Ct=new B({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/main/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/main/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L1786"}}),Wt=new B({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/main/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for detail.</p>
<p>To know more on how to prepare <code>input_ids</code> for pretraining take a look a <a href="./switch_transformers#training">SWITCH_TRANSFORMERS
Training</a>.`,name:"input_ids"},{anchor:"transformers.SwitchTransformersEncoderModel.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.SwitchTransformersEncoderModel.forward.head_mask",description:`<strong>head_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(num_heads,)</code> or <code>(num_layers, num_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the self-attention modules. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 indicates the head is <strong>not masked</strong>,</li>
<li>0 indicates the head is <strong>masked</strong>.</li>
</ul>`,name:"head_mask"},{anchor:"transformers.SwitchTransformersEncoderModel.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>input_ids</code> you can choose to directly pass an embedded representation. This
is useful if you want more control over how to convert <code>input_ids</code> indices into associated vectors than the
model&#x2019;s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.SwitchTransformersEncoderModel.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.SwitchTransformersEncoderModel.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.SwitchTransformersEncoderModel.forward.output_router_logits",description:`<strong>output_router_logits</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the logits of all the routers. They are useful for computing the router loss, and
should not be returned during inference.`,name:"output_router_logits"},{anchor:"transformers.SwitchTransformersEncoderModel.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/main/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/switch_transformers/modeling_switch_transformers.py#L1822",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/main/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>
`}}),Re=new wi({props:{$$slots:{default:[ll]},$$scope:{ctx:C}}}),Ie=new Ti({props:{anchor:"transformers.SwitchTransformersEncoderModel.forward.example",$$slots:{default:[cl]},$$scope:{ctx:C}}}),{c(){m=s("meta"),S=l(),g=s("h1"),_=s("a"),w=s("span"),T(h.$$.fragment),f=l(),F=s("span"),Or=r("SwitchTransformers"),rr=l(),te=s("h2"),_e=s("a"),mo=s("span"),T(Ae.$$.fragment),Vr=l(),uo=s("span"),Xr=r("Overview"),nr=l(),ge=s("p"),Lr=r("The SwitchTransformers model was proposed in "),Pe=s("a"),Dr=r("Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity"),Yr=r(" by William Fedus, Barret Zoph, Noam Shazeer."),sr=l(),At=s("p"),Qr=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(),Pt=s("p"),Kr=r("The abstract from the paper is the following:"),ir=l(),Gt=s("p"),fo=s("em"),en=r("In deep learning, models typically reuse the same parameters for all inputs. Mixture of Experts (MoE) defies this and instead selects different parameters for each incoming example. The result is a sparsely-activated model \u2014 with outrageous numbers of parameters \u2014 but a constant computational cost. However, despite several notable successes of MoE, widespread adoption has been hindered by complexity, communication costs and training instability \u2014 we address these with the Switch Transformer. We simplify the MoE routing algorithm and design intuitive improved models with reduced communication and computational costs. Our proposed training techniques help wrangle the instabilities and we show large sparse models may be trained, for the first time, with lower precision (bfloat16) formats. We design models based off T5-Base and T5-Large to obtain up to 7x increases in pre-training speed with the same computational resources. These improvements extend into multilingual settings where we measure gains over the mT5-Base version across all 101 languages. Finally, we advance the current scale of language models by pre-training up to trillion parameter models on the \u201CColossal Clean Crawled Corpus\u201D and achieve a 4x speedup over the T5-XXL model."),dr=l(),Bt=s("p"),tn=r("Tips:"),lr=l(),we=s("ul"),Ge=s("li"),on=r("SwitchTransformers uses the "),Ht=s("a"),rn=r("T5Tokenizer"),nn=r(", which can be loaded directly from each model\u2019s repository."),sn=l(),Be=s("li"),an=r("The released weights are pretrained on English "),He=s("a"),dn=r("Masked Language Modeling"),ln=r(" task, and should be finetuned."),cr=l(),j=s("p"),cn=r("This model was contributed by "),Oe=s("a"),hn=r("Younes Belkada"),pn=r(" and "),Ve=s("a"),mn=r("Arthur Zucker"),un=r(` .
The original code can be found `),Xe=s("a"),fn=r("here"),_n=r("."),hr=l(),oe=s("h2"),Te=s("a"),_o=s("span"),T(Le.$$.fragment),gn=l(),go=s("span"),wn=r("Resources"),pr=l(),ye=s("ul"),wo=s("li"),Ot=s("a"),Tn=r("Translation task guide"),yn=l(),To=s("li"),Vt=s("a"),bn=r("Summarization task guide"),mr=l(),re=s("h2"),be=s("a"),yo=s("span"),T(De.$$.fragment),vn=l(),bo=s("span"),Mn=r("SwitchTransformersConfig"),ur=l(),H=s("div"),T(Ye.$$.fragment),kn=l(),ne=s("p"),Sn=r("This is the configuration class to store the configuration of a "),Xt=s("a"),En=r("SwitchTransformersModel"),xn=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 `),Qe=s("a"),$n=r("google/switch-base-8"),zn=r(" architecture."),Cn=l(),se=s("p"),Fn=r("Configuration objects inherit from "),Lt=s("a"),Rn=r("PretrainedConfig"),In=r(` and can be used to control the model outputs. Read the
documentation from `),Dt=s("a"),Un=r("PretrainedConfig"),Jn=r(" for more information."),fr=l(),ae=s("h2"),ve=s("a"),vo=s("span"),T(Ke.$$.fragment),jn=l(),Mo=s("span"),qn=r("SwitchTransformersTop1Router"),_r=l(),z=s("div"),T(et.$$.fragment),Wn=l(),ko=s("p"),Nn=r("Router using tokens choose top-1 experts assignment."),Zn=l(),O=s("p"),An=r("This router uses the same mechanism as in Switch Transformer ("),tt=s("a"),Pn=r("https://arxiv.org/abs/2101.03961"),Gn=r(`) and V-MoE
(`),ot=s("a"),Bn=r("https://arxiv.org/abs/2106.05974"),Hn=r(`): tokens choose their top experts. Items are sorted by router_probs and then
routed to their choice of expert until the expert\u2019s expert_capacity is reached. `),So=s("strong"),On=r(`There is no guarantee that each
token is processed by an expert`),Vn=r(", or that each expert receives at least one token."),Xn=l(),Me=s("div"),T(rt.$$.fragment),Ln=l(),Eo=s("p"),Dn=r("Computes router probabilities from input hidden states."),Yn=l(),L=s("div"),T(nt.$$.fragment),Qn=l(),ie=s("p"),Kn=r(`Generic forward function for every Router class. Each Router expects to have the same input hidden states
(`),xo=s("code"),es=r("hidden_states"),ts=r(") corresponding to the hidden states for each token, the "),$o=s("code"),os=r("expert_capacity"),rs=r(` corresponding to the
number of tokens the Router will send to each expert, some Routers can send up to few tokens to each expert.`),ns=l(),R=s("p"),ss=r("Each Router works as the following: it expects the hidden states for each token, gets the "),zo=s("code"),as=r("router_probs"),is=r(` and
`),Co=s("code"),ds=r("router_logits"),ls=r(" from the "),Fo=s("code"),cs=r("router_weights"),hs=r(`. This will assign for each token, the raw probability to be assigned
to an expert. Then each Router class will have to define its own `),Ro=s("code"),ps=r("_compute_routing_instructions"),ms=r("."),gr=l(),de=s("h2"),ke=s("a"),Io=s("span"),T(st.$$.fragment),us=l(),Uo=s("span"),fs=r("SwitchTransformersSparseMLP"),wr=l(),V=s("div"),T(at.$$.fragment),_s=l(),Jo=s("p"),gs=r("Implementation of the Switch Transformers Sparse MLP module."),ws=l(),q=s("div"),T(it.$$.fragment),Ts=l(),jo=s("p"),ys=r("Hold on, this will be slightly tricky to understand In the correct order, a MoE layer does the following:"),bs=l(),X=s("p"),vs=r("1- Gets the "),qo=s("code"),Ms=r("router_mask"),ks=r(" from the router. The shape of the mask is "),Wo=s("code"),Ss=r("(batch_size, sequence_length, num_expert)"),Es=r(`
and corresponds to the argmax of the `),No=s("code"),xs=r("router_probs"),$s=r(`. The probabilities are needed in the computation of the
hidden states : they are broadcasted to the hidden states values (can be interpreted as a scaling factor).`),zs=l(),Zo=s("p"),Cs=r(`2- Dispatch the tokens to its associated experts. We do a classic for loop over the experts and assign for each
expert the corresponding hidden states.`),Tr=l(),le=s("h2"),Se=s("a"),Ao=s("span"),T(dt.$$.fragment),Fs=l(),Po=s("span"),Rs=r("SwitchTransformersModel"),yr=l(),E=s("div"),T(lt.$$.fragment),Is=l(),Go=s("p"),Us=r("The bare SWITCH_TRANSFORMERS Model transformer outputting raw hidden-states without any specific head on top."),Js=l(),I=s("p"),js=r("The SWITCH_TRANSFORMERS model was proposed in "),ct=s("a"),qs=r(`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),Ws=r(" by "),ht=s("a"),Ns=r(`William
Fedus`),Zs=r(", "),pt=s("a"),As=r(`Barret
Zoph`),Ps=r(", and "),mt=s("a"),Gs=r(`Noam
Shazeer`),Bs=r(`. It\u2019s an encoder-decoder T5-like model
with sparse Feed Forward that stands for Mixture of Experts (MoE) architecture.`),Hs=l(),ut=s("p"),Os=r("This model inherits from "),Yt=s("a"),Vs=r("PreTrainedModel"),Xs=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.)`),Ls=l(),ft=s("p"),Ds=r("This model is also a PyTorch "),_t=s("a"),Ys=r("torch.nn.Module"),Qs=r(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Ks=l(),W=s("div"),T(gt.$$.fragment),ea=l(),ce=s("p"),ta=r("The "),Qt=s("a"),oa=r("SwitchTransformersModel"),ra=r(" forward method, overrides the "),Bo=s("code"),na=r("__call__"),sa=r(" special method."),aa=l(),T(Ee.$$.fragment),ia=l(),T(xe.$$.fragment),br=l(),he=s("h2"),$e=s("a"),Ho=s("span"),T(wt.$$.fragment),da=l(),Oo=s("span"),la=r("SwitchTransformersForConditionalGeneration"),vr=l(),x=s("div"),T(Tt.$$.fragment),ca=l(),yt=s("p"),ha=r("SWITCH_TRANSFORMERS Model with a "),Vo=s("code"),pa=r("language modeling"),ma=r(" head on top."),ua=l(),U=s("p"),fa=r("The SWITCH_TRANSFORMERS model was proposed in "),bt=s("a"),_a=r(`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),ga=r(" by "),vt=s("a"),wa=r(`William
Fedus`),Ta=r(", "),Mt=s("a"),ya=r(`Barret
Zoph`),ba=r(", and "),kt=s("a"),va=r(`Noam
Shazeer`),Ma=r(`. It\u2019s an encoder-decoder T5-like model
with sparse Feed Forward that stands for Mixture of Experts (MoE) architecture.`),ka=l(),St=s("p"),Sa=r("This model inherits from "),Kt=s("a"),Ea=r("PreTrainedModel"),xa=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.)`),$a=l(),Et=s("p"),za=r("This model is also a PyTorch "),xt=s("a"),Ca=r("torch.nn.Module"),Fa=r(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Ra=l(),N=s("div"),T($t.$$.fragment),Ia=l(),pe=s("p"),Ua=r("The "),eo=s("a"),Ja=r("SwitchTransformersForConditionalGeneration"),ja=r(" forward method, overrides the "),Xo=s("code"),qa=r("__call__"),Wa=r(" special method."),Na=l(),T(ze.$$.fragment),Za=l(),T(Ce.$$.fragment),Mr=l(),me=s("h2"),Fe=s("a"),Lo=s("span"),T(zt.$$.fragment),Aa=l(),Do=s("span"),Pa=r("SwitchTransformersEncoderModel"),kr=l(),$=s("div"),T(Ct.$$.fragment),Ga=l(),Yo=s("p"),Ba=r("The bare SWITCH_TRANSFORMERS Model transformer outputting encoder\u2019s raw hidden-states without any specific head on top."),Ha=l(),J=s("p"),Oa=r("The SWITCH_TRANSFORMERS model was proposed in "),Ft=s("a"),Va=r(`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),Xa=r(" by "),Rt=s("a"),La=r(`William
Fedus`),Da=r(", "),It=s("a"),Ya=r(`Barret
Zoph`),Qa=r(", and "),Ut=s("a"),Ka=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(),Jt=s("p"),oi=r("This model inherits from "),to=s("a"),ri=r("PreTrainedModel"),ni=r(`. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`),si=l(),jt=s("p"),ai=r("This model is also a PyTorch "),qt=s("a"),ii=r("torch.nn.Module"),di=r(` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),li=l(),Z=s("div"),T(Wt.$$.fragment),ci=l(),ue=s("p"),hi=r("The "),oo=s("a"),pi=r("SwitchTransformersEncoderModel"),mi=r(" forward method, overrides the "),Qo=s("code"),ui=r("__call__"),fi=r(" special method."),_i=l(),T(Re.$$.fragment),gi=l(),T(Ie.$$.fragment),this.h()},l(t){const p=rl('[data-svelte="svelte-1phssyn"]',document.head);m=a(p,"META",{name:!0,content:!0}),p.forEach(o),S=c(t),g=a(t,"H1",{class:!0});var Nt=i(g);_=a(Nt,"A",{id:!0,class:!0,href:!0});var Ko=i(_);w=a(Ko,"SPAN",{});var er=i(w);y(h.$$.fragment,er),er.forEach(o),Ko.forEach(o),f=c(Nt),F=a(Nt,"SPAN",{});var tr=i(F);Or=n(tr,"SwitchTransformers"),tr.forEach(o),Nt.forEach(o),rr=c(t),te=a(t,"H2",{class:!0});var Zt=i(te);_e=a(Zt,"A",{id:!0,class:!0,href:!0});var or=i(_e);mo=a(or,"SPAN",{});var vi=i(mo);y(Ae.$$.fragment,vi),vi.forEach(o),or.forEach(o),Vr=c(Zt),uo=a(Zt,"SPAN",{});var Mi=i(uo);Xr=n(Mi,"Overview"),Mi.forEach(o),Zt.forEach(o),nr=c(t),ge=a(t,"P",{});var Er=i(ge);Lr=n(Er,"The SwitchTransformers model was proposed in "),Pe=a(Er,"A",{href:!0,rel:!0});var ki=i(Pe);Dr=n(ki,"Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity"),ki.forEach(o),Yr=n(Er," by William Fedus, Barret Zoph, Noam Shazeer."),Er.forEach(o),sr=c(t),At=a(t,"P",{});var Si=i(At);Qr=n(Si,`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.`),Si.forEach(o),ar=c(t),Pt=a(t,"P",{});var Ei=i(Pt);Kr=n(Ei,"The abstract from the paper is the following:"),Ei.forEach(o),ir=c(t),Gt=a(t,"P",{});var xi=i(Gt);fo=a(xi,"EM",{});var $i=i(fo);en=n($i,"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."),$i.forEach(o),xi.forEach(o),dr=c(t),Bt=a(t,"P",{});var zi=i(Bt);tn=n(zi,"Tips:"),zi.forEach(o),lr=c(t),we=a(t,"UL",{});var xr=i(we);Ge=a(xr,"LI",{});var $r=i(Ge);on=n($r,"SwitchTransformers uses the "),Ht=a($r,"A",{href:!0});var Ci=i(Ht);rn=n(Ci,"T5Tokenizer"),Ci.forEach(o),nn=n($r,", which can be loaded directly from each model\u2019s repository."),$r.forEach(o),sn=c(xr),Be=a(xr,"LI",{});var zr=i(Be);an=n(zr,"The released weights are pretrained on English "),He=a(zr,"A",{href:!0,rel:!0});var Fi=i(He);dn=n(Fi,"Masked Language Modeling"),Fi.forEach(o),ln=n(zr," task, and should be finetuned."),zr.forEach(o),xr.forEach(o),cr=c(t),j=a(t,"P",{});var Ue=i(j);cn=n(Ue,"This model was contributed by "),Oe=a(Ue,"A",{href:!0,rel:!0});var Ri=i(Oe);hn=n(Ri,"Younes Belkada"),Ri.forEach(o),pn=n(Ue," and "),Ve=a(Ue,"A",{href:!0,rel:!0});var Ii=i(Ve);mn=n(Ii,"Arthur Zucker"),Ii.forEach(o),un=n(Ue,` .
The original code can be found `),Xe=a(Ue,"A",{href:!0,rel:!0});var Ui=i(Xe);fn=n(Ui,"here"),Ui.forEach(o),_n=n(Ue,"."),Ue.forEach(o),hr=c(t),oe=a(t,"H2",{class:!0});var Cr=i(oe);Te=a(Cr,"A",{id:!0,class:!0,href:!0});var Ji=i(Te);_o=a(Ji,"SPAN",{});var ji=i(_o);y(Le.$$.fragment,ji),ji.forEach(o),Ji.forEach(o),gn=c(Cr),go=a(Cr,"SPAN",{});var qi=i(go);wn=n(qi,"Resources"),qi.forEach(o),Cr.forEach(o),pr=c(t),ye=a(t,"UL",{});var Fr=i(ye);wo=a(Fr,"LI",{});var Wi=i(wo);Ot=a(Wi,"A",{href:!0});var Ni=i(Ot);Tn=n(Ni,"Translation task guide"),Ni.forEach(o),Wi.forEach(o),yn=c(Fr),To=a(Fr,"LI",{});var Zi=i(To);Vt=a(Zi,"A",{href:!0});var Ai=i(Vt);bn=n(Ai,"Summarization task guide"),Ai.forEach(o),Zi.forEach(o),Fr.forEach(o),mr=c(t),re=a(t,"H2",{class:!0});var Rr=i(re);be=a(Rr,"A",{id:!0,class:!0,href:!0});var Pi=i(be);yo=a(Pi,"SPAN",{});var Gi=i(yo);y(De.$$.fragment,Gi),Gi.forEach(o),Pi.forEach(o),vn=c(Rr),bo=a(Rr,"SPAN",{});var Bi=i(bo);Mn=n(Bi,"SwitchTransformersConfig"),Bi.forEach(o),Rr.forEach(o),ur=c(t),H=a(t,"DIV",{class:!0});var ro=i(H);y(Ye.$$.fragment,ro),kn=c(ro),ne=a(ro,"P",{});var no=i(ne);Sn=n(no,"This is the configuration class to store the configuration of a "),Xt=a(no,"A",{href:!0});var Hi=i(Xt);En=n(Hi,"SwitchTransformersModel"),Hi.forEach(o),xn=n(no,`. It is used to
instantiate a SwitchTransformers model according to the specified arguments, defining the model architecture.
Instantiating a configuration with the defaults will yield a similar configuration to that of the
SwitchTransformers `),Qe=a(no,"A",{href:!0,rel:!0});var Oi=i(Qe);$n=n(Oi,"google/switch-base-8"),Oi.forEach(o),zn=n(no," architecture."),no.forEach(o),Cn=c(ro),se=a(ro,"P",{});var so=i(se);Fn=n(so,"Configuration objects inherit from "),Lt=a(so,"A",{href:!0});var Vi=i(Lt);Rn=n(Vi,"PretrainedConfig"),Vi.forEach(o),In=n(so,` and can be used to control the model outputs. Read the
documentation from `),Dt=a(so,"A",{href:!0});var Xi=i(Dt);Un=n(Xi,"PretrainedConfig"),Xi.forEach(o),Jn=n(so," for more information."),so.forEach(o),ro.forEach(o),fr=c(t),ae=a(t,"H2",{class:!0});var Ir=i(ae);ve=a(Ir,"A",{id:!0,class:!0,href:!0});var Li=i(ve);vo=a(Li,"SPAN",{});var Di=i(vo);y(Ke.$$.fragment,Di),Di.forEach(o),Li.forEach(o),jn=c(Ir),Mo=a(Ir,"SPAN",{});var Yi=i(Mo);qn=n(Yi,"SwitchTransformersTop1Router"),Yi.forEach(o),Ir.forEach(o),_r=c(t),z=a(t,"DIV",{class:!0});var D=i(z);y(et.$$.fragment,D),Wn=c(D),ko=a(D,"P",{});var Qi=i(ko);Nn=n(Qi,"Router using tokens choose top-1 experts assignment."),Qi.forEach(o),Zn=c(D),O=a(D,"P",{});var Je=i(O);An=n(Je,"This router uses the same mechanism as in Switch Transformer ("),tt=a(Je,"A",{href:!0,rel:!0});var Ki=i(tt);Pn=n(Ki,"https://arxiv.org/abs/2101.03961"),Ki.forEach(o),Gn=n(Je,`) and V-MoE
(`),ot=a(Je,"A",{href:!0,rel:!0});var ed=i(ot);Bn=n(ed,"https://arxiv.org/abs/2106.05974"),ed.forEach(o),Hn=n(Je,`): 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. `),So=a(Je,"STRONG",{});var td=i(So);On=n(td,`There is no guarantee that each
token is processed by an expert`),td.forEach(o),Vn=n(Je,", or that each expert receives at least one token."),Je.forEach(o),Xn=c(D),Me=a(D,"DIV",{class:!0});var Ur=i(Me);y(rt.$$.fragment,Ur),Ln=c(Ur),Eo=a(Ur,"P",{});var od=i(Eo);Dn=n(od,"Computes router probabilities from input hidden states."),od.forEach(o),Ur.forEach(o),Yn=c(D),L=a(D,"DIV",{class:!0});var ao=i(L);y(nt.$$.fragment,ao),Qn=c(ao),ie=a(ao,"P",{});var io=i(ie);Kn=n(io,`Generic forward function for every Router class. Each Router expects to have the same input hidden states
(`),xo=a(io,"CODE",{});var rd=i(xo);es=n(rd,"hidden_states"),rd.forEach(o),ts=n(io,") corresponding to the hidden states for each token, the "),$o=a(io,"CODE",{});var nd=i($o);os=n(nd,"expert_capacity"),nd.forEach(o),rs=n(io,` corresponding to the
number of tokens the Router will send to each expert, some Routers can send up to few tokens to each expert.`),io.forEach(o),ns=c(ao),R=a(ao,"P",{});var Y=i(R);ss=n(Y,"Each Router works as the following: it expects the hidden states for each token, gets the "),zo=a(Y,"CODE",{});var sd=i(zo);as=n(sd,"router_probs"),sd.forEach(o),is=n(Y,` and
`),Co=a(Y,"CODE",{});var ad=i(Co);ds=n(ad,"router_logits"),ad.forEach(o),ls=n(Y," from the "),Fo=a(Y,"CODE",{});var id=i(Fo);cs=n(id,"router_weights"),id.forEach(o),hs=n(Y,`. 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 `),Ro=a(Y,"CODE",{});var dd=i(Ro);ps=n(dd,"_compute_routing_instructions"),dd.forEach(o),ms=n(Y,"."),Y.forEach(o),ao.forEach(o),D.forEach(o),gr=c(t),de=a(t,"H2",{class:!0});var Jr=i(de);ke=a(Jr,"A",{id:!0,class:!0,href:!0});var ld=i(ke);Io=a(ld,"SPAN",{});var cd=i(Io);y(st.$$.fragment,cd),cd.forEach(o),ld.forEach(o),us=c(Jr),Uo=a(Jr,"SPAN",{});var hd=i(Uo);fs=n(hd,"SwitchTransformersSparseMLP"),hd.forEach(o),Jr.forEach(o),wr=c(t),V=a(t,"DIV",{class:!0});var lo=i(V);y(at.$$.fragment,lo),_s=c(lo),Jo=a(lo,"P",{});var pd=i(Jo);gs=n(pd,"Implementation of the Switch Transformers Sparse MLP module."),pd.forEach(o),ws=c(lo),q=a(lo,"DIV",{class:!0});var je=i(q);y(it.$$.fragment,je),Ts=c(je),jo=a(je,"P",{});var md=i(jo);ys=n(md,"Hold on, this will be slightly tricky to understand In the correct order, a MoE layer does the following:"),md.forEach(o),bs=c(je),X=a(je,"P",{});var qe=i(X);vs=n(qe,"1- Gets the "),qo=a(qe,"CODE",{});var ud=i(qo);Ms=n(ud,"router_mask"),ud.forEach(o),ks=n(qe," from the router. The shape of the mask is "),Wo=a(qe,"CODE",{});var fd=i(Wo);Ss=n(fd,"(batch_size, sequence_length, num_expert)"),fd.forEach(o),Es=n(qe,`
and corresponds to the argmax of the `),No=a(qe,"CODE",{});var _d=i(No);xs=n(_d,"router_probs"),_d.forEach(o),$s=n(qe,`. 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).`),qe.forEach(o),zs=c(je),Zo=a(je,"P",{});var gd=i(Zo);Cs=n(gd,`2- Dispatch the tokens to its associated experts. We do a classic for loop over the experts and assign for each
expert the corresponding hidden states.`),gd.forEach(o),je.forEach(o),lo.forEach(o),Tr=c(t),le=a(t,"H2",{class:!0});var jr=i(le);Se=a(jr,"A",{id:!0,class:!0,href:!0});var wd=i(Se);Ao=a(wd,"SPAN",{});var Td=i(Ao);y(dt.$$.fragment,Td),Td.forEach(o),wd.forEach(o),Fs=c(jr),Po=a(jr,"SPAN",{});var yd=i(Po);Rs=n(yd,"SwitchTransformersModel"),yd.forEach(o),jr.forEach(o),yr=c(t),E=a(t,"DIV",{class:!0});var A=i(E);y(lt.$$.fragment,A),Is=c(A),Go=a(A,"P",{});var bd=i(Go);Us=n(bd,"The bare SWITCH_TRANSFORMERS Model transformer outputting raw hidden-states without any specific head on top."),bd.forEach(o),Js=c(A),I=a(A,"P",{});var Q=i(I);js=n(Q,"The SWITCH_TRANSFORMERS model was proposed in "),ct=a(Q,"A",{href:!0,rel:!0});var vd=i(ct);qs=n(vd,`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),vd.forEach(o),Ws=n(Q," by "),ht=a(Q,"A",{href:!0,rel:!0});var Md=i(ht);Ns=n(Md,`William
Fedus`),Md.forEach(o),Zs=n(Q,", "),pt=a(Q,"A",{href:!0,rel:!0});var kd=i(pt);As=n(kd,`Barret
Zoph`),kd.forEach(o),Ps=n(Q,", and "),mt=a(Q,"A",{href:!0,rel:!0});var Sd=i(mt);Gs=n(Sd,`Noam
Shazeer`),Sd.forEach(o),Bs=n(Q,`. It\u2019s an encoder-decoder T5-like model
with sparse Feed Forward that stands for Mixture of Experts (MoE) architecture.`),Q.forEach(o),Hs=c(A),ut=a(A,"P",{});var qr=i(ut);Os=n(qr,"This model inherits from "),Yt=a(qr,"A",{href:!0});var Ed=i(Yt);Vs=n(Ed,"PreTrainedModel"),Ed.forEach(o),Xs=n(qr,`. 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.)`),qr.forEach(o),Ls=c(A),ft=a(A,"P",{});var Wr=i(ft);Ds=n(Wr,"This model is also a PyTorch "),_t=a(Wr,"A",{href:!0,rel:!0});var xd=i(_t);Ys=n(xd,"torch.nn.Module"),xd.forEach(o),Qs=n(Wr,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Wr.forEach(o),Ks=c(A),W=a(A,"DIV",{class:!0});var We=i(W);y(gt.$$.fragment,We),ea=c(We),ce=a(We,"P",{});var co=i(ce);ta=n(co,"The "),Qt=a(co,"A",{href:!0});var $d=i(Qt);oa=n($d,"SwitchTransformersModel"),$d.forEach(o),ra=n(co," forward method, overrides the "),Bo=a(co,"CODE",{});var zd=i(Bo);na=n(zd,"__call__"),zd.forEach(o),sa=n(co," special method."),co.forEach(o),aa=c(We),y(Ee.$$.fragment,We),ia=c(We),y(xe.$$.fragment,We),We.forEach(o),A.forEach(o),br=c(t),he=a(t,"H2",{class:!0});var Nr=i(he);$e=a(Nr,"A",{id:!0,class:!0,href:!0});var Cd=i($e);Ho=a(Cd,"SPAN",{});var Fd=i(Ho);y(wt.$$.fragment,Fd),Fd.forEach(o),Cd.forEach(o),da=c(Nr),Oo=a(Nr,"SPAN",{});var Rd=i(Oo);la=n(Rd,"SwitchTransformersForConditionalGeneration"),Rd.forEach(o),Nr.forEach(o),vr=c(t),x=a(t,"DIV",{class:!0});var P=i(x);y(Tt.$$.fragment,P),ca=c(P),yt=a(P,"P",{});var Zr=i(yt);ha=n(Zr,"SWITCH_TRANSFORMERS Model with a "),Vo=a(Zr,"CODE",{});var Id=i(Vo);pa=n(Id,"language modeling"),Id.forEach(o),ma=n(Zr," head on top."),Zr.forEach(o),ua=c(P),U=a(P,"P",{});var K=i(U);fa=n(K,"The SWITCH_TRANSFORMERS model was proposed in "),bt=a(K,"A",{href:!0,rel:!0});var Ud=i(bt);_a=n(Ud,`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),Ud.forEach(o),ga=n(K," by "),vt=a(K,"A",{href:!0,rel:!0});var Jd=i(vt);wa=n(Jd,`William
Fedus`),Jd.forEach(o),Ta=n(K,", "),Mt=a(K,"A",{href:!0,rel:!0});var jd=i(Mt);ya=n(jd,`Barret
Zoph`),jd.forEach(o),ba=n(K,", and "),kt=a(K,"A",{href:!0,rel:!0});var qd=i(kt);va=n(qd,`Noam
Shazeer`),qd.forEach(o),Ma=n(K,`. It\u2019s an encoder-decoder T5-like model
with sparse Feed Forward that stands for Mixture of Experts (MoE) architecture.`),K.forEach(o),ka=c(P),St=a(P,"P",{});var Ar=i(St);Sa=n(Ar,"This model inherits from "),Kt=a(Ar,"A",{href:!0});var Wd=i(Kt);Ea=n(Wd,"PreTrainedModel"),Wd.forEach(o),xa=n(Ar,`. 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.)`),Ar.forEach(o),$a=c(P),Et=a(P,"P",{});var Pr=i(Et);za=n(Pr,"This model is also a PyTorch "),xt=a(Pr,"A",{href:!0,rel:!0});var Nd=i(xt);Ca=n(Nd,"torch.nn.Module"),Nd.forEach(o),Fa=n(Pr,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Pr.forEach(o),Ra=c(P),N=a(P,"DIV",{class:!0});var Ne=i(N);y($t.$$.fragment,Ne),Ia=c(Ne),pe=a(Ne,"P",{});var ho=i(pe);Ua=n(ho,"The "),eo=a(ho,"A",{href:!0});var Zd=i(eo);Ja=n(Zd,"SwitchTransformersForConditionalGeneration"),Zd.forEach(o),ja=n(ho," forward method, overrides the "),Xo=a(ho,"CODE",{});var Ad=i(Xo);qa=n(Ad,"__call__"),Ad.forEach(o),Wa=n(ho," special method."),ho.forEach(o),Na=c(Ne),y(ze.$$.fragment,Ne),Za=c(Ne),y(Ce.$$.fragment,Ne),Ne.forEach(o),P.forEach(o),Mr=c(t),me=a(t,"H2",{class:!0});var Gr=i(me);Fe=a(Gr,"A",{id:!0,class:!0,href:!0});var Pd=i(Fe);Lo=a(Pd,"SPAN",{});var Gd=i(Lo);y(zt.$$.fragment,Gd),Gd.forEach(o),Pd.forEach(o),Aa=c(Gr),Do=a(Gr,"SPAN",{});var Bd=i(Do);Pa=n(Bd,"SwitchTransformersEncoderModel"),Bd.forEach(o),Gr.forEach(o),kr=c(t),$=a(t,"DIV",{class:!0});var G=i($);y(Ct.$$.fragment,G),Ga=c(G),Yo=a(G,"P",{});var Hd=i(Yo);Ba=n(Hd,"The bare SWITCH_TRANSFORMERS Model transformer outputting encoder\u2019s raw hidden-states without any specific head on top."),Hd.forEach(o),Ha=c(G),J=a(G,"P",{});var ee=i(J);Oa=n(ee,"The SWITCH_TRANSFORMERS model was proposed in "),Ft=a(ee,"A",{href:!0,rel:!0});var Od=i(Ft);Va=n(Od,`Switch Transformers: Scaling to Trillion Parameter Models with
Simple and Efficient Sparsity`),Od.forEach(o),Xa=n(ee," by "),Rt=a(ee,"A",{href:!0,rel:!0});var Vd=i(Rt);La=n(Vd,`William
Fedus`),Vd.forEach(o),Da=n(ee,", "),It=a(ee,"A",{href:!0,rel:!0});var Xd=i(It);Ya=n(Xd,`Barret
Zoph`),Xd.forEach(o),Qa=n(ee,", and "),Ut=a(ee,"A",{href:!0,rel:!0});var Ld=i(Ut);Ka=n(Ld,`Noam
Shazeer`),Ld.forEach(o),ei=n(ee,`. It\u2019s an encoder-decoder T5-like model
with sparse Feed Forward that stands for Mixture of Experts (MoE) architecture.`),ee.forEach(o),ti=c(G),Jt=a(G,"P",{});var Br=i(Jt);oi=n(Br,"This model inherits from "),to=a(Br,"A",{href:!0});var Dd=i(to);ri=n(Dd,"PreTrainedModel"),Dd.forEach(o),ni=n(Br,`. 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.)`),Br.forEach(o),si=c(G),jt=a(G,"P",{});var Hr=i(jt);ai=n(Hr,"This model is also a PyTorch "),qt=a(Hr,"A",{href:!0,rel:!0});var Yd=i(qt);ii=n(Yd,"torch.nn.Module"),Yd.forEach(o),di=n(Hr,` subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`),Hr.forEach(o),li=c(G),Z=a(G,"DIV",{class:!0});var Ze=i(Z);y(Wt.$$.fragment,Ze),ci=c(Ze),ue=a(Ze,"P",{});var po=i(ue);hi=n(po,"The "),oo=a(po,"A",{href:!0});var Qd=i(oo);pi=n(Qd,"SwitchTransformersEncoderModel"),Qd.forEach(o),mi=n(po," forward method, overrides the "),Qo=a(po,"CODE",{});var Kd=i(Qo);ui=n(Kd,"__call__"),Kd.forEach(o),fi=n(po," special method."),po.forEach(o),_i=c(Ze),y(Re.$$.fragment,Ze),gi=c(Ze),y(Ie.$$.fragment,Ze),Ze.forEach(o),G.forEach(o),this.h()},h(){d(m,"name","hf:doc:metadata"),d(m,"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(Pe,"href","https://arxiv.org/abs/2101.03961"),d(Pe,"rel","nofollow"),d(Ht,"href","/docs/transformers/main/en/model_doc/t5#transformers.T5Tokenizer"),d(He,"href","https://moon-ci-docs.huggingface.co/docs/transformers/pr_19323/en/glossary#general-terms"),d(He,"rel","nofollow"),d(Oe,"href","https://huggingface.co/ybelkada"),d(Oe,"rel","nofollow"),d(Ve,"href","https://huggingface.co/ArtZucker"),d(Ve,"rel","nofollow"),d(Xe,"href","https://github.com/google/flaxformer/tree/main/flaxformer/architectures/moe"),d(Xe,"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(Ot,"href","../tasks/translation"),d(Vt,"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(Xt,"href","/docs/transformers/main/en/model_doc/switch_transformers#transformers.SwitchTransformersModel"),d(Qe,"href","https://huggingface.co/google/switch-base-8"),d(Qe,"rel","nofollow"),d(Lt,"href","/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig"),d(Dt,"href","/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig"),d(H,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(ve,"id","transformers.SwitchTransformersTop1Router"),d(ve,"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(ve,"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(Me,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(L,"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(ke,"id","transformers.SwitchTransformersSparseMLP"),d(ke,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(ke,"href","#transformers.SwitchTransformersSparseMLP"),d(de,"class","relative group"),d(q,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(V,"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.SwitchTransformersModel"),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.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(mt,"href","https://arxiv.org/search/cs?searchtype=author&query=Shazeer%2C+N"),d(mt,"rel","nofollow"),d(Yt,"href","/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel"),d(_t,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),d(_t,"rel","nofollow"),d(Qt,"href","/docs/transformers/main/en/model_doc/switch_transformers#transformers.SwitchTransformersModel"),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(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($e,"id","transformers.SwitchTransformersForConditionalGeneration"),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","#transformers.SwitchTransformersForConditionalGeneration"),d(he,"class","relative group"),d(bt,"href","https://arxiv.org/abs/2101.03961"),d(bt,"rel","nofollow"),d(vt,"href","https://arxiv.org/search/cs?searchtype=author&query=Fedus%2C+W"),d(vt,"rel","nofollow"),d(Mt,"href","https://arxiv.org/search/cs?searchtype=author&query=Zoph%2C+B"),d(Mt,"rel","nofollow"),d(kt,"href","https://arxiv.org/search/cs?searchtype=author&query=Shazeer%2C+N"),d(kt,"rel","nofollow"),d(Kt,"href","/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel"),d(xt,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),d(xt,"rel","nofollow"),d(eo,"href","/docs/transformers/main/en/model_doc/switch_transformers#transformers.SwitchTransformersForConditionalGeneration"),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(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(Fe,"id","transformers.SwitchTransformersEncoderModel"),d(Fe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(Fe,"href","#transformers.SwitchTransformersEncoderModel"),d(me,"class","relative group"),d(Ft,"href","https://arxiv.org/abs/2101.03961"),d(Ft,"rel","nofollow"),d(Rt,"href","https://arxiv.org/search/cs?searchtype=author&query=Fedus%2C+W"),d(Rt,"rel","nofollow"),d(It,"href","https://arxiv.org/search/cs?searchtype=author&query=Zoph%2C+B"),d(It,"rel","nofollow"),d(Ut,"href","https://arxiv.org/search/cs?searchtype=author&query=Shazeer%2C+N"),d(Ut,"rel","nofollow"),d(to,"href","/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel"),d(qt,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),d(qt,"rel","nofollow"),d(oo,"href","/docs/transformers/main/en/model_doc/switch_transformers#transformers.SwitchTransformersEncoderModel"),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($,"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,m),u(t,S,p),u(t,g,p),e(g,_),e(_,w),b(h,w,null),e(g,f),e(g,F),e(F,Or),u(t,rr,p),u(t,te,p),e(te,_e),e(_e,mo),b(Ae,mo,null),e(te,Vr),e(te,uo),e(uo,Xr),u(t,nr,p),u(t,ge,p),e(ge,Lr),e(ge,Pe),e(Pe,Dr),e(ge,Yr),u(t,sr,p),u(t,At,p),e(At,Qr),u(t,ar,p),u(t,Pt,p),e(Pt,Kr),u(t,ir,p),u(t,Gt,p),e(Gt,fo),e(fo,en),u(t,dr,p),u(t,Bt,p),e(Bt,tn),u(t,lr,p),u(t,we,p),e(we,Ge),e(Ge,on),e(Ge,Ht),e(Ht,rn),e(Ge,nn),e(we,sn),e(we,Be),e(Be,an),e(Be,He),e(He,dn),e(Be,ln),u(t,cr,p),u(t,j,p),e(j,cn),e(j,Oe),e(Oe,hn),e(j,pn),e(j,Ve),e(Ve,mn),e(j,un),e(j,Xe),e(Xe,fn),e(j,_n),u(t,hr,p),u(t,oe,p),e(oe,Te),e(Te,_o),b(Le,_o,null),e(oe,gn),e(oe,go),e(go,wn),u(t,pr,p),u(t,ye,p),e(ye,wo),e(wo,Ot),e(Ot,Tn),e(ye,yn),e(ye,To),e(To,Vt),e(Vt,bn),u(t,mr,p),u(t,re,p),e(re,be),e(be,yo),b(De,yo,null),e(re,vn),e(re,bo),e(bo,Mn),u(t,ur,p),u(t,H,p),b(Ye,H,null),e(H,kn),e(H,ne),e(ne,Sn),e(ne,Xt),e(Xt,En),e(ne,xn),e(ne,Qe),e(Qe,$n),e(ne,zn),e(H,Cn),e(H,se),e(se,Fn),e(se,Lt),e(Lt,Rn),e(se,In),e(se,Dt),e(Dt,Un),e(se,Jn),u(t,fr,p),u(t,ae,p),e(ae,ve),e(ve,vo),b(Ke,vo,null),e(ae,jn),e(ae,Mo),e(Mo,qn),u(t,_r,p),u(t,z,p),b(et,z,null),e(z,Wn),e(z,ko),e(ko,Nn),e(z,Zn),e(z,O),e(O,An),e(O,tt),e(tt,Pn),e(O,Gn),e(O,ot),e(ot,Bn),e(O,Hn),e(O,So),e(So,On),e(O,Vn),e(z,Xn),e(z,Me),b(rt,Me,null),e(Me,Ln),e(Me,Eo),e(Eo,Dn),e(z,Yn),e(z,L),b(nt,L,null),e(L,Qn),e(L,ie),e(ie,Kn),e(ie,xo),e(xo,es),e(ie,ts),e(ie,$o),e($o,os),e(ie,rs),e(L,ns),e(L,R),e(R,ss),e(R,zo),e(zo,as),e(R,is),e(R,Co),e(Co,ds),e(R,ls),e(R,Fo),e(Fo,cs),e(R,hs),e(R,Ro),e(Ro,ps),e(R,ms),u(t,gr,p),u(t,de,p),e(de,ke),e(ke,Io),b(st,Io,null),e(de,us),e(de,Uo),e(Uo,fs),u(t,wr,p),u(t,V,p),b(at,V,null),e(V,_s),e(V,Jo),e(Jo,gs),e(V,ws),e(V,q),b(it,q,null),e(q,Ts),e(q,jo),e(jo,ys),e(q,bs),e(q,X),e(X,vs),e(X,qo),e(qo,Ms),e(X,ks),e(X,Wo),e(Wo,Ss),e(X,Es),e(X,No),e(No,xs),e(X,$s),e(q,zs),e(q,Zo),e(Zo,Cs),u(t,Tr,p),u(t,le,p),e(le,Se),e(Se,Ao),b(dt,Ao,null),e(le,Fs),e(le,Po),e(Po,Rs),u(t,yr,p),u(t,E,p),b(lt,E,null),e(E,Is),e(E,Go),e(Go,Us),e(E,Js),e(E,I),e(I,js),e(I,ct),e(ct,qs),e(I,Ws),e(I,ht),e(ht,Ns),e(I,Zs),e(I,pt),e(pt,As),e(I,Ps),e(I,mt),e(mt,Gs),e(I,Bs),e(E,Hs),e(E,ut),e(ut,Os),e(ut,Yt),e(Yt,Vs),e(ut,Xs),e(E,Ls),e(E,ft),e(ft,Ds),e(ft,_t),e(_t,Ys),e(ft,Qs),e(E,Ks),e(E,W),b(gt,W,null),e(W,ea),e(W,ce),e(ce,ta),e(ce,Qt),e(Qt,oa),e(ce,ra),e(ce,Bo),e(Bo,na),e(ce,sa),e(W,aa),b(Ee,W,null),e(W,ia),b(xe,W,null),u(t,br,p),u(t,he,p),e(he,$e),e($e,Ho),b(wt,Ho,null),e(he,da),e(he,Oo),e(Oo,la),u(t,vr,p),u(t,x,p),b(Tt,x,null),e(x,ca),e(x,yt),e(yt,ha),e(yt,Vo),e(Vo,pa),e(yt,ma),e(x,ua),e(x,U),e(U,fa),e(U,bt),e(bt,_a),e(U,ga),e(U,vt),e(vt,wa),e(U,Ta),e(U,Mt),e(Mt,ya),e(U,ba),e(U,kt),e(kt,va),e(U,Ma),e(x,ka),e(x,St),e(St,Sa),e(St,Kt),e(Kt,Ea),e(St,xa),e(x,$a),e(x,Et),e(Et,za),e(Et,xt),e(xt,Ca),e(Et,Fa),e(x,Ra),e(x,N),b($t,N,null),e(N,Ia),e(N,pe),e(pe,Ua),e(pe,eo),e(eo,Ja),e(pe,ja),e(pe,Xo),e(Xo,qa),e(pe,Wa),e(N,Na),b(ze,N,null),e(N,Za),b(Ce,N,null),u(t,Mr,p),u(t,me,p),e(me,Fe),e(Fe,Lo),b(zt,Lo,null),e(me,Aa),e(me,Do),e(Do,Pa),u(t,kr,p),u(t,$,p),b(Ct,$,null),e($,Ga),e($,Yo),e(Yo,Ba),e($,Ha),e($,J),e(J,Oa),e(J,Ft),e(Ft,Va),e(J,Xa),e(J,Rt),e(Rt,La),e(J,Da),e(J,It),e(It,Ya),e(J,Qa),e(J,Ut),e(Ut,Ka),e(J,ei),e($,ti),e($,Jt),e(Jt,oi),e(Jt,to),e(to,ri),e(Jt,ni),e($,si),e($,jt),e(jt,ai),e(jt,qt),e(qt,ii),e(jt,di),e($,li),e($,Z),b(Wt,Z,null),e(Z,ci),e(Z,ue),e(ue,hi),e(ue,oo),e(oo,pi),e(ue,mi),e(ue,Qo),e(Qo,ui),e(ue,fi),e(Z,_i),b(Re,Z,null),e(Z,gi),b(Ie,Z,null),Sr=!0},p(t,[p]){const Nt={};p&2&&(Nt.$$scope={dirty:p,ctx:t}),Ee.$set(Nt);const Ko={};p&2&&(Ko.$$scope={dirty:p,ctx:t}),xe.$set(Ko);const er={};p&2&&(er.$$scope={dirty:p,ctx:t}),ze.$set(er);const tr={};p&2&&(tr.$$scope={dirty:p,ctx:t}),Ce.$set(tr);const Zt={};p&2&&(Zt.$$scope={dirty:p,ctx:t}),Re.$set(Zt);const or={};p&2&&(or.$$scope={dirty:p,ctx:t}),Ie.$set(or)},i(t){Sr||(v(h.$$.fragment,t),v(Ae.$$.fragment,t),v(Le.$$.fragment,t),v(De.$$.fragment,t),v(Ye.$$.fragment,t),v(Ke.$$.fragment,t),v(et.$$.fragment,t),v(rt.$$.fragment,t),v(nt.$$.fragment,t),v(st.$$.fragment,t),v(at.$$.fragment,t),v(it.$$.fragment,t),v(dt.$$.fragment,t),v(lt.$$.fragment,t),v(gt.$$.fragment,t),v(Ee.$$.fragment,t),v(xe.$$.fragment,t),v(wt.$$.fragment,t),v(Tt.$$.fragment,t),v($t.$$.fragment,t),v(ze.$$.fragment,t),v(Ce.$$.fragment,t),v(zt.$$.fragment,t),v(Ct.$$.fragment,t),v(Wt.$$.fragment,t),v(Re.$$.fragment,t),v(Ie.$$.fragment,t),Sr=!0)},o(t){M(h.$$.fragment,t),M(Ae.$$.fragment,t),M(Le.$$.fragment,t),M(De.$$.fragment,t),M(Ye.$$.fragment,t),M(Ke.$$.fragment,t),M(et.$$.fragment,t),M(rt.$$.fragment,t),M(nt.$$.fragment,t),M(st.$$.fragment,t),M(at.$$.fragment,t),M(it.$$.fragment,t),M(dt.$$.fragment,t),M(lt.$$.fragment,t),M(gt.$$.fragment,t),M(Ee.$$.fragment,t),M(xe.$$.fragment,t),M(wt.$$.fragment,t),M(Tt.$$.fragment,t),M($t.$$.fragment,t),M(ze.$$.fragment,t),M(Ce.$$.fragment,t),M(zt.$$.fragment,t),M(Ct.$$.fragment,t),M(Wt.$$.fragment,t),M(Re.$$.fragment,t),M(Ie.$$.fragment,t),Sr=!1},d(t){o(m),t&&o(S),t&&o(g),k(h),t&&o(rr),t&&o(te),k(Ae),t&&o(nr),t&&o(ge),t&&o(sr),t&&o(At),t&&o(ar),t&&o(Pt),t&&o(ir),t&&o(Gt),t&&o(dr),t&&o(Bt),t&&o(lr),t&&o(we),t&&o(cr),t&&o(j),t&&o(hr),t&&o(oe),k(Le),t&&o(pr),t&&o(ye),t&&o(mr),t&&o(re),k(De),t&&o(ur),t&&o(H),k(Ye),t&&o(fr),t&&o(ae),k(Ke),t&&o(_r),t&&o(z),k(et),k(rt),k(nt),t&&o(gr),t&&o(de),k(st),t&&o(wr),t&&o(V),k(at),k(it),t&&o(Tr),t&&o(le),k(dt),t&&o(yr),t&&o(E),k(lt),k(gt),k(Ee),k(xe),t&&o(br),t&&o(he),k(wt),t&&o(vr),t&&o(x),k(Tt),k($t),k(ze),k(Ce),t&&o(Mr),t&&o(me),k(zt),t&&o(kr),t&&o($),k(Ct),k(Wt),k(Re),k(Ie)}}}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 ml(C){return nl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class yl extends el{constructor(m){super();tl(this,m,ml,hl,ol,{})}}export{yl as default,pl as metadata};
