import{S as mt,i as ht,s as gt,e as i,k as h,w as I,t as d,M as vt,c as o,d as t,m as g,a as s,x as k,h as f,b as p,G as n,g as c,y as T,q as U,o as S,B as G,v as _t,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,u,m,v,a,_,P;return{c(){l=i("p"),w=d("Make sure to check out the Schedulers "),u=i("a"),m=d("guide"),v=d(" to learn how to explore the tradeoff between scheduler speed and quality, and see the "),a=i("a"),_=d("reuse components across pipelines"),P=d(" section to learn how to efficiently load the same components into multiple pipelines."),this.h()},l(D){l=o(D,"P",{});var y=s(l);w=f(y,"Make sure to check out the Schedulers "),u=o(y,"A",{href:!0});var $=s(u);m=f($,"guide"),$.forEach(t),v=f(y," to learn how to explore the tradeoff between scheduler speed and quality, and see the "),a=o(y,"A",{href:!0});var F=s(a);_=f(F,"reuse components across pipelines"),F.forEach(t),P=f(y," section to learn how to efficiently load the same components into multiple pipelines."),y.forEach(t),this.h()},h(){p(u,"href","/using-diffusers/schedulers"),p(a,"href","/using-diffusers/loading#reuse-components-across-pipelines")},m(D,y){c(D,l,y),n(l,w),n(l,u),n(u,m),n(l,v),n(l,a),n(a,_),n(l,P)},d(D){D&&t(l)}}}function Pt(Q){let l,w,u,m,v;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=d("Example:"),u=h(),I(m.$$.fragment)},l(a){l=o(a,"P",{});var _=s(l);w=f(_,"Example:"),_.forEach(t),u=g(a),k(m.$$.fragment,a)},m(a,_){c(a,l,_),n(l,w),c(a,u,_),T(m,a,_),v=!0},p:yt,i(a){v||(U(m.$$.fragment,a),v=!0)},o(a){S(m.$$.fragment,a),v=!1},d(a){a&&t(l),a&&t(u),G(m,a)}}}function Dt(Q){let l,w,u,m,v,a,_,P,D,y,$,F,C,xe,Ee,fe,Y,Le,ce,K,ne,Ie,ue,q,ke,J,Te,Ue,me,B,he,x,O,ie,j,Se,oe,Ge,ge,b,z,qe,se,Be,Oe,Z,Ve,ee,Ne,Ae,Ce,M,R,Je,ae,je,ze,V,ve,E,N,re,W,Ze,le,Re,_e,L,H,We,pe,He,ye;return a=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/v0.20.0/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/v0.20.0/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/v0.20.0/en/api/schedulers/overview#diffusers.SchedulerMixin">SchedulerMixin</a>) &#x2014;
<a href="/docs/diffusers/v0.20.0/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/v0.20.0/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/v0.20.0/en/api/pipelines/ddim#diffusers.ImagePipelineOutput">ImagePipelineOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/v0.20.0/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/v0.20.0/en/api/pipelines/ddim#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/v0.20.0/en/api/pipelines/ddim#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/v0.20.0/src/diffusers/pipelines/pipeline_utils.py#L112"}}),{c(){l=i("meta"),w=h(),u=i("h1"),m=i("a"),v=i("span"),I(a.$$.fragment),_=h(),P=i("span"),D=d("Unconditional Latent Diffusion"),y=h(),$=i("p"),F=d("Unconditional Latent Diffusion was proposed in "),C=i("a"),xe=d("High-Resolution Image Synthesis with Latent Diffusion Models"),Ee=d(" by Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, Bj\xF6rn Ommer."),fe=h(),Y=i("p"),Le=d("The abstract from the paper is:"),ce=h(),K=i("p"),ne=i("em"),Ie=d("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."),ue=h(),q=i("p"),ke=d("The original codebase can be found at "),J=i("a"),Te=d("CompVis/latent-diffusion"),Ue=d("."),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=d("LDMPipeline"),ge=h(),b=i("div"),I(z.$$.fragment),qe=h(),se=i("p"),Be=d("Pipeline for unconditional image generation using latent diffusion."),Oe=h(),Z=i("p"),Ve=d("This model inherits from "),ee=i("a"),Ne=d("DiffusionPipeline"),Ae=d(`. 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(),ae=i("p"),je=d("The call function to the pipeline for generation."),ze=h(),I(V.$$.fragment),ve=h(),E=i("h2"),N=i("a"),re=i("span"),I(W.$$.fragment),Ze=h(),le=i("span"),Re=d("ImagePipelineOutput"),_e=h(),L=i("div"),I(H.$$.fragment),We=h(),pe=i("p"),He=d("Output class for image pipelines."),this.h()},l(e){const r=vt('[data-svelte="svelte-1phssyn"]',document.head);l=o(r,"META",{name:!0,content:!0}),r.forEach(t),w=g(e),u=o(e,"H1",{class:!0});var X=s(u);m=o(X,"A",{id:!0,class:!0,href:!0});var de=s(m);v=o(de,"SPAN",{});var Fe=s(v);k(a.$$.fragment,Fe),Fe.forEach(t),de.forEach(t),_=g(X),P=o(X,"SPAN",{});var Ye=s(P);D=f(Ye,"Unconditional Latent Diffusion"),Ye.forEach(t),X.forEach(t),y=g(e),$=o(e,"P",{});var be=s($);F=f(be,"Unconditional Latent Diffusion was proposed in "),C=o(be,"A",{href:!0,rel:!0});var Ke=s(C);xe=f(Ke,"High-Resolution Image Synthesis with Latent Diffusion Models"),Ke.forEach(t),Ee=f(be," by Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, Bj\xF6rn Ommer."),be.forEach(t),fe=g(e),Y=o(e,"P",{});var et=s(Y);Le=f(et,"The abstract from the paper is:"),et.forEach(t),ce=g(e),K=o(e,"P",{});var tt=s(K);ne=o(tt,"EM",{});var nt=s(ne);Ie=f(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),ue=g(e),q=o(e,"P",{});var we=s(q);ke=f(we,"The original codebase can be found at "),J=o(we,"A",{href:!0,rel:!0});var it=s(J);Te=f(it,"CompVis/latent-diffusion"),it.forEach(t),Ue=f(we,"."),we.forEach(t),me=g(e),k(B.$$.fragment,e),he=g(e),x=o(e,"H2",{class:!0});var $e=s(x);O=o($e,"A",{id:!0,class:!0,href:!0});var ot=s(O);ie=o(ot,"SPAN",{});var st=s(ie);k(j.$$.fragment,st),st.forEach(t),ot.forEach(t),Se=g($e),oe=o($e,"SPAN",{});var at=s(oe);Ge=f(at,"LDMPipeline"),at.forEach(t),$e.forEach(t),ge=g(e),b=o(e,"DIV",{class:!0});var A=s(b);k(z.$$.fragment,A),qe=g(A),se=o(A,"P",{});var rt=s(se);Be=f(rt,"Pipeline for unconditional image generation using latent diffusion."),rt.forEach(t),Oe=g(A),Z=o(A,"P",{});var Me=s(Z);Ve=f(Me,"This model inherits from "),ee=o(Me,"A",{href:!0});var lt=s(ee);Ne=f(lt,"DiffusionPipeline"),lt.forEach(t),Ae=f(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=s(M);k(R.$$.fragment,te),Je=g(te),ae=o(te,"P",{});var pt=s(ae);je=f(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),ve=g(e),E=o(e,"H2",{class:!0});var Pe=s(E);N=o(Pe,"A",{id:!0,class:!0,href:!0});var dt=s(N);re=o(dt,"SPAN",{});var ft=s(re);k(W.$$.fragment,ft),ft.forEach(t),dt.forEach(t),Ze=g(Pe),le=o(Pe,"SPAN",{});var ct=s(le);Re=f(ct,"ImagePipelineOutput"),ct.forEach(t),Pe.forEach(t),_e=g(e),L=o(e,"DIV",{class:!0});var De=s(L);k(H.$$.fragment,De),We=g(De),pe=o(De,"P",{});var ut=s(pe);He=f(ut,"Output class for image pipelines."),ut.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(u,"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/v0.20.0/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),c(e,w,r),c(e,u,r),n(u,m),n(m,v),T(a,v,null),n(u,_),n(u,P),n(P,D),c(e,y,r),c(e,$,r),n($,F),n($,C),n(C,xe),n($,Ee),c(e,fe,r),c(e,Y,r),n(Y,Le),c(e,ce,r),c(e,K,r),n(K,ne),n(ne,Ie),c(e,ue,r),c(e,q,r),n(q,ke),n(q,J),n(J,Te),n(q,Ue),c(e,me,r),T(B,e,r),c(e,he,r),c(e,x,r),n(x,O),n(O,ie),T(j,ie,null),n(x,Se),n(x,oe),n(oe,Ge),c(e,ge,r),c(e,b,r),T(z,b,null),n(b,qe),n(b,se),n(se,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,ae),n(ae,je),n(M,ze),T(V,M,null),c(e,ve,r),c(e,E,r),n(E,N),n(N,re),T(W,re,null),n(E,Ze),n(E,le),n(le,Re),c(e,_e,r),c(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 de={};r&2&&(de.$$scope={dirty:r,ctx:e}),V.$set(de)},i(e){ye||(U(a.$$.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(a.$$.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(u),G(a),e&&t(y),e&&t($),e&&t(fe),e&&t(Y),e&&t(ce),e&&t(K),e&&t(ue),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(ve),e&&t(E),G(W),e&&t(_e),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 _t(()=>{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};
