import{s as ce,n as fe,o as ue}from"../chunks/scheduler.53228c21.js";import{S as pe,i as he,e as r,s as a,c,h as _e,a as i,d as t,b as s,f as K,g as f,j as z,k as Q,l as F,m as o,n as u,t as p,o as h,p as _}from"../chunks/index.100fac89.js";import{C as ge}from"../chunks/CopyLLMTxtMenu.20a72e0e.js";import{D as me}from"../chunks/Docstring.49101787.js";import{C as Te}from"../chunks/CodeBlock.d30a6509.js";import{H as te,E as be}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.4d82655d.js";function Me(oe){let l,H,E,J,g,P,T,U,b,ae='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.',N,M,se="The abstract from the paper is:",O,y,re="<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>",j,$,ie="The model can be loaded with the following code snippet.",q,v,G,D,I,d,w,ee,L,le='A 2D Transformer model introduced in <a href="https://huggingface.co/papers/2410.10629" rel="nofollow">Sana</a> family of models.',V,x,A,m,S,ne,k,de='The output of <a href="/docs/diffusers/main/en/api/models/transformer2d#diffusers.Transformer2DModel">Transformer2DModel</a>.',B,C,R,Z,W;return g=new ge({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),T=new te({props:{title:"SanaTransformer2DModel",local:"sanatransformer2dmodel",headingTag:"h1"}}),v=new Te({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}}),D=new te({props:{title:"SanaTransformer2DModel",local:"diffusers.SanaTransformer2DModel",headingTag:"h2"}}),w=new me({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"},{name:"guidance_embeds",val:": bool = False"},{name:"guidance_embeds_scale",val:": float = 0.1"},{name:"qk_norm",val:": typing.Optional[str] = None"},{name:"timestep_scale",val:": float = 1.0"}],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"},{anchor:"diffusers.SanaTransformer2DModel.qk_norm",description:`<strong>qk_norm</strong> (<code>str</code>, <em>optional</em>, defaults to <code>None</code>) &#x2014;
The normalization to use for the query and key.`,name:"qk_norm"},{anchor:"diffusers.SanaTransformer2DModel.timestep_scale",description:`<strong>timestep_scale</strong> (<code>float</code>, defaults to <code>1.0</code>) &#x2014;
The scale to use for the timesteps.`,name:"timestep_scale"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/transformers/sana_transformer.py#L292"}}),x=new te({props:{title:"Transformer2DModelOutput",local:"diffusers.models.modeling_outputs.Transformer2DModelOutput",headingTag:"h2"}}),S=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/main/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/main/src/diffusers/models/modeling_outputs.py#L21"}}),C=new be({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/sana_transformer2d.md"}}),{c(){l=r("meta"),H=a(),E=r("p"),J=a(),c(g.$$.fragment),P=a(),c(T.$$.fragment),U=a(),b=r("p"),b.innerHTML=ae,N=a(),M=r("p"),M.textContent=se,O=a(),y=r("p"),y.innerHTML=re,j=a(),$=r("p"),$.textContent=ie,q=a(),c(v.$$.fragment),G=a(),c(D.$$.fragment),I=a(),d=r("div"),c(w.$$.fragment),ee=a(),L=r("p"),L.innerHTML=le,V=a(),c(x.$$.fragment),A=a(),m=r("div"),c(S.$$.fragment),ne=a(),k=r("p"),k.innerHTML=de,B=a(),c(C.$$.fragment),R=a(),Z=r("p"),this.h()},l(e){const n=_e("svelte-u9bgzb",document.head);l=i(n,"META",{name:!0,content:!0}),n.forEach(t),H=s(e),E=i(e,"P",{}),K(E).forEach(t),J=s(e),f(g.$$.fragment,e),P=s(e),f(T.$$.fragment,e),U=s(e),b=i(e,"P",{"data-svelte-h":!0}),z(b)!=="svelte-1hitpek"&&(b.innerHTML=ae),N=s(e),M=i(e,"P",{"data-svelte-h":!0}),z(M)!=="svelte-1cwsb16"&&(M.textContent=se),O=s(e),y=i(e,"P",{"data-svelte-h":!0}),z(y)!=="svelte-1uh3w7a"&&(y.innerHTML=re),j=s(e),$=i(e,"P",{"data-svelte-h":!0}),z($)!=="svelte-1vuni30"&&($.textContent=ie),q=s(e),f(v.$$.fragment,e),G=s(e),f(D.$$.fragment,e),I=s(e),d=i(e,"DIV",{class:!0});var X=K(d);f(w.$$.fragment,X),ee=s(X),L=i(X,"P",{"data-svelte-h":!0}),z(L)!=="svelte-1n205fh"&&(L.innerHTML=le),X.forEach(t),V=s(e),f(x.$$.fragment,e),A=s(e),m=i(e,"DIV",{class:!0});var Y=K(m);f(S.$$.fragment,Y),ne=s(Y),k=i(Y,"P",{"data-svelte-h":!0}),z(k)!=="svelte-1x8c0js"&&(k.innerHTML=de),Y.forEach(t),B=s(e),f(C.$$.fragment,e),R=s(e),Z=i(e,"P",{}),K(Z).forEach(t),this.h()},h(){Q(l,"name","hf:doc:metadata"),Q(l,"content",ye),Q(d,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Q(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,n){F(document.head,l),o(e,H,n),o(e,E,n),o(e,J,n),u(g,e,n),o(e,P,n),u(T,e,n),o(e,U,n),o(e,b,n),o(e,N,n),o(e,M,n),o(e,O,n),o(e,y,n),o(e,j,n),o(e,$,n),o(e,q,n),u(v,e,n),o(e,G,n),u(D,e,n),o(e,I,n),o(e,d,n),u(w,d,null),F(d,ee),F(d,L),o(e,V,n),u(x,e,n),o(e,A,n),o(e,m,n),u(S,m,null),F(m,ne),F(m,k),o(e,B,n),u(C,e,n),o(e,R,n),o(e,Z,n),W=!0},p:fe,i(e){W||(p(g.$$.fragment,e),p(T.$$.fragment,e),p(v.$$.fragment,e),p(D.$$.fragment,e),p(w.$$.fragment,e),p(x.$$.fragment,e),p(S.$$.fragment,e),p(C.$$.fragment,e),W=!0)},o(e){h(g.$$.fragment,e),h(T.$$.fragment,e),h(v.$$.fragment,e),h(D.$$.fragment,e),h(w.$$.fragment,e),h(x.$$.fragment,e),h(S.$$.fragment,e),h(C.$$.fragment,e),W=!1},d(e){e&&(t(H),t(E),t(J),t(P),t(U),t(b),t(N),t(M),t(O),t(y),t(j),t($),t(q),t(G),t(I),t(d),t(V),t(A),t(m),t(B),t(R),t(Z)),t(l),_(g,e),_(T,e),_(v,e),_(D,e),_(w),_(x,e),_(S),_(C,e)}}}const ye='{"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 $e(oe){return ue(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Le extends pe{constructor(l){super(),he(this,l,$e,Me,ce,{})}}export{Le as component};
