import{s as Te,o as ve,n as $e}from"../chunks/scheduler.8c3d61f6.js";import{S as De,i as Me,g as i,s,r as g,A as ye,h as d,f as n,c as r,j as U,u as b,x as u,k as j,y as p,a as o,v as T,d as v,t as $,w as D}from"../chunks/index.da70eac4.js";import{T as xe}from"../chunks/Tip.1d9b8c37.js";import{D as le}from"../chunks/Docstring.6b390b9a.js";import{H as me,E as we}from"../chunks/EditOnGithub.1e64e623.js";function ke(S){let a,M="It is assumed one of the input classes is the masked latent pixel. The predicted classes of the unnoised image don’t contain a prediction for the masked pixel because the unnoised image cannot be masked.";return{c(){a=i("p"),a.textContent=M},l(l){a=d(l,"P",{"data-svelte-h":!0}),u(a)!=="svelte-3w1alv"&&(a.textContent=M)},m(l,I){o(l,a,I)},p:$e,d(l){l&&n(a)}}}function Le(S){let a,M,l,I,y,W,x,ce='A Transformer model for image-like data from <a href="https://huggingface.co/CompVis" rel="nofollow">CompVis</a> that is based on the <a href="https://huggingface.co/papers/2010.11929" rel="nofollow">Vision Transformer</a> introduced by Dosovitskiy et al. The <a href="/docs/diffusers/pr_10099/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a> accepts discrete (classes of vector embeddings) or continuous (actual embeddings) inputs.',B,w,fe="When the input is <strong>continuous</strong>:",R,k,pe="<li>Project the input and reshape it to <code>(batch_size, sequence_length, feature_dimension)</code>.</li> <li>Apply the Transformer blocks in the standard way.</li> <li>Reshape to image.</li>",G,L,ue="When the input is <strong>discrete</strong>:",Z,h,J,O,he="<li>Convert input (classes of latent pixels) to embeddings and apply positional embeddings.</li> <li>Apply the Transformer blocks in the standard way.</li> <li>Predict classes of unnoised image.</li>",K,C,Q,m,N,re,E,_e="A 2D Transformer model for image-like data.",ae,_,P,ie,q,ge='The <a href="/docs/diffusers/pr_10099/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a> forward method.',X,H,Y,c,A,de,F,be='The output of <a href="/docs/diffusers/pr_10099/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a>.',ee,z,te,V,ne;return y=new me({props:{title:"Transformer2DModel",local:"transformer2dmodel",headingTag:"h1"}}),h=new xe({props:{$$slots:{default:[ke]},$$scope:{ctx:S}}}),C=new me({props:{title:"Transformer2DModel",local:"diffusers.Transformer2DModel",headingTag:"h2"}}),N=new le({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:"double_self_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:"norm_eps",val:": float = 1e-05"},{name:"attention_type",val:": str = 'default'"},{name:"caption_channels",val:": int = None"},{name:"interpolation_scale",val:": float = None"},{name:"use_additional_conditions",val:": typing.Optional[bool] = None"}],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/vr_10099/src/diffusers/models/transformers/transformer_2d.py#L39"}}),P=new le({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:"added_cond_kwargs",val:": typing.Dict[str, torch.Tensor] = 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.Tensor</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.Tensor</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.cross_attention_kwargs",description:`<strong>cross_attention_kwargs</strong> ( <code>Dict[str, Any]</code>, <em>optional</em>) &#x2014;
A kwargs dictionary that if specified is passed along to the <code>AttentionProcessor</code> as defined under
<code>self.processor</code> in
<a href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py" rel="nofollow">diffusers.models.attention_processor</a>.`,name:"cross_attention_kwargs"},{anchor:"diffusers.Transformer2DModel.forward.attention_mask",description:`<strong>attention_mask</strong> ( <code>torch.Tensor</code>, <em>optional</em>) &#x2014;
An attention mask of shape <code>(batch, key_tokens)</code> is applied to <code>encoder_hidden_states</code>. If <code>1</code> the mask
is kept, otherwise if <code>0</code> it is discarded. Mask will be converted into a bias, which adds large
negative values to the attention scores corresponding to &#x201C;discard&#x201D; tokens.`,name:"attention_mask"},{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/pr_10099/en/api/models/unet2d-cond#diffusers.models.unets.unet_2d_condition.UNet2DConditionOutput">UNet2DConditionOutput</a> instead of a plain
tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/vr_10099/src/diffusers/models/transformers/transformer_2d.py#L327",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>If <code>return_dict</code> is True, an <code>Transformer2DModelOutput</code> is returned,
otherwise a <code>tuple</code> where the first element is the sample tensor.</p>
`}}),H=new me({props:{title:"Transformer2DModelOutput",local:"diffusers.models.modeling_outputs.Transformer2DModelOutput",headingTag:"h2"}}),A=new le({props:{name:"class diffusers.models.modeling_outputs.Transformer2DModelOutput",anchor:"diffusers.models.modeling_outputs.Transformer2DModelOutput",parameters:[{name:"sample",val:": torch.Tensor"}],parametersDescription:[{anchor:"diffusers.models.modeling_outputs.Transformer2DModelOutput.sample",description:`<strong>sample</strong> (<code>torch.Tensor</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/pr_10099/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/vr_10099/src/diffusers/models/modeling_outputs.py#L20"}}),z=new we({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/transformer2d.md"}}),{c(){a=i("meta"),M=s(),l=i("p"),I=s(),g(y.$$.fragment),W=s(),x=i("p"),x.innerHTML=ce,B=s(),w=i("p"),w.innerHTML=fe,R=s(),k=i("ol"),k.innerHTML=pe,G=s(),L=i("p"),L.innerHTML=ue,Z=s(),g(h.$$.fragment),J=s(),O=i("ol"),O.innerHTML=he,K=s(),g(C.$$.fragment),Q=s(),m=i("div"),g(N.$$.fragment),re=s(),E=i("p"),E.textContent=_e,ae=s(),_=i("div"),g(P.$$.fragment),ie=s(),q=i("p"),q.innerHTML=ge,X=s(),g(H.$$.fragment),Y=s(),c=i("div"),g(A.$$.fragment),de=s(),F=i("p"),F.innerHTML=be,ee=s(),g(z.$$.fragment),te=s(),V=i("p"),this.h()},l(e){const t=ye("svelte-u9bgzb",document.head);a=d(t,"META",{name:!0,content:!0}),t.forEach(n),M=r(e),l=d(e,"P",{}),U(l).forEach(n),I=r(e),b(y.$$.fragment,e),W=r(e),x=d(e,"P",{"data-svelte-h":!0}),u(x)!=="svelte-g54c1x"&&(x.innerHTML=ce),B=r(e),w=d(e,"P",{"data-svelte-h":!0}),u(w)!=="svelte-ytlpm7"&&(w.innerHTML=fe),R=r(e),k=d(e,"OL",{"data-svelte-h":!0}),u(k)!=="svelte-10ra9yx"&&(k.innerHTML=pe),G=r(e),L=d(e,"P",{"data-svelte-h":!0}),u(L)!=="svelte-1wqmwav"&&(L.innerHTML=ue),Z=r(e),b(h.$$.fragment,e),J=r(e),O=d(e,"OL",{"data-svelte-h":!0}),u(O)!=="svelte-m2jel9"&&(O.innerHTML=he),K=r(e),b(C.$$.fragment,e),Q=r(e),m=d(e,"DIV",{class:!0});var f=U(m);b(N.$$.fragment,f),re=r(f),E=d(f,"P",{"data-svelte-h":!0}),u(E)!=="svelte-1dpkeub"&&(E.textContent=_e),ae=r(f),_=d(f,"DIV",{class:!0});var oe=U(_);b(P.$$.fragment,oe),ie=r(oe),q=d(oe,"P",{"data-svelte-h":!0}),u(q)!=="svelte-1s5gnkt"&&(q.innerHTML=ge),oe.forEach(n),f.forEach(n),X=r(e),b(H.$$.fragment,e),Y=r(e),c=d(e,"DIV",{class:!0});var se=U(c);b(A.$$.fragment,se),de=r(se),F=d(se,"P",{"data-svelte-h":!0}),u(F)!=="svelte-eohg5d"&&(F.innerHTML=be),se.forEach(n),ee=r(e),b(z.$$.fragment,e),te=r(e),V=d(e,"P",{}),U(V).forEach(n),this.h()},h(){j(a,"name","hf:doc:metadata"),j(a,"content",Oe),j(_,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),j(m,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),j(c,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,t){p(document.head,a),o(e,M,t),o(e,l,t),o(e,I,t),T(y,e,t),o(e,W,t),o(e,x,t),o(e,B,t),o(e,w,t),o(e,R,t),o(e,k,t),o(e,G,t),o(e,L,t),o(e,Z,t),T(h,e,t),o(e,J,t),o(e,O,t),o(e,K,t),T(C,e,t),o(e,Q,t),o(e,m,t),T(N,m,null),p(m,re),p(m,E),p(m,ae),p(m,_),T(P,_,null),p(_,ie),p(_,q),o(e,X,t),T(H,e,t),o(e,Y,t),o(e,c,t),T(A,c,null),p(c,de),p(c,F),o(e,ee,t),T(z,e,t),o(e,te,t),o(e,V,t),ne=!0},p(e,[t]){const f={};t&2&&(f.$$scope={dirty:t,ctx:e}),h.$set(f)},i(e){ne||(v(y.$$.fragment,e),v(h.$$.fragment,e),v(C.$$.fragment,e),v(N.$$.fragment,e),v(P.$$.fragment,e),v(H.$$.fragment,e),v(A.$$.fragment,e),v(z.$$.fragment,e),ne=!0)},o(e){$(y.$$.fragment,e),$(h.$$.fragment,e),$(C.$$.fragment,e),$(N.$$.fragment,e),$(P.$$.fragment,e),$(H.$$.fragment,e),$(A.$$.fragment,e),$(z.$$.fragment,e),ne=!1},d(e){e&&(n(M),n(l),n(I),n(W),n(x),n(B),n(w),n(R),n(k),n(G),n(L),n(Z),n(J),n(O),n(K),n(Q),n(m),n(X),n(Y),n(c),n(ee),n(te),n(V)),n(a),D(y,e),D(h,e),D(C,e),D(N),D(P),D(H,e),D(A),D(z,e)}}}const Oe='{"title":"Transformer2DModel","local":"transformer2dmodel","sections":[{"title":"Transformer2DModel","local":"diffusers.Transformer2DModel","sections":[],"depth":2},{"title":"Transformer2DModelOutput","local":"diffusers.models.modeling_outputs.Transformer2DModelOutput","sections":[],"depth":2}],"depth":1}';function Ce(S){return ve(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ie extends De{constructor(a){super(),Me(this,a,Ce,Le,Te,{})}}export{Ie as component};
