import{s as he,n as Ae,o as ge}from"../chunks/scheduler.8c3d61f6.js";import{S as Pe,i as Te,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 U,y as f,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 ye}from"../chunks/CodeBlock.00a903b3.js";import{H as ie,E as Me}from"../chunks/EditOnGithub.1e64e623.js";function Se(de){let c,Z,I,z,P,X,T,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.',k,b,le="The abstract from the paper is:",N,y,fe="<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>",R,M,me="The model can be loaded with the following code snippet.",j,S,O,v,K,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.",B,F,q,l,w,ne,J,_e='The output of <a href="/docs/diffusers/pr_10037/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a>.',W,x,Y,H,Q;return P=new ie({props:{title:"SanaTransformer2DModel",local:"sanatransformer2dmodel",headingTag:"h1"}}),S=new ye({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFNhbmFUcmFuc2Zvcm1lcjJETW9kZWwlMEElMEF0cmFuc2Zvcm1lciUyMCUzRCUyMFNhbmFUcmFuc2Zvcm1lcjJETW9kZWwuZnJvbV9wcmV0cmFpbmVkKCUyMkVmZmljaWVudC1MYXJnZS1Nb2RlbCUyRlNhbmFfMTYwME1fMTAyNHB4X0JGMTZfZGlmZnVzZXJzJTIyJTJDJTIwc3ViZm9sZGVyJTNEJTIydHJhbnNmb3JtZXIlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2KQ==",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_BF16_diffusers&quot;</span>, subfolder=<span class="hljs-string">&quot;transformer&quot;</span>, torch_dtype=torch.bfloat16)`,wrap:!1}}),v=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"},{name:"interpolation_scale",val:": typing.Optional[int] = None"}],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_10037/src/diffusers/models/transformers/sana_transformer.py#L184"}}),$=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.MochiAttnProcessor2_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.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.SD3IPAdapterJointAttnProcessor2_0, 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.MochiAttnProcessor2_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.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.SD3IPAdapterJointAttnProcessor2_0, 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_10037/src/diffusers/models/transformers/sana_transformer.py#L327"}}),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_10037/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_10037/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"),Z=r(),I=a("p"),z=r(),u(P.$$.fragment),X=r(),T=a("p"),T.innerHTML=ce,k=r(),b=a("p"),b.textContent=le,N=r(),y=a("p"),y.innerHTML=fe,R=r(),M=a("p"),M.textContent=me,j=r(),u(S.$$.fragment),O=r(),u(v.$$.fragment),K=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,B=r(),u(F.$$.fragment),q=r(),l=a("div"),u(w.$$.fragment),ne=r(),J=a("p"),J.innerHTML=_e,W=r(),u(x.$$.fragment),Y=r(),H=a("p"),this.h()},l(e){const s=be("svelte-u9bgzb",document.head);c=i(s,"META",{name:!0,content:!0}),s.forEach(o),Z=n(e),I=i(e,"P",{}),E(I).forEach(o),z=n(e),p(P.$$.fragment,e),X=n(e),T=i(e,"P",{"data-svelte-h":!0}),C(T)!=="svelte-1hitpek"&&(T.innerHTML=ce),k=n(e),b=i(e,"P",{"data-svelte-h":!0}),C(b)!=="svelte-1cwsb16"&&(b.textContent=le),N=n(e),y=i(e,"P",{"data-svelte-h":!0}),C(y)!=="svelte-1uh3w7a"&&(y.innerHTML=fe),R=n(e),M=i(e,"P",{"data-svelte-h":!0}),C(M)!=="svelte-1vuni30"&&(M.textContent=me),j=n(e),p(S.$$.fragment,e),O=n(e),p(v.$$.fragment,e),K=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),B=n(e),p(F.$$.fragment,e),q=n(e),l=i(e,"DIV",{class:!0});var se=E(l);p(w.$$.fragment,se),ne=n(se),J=i(se,"P",{"data-svelte-h":!0}),C(J)!=="svelte-1netq91"&&(J.innerHTML=_e),se.forEach(o),W=n(e),p(x.$$.fragment,e),Y=n(e),H=i(e,"P",{}),E(H).forEach(o),this.h()},h(){U(c,"name","hf:doc:metadata"),U(c,"content",ve),U(m,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),U(d,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),U(l,"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){f(document.head,c),t(e,Z,s),t(e,I,s),t(e,z,s),_(P,e,s),t(e,X,s),t(e,T,s),t(e,k,s),t(e,b,s),t(e,N,s),t(e,y,s),t(e,R,s),t(e,M,s),t(e,j,s),_(S,e,s),t(e,O,s),_(v,e,s),t(e,K,s),t(e,d,s),_(D,d,null),f(d,oe),f(d,L),f(d,te),f(d,m),_($,m,null),f(m,re),f(m,G),t(e,B,s),_(F,e,s),t(e,q,s),t(e,l,s),_(w,l,null),f(l,ne),f(l,J),t(e,W,s),_(x,e,s),t(e,Y,s),t(e,H,s),Q=!0},p:Ae,i(e){Q||(h(P.$$.fragment,e),h(S.$$.fragment,e),h(v.$$.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(S.$$.fragment,e),A(v.$$.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(Z),o(I),o(z),o(X),o(T),o(k),o(b),o(N),o(y),o(R),o(M),o(j),o(O),o(K),o(d),o(B),o(q),o(l),o(W),o(Y),o(H)),o(c),g(P,e),g(S,e),g(v,e),g(D),g($),g(F,e),g(w),g(x,e)}}}const ve='{"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(),Te(this,c,De,Se,he,{})}}export{Le as component};
