import{s as Le,n as Ee,o as Oe}from"../chunks/scheduler.8c3d61f6.js";import{S as He,i as qe,g as a,s as n,r as m,A as Ie,h as d,f as t,c as o,j as P,u as h,x as u,k as M,y as r,a as c,v as g,d as _,t as b,w as v}from"../chunks/index.589a98e8.js";import{D as B}from"../chunks/Docstring.27406313.js";import{H as ke,E as Ue}from"../chunks/EditOnGithub.e5a8d9cb.js";function Ve(xe){let p,W,F,J,T,Q,w,$e='The <code>KDPM2DiscreteScheduler</code> with ancestral sampling is inspired by the <a href="https://huggingface.co/papers/2206.00364" rel="nofollow">Elucidating the Design Space of Diffusion-Based Generative Models</a> paper, and the scheduler is ported from and created by <a href="https://github.com/crowsonkb/" rel="nofollow">Katherine Crowson</a>.',X,y,Se='The original codebase can be found at <a href="https://github.com/crowsonkb/k-diffusion" rel="nofollow">crowsonkb/k-diffusion</a>.',Y,A,Z,i,K,le,I,Pe=`KDPM2DiscreteScheduler with ancestral sampling is inspired by the DPMSolver2 and Algorithm 2 from the <a href="https://huggingface.co/papers/2206.00364" rel="nofollow">Elucidating
the Design Space of Diffusion-Based Generative Models</a> paper.`,ue,U,Me=`This model inherits from <a href="/docs/diffusers/pr_8428/en/api/schedulers/overview#diffusers.SchedulerMixin">SchedulerMixin</a> and <a href="/docs/diffusers/pr_8428/en/api/configuration#diffusers.ConfigMixin">ConfigMixin</a>. Check the superclass documentation for the generic
methods the library implements for all schedulers such as loading and saving.`,pe,D,C,fe,V,Te=`Ensures interchangeability with schedulers that need to scale the denoising model input depending on the
current timestep.`,me,x,k,he,N,we="Sets the begin index for the scheduler. This function should be run from pipeline before the inference.",ge,$,L,_e,z,ye="Sets the discrete timesteps used for the diffusion chain (to be run before inference).",be,S,E,ve,j,Ae=`Predict the sample from the previous timestep by reversing the SDE. This function propagates the diffusion
process from the learned model outputs (most often the predicted noise).`,ee,O,Ke="## SchedulerOutput[[diffusers.schedulers.scheduling_utils.SchedulerOutput]]",te,f,H,De,G,Ce="Base class for the output of a scheduler’s <code>step</code> function.",se,q,re,R,ne;return T=new ke({props:{title:"KDPM2AncestralDiscreteScheduler",local:"kdpm2ancestraldiscretescheduler",headingTag:"h1"}}),A=new ke({props:{title:"KDPM2AncestralDiscreteScheduler",local:"diffusers.KDPM2AncestralDiscreteScheduler",headingTag:"h2"}}),K=new B({props:{name:"class diffusers.KDPM2AncestralDiscreteScheduler",anchor:"diffusers.KDPM2AncestralDiscreteScheduler",parameters:[{name:"num_train_timesteps",val:": int = 1000"},{name:"beta_start",val:": float = 0.00085"},{name:"beta_end",val:": float = 0.012"},{name:"beta_schedule",val:": str = 'linear'"},{name:"trained_betas",val:": Union = None"},{name:"use_karras_sigmas",val:": Optional = False"},{name:"prediction_type",val:": str = 'epsilon'"},{name:"timestep_spacing",val:": str = 'linspace'"},{name:"steps_offset",val:": int = 0"}],parametersDescription:[{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.num_train_timesteps",description:`<strong>num_train_timesteps</strong> (<code>int</code>, defaults to 1000) &#x2014;
The number of diffusion steps to train the model.`,name:"num_train_timesteps"},{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.beta_start",description:`<strong>beta_start</strong> (<code>float</code>, defaults to 0.00085) &#x2014;
The starting <code>beta</code> value of inference.`,name:"beta_start"},{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.beta_end",description:`<strong>beta_end</strong> (<code>float</code>, defaults to 0.012) &#x2014;
The final <code>beta</code> value.`,name:"beta_end"},{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.beta_schedule",description:`<strong>beta_schedule</strong> (<code>str</code>, defaults to <code>&quot;linear&quot;</code>) &#x2014;
The beta schedule, a mapping from a beta range to a sequence of betas for stepping the model. Choose from
<code>linear</code> or <code>scaled_linear</code>.`,name:"beta_schedule"},{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.trained_betas",description:`<strong>trained_betas</strong> (<code>np.ndarray</code>, <em>optional</em>) &#x2014;
Pass an array of betas directly to the constructor to bypass <code>beta_start</code> and <code>beta_end</code>.`,name:"trained_betas"},{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.use_karras_sigmas",description:`<strong>use_karras_sigmas</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to use Karras sigmas for step sizes in the noise schedule during the sampling process. If <code>True</code>,
the sigmas are determined according to a sequence of noise levels {&#x3C3;i}.`,name:"use_karras_sigmas"},{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.prediction_type",description:`<strong>prediction_type</strong> (<code>str</code>, defaults to <code>epsilon</code>, <em>optional</em>) &#x2014;
Prediction type of the scheduler function; can be <code>epsilon</code> (predicts the noise of the diffusion process),
<code>sample</code> (directly predicts the noisy sample<code>) or </code>v_prediction\` (see section 2.4 of <a href="https://imagen.research.google/video/paper.pdf" rel="nofollow">Imagen
Video</a> paper).`,name:"prediction_type"},{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.timestep_spacing",description:`<strong>timestep_spacing</strong> (<code>str</code>, defaults to <code>&quot;linspace&quot;</code>) &#x2014;
The way the timesteps should be scaled. Refer to Table 2 of the <a href="https://huggingface.co/papers/2305.08891" rel="nofollow">Common Diffusion Noise Schedules and
Sample Steps are Flawed</a> for more information.`,name:"timestep_spacing"},{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.steps_offset",description:`<strong>steps_offset</strong> (<code>int</code>, defaults to 0) &#x2014;
An offset added to the inference steps, as required by some model families.`,name:"steps_offset"}],source:"https://github.com/huggingface/diffusers/blob/vr_8428/src/diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py#L71"}}),C=new B({props:{name:"scale_model_input",anchor:"diffusers.KDPM2AncestralDiscreteScheduler.scale_model_input",parameters:[{name:"sample",val:": Tensor"},{name:"timestep",val:": Union"}],parametersDescription:[{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.scale_model_input.sample",description:`<strong>sample</strong> (<code>torch.Tensor</code>) &#x2014;
The input sample.`,name:"sample"},{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.scale_model_input.timestep",description:`<strong>timestep</strong> (<code>int</code>, <em>optional</em>) &#x2014;
The current timestep in the diffusion chain.`,name:"timestep"}],source:"https://github.com/huggingface/diffusers/blob/vr_8428/src/diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py#L176",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A scaled input sample.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>torch.Tensor</code></p>
`}}),k=new B({props:{name:"set_begin_index",anchor:"diffusers.KDPM2AncestralDiscreteScheduler.set_begin_index",parameters:[{name:"begin_index",val:": int = 0"}],parametersDescription:[{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.set_begin_index.begin_index",description:`<strong>begin_index</strong> (<code>int</code>) &#x2014;
The begin index for the scheduler.`,name:"begin_index"}],source:"https://github.com/huggingface/diffusers/blob/vr_8428/src/diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py#L166"}}),L=new B({props:{name:"set_timesteps",anchor:"diffusers.KDPM2AncestralDiscreteScheduler.set_timesteps",parameters:[{name:"num_inference_steps",val:": int"},{name:"device",val:": Union = None"},{name:"num_train_timesteps",val:": Optional = None"}],parametersDescription:[{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.set_timesteps.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>) &#x2014;
The number of diffusion steps used when generating samples with a pre-trained model.`,name:"num_inference_steps"},{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.set_timesteps.device",description:`<strong>device</strong> (<code>str</code> or <code>torch.device</code>, <em>optional</em>) &#x2014;
The device to which the timesteps should be moved to. If <code>None</code>, the timesteps are not moved.`,name:"device"}],source:"https://github.com/huggingface/diffusers/blob/vr_8428/src/diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py#L206"}}),E=new B({props:{name:"step",anchor:"diffusers.KDPM2AncestralDiscreteScheduler.step",parameters:[{name:"model_output",val:": Union"},{name:"timestep",val:": Union"},{name:"sample",val:": Union"},{name:"generator",val:": Optional = None"},{name:"return_dict",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.step.model_output",description:`<strong>model_output</strong> (<code>torch.Tensor</code>) &#x2014;
The direct output from learned diffusion model.`,name:"model_output"},{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.step.timestep",description:`<strong>timestep</strong> (<code>float</code>) &#x2014;
The current discrete timestep in the diffusion chain.`,name:"timestep"},{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.step.sample",description:`<strong>sample</strong> (<code>torch.Tensor</code>) &#x2014;
A current instance of a sample created by the diffusion process.`,name:"sample"},{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.step.generator",description:`<strong>generator</strong> (<code>torch.Generator</code>, <em>optional</em>) &#x2014;
A random number generator.`,name:"generator"},{anchor:"diffusers.KDPM2AncestralDiscreteScheduler.step.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>) &#x2014;
Whether or not to return a <a href="/docs/diffusers/pr_8428/en/api/schedulers/overview#diffusers.schedulers.scheduling_utils.SchedulerOutput">SchedulerOutput</a> or tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/vr_8428/src/diffusers/schedulers/scheduling_k_dpm_2_ancestral_discrete.py#L377",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>If return_dict is <code>True</code>, <code>~schedulers.scheduling_ddim.SchedulerOutput</code> is returned, otherwise a
tuple is returned where the first element is the sample tensor.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><a
  href="/docs/diffusers/pr_8428/en/api/schedulers/overview#diffusers.schedulers.scheduling_utils.SchedulerOutput"
>SchedulerOutput</a> or <code>tuple</code></p>
`}}),H=new B({props:{name:"class diffusers.schedulers.scheduling_utils.SchedulerOutput",anchor:"diffusers.schedulers.scheduling_utils.SchedulerOutput",parameters:[{name:"prev_sample",val:": Tensor"}],parametersDescription:[{anchor:"diffusers.schedulers.scheduling_utils.SchedulerOutput.prev_sample",description:`<strong>prev_sample</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_channels, height, width)</code> for images) &#x2014;
Computed sample <code>(x_{t-1})</code> of previous timestep. <code>prev_sample</code> should be used as next model input in the
denoising loop.`,name:"prev_sample"}],source:"https://github.com/huggingface/diffusers/blob/vr_8428/src/diffusers/schedulers/scheduling_utils.py#L60"}}),q=new Ue({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/schedulers/dpm_discrete_ancestral.md"}}),{c(){p=a("meta"),W=n(),F=a("p"),J=n(),m(T.$$.fragment),Q=n(),w=a("p"),w.innerHTML=$e,X=n(),y=a("p"),y.innerHTML=Se,Y=n(),m(A.$$.fragment),Z=n(),i=a("div"),m(K.$$.fragment),le=n(),I=a("p"),I.innerHTML=Pe,ue=n(),U=a("p"),U.innerHTML=Me,pe=n(),D=a("div"),m(C.$$.fragment),fe=n(),V=a("p"),V.textContent=Te,me=n(),x=a("div"),m(k.$$.fragment),he=n(),N=a("p"),N.textContent=we,ge=n(),$=a("div"),m(L.$$.fragment),_e=n(),z=a("p"),z.textContent=ye,be=n(),S=a("div"),m(E.$$.fragment),ve=n(),j=a("p"),j.textContent=Ae,ee=n(),O=a("p"),O.textContent=Ke,te=n(),f=a("div"),m(H.$$.fragment),De=n(),G=a("p"),G.innerHTML=Ce,se=n(),m(q.$$.fragment),re=n(),R=a("p"),this.h()},l(e){const s=Ie("svelte-u9bgzb",document.head);p=d(s,"META",{name:!0,content:!0}),s.forEach(t),W=o(e),F=d(e,"P",{}),P(F).forEach(t),J=o(e),h(T.$$.fragment,e),Q=o(e),w=d(e,"P",{"data-svelte-h":!0}),u(w)!=="svelte-1xsfzct"&&(w.innerHTML=$e),X=o(e),y=d(e,"P",{"data-svelte-h":!0}),u(y)!=="svelte-loovl7"&&(y.innerHTML=Se),Y=o(e),h(A.$$.fragment,e),Z=o(e),i=d(e,"DIV",{class:!0});var l=P(i);h(K.$$.fragment,l),le=o(l),I=d(l,"P",{"data-svelte-h":!0}),u(I)!=="svelte-lafslh"&&(I.innerHTML=Pe),ue=o(l),U=d(l,"P",{"data-svelte-h":!0}),u(U)!=="svelte-m9ukjl"&&(U.innerHTML=Me),pe=o(l),D=d(l,"DIV",{class:!0});var oe=P(D);h(C.$$.fragment,oe),fe=o(oe),V=d(oe,"P",{"data-svelte-h":!0}),u(V)!=="svelte-1rkfgpx"&&(V.textContent=Te),oe.forEach(t),me=o(l),x=d(l,"DIV",{class:!0});var ie=P(x);h(k.$$.fragment,ie),he=o(ie),N=d(ie,"P",{"data-svelte-h":!0}),u(N)!=="svelte-1k141rk"&&(N.textContent=we),ie.forEach(t),ge=o(l),$=d(l,"DIV",{class:!0});var ae=P($);h(L.$$.fragment,ae),_e=o(ae),z=d(ae,"P",{"data-svelte-h":!0}),u(z)!=="svelte-1vzm9q"&&(z.textContent=ye),ae.forEach(t),be=o(l),S=d(l,"DIV",{class:!0});var de=P(S);h(E.$$.fragment,de),ve=o(de),j=d(de,"P",{"data-svelte-h":!0}),u(j)!=="svelte-hi84tp"&&(j.textContent=Ae),de.forEach(t),l.forEach(t),ee=o(e),O=d(e,"P",{"data-svelte-h":!0}),u(O)!=="svelte-jslqpb"&&(O.textContent=Ke),te=o(e),f=d(e,"DIV",{class:!0});var ce=P(f);h(H.$$.fragment,ce),De=o(ce),G=d(ce,"P",{"data-svelte-h":!0}),u(G)!=="svelte-6ojmkw"&&(G.innerHTML=Ce),ce.forEach(t),se=o(e),h(q.$$.fragment,e),re=o(e),R=d(e,"P",{}),P(R).forEach(t),this.h()},h(){M(p,"name","hf:doc:metadata"),M(p,"content",Ne),M(D,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),M(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),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(S,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),M(i,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),M(f,"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,s){r(document.head,p),c(e,W,s),c(e,F,s),c(e,J,s),g(T,e,s),c(e,Q,s),c(e,w,s),c(e,X,s),c(e,y,s),c(e,Y,s),g(A,e,s),c(e,Z,s),c(e,i,s),g(K,i,null),r(i,le),r(i,I),r(i,ue),r(i,U),r(i,pe),r(i,D),g(C,D,null),r(D,fe),r(D,V),r(i,me),r(i,x),g(k,x,null),r(x,he),r(x,N),r(i,ge),r(i,$),g(L,$,null),r($,_e),r($,z),r(i,be),r(i,S),g(E,S,null),r(S,ve),r(S,j),c(e,ee,s),c(e,O,s),c(e,te,s),c(e,f,s),g(H,f,null),r(f,De),r(f,G),c(e,se,s),g(q,e,s),c(e,re,s),c(e,R,s),ne=!0},p:Ee,i(e){ne||(_(T.$$.fragment,e),_(A.$$.fragment,e),_(K.$$.fragment,e),_(C.$$.fragment,e),_(k.$$.fragment,e),_(L.$$.fragment,e),_(E.$$.fragment,e),_(H.$$.fragment,e),_(q.$$.fragment,e),ne=!0)},o(e){b(T.$$.fragment,e),b(A.$$.fragment,e),b(K.$$.fragment,e),b(C.$$.fragment,e),b(k.$$.fragment,e),b(L.$$.fragment,e),b(E.$$.fragment,e),b(H.$$.fragment,e),b(q.$$.fragment,e),ne=!1},d(e){e&&(t(W),t(F),t(J),t(Q),t(w),t(X),t(y),t(Y),t(Z),t(i),t(ee),t(O),t(te),t(f),t(se),t(re),t(R)),t(p),v(T,e),v(A,e),v(K),v(C),v(k),v(L),v(E),v(H),v(q,e)}}}const Ne='{"title":"KDPM2AncestralDiscreteScheduler","local":"kdpm2ancestraldiscretescheduler","sections":[{"title":"KDPM2AncestralDiscreteScheduler","local":"diffusers.KDPM2AncestralDiscreteScheduler","sections":[],"depth":2}],"depth":1}';function ze(xe){return Oe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Re extends He{constructor(p){super(),qe(this,p,ze,Ve,Le,{})}}export{Re as component};
