import{S as mt,i as ht,s as gt,e as i,k as h,w as I,t as f,M as _t,c as o,d as t,m as g,a,x as k,h as d,b as p,G as n,g as u,y as T,q as U,o as S,B as G,v as vt,L as yt}from"../../../chunks/vendor-hf-doc-builder.js";import{T as bt}from"../../../chunks/Tip-hf-doc-builder.js";import{D as Xe}from"../../../chunks/Docstring-hf-doc-builder.js";import{C as wt}from"../../../chunks/CodeBlock-hf-doc-builder.js";import{I as Qe}from"../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as $t}from"../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function Mt(Q){let l,w,c,m,_,s,v,P;return{c(){l=i("p"),w=f("Make sure to check out the Schedulers "),c=i("a"),m=f("guide"),_=f(" to learn how to explore the tradeoff between scheduler speed and quality, and see the "),s=i("a"),v=f("reuse components across pipelines"),P=f(" section to learn how to efficiently load the same components into multiple pipelines."),this.h()},l(D){l=o(D,"P",{});var y=a(l);w=d(y,"Make sure to check out the Schedulers "),c=o(y,"A",{href:!0});var $=a(c);m=d($,"guide"),$.forEach(t),_=d(y," to learn how to explore the tradeoff between scheduler speed and quality, and see the "),s=o(y,"A",{href:!0});var F=a(s);v=d(F,"reuse components across pipelines"),F.forEach(t),P=d(y," section to learn how to efficiently load the same components into multiple pipelines."),y.forEach(t),this.h()},h(){p(c,"href","/using-diffusers/schedulers"),p(s,"href","/using-diffusers/loading#reuse-components-across-pipelines")},m(D,y){u(D,l,y),n(l,w),n(l,c),n(c,m),n(l,_),n(l,s),n(s,v),n(l,P)},d(D){D&&t(l)}}}function Pt(Q){let l,w,c,m,_;return m=new wt({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMExETVBpcGVsaW5lJTBBJTBBJTIzJTIwbG9hZCUyMG1vZGVsJTIwYW5kJTIwc2NoZWR1bGVyJTBBcGlwZSUyMCUzRCUyMExETVBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJDb21wVmlzJTJGbGRtLWNlbGViYWhxLTI1NiUyMiklMEElMEElMjMlMjBydW4lMjBwaXBlbGluZSUyMGluJTIwaW5mZXJlbmNlJTIwKHNhbXBsZSUyMHJhbmRvbSUyMG5vaXNlJTIwYW5kJTIwZGVub2lzZSklMEFpbWFnZSUyMCUzRCUyMHBpcGUoKS5pbWFnZXMlNUIwJTVE",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> LDMPipeline

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># load model and scheduler</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = LDMPipeline.from_pretrained(<span class="hljs-string">&quot;CompVis/ldm-celebahq-256&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># run pipeline in inference (sample random noise and denoise)</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = pipe().images[<span class="hljs-number">0</span>]`}}),{c(){l=i("p"),w=f("Example:"),c=h(),I(m.$$.fragment)},l(s){l=o(s,"P",{});var v=a(l);w=d(v,"Example:"),v.forEach(t),c=g(s),k(m.$$.fragment,s)},m(s,v){u(s,l,v),n(l,w),u(s,c,v),T(m,s,v),_=!0},p:yt,i(s){_||(U(m.$$.fragment,s),_=!0)},o(s){S(m.$$.fragment,s),_=!1},d(s){s&&t(l),s&&t(c),G(m,s)}}}function Dt(Q){let l,w,c,m,_,s,v,P,D,y,$,F,C,xe,Ee,de,Y,Le,ue,K,ne,Ie,ce,q,ke,J,Te,Ue,me,B,he,x,O,ie,j,Se,oe,Ge,ge,b,z,qe,ae,Be,Oe,Z,Ve,ee,Ne,Ae,Ce,M,R,Je,se,je,ze,V,_e,E,N,re,W,Ze,le,Re,ve,L,H,We,pe,He,ye;return s=new Qe({}),B=new bt({props:{$$slots:{default:[Mt]},$$scope:{ctx:Q}}}),j=new Qe({}),z=new Xe({props:{name:"class diffusers.LDMPipeline",anchor:"diffusers.LDMPipeline",parameters:[{name:"vqvae",val:": VQModel"},{name:"unet",val:": UNet2DModel"},{name:"scheduler",val:": DDIMScheduler"}],parametersDescription:[{anchor:"diffusers.LDMPipeline.vqvae",description:`<strong>vqvae</strong> (<a href="/docs/diffusers/main/en/api/models/vq#diffusers.VQModel">VQModel</a>) &#x2014;
Vector-quantized (VQ) model to encode and decode images to and from latent representations.`,name:"vqvae"},{anchor:"diffusers.LDMPipeline.unet",description:`<strong>unet</strong> (<a href="/docs/diffusers/main/en/api/models/unet2d#diffusers.UNet2DModel">UNet2DModel</a>) &#x2014;
A <code>UNet2DModel</code> to denoise the encoded image latents.`,name:"unet"},{anchor:"diffusers.LDMPipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/main/en/api/schedulers/overview#diffusers.SchedulerMixin">SchedulerMixin</a>) &#x2014;
<a href="/docs/diffusers/main/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a> is used in combination with <code>unet</code> to denoise the encoded image latents.`,name:"scheduler"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/latent_diffusion_uncond/pipeline_latent_diffusion_uncond.py#L26"}}),R=new Xe({props:{name:"__call__",anchor:"diffusers.LDMPipeline.__call__",parameters:[{name:"batch_size",val:": int = 1"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"eta",val:": float = 0.0"},{name:"num_inference_steps",val:": int = 50"},{name:"output_type",val:": typing.Optional[str] = 'pil'"},{name:"return_dict",val:": bool = True"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.LDMPipeline.__call__.batch_size",description:`<strong>batch_size</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
Number of images to generate.`,name:"batch_size"},{anchor:"diffusers.LDMPipeline.__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"><code>torch.Generator</code></a> to make
generation deterministic.`,name:"generator"},{anchor:"diffusers.LDMPipeline.__call__.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 50) &#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.LDMPipeline.__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 generated image. Choose between <code>PIL.Image</code> or <code>np.array</code>.`,name:"output_type"},{anchor:"diffusers.LDMPipeline.__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/pipelines/latent_diffusion#diffusers.ImagePipelineOutput">ImagePipelineOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/latent_diffusion_uncond/pipeline_latent_diffusion_uncond.py#L46",returnDescription:`
<p>If <code>return_dict</code> is <code>True</code>, <a
  href="/docs/diffusers/main/en/api/pipelines/latent_diffusion#diffusers.ImagePipelineOutput"
>ImagePipelineOutput</a> is returned, otherwise a <code>tuple</code> is
returned where the first element is a list with the generated images</p>
`,returnType:`
<p><a
  href="/docs/diffusers/main/en/api/pipelines/latent_diffusion#diffusers.ImagePipelineOutput"
>ImagePipelineOutput</a> or <code>tuple</code></p>
`}}),V=new $t({props:{anchor:"diffusers.LDMPipeline.__call__.example",$$slots:{default:[Pt]},$$scope:{ctx:Q}}}),W=new Qe({}),H=new Xe({props:{name:"class diffusers.ImagePipelineOutput",anchor:"diffusers.ImagePipelineOutput",parameters:[{name:"images",val:": typing.Union[typing.List[PIL.Image.Image], numpy.ndarray]"}],parametersDescription:[{anchor:"diffusers.ImagePipelineOutput.images",description:`<strong>images</strong> (<code>List[PIL.Image.Image]</code> or <code>np.ndarray</code>) &#x2014;
List of denoised PIL images of length <code>batch_size</code> or NumPy array of shape <code>(batch_size, height, width, num_channels)</code>.`,name:"images"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L113"}}),{c(){l=i("meta"),w=h(),c=i("h1"),m=i("a"),_=i("span"),I(s.$$.fragment),v=h(),P=i("span"),D=f("Unconditional Latent Diffusion"),y=h(),$=i("p"),F=f("Unconditional Latent Diffusion was proposed in "),C=i("a"),xe=f("High-Resolution Image Synthesis with Latent Diffusion Models"),Ee=f(" by Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, Bj\xF6rn Ommer."),de=h(),Y=i("p"),Le=f("The abstract from the paper is:"),ue=h(),K=i("p"),ne=i("em"),Ie=f("By decomposing the image formation process into a sequential application of denoising autoencoders, diffusion models (DMs) achieve state-of-the-art synthesis results on image data and beyond. Additionally, their formulation allows for a guiding mechanism to control the image generation process without retraining. However, since these models typically operate directly in pixel space, optimization of powerful DMs often consumes hundreds of GPU days and inference is expensive due to sequential evaluations. To enable DM training on limited computational resources while retaining their quality and flexibility, we apply them in the latent space of powerful pretrained autoencoders. In contrast to previous work, training diffusion models on such a representation allows for the first time to reach a near-optimal point between complexity reduction and detail preservation, greatly boosting visual fidelity. By introducing cross-attention layers into the model architecture, we turn diffusion models into powerful and flexible generators for general conditioning inputs such as text or bounding boxes and high-resolution synthesis becomes possible in a convolutional manner. Our latent diffusion models (LDMs) achieve a new state of the art for image inpainting and highly competitive performance on various tasks, including unconditional image generation, semantic scene synthesis, and super-resolution, while significantly reducing computational requirements compared to pixel-based DMs."),ce=h(),q=i("p"),ke=f("The original codebase can be found at "),J=i("a"),Te=f("CompVis/latent-diffusion"),Ue=f("."),me=h(),I(B.$$.fragment),he=h(),x=i("h2"),O=i("a"),ie=i("span"),I(j.$$.fragment),Se=h(),oe=i("span"),Ge=f("LDMPipeline"),ge=h(),b=i("div"),I(z.$$.fragment),qe=h(),ae=i("p"),Be=f("Pipeline for unconditional image generation using latent diffusion."),Oe=h(),Z=i("p"),Ve=f("This model inherits from "),ee=i("a"),Ne=f("DiffusionPipeline"),Ae=f(`. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).`),Ce=h(),M=i("div"),I(R.$$.fragment),Je=h(),se=i("p"),je=f("The call function to the pipeline for generation."),ze=h(),I(V.$$.fragment),_e=h(),E=i("h2"),N=i("a"),re=i("span"),I(W.$$.fragment),Ze=h(),le=i("span"),Re=f("ImagePipelineOutput"),ve=h(),L=i("div"),I(H.$$.fragment),We=h(),pe=i("p"),He=f("Output class for image pipelines."),this.h()},l(e){const r=_t('[data-svelte="svelte-1phssyn"]',document.head);l=o(r,"META",{name:!0,content:!0}),r.forEach(t),w=g(e),c=o(e,"H1",{class:!0});var X=a(c);m=o(X,"A",{id:!0,class:!0,href:!0});var fe=a(m);_=o(fe,"SPAN",{});var Fe=a(_);k(s.$$.fragment,Fe),Fe.forEach(t),fe.forEach(t),v=g(X),P=o(X,"SPAN",{});var Ye=a(P);D=d(Ye,"Unconditional Latent Diffusion"),Ye.forEach(t),X.forEach(t),y=g(e),$=o(e,"P",{});var be=a($);F=d(be,"Unconditional Latent Diffusion was proposed in "),C=o(be,"A",{href:!0,rel:!0});var Ke=a(C);xe=d(Ke,"High-Resolution Image Synthesis with Latent Diffusion Models"),Ke.forEach(t),Ee=d(be," by Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, Bj\xF6rn Ommer."),be.forEach(t),de=g(e),Y=o(e,"P",{});var et=a(Y);Le=d(et,"The abstract from the paper is:"),et.forEach(t),ue=g(e),K=o(e,"P",{});var tt=a(K);ne=o(tt,"EM",{});var nt=a(ne);Ie=d(nt,"By decomposing the image formation process into a sequential application of denoising autoencoders, diffusion models (DMs) achieve state-of-the-art synthesis results on image data and beyond. Additionally, their formulation allows for a guiding mechanism to control the image generation process without retraining. However, since these models typically operate directly in pixel space, optimization of powerful DMs often consumes hundreds of GPU days and inference is expensive due to sequential evaluations. To enable DM training on limited computational resources while retaining their quality and flexibility, we apply them in the latent space of powerful pretrained autoencoders. In contrast to previous work, training diffusion models on such a representation allows for the first time to reach a near-optimal point between complexity reduction and detail preservation, greatly boosting visual fidelity. By introducing cross-attention layers into the model architecture, we turn diffusion models into powerful and flexible generators for general conditioning inputs such as text or bounding boxes and high-resolution synthesis becomes possible in a convolutional manner. Our latent diffusion models (LDMs) achieve a new state of the art for image inpainting and highly competitive performance on various tasks, including unconditional image generation, semantic scene synthesis, and super-resolution, while significantly reducing computational requirements compared to pixel-based DMs."),nt.forEach(t),tt.forEach(t),ce=g(e),q=o(e,"P",{});var we=a(q);ke=d(we,"The original codebase can be found at "),J=o(we,"A",{href:!0,rel:!0});var it=a(J);Te=d(it,"CompVis/latent-diffusion"),it.forEach(t),Ue=d(we,"."),we.forEach(t),me=g(e),k(B.$$.fragment,e),he=g(e),x=o(e,"H2",{class:!0});var $e=a(x);O=o($e,"A",{id:!0,class:!0,href:!0});var ot=a(O);ie=o(ot,"SPAN",{});var at=a(ie);k(j.$$.fragment,at),at.forEach(t),ot.forEach(t),Se=g($e),oe=o($e,"SPAN",{});var st=a(oe);Ge=d(st,"LDMPipeline"),st.forEach(t),$e.forEach(t),ge=g(e),b=o(e,"DIV",{class:!0});var A=a(b);k(z.$$.fragment,A),qe=g(A),ae=o(A,"P",{});var rt=a(ae);Be=d(rt,"Pipeline for unconditional image generation using latent diffusion."),rt.forEach(t),Oe=g(A),Z=o(A,"P",{});var Me=a(Z);Ve=d(Me,"This model inherits from "),ee=o(Me,"A",{href:!0});var lt=a(ee);Ne=d(lt,"DiffusionPipeline"),lt.forEach(t),Ae=d(Me,`. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).`),Me.forEach(t),Ce=g(A),M=o(A,"DIV",{class:!0});var te=a(M);k(R.$$.fragment,te),Je=g(te),se=o(te,"P",{});var pt=a(se);je=d(pt,"The call function to the pipeline for generation."),pt.forEach(t),ze=g(te),k(V.$$.fragment,te),te.forEach(t),A.forEach(t),_e=g(e),E=o(e,"H2",{class:!0});var Pe=a(E);N=o(Pe,"A",{id:!0,class:!0,href:!0});var ft=a(N);re=o(ft,"SPAN",{});var dt=a(re);k(W.$$.fragment,dt),dt.forEach(t),ft.forEach(t),Ze=g(Pe),le=o(Pe,"SPAN",{});var ut=a(le);Re=d(ut,"ImagePipelineOutput"),ut.forEach(t),Pe.forEach(t),ve=g(e),L=o(e,"DIV",{class:!0});var De=a(L);k(H.$$.fragment,De),We=g(De),pe=o(De,"P",{});var ct=a(pe);He=d(ct,"Output class for image pipelines."),ct.forEach(t),De.forEach(t),this.h()},h(){p(l,"name","hf:doc:metadata"),p(l,"content",JSON.stringify(xt)),p(m,"id","unconditional-latent-diffusion"),p(m,"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"),p(m,"href","#unconditional-latent-diffusion"),p(c,"class","relative group"),p(C,"href","https://huggingface.co/papers/2112.10752"),p(C,"rel","nofollow"),p(J,"href","https://github.com/CompVis/latent-diffusion"),p(J,"rel","nofollow"),p(O,"id","diffusers.LDMPipeline"),p(O,"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"),p(O,"href","#diffusers.LDMPipeline"),p(x,"class","relative group"),p(ee,"href","/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline"),p(M,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),p(b,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),p(N,"id","diffusers.ImagePipelineOutput"),p(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"),p(N,"href","#diffusers.ImagePipelineOutput"),p(E,"class","relative group"),p(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,r){n(document.head,l),u(e,w,r),u(e,c,r),n(c,m),n(m,_),T(s,_,null),n(c,v),n(c,P),n(P,D),u(e,y,r),u(e,$,r),n($,F),n($,C),n(C,xe),n($,Ee),u(e,de,r),u(e,Y,r),n(Y,Le),u(e,ue,r),u(e,K,r),n(K,ne),n(ne,Ie),u(e,ce,r),u(e,q,r),n(q,ke),n(q,J),n(J,Te),n(q,Ue),u(e,me,r),T(B,e,r),u(e,he,r),u(e,x,r),n(x,O),n(O,ie),T(j,ie,null),n(x,Se),n(x,oe),n(oe,Ge),u(e,ge,r),u(e,b,r),T(z,b,null),n(b,qe),n(b,ae),n(ae,Be),n(b,Oe),n(b,Z),n(Z,Ve),n(Z,ee),n(ee,Ne),n(Z,Ae),n(b,Ce),n(b,M),T(R,M,null),n(M,Je),n(M,se),n(se,je),n(M,ze),T(V,M,null),u(e,_e,r),u(e,E,r),n(E,N),n(N,re),T(W,re,null),n(E,Ze),n(E,le),n(le,Re),u(e,ve,r),u(e,L,r),T(H,L,null),n(L,We),n(L,pe),n(pe,He),ye=!0},p(e,[r]){const X={};r&2&&(X.$$scope={dirty:r,ctx:e}),B.$set(X);const fe={};r&2&&(fe.$$scope={dirty:r,ctx:e}),V.$set(fe)},i(e){ye||(U(s.$$.fragment,e),U(B.$$.fragment,e),U(j.$$.fragment,e),U(z.$$.fragment,e),U(R.$$.fragment,e),U(V.$$.fragment,e),U(W.$$.fragment,e),U(H.$$.fragment,e),ye=!0)},o(e){S(s.$$.fragment,e),S(B.$$.fragment,e),S(j.$$.fragment,e),S(z.$$.fragment,e),S(R.$$.fragment,e),S(V.$$.fragment,e),S(W.$$.fragment,e),S(H.$$.fragment,e),ye=!1},d(e){t(l),e&&t(w),e&&t(c),G(s),e&&t(y),e&&t($),e&&t(de),e&&t(Y),e&&t(ue),e&&t(K),e&&t(ce),e&&t(q),e&&t(me),G(B,e),e&&t(he),e&&t(x),G(j),e&&t(ge),e&&t(b),G(z),G(R),G(V),e&&t(_e),e&&t(E),G(W),e&&t(ve),e&&t(L),G(H)}}}const xt={local:"unconditional-latent-diffusion",sections:[{local:"diffusers.LDMPipeline",title:"LDMPipeline"},{local:"diffusers.ImagePipelineOutput",title:"ImagePipelineOutput"}],title:"Unconditional Latent Diffusion"};function Et(Q){return vt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Gt extends mt{constructor(l){super();ht(this,l,Et,Dt,gt,{})}}export{Gt as default,xt as metadata};
