import{s as _e,o as Me,n as De}from"../chunks/scheduler.182ea377.js";import{S as be,i as ye,g as r,s as i,r as y,A as Ie,h as p,f as s,c as o,j as E,u as I,x as D,k as V,y as u,a as n,v as w,d as $,t as v,w as P}from"../chunks/index.abf12888.js";import{D as le}from"../chunks/Docstring.93f6f462.js";import{C as we}from"../chunks/CodeBlock.57fe6e13.js";import{E as $e}from"../chunks/ExampleCodeBlock.658f5cd6.js";import{H as re}from"../chunks/Heading.16916d63.js";function ve(H){let l,j="Example:",h,c,m;return c=new we({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>)`,wrap:!1}}),{c(){l=r("p"),l.textContent=j,h=i(),y(c.$$.fragment)},l(a){l=p(a,"P",{"data-svelte-h":!0}),D(l)!=="svelte-11lpom8"&&(l.textContent=j),h=o(a),I(c.$$.fragment,a)},m(a,f){n(a,l,f),n(a,h,f),w(c,a,f),m=!0},p:De,i(a){m||($(c.$$.fragment,a),m=!0)},o(a){v(c.$$.fragment,a),m=!1},d(a){a&&(s(l),s(h)),P(c,a)}}}function Pe(H){let l,j,h,c,m,a,f,pe='<a href="https://huggingface.co/papers/2010.02502" rel="nofollow">Denoising Diffusion Implicit Models</a> (DDIM) by Jiaming Song, Chenlin Meng and Stefano Ermon.',O,T,de="The abstract from the paper is:",X,x,ce="<em>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× to 50× 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.</em>",z,U,me='The original codebase can be found at <a href="https://github.com/ermongroup/ddim" rel="nofollow">ermongroup/ddim</a>.',A,C,q,d,J,te,B,ue="Pipeline for image generation.",se,N,fe=`This model inherits from <a href="/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a>. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).`,ne,_,Z,ae,k,ge="The call function to the pipeline for generation.",ie,b,F,W,R,M,S,oe,G,he="Output class for image pipelines.",Y,Q,K;return m=new re({props:{title:"DDIM",local:"ddim",headingTag:"h1"}}),C=new re({props:{title:"DDIMPipeline",local:"diffusers.DDIMPipeline",headingTag:"h2"}}),J=new le({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"}}),Z=new le({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/audio_diffusion#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#L48",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>If <code>return_dict</code> is <code>True</code>, <a
  href="/docs/diffusers/main/en/api/pipelines/audio_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:`<script context="module">export const metadata = 'undefined';<\/script>


<p><a
  href="/docs/diffusers/main/en/api/pipelines/audio_diffusion#diffusers.ImagePipelineOutput"
>ImagePipelineOutput</a> or <code>tuple</code></p>
`}}),b=new $e({props:{anchor:"diffusers.DDIMPipeline.__call__.example",$$slots:{default:[ve]},$$scope:{ctx:H}}}),W=new re({props:{title:"ImagePipelineOutput",local:"diffusers.ImagePipelineOutput",headingTag:"h2"}}),S=new le({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(){l=r("meta"),j=i(),h=r("p"),c=i(),y(m.$$.fragment),a=i(),f=r("p"),f.innerHTML=pe,O=i(),T=r("p"),T.textContent=de,X=i(),x=r("p"),x.innerHTML=ce,z=i(),U=r("p"),U.innerHTML=me,A=i(),y(C.$$.fragment),q=i(),d=r("div"),y(J.$$.fragment),te=i(),B=r("p"),B.textContent=ue,se=i(),N=r("p"),N.innerHTML=fe,ne=i(),_=r("div"),y(Z.$$.fragment),ae=i(),k=r("p"),k.textContent=ge,ie=i(),y(b.$$.fragment),F=i(),y(W.$$.fragment),R=i(),M=r("div"),y(S.$$.fragment),oe=i(),G=r("p"),G.textContent=he,Y=i(),Q=r("p"),this.h()},l(e){const t=Ie("svelte-u9bgzb",document.head);l=p(t,"META",{name:!0,content:!0}),t.forEach(s),j=o(e),h=p(e,"P",{}),E(h).forEach(s),c=o(e),I(m.$$.fragment,e),a=o(e),f=p(e,"P",{"data-svelte-h":!0}),D(f)!=="svelte-1qeb1a3"&&(f.innerHTML=pe),O=o(e),T=p(e,"P",{"data-svelte-h":!0}),D(T)!=="svelte-1cwsb16"&&(T.textContent=de),X=o(e),x=p(e,"P",{"data-svelte-h":!0}),D(x)!=="svelte-ui1c4c"&&(x.innerHTML=ce),z=o(e),U=p(e,"P",{"data-svelte-h":!0}),D(U)!=="svelte-m1hmpt"&&(U.innerHTML=me),A=o(e),I(C.$$.fragment,e),q=o(e),d=p(e,"DIV",{class:!0});var g=E(d);I(J.$$.fragment,g),te=o(g),B=p(g,"P",{"data-svelte-h":!0}),D(B)!=="svelte-2egq7o"&&(B.textContent=ue),se=o(g),N=p(g,"P",{"data-svelte-h":!0}),D(N)!=="svelte-496sm0"&&(N.innerHTML=fe),ne=o(g),_=p(g,"DIV",{class:!0});var L=E(_);I(Z.$$.fragment,L),ae=o(L),k=p(L,"P",{"data-svelte-h":!0}),D(k)!=="svelte-50j04k"&&(k.textContent=ge),ie=o(L),I(b.$$.fragment,L),L.forEach(s),g.forEach(s),F=o(e),I(W.$$.fragment,e),R=o(e),M=p(e,"DIV",{class:!0});var ee=E(M);I(S.$$.fragment,ee),oe=o(ee),G=p(ee,"P",{"data-svelte-h":!0}),D(G)!=="svelte-19wetgi"&&(G.textContent=he),ee.forEach(s),Y=o(e),Q=p(e,"P",{}),E(Q).forEach(s),this.h()},h(){V(l,"name","hf:doc:metadata"),V(l,"content",je),V(_,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),V(d,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),V(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,t){u(document.head,l),n(e,j,t),n(e,h,t),n(e,c,t),w(m,e,t),n(e,a,t),n(e,f,t),n(e,O,t),n(e,T,t),n(e,X,t),n(e,x,t),n(e,z,t),n(e,U,t),n(e,A,t),w(C,e,t),n(e,q,t),n(e,d,t),w(J,d,null),u(d,te),u(d,B),u(d,se),u(d,N),u(d,ne),u(d,_),w(Z,_,null),u(_,ae),u(_,k),u(_,ie),w(b,_,null),n(e,F,t),w(W,e,t),n(e,R,t),n(e,M,t),w(S,M,null),u(M,oe),u(M,G),n(e,Y,t),n(e,Q,t),K=!0},p(e,[t]){const g={};t&2&&(g.$$scope={dirty:t,ctx:e}),b.$set(g)},i(e){K||($(m.$$.fragment,e),$(C.$$.fragment,e),$(J.$$.fragment,e),$(Z.$$.fragment,e),$(b.$$.fragment,e),$(W.$$.fragment,e),$(S.$$.fragment,e),K=!0)},o(e){v(m.$$.fragment,e),v(C.$$.fragment,e),v(J.$$.fragment,e),v(Z.$$.fragment,e),v(b.$$.fragment,e),v(W.$$.fragment,e),v(S.$$.fragment,e),K=!1},d(e){e&&(s(j),s(h),s(c),s(a),s(f),s(O),s(T),s(X),s(x),s(z),s(U),s(A),s(q),s(d),s(F),s(R),s(M),s(Y),s(Q)),s(l),P(m,e),P(C,e),P(J),P(Z),P(b),P(W,e),P(S)}}}const je='{"title":"DDIM","local":"ddim","sections":[{"title":"DDIMPipeline","local":"diffusers.DDIMPipeline","sections":[],"depth":2},{"title":"ImagePipelineOutput","local":"diffusers.ImagePipelineOutput","sections":[],"depth":2}],"depth":1}';function Te(H){return Me(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Se extends be{constructor(l){super(),ye(this,l,Te,Pe,_e,{})}}export{Se as component};
