Buckets:
| import{s as $e,n as De,o as xe}from"../chunks/scheduler.53228c21.js";import{S as we,i as ye,e as a,s,c as h,h as ke,a as i,d as n,b as r,f as V,g as _,j as c,k as E,l as f,m as o,n as g,t as b,o as T,p as v}from"../chunks/index.cac5d66a.js";import{C as Ne}from"../chunks/CopyLLMTxtMenu.0ef49226.js";import{D as me}from"../chunks/Docstring.9de32ff4.js";import{H as ce,E as Le}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.48d5cb47.js";function Ce(fe){let l,j,F,S,M,B,$,W,D,ue='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_13921/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a> accepts discrete (classes of vector embeddings) or continuous (actual embeddings) inputs.',R,x,pe="When the input is <strong>continuous</strong>:",G,w,he="<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>",K,y,_e="When the input is <strong>discrete</strong>:",Q,u,ge="<p>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.</p>",Z,k,be="<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>",J,N,X,d,L,ae,z,Te="A 2D Transformer model for image-like data.",ie,p,C,de,A,ve='The <a href="/docs/diffusers/pr_13921/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a> forward method.',Y,H,ee,m,O,le,I,Me='The output of <a href="/docs/diffusers/pr_13921/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a>.',te,P,ne,U,oe;return M=new Ne({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),$=new ce({props:{title:"Transformer2DModel",local:"transformer2dmodel",headingTag:"h1"}}),N=new ce({props:{title:"Transformer2DModel",local:"diffusers.Transformer2DModel",headingTag:"h2"}}),L=new me({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:": int | None = None"},{name:"out_channels",val:": int | None = 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:": int | None = None"},{name:"attention_bias",val:": bool = False"},{name:"sample_size",val:": int | None = None"},{name:"num_vector_embeds",val:": int | None = None"},{name:"patch_size",val:": int | None = None"},{name:"activation_fn",val:": str = 'geglu'"},{name:"num_embeds_ada_norm",val:": int | None = 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:": bool | None = None"}],parametersDescription:[{anchor:"diffusers.Transformer2DModel.num_attention_heads",description:"<strong>num_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to 16) — 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) — 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>) — | |
| 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) — 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) — 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>) — 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>) — 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>) — | |
| 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>"geglu"</code>) — 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>) — | |
| 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>) — | |
| Configure if the <code>TransformerBlocks</code> attention should contain a bias parameter.`,name:"attention_bias"}],source:"https://github.com/huggingface/diffusers/blob/vr_13921/src/diffusers/models/transformers/transformer_2d.py#L39"}}),C=new me({props:{name:"forward",anchor:"diffusers.Transformer2DModel.forward",parameters:[{name:"hidden_states",val:": Tensor"},{name:"encoder_hidden_states",val:": torch.Tensor | None = None"},{name:"timestep",val:": torch.LongTensor | None = None"},{name:"added_cond_kwargs",val:": dict = None"},{name:"class_labels",val:": torch.LongTensor | None = None"},{name:"cross_attention_kwargs",val:": dict = None"},{name:"attention_mask",val:": torch.Tensor | None = None"},{name:"encoder_attention_mask",val:": torch.Tensor | None = 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) — | |
| 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>) — | |
| 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>) — | |
| 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>) — | |
| 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>) — | |
| 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>) — | |
| 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 “discard” tokens.`,name:"attention_mask"},{anchor:"diffusers.Transformer2DModel.forward.encoder_attention_mask",description:`<strong>encoder_attention_mask</strong> ( <code>torch.Tensor</code>, <em>optional</em>) — | |
| 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>) — | |
| Whether or not to return a <a href="/docs/diffusers/pr_13921/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_13921/src/diffusers/models/transformers/transformer_2d.py#L324",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 ce({props:{title:"Transformer2DModelOutput",local:"diffusers.models.modeling_outputs.Transformer2DModelOutput",headingTag:"h2"}}),O=new me({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_13921/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a> is discrete) — | |
| 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_13921/src/diffusers/models/modeling_outputs.py#L21"}}),P=new Le({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/transformer2d.md"}}),{c(){l=a("meta"),j=s(),F=a("p"),S=s(),h(M.$$.fragment),B=s(),h($.$$.fragment),W=s(),D=a("p"),D.innerHTML=ue,R=s(),x=a("p"),x.innerHTML=pe,G=s(),w=a("ol"),w.innerHTML=he,K=s(),y=a("p"),y.innerHTML=_e,Q=s(),u=a("blockquote"),u.innerHTML=ge,Z=s(),k=a("ol"),k.innerHTML=be,J=s(),h(N.$$.fragment),X=s(),d=a("div"),h(L.$$.fragment),ae=s(),z=a("p"),z.textContent=Te,ie=s(),p=a("div"),h(C.$$.fragment),de=s(),A=a("p"),A.innerHTML=ve,Y=s(),h(H.$$.fragment),ee=s(),m=a("div"),h(O.$$.fragment),le=s(),I=a("p"),I.innerHTML=Me,te=s(),h(P.$$.fragment),ne=s(),U=a("p"),this.h()},l(e){const t=ke("svelte-u9bgzb",document.head);l=i(t,"META",{name:!0,content:!0}),t.forEach(n),j=r(e),F=i(e,"P",{}),V(F).forEach(n),S=r(e),_(M.$$.fragment,e),B=r(e),_($.$$.fragment,e),W=r(e),D=i(e,"P",{"data-svelte-h":!0}),c(D)!=="svelte-1s06tdy"&&(D.innerHTML=ue),R=r(e),x=i(e,"P",{"data-svelte-h":!0}),c(x)!=="svelte-ytlpm7"&&(x.innerHTML=pe),G=r(e),w=i(e,"OL",{"data-svelte-h":!0}),c(w)!=="svelte-10ra9yx"&&(w.innerHTML=he),K=r(e),y=i(e,"P",{"data-svelte-h":!0}),c(y)!=="svelte-1wqmwav"&&(y.innerHTML=_e),Q=r(e),u=i(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),c(u)!=="svelte-110unxw"&&(u.innerHTML=ge),Z=r(e),k=i(e,"OL",{"data-svelte-h":!0}),c(k)!=="svelte-m2jel9"&&(k.innerHTML=be),J=r(e),_(N.$$.fragment,e),X=r(e),d=i(e,"DIV",{class:!0});var q=V(d);_(L.$$.fragment,q),ae=r(q),z=i(q,"P",{"data-svelte-h":!0}),c(z)!=="svelte-1dpkeub"&&(z.textContent=Te),ie=r(q),p=i(q,"DIV",{class:!0});var se=V(p);_(C.$$.fragment,se),de=r(se),A=i(se,"P",{"data-svelte-h":!0}),c(A)!=="svelte-1u5w1ua"&&(A.innerHTML=ve),se.forEach(n),q.forEach(n),Y=r(e),_(H.$$.fragment,e),ee=r(e),m=i(e,"DIV",{class:!0});var re=V(m);_(O.$$.fragment,re),le=r(re),I=i(re,"P",{"data-svelte-h":!0}),c(I)!=="svelte-2clpd6"&&(I.innerHTML=Me),re.forEach(n),te=r(e),_(P.$$.fragment,e),ne=r(e),U=i(e,"P",{}),V(U).forEach(n),this.h()},h(){E(l,"name","hf:doc:metadata"),E(l,"content",He),E(u,"class","tip"),E(p,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),E(d,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),E(m,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,t){f(document.head,l),o(e,j,t),o(e,F,t),o(e,S,t),g(M,e,t),o(e,B,t),g($,e,t),o(e,W,t),o(e,D,t),o(e,R,t),o(e,x,t),o(e,G,t),o(e,w,t),o(e,K,t),o(e,y,t),o(e,Q,t),o(e,u,t),o(e,Z,t),o(e,k,t),o(e,J,t),g(N,e,t),o(e,X,t),o(e,d,t),g(L,d,null),f(d,ae),f(d,z),f(d,ie),f(d,p),g(C,p,null),f(p,de),f(p,A),o(e,Y,t),g(H,e,t),o(e,ee,t),o(e,m,t),g(O,m,null),f(m,le),f(m,I),o(e,te,t),g(P,e,t),o(e,ne,t),o(e,U,t),oe=!0},p:De,i(e){oe||(b(M.$$.fragment,e),b($.$$.fragment,e),b(N.$$.fragment,e),b(L.$$.fragment,e),b(C.$$.fragment,e),b(H.$$.fragment,e),b(O.$$.fragment,e),b(P.$$.fragment,e),oe=!0)},o(e){T(M.$$.fragment,e),T($.$$.fragment,e),T(N.$$.fragment,e),T(L.$$.fragment,e),T(C.$$.fragment,e),T(H.$$.fragment,e),T(O.$$.fragment,e),T(P.$$.fragment,e),oe=!1},d(e){e&&(n(j),n(F),n(S),n(B),n(W),n(D),n(R),n(x),n(G),n(w),n(K),n(y),n(Q),n(u),n(Z),n(k),n(J),n(X),n(d),n(Y),n(ee),n(m),n(te),n(ne),n(U)),n(l),v(M,e),v($,e),v(N,e),v(L),v(C),v(H,e),v(O),v(P,e)}}}const He='{"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 Oe(fe){return xe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ee extends we{constructor(l){super(),ye(this,l,Oe,Ce,$e,{})}}export{Ee as component}; | |
Xet Storage Details
- Size:
- 16.4 kB
- Xet hash:
- f96b132e9452d2f550ef52018382984e6622c8a6311af846c49d2ac6afde7174
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.