import{S as At,i as Tt,s as Pt,e as s,k as f,w as L,t as i,M as Ct,c as n,d as r,m as h,a as o,x as I,h as c,b as a,G as e,g,y as q,L as Ot,q as U,o as V,B,v as Ft}from"../../../chunks/vendor-hf-doc-builder.js";import{D as be}from"../../../chunks/Docstring-hf-doc-builder.js";import{I as nt}from"../../../chunks/IconCopyLink-hf-doc-builder.js";function Kt(ot){let v,ce,b,S,X,D,ye,Z,we,de,y,$,ee,E,Se,te,$e,le,_,ke,H,xe,De,A,Ee,He,ue,T,Ae,P,Te,pe,w,k,re,C,Pe,se,Ce,fe,l,O,Oe,R,Fe,F,Ke,Me,d,z,Ne,Le,ne,Ie,qe,oe,Ue,Ve,ae,Be,Re,G,ze,Ge,J,Je,We,W,Ye,je,Qe,Y,K,Xe,x,M,Ze,ie,et,tt,j,N,he;return D=new nt({}),E=new nt({}),C=new nt({}),O=new be({props:{name:"class diffusers.HeunDiscreteScheduler",anchor:"diffusers.HeunDiscreteScheduler",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:": typing.Union[numpy.ndarray, typing.List[float], NoneType] = None"},{name:"prediction_type",val:": str = 'epsilon'"},{name:"use_karras_sigmas",val:": typing.Optional[bool] = False"},{name:"clip_sample",val:": typing.Optional[bool] = False"},{name:"clip_sample_range",val:": float = 1.0"},{name:"timestep_spacing",val:": str = 'linspace'"},{name:"steps_offset",val:": int = 0"}],parametersDescription:[{anchor:"diffusers.HeunDiscreteScheduler.num_train_timesteps",description:"<strong>num_train_timesteps</strong> (<code>int</code>) &#x2014; number of diffusion steps used to train the model. beta_start (<code>float</code>): the",name:"num_train_timesteps"},{anchor:"diffusers.HeunDiscreteScheduler.starting",description:`<strong>starting</strong> <code>beta</code> value of inference. beta_end (<code>float</code>) &#x2014; the final <code>beta</code> value. beta_schedule (<code>str</code>):
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:"starting"},{anchor:"diffusers.HeunDiscreteScheduler.trained_betas",description:`<strong>trained_betas</strong> (<code>np.ndarray</code>, optional) &#x2014;
option to pass an array of betas directly to the constructor to bypass <code>beta_start</code>, <code>beta_end</code> etc.`,name:"trained_betas"},{anchor:"diffusers.HeunDiscreteScheduler.prediction_type",description:`<strong>prediction_type</strong> (<code>str</code>, default <code>epsilon</code>, optional) &#x2014;
prediction type of the scheduler function, one of <code>epsilon</code> (predicting the noise of the diffusion
process), <code>sample</code> (directly predicting the noisy sample<code>) or </code>v_prediction\` (see section 2.4
<a href="https://imagen.research.google/video/paper.pdf" rel="nofollow">https://imagen.research.google/video/paper.pdf</a>).`,name:"prediction_type"},{anchor:"diffusers.HeunDiscreteScheduler.clip_sample",description:`<strong>clip_sample</strong> (<code>bool</code>, default <code>True</code>) &#x2014;
option to clip predicted sample for numerical stability.`,name:"clip_sample"},{anchor:"diffusers.HeunDiscreteScheduler.clip_sample_range",description:`<strong>clip_sample_range</strong> (<code>float</code>, default <code>1.0</code>) &#x2014;
the maximum magnitude for sample clipping. Valid only when <code>clip_sample=True</code>.`,name:"clip_sample_range"},{anchor:"diffusers.HeunDiscreteScheduler.use_karras_sigmas",description:`<strong>use_karras_sigmas</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
This parameter controls whether to use Karras sigmas (Karras et al. (2022) scheme) for step sizes in the
noise schedule during the sampling process. If True, the sigmas will be determined according to a sequence
of noise levels {&#x3C3;i} as defined in Equation (5) of the paper <a href="https://arxiv.org/pdf/2206.00364.pdf" rel="nofollow">https://arxiv.org/pdf/2206.00364.pdf</a>.`,name:"use_karras_sigmas"},{anchor:"diffusers.HeunDiscreteScheduler.timestep_spacing",description:`<strong>timestep_spacing</strong> (<code>str</code>, default <code>&quot;linspace&quot;</code>) &#x2014;
The way the timesteps should be scaled. Refer to Table 2. of <a href="https://arxiv.org/abs/2305.08891" rel="nofollow">Common Diffusion Noise Schedules and Sample
Steps are Flawed</a> for more information.`,name:"timestep_spacing"},{anchor:"diffusers.HeunDiscreteScheduler.steps_offset",description:`<strong>steps_offset</strong> (<code>int</code>, default <code>0</code>) &#x2014;
an offset added to the inference steps. You can use a combination of <code>offset=1</code> and
<code>set_alpha_to_one=False</code>, to make the last step use step 0 for the previous alpha product, as done in
stable diffusion.`,name:"steps_offset"}],source:"https://github.com/huggingface/diffusers/blob/v0.19.0/src/diffusers/schedulers/scheduling_heun_discrete.py#L71"}}),K=new be({props:{name:"scale_model_input",anchor:"diffusers.HeunDiscreteScheduler.scale_model_input",parameters:[{name:"sample",val:": FloatTensor"},{name:"timestep",val:": typing.Union[float, torch.FloatTensor]"}],parametersDescription:[{anchor:"diffusers.HeunDiscreteScheduler.scale_model_input.Ensures",description:"<strong>Ensures</strong> interchangeability with schedulers that need to scale the denoising model input depending on the &#x2014;",name:"Ensures"},{anchor:"diffusers.HeunDiscreteScheduler.scale_model_input.current",description:`<strong>current</strong> timestep. &#x2014;
sample (<code>torch.FloatTensor</code>): input sample timestep (<code>int</code>, optional): current timestep`,name:"current"}],source:"https://github.com/huggingface/diffusers/blob/v0.19.0/src/diffusers/schedulers/scheduling_heun_discrete.py#L178",returnDescription:`
<p>scaled input sample</p>
`,returnType:`
<p><code>torch.FloatTensor</code></p>
`}}),M=new be({props:{name:"set_timesteps",anchor:"diffusers.HeunDiscreteScheduler.set_timesteps",parameters:[{name:"num_inference_steps",val:": int"},{name:"device",val:": typing.Union[str, torch.device] = None"},{name:"num_train_timesteps",val:": typing.Optional[int] = None"}],parametersDescription:[{anchor:"diffusers.HeunDiscreteScheduler.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.HeunDiscreteScheduler.set_timesteps.device",description:`<strong>device</strong> (<code>str</code> or <code>torch.device</code>, optional) &#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/v0.19.0/src/diffusers/schedulers/scheduling_heun_discrete.py#L197"}}),N=new be({props:{name:"step",anchor:"diffusers.HeunDiscreteScheduler.step",parameters:[{name:"model_output",val:": typing.Union[torch.FloatTensor, numpy.ndarray]"},{name:"timestep",val:": typing.Union[float, torch.FloatTensor]"},{name:"sample",val:": typing.Union[torch.FloatTensor, numpy.ndarray]"},{name:"return_dict",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.HeunDiscreteScheduler.step.Predict",description:"<strong>Predict</strong> the sample at the previous timestep by reversing the SDE. Core function to propagate the diffusion &#x2014;",name:"Predict"},{anchor:"diffusers.HeunDiscreteScheduler.step.process",description:`<strong>process</strong> from the learned model outputs (most often the predicted noise). &#x2014;
model_output (<code>torch.FloatTensor</code> or <code>np.ndarray</code>): direct output from learned diffusion model. timestep
(<code>int</code>): current discrete timestep in the diffusion chain. sample (<code>torch.FloatTensor</code> or <code>np.ndarray</code>):
current instance of sample being created by diffusion process.
return_dict (<code>bool</code>): option for returning tuple rather than SchedulerOutput class`,name:"process"}],source:"https://github.com/huggingface/diffusers/blob/v0.19.0/src/diffusers/schedulers/scheduling_heun_discrete.py#L307",returnDescription:`
<p><a
  href="/docs/diffusers/v0.19.0/en/api/schedulers/overview#diffusers.schedulers.scheduling_utils.SchedulerOutput"
>SchedulerOutput</a> if <code>return_dict</code> is True, otherwise a <code>tuple</code>. When
returning a tuple, the first element is the sample tensor.</p>
`,returnType:`
<p><a
  href="/docs/diffusers/v0.19.0/en/api/schedulers/overview#diffusers.schedulers.scheduling_utils.SchedulerOutput"
>SchedulerOutput</a> or <code>tuple</code></p>
`}}),{c(){v=s("meta"),ce=f(),b=s("h1"),S=s("a"),X=s("span"),L(D.$$.fragment),ye=f(),Z=s("span"),we=i("Heun scheduler inspired by Karras et. al paper"),de=f(),y=s("h2"),$=s("a"),ee=s("span"),L(E.$$.fragment),Se=f(),te=s("span"),$e=i("Overview"),le=f(),_=s("p"),ke=i("Algorithm 1 of "),H=s("a"),xe=i("Karras et. al"),De=i(`.
Scheduler ported from @crowsonkb\u2019s `),A=s("a"),Ee=i("https://github.com/crowsonkb/k-diffusion"),He=i(" library:"),ue=f(),T=s("p"),Ae=i("All credit for making this scheduler work goes to "),P=s("a"),Te=i("Katherine Crowson"),pe=f(),w=s("h2"),k=s("a"),re=s("span"),L(C.$$.fragment),Pe=f(),se=s("span"),Ce=i("HeunDiscreteScheduler"),fe=f(),l=s("div"),L(O.$$.fragment),Oe=f(),R=s("p"),Fe=i(`Implements Algorithm 2 (Heun steps) from Karras et al. (2022). for discrete beta schedules. Based on the original
k-diffusion implementation by Katherine Crowson:
`),F=s("a"),Ke=i("https://github.com/crowsonkb/k-diffusion/blob/481677d114f6ea445aa009cf5bd7a9cdee909e47/k_diffusion/sampling.py#L90"),Me=f(),d=s("p"),z=s("a"),Ne=i("~ConfigMixin"),Le=i(" takes care of storing all config attributes that are passed in the scheduler\u2019s "),ne=s("code"),Ie=i("__init__"),qe=i(`
function, such as `),oe=s("code"),Ue=i("num_train_timesteps"),Ve=i(". They can be accessed via "),ae=s("code"),Be=i("scheduler.config.num_train_timesteps"),Re=i(`.
`),G=s("a"),ze=i("SchedulerMixin"),Ge=i(" provides general loading and saving functionality via the "),J=s("a"),Je=i("SchedulerMixin.save_pretrained()"),We=i(` and
`),W=s("a"),Ye=i("from_pretrained()"),je=i(" functions."),Qe=f(),Y=s("div"),L(K.$$.fragment),Xe=f(),x=s("div"),L(M.$$.fragment),Ze=f(),ie=s("p"),et=i("Sets the timesteps used for the diffusion chain. Supporting function to be run before inference."),tt=f(),j=s("div"),L(N.$$.fragment),this.h()},l(t){const u=Ct('[data-svelte="svelte-1phssyn"]',document.head);v=n(u,"META",{name:!0,content:!0}),u.forEach(r),ce=h(t),b=n(t,"H1",{class:!0});var me=o(b);S=n(me,"A",{id:!0,class:!0,href:!0});var at=o(S);X=n(at,"SPAN",{});var it=o(X);I(D.$$.fragment,it),it.forEach(r),at.forEach(r),ye=h(me),Z=n(me,"SPAN",{});var ct=o(Z);we=c(ct,"Heun scheduler inspired by Karras et. al paper"),ct.forEach(r),me.forEach(r),de=h(t),y=n(t,"H2",{class:!0});var ge=o(y);$=n(ge,"A",{id:!0,class:!0,href:!0});var dt=o($);ee=n(dt,"SPAN",{});var lt=o(ee);I(E.$$.fragment,lt),lt.forEach(r),dt.forEach(r),Se=h(ge),te=n(ge,"SPAN",{});var ut=o(te);$e=c(ut,"Overview"),ut.forEach(r),ge.forEach(r),le=h(t),_=n(t,"P",{});var Q=o(_);ke=c(Q,"Algorithm 1 of "),H=n(Q,"A",{href:!0,rel:!0});var pt=o(H);xe=c(pt,"Karras et. al"),pt.forEach(r),De=c(Q,`.
Scheduler ported from @crowsonkb\u2019s `),A=n(Q,"A",{href:!0,rel:!0});var ft=o(A);Ee=c(ft,"https://github.com/crowsonkb/k-diffusion"),ft.forEach(r),He=c(Q," library:"),Q.forEach(r),ue=h(t),T=n(t,"P",{});var rt=o(T);Ae=c(rt,"All credit for making this scheduler work goes to "),P=n(rt,"A",{href:!0,rel:!0});var ht=o(P);Te=c(ht,"Katherine Crowson"),ht.forEach(r),rt.forEach(r),pe=h(t),w=n(t,"H2",{class:!0});var _e=o(w);k=n(_e,"A",{id:!0,class:!0,href:!0});var mt=o(k);re=n(mt,"SPAN",{});var gt=o(re);I(C.$$.fragment,gt),gt.forEach(r),mt.forEach(r),Pe=h(_e),se=n(_e,"SPAN",{});var _t=o(se);Ce=c(_t,"HeunDiscreteScheduler"),_t.forEach(r),_e.forEach(r),fe=h(t),l=n(t,"DIV",{class:!0});var m=o(l);I(O.$$.fragment,m),Oe=h(m),R=n(m,"P",{});var st=o(R);Fe=c(st,`Implements Algorithm 2 (Heun steps) from Karras et al. (2022). for discrete beta schedules. Based on the original
k-diffusion implementation by Katherine Crowson:
`),F=n(st,"A",{href:!0,rel:!0});var vt=o(F);Ke=c(vt,"https://github.com/crowsonkb/k-diffusion/blob/481677d114f6ea445aa009cf5bd7a9cdee909e47/k_diffusion/sampling.py#L90"),vt.forEach(r),st.forEach(r),Me=h(m),d=n(m,"P",{});var p=o(d);z=n(p,"A",{href:!0});var bt=o(z);Ne=c(bt,"~ConfigMixin"),bt.forEach(r),Le=c(p," takes care of storing all config attributes that are passed in the scheduler\u2019s "),ne=n(p,"CODE",{});var yt=o(ne);Ie=c(yt,"__init__"),yt.forEach(r),qe=c(p,`
function, such as `),oe=n(p,"CODE",{});var wt=o(oe);Ue=c(wt,"num_train_timesteps"),wt.forEach(r),Ve=c(p,". They can be accessed via "),ae=n(p,"CODE",{});var St=o(ae);Be=c(St,"scheduler.config.num_train_timesteps"),St.forEach(r),Re=c(p,`.
`),G=n(p,"A",{href:!0});var $t=o(G);ze=c($t,"SchedulerMixin"),$t.forEach(r),Ge=c(p," provides general loading and saving functionality via the "),J=n(p,"A",{href:!0});var kt=o(J);Je=c(kt,"SchedulerMixin.save_pretrained()"),kt.forEach(r),We=c(p,` and
`),W=n(p,"A",{href:!0});var xt=o(W);Ye=c(xt,"from_pretrained()"),xt.forEach(r),je=c(p," functions."),p.forEach(r),Qe=h(m),Y=n(m,"DIV",{class:!0});var Dt=o(Y);I(K.$$.fragment,Dt),Dt.forEach(r),Xe=h(m),x=n(m,"DIV",{class:!0});var ve=o(x);I(M.$$.fragment,ve),Ze=h(ve),ie=n(ve,"P",{});var Et=o(ie);et=c(Et,"Sets the timesteps used for the diffusion chain. Supporting function to be run before inference."),Et.forEach(r),ve.forEach(r),tt=h(m),j=n(m,"DIV",{class:!0});var Ht=o(j);I(N.$$.fragment,Ht),Ht.forEach(r),m.forEach(r),this.h()},h(){a(v,"name","hf:doc:metadata"),a(v,"content",JSON.stringify(Mt)),a(S,"id","heun-scheduler-inspired-by-karras-et-al-paper"),a(S,"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"),a(S,"href","#heun-scheduler-inspired-by-karras-et-al-paper"),a(b,"class","relative group"),a($,"id","overview"),a($,"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"),a($,"href","#overview"),a(y,"class","relative group"),a(H,"href","https://arxiv.org/abs/2206.00364"),a(H,"rel","nofollow"),a(A,"href","https://github.com/crowsonkb/k-diffusion"),a(A,"rel","nofollow"),a(P,"href","https://github.com/crowsonkb/"),a(P,"rel","nofollow"),a(k,"id","diffusers.HeunDiscreteScheduler"),a(k,"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"),a(k,"href","#diffusers.HeunDiscreteScheduler"),a(w,"class","relative group"),a(F,"href","https://github.com/crowsonkb/k-diffusion/blob/481677d114f6ea445aa009cf5bd7a9cdee909e47/k_diffusion/sampling.py#L90"),a(F,"rel","nofollow"),a(z,"href","/docs/diffusers/v0.19.0/en/api/configuration#diffusers.ConfigMixin"),a(G,"href","/docs/diffusers/v0.19.0/en/api/schedulers/overview#diffusers.SchedulerMixin"),a(J,"href","/docs/diffusers/v0.19.0/en/api/schedulers/overview#diffusers.SchedulerMixin.save_pretrained"),a(W,"href","/docs/diffusers/v0.19.0/en/api/schedulers/overview#diffusers.SchedulerMixin.from_pretrained"),a(Y,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),a(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),a(j,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),a(l,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(t,u){e(document.head,v),g(t,ce,u),g(t,b,u),e(b,S),e(S,X),q(D,X,null),e(b,ye),e(b,Z),e(Z,we),g(t,de,u),g(t,y,u),e(y,$),e($,ee),q(E,ee,null),e(y,Se),e(y,te),e(te,$e),g(t,le,u),g(t,_,u),e(_,ke),e(_,H),e(H,xe),e(_,De),e(_,A),e(A,Ee),e(_,He),g(t,ue,u),g(t,T,u),e(T,Ae),e(T,P),e(P,Te),g(t,pe,u),g(t,w,u),e(w,k),e(k,re),q(C,re,null),e(w,Pe),e(w,se),e(se,Ce),g(t,fe,u),g(t,l,u),q(O,l,null),e(l,Oe),e(l,R),e(R,Fe),e(R,F),e(F,Ke),e(l,Me),e(l,d),e(d,z),e(z,Ne),e(d,Le),e(d,ne),e(ne,Ie),e(d,qe),e(d,oe),e(oe,Ue),e(d,Ve),e(d,ae),e(ae,Be),e(d,Re),e(d,G),e(G,ze),e(d,Ge),e(d,J),e(J,Je),e(d,We),e(d,W),e(W,Ye),e(d,je),e(l,Qe),e(l,Y),q(K,Y,null),e(l,Xe),e(l,x),q(M,x,null),e(x,Ze),e(x,ie),e(ie,et),e(l,tt),e(l,j),q(N,j,null),he=!0},p:Ot,i(t){he||(U(D.$$.fragment,t),U(E.$$.fragment,t),U(C.$$.fragment,t),U(O.$$.fragment,t),U(K.$$.fragment,t),U(M.$$.fragment,t),U(N.$$.fragment,t),he=!0)},o(t){V(D.$$.fragment,t),V(E.$$.fragment,t),V(C.$$.fragment,t),V(O.$$.fragment,t),V(K.$$.fragment,t),V(M.$$.fragment,t),V(N.$$.fragment,t),he=!1},d(t){r(v),t&&r(ce),t&&r(b),B(D),t&&r(de),t&&r(y),B(E),t&&r(le),t&&r(_),t&&r(ue),t&&r(T),t&&r(pe),t&&r(w),B(C),t&&r(fe),t&&r(l),B(O),B(K),B(M),B(N)}}}const Mt={local:"heun-scheduler-inspired-by-karras-et-al-paper",sections:[{local:"overview",title:"Overview"},{local:"diffusers.HeunDiscreteScheduler",title:"HeunDiscreteScheduler"}],title:"Heun scheduler inspired by Karras et. al paper"};function Nt(ot){return Ft(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ut extends At{constructor(v){super();Tt(this,v,Nt,Kt,Pt,{})}}export{Ut as default,Mt as metadata};
