import{S as ft,i as ht,s as mt,e as i,k as m,w as x,t as c,M as gt,c as n,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 vt,L as _t}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,v,o,_,$;return{c(){l=i("p"),D=c("Make sure to check out the Schedulers "),f=i("a"),h=c("guide"),v=c(" to learn how to explore the tradeoff between scheduler speed and quality, and see the "),o=i("a"),_=c("reuse components across pipelines"),$=c(" section to learn how to efficiently load the same components into multiple pipelines."),this.h()},l(N){l=n(N,"P",{});var P=a(l);D=u(P,"Make sure to check out the Schedulers "),f=n(P,"A",{href:!0});var b=a(f);h=u(b,"guide"),b.forEach(t),v=u(P," to learn how to explore the tradeoff between scheduler speed and quality, and see the "),o=n(P,"A",{href:!0});var y=a(o);_=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,v),s(l,o),s(o,_),s(l,$)},d(N){N&&t(l)}}}function yt(X){let l,D,f,h,v;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=i("p"),D=c("Example:"),f=m(),x(h.$$.fragment)},l(o){l=n(o,"P",{});var _=a(l);D=u(_,"Example:"),_.forEach(t),f=g(o),S(h.$$.fragment,o)},m(o,_){d(o,l,_),s(l,D),d(o,f,_),U(h,o,_),v=!0},p:_t,i(o){v||(T(h.$$.fragment,o),v=!0)},o(o){j(h.$$.fragment,o),v=!1},d(o){o&&t(l),o&&t(f),q(h,o)}}}function wt(X){let l,D,f,h,v,o,_,$,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,ie,Ue,me,M,W,Te,ne,je,qe,R,Ze,K,Ae,Ge,Le,w,z,Ce,ae,Oe,Be,L,ge,E,C,oe,F,Je,re,We,ve,k,H,Re,le,ze,_e;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/v0.19.0/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.19.0/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.19.0/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/v0.19.0/en/api/pipelines/latent_diffusion#diffusers.ImagePipelineOutput">ImagePipelineOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/v0.19.0/src/diffusers/pipelines/pndm/pipeline_pndm.py#L50",returnDescription:`
<p>If <code>return_dict</code> is <code>True</code>, <a
  href="/docs/diffusers/v0.19.0/en/api/pipelines/latent_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:`
<p><a
  href="/docs/diffusers/v0.19.0/en/api/pipelines/latent_diffusion#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/v0.19.0/src/diffusers/pipelines/pipeline_utils.py#L113"}}),{c(){l=i("meta"),D=m(),f=i("h1"),h=i("a"),v=i("span"),x(o.$$.fragment),_=m(),$=i("span"),N=c("PNDM"),P=m(),b=i("p"),y=i("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=i("p"),Ne=c("The abstract from the paper is:"),ce=m(),Q=i("p"),te=i("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=i("p"),Ee=c("The original codebase can be found at "),B=i("a"),ke=c("luping-liu/PNDM"),xe=c("."),fe=m(),x(A.$$.fragment),he=m(),I=i("h2"),G=i("a"),se=i("span"),x(J.$$.fragment),Se=m(),ie=i("span"),Ue=c("PNDMPipeline"),me=m(),M=i("div"),x(W.$$.fragment),Te=m(),ne=i("p"),je=c("Pipeline for unconditional image generation."),qe=m(),R=i("p"),Ze=c("This model inherits from "),K=i("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=i("div"),x(z.$$.fragment),Ce=m(),ae=i("p"),Oe=c("The call function to the pipeline for generation."),Be=m(),x(L.$$.fragment),ge=m(),E=i("h2"),C=i("a"),oe=i("span"),x(F.$$.fragment),Je=m(),re=i("span"),We=c("ImagePipelineOutput"),ve=m(),k=i("div"),x(H.$$.fragment),Re=m(),le=i("p"),ze=c("Output class for image pipelines."),this.h()},l(e){const r=gt('[data-svelte="svelte-1phssyn"]',document.head);l=n(r,"META",{name:!0,content:!0}),r.forEach(t),D=g(e),f=n(e,"H1",{class:!0});var V=a(f);h=n(V,"A",{id:!0,class:!0,href:!0});var pe=a(h);v=n(pe,"SPAN",{});var Xe=a(v);S(o.$$.fragment,Xe),Xe.forEach(t),pe.forEach(t),_=g(V),$=n(V,"SPAN",{});var Ye=a($);N=u(Ye,"PNDM"),Ye.forEach(t),V.forEach(t),P=g(e),b=n(e,"P",{});var Fe=a(b);y=n(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=n(e,"P",{});var Ke=a(Y);Ne=u(Ke,"The abstract from the paper is:"),Ke.forEach(t),ce=g(e),Q=n(e,"P",{});var et=a(Q);te=n(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=n(e,"P",{});var Pe=a(Z);Ee=u(Pe,"The original codebase can be found at "),B=n(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=n(e,"H2",{class:!0});var Me=a(I);G=n(Me,"A",{id:!0,class:!0,href:!0});var it=a(G);se=n(it,"SPAN",{});var nt=a(se);S(J.$$.fragment,nt),nt.forEach(t),it.forEach(t),Se=g(Me),ie=n(Me,"SPAN",{});var at=a(ie);Ue=u(at,"PNDMPipeline"),at.forEach(t),Me.forEach(t),me=g(e),M=n(e,"DIV",{class:!0});var O=a(M);S(W.$$.fragment,O),Te=g(O),ne=n(O,"P",{});var ot=a(ne);je=u(ot,"Pipeline for unconditional image generation."),ot.forEach(t),qe=g(O),R=n(O,"P",{});var De=a(R);Ze=u(De,"This model inherits from "),K=n(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=n(O,"DIV",{class:!0});var ee=a(w);S(z.$$.fragment,ee),Ce=g(ee),ae=n(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=n(e,"H2",{class:!0});var be=a(E);C=n(be,"A",{id:!0,class:!0,href:!0});var pt=a(C);oe=n(pt,"SPAN",{});var dt=a(oe);S(F.$$.fragment,dt),dt.forEach(t),pt.forEach(t),Je=g(be),re=n(be,"SPAN",{});var ct=a(re);We=u(ct,"ImagePipelineOutput"),ct.forEach(t),be.forEach(t),ve=g(e),k=n(e,"DIV",{class:!0});var ye=a(k);S(H.$$.fragment,ye),Re=g(ye),le=n(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/v0.19.0/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,v),U(o,v,null),s(f,_),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,ie),s(ie,Ue),d(e,me,r),d(e,M,r),U(W,M,null),s(M,Te),s(M,ne),s(ne,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,ve,r),d(e,k,r),U(H,k,null),s(k,Re),s(k,le),s(le,ze),_e=!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){_e||(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),_e=!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),_e=!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(ve),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 vt(()=>{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};
