import{S as ba,i as wa,s as Da,e as r,k as l,w as y,t as f,M as ya,c as s,d as a,m as p,a as i,x as T,h as d,b as o,G as t,g as c,y as $,L as Ta,q as P,o as E,B as k,v as $a}from"../../../chunks/vendor-hf-doc-builder.js";import{D as Gt}from"../../../chunks/Docstring-hf-doc-builder.js";import{C as Pa}from"../../../chunks/CodeBlock-hf-doc-builder.js";import{I as Ee}from"../../../chunks/IconCopyLink-hf-doc-builder.js";function Ea(Wt){let u,ke,m,x,oe,G,Ye,ne,Qe,xe,g,S,le,W,Ze,pe,et,Se,H,U,tt,at,Ae,Z,rt,Ie,ee,fe,st,Me,A,it,O,ot,nt,Ne,_,I,de,F,lt,ce,pt,Le,M,he,v,ue,ft,dt,me,ct,ht,te,ut,mt,ge,b,_e,X,gt,_t,ve,be,vt,bt,ae,wt,Ce,w,N,we,V,Dt,De,yt,je,B,qe,D,L,ye,K,Tt,Te,$t,Ge,h,R,Pt,z,Et,re,kt,xt,St,C,J,At,$e,It,Mt,j,Y,Nt,Q,Lt,Pe,Ct,jt,We;return G=new Ee({}),W=new Ee({}),F=new Ee({}),V=new Ee({}),B=new Pa({props:{code:`from diffusers import DiTPipeline, DPMSolverMultistepScheduler
import torch

pipe = DiTPipeline.from_pretrained("facebook/DiT-XL-2-256", torch_dtype=torch.float16)
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
pipe = pipe.to("cuda")

# pick words from Imagenet class labels
pipe.labels  # to print all available words

# pick words that exist in ImageNet
words = ["white shark", "umbrella"]

class_ids = pipe.get_label_ids(words)

generator = torch.manual_seed(33)
output = pipe(class_labels=class_ids, num_inference_steps=25, generator=generator)

image = output.images[0]  # label 'white shark'`,highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiTPipeline, DPMSolverMultistepScheduler
<span class="hljs-keyword">import</span> torch

pipe = DiTPipeline.from_pretrained(<span class="hljs-string">&quot;facebook/DiT-XL-2-256&quot;</span>, torch_dtype=torch.float16)
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
pipe = pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-comment"># pick words from Imagenet class labels</span>
pipe.labels  <span class="hljs-comment"># to print all available words</span>

<span class="hljs-comment"># pick words that exist in ImageNet</span>
words = [<span class="hljs-string">&quot;white shark&quot;</span>, <span class="hljs-string">&quot;umbrella&quot;</span>]

class_ids = pipe.get_label_ids(words)

generator = torch.manual_seed(<span class="hljs-number">33</span>)
output = pipe(class_labels=class_ids, num_inference_steps=<span class="hljs-number">25</span>, generator=generator)

image = output.images[<span class="hljs-number">0</span>]  <span class="hljs-comment"># label &#x27;white shark&#x27;</span>`}}),K=new Ee({}),R=new Gt({props:{name:"class diffusers.DiTPipeline",anchor:"diffusers.DiTPipeline",parameters:[{name:"transformer",val:": Transformer2DModel"},{name:"vae",val:": AutoencoderKL"},{name:"scheduler",val:": KarrasDiffusionSchedulers"},{name:"id2label",val:": typing.Union[typing.Dict[int, str], NoneType] = None"}],parametersDescription:[{anchor:"diffusers.DiTPipeline.transformer",description:`<strong>transformer</strong> (<a href="/docs/diffusers/main/en/api/models#diffusers.Transformer2DModel">Transformer2DModel</a>) &#x2014;
Class conditioned Transformer in Diffusion model to denoise the encoded image latents.`,name:"transformer"},{anchor:"diffusers.DiTPipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/main/en/api/models#diffusers.AutoencoderKL">AutoencoderKL</a>) &#x2014;
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.`,name:"vae"},{anchor:"diffusers.DiTPipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/main/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>) &#x2014;
A scheduler to be used in combination with <code>dit</code> to denoise the encoded image latents.`,name:"scheduler"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/dit/pipeline_dit.py#L31"}}),J=new Gt({props:{name:"__call__",anchor:"diffusers.DiTPipeline.__call__",parameters:[{name:"class_labels",val:": typing.List[int]"},{name:"guidance_scale",val:": float = 4.0"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"num_inference_steps",val:": int = 50"},{name:"output_type",val:": typing.Optional[str] = 'pil'"},{name:"return_dict",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.DiTPipeline.__call__.class_labels",description:`<strong>class_labels</strong> (List[int]) &#x2014;
List of imagenet class labels for the images to be generated.`,name:"class_labels"},{anchor:"diffusers.DiTPipeline.__call__.guidance_scale",description:`<strong>guidance_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 4.0) &#x2014;
Scale of the guidance signal.`,name:"guidance_scale"},{anchor:"diffusers.DiTPipeline.__call__.generator",description:`<strong>generator</strong> (<code>torch.Generator</code>, <em>optional</em>) &#x2014;
A <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow">torch generator</a> to make generation
deterministic.`,name:"generator"},{anchor:"diffusers.DiTPipeline.__call__.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 250) &#x2014;
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference.`,name:"num_inference_steps"},{anchor:"diffusers.DiTPipeline.__call__.output_type",description:`<strong>output_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;pil&quot;</code>) &#x2014;
The output format of the generate image. Choose between
<a href="https://pillow.readthedocs.io/en/stable/" rel="nofollow">PIL</a>: <code>PIL.Image.Image</code> or <code>np.array</code>.`,name:"output_type"},{anchor:"diffusers.DiTPipeline.__call__.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/main/en/api/diffusion_pipeline#diffusers.ImagePipelineOutput">ImagePipelineOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/dit/pipeline_dit.py#L86"}}),Y=new Gt({props:{name:"get_label_ids",anchor:"diffusers.DiTPipeline.get_label_ids",parameters:[{name:"label",val:": typing.Union[str, typing.List[str]]"}],parametersDescription:[{anchor:"diffusers.DiTPipeline.get_label_ids.label",description:"<strong>label</strong> (<code>str</code> or <code>dict</code> of <code>str</code>) &#x2014; label strings to be mapped to class ids.",name:"label"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/dit/pipeline_dit.py#L63",returnDescription:`
<p>Class ids to be processed by pipeline.</p>
`,returnType:`
<p><code>list</code> of <code>int</code></p>
`}}),{c(){u=r("meta"),ke=l(),m=r("h1"),x=r("a"),oe=r("span"),y(G.$$.fragment),Ye=l(),ne=r("span"),Qe=f("Scalable Diffusion Models with Transformers (DiT)"),xe=l(),g=r("h2"),S=r("a"),le=r("span"),y(W.$$.fragment),Ze=l(),pe=r("span"),et=f("Overview"),Se=l(),H=r("p"),U=r("a"),tt=f("Scalable Diffusion Models with Transformers"),at=f(" (DiT) by William Peebles and Saining Xie."),Ae=l(),Z=r("p"),rt=f("The abstract of the paper is the following:"),Ie=l(),ee=r("p"),fe=r("em"),st=f("We explore a new class of diffusion models based on the transformer architecture. We train latent diffusion models of images, replacing the commonly-used U-Net backbone with a transformer that operates on latent patches. We analyze the scalability of our Diffusion Transformers (DiTs) through the lens of forward pass complexity as measured by Gflops. We find that DiTs with higher Gflops \u2014 through increased transformer depth/width or increased number of input tokens \u2014 consistently have lower FID. In addition to possessing good scalability properties, our largest DiT-XL/2 models outperform all prior diffusion models on the class-conditional ImageNet 512x512 and 256x256 benchmarks, achieving a state-of-the-art FID of 2.27 on the latter."),Me=l(),A=r("p"),it=f("The original codebase of this paper can be found here: "),O=r("a"),ot=f("facebookresearch/dit"),nt=f("."),Ne=l(),_=r("h2"),I=r("a"),de=r("span"),y(F.$$.fragment),lt=l(),ce=r("span"),pt=f("Available Pipelines:"),Le=l(),M=r("table"),he=r("thead"),v=r("tr"),ue=r("th"),ft=f("Pipeline"),dt=l(),me=r("th"),ct=f("Tasks"),ht=l(),te=r("th"),ut=f("Colab"),mt=l(),ge=r("tbody"),b=r("tr"),_e=r("td"),X=r("a"),gt=f("pipeline_dit.py"),_t=l(),ve=r("td"),be=r("em"),vt=f("Conditional Image Generation"),bt=l(),ae=r("td"),wt=f("-"),Ce=l(),w=r("h2"),N=r("a"),we=r("span"),y(V.$$.fragment),Dt=l(),De=r("span"),yt=f("Usage example"),je=l(),y(B.$$.fragment),qe=l(),D=r("h2"),L=r("a"),ye=r("span"),y(K.$$.fragment),Tt=l(),Te=r("span"),$t=f("DiTPipeline"),Ge=l(),h=r("div"),y(R.$$.fragment),Pt=l(),z=r("p"),Et=f("This pipeline inherits from "),re=r("a"),kt=f("DiffusionPipeline"),xt=f(`. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)`),St=l(),C=r("div"),y(J.$$.fragment),At=l(),$e=r("p"),It=f("Function invoked when calling the pipeline for generation."),Mt=l(),j=r("div"),y(Y.$$.fragment),Nt=l(),Q=r("p"),Lt=f("Map label strings, "),Pe=r("em"),Ct=f("e.g."),jt=f(" from ImageNet, to corresponding class ids."),this.h()},l(e){const n=ya('[data-svelte="svelte-1phssyn"]',document.head);u=s(n,"META",{name:!0,content:!0}),n.forEach(a),ke=p(e),m=s(e,"H1",{class:!0});var He=i(m);x=s(He,"A",{id:!0,class:!0,href:!0});var Ht=i(x);oe=s(Ht,"SPAN",{});var Ut=i(oe);T(G.$$.fragment,Ut),Ut.forEach(a),Ht.forEach(a),Ye=p(He),ne=s(He,"SPAN",{});var Ot=i(ne);Qe=d(Ot,"Scalable Diffusion Models with Transformers (DiT)"),Ot.forEach(a),He.forEach(a),xe=p(e),g=s(e,"H2",{class:!0});var Ue=i(g);S=s(Ue,"A",{id:!0,class:!0,href:!0});var Ft=i(S);le=s(Ft,"SPAN",{});var Xt=i(le);T(W.$$.fragment,Xt),Xt.forEach(a),Ft.forEach(a),Ze=p(Ue),pe=s(Ue,"SPAN",{});var Vt=i(pe);et=d(Vt,"Overview"),Vt.forEach(a),Ue.forEach(a),Se=p(e),H=s(e,"P",{});var qt=i(H);U=s(qt,"A",{href:!0,rel:!0});var Bt=i(U);tt=d(Bt,"Scalable Diffusion Models with Transformers"),Bt.forEach(a),at=d(qt," (DiT) by William Peebles and Saining Xie."),qt.forEach(a),Ae=p(e),Z=s(e,"P",{});var Kt=i(Z);rt=d(Kt,"The abstract of the paper is the following:"),Kt.forEach(a),Ie=p(e),ee=s(e,"P",{});var Rt=i(ee);fe=s(Rt,"EM",{});var zt=i(fe);st=d(zt,"We explore a new class of diffusion models based on the transformer architecture. We train latent diffusion models of images, replacing the commonly-used U-Net backbone with a transformer that operates on latent patches. We analyze the scalability of our Diffusion Transformers (DiTs) through the lens of forward pass complexity as measured by Gflops. We find that DiTs with higher Gflops \u2014 through increased transformer depth/width or increased number of input tokens \u2014 consistently have lower FID. In addition to possessing good scalability properties, our largest DiT-XL/2 models outperform all prior diffusion models on the class-conditional ImageNet 512x512 and 256x256 benchmarks, achieving a state-of-the-art FID of 2.27 on the latter."),zt.forEach(a),Rt.forEach(a),Me=p(e),A=s(e,"P",{});var Oe=i(A);it=d(Oe,"The original codebase of this paper can be found here: "),O=s(Oe,"A",{href:!0,rel:!0});var Jt=i(O);ot=d(Jt,"facebookresearch/dit"),Jt.forEach(a),nt=d(Oe,"."),Oe.forEach(a),Ne=p(e),_=s(e,"H2",{class:!0});var Fe=i(_);I=s(Fe,"A",{id:!0,class:!0,href:!0});var Yt=i(I);de=s(Yt,"SPAN",{});var Qt=i(de);T(F.$$.fragment,Qt),Qt.forEach(a),Yt.forEach(a),lt=p(Fe),ce=s(Fe,"SPAN",{});var Zt=i(ce);pt=d(Zt,"Available Pipelines:"),Zt.forEach(a),Fe.forEach(a),Le=p(e),M=s(e,"TABLE",{});var Xe=i(M);he=s(Xe,"THEAD",{});var ea=i(he);v=s(ea,"TR",{});var se=i(v);ue=s(se,"TH",{});var ta=i(ue);ft=d(ta,"Pipeline"),ta.forEach(a),dt=p(se),me=s(se,"TH",{});var aa=i(me);ct=d(aa,"Tasks"),aa.forEach(a),ht=p(se),te=s(se,"TH",{align:!0});var ra=i(te);ut=d(ra,"Colab"),ra.forEach(a),se.forEach(a),ea.forEach(a),mt=p(Xe),ge=s(Xe,"TBODY",{});var sa=i(ge);b=s(sa,"TR",{});var ie=i(b);_e=s(ie,"TD",{});var ia=i(_e);X=s(ia,"A",{href:!0,rel:!0});var oa=i(X);gt=d(oa,"pipeline_dit.py"),oa.forEach(a),ia.forEach(a),_t=p(ie),ve=s(ie,"TD",{});var na=i(ve);be=s(na,"EM",{});var la=i(be);vt=d(la,"Conditional Image Generation"),la.forEach(a),na.forEach(a),bt=p(ie),ae=s(ie,"TD",{align:!0});var pa=i(ae);wt=d(pa,"-"),pa.forEach(a),ie.forEach(a),sa.forEach(a),Xe.forEach(a),Ce=p(e),w=s(e,"H2",{class:!0});var Ve=i(w);N=s(Ve,"A",{id:!0,class:!0,href:!0});var fa=i(N);we=s(fa,"SPAN",{});var da=i(we);T(V.$$.fragment,da),da.forEach(a),fa.forEach(a),Dt=p(Ve),De=s(Ve,"SPAN",{});var ca=i(De);yt=d(ca,"Usage example"),ca.forEach(a),Ve.forEach(a),je=p(e),T(B.$$.fragment,e),qe=p(e),D=s(e,"H2",{class:!0});var Be=i(D);L=s(Be,"A",{id:!0,class:!0,href:!0});var ha=i(L);ye=s(ha,"SPAN",{});var ua=i(ye);T(K.$$.fragment,ua),ua.forEach(a),ha.forEach(a),Tt=p(Be),Te=s(Be,"SPAN",{});var ma=i(Te);$t=d(ma,"DiTPipeline"),ma.forEach(a),Be.forEach(a),Ge=p(e),h=s(e,"DIV",{class:!0});var q=i(h);T(R.$$.fragment,q),Pt=p(q),z=s(q,"P",{});var Ke=i(z);Et=d(Ke,"This pipeline inherits from "),re=s(Ke,"A",{href:!0});var ga=i(re);kt=d(ga,"DiffusionPipeline"),ga.forEach(a),xt=d(Ke,`. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)`),Ke.forEach(a),St=p(q),C=s(q,"DIV",{class:!0});var Re=i(C);T(J.$$.fragment,Re),At=p(Re),$e=s(Re,"P",{});var _a=i($e);It=d(_a,"Function invoked when calling the pipeline for generation."),_a.forEach(a),Re.forEach(a),Mt=p(q),j=s(q,"DIV",{class:!0});var ze=i(j);T(Y.$$.fragment,ze),Nt=p(ze),Q=s(ze,"P",{});var Je=i(Q);Lt=d(Je,"Map label strings, "),Pe=s(Je,"EM",{});var va=i(Pe);Ct=d(va,"e.g."),va.forEach(a),jt=d(Je," from ImageNet, to corresponding class ids."),Je.forEach(a),ze.forEach(a),q.forEach(a),this.h()},h(){o(u,"name","hf:doc:metadata"),o(u,"content",JSON.stringify(ka)),o(x,"id","scalable-diffusion-models-with-transformers-dit"),o(x,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),o(x,"href","#scalable-diffusion-models-with-transformers-dit"),o(m,"class","relative group"),o(S,"id","overview"),o(S,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),o(S,"href","#overview"),o(g,"class","relative group"),o(U,"href","https://arxiv.org/abs/2212.09748"),o(U,"rel","nofollow"),o(O,"href","https://github.com/facebookresearch/dit"),o(O,"rel","nofollow"),o(I,"id","available-pipelines"),o(I,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),o(I,"href","#available-pipelines"),o(_,"class","relative group"),o(te,"align","center"),o(X,"href","https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/dit/pipeline_dit.py"),o(X,"rel","nofollow"),o(ae,"align","center"),o(N,"id","usage-example"),o(N,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),o(N,"href","#usage-example"),o(w,"class","relative group"),o(L,"id","diffusers.DiTPipeline"),o(L,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),o(L,"href","#diffusers.DiTPipeline"),o(D,"class","relative group"),o(re,"href","/docs/diffusers/main/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),o(C,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),o(j,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),o(h,"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){t(document.head,u),c(e,ke,n),c(e,m,n),t(m,x),t(x,oe),$(G,oe,null),t(m,Ye),t(m,ne),t(ne,Qe),c(e,xe,n),c(e,g,n),t(g,S),t(S,le),$(W,le,null),t(g,Ze),t(g,pe),t(pe,et),c(e,Se,n),c(e,H,n),t(H,U),t(U,tt),t(H,at),c(e,Ae,n),c(e,Z,n),t(Z,rt),c(e,Ie,n),c(e,ee,n),t(ee,fe),t(fe,st),c(e,Me,n),c(e,A,n),t(A,it),t(A,O),t(O,ot),t(A,nt),c(e,Ne,n),c(e,_,n),t(_,I),t(I,de),$(F,de,null),t(_,lt),t(_,ce),t(ce,pt),c(e,Le,n),c(e,M,n),t(M,he),t(he,v),t(v,ue),t(ue,ft),t(v,dt),t(v,me),t(me,ct),t(v,ht),t(v,te),t(te,ut),t(M,mt),t(M,ge),t(ge,b),t(b,_e),t(_e,X),t(X,gt),t(b,_t),t(b,ve),t(ve,be),t(be,vt),t(b,bt),t(b,ae),t(ae,wt),c(e,Ce,n),c(e,w,n),t(w,N),t(N,we),$(V,we,null),t(w,Dt),t(w,De),t(De,yt),c(e,je,n),$(B,e,n),c(e,qe,n),c(e,D,n),t(D,L),t(L,ye),$(K,ye,null),t(D,Tt),t(D,Te),t(Te,$t),c(e,Ge,n),c(e,h,n),$(R,h,null),t(h,Pt),t(h,z),t(z,Et),t(z,re),t(re,kt),t(z,xt),t(h,St),t(h,C),$(J,C,null),t(C,At),t(C,$e),t($e,It),t(h,Mt),t(h,j),$(Y,j,null),t(j,Nt),t(j,Q),t(Q,Lt),t(Q,Pe),t(Pe,Ct),t(Q,jt),We=!0},p:Ta,i(e){We||(P(G.$$.fragment,e),P(W.$$.fragment,e),P(F.$$.fragment,e),P(V.$$.fragment,e),P(B.$$.fragment,e),P(K.$$.fragment,e),P(R.$$.fragment,e),P(J.$$.fragment,e),P(Y.$$.fragment,e),We=!0)},o(e){E(G.$$.fragment,e),E(W.$$.fragment,e),E(F.$$.fragment,e),E(V.$$.fragment,e),E(B.$$.fragment,e),E(K.$$.fragment,e),E(R.$$.fragment,e),E(J.$$.fragment,e),E(Y.$$.fragment,e),We=!1},d(e){a(u),e&&a(ke),e&&a(m),k(G),e&&a(xe),e&&a(g),k(W),e&&a(Se),e&&a(H),e&&a(Ae),e&&a(Z),e&&a(Ie),e&&a(ee),e&&a(Me),e&&a(A),e&&a(Ne),e&&a(_),k(F),e&&a(Le),e&&a(M),e&&a(Ce),e&&a(w),k(V),e&&a(je),k(B,e),e&&a(qe),e&&a(D),k(K),e&&a(Ge),e&&a(h),k(R),k(J),k(Y)}}}const ka={local:"scalable-diffusion-models-with-transformers-dit",sections:[{local:"overview",title:"Overview"},{local:"available-pipelines",title:"Available Pipelines:"},{local:"usage-example",title:"Usage example"},{local:"diffusers.DiTPipeline",title:"DiTPipeline"}],title:"Scalable Diffusion Models with Transformers (DiT)"};function xa(Wt){return $a(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Na extends ba{constructor(u){super();wa(this,u,xa,Ea,Da,{})}}export{Na as default,ka as metadata};
