import{S as ft,i as ht,s as mt,e as n,k as m,w as x,t as c,M as gt,c as i,d as t,m as g,a,x as S,h as u,b as p,G as s,g as d,y as U,q as T,o as j,B as q,v as _t,L as vt}from"../../../chunks/vendor-hf-doc-builder.js";import{T as Pt}from"../../../chunks/Tip-hf-doc-builder.js";import{D as He}from"../../../chunks/Docstring-hf-doc-builder.js";import{C as Mt}from"../../../chunks/CodeBlock-hf-doc-builder.js";import{I as Ve}from"../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as Dt}from"../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function bt(X){let l,D,f,h,_,o,v,$;return{c(){l=n("p"),D=c("Make sure to check out the Schedulers "),f=n("a"),h=c("guide"),_=c(" to learn how to explore the tradeoff between scheduler speed and quality, and see the "),o=n("a"),v=c("reuse components across pipelines"),$=c(" section to learn how to efficiently load the same components into multiple pipelines."),this.h()},l(N){l=i(N,"P",{});var P=a(l);D=u(P,"Make sure to check out the Schedulers "),f=i(P,"A",{href:!0});var b=a(f);h=u(b,"guide"),b.forEach(t),_=u(P," to learn how to explore the tradeoff between scheduler speed and quality, and see the "),o=i(P,"A",{href:!0});var y=a(o);v=u(y,"reuse components across pipelines"),y.forEach(t),$=u(P," section to learn how to efficiently load the same components into multiple pipelines."),P.forEach(t),this.h()},h(){p(f,"href","/using-diffusers/schedulers"),p(o,"href","/using-diffusers/loading#reuse-components-across-pipelines")},m(N,P){d(N,l,P),s(l,D),s(l,f),s(f,h),s(l,_),s(l,o),s(o,v),s(l,$)},d(N){N&&t(l)}}}function yt(X){let l,D,f,h,_;return h=new Mt({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>)`}}),{c(){l=n("p"),D=c("Example:"),f=m(),x(h.$$.fragment)},l(o){l=i(o,"P",{});var v=a(l);D=u(v,"Example:"),v.forEach(t),f=g(o),S(h.$$.fragment,o)},m(o,v){d(o,l,v),s(l,D),d(o,f,v),U(h,o,v),_=!0},p:vt,i(o){_||(T(h.$$.fragment,o),_=!0)},o(o){j(h.$$.fragment,o),_=!1},d(o){o&&t(l),o&&t(f),q(h,o)}}}function wt(X){let l,D,f,h,_,o,v,$,N,P,b,y,we,$e,de,Y,Ne,ce,Q,te,Ie,ue,Z,Ee,B,ke,xe,fe,A,he,I,G,se,J,Se,ne,Ue,me,M,W,Te,ie,je,qe,R,Ze,K,Ae,Ge,Le,w,z,Ce,ae,Oe,Be,L,ge,E,C,oe,F,Je,re,We,_e,k,H,Re,le,ze,ve;return o=new Ve({}),A=new Pt({props:{$$slots:{default:[bt]},$$scope:{ctx:X}}}),J=new Ve({}),W=new He({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/main/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/main/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/main/src/diffusers/pipelines/pndm/pipeline_pndm.py#L26"}}),z=new He({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/main/en/api/pipelines/latent_diffusion_uncond#diffusers.ImagePipelineOutput">ImagePipelineOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pndm/pipeline_pndm.py#L50",returnDescription:`
<p>If <code>return_dict</code> is <code>True</code>, <a
  href="/docs/diffusers/main/en/api/pipelines/latent_diffusion_uncond#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_uncond#diffusers.ImagePipelineOutput"
>ImagePipelineOutput</a> or <code>tuple</code></p>
`}}),L=new Dt({props:{anchor:"diffusers.PNDMPipeline.__call__.example",$$slots:{default:[yt]},$$scope:{ctx:X}}}),F=new Ve({}),H=new He({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=n("meta"),D=m(),f=n("h1"),h=n("a"),_=n("span"),x(o.$$.fragment),v=m(),$=n("span"),N=c("PNDM"),P=m(),b=n("p"),y=n("a"),we=c("Pseudo Numerical methods for Diffusion Models on manifolds"),$e=c(" (PNDM) is by Luping Liu, Yi Ren, Zhijie Lin and Zhou Zhao."),de=m(),Y=n("p"),Ne=c("The abstract from the paper is:"),ce=m(),Q=n("p"),te=n("em"),Ie=c("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."),ue=m(),Z=n("p"),Ee=c("The original codebase can be found at "),B=n("a"),ke=c("luping-liu/PNDM"),xe=c("."),fe=m(),x(A.$$.fragment),he=m(),I=n("h2"),G=n("a"),se=n("span"),x(J.$$.fragment),Se=m(),ne=n("span"),Ue=c("PNDMPipeline"),me=m(),M=n("div"),x(W.$$.fragment),Te=m(),ie=n("p"),je=c("Pipeline for unconditional image generation."),qe=m(),R=n("p"),Ze=c("This model inherits from "),K=n("a"),Ae=c("DiffusionPipeline"),Ge=c(`. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).`),Le=m(),w=n("div"),x(z.$$.fragment),Ce=m(),ae=n("p"),Oe=c("The call function to the pipeline for generation."),Be=m(),x(L.$$.fragment),ge=m(),E=n("h2"),C=n("a"),oe=n("span"),x(F.$$.fragment),Je=m(),re=n("span"),We=c("ImagePipelineOutput"),_e=m(),k=n("div"),x(H.$$.fragment),Re=m(),le=n("p"),ze=c("Output class for image pipelines."),this.h()},l(e){const r=gt('[data-svelte="svelte-1phssyn"]',document.head);l=i(r,"META",{name:!0,content:!0}),r.forEach(t),D=g(e),f=i(e,"H1",{class:!0});var V=a(f);h=i(V,"A",{id:!0,class:!0,href:!0});var pe=a(h);_=i(pe,"SPAN",{});var Xe=a(_);S(o.$$.fragment,Xe),Xe.forEach(t),pe.forEach(t),v=g(V),$=i(V,"SPAN",{});var Ye=a($);N=u(Ye,"PNDM"),Ye.forEach(t),V.forEach(t),P=g(e),b=i(e,"P",{});var Fe=a(b);y=i(Fe,"A",{href:!0,rel:!0});var Qe=a(y);we=u(Qe,"Pseudo Numerical methods for Diffusion Models on manifolds"),Qe.forEach(t),$e=u(Fe," (PNDM) is by Luping Liu, Yi Ren, Zhijie Lin and Zhou Zhao."),Fe.forEach(t),de=g(e),Y=i(e,"P",{});var Ke=a(Y);Ne=u(Ke,"The abstract from the paper is:"),Ke.forEach(t),ce=g(e),Q=i(e,"P",{});var et=a(Q);te=i(et,"EM",{});var tt=a(te);Ie=u(tt,"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."),tt.forEach(t),et.forEach(t),ue=g(e),Z=i(e,"P",{});var Pe=a(Z);Ee=u(Pe,"The original codebase can be found at "),B=i(Pe,"A",{href:!0,rel:!0});var st=a(B);ke=u(st,"luping-liu/PNDM"),st.forEach(t),xe=u(Pe,"."),Pe.forEach(t),fe=g(e),S(A.$$.fragment,e),he=g(e),I=i(e,"H2",{class:!0});var Me=a(I);G=i(Me,"A",{id:!0,class:!0,href:!0});var nt=a(G);se=i(nt,"SPAN",{});var it=a(se);S(J.$$.fragment,it),it.forEach(t),nt.forEach(t),Se=g(Me),ne=i(Me,"SPAN",{});var at=a(ne);Ue=u(at,"PNDMPipeline"),at.forEach(t),Me.forEach(t),me=g(e),M=i(e,"DIV",{class:!0});var O=a(M);S(W.$$.fragment,O),Te=g(O),ie=i(O,"P",{});var ot=a(ie);je=u(ot,"Pipeline for unconditional image generation."),ot.forEach(t),qe=g(O),R=i(O,"P",{});var De=a(R);Ze=u(De,"This model inherits from "),K=i(De,"A",{href:!0});var rt=a(K);Ae=u(rt,"DiffusionPipeline"),rt.forEach(t),Ge=u(De,`. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).`),De.forEach(t),Le=g(O),w=i(O,"DIV",{class:!0});var ee=a(w);S(z.$$.fragment,ee),Ce=g(ee),ae=i(ee,"P",{});var lt=a(ae);Oe=u(lt,"The call function to the pipeline for generation."),lt.forEach(t),Be=g(ee),S(L.$$.fragment,ee),ee.forEach(t),O.forEach(t),ge=g(e),E=i(e,"H2",{class:!0});var be=a(E);C=i(be,"A",{id:!0,class:!0,href:!0});var pt=a(C);oe=i(pt,"SPAN",{});var dt=a(oe);S(F.$$.fragment,dt),dt.forEach(t),pt.forEach(t),Je=g(be),re=i(be,"SPAN",{});var ct=a(re);We=u(ct,"ImagePipelineOutput"),ct.forEach(t),be.forEach(t),_e=g(e),k=i(e,"DIV",{class:!0});var ye=a(k);S(H.$$.fragment,ye),Re=g(ye),le=i(ye,"P",{});var ut=a(le);ze=u(ut,"Output class for image pipelines."),ut.forEach(t),ye.forEach(t),this.h()},h(){p(l,"name","hf:doc:metadata"),p(l,"content",JSON.stringify($t)),p(h,"id","pndm"),p(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"),p(h,"href","#pndm"),p(f,"class","relative group"),p(y,"href","https://huggingface.co/papers/2202.09778"),p(y,"rel","nofollow"),p(B,"href","https://github.com/luping-liu/PNDM"),p(B,"rel","nofollow"),p(G,"id","diffusers.PNDMPipeline"),p(G,"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(G,"href","#diffusers.PNDMPipeline"),p(I,"class","relative group"),p(K,"href","/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline"),p(w,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),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(C,"id","diffusers.ImagePipelineOutput"),p(C,"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(C,"href","#diffusers.ImagePipelineOutput"),p(E,"class","relative group"),p(k,"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,l),d(e,D,r),d(e,f,r),s(f,h),s(h,_),U(o,_,null),s(f,v),s(f,$),s($,N),d(e,P,r),d(e,b,r),s(b,y),s(y,we),s(b,$e),d(e,de,r),d(e,Y,r),s(Y,Ne),d(e,ce,r),d(e,Q,r),s(Q,te),s(te,Ie),d(e,ue,r),d(e,Z,r),s(Z,Ee),s(Z,B),s(B,ke),s(Z,xe),d(e,fe,r),U(A,e,r),d(e,he,r),d(e,I,r),s(I,G),s(G,se),U(J,se,null),s(I,Se),s(I,ne),s(ne,Ue),d(e,me,r),d(e,M,r),U(W,M,null),s(M,Te),s(M,ie),s(ie,je),s(M,qe),s(M,R),s(R,Ze),s(R,K),s(K,Ae),s(R,Ge),s(M,Le),s(M,w),U(z,w,null),s(w,Ce),s(w,ae),s(ae,Oe),s(w,Be),U(L,w,null),d(e,ge,r),d(e,E,r),s(E,C),s(C,oe),U(F,oe,null),s(E,Je),s(E,re),s(re,We),d(e,_e,r),d(e,k,r),U(H,k,null),s(k,Re),s(k,le),s(le,ze),ve=!0},p(e,[r]){const V={};r&2&&(V.$$scope={dirty:r,ctx:e}),A.$set(V);const pe={};r&2&&(pe.$$scope={dirty:r,ctx:e}),L.$set(pe)},i(e){ve||(T(o.$$.fragment,e),T(A.$$.fragment,e),T(J.$$.fragment,e),T(W.$$.fragment,e),T(z.$$.fragment,e),T(L.$$.fragment,e),T(F.$$.fragment,e),T(H.$$.fragment,e),ve=!0)},o(e){j(o.$$.fragment,e),j(A.$$.fragment,e),j(J.$$.fragment,e),j(W.$$.fragment,e),j(z.$$.fragment,e),j(L.$$.fragment,e),j(F.$$.fragment,e),j(H.$$.fragment,e),ve=!1},d(e){t(l),e&&t(D),e&&t(f),q(o),e&&t(P),e&&t(b),e&&t(de),e&&t(Y),e&&t(ce),e&&t(Q),e&&t(ue),e&&t(Z),e&&t(fe),q(A,e),e&&t(he),e&&t(I),q(J),e&&t(me),e&&t(M),q(W),q(z),q(L),e&&t(ge),e&&t(E),q(F),e&&t(_e),e&&t(k),q(H)}}}const $t={local:"pndm",sections:[{local:"diffusers.PNDMPipeline",title:"PNDMPipeline"},{local:"diffusers.ImagePipelineOutput",title:"ImagePipelineOutput"}],title:"PNDM"};function Nt(X){return _t(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Tt extends ft{constructor(l){super();ht(this,l,Nt,wt,mt,{})}}export{Tt as default,$t as metadata};
