import{S as Kt,i as Qt,s as Xt,e as n,k as f,w as W,t as a,M as Yt,c as r,d as o,m,a as s,x as j,h as i,b as l,G as t,g as c,y as B,q as G,o as H,B as J,v as eo}from"../../../chunks/vendor-hf-doc-builder.js";import{T as to}from"../../../chunks/Tip-hf-doc-builder.js";import{D as Mt}from"../../../chunks/Docstring-hf-doc-builder.js";import{I as xt}from"../../../chunks/IconCopyLink-hf-doc-builder.js";function oo(_e){let p,$;return{c(){p=n("p"),$=a("It is assumed one of the input classes is the masked latent pixel. The predicted classes of the unnoised image don\u2019t contain a prediction for the masked pixel because the unnoised image cannot be masked.")},l(u){p=r(u,"P",{});var h=s(p);$=i(h,"It is assumed one of the input classes is the masked latent pixel. The predicted classes of the unnoised image don\u2019t contain a prediction for the masked pixel because the unnoised image cannot be masked."),h.forEach(o)},m(u,h){c(u,p,h),t(p,$)},d(u){u&&o(p)}}}function no(_e){let p,$,u,h,te,N,Se,oe,qe,ge,_,Fe,L,Ve,Re,P,Ue,We,Z,je,Be,ve,w,Ge,ne,He,Je,be,v,I,Ze,re,Ke,Qe,Xe,se,Ye,et,ae,tt,Te,M,ot,ie,nt,rt,ye,x,De,b,de,st,at,le,it,dt,fe,lt,$e,T,k,me,z,ft,ce,mt,we,g,C,ct,pe,pt,ut,E,S,ht,q,_t,K,gt,vt,Me,y,O,ue,F,bt,he,Tt,xe,D,V,yt,R,Dt,Q,$t,wt,ke;return N=new xt({}),x=new to({props:{$$slots:{default:[oo]},$$scope:{ctx:_e}}}),z=new xt({}),C=new Mt({props:{name:"class diffusers.Transformer2DModel",anchor:"diffusers.Transformer2DModel",parameters:[{name:"num_attention_heads",val:": int = 16"},{name:"attention_head_dim",val:": int = 88"},{name:"in_channels",val:": typing.Optional[int] = None"},{name:"out_channels",val:": typing.Optional[int] = None"},{name:"num_layers",val:": int = 1"},{name:"dropout",val:": float = 0.0"},{name:"norm_num_groups",val:": int = 32"},{name:"cross_attention_dim",val:": typing.Optional[int] = None"},{name:"attention_bias",val:": bool = False"},{name:"sample_size",val:": typing.Optional[int] = None"},{name:"num_vector_embeds",val:": typing.Optional[int] = None"},{name:"patch_size",val:": typing.Optional[int] = None"},{name:"activation_fn",val:": str = 'geglu'"},{name:"num_embeds_ada_norm",val:": typing.Optional[int] = None"},{name:"use_linear_projection",val:": bool = False"},{name:"only_cross_attention",val:": bool = False"},{name:"upcast_attention",val:": bool = False"},{name:"norm_type",val:": str = 'layer_norm'"},{name:"norm_elementwise_affine",val:": bool = True"},{name:"attention_type",val:": str = 'default'"}],parametersDescription:[{anchor:"diffusers.Transformer2DModel.num_attention_heads",description:"<strong>num_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to 16) &#x2014; The number of heads to use for multi-head attention.",name:"num_attention_heads"},{anchor:"diffusers.Transformer2DModel.attention_head_dim",description:"<strong>attention_head_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 88) &#x2014; The number of channels in each head.",name:"attention_head_dim"},{anchor:"diffusers.Transformer2DModel.in_channels",description:`<strong>in_channels</strong> (<code>int</code>, <em>optional</em>) &#x2014;
The number of channels in the input and output (specify if the input is <strong>continuous</strong>).`,name:"in_channels"},{anchor:"diffusers.Transformer2DModel.num_layers",description:"<strong>num_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014; The number of layers of Transformer blocks to use.",name:"num_layers"},{anchor:"diffusers.Transformer2DModel.dropout",description:"<strong>dropout</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014; The dropout probability to use.",name:"dropout"},{anchor:"diffusers.Transformer2DModel.cross_attention_dim",description:"<strong>cross_attention_dim</strong> (<code>int</code>, <em>optional</em>) &#x2014; The number of <code>encoder_hidden_states</code> dimensions to use.",name:"cross_attention_dim"},{anchor:"diffusers.Transformer2DModel.sample_size",description:`<strong>sample_size</strong> (<code>int</code>, <em>optional</em>) &#x2014; The width of the latent images (specify if the input is <strong>discrete</strong>).
This is fixed during training since it is used to learn a number of position embeddings.`,name:"sample_size"},{anchor:"diffusers.Transformer2DModel.num_vector_embeds",description:`<strong>num_vector_embeds</strong> (<code>int</code>, <em>optional</em>) &#x2014;
The number of classes of the vector embeddings of the latent pixels (specify if the input is <strong>discrete</strong>).
Includes the class for the masked latent pixel.`,name:"num_vector_embeds"},{anchor:"diffusers.Transformer2DModel.activation_fn",description:"<strong>activation_fn</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;geglu&quot;</code>) &#x2014; Activation function to use in feed-forward.",name:"activation_fn"},{anchor:"diffusers.Transformer2DModel.num_embeds_ada_norm",description:`<strong>num_embeds_ada_norm</strong> ( <code>int</code>, <em>optional</em>) &#x2014;
The number of diffusion steps used during training. Pass if at least one of the norm_layers is
<code>AdaLayerNorm</code>. This is fixed during training since it is used to learn a number of embeddings that are
added to the hidden states.</p>
<p>During inference, you can denoise for up to but not more steps than <code>num_embeds_ada_norm</code>.`,name:"num_embeds_ada_norm"},{anchor:"diffusers.Transformer2DModel.attention_bias",description:`<strong>attention_bias</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Configure if the <code>TransformerBlocks</code> attention should contain a bias parameter.`,name:"attention_bias"}],source:"https://github.com/huggingface/diffusers/blob/v0.20.0/src/diffusers/models/transformer_2d.py#L44"}}),S=new Mt({props:{name:"forward",anchor:"diffusers.Transformer2DModel.forward",parameters:[{name:"hidden_states",val:": Tensor"},{name:"encoder_hidden_states",val:": typing.Optional[torch.Tensor] = None"},{name:"timestep",val:": typing.Optional[torch.LongTensor] = None"},{name:"class_labels",val:": typing.Optional[torch.LongTensor] = None"},{name:"cross_attention_kwargs",val:": typing.Dict[str, typing.Any] = None"},{name:"attention_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"encoder_attention_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"return_dict",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.Transformer2DModel.forward.hidden_states",description:`<strong>hidden_states</strong> (<code>torch.LongTensor</code> of shape <code>(batch size, num latent pixels)</code> if discrete, <code>torch.FloatTensor</code> of shape <code>(batch size, channel, height, width)</code> if continuous) &#x2014;
Input <code>hidden_states</code>.`,name:"hidden_states"},{anchor:"diffusers.Transformer2DModel.forward.encoder_hidden_states",description:`<strong>encoder_hidden_states</strong> ( <code>torch.FloatTensor</code> of shape <code>(batch size, sequence len, embed dims)</code>, <em>optional</em>) &#x2014;
Conditional embeddings for cross attention layer. If not given, cross-attention defaults to
self-attention.`,name:"encoder_hidden_states"},{anchor:"diffusers.Transformer2DModel.forward.timestep",description:`<strong>timestep</strong> ( <code>torch.LongTensor</code>, <em>optional</em>) &#x2014;
Used to indicate denoising step. Optional timestep to be applied as an embedding in <code>AdaLayerNorm</code>.`,name:"timestep"},{anchor:"diffusers.Transformer2DModel.forward.class_labels",description:`<strong>class_labels</strong> ( <code>torch.LongTensor</code> of shape <code>(batch size, num classes)</code>, <em>optional</em>) &#x2014;
Used to indicate class labels conditioning. Optional class labels to be applied as an embedding in
<code>AdaLayerZeroNorm</code>.`,name:"class_labels"},{anchor:"diffusers.Transformer2DModel.forward.encoder_attention_mask",description:`<strong>encoder_attention_mask</strong> ( <code>torch.Tensor</code>, <em>optional</em>) &#x2014;
Cross-attention mask applied to <code>encoder_hidden_states</code>. Two formats supported:</p>
<ul>
<li>Mask <code>(batch, sequence_length)</code> True = keep, False = discard.</li>
<li>Bias <code>(batch, 1, sequence_length)</code> 0 = keep, -10000 = discard.</li>
</ul>
<p>If <code>ndim == 2</code>: will be interpreted as a mask, then converted into a bias consistent with the format
above. This bias will be added to the cross-attention scores.`,name:"encoder_attention_mask"},{anchor:"diffusers.Transformer2DModel.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to return a <a href="/docs/diffusers/v0.20.0/en/api/models/unet2d-cond#diffusers.models.unet_2d_condition.UNet2DConditionOutput">UNet2DConditionOutput</a> instead of a plain
tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/v0.20.0/src/diffusers/models/transformer_2d.py#L211",returnDescription:`
<p>If <code>return_dict</code> is True, an <a
  href="/docs/diffusers/v0.20.0/en/api/models/transformer2d#diffusers.models.transformer_2d.Transformer2DModelOutput"
>Transformer2DModelOutput</a> is returned, otherwise a
<code>tuple</code> where the first element is the sample tensor.</p>
`}}),F=new xt({}),V=new Mt({props:{name:"class diffusers.models.transformer_2d.Transformer2DModelOutput",anchor:"diffusers.models.transformer_2d.Transformer2DModelOutput",parameters:[{name:"sample",val:": FloatTensor"}],parametersDescription:[{anchor:"diffusers.models.transformer_2d.Transformer2DModelOutput.sample",description:`<strong>sample</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, num_channels, height, width)</code> or <code>(batch size, num_vector_embeds - 1, num_latent_pixels)</code> if <a href="/docs/diffusers/v0.20.0/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a> is discrete) &#x2014;
The hidden states output conditioned on the <code>encoder_hidden_states</code> input. If discrete, returns probability
distributions for the unnoised latent pixels.`,name:"sample"}],source:"https://github.com/huggingface/diffusers/blob/v0.20.0/src/diffusers/models/transformer_2d.py#L31"}}),{c(){p=n("meta"),$=f(),u=n("h1"),h=n("a"),te=n("span"),W(N.$$.fragment),Se=f(),oe=n("span"),qe=a("Transformer2D"),ge=f(),_=n("p"),Fe=a("A Transformer model for image-like data from "),L=n("a"),Ve=a("CompVis"),Re=a(" that is based on the "),P=n("a"),Ue=a("Vision Transformer"),We=a(" introduced by Dosovitskiy et al. The "),Z=n("a"),je=a("Transformer2DModel"),Be=a(" accepts discrete (classes of vector embeddings) or continuous (actual embeddings) inputs."),ve=f(),w=n("p"),Ge=a("When the input is "),ne=n("strong"),He=a("continuous"),Je=a(":"),be=f(),v=n("ol"),I=n("li"),Ze=a("Project the input and reshape it to "),re=n("code"),Ke=a("(batch_size, sequence_length, feature_dimension)"),Qe=a("."),Xe=f(),se=n("li"),Ye=a("Apply the Transformer blocks in the standard way."),et=f(),ae=n("li"),tt=a("Reshape to image."),Te=f(),M=n("p"),ot=a("When the input is "),ie=n("strong"),nt=a("discrete"),rt=a(":"),ye=f(),W(x.$$.fragment),De=f(),b=n("ol"),de=n("li"),st=a("Convert input (classes of latent pixels) to embeddings and apply positional embeddings."),at=f(),le=n("li"),it=a("Apply the Transformer blocks in the standard way."),dt=f(),fe=n("li"),lt=a("Predict classes of unnoised image."),$e=f(),T=n("h2"),k=n("a"),me=n("span"),W(z.$$.fragment),ft=f(),ce=n("span"),mt=a("Transformer2DModel"),we=f(),g=n("div"),W(C.$$.fragment),ct=f(),pe=n("p"),pt=a("A 2D Transformer model for image-like data."),ut=f(),E=n("div"),W(S.$$.fragment),ht=f(),q=n("p"),_t=a("The "),K=n("a"),gt=a("Transformer2DModel"),vt=a(" forward method."),Me=f(),y=n("h2"),O=n("a"),ue=n("span"),W(F.$$.fragment),bt=f(),he=n("span"),Tt=a("Transformer2DModelOutput"),xe=f(),D=n("div"),W(V.$$.fragment),yt=f(),R=n("p"),Dt=a("The output of "),Q=n("a"),$t=a("Transformer2DModel"),wt=a("."),this.h()},l(e){const d=Yt('[data-svelte="svelte-1phssyn"]',document.head);p=r(d,"META",{name:!0,content:!0}),d.forEach(o),$=m(e),u=r(e,"H1",{class:!0});var U=s(u);h=r(U,"A",{id:!0,class:!0,href:!0});var kt=s(h);te=r(kt,"SPAN",{});var Et=s(te);j(N.$$.fragment,Et),Et.forEach(o),kt.forEach(o),Se=m(U),oe=r(U,"SPAN",{});var Ot=s(oe);qe=i(Ot,"Transformer2D"),Ot.forEach(o),U.forEach(o),ge=m(e),_=r(e,"P",{});var A=s(_);Fe=i(A,"A Transformer model for image-like data from "),L=r(A,"A",{href:!0,rel:!0});var At=s(L);Ve=i(At,"CompVis"),At.forEach(o),Re=i(A," that is based on the "),P=r(A,"A",{href:!0,rel:!0});var Nt=s(P);Ue=i(Nt,"Vision Transformer"),Nt.forEach(o),We=i(A," introduced by Dosovitskiy et al. The "),Z=r(A,"A",{href:!0});var Lt=s(Z);je=i(Lt,"Transformer2DModel"),Lt.forEach(o),Be=i(A," accepts discrete (classes of vector embeddings) or continuous (actual embeddings) inputs."),A.forEach(o),ve=m(e),w=r(e,"P",{});var Ee=s(w);Ge=i(Ee,"When the input is "),ne=r(Ee,"STRONG",{});var Pt=s(ne);He=i(Pt,"continuous"),Pt.forEach(o),Je=i(Ee,":"),Ee.forEach(o),be=m(e),v=r(e,"OL",{});var X=s(v);I=r(X,"LI",{});var Oe=s(I);Ze=i(Oe,"Project the input and reshape it to "),re=r(Oe,"CODE",{});var It=s(re);Ke=i(It,"(batch_size, sequence_length, feature_dimension)"),It.forEach(o),Qe=i(Oe,"."),Oe.forEach(o),Xe=m(X),se=r(X,"LI",{});var zt=s(se);Ye=i(zt,"Apply the Transformer blocks in the standard way."),zt.forEach(o),et=m(X),ae=r(X,"LI",{});var Ct=s(ae);tt=i(Ct,"Reshape to image."),Ct.forEach(o),X.forEach(o),Te=m(e),M=r(e,"P",{});var Ae=s(M);ot=i(Ae,"When the input is "),ie=r(Ae,"STRONG",{});var St=s(ie);nt=i(St,"discrete"),St.forEach(o),rt=i(Ae,":"),Ae.forEach(o),ye=m(e),j(x.$$.fragment,e),De=m(e),b=r(e,"OL",{});var Y=s(b);de=r(Y,"LI",{});var qt=s(de);st=i(qt,"Convert input (classes of latent pixels) to embeddings and apply positional embeddings."),qt.forEach(o),at=m(Y),le=r(Y,"LI",{});var Ft=s(le);it=i(Ft,"Apply the Transformer blocks in the standard way."),Ft.forEach(o),dt=m(Y),fe=r(Y,"LI",{});var Vt=s(fe);lt=i(Vt,"Predict classes of unnoised image."),Vt.forEach(o),Y.forEach(o),$e=m(e),T=r(e,"H2",{class:!0});var Ne=s(T);k=r(Ne,"A",{id:!0,class:!0,href:!0});var Rt=s(k);me=r(Rt,"SPAN",{});var Ut=s(me);j(z.$$.fragment,Ut),Ut.forEach(o),Rt.forEach(o),ft=m(Ne),ce=r(Ne,"SPAN",{});var Wt=s(ce);mt=i(Wt,"Transformer2DModel"),Wt.forEach(o),Ne.forEach(o),we=m(e),g=r(e,"DIV",{class:!0});var ee=s(g);j(C.$$.fragment,ee),ct=m(ee),pe=r(ee,"P",{});var jt=s(pe);pt=i(jt,"A 2D Transformer model for image-like data."),jt.forEach(o),ut=m(ee),E=r(ee,"DIV",{class:!0});var Le=s(E);j(S.$$.fragment,Le),ht=m(Le),q=r(Le,"P",{});var Pe=s(q);_t=i(Pe,"The "),K=r(Pe,"A",{href:!0});var Bt=s(K);gt=i(Bt,"Transformer2DModel"),Bt.forEach(o),vt=i(Pe," forward method."),Pe.forEach(o),Le.forEach(o),ee.forEach(o),Me=m(e),y=r(e,"H2",{class:!0});var Ie=s(y);O=r(Ie,"A",{id:!0,class:!0,href:!0});var Gt=s(O);ue=r(Gt,"SPAN",{});var Ht=s(ue);j(F.$$.fragment,Ht),Ht.forEach(o),Gt.forEach(o),bt=m(Ie),he=r(Ie,"SPAN",{});var Jt=s(he);Tt=i(Jt,"Transformer2DModelOutput"),Jt.forEach(o),Ie.forEach(o),xe=m(e),D=r(e,"DIV",{class:!0});var ze=s(D);j(V.$$.fragment,ze),yt=m(ze),R=r(ze,"P",{});var Ce=s(R);Dt=i(Ce,"The output of "),Q=r(Ce,"A",{href:!0});var Zt=s(Q);$t=i(Zt,"Transformer2DModel"),Zt.forEach(o),wt=i(Ce,"."),Ce.forEach(o),ze.forEach(o),this.h()},h(){l(p,"name","hf:doc:metadata"),l(p,"content",JSON.stringify(ro)),l(h,"id","transformer2d"),l(h,"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"),l(h,"href","#transformer2d"),l(u,"class","relative group"),l(L,"href","https://huggingface.co/CompVis"),l(L,"rel","nofollow"),l(P,"href","https://huggingface.co/papers/2010.11929"),l(P,"rel","nofollow"),l(Z,"href","/docs/diffusers/v0.20.0/en/api/models/transformer2d#diffusers.Transformer2DModel"),l(k,"id","diffusers.Transformer2DModel"),l(k,"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"),l(k,"href","#diffusers.Transformer2DModel"),l(T,"class","relative group"),l(K,"href","/docs/diffusers/v0.20.0/en/api/models/transformer2d#diffusers.Transformer2DModel"),l(E,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(g,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(O,"id","diffusers.models.transformer_2d.Transformer2DModelOutput"),l(O,"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"),l(O,"href","#diffusers.models.transformer_2d.Transformer2DModelOutput"),l(y,"class","relative group"),l(Q,"href","/docs/diffusers/v0.20.0/en/api/models/transformer2d#diffusers.Transformer2DModel"),l(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(e,d){t(document.head,p),c(e,$,d),c(e,u,d),t(u,h),t(h,te),B(N,te,null),t(u,Se),t(u,oe),t(oe,qe),c(e,ge,d),c(e,_,d),t(_,Fe),t(_,L),t(L,Ve),t(_,Re),t(_,P),t(P,Ue),t(_,We),t(_,Z),t(Z,je),t(_,Be),c(e,ve,d),c(e,w,d),t(w,Ge),t(w,ne),t(ne,He),t(w,Je),c(e,be,d),c(e,v,d),t(v,I),t(I,Ze),t(I,re),t(re,Ke),t(I,Qe),t(v,Xe),t(v,se),t(se,Ye),t(v,et),t(v,ae),t(ae,tt),c(e,Te,d),c(e,M,d),t(M,ot),t(M,ie),t(ie,nt),t(M,rt),c(e,ye,d),B(x,e,d),c(e,De,d),c(e,b,d),t(b,de),t(de,st),t(b,at),t(b,le),t(le,it),t(b,dt),t(b,fe),t(fe,lt),c(e,$e,d),c(e,T,d),t(T,k),t(k,me),B(z,me,null),t(T,ft),t(T,ce),t(ce,mt),c(e,we,d),c(e,g,d),B(C,g,null),t(g,ct),t(g,pe),t(pe,pt),t(g,ut),t(g,E),B(S,E,null),t(E,ht),t(E,q),t(q,_t),t(q,K),t(K,gt),t(q,vt),c(e,Me,d),c(e,y,d),t(y,O),t(O,ue),B(F,ue,null),t(y,bt),t(y,he),t(he,Tt),c(e,xe,d),c(e,D,d),B(V,D,null),t(D,yt),t(D,R),t(R,Dt),t(R,Q),t(Q,$t),t(R,wt),ke=!0},p(e,[d]){const U={};d&2&&(U.$$scope={dirty:d,ctx:e}),x.$set(U)},i(e){ke||(G(N.$$.fragment,e),G(x.$$.fragment,e),G(z.$$.fragment,e),G(C.$$.fragment,e),G(S.$$.fragment,e),G(F.$$.fragment,e),G(V.$$.fragment,e),ke=!0)},o(e){H(N.$$.fragment,e),H(x.$$.fragment,e),H(z.$$.fragment,e),H(C.$$.fragment,e),H(S.$$.fragment,e),H(F.$$.fragment,e),H(V.$$.fragment,e),ke=!1},d(e){o(p),e&&o($),e&&o(u),J(N),e&&o(ge),e&&o(_),e&&o(ve),e&&o(w),e&&o(be),e&&o(v),e&&o(Te),e&&o(M),e&&o(ye),J(x,e),e&&o(De),e&&o(b),e&&o($e),e&&o(T),J(z),e&&o(we),e&&o(g),J(C),J(S),e&&o(Me),e&&o(y),J(F),e&&o(xe),e&&o(D),J(V)}}}const ro={local:"transformer2d",sections:[{local:"diffusers.Transformer2DModel",title:"Transformer2DModel"},{local:"diffusers.models.transformer_2d.Transformer2DModelOutput",title:"Transformer2DModelOutput"}],title:"Transformer2D"};function so(_e){return eo(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class mo extends Kt{constructor(p){super();Qt(this,p,so,no,Xt,{})}}export{mo as default,ro as metadata};
