
    
3js                         S SK r S SKJr  S SKJr  S SKrS SKrSSKJ	r	J
r
  SSKJr  SSKJrJr  \ " S S	\5      5       r " S
 S\\	5      rg)    N)	dataclass)Literal   )ConfigMixinregister_to_config)SchedulerMixin)
BaseOutput	deprecatec                       \ rS rSr% \R
                  \S'   Sr\R
                  S-  \S'   Sr\R
                  S-  \S'   Sr	\
S-  \S'   Srg)HeliosSchedulerOutput   prev_sampleNmodel_outputslast_sample
this_order )__name__
__module____qualname____firstlineno__torchFloatTensor__annotations__r   r   r   int__static_attributes__r       `/home/wildlama/miniconda3/lib/python3.13/site-packages/diffusers/schedulers/scheduling_helios.pyr   r      sF    """.2M5$$t+2,0K""T)0!Jd
!r   r   c            %          \ rS rSr/ rSr\SSS/ SQSSS	S
SSS/ SSSSS4S\S\S\S\	S\S\
S\S\S\
S\S\
S\	\   S\S\
S\S\
S \S!   4"S" jj5       rS# rS$ r\S% 5       r\S& 5       rSWS'\4S( jjrS) r     SXS*\S+\S-  S,\\R.                  -  S-\
S-  S.\
S-  S/\
4S0 jjrS.\S1\S2\R2                  4S3 jrS4 rS5 rSYS6 jrS7 r      SZS8\R>                  S9\\R>                  -  S:\R>                  S;\R@                  S-  S1\R>                  S-  S<\R>                  S-  S=\
S>\!\"-  4S? jjr#S@ r$SSSA.S8\R2                  S:\R2                  S1\R2                  S>\R2                  4SB jjr%SSSSSC.S8\R2                  S:\R2                  SD\S1\R2                  S<\R2                  S>\R2                  4SE jjr&SSSSSSF.SG\R2                  SH\R2                  SI\R2                  SD\SJ\R2                  S1\R2                  S>\R2                  4SK jjr'            S[S8\R2                  S9\\R2                  -  S:\R2                  S=\
SL\	SM\	SJ\R2                  S1\R2                  S<\R2                  SN\SO\SP\SQ\R2                  S>\!\"-  4SR jjr(    S\S8\R>                  S9\\R>                  -  S:\R>                  S;\R@                  S-  S=\
S>\!\"-  4SS jjr)ST r*SU r+SVr,g)]HeliosScheduler#      i        ?   )r   UUUUUU?gUUUUUU?r!   r$   Fflow_predictionr   Tbh2Nunipcexponentialnum_train_timestepsshiftstagesstage_rangegammathresholdingprediction_typesolver_order
predict_x0solver_typelower_order_finaldisable_correctorsolver_puse_flow_sigmasscheduler_typeuse_dynamic_shiftingtime_shift_type)r(   linearc                     0 U l         0 U l        0 U l        0 U l        0 U l        0 U l        U R                  5         U R                  S   R                  5       U l	        U R                  S   R                  5       U l
        XPl        U
S;  a0  U
S;   a  U R                  SS9  O[        U
 SU R                   35      eXl        S /U-  U l        S /U-  U l        SU l        Xl        Xl        S U l        S U l        S U l        g )Nr   )bh1r&   )midpointheunlogrhor&   )r2   z is not implemented for )timestep_ratiostimesteps_per_stagesigmas_per_stagestart_sigmas
end_sigmasori_start_sigmasinit_sigmas_for_each_stagesigmasitem	sigma_min	sigma_maxr-   r   NotImplementedError	__class__r1   r   timestep_listlower_order_numsr4   r5   r   _step_index_begin_index)selfr)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   s                     r   __init__HeliosScheduler.__init__'   s   ,  "#%  " " 	'')R--/Q,,.
n,<<''E':)[M9QRVR`R`Qa*bcc$"Vl2"Vl2 !!2  r   c                    U R                   R                  nU R                   R                  n[        R                  " SSU-  US-   5      nSU-
  n[        R
                  " X$-  SUS-
  U-  -   -  5      SS R                  5       n[        R                  " U5      nXA-  R                  5       nSU l
        SU l        XPl        UR                  S5      U l        g)z,
initialize the global timesteps and sigmas
r!   r"   Nr<   cpu)configr)   r*   nplinspaceflipcopyr   
from_numpyclonerP   rQ   	timestepstorH   )rR   r)   r*   alphasrH   r^   s         r   init_sigmasHeliosScheduler.init_sigmasZ   s     #kk==!!Q$7 79Lq9PQv1	V/C+CDEcrJOOQ!!&)188:	 "ii&r   c                    U R                  5         / nU R                  R                  nU R                  R                  nU R                  R                  n[        U5       GH  n[        XE   U-  5      n[        US5      n[        XES-      U-  5      n[        Xs5      nU R                  U   R                  5       nXs:  a  U R                  U   R                  5       OSn	XR                  U'   US:w  aK  SU-
  n
U R                  R                  nS[        R                  " SSU-  -   5      SU
-
  -  U
-   -  U
-  nSU-
  nUR                  X-
  5        XR                   U'   XR"                  U'   GM     [%        U5      n[        U5       HL  nUS:X  a  SnO[%        USU 5      U-  nXRS-
  :X  a  SnO[%        USUS-    5      U-  nX4U R&                  U'   MN     [        U5       GH  nU R&                  U   n[        U R(                  [        US   U-  5         S5      nU R(                  [        [        US   U-  5      US-
  5         n[*        R,                  " UUUS-   5      n[/        U[0        R2                  5      (       a  USS O[0        R4                  " USS 5      U R6                  U'   [*        R,                  " SSUS-   5      n[0        R4                  " USS 5      U R8                  U'   GM     g)	z#
Init the timesteps for each stage
r   r!   g        Ng?i  r<   g+?)ra   rW   r+   r)   r,   ranger   maxminrH   rI   rF   r-   mathsqrtappendrD   rE   sumrA   r^   rX   rY   
isinstancer   Tensorr\   rB   rC   )rR   stage_distancer+   training_stepsr,   i_sstart_indice
end_indicestart_sigma	end_sigma	ori_sigmar-   corrected_sigmatot_distancestart_ratio	end_ratiotimestep_ratiotimestep_maxtimestep_minr^   stage_sigmass                        r   rG   *HeliosScheduler.init_sigmas_for_each_stagel   s    	##88kk-- =C{/.@AL|Q/L[q1NBCJZ8J++l388:K:D:UJ/446[^I)4!!#&axO	))#$		!q5y/(Ba)m(TW`(`#aen"n/1!!+"9:%0c"#,OOC ' !, >*=Cax!!.#"67,Fqj .	yq 9:\I	)4(@D  % ! =C!11#6Nt~~c.2Cn2T.UVX[\L>>#c.2Cn2T.UWehiWi*jkLL,QR@RSI",Y"E"E	#25K[K[\efigi\jKk $$S) ;;ua!1CDL).)9)9,s:K)LD!!#& !r   c                     U R                   $ )zW
The index counter for current timestep. It will increase 1 after each scheduler step.
)rP   rR   s    r   
step_indexHeliosScheduler.step_index   s    
 r   c                     U R                   $ )za
The index for the first timestep. It should be set from pipeline with `set_begin_index` method.
rQ   r   s    r   begin_indexHeliosScheduler.begin_index   s    
    r   r   c                     Xl         g)z
Sets the begin index for the scheduler. This function should be run from pipeline before the inference.

Args:
    begin_index (`int`):
        The begin index for the scheduler.
Nr   )rR   r   s     r   set_begin_indexHeliosScheduler.set_begin_index   s
     (r   c                 2    XR                   R                  -  $ NrW   r)   )rR   sigmas     r   _sigma_to_tHeliosScheduler._sigma_to_t   s    {{6666r   num_inference_stepsstage_indexdevicerH   muis_amplify_first_chunkc                    U R                   R                  S:X  a  U(       a	  US-  S-   nOUS-   nXl        U R                  5         U R                   R                  S:X  a  Uc  [
        R                  " SSU R                   R                  -  US-   5      SS R                  [
        R                  5      nU R                   R                  S:w  aD  U R                   R                  (       a   eU R                  U R                   R                  SU5      nX@R                   R                  -  R                  5       n[        R                  " U5      nOU R                   U   n[
        R                  " US   R#                  5       US   R#                  5       U5      nU R$                  U   n	[
        R                  " U	S   R#                  5       U	S   R#                  5       U5      n
[        R                  " U
5      n[        R                  " U5      R'                  US9U l        [        R*                  " U[        R,                  " S5      /5      R'                  US9U l        SU l        U R3                  5         U R                   R                  S:X  aK  U R(                  SS U l        [        R*                  " U R.                  SS	 U R.                  SS /5      U l        U R                   R                  (       a  U R                   R                  S:X  d   eU R                  USU R.                  5      U l        U R                   R                  S:X  a,  U R.                  SS U R                   R                  -  U l        gU R                   U   R5                  5       U R.                  SS U R                   U   R7                  5       U R                   U   R5                  5       -
  -  -   U l        gg)
z1
Setting the timesteps and sigmas for each stage
dmdr   r!   Nr<   r"   r   r   )rW   r7   r   ra   r+   rX   rY   r)   astypefloat32r*   r8   
time_shiftr[   r   r\   rB   rI   rC   r_   r^   catzerosrH   rP   reset_scheduler_historyrf   re   )rR   r   r   r   rH   r   r   r^   stage_timestepsr|   ratioss              r   set_timestepsHeliosScheduler.set_timesteps   s*    ;;%%.%&9A&=&A#&9A&=##6 ;;"~QDKK,K,K(KM`cdMdefigijqqJJ ;;$$+#{{????!__T[[->->VLF++"A"AAGGII%%f-F"66{CO"'')#((*#I  00=L[[a!5!5!7b9I9N9N9PRefF%%f-F)))477v7FiiQ 89<<F<K$$&;;%%.!^^CR0DN))T[["%5t{{237G$HIDK;;++;;$$+++//"c4;;?DK{{!!Q&!%Sb!1DKK4S4S!S!%!9!9+!F!J!J!Lt{{[^\^O_,,[9==?$BZBZ[fBgBkBkBmmP " ,r   r   tc                     U R                   R                  S:X  a  U R                  XU5      $ U R                   R                  S:X  a  U R                  XU5      $ g)a&  
Apply time shifting to the sigmas.

Args:
    mu (`float`):
        The mu parameter for the time shift.
    sigma (`float`):
        The sigma parameter for the time shift.
    t (`torch.Tensor`):
        The input timesteps.

Returns:
    `torch.Tensor`:
        The time-shifted timesteps.
r(   r:   N)rW   r9   _time_shift_exponential_time_shift_linearrR   r   r   r   s       r   r   HeliosScheduler.time_shift  sS      ;;&&-7//1==[[((H4**2a88 5r   c                 t    [         R                  " U5      [         R                  " U5      SU-  S-
  U-  -   -  $ Nr!   )rg   expr   s       r   r   'HeliosScheduler._time_shift_exponential  s/    xx|txx|q1uqyU.BBCCr   c                 "    XSU-  S-
  U-  -   -  $ r   r   r   s       r   r   "HeliosScheduler._time_shift_linear  s    1q519..//r   c                     Uc  U R                   nX!:H  R                  5       n[        U5      S:  a  SOSnX4   R                  5       $ )Nr!   r   )r^   nonzerolenrI   )rR   timestepschedule_timestepsindicesposs        r   index_for_timestep"HeliosScheduler.index_for_timestep!  sH    %!%%1::< w<!#a|  ""r   c                     U R                   c[  [        U[        R                  5      (       a%  UR	                  U R
                  R                  5      nU R                  U5      U l        g U R                  U l        g r   )
r   rk   r   rl   r_   r^   r   r   rP   rQ   )rR   r   s     r   _init_step_index HeliosScheduler._init_step_index/  sX    #(ELL11#;;t~~'<'<=#66x@D#00Dr   model_outputr   sample	generator
sigma_nextreturn_dictreturnc                 b   US L US L :X  d   S5       eUca  Uc^  [        U[        5      (       d>  [        U[        R                  5      (       d  [        U[        R                  5      (       a  [        S5      eU R                  c  SU l        UR                  [        R                  5      nUc8  Uc5  U R                  U R                     nU R                  U R                  S-      nX6U-
  U-  -   nUR                  UR                  5      nU =R                  S-  sl        U(       d  U4$ [        US9$ )Nz:sigma and sigma_next must both be None or both be not NonezPassing integer indices (e.g. from `enumerate(timesteps)`) as timesteps to `EulerDiscreteScheduler.step()` is not supported. Make sure to pass one of the `scheduler.timesteps` as a timestep.r   r!   )r   )rk   r   r   	IntTensor
LongTensor
ValueErrorr   rP   r_   r   rH   dtyper   )	rR   r   r   r   r   r   r   r   r   s	            r   
step_eulerHeliosScheduler.step_euler7  s    :#56t8tt6=Z/8S))h88h(8(899 K  ??" D 5==)=Z/KK0ET__q%89JU 2lBB "nn\%7%78 	A>!$==r   c                     U R                   R                  (       a  SU-
  n[        R                  " USS9nX#4$ SUS-  S-   S-  -  nX-  nX#4$ )Nr!   g:0yE>)rf   r         ?)rW   r6   r   clamp)rR   r   alpha_tsigma_ts       r   _sigma_to_alpha_sigma_t'HeliosScheduler._sigma_to_alpha_sigma_ti  s\    ;;&&%iGkk%T2G
  E1HqLS01GoGr   r   r   c                H   [        U5      S:  a  US   OUR                  SS5      nUc   [        U5      S:  a  US   nO[        S5      eUb  [        SSS5        S	nUc  S
nU R                  U R
                     nU R                  U5      u  pU R                  (       a  U R                  R                  S:X  a  X)U-  -
  U-  n
OU R                  R                  S:X  a  Un
OU R                  R                  S:X  a
  X-  X-  -
  n
OhU R                  R                  S:X  a+  U(       a  U R                  U R
                     n	OUn	X)U-  -
  n
O#[        SU R                  R                   S35      eU R                  R                  (       a  U R                  U
5      n
U
$ U R                  R                  S:X  a  U$ U R                  R                  S:X  a  X(U-  -
  U	-  nU$ U R                  R                  S:X  a  X-  X-  -   nU$ [        SU R                  R                   S35      e)a  
Convert the model output to the corresponding type the UniPC algorithm needs.

Args:
    model_output (`torch.Tensor`):
        The direct output from the learned diffusion model.
    timestep (`int`):
        The current discrete timestep in the diffusion chain.
    sample (`torch.Tensor`):
        A current instance of a sample created by the diffusion process.

Returns:
    `torch.Tensor`:
        The converted model output.
r   r   Nr!   /missing `sample` as a required keyword argumentr^   1.0.0zPassing `timesteps` is deprecated and has no effect as model output conversion is now handled via an internal counter `self.step_index`FTepsilonr   v_predictionr%   zprediction_type given as zj must be one of `epsilon`, `sample`, `v_prediction`, or `flow_prediction` for the UniPCMultistepScheduler.zW must be one of `epsilon`, `sample`, or `v_prediction` for the UniPCMultistepScheduler.)r   popr   r
   rH   r   r   r1   rW   r/   r.   _threshold_sample)rR   r   r   r   argskwargsr   flagr   r   x0_predr   s               r   convert_model_output$HeliosScheduler.convert_model_outputs  s   . "$i!m47J1M>4y1}a !RSS Z =DKK0E77>??{{**i7!l$::gE,,8&,,>!*W-CC,,0AA"kk$//:G#G \#99 /0K0K/L M\ \ 
 {{''009N{{**i7##,,8!l$::gE,,>!073CC /0K0K/L MG G r   )r   orderr   r   r   c                	   [        U5      S:  a  US   OUR                  SS5      nUc   [        U5      S:  a  US   nO[        S5      eUc   [        U5      S:  a  US   nO[        S5      eUb  [        SSS	5        U R                  n	U R
                  S
   n
U	S
   nUnU R                  (       a(  U R                  R                  XU5      R                  nU$ Uc8  Uc5  U R                  U R                  S-      U R                  U R                     pOXTpU R                  U5      u  nnU R                  U5      u  nn[        R                  " U5      [        R                  " U5      -
  n[        R                  " U5      [        R                  " U5      -
  nUU-
  nUR                  n/ n/ n[        SU5       H  nU R                  U-
  nU	US-   *    nU R                  U R                  U   5      u  nn[        R                  " U5      [        R                  " U5      -
  nUU-
  U-  nUR!                  U5        UR!                  UU-
  U-  5        M     UR!                  S5        [        R"                  " UUS9n/ n/ n U R$                  (       a  U* OUn![        R&                  " U!5      n"U"U!-  S-
  n#Sn$U R(                  R*                  S:X  a  U!n%O;U R(                  R*                  S:X  a  [        R&                  " U!5      n%O
[-        5       e[        SUS-   5       HV  nUR!                  [        R.                  " UUS-
  5      5        U R!                  U#U$-  U%-  5        U$US-   -  n$U#U!-  SU$-  -
  n#MX     [        R0                  " U5      n[        R"                  " U US9n [        U5      S:  a  [        R0                  " USS9nUS:X  a"  [        R"                  " S/UR2                  US9n&OW[        R4                  R7                  USS
2SS
24   U SS
 5      R9                  U5      R9                  UR2                  5      n&OSnU R$                  (       a:  X-  U-  UU"-  U-  -
  n'Ub  [        R:                  " SW&U5      n(OSn(U'UU%-  U(-  -
  nO:UU-  U-  UU"-  U-  -
  n'Ub  [        R:                  " SW&U5      n(OSn(U'UU%-  U(-  -
  nUR9                  UR2                  5      nU$ )aR  
One step for the UniP (B(h) version). Alternatively, `self.solver_p` is used if is specified.

Args:
    model_output (`torch.Tensor`):
        The direct output from the learned diffusion model at the current timestep.
    prev_timestep (`int`):
        The previous discrete timestep in the diffusion chain.
    sample (`torch.Tensor`):
        A current instance of a sample created by the diffusion process.
    order (`int`):
        The order of UniP at this timestep (corresponds to the *p* in UniPC-p).

Returns:
    `torch.Tensor`:
        The sample tensor at the previous timestep.
r   prev_timestepNr!   r   r   .missing `order` as a required keyword argumentr   zPassing `prev_timestep` is deprecated and has no effect as model output conversion is now handled via an internal counter `self.step_index`r<   r"   r   r=   r&   dimr   r   r   k,bkc...->bc...)r   r   r   r
   r   rN   r5   stepr   rH   r   r   r   logr   rd   ri   tensorr1   expm1rW   r2   rL   powstackr   linalgsolver_   einsum))rR   r   r   r   r   r   r   r   r   model_output_lists0m0xx_tr   sigma_s0r   alpha_s0lambda_t	lambda_s0hr   rksD1sisimialpha_sisigma_si	lambda_sirkRbhhh_phi_1h_phi_kfactorial_iB_hrhos_px_t_pred_ress)                                            r   multistep_uni_p_bh_update)HeliosScheduler.multistep_uni_p_bh_update  s}   6 $'t9q=QfjjRV6W>4y1}a !RSS=4y1}Q !QRR$ ^
 !..#r"==--$$\q9EECJ%- $DOOa,? @$++dooB^X *X77@!99(C(99W%		'(::IIh'%))H*==	y q%A1$B"QU8,B!%!=!=dkk"o!NHh		(+eii.AAIi'1,BJJrNJJR2~& ! 	

3ll3v.??aR++b/B,";;""e+C[[$$-++b/C%''q%!)$AHHUYYsAE*+HHW{*S011q5 KlQ_4G	 % KKNLL6*s8a<++cq)Czse1776J++Acrc3B3hK3B@CCFKNNqwwWC??%)Gg,=,BBD <<(963G311CX%)Gg,=,BBD <<(963G311CffQWWo
r   )r   this_sampler   sigma_beforer   this_model_outputr   r  r  c                	   [        U5      S:  a  US   OUR                  SS5      n	Uc   [        U5      S:  a  US   nO[        S5      eUc   [        U5      S:  a  US   nO[        S5      eUc   [        U5      S:  a  US   nO[        S	5      eU	b  [        SS
S5        U R                  n
U
S   nUnUnUnUc9  Uc6  U R
                  U R                     U R
                  U R                  S-
     nnOXennU R                  U5      u  nnU R                  U5      u  nn[        R                  " U5      [        R                  " U5      -
  n[        R                  " U5      [        R                  " U5      -
  nUU-
  nUR                  n/ n/ n[        SU5       H  nU R                  US-   -
  nU
US-   *    nU R                  U R
                  U   5      u  nn[        R                  " U5      [        R                  " U5      -
  nUU-
  U-  nUR                  U5        UR                  UU-
  U-  5        M     UR                  S5        [        R                  " UUS9n/ n / n!U R                  (       a  U* OUn"[        R                  " U"5      n#U#U"-  S-
  n$Sn%U R                   R"                  S:X  a  U"n&O;U R                   R"                  S:X  a  [        R                  " U"5      n&O
[%        5       e[        SUS-   5       HV  nU R                  [        R&                  " UUS-
  5      5        U!R                  U$U%-  U&-  5        U%US-   -  n%U$U"-  SU%-  -
  n$MX     [        R(                  " U 5      n [        R                  " U!US9n![        U5      S:  a  [        R(                  " USS9nOSnUS:X  a"  [        R                  " S/UR*                  US9n'OH[        R,                  R/                  U U!5      R1                  U5      R1                  UR*                  5      n'U R                  (       aK  UU-  U-  UU#-  U-  -
  n(Ub  [        R2                  " SU'SS U5      n)OSn)X-
  n*U(UU&-  U)U'S   U*-  -   -  -
  nOJUU-  U-  UU#-  U-  -
  n(Ub  [        R2                  " SU'SS U5      n)OSn)X-
  n*U(UU&-  U)U'S   U*-  -   -  -
  nUR1                  UR*                  5      nU$ )aI  
One step for the UniC (B(h) version).

Args:
    this_model_output (`torch.Tensor`):
        The model outputs at `x_t`.
    this_timestep (`int`):
        The current timestep `t`.
    last_sample (`torch.Tensor`):
        The generated sample before the last predictor `x_{t-1}`.
    this_sample (`torch.Tensor`):
        The generated sample after the last predictor `x_{t}`.
    order (`int`):
        The `p` of UniC-p at this step. The effective order of accuracy should be `order + 1`.

Returns:
    `torch.Tensor`:
        The corrected sample tensor at the current timestep.
r   this_timestepNr!   z4missing `last_sample` as a required keyword argumentr   z4missing `this_sample` as a required keyword argumentr#   r   r   zPassing `this_timestep` is deprecated and has no effect as model output conversion is now handled via an internal counter `self.step_index`r<   r"   r   r=   r&   r   r   r   r   )r   r   r   r
   r   rH   r   r   r   r   r   rd   ri   r   r1   r   rW   r2   rL   r   r   r   r   r   r_   r   )+rR   r  r   r  r   r  r   r   r   r  r   r   r   r   model_tr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  rhos_cr  corr_resD1_ts+                                              r   multistep_uni_c_bh_update)HeliosScheduler.multistep_uni_c_bh_updateI  s   < $'t9q=QfjjRV6W4y1}"1g !WXX4y1}"1g !WXX=4y1}Q !QRR$ ^ !..r"#EM $DOO <dkk$//\]J]>^XGX %XG77@!99(C(99W%		'(::IIh'%))H*==	y ##q%AAE*B"QU8,B!%!=!=dkk"o!NHh		(+eii.AAIi'1,BJJrNJJR2~& ! 	

3ll3v.??aR++b/B,";;""e+C[[$$-++b/C%''q%!)$AHHUYYsAE*+HHW{*S011q5 KlQ_4G	 % KKNLL6*s8a<++cq)CC A:\\3%qwwvFF\\''1-008;;AGGDF??X%)Gg,=,BBD <<(96#2;L<D3(VBZ$5F*FGGCX%)Gg,=,BBD <<(96#2;L<D3(VBZ$5F*FGGCffQWWo
r   r   rN   cus_step_indexcus_lower_order_numcus_this_ordercus_last_samplec           	         U R                   c  [        S5      eU
c  U R                  c  SU l        OXl        Ub  Xl        Ub  Xl        Ub  Xl        U R                  S:  =(       a1    U R                  S-
  U R                  ;  =(       a    U R                  S LnU R                  XUS9nUb  Ub  US S U l	        US S U l
        U(       a(  U R                  UU R                  UU R
                  UUS9nUb  Ub  XS'   USS  U l	        USS  U l
        O[        U R                  R                  S-
  5       HA  nU R                  US-      U R                  U'   U R                  US-      U R                  U'   MC     XR                  S'   X R                  S'   U R                  R                  (       aA  [!        U R                  R                  [#        U R$                  5      U R                  -
  5      nOU R                  R                  n[!        UU R                  S-   5      U l        U R
                  S:  d   eX0l        U R'                  UUU R
                  UU	S9nUc9  U R                  U R                  R                  :  a  U =R                  S-  sl        U
c  U =R                  S-  sl        U(       d  UXPR                  U R
                  4$ [)        UUU R                  U R
                  S9$ )	NzaNumber of inference steps is 'None', you need to run 'set_timesteps' after creating the schedulerr   r!   r   r<   )r  r   r  r   r  r   )r   r   r   r   r   )r   r   r   r   )r   r   r   rP   rO   r   r   r4   r   r   rN   r  rd   rW   r0   r3   rf   r   r^   r
  r   )rR   r   r   r   r   r   rN   r  r   r   r  r  r  r  use_correctormodel_output_convertr   r   r   s                      r   
step_unipcHeliosScheduler.step_unipc  s     ##+s  !&#$ -*$7!%,O&. OOavDOOa$7t?U?U$UvZ^ZjZjrvZv 	
  $88\a8b$)B!.s!3D!.s!3D33"6 ,,"oo) 4 F $)B 4"!.qr!2D!.qr!2D4;;33a78(,(:(:1q5(A""1%(,(:(:1q5(A""1% 9 &:r"%-r";;((T[[55s4>>7JT__7\]J11Jj$*?*?!*CD"""!44%//! 5 
 &$$t{{'?'??%%*% !!0@0@$//RR$#'((	
 	
r   c                     U R                   R                  S:X  a  U R                  UUUUUS9$ U R                   R                  S:X  a  U R                  UUUUS9$ [        e)Neuler)r   r   r   r   r   r'   )r   r   r   r   )rW   r7   r   r  rL   )rR   r   r   r   r   r   s         r   r   HeliosScheduler.step>  sy     ;;%%0??)!#' #   [[''72??)!'	 #   &%r   c                 $   S /U R                   R                  -  U l        S /U R                   R                  -  U l        SU l        U R                   R
                  U l        U R                   R                  U l        S U l        S U l        S U l	        g )Nr   )
rW   r0   r   rN   rO   r4   r5   r   rP   rQ   r   s    r   r   'HeliosScheduler.reset_scheduler_historyX  sw    "Vdkk&>&>>"Vdkk&>&>> !!%!>!>,, r   c                 .    U R                   R                  $ r   r   r   s    r   __len__HeliosScheduler.__len__b  s    {{...r   )rQ   rP   r4   rE   r-   r   rO   r   r   rF   r1   rK   rJ   rH   rC   r5   rD   r   rN   rA   r^   rB   )r   )NNNNFr   )NNNNNT)NNTNNNNNNNNN)NNNT)-r   r   r   r   _compatiblesr   r   r   floatlistboolstrr   r   rS   ra   rG   propertyr   r   r   r   r   r   r   rl   r   r   r   r   r   r   	Generatorr   tupler   r   r   r
  r  r  r   r   r&  r   r   r   r   r   r   #   s    LE $(0"0 "&')#' $%%*<I'0! 0! 0! 	0!
 0! 0! 0! 0! 0! 0! 0!  0!  90! !0!  !0!" #0!$ #%0!& !!89'0! 0!d'$:Mx     ! !(3 (7 #'%)"',= = 4Z= ell"	=
 t= 4K= !%=@9U 95 9U\\ 9,D0#1 /3$(,0*./3 />''/> %+++/> !!	/>
 ??T)/>   4'/> %%,/> /> 
	&/>d   $"NllN 	N
 ||N 
Nh  $"#'DllD 	D
 D ||D LLD 
DT %)$(%)"L <<L \\	L
 \\L L llL ||L 
Lb (,# ""%)"#'"#'"(,d
lld
 $d
 	d

 d
 d
 d
 lld
 ||d
 LLd
 d
 !d
 d
 d
 
	&d
T /3$(,0 &''& %+++& !!	&
 ??T)& & 
	&&4!/r   r   )rg   dataclassesr   typingr   numpyrX   r   configuration_utilsr   r   schedulers.scheduling_utilsr   utilsr	   r
   r   r   r   r   r   <module>r6     sJ     !    A 8 ) "J " "@/nk @/r   