import{s as he,n as Ae,o as ge}from"../chunks/scheduler.8c3d61f6.js";import{S as Pe,i as ye,g as a,s as r,r as u,A as be,h as i,f as o,c as n,j as E,u as p,x as C,k as z,y as l,a as t,v as _,d as h,t as A,w as g}from"../chunks/index.da70eac4.js";import{D as ae}from"../chunks/Docstring.6b390b9a.js";import{C as Te}from"../chunks/CodeBlock.00a903b3.js";import{H as ie,E as Me}from"../chunks/EditOnGithub.1e64e623.js";function ve(de){let c,J,H,R,P,X,y,ce='A Diffusion Transformer model for 2D data from <a href="https://huggingface.co/papers/2410.10629" rel="nofollow">SANA: Efficient High-Resolution Image Synthesis with Linear Diffusion Transformers</a> was introduced from NVIDIA and MIT HAN Lab, by Enze Xie, Junsong Chen, Junyu Chen, Han Cai, Haotian Tang, Yujun Lin, Zhekai Zhang, Muyang Li, Ligeng Zhu, Yao Lu, Song Han.',Z,b,fe="The abstract from the paper is:",k,T,le="<em>We introduce Sana, a text-to-image framework that can efficiently generate images up to 4096×4096 resolution. Sana can synthesize high-resolution, high-quality images with strong text-image alignment at a remarkably fast speed, deployable on laptop GPU. Core designs include: (1) Deep compression autoencoder: unlike traditional AEs, which compress images only 8×, we trained an AE that can compress images 32×, effectively reducing the number of latent tokens. (2) Linear DiT: we replace all vanilla attention in DiT with linear attention, which is more efficient at high resolutions without sacrificing quality. (3) Decoder-only text encoder: we replaced T5 with modern decoder-only small LLM as the text encoder and designed complex human instruction with in-context learning to enhance the image-text alignment. (4) Efficient training and sampling: we propose Flow-DPM-Solver to reduce sampling steps, with efficient caption labeling and selection to accelerate convergence. As a result, Sana-0.6B is very competitive with modern giant diffusion model (e.g. Flux-12B), being 20 times smaller and 100+ times faster in measured throughput. Moreover, Sana-0.6B can be deployed on a 16GB laptop GPU, taking less than 1 second to generate a 1024×1024 resolution image. Sana enables content creation at low cost. Code and model will be publicly released.</em>",N,M,me="The model can be loaded with the following code snippet.",j,v,K,S,O,d,D,oe,L,ue='A 2D Transformer model introduced in <a href="https://huggingface.co/papers/2410.10629" rel="nofollow">Sana</a> family of models.',te,m,$,re,G,pe="Sets the attention processor to use to compute attention.",W,F,q,f,w,ne,U,_e='The output of <a href="/docs/diffusers/pr_10136/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a>.',B,x,Y,I,Q;return P=new ie({props:{title:"SanaTransformer2DModel",local:"sanatransformer2dmodel",headingTag:"h1"}}),v=new Te({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFNhbmFUcmFuc2Zvcm1lcjJETW9kZWwlMEElMEF0cmFuc2Zvcm1lciUyMCUzRCUyMFNhbmFUcmFuc2Zvcm1lcjJETW9kZWwuZnJvbV9wcmV0cmFpbmVkKCUyMkVmZmljaWVudC1MYXJnZS1Nb2RlbCUyRlNhbmFfMTYwME1fMTAyNHB4X2RpZmZ1c2VycyUyMiUyQyUyMHN1YmZvbGRlciUzRCUyMnRyYW5zZm9ybWVyJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2KQ==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> SanaTransformer2DModel

transformer = SanaTransformer2DModel.from_pretrained(<span class="hljs-string">&quot;Efficient-Large-Model/Sana_1600M_1024px_diffusers&quot;</span>, subfolder=<span class="hljs-string">&quot;transformer&quot;</span>, torch_dtype=torch.float16)`,wrap:!1}}),S=new ie({props:{title:"SanaTransformer2DModel",local:"diffusers.SanaTransformer2DModel",headingTag:"h2"}}),D=new ae({props:{name:"class diffusers.SanaTransformer2DModel",anchor:"diffusers.SanaTransformer2DModel",parameters:[{name:"in_channels",val:": int = 32"},{name:"out_channels",val:": typing.Optional[int] = 32"},{name:"num_attention_heads",val:": int = 70"},{name:"attention_head_dim",val:": int = 32"},{name:"num_layers",val:": int = 20"},{name:"num_cross_attention_heads",val:": typing.Optional[int] = 20"},{name:"cross_attention_head_dim",val:": typing.Optional[int] = 112"},{name:"cross_attention_dim",val:": typing.Optional[int] = 2240"},{name:"caption_channels",val:": int = 2304"},{name:"mlp_ratio",val:": float = 2.5"},{name:"dropout",val:": float = 0.0"},{name:"attention_bias",val:": bool = False"},{name:"sample_size",val:": int = 32"},{name:"patch_size",val:": int = 1"},{name:"norm_elementwise_affine",val:": bool = False"},{name:"norm_eps",val:": float = 1e-06"}],parametersDescription:[{anchor:"diffusers.SanaTransformer2DModel.in_channels",description:`<strong>in_channels</strong> (<code>int</code>, defaults to <code>32</code>) &#x2014;
The number of channels in the input.`,name:"in_channels"},{anchor:"diffusers.SanaTransformer2DModel.out_channels",description:`<strong>out_channels</strong> (<code>int</code>, <em>optional</em>, defaults to <code>32</code>) &#x2014;
The number of channels in the output.`,name:"out_channels"},{anchor:"diffusers.SanaTransformer2DModel.num_attention_heads",description:`<strong>num_attention_heads</strong> (<code>int</code>, defaults to <code>70</code>) &#x2014;
The number of heads to use for multi-head attention.`,name:"num_attention_heads"},{anchor:"diffusers.SanaTransformer2DModel.attention_head_dim",description:`<strong>attention_head_dim</strong> (<code>int</code>, defaults to <code>32</code>) &#x2014;
The number of channels in each head.`,name:"attention_head_dim"},{anchor:"diffusers.SanaTransformer2DModel.num_layers",description:`<strong>num_layers</strong> (<code>int</code>, defaults to <code>20</code>) &#x2014;
The number of layers of Transformer blocks to use.`,name:"num_layers"},{anchor:"diffusers.SanaTransformer2DModel.num_cross_attention_heads",description:`<strong>num_cross_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to <code>20</code>) &#x2014;
The number of heads to use for cross-attention.`,name:"num_cross_attention_heads"},{anchor:"diffusers.SanaTransformer2DModel.cross_attention_head_dim",description:`<strong>cross_attention_head_dim</strong> (<code>int</code>, <em>optional</em>, defaults to <code>112</code>) &#x2014;
The number of channels in each head for cross-attention.`,name:"cross_attention_head_dim"},{anchor:"diffusers.SanaTransformer2DModel.cross_attention_dim",description:`<strong>cross_attention_dim</strong> (<code>int</code>, <em>optional</em>, defaults to <code>2240</code>) &#x2014;
The number of channels in the cross-attention output.`,name:"cross_attention_dim"},{anchor:"diffusers.SanaTransformer2DModel.caption_channels",description:`<strong>caption_channels</strong> (<code>int</code>, defaults to <code>2304</code>) &#x2014;
The number of channels in the caption embeddings.`,name:"caption_channels"},{anchor:"diffusers.SanaTransformer2DModel.mlp_ratio",description:`<strong>mlp_ratio</strong> (<code>float</code>, defaults to <code>2.5</code>) &#x2014;
The expansion ratio to use in the GLUMBConv layer.`,name:"mlp_ratio"},{anchor:"diffusers.SanaTransformer2DModel.dropout",description:`<strong>dropout</strong> (<code>float</code>, defaults to <code>0.0</code>) &#x2014;
The dropout probability.`,name:"dropout"},{anchor:"diffusers.SanaTransformer2DModel.attention_bias",description:`<strong>attention_bias</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Whether to use bias in the attention layer.`,name:"attention_bias"},{anchor:"diffusers.SanaTransformer2DModel.sample_size",description:`<strong>sample_size</strong> (<code>int</code>, defaults to <code>32</code>) &#x2014;
The base size of the input latent.`,name:"sample_size"},{anchor:"diffusers.SanaTransformer2DModel.patch_size",description:`<strong>patch_size</strong> (<code>int</code>, defaults to <code>1</code>) &#x2014;
The size of the patches to use in the patch embedding layer.`,name:"patch_size"},{anchor:"diffusers.SanaTransformer2DModel.norm_elementwise_affine",description:`<strong>norm_elementwise_affine</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Whether to use elementwise affinity in the normalization layer.`,name:"norm_elementwise_affine"},{anchor:"diffusers.SanaTransformer2DModel.norm_eps",description:`<strong>norm_eps</strong> (<code>float</code>, defaults to <code>1e-6</code>) &#x2014;
The epsilon value for the normalization layer.`,name:"norm_eps"}],source:"https://github.com/huggingface/diffusers/blob/vr_10136/src/diffusers/models/transformers/sana_transformer.py#L183"}}),$=new ae({props:{name:"set_attn_processor",anchor:"diffusers.SanaTransformer2DModel.set_attn_processor",parameters:[{name:"processor",val:": typing.Union[diffusers.models.attention_processor.AttnProcessor, diffusers.models.attention_processor.CustomDiffusionAttnProcessor, diffusers.models.attention_processor.AttnAddedKVProcessor, diffusers.models.attention_processor.AttnAddedKVProcessor2_0, diffusers.models.attention_processor.JointAttnProcessor2_0, diffusers.models.attention_processor.PAGJointAttnProcessor2_0, diffusers.models.attention_processor.PAGCFGJointAttnProcessor2_0, diffusers.models.attention_processor.FusedJointAttnProcessor2_0, diffusers.models.attention_processor.AllegroAttnProcessor2_0, diffusers.models.attention_processor.AuraFlowAttnProcessor2_0, diffusers.models.attention_processor.FusedAuraFlowAttnProcessor2_0, diffusers.models.attention_processor.FluxAttnProcessor2_0, diffusers.models.attention_processor.FluxAttnProcessor2_0_NPU, diffusers.models.attention_processor.FusedFluxAttnProcessor2_0, diffusers.models.attention_processor.FusedFluxAttnProcessor2_0_NPU, diffusers.models.attention_processor.CogVideoXAttnProcessor2_0, diffusers.models.attention_processor.FusedCogVideoXAttnProcessor2_0, diffusers.models.attention_processor.XFormersAttnAddedKVProcessor, diffusers.models.attention_processor.XFormersAttnProcessor, diffusers.models.attention_processor.XLAFlashAttnProcessor2_0, diffusers.models.attention_processor.AttnProcessorNPU, diffusers.models.attention_processor.AttnProcessor2_0, diffusers.models.attention_processor.MochiVaeAttnProcessor2_0, diffusers.models.attention_processor.StableAudioAttnProcessor2_0, diffusers.models.attention_processor.HunyuanAttnProcessor2_0, diffusers.models.attention_processor.FusedHunyuanAttnProcessor2_0, diffusers.models.attention_processor.PAGHunyuanAttnProcessor2_0, diffusers.models.attention_processor.PAGCFGHunyuanAttnProcessor2_0, diffusers.models.attention_processor.LuminaAttnProcessor2_0, diffusers.models.attention_processor.MochiAttnProcessor2_0, diffusers.models.attention_processor.FusedAttnProcessor2_0, diffusers.models.attention_processor.CustomDiffusionXFormersAttnProcessor, diffusers.models.attention_processor.CustomDiffusionAttnProcessor2_0, diffusers.models.attention_processor.SlicedAttnProcessor, diffusers.models.attention_processor.SlicedAttnAddedKVProcessor, diffusers.models.attention_processor.SanaLinearAttnProcessor2_0, diffusers.models.attention_processor.PAGCFGSanaLinearAttnProcessor2_0, diffusers.models.attention_processor.PAGIdentitySanaLinearAttnProcessor2_0, diffusers.models.attention_processor.SanaMultiscaleLinearAttention, diffusers.models.attention_processor.SanaMultiscaleAttnProcessor2_0, diffusers.models.attention_processor.SanaMultiscaleAttentionProjection, diffusers.models.attention_processor.IPAdapterAttnProcessor, diffusers.models.attention_processor.IPAdapterAttnProcessor2_0, diffusers.models.attention_processor.IPAdapterXFormersAttnProcessor, diffusers.models.attention_processor.PAGIdentitySelfAttnProcessor2_0, diffusers.models.attention_processor.PAGCFGIdentitySelfAttnProcessor2_0, diffusers.models.attention_processor.LoRAAttnProcessor, diffusers.models.attention_processor.LoRAAttnProcessor2_0, diffusers.models.attention_processor.LoRAXFormersAttnProcessor, diffusers.models.attention_processor.LoRAAttnAddedKVProcessor, typing.Dict[str, typing.Union[diffusers.models.attention_processor.AttnProcessor, diffusers.models.attention_processor.CustomDiffusionAttnProcessor, diffusers.models.attention_processor.AttnAddedKVProcessor, diffusers.models.attention_processor.AttnAddedKVProcessor2_0, diffusers.models.attention_processor.JointAttnProcessor2_0, diffusers.models.attention_processor.PAGJointAttnProcessor2_0, diffusers.models.attention_processor.PAGCFGJointAttnProcessor2_0, diffusers.models.attention_processor.FusedJointAttnProcessor2_0, diffusers.models.attention_processor.AllegroAttnProcessor2_0, diffusers.models.attention_processor.AuraFlowAttnProcessor2_0, diffusers.models.attention_processor.FusedAuraFlowAttnProcessor2_0, diffusers.models.attention_processor.FluxAttnProcessor2_0, diffusers.models.attention_processor.FluxAttnProcessor2_0_NPU, diffusers.models.attention_processor.FusedFluxAttnProcessor2_0, diffusers.models.attention_processor.FusedFluxAttnProcessor2_0_NPU, diffusers.models.attention_processor.CogVideoXAttnProcessor2_0, diffusers.models.attention_processor.FusedCogVideoXAttnProcessor2_0, diffusers.models.attention_processor.XFormersAttnAddedKVProcessor, diffusers.models.attention_processor.XFormersAttnProcessor, diffusers.models.attention_processor.XLAFlashAttnProcessor2_0, diffusers.models.attention_processor.AttnProcessorNPU, diffusers.models.attention_processor.AttnProcessor2_0, diffusers.models.attention_processor.MochiVaeAttnProcessor2_0, diffusers.models.attention_processor.StableAudioAttnProcessor2_0, diffusers.models.attention_processor.HunyuanAttnProcessor2_0, diffusers.models.attention_processor.FusedHunyuanAttnProcessor2_0, diffusers.models.attention_processor.PAGHunyuanAttnProcessor2_0, diffusers.models.attention_processor.PAGCFGHunyuanAttnProcessor2_0, diffusers.models.attention_processor.LuminaAttnProcessor2_0, diffusers.models.attention_processor.MochiAttnProcessor2_0, diffusers.models.attention_processor.FusedAttnProcessor2_0, diffusers.models.attention_processor.CustomDiffusionXFormersAttnProcessor, diffusers.models.attention_processor.CustomDiffusionAttnProcessor2_0, diffusers.models.attention_processor.SlicedAttnProcessor, diffusers.models.attention_processor.SlicedAttnAddedKVProcessor, diffusers.models.attention_processor.SanaLinearAttnProcessor2_0, diffusers.models.attention_processor.PAGCFGSanaLinearAttnProcessor2_0, diffusers.models.attention_processor.PAGIdentitySanaLinearAttnProcessor2_0, diffusers.models.attention_processor.SanaMultiscaleLinearAttention, diffusers.models.attention_processor.SanaMultiscaleAttnProcessor2_0, diffusers.models.attention_processor.SanaMultiscaleAttentionProjection, diffusers.models.attention_processor.IPAdapterAttnProcessor, diffusers.models.attention_processor.IPAdapterAttnProcessor2_0, diffusers.models.attention_processor.IPAdapterXFormersAttnProcessor, diffusers.models.attention_processor.PAGIdentitySelfAttnProcessor2_0, diffusers.models.attention_processor.PAGCFGIdentitySelfAttnProcessor2_0, diffusers.models.attention_processor.LoRAAttnProcessor, diffusers.models.attention_processor.LoRAAttnProcessor2_0, diffusers.models.attention_processor.LoRAXFormersAttnProcessor, diffusers.models.attention_processor.LoRAAttnAddedKVProcessor]]]"}],parametersDescription:[{anchor:"diffusers.SanaTransformer2DModel.set_attn_processor.processor",description:`<strong>processor</strong> (<code>dict</code> of <code>AttentionProcessor</code> or only <code>AttentionProcessor</code>) &#x2014;
The instantiated processor class or a dictionary of processor classes that will be set as the processor
for <strong>all</strong> <code>Attention</code> layers.</p>
<p>If <code>processor</code> is a dict, the key needs to define the path to the corresponding cross attention
processor. This is strongly recommended when setting trainable attention processors.`,name:"processor"}],source:"https://github.com/huggingface/diffusers/blob/vr_10136/src/diffusers/models/transformers/sana_transformer.py#L325"}}),F=new ie({props:{title:"Transformer2DModelOutput",local:"diffusers.models.modeling_outputs.Transformer2DModelOutput",headingTag:"h2"}}),w=new ae({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_10136/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_10136/src/diffusers/models/modeling_outputs.py#L20"}}),x=new Me({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/sana_transformer2d.md"}}),{c(){c=a("meta"),J=r(),H=a("p"),R=r(),u(P.$$.fragment),X=r(),y=a("p"),y.innerHTML=ce,Z=r(),b=a("p"),b.textContent=fe,k=r(),T=a("p"),T.innerHTML=le,N=r(),M=a("p"),M.textContent=me,j=r(),u(v.$$.fragment),K=r(),u(S.$$.fragment),O=r(),d=a("div"),u(D.$$.fragment),oe=r(),L=a("p"),L.innerHTML=ue,te=r(),m=a("div"),u($.$$.fragment),re=r(),G=a("p"),G.textContent=pe,W=r(),u(F.$$.fragment),q=r(),f=a("div"),u(w.$$.fragment),ne=r(),U=a("p"),U.innerHTML=_e,B=r(),u(x.$$.fragment),Y=r(),I=a("p"),this.h()},l(e){const s=be("svelte-u9bgzb",document.head);c=i(s,"META",{name:!0,content:!0}),s.forEach(o),J=n(e),H=i(e,"P",{}),E(H).forEach(o),R=n(e),p(P.$$.fragment,e),X=n(e),y=i(e,"P",{"data-svelte-h":!0}),C(y)!=="svelte-1hitpek"&&(y.innerHTML=ce),Z=n(e),b=i(e,"P",{"data-svelte-h":!0}),C(b)!=="svelte-1cwsb16"&&(b.textContent=fe),k=n(e),T=i(e,"P",{"data-svelte-h":!0}),C(T)!=="svelte-1uh3w7a"&&(T.innerHTML=le),N=n(e),M=i(e,"P",{"data-svelte-h":!0}),C(M)!=="svelte-1vuni30"&&(M.textContent=me),j=n(e),p(v.$$.fragment,e),K=n(e),p(S.$$.fragment,e),O=n(e),d=i(e,"DIV",{class:!0});var V=E(d);p(D.$$.fragment,V),oe=n(V),L=i(V,"P",{"data-svelte-h":!0}),C(L)!=="svelte-1n205fh"&&(L.innerHTML=ue),te=n(V),m=i(V,"DIV",{class:!0});var ee=E(m);p($.$$.fragment,ee),re=n(ee),G=i(ee,"P",{"data-svelte-h":!0}),C(G)!=="svelte-1o77hl2"&&(G.textContent=pe),ee.forEach(o),V.forEach(o),W=n(e),p(F.$$.fragment,e),q=n(e),f=i(e,"DIV",{class:!0});var se=E(f);p(w.$$.fragment,se),ne=n(se),U=i(se,"P",{"data-svelte-h":!0}),C(U)!=="svelte-1lq1m3h"&&(U.innerHTML=_e),se.forEach(o),B=n(e),p(x.$$.fragment,e),Y=n(e),I=i(e,"P",{}),E(I).forEach(o),this.h()},h(){z(c,"name","hf:doc:metadata"),z(c,"content",Se),z(m,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),z(d,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),z(f,"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,s){l(document.head,c),t(e,J,s),t(e,H,s),t(e,R,s),_(P,e,s),t(e,X,s),t(e,y,s),t(e,Z,s),t(e,b,s),t(e,k,s),t(e,T,s),t(e,N,s),t(e,M,s),t(e,j,s),_(v,e,s),t(e,K,s),_(S,e,s),t(e,O,s),t(e,d,s),_(D,d,null),l(d,oe),l(d,L),l(d,te),l(d,m),_($,m,null),l(m,re),l(m,G),t(e,W,s),_(F,e,s),t(e,q,s),t(e,f,s),_(w,f,null),l(f,ne),l(f,U),t(e,B,s),_(x,e,s),t(e,Y,s),t(e,I,s),Q=!0},p:Ae,i(e){Q||(h(P.$$.fragment,e),h(v.$$.fragment,e),h(S.$$.fragment,e),h(D.$$.fragment,e),h($.$$.fragment,e),h(F.$$.fragment,e),h(w.$$.fragment,e),h(x.$$.fragment,e),Q=!0)},o(e){A(P.$$.fragment,e),A(v.$$.fragment,e),A(S.$$.fragment,e),A(D.$$.fragment,e),A($.$$.fragment,e),A(F.$$.fragment,e),A(w.$$.fragment,e),A(x.$$.fragment,e),Q=!1},d(e){e&&(o(J),o(H),o(R),o(X),o(y),o(Z),o(b),o(k),o(T),o(N),o(M),o(j),o(K),o(O),o(d),o(W),o(q),o(f),o(B),o(Y),o(I)),o(c),g(P,e),g(v,e),g(S,e),g(D),g($),g(F,e),g(w),g(x,e)}}}const Se='{"title":"SanaTransformer2DModel","local":"sanatransformer2dmodel","sections":[{"title":"SanaTransformer2DModel","local":"diffusers.SanaTransformer2DModel","sections":[],"depth":2},{"title":"Transformer2DModelOutput","local":"diffusers.models.modeling_outputs.Transformer2DModelOutput","sections":[],"depth":2}],"depth":1}';function De(de){return ge(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Le extends Pe{constructor(c){super(),ye(this,c,De,ve,he,{})}}export{Le as component};
