import{S as dt,i as mt,s as ut,e as a,k as c,w as T,t as m,M as ft,c as n,d as t,m as d,a as i,x as S,h as u,b as l,G as s,g as p,y as k,q as J,o as x,B as W,v as ht,L as gt}from"../../../chunks/vendor-hf-doc-builder.js";import{D as Ve}from"../../../chunks/Docstring-hf-doc-builder.js";import{C as _t}from"../../../chunks/CodeBlock-hf-doc-builder.js";import{I as qe}from"../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as Dt}from"../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function Mt(ie){let f,I,g,h,D;return h=new _t({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERESU1QaXBlbGluZSUwQWltcG9ydCUyMFBJTC5JbWFnZSUwQWltcG9ydCUyMG51bXB5JTIwYXMlMjBucCUwQSUwQSUyMyUyMGxvYWQlMjBtb2RlbCUyMGFuZCUyMHNjaGVkdWxlciUwQXBpcGUlMjAlM0QlMjBERElNUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUyMmZ1c2luZyUyRmRkaW0tbHN1bi1iZWRyb29tJTIyKSUwQSUwQSUyMyUyMHJ1biUyMHBpcGVsaW5lJTIwaW4lMjBpbmZlcmVuY2UlMjAoc2FtcGxlJTIwcmFuZG9tJTIwbm9pc2UlMjBhbmQlMjBkZW5vaXNlKSUwQWltYWdlJTIwJTNEJTIwcGlwZShldGElM0QwLjAlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNENTApJTBBJTBBJTIzJTIwcHJvY2VzcyUyMGltYWdlJTIwdG8lMjBQSUwlMEFpbWFnZV9wcm9jZXNzZWQlMjAlM0QlMjBpbWFnZS5jcHUoKS5wZXJtdXRlKDAlMkMlMjAyJTJDJTIwMyUyQyUyMDEpJTBBaW1hZ2VfcHJvY2Vzc2VkJTIwJTNEJTIwKGltYWdlX3Byb2Nlc3NlZCUyMCUyQiUyMDEuMCklMjAqJTIwMTI3LjUlMEFpbWFnZV9wcm9jZXNzZWQlMjAlM0QlMjBpbWFnZV9wcm9jZXNzZWQubnVtcHkoKS5hc3R5cGUobnAudWludDgpJTBBaW1hZ2VfcGlsJTIwJTNEJTIwUElMLkltYWdlLmZyb21hcnJheShpbWFnZV9wcm9jZXNzZWQlNUIwJTVEKSUwQSUwQSUyMyUyMHNhdmUlMjBpbWFnZSUwQWltYWdlX3BpbC5zYXZlKCUyMnRlc3QucG5nJTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMPipeline
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> PIL.Image
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

<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 = DDIMPipeline.from_pretrained(<span class="hljs-string">&quot;fusing/ddim-lsun-bedroom&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(eta=<span class="hljs-number">0.0</span>, num_inference_steps=<span class="hljs-number">50</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># process image to PIL</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image_processed = image.cpu().permute(<span class="hljs-number">0</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">1</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>image_processed = (image_processed + <span class="hljs-number">1.0</span>) * <span class="hljs-number">127.5</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image_processed = image_processed.numpy().astype(np.uint8)
<span class="hljs-meta">&gt;&gt;&gt; </span>image_pil = PIL.Image.fromarray(image_processed[<span class="hljs-number">0</span>])

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># save image</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image_pil.save(<span class="hljs-string">&quot;test.png&quot;</span>)`}}),{c(){f=a("p"),I=m("Example:"),g=c(),T(h.$$.fragment)},l(o){f=n(o,"P",{});var M=i(f);I=u(M,"Example:"),M.forEach(t),g=d(o),S(h.$$.fragment,o)},m(o,M){p(o,f,M),s(f,I),p(o,g,M),k(h,o,M),D=!0},p:gt,i(o){D||(J(h.$$.fragment,o),D=!0)},o(o){x(h.$$.fragment,o),D=!1},d(o){o&&t(f),o&&t(g),W(h,o)}}}function vt(ie){let f,I,g,h,D,o,M,H,ve,re,Z,N,ye,be,oe,q,we,le,X,R,Ie,pe,P,Pe,B,$e,je,ce,y,$,Y,G,Ue,K,Ee,de,_,A,Te,ee,Se,ke,C,Je,z,xe,We,Ze,v,Q,Ne,te,Be,Ge,j,me,b,U,se,L,Ae,ae,Ce,ue,w,O,Qe,ne,Le,fe;return o=new qe({}),G=new qe({}),A=new Ve({props:{name:"class diffusers.DDIMPipeline",anchor:"diffusers.DDIMPipeline",parameters:[{name:"unet",val:""},{name:"scheduler",val:""}],parametersDescription:[{anchor:"diffusers.DDIMPipeline.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.DDIMPipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/main/en/api/schedulers/overview#diffusers.SchedulerMixin">SchedulerMixin</a>) &#x2014;
A scheduler to be used in combination with <code>unet</code> to denoise the encoded image. Can be one of
<a href="/docs/diffusers/main/en/api/schedulers/ddpm#diffusers.DDPMScheduler">DDPMScheduler</a>, or <a href="/docs/diffusers/main/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>.`,name:"scheduler"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/ddim/pipeline_ddim.py#L24"}}),Q=new Ve({props:{name:"__call__",anchor:"diffusers.DDIMPipeline.__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:"use_clipped_model_output",val:": typing.Optional[bool] = None"},{name:"output_type",val:": typing.Optional[str] = 'pil'"},{name:"return_dict",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.DDIMPipeline.__call__.batch_size",description:`<strong>batch_size</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The number of images to generate.`,name:"batch_size"},{anchor:"diffusers.DDIMPipeline.__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.DDIMPipeline.__call__.eta",description:`<strong>eta</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
Corresponds to parameter eta (&#x3B7;) from the <a href="https://arxiv.org/abs/2010.02502" rel="nofollow">DDIM</a> paper. Only applies
to the <a href="/docs/diffusers/main/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, and is ignored in other schedulers. A value of <code>0</code> corresponds to
DDIM and <code>1</code> corresponds to DDPM.`,name:"eta"},{anchor:"diffusers.DDIMPipeline.__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.DDIMPipeline.__call__.use_clipped_model_output",description:`<strong>use_clipped_model_output</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>None</code>) &#x2014;
If <code>True</code> or <code>False</code>, see documentation for <a href="/docs/diffusers/main/en/api/schedulers/ddim#diffusers.DDIMScheduler.step">DDIMScheduler.step()</a>. If <code>None</code>, nothing is passed
downstream to the scheduler (use <code>None</code> for schedulers which don&#x2019;t support this argument).`,name:"use_clipped_model_output"},{anchor:"diffusers.DDIMPipeline.__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.DDIMPipeline.__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/ddim#diffusers.ImagePipelineOutput">ImagePipelineOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/ddim/pipeline_ddim.py#L47",returnDescription:`
<p>If <code>return_dict</code> is <code>True</code>, <a
  href="/docs/diffusers/main/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/main/en/api/pipelines/ddim#diffusers.ImagePipelineOutput"
>ImagePipelineOutput</a> or <code>tuple</code></p>
`}}),j=new Dt({props:{anchor:"diffusers.DDIMPipeline.__call__.example",$$slots:{default:[Mt]},$$scope:{ctx:ie}}}),L=new qe({}),O=new Ve({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#L112"}}),{c(){f=a("meta"),I=c(),g=a("h1"),h=a("a"),D=a("span"),T(o.$$.fragment),M=c(),H=a("span"),ve=m("DDIM"),re=c(),Z=a("p"),N=a("a"),ye=m("Denoising Diffusion Implicit Models"),be=m(" (DDIM) by Jiaming Song, Chenlin Meng and Stefano Ermon."),oe=c(),q=a("p"),we=m("The abstract from the paper is:"),le=c(),X=a("p"),R=a("em"),Ie=m("Denoising diffusion probabilistic models (DDPMs) have achieved high quality image generation without adversarial training, yet they require simulating a Markov chain for many steps to produce a sample. To accelerate sampling, we present denoising diffusion implicit models (DDIMs), a more efficient class of iterative implicit probabilistic models with the same training procedure as DDPMs. In DDPMs, the generative process is defined as the reverse of a Markovian diffusion process. We construct a class of non-Markovian diffusion processes that lead to the same training objective, but whose reverse process can be much faster to sample from. We empirically demonstrate that DDIMs can produce high quality samples 10\xD7 to 50\xD7 faster in terms of wall-clock time compared to DDPMs, allow us to trade off computation for sample quality, and can perform semantically meaningful image interpolation directly in the latent space."),pe=c(),P=a("p"),Pe=m("The original codebase can be found at "),B=a("a"),$e=m("ermongroup/ddim"),je=m("."),ce=c(),y=a("h2"),$=a("a"),Y=a("span"),T(G.$$.fragment),Ue=c(),K=a("span"),Ee=m("DDIMPipeline"),de=c(),_=a("div"),T(A.$$.fragment),Te=c(),ee=a("p"),Se=m("Pipeline for image generation."),ke=c(),C=a("p"),Je=m("This model inherits from "),z=a("a"),xe=m("DiffusionPipeline"),We=m(`. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).`),Ze=c(),v=a("div"),T(Q.$$.fragment),Ne=c(),te=a("p"),Be=m("The call function to the pipeline for generation."),Ge=c(),T(j.$$.fragment),me=c(),b=a("h2"),U=a("a"),se=a("span"),T(L.$$.fragment),Ae=c(),ae=a("span"),Ce=m("ImagePipelineOutput"),ue=c(),w=a("div"),T(O.$$.fragment),Qe=c(),ne=a("p"),Le=m("Output class for image pipelines."),this.h()},l(e){const r=ft('[data-svelte="svelte-1phssyn"]',document.head);f=n(r,"META",{name:!0,content:!0}),r.forEach(t),I=d(e),g=n(e,"H1",{class:!0});var V=i(g);h=n(V,"A",{id:!0,class:!0,href:!0});var Xe=i(h);D=n(Xe,"SPAN",{});var ze=i(D);S(o.$$.fragment,ze),ze.forEach(t),Xe.forEach(t),M=d(V),H=n(V,"SPAN",{});var Fe=i(H);ve=u(Fe,"DDIM"),Fe.forEach(t),V.forEach(t),re=d(e),Z=n(e,"P",{});var Oe=i(Z);N=n(Oe,"A",{href:!0,rel:!0});var He=i(N);ye=u(He,"Denoising Diffusion Implicit Models"),He.forEach(t),be=u(Oe," (DDIM) by Jiaming Song, Chenlin Meng and Stefano Ermon."),Oe.forEach(t),oe=d(e),q=n(e,"P",{});var Re=i(q);we=u(Re,"The abstract from the paper is:"),Re.forEach(t),le=d(e),X=n(e,"P",{});var Ye=i(X);R=n(Ye,"EM",{});var Ke=i(R);Ie=u(Ke,"Denoising diffusion probabilistic models (DDPMs) have achieved high quality image generation without adversarial training, yet they require simulating a Markov chain for many steps to produce a sample. To accelerate sampling, we present denoising diffusion implicit models (DDIMs), a more efficient class of iterative implicit probabilistic models with the same training procedure as DDPMs. In DDPMs, the generative process is defined as the reverse of a Markovian diffusion process. We construct a class of non-Markovian diffusion processes that lead to the same training objective, but whose reverse process can be much faster to sample from. We empirically demonstrate that DDIMs can produce high quality samples 10\xD7 to 50\xD7 faster in terms of wall-clock time compared to DDPMs, allow us to trade off computation for sample quality, and can perform semantically meaningful image interpolation directly in the latent space."),Ke.forEach(t),Ye.forEach(t),pe=d(e),P=n(e,"P",{});var he=i(P);Pe=u(he,"The original codebase can be found at "),B=n(he,"A",{href:!0,rel:!0});var et=i(B);$e=u(et,"ermongroup/ddim"),et.forEach(t),je=u(he,"."),he.forEach(t),ce=d(e),y=n(e,"H2",{class:!0});var ge=i(y);$=n(ge,"A",{id:!0,class:!0,href:!0});var tt=i($);Y=n(tt,"SPAN",{});var st=i(Y);S(G.$$.fragment,st),st.forEach(t),tt.forEach(t),Ue=d(ge),K=n(ge,"SPAN",{});var at=i(K);Ee=u(at,"DDIMPipeline"),at.forEach(t),ge.forEach(t),de=d(e),_=n(e,"DIV",{class:!0});var E=i(_);S(A.$$.fragment,E),Te=d(E),ee=n(E,"P",{});var nt=i(ee);Se=u(nt,"Pipeline for image generation."),nt.forEach(t),ke=d(E),C=n(E,"P",{});var _e=i(C);Je=u(_e,"This model inherits from "),z=n(_e,"A",{href:!0});var it=i(z);xe=u(it,"DiffusionPipeline"),it.forEach(t),We=u(_e,`. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).`),_e.forEach(t),Ze=d(E),v=n(E,"DIV",{class:!0});var F=i(v);S(Q.$$.fragment,F),Ne=d(F),te=n(F,"P",{});var rt=i(te);Be=u(rt,"The call function to the pipeline for generation."),rt.forEach(t),Ge=d(F),S(j.$$.fragment,F),F.forEach(t),E.forEach(t),me=d(e),b=n(e,"H2",{class:!0});var De=i(b);U=n(De,"A",{id:!0,class:!0,href:!0});var ot=i(U);se=n(ot,"SPAN",{});var lt=i(se);S(L.$$.fragment,lt),lt.forEach(t),ot.forEach(t),Ae=d(De),ae=n(De,"SPAN",{});var pt=i(ae);Ce=u(pt,"ImagePipelineOutput"),pt.forEach(t),De.forEach(t),ue=d(e),w=n(e,"DIV",{class:!0});var Me=i(w);S(O.$$.fragment,Me),Qe=d(Me),ne=n(Me,"P",{});var ct=i(ne);Le=u(ct,"Output class for image pipelines."),ct.forEach(t),Me.forEach(t),this.h()},h(){l(f,"name","hf:doc:metadata"),l(f,"content",JSON.stringify(yt)),l(h,"id","ddim"),l(h,"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"),l(h,"href","#ddim"),l(g,"class","relative group"),l(N,"href","https://huggingface.co/papers/2010.02502"),l(N,"rel","nofollow"),l(B,"href","https://github.com/ermongroup/ddim"),l(B,"rel","nofollow"),l($,"id","diffusers.DDIMPipeline"),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"),l($,"href","#diffusers.DDIMPipeline"),l(y,"class","relative group"),l(z,"href","/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline"),l(v,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(_,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(U,"id","diffusers.ImagePipelineOutput"),l(U,"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"),l(U,"href","#diffusers.ImagePipelineOutput"),l(b,"class","relative group"),l(w,"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){s(document.head,f),p(e,I,r),p(e,g,r),s(g,h),s(h,D),k(o,D,null),s(g,M),s(g,H),s(H,ve),p(e,re,r),p(e,Z,r),s(Z,N),s(N,ye),s(Z,be),p(e,oe,r),p(e,q,r),s(q,we),p(e,le,r),p(e,X,r),s(X,R),s(R,Ie),p(e,pe,r),p(e,P,r),s(P,Pe),s(P,B),s(B,$e),s(P,je),p(e,ce,r),p(e,y,r),s(y,$),s($,Y),k(G,Y,null),s(y,Ue),s(y,K),s(K,Ee),p(e,de,r),p(e,_,r),k(A,_,null),s(_,Te),s(_,ee),s(ee,Se),s(_,ke),s(_,C),s(C,Je),s(C,z),s(z,xe),s(C,We),s(_,Ze),s(_,v),k(Q,v,null),s(v,Ne),s(v,te),s(te,Be),s(v,Ge),k(j,v,null),p(e,me,r),p(e,b,r),s(b,U),s(U,se),k(L,se,null),s(b,Ae),s(b,ae),s(ae,Ce),p(e,ue,r),p(e,w,r),k(O,w,null),s(w,Qe),s(w,ne),s(ne,Le),fe=!0},p(e,[r]){const V={};r&2&&(V.$$scope={dirty:r,ctx:e}),j.$set(V)},i(e){fe||(J(o.$$.fragment,e),J(G.$$.fragment,e),J(A.$$.fragment,e),J(Q.$$.fragment,e),J(j.$$.fragment,e),J(L.$$.fragment,e),J(O.$$.fragment,e),fe=!0)},o(e){x(o.$$.fragment,e),x(G.$$.fragment,e),x(A.$$.fragment,e),x(Q.$$.fragment,e),x(j.$$.fragment,e),x(L.$$.fragment,e),x(O.$$.fragment,e),fe=!1},d(e){t(f),e&&t(I),e&&t(g),W(o),e&&t(re),e&&t(Z),e&&t(oe),e&&t(q),e&&t(le),e&&t(X),e&&t(pe),e&&t(P),e&&t(ce),e&&t(y),W(G),e&&t(de),e&&t(_),W(A),W(Q),W(j),e&&t(me),e&&t(b),W(L),e&&t(ue),e&&t(w),W(O)}}}const yt={local:"ddim",sections:[{local:"diffusers.DDIMPipeline",title:"DDIMPipeline"},{local:"diffusers.ImagePipelineOutput",title:"ImagePipelineOutput"}],title:"DDIM"};function bt(ie){return ht(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ut extends dt{constructor(f){super();mt(this,f,bt,vt,ut,{})}}export{Ut as default,yt as metadata};
