import{s as $e,o as ve,n as Pe}from"../chunks/scheduler.182ea377.js";import{S as be,i as ye,g as p,s as o,r as b,A as De,h as d,f as n,c as r,j as z,u as y,x as P,k as W,y as f,a as i,v as D,d as w,t as x,w as N}from"../chunks/index.abf12888.js";import{T as we}from"../chunks/Tip.230e2334.js";import{D as pe}from"../chunks/Docstring.93f6f462.js";import{C as xe}from"../chunks/CodeBlock.57fe6e13.js";import{E as Ne}from"../chunks/ExampleCodeBlock.658f5cd6.js";import{H as de}from"../chunks/Heading.16916d63.js";function Ie(q){let s,_='Make sure to check out the Schedulers <a href="../../using-diffusers/schedulers">guide</a> to learn how to explore the tradeoff between scheduler speed and quality, and see the <a href="../../using-diffusers/loading#reuse-components-across-pipelines">reuse components across pipelines</a> section to learn how to efficiently load the same components into multiple pipelines.';return{c(){s=p("p"),s.innerHTML=_},l(l){s=d(l,"P",{"data-svelte-h":!0}),P(s)!=="svelte-1wmc0l4"&&(s.innerHTML=_)},m(l,c){i(l,s,c)},p:Pe,d(l){l&&n(s)}}}function Te(q){let s,_="Example:",l,c,m;return c=new xe({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFBORE1QaXBlbGluZSUwQSUwQSUyMyUyMGxvYWQlMjBtb2RlbCUyMGFuZCUyMHNjaGVkdWxlciUwQXBuZG0lMjAlM0QlMjBQTkRNUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUyMmdvb2dsZSUyRmRkcG0tY2lmYXIxMC0zMiUyMiklMEElMEElMjMlMjBydW4lMjBwaXBlbGluZSUyMGluJTIwaW5mZXJlbmNlJTIwKHNhbXBsZSUyMHJhbmRvbSUyMG5vaXNlJTIwYW5kJTIwZGVub2lzZSklMEFpbWFnZSUyMCUzRCUyMHBuZG0oKS5pbWFnZXMlNUIwJTVEJTBBJTBBJTIzJTIwc2F2ZSUyMGltYWdlJTBBaW1hZ2Uuc2F2ZSglMjJwbmRtX2dlbmVyYXRlZF9pbWFnZS5wbmclMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> PNDMPipeline

<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>pndm = PNDMPipeline.from_pretrained(<span class="hljs-string">&quot;google/ddpm-cifar10-32&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 = pndm().images[<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.save(<span class="hljs-string">&quot;pndm_generated_image.png&quot;</span>)`,wrap:!1}}),{c(){s=p("p"),s.textContent=_,l=o(),b(c.$$.fragment)},l(a){s=d(a,"P",{"data-svelte-h":!0}),P(s)!=="svelte-11lpom8"&&(s.textContent=_),l=r(a),y(c.$$.fragment,a)},m(a,h){i(a,s,h),i(a,l,h),D(c,a,h),m=!0},p:Pe,i(a){m||(w(c.$$.fragment,a),m=!0)},o(a){x(c.$$.fragment,a),m=!1},d(a){a&&(n(s),n(l)),N(c,a)}}}function Ce(q){let s,_,l,c,m,a,h,ce='<a href="https://huggingface.co/papers/2202.09778" rel="nofollow">Pseudo Numerical methods for Diffusion Models on manifolds</a> (PNDM) is by Luping Liu, Yi Ren, Zhijie Lin and Zhou Zhao.',R,C,ue="The abstract from the paper is:",F,U,me="<em>Denoising Diffusion Probabilistic Models (DDPMs) can generate high-quality samples such as image and audio samples. However, DDPMs require hundreds to thousands of iterations to produce final samples. Several prior works have successfully accelerated DDPMs through adjusting the variance schedule (e.g., Improved Denoising Diffusion Probabilistic Models) or the denoising equation (e.g., Denoising Diffusion Implicit Models (DDIMs)). However, these acceleration methods cannot maintain the quality of samples and even introduce new noise at a high speedup rate, which limit their practicability. To accelerate the inference process while keeping the sample quality, we provide a fresh perspective that DDPMs should be treated as solving differential equations on manifolds. Under such a perspective, we propose pseudo numerical methods for diffusion models (PNDMs). Specifically, we figure out how to solve differential equations on manifolds and show that DDIMs are simple cases of pseudo numerical methods. We change several classical numerical methods to corresponding pseudo numerical methods and find that the pseudo linear multi-step method is the best in most situations. According to our experiments, by directly using pre-trained models on Cifar10, CelebA and LSUN, PNDMs can generate higher quality synthetic images with only 50 steps compared with 1000-step DDIMs (20x speedup), significantly outperform DDIMs with 250 steps (by around 0.4 in FID) and have good generalization on different variance schedules.</em>",V,j,fe='The original codebase can be found at <a href="https://github.com/luping-liu/PNDM" rel="nofollow">luping-liu/PNDM</a>.',X,I,A,L,Q,u,S,se,B,he="Pipeline for unconditional image generation.",ie,H,ge=`This model inherits from <a href="/docs/diffusers/v0.22.3/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.).`,ae,M,Z,oe,E,_e="The call function to the pipeline for generation.",re,T,Y,k,K,$,G,le,O,Me="Output class for image pipelines.",ee,J,te;return m=new de({props:{title:"PNDM",local:"pndm",headingTag:"h1"}}),I=new we({props:{$$slots:{default:[Ie]},$$scope:{ctx:q}}}),L=new de({props:{title:"PNDMPipeline",local:"diffusers.PNDMPipeline",headingTag:"h2"}}),S=new pe({props:{name:"class diffusers.PNDMPipeline",anchor:"diffusers.PNDMPipeline",parameters:[{name:"unet",val:": UNet2DModel"},{name:"scheduler",val:": PNDMScheduler"}],parametersDescription:[{anchor:"diffusers.PNDMPipeline.unet",description:`<strong>unet</strong> (<a href="/docs/diffusers/v0.22.3/en/api/models/unet2d#diffusers.UNet2DModel">UNet2DModel</a>) &#x2014;
A <code>UNet2DModel</code> to denoise the encoded image latents.`,name:"unet"},{anchor:"diffusers.PNDMPipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/v0.22.3/en/api/schedulers/pndm#diffusers.PNDMScheduler">PNDMScheduler</a>) &#x2014;
A <code>PNDMScheduler</code> to be used in combination with <code>unet</code> to denoise the encoded image.`,name:"scheduler"}],source:"https://github.com/huggingface/diffusers/blob/v0.22.3/src/diffusers/pipelines/pndm/pipeline_pndm.py#L26"}}),Z=new pe({props:{name:"__call__",anchor:"diffusers.PNDMPipeline.__call__",parameters:[{name:"batch_size",val:": int = 1"},{name:"num_inference_steps",val:": int = 50"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"output_type",val:": typing.Optional[str] = 'pil'"},{name:"return_dict",val:": bool = True"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.PNDMPipeline.__call__.batch_size",description:`<strong>batch_size</strong> (<code>int</code>, <code>optional</code>, defaults to 1) &#x2014;
The number of images to generate.`,name:"batch_size"},{anchor:"diffusers.PNDMPipeline.__call__.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, <code>optional</code>, 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.PNDMPipeline.__call__.generator",description:`<strong>generator</strong> (<code>torch.Generator</code>, <code>optional</code>) &#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.PNDMPipeline.__call__.output_type",description:`<strong>output_type</strong> (<code>str</code>, <code>optional</code>, 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.PNDMPipeline.__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.22.3/en/api/pipelines/ddim#diffusers.ImagePipelineOutput">ImagePipelineOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/v0.22.3/src/diffusers/pipelines/pndm/pipeline_pndm.py#L50",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


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


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