
    
3jt              	          S SK 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
JrJr  SSKJr  SSKJrJrJr  \" 5       (       a  S SKr\R*                  " \5      r  SS	\S
\S\S   S\R4                  4S jjr " S S\\5      rg)    N)Literal   )ConfigMixinregister_to_config)	deprecateis_scipy_availablelogging)randn_tensor   )KarrasDiffusionSchedulersSchedulerMixinSchedulerOutputnum_diffusion_timestepsmax_betaalpha_transform_type)cosineexplaplacereturnc           
      :   US:X  a  S nO"US:X  a  S nOUS:X  a  S nO[        SU 35      e/ n[        U 5       H<  nXP-  nUS-   U -  nUR                  [        SU" U5      U" U5      -  -
  U5      5        M>     [        R
                  " U[        R                  S	9$ )
a  
Create a beta schedule that discretizes the given alpha_t_bar function, which defines the cumulative product of
(1-beta) over time from t = [0,1].

Contains a function alpha_bar that takes an argument t and transforms it to the cumulative product of (1-beta) up
to that part of the diffusion process.

Args:
    num_diffusion_timesteps (`int`):
        The number of betas to produce.
    max_beta (`float`, defaults to `0.999`):
        The maximum beta to use; use values lower than 1 to avoid numerical instability.
    alpha_transform_type (`str`, defaults to `"cosine"`):
        The type of noise schedule for `alpha_bar`. Choose from `cosine`, `exp`, or `laplace`.

Returns:
    `torch.Tensor`:
        The betas used by the scheduler to step the model outputs.
r   c                 h    [         R                  " U S-   S-  [         R                  -  S-  5      S-  $ )NgMb?gT㥛 ?r   )mathcospits    n/home/wildlama/miniconda3/lib/python3.13/site-packages/diffusers/schedulers/scheduling_dpmsolver_singlestep.pyalpha_bar_fn)betas_for_alpha_bar.<locals>.alpha_bar_fn>   s-    88QY%/$''9A=>!CC    r   c           	         S[         R                  " SSU -
  5      -  [         R                  " SS[         R                  " SU -
  5      -  -
  S-   5      -  n[         R                  " U5      n[         R
                  " USU-   -  5      $ )Ng      r         ?r   gư>)r   copysignlogfabsr   sqrt)r   lmbsnrs      r   r   r   C   sm    q#'22TXXa!diiPSVWPWFXBX>X[_>_5``C((3-C99SAG_--r    r   c                 4    [         R                  " U S-  5      $ )Ng      ()r   r   r   s    r   r   r   J   s    88AI&&r    z"Unsupported alpha_transform_type: r   dtype)
ValueErrorrangeappendmintorchtensorfloat32)r   r   r   r   betasit1t2s           r   betas_for_alpha_barr7   $   s    0 x'	D 
	*	.
 
	&	' =>R=STUUE*+(!e..S\"-R0@@@(KL , <<U]]33r    c            2          \ rS rSrSr\ V Vs/ s H  oR                  PM     snn rSr\	SSSSSS	S
SSSSSSSSSSSS\
" S5      * SSS4S\S\
S\
S\S   S\R                  \\
   -  S-  S\S\S   S\S\
S\
S\S    S!\S"   S#\S$\S%\S&\S'\S(\
S)\S*   S+\
S,\S-   S-  S.\S/\S   S0S40S1 jj5       rS2\S0\\   4S3 jr\S0\4S4 j5       r\S0\4S5 j5       rS`S6\S0S4S7 jjr    SaS2\S8\\R2                  -  S9\
S-  S:\\   S-  4S; jjrS<\R6                  S0\R6                  4S= jrS>\R                  S?\R                  S0\R                  4S@ jrS>\R6                  S0\\R6                  \R6                  4   4SA jrSB\R6                  S2\S0\R6                  4SC jr SB\R6                  S2\S0\R6                  4SD jr! SbSB\R6                  S2\SE\
SF\
S0\R6                  4
SG jjr"SSH.SI\R6                  S<\R6                  S-  S0\R6                  4SJ jjr#SSSK.SI\R6                  S<\R6                  S-  SL\R6                  S-  S0\R6                  4SM jjr$SSSK.SN\\R6                     S<\R6                  S-  SL\R6                  S-  S0\R6                  4SO jjr%SSSK.SN\\R6                     S<\R6                  S-  SL\R6                  S-  S0\R6                  4SP jjr&SSSSQ.SN\\R6                     S<\R6                  S-  SR\SL\R6                  S-  S0\R6                  4
SS jjr' ScST\\R6                  -  SU\R6                  S-  S0\4SV jjr(ST\\R6                  -  S0S4SW jr)  SdSI\R6                  ST\\R6                  -  S<\R6                  SX\RT                  S-  SY\S0\+\-  4SZ jjr,S<\R6                  S0\R6                  4S[ jr-S\\R6                  SL\R6                  S:\R\                  S0\R6                  4S] jr/S0\4S^ jr0S_r1gs  snn f )eDPMSolverSinglestepSchedulerX   u  
`DPMSolverSinglestepScheduler` is a fast dedicated high-order solver for diffusion ODEs.

This model inherits from [`SchedulerMixin`] and [`ConfigMixin`]. Check the superclass documentation for the generic
methods the library implements for all schedulers such as loading and saving.

Args:
    num_train_timesteps (`int`, defaults to `1000`):
        The number of diffusion steps to train the model.
    beta_start (`float`, defaults to `0.0001`):
        The starting `beta` value of inference.
    beta_end (`float`, defaults to `0.02`):
        The final `beta` value.
    beta_schedule (`"linear"`, `"scaled_linear"`, or `"squaredcos_cap_v2"`, defaults to `"linear"`):
        The beta schedule, a mapping from a beta range to a sequence of betas for stepping the model. Choose from
        `linear`, `scaled_linear`, or `squaredcos_cap_v2`.
    trained_betas (`np.ndarray` or `list[float]`, *optional*):
        Pass an array of betas directly to the constructor to bypass `beta_start` and `beta_end`.
    solver_order (`int`, defaults to `2`):
        The DPMSolver order which can be `1` or `2` or `3`. It is recommended to use `solver_order=2` for guided
        sampling, and `solver_order=3` for unconditional sampling.
    prediction_type (`"epsilon"`, `"sample"`, `"v_prediction"`, or `"flow_prediction"`, defaults to `"epsilon"`):
        Prediction type of the scheduler function; can be `epsilon` (predicts the noise of the diffusion process),
        `sample` (directly predicts the noisy sample`), `v_prediction` (see section 2.4 of [Imagen
        Video](https://huggingface.co/papers/2210.02303) paper), or `flow_prediction`.
    thresholding (`bool`, defaults to `False`):
        Whether to use the "dynamic thresholding" method. This is unsuitable for latent-space diffusion models such
        as Stable Diffusion.
    dynamic_thresholding_ratio (`float`, defaults to `0.995`):
        The ratio for the dynamic thresholding method. Valid only when `thresholding=True`.
    sample_max_value (`float`, defaults to `1.0`):
        The threshold value for dynamic thresholding. Valid only when `thresholding=True` and
        `algorithm_type="dpmsolver++"`.
    algorithm_type (`"dpmsolver"`, `"dpmsolver++"`, or `"sde-dpmsolver++"`, defaults to `"dpmsolver++"`):
        Algorithm type for the solver; can be `dpmsolver`, `dpmsolver++`, or `sde-dpmsolver++`. The `dpmsolver`
        type implements the algorithms in the [DPMSolver](https://huggingface.co/papers/2206.00927) paper, and the
        `dpmsolver++` type implements the algorithms in the [DPMSolver++](https://huggingface.co/papers/2211.01095)
        paper. It is recommended to use `dpmsolver++` or `sde-dpmsolver++` with `solver_order=2` for guided
        sampling like in Stable Diffusion.
    solver_type (`"midpoint"` or `"heun"`, defaults to `"midpoint"`):
        Solver type for the second-order solver; can be `midpoint` or `heun`. The solver type slightly affects the
        sample quality, especially for a small number of steps. It is recommended to use `midpoint` solvers.
    lower_order_final (`bool`, defaults to `False`):
        Whether to use lower-order solvers in the final steps. Only valid for < 15 inference steps. This can
        stabilize the sampling of DPMSolver for steps < 15, especially for steps <= 10.
    use_karras_sigmas (`bool`, *optional*, defaults to `False`):
        Whether to use Karras sigmas for step sizes in the noise schedule during the sampling process. If `True`,
        the sigmas are determined according to a sequence of noise levels {σi}.
    use_exponential_sigmas (`bool`, *optional*, defaults to `False`):
        Whether to use exponential sigmas for step sizes in the noise schedule during the sampling process.
    use_beta_sigmas (`bool`, *optional*, defaults to `False`):
        Whether to use beta sigmas for step sizes in the noise schedule during the sampling process. Refer to [Beta
        Sampling is All You Need](https://huggingface.co/papers/2407.12173) for more information.
    use_flow_sigmas (`bool`, *optional*, defaults to `False`):
        Whether to use flow sigmas for step sizes in the noise schedule during the sampling process.
    flow_shift (`float`, *optional*, defaults to `1.0`):
        The flow shift parameter for flow-based models.
    final_sigmas_type (`"zero"` or `"sigma_min"`, *optional*, defaults to `"zero"`):
        The final `sigma` value for the noise schedule during the sampling process. If `"sigma_min"`, the final
        sigma is the same as the last sigma in the training schedule. If `"zero"`, the final sigma is set to 0.
    lambda_min_clipped (`float`, defaults to `-inf`):
        Clipping threshold for the minimum value of `lambda(t)` for numerical stability. This is critical for the
        cosine (`squaredcos_cap_v2`) noise schedule.
    variance_type (`"learned"` or `"learned_range"`, *optional*):
        Set to `"learned"` or `"learned_range"` for diffusion models that predict variance. If set, the model's
        output contains the predicted Gaussian variance.
    use_dynamic_shifting (`bool`, defaults to `False`):
        Whether to use dynamic shifting for the noise schedule.
    time_shift_type (`"exponential"`, defaults to `"exponential"`):
        The type of time shifting to apply.
r   i  g-C6?g{Gz?linearNr   epsilonFgףp=
?      ?dpmsolver++midpointzeroinfexponentialnum_train_timesteps
beta_startbeta_endbeta_schedule)r;   scaled_linearsquaredcos_cap_v2trained_betassolver_orderprediction_type)r<   samplev_predictionflow_predictionthresholdingdynamic_thresholding_ratiosample_max_valuealgorithm_type	dpmsolverr>   sde-dpmsolver++solver_typer?   heunlower_order_finaluse_karras_sigmasuse_exponential_sigmasuse_beta_sigmasuse_flow_sigmas
flow_shiftfinal_sigmas_type)r@   	sigma_minlambda_min_clippedvariance_typelearnedlearned_rangeuse_dynamic_shiftingtime_shift_typer   c                 @   U R                   R                  (       a  [        5       (       d  [        S5      e[	        U R                   R                  U R                   R
                  U R                   R                  /5      S:  a  [        S5      eUS:X  a  Sn[        SSU5        Ub)  [        R                  " U[        R                  S9U l        OUS	:X  a*  [        R                  " X#U[        R                  S9U l        OkUS
:X  a4  [        R                  " US-  US-  U[        R                  S9S-  U l        O1US:X  a  [        U5      U l        O[        U SU R                    35      eSU R                  -
  U l        [        R$                  " U R"                  SS9U l        [        R(                  " U R&                  5      U l        [        R(                  " SU R&                  -
  5      U l        [        R.                  " U R*                  5      [        R.                  " U R,                  5      -
  U l        SU R&                  -
  U R&                  -  S-  U l        SU l        US;  a0  US:X  a  U R7                  SS9  O[        U SU R                    35      eUS;  a0  US;   a  U R7                  SS9  O[        U SU R                    35      eUS;  a  US:X  a  [        SU SU S35      eS U l        [:        R                  " SUS-
  U[:        R                  S9S S S2   R=                  5       n[        R>                  " U5      U l         S /U-  U l!        S U l"        U RG                  U5      U l$        S U l%        S U l&        U R2                  RO                  S 5      U l        g )!Nz:Make sure to install scipy if you want to use beta sigmas.r   znOnly one of `config.use_beta_sigmas`, `config.use_exponential_sigmas`, `config.use_karras_sigmas` can be used.rT   zalgorithm_type `dpmsolver` is deprecated and will be removed in a future version. Choose from `dpmsolver++` or `sde-dpmsolver++` insteadzalgorithm_types=dpmsolver1.0.0r*   r;   rG   r"   r   rH   z is not implemented for r=   r   dimrS   deisr>   )rR   rW   )logrhobh1bh2r?   )rV   r>   rU   r@   z`final_sigmas_type` z' is not supported for `algorithm_type` z$. Please choose `sigma_min` instead.cpu)(configr\   r   ImportErrorsumr[   rZ   r,   r   r0   r1   r2   r3   linspacer7   NotImplementedError	__class__alphascumprodalphas_cumprodr&   alpha_tsigma_tr$   lambda_tsigmasinit_noise_sigmar   num_inference_stepsnpcopy
from_numpy	timestepsmodel_outputsrL   get_order_list
order_list_step_index_begin_indexto)selfrC   rD   rE   rF   rI   rJ   rK   rO   rP   rQ   rR   rV   rY   rZ   r[   r\   r]   r^   r_   ra   rb   rf   rg   deprecation_messager   s                             r   __init__%DPMSolverSinglestepScheduler.__init__   sG   6 ;;&&/A/C/CZ[[++T[[-O-OQUQ\Q\QnQnopstt A  [( #m17<OP$m5==IDJh&
>QY^YfYfgDJo-
C3H[chcpcpquvvDJ11,-@ADJ%7OPTP^P^O_&`aaDJJ&#mmDKKQ?zz$"5"56zz!d&9&9"9:		$,,/%))DLL2IID///43F3FF3N !$ !PP'''}'E)^,<<TUYUcUcTd*eff2266''J'?)[M9QRVR`R`Qa*bcc!CCHY]cHc&'8&99`ao`p  qU  V 
 $( KK#6#:<OWYWaWabcgegcghmmo	)))4"Vl2--.AB kknnU+r    r   c                 @   UnU R                   R                  nUS:  a  [        S5      eU R                   R                  (       a  US:X  aH  US-  S:X  a  / SQUS-  S-
  -  SS/-   S/-   nOUS-  S:X  a  / SQUS-  -  S/-   nO|/ SQUS-  -  SS/-   nOlUS:X  a+  US-  S:X  a  SS/US-  S-
  -  SS/-   nOJSS/US-  -  S/-   nO;US:X  a  S/U-  nO.US:X  a  / SQUS-  -  nOUS:X  a  SS/US-  -  nOUS:X  a  S/U-  nU R                   R                  S:X  a  SWS'   W$ )	a  
Computes the solver order at each time step.

Args:
    num_inference_steps (`int`):
        The number of diffusion steps used when generating samples with a pre-trained model.

Returns:
    `list[int]`:
        The list of solver orders for each timestep.
   z,Order > 3 is not supported by this schedulerr   )r   r   r   r   r   r@   rq   )rs   rJ   r,   rY   r_   )r   r   stepsorderorderss        r   r   +DPMSolverSinglestepScheduler.get_order_list   s`    $((19KLL;;((z19>&%1*q.9QFBaSHFQY!^&%1*5;F&%1*5A>F!19>VuzA~6!Q?FVuz2aS8F!uz"eqj1!Q5A:.!u;;((F2F2Jr    c                     U R                   $ )z
The index counter for current timestep. It will increase 1 after each scheduler step.

Returns:
    `int` or `None`:
        The current step index.
)r   r   s    r   
step_index'DPMSolverSinglestepScheduler.step_index)  s     r    c                     U R                   $ )z
The index for the first timestep. It should be set from pipeline with `set_begin_index` method.

Returns:
    `int` or `None`:
        The begin index.
r   r   s    r   begin_index(DPMSolverSinglestepScheduler.begin_index4  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`, defaults to `0`):
        The begin index for the scheduler.
Nr   )r   r   s     r   set_begin_index,DPMSolverSinglestepScheduler.set_begin_index@  s
     (r    devicemur   c           	         Ub\  U R                   R                  (       a  U R                   R                  S:X  d   e[        R                  " U5      U R                   l        Uc  Uc  [        S5      eUb  Ub  [        S5      eUb&  U R                   R                  (       a  [        S5      eUb&  U R                   R                  (       a  [        S5      eUb&  U R                   R                  (       a  [        S5      eU=(       d    [        U5      nXl        Ub4  [        R                  " U5      R                  [        R                  5      nO[        R                   " [        R"                  " U R$                  S/5      U R                   R&                  5      nUR)                  5       n[        R*                  " SU R                   R,                  S-
  U-
  US-   5      R/                  5       SSS	2   SS	 R1                  5       R                  [        R                  5      n[        R                  " SU R2                  -
  U R2                  -  S
-  5      n[        R4                  " U5      nU R                   R                  (       ax  [        R"                  " U5      R1                  5       nU R7                  XaS9n[        R                  " U Vs/ s H  oR9                  X5      PM     sn5      R/                  5       nGOU R                   R                  (       aj  [        R"                  " U5      R1                  5       nU R;                  XaS9n[        R                  " U Vs/ s H  oR9                  X5      PM     sn5      nGOU R                   R                  (       aj  [        R"                  " U5      R1                  5       nU R=                  XaS9n[        R                  " U Vs/ s H  oR9                  X5      PM     sn5      nGOU R                   R>                  (       a  [        R*                  " SSU R                   R,                  -  US-   5      n	SU	-
  n[        R"                  " U R                   R
                  U-  SU R                   R
                  S-
  U-  -   -  5      SS	 R1                  5       nX`R                   R,                  -  R1                  5       nO6[        R@                  " U[        RB                  " S[        U5      5      U5      nU R                   RD                  S:X  a&  SU R2                  S   -
  U R2                  S   -  S
-  n
O?U R                   RD                  S:X  a  Sn
O"[        SU R                   RD                   35      e[        RF                  " Xj//5      R                  [        RH                  5      n[        RJ                  " U5      RM                  US9U l'        [        RJ                  " U5      RM                  U[        R                  S9U l(        S/U R                   RR                  -  U l*        SU l+        U R                   RX                  (       d@  XR                   RR                  -  S:w  a$  [Z        R]                  S5        U R_                  SS9  U R                   RX                  (       d>  U R                   RD                  S:X  a$  [Z        R]                  S5        U R_                  SS9  U Ra                  U5      U l1        SU l2        SU l3        U RN                  RM                  S5      U l'        gs  snf s  snf s  snf )a  
Sets the discrete timesteps used for the diffusion chain (to be run before inference).

Args:
    num_inference_steps (`int`, *optional*):
        The number of diffusion steps used when generating samples with a pre-trained model.
    device (`str` or `torch.device`, *optional*):
        The device to which the timesteps should be moved to. If `None`, the timesteps are not moved.
    timesteps (`list[int]`, *optional*):
        Custom timesteps used to support arbitrary spacing between timesteps. If `None`, then the default
        timestep spacing strategy of equal spacing between timesteps schedule is used. If `timesteps` is
        passed, `num_inference_steps` must be `None`.
NrB   z?Must pass exactly one of  `num_inference_steps` or `timesteps`.z<Cannot use `timesteps` when `config.use_karras_sigmas=True`.zCCannot set `timesteps` with `config.use_exponential_sigmas = True`.z<Cannot set `timesteps` with `config.use_beta_sigmas = True`.r   r   rq   r"   )	in_sigmasr   r=   r`   r@   zC `final_sigmas_type` must be one of `sigma_min` or `zero`, but got )r   r   r+   zChanging scheduler {self.config} to have `lower_order_final` set to True to handle uneven amount of inference steps. Please make sure to always use an even number of `num_inference steps when using `lower_order_final=False`.T)rY   z `last_sigmas_type='zero'` is not supported for `lower_order_final=False`. Changing scheduler {self.config} to have `lower_order_final` set to True.rr   )4rs   rf   rg   r   r   r^   r,   rZ   r[   r\   lenr   arrayastypeint64r0   searchsortedflipr~   ra   itemrv   rC   roundr   r{   r$   _convert_to_karras_sigma_to_t_convert_to_exponential_convert_to_betar]   interparanger_   concatenater2   r   r   r   r   rJ   r   rL   rY   loggerwarningr   r   r   r   r   )r   r   r   r   r   clipped_idxr   
log_sigmassigmary   
sigma_lasts              r   set_timesteps*DPMSolverSinglestepScheduler.set_timestepsJ  s   ( >;;338S8SWd8ddd%'VVBZDKK"&9+<^__*y/D^__ T[[%B%B[\\ T[[%G%Gbcc T[[%@%@[\\1CS^#6  +22288<I  ,,UZZs-KT[[MkMklK%**,KAt{{>>B[PRehiRij2"$!	  A 3 33t7J7JJsRSVVF^
;;((WWV_))+F,,v,gFSY!ZSY%"2"25"ESY!Z[aacI[[//WWV_))+F11F1lFSY!ZSY%"2"25"ESY!Z[I[[((WWV_))+F**V*eFSY!ZSY%"2"25"ESY!Z[I[[(([[A(G(G$GI\_`I`aF6\FWWT[[33f<T[[E[E[^_E_ciDi@ijklomopuuwF++"A"AAGGIIYYy"))As6{*CVLF;;((K7t221559L9LQ9OOTWWJ[[**f4JUVZVaVaVsVsUtu   67>>rzzJ&&v.111@)))477vU[[7Y"Vdkk&>&>>{{,,1D{{G_G_1_cd1dNN s ##d#;{{,,1N1NRX1XNN g ##d#;--.AB   kknnU+e "[ "[ "[s   ]]
#]rL   c                 X   UR                   nUR                  tp4nU[        R                  [        R                  4;  a  UR                  5       nUR                  X4[        R                  " U5      -  5      nUR                  5       n[        R                  " X`R                  R                  SS9n[        R                  " USU R                  R                  S9nUR                  S5      n[        R                  " X* U5      U-  nUR                  " X4/UQ76 nUR!                  U5      nU$ )a
  
Apply dynamic thresholding to the predicted sample.

"Dynamic thresholding: At each sampling step we set s to a certain percentile absolute pixel value in xt0 (the
prediction of x_0 at timestep t), and if s > 1, then we threshold xt0 to the range [-s, s] and then divide by
s. Dynamic thresholding pushes saturated pixels (those near -1 and 1) inwards, thereby actively preventing
pixels from saturation at each step. We find that dynamic thresholding results in significantly better
photorealism as well as better image-text alignment, especially when using very large guidance weights."

https://huggingface.co/papers/2205.11487

Args:
    sample (`torch.Tensor`):
        The predicted sample to be thresholded.

Returns:
    `torch.Tensor`:
        The thresholded sample.
r   rj   )r/   max)r+   shaper0   r2   float64floatreshaper   prodabsquantilers   rP   clamprQ   	unsqueezer   )r   rL   r+   
batch_sizechannelsremaining_dims
abs_sampless           r   _threshold_sample.DPMSolverSinglestepScheduler._threshold_sample  s    ( 06-
~66\\^F 
rww~7N,NOZZ\
NN:{{'M'MSTUKK1$++66
 KKNVR+a/
F~F5!r    r   r   c                    [         R                  " [         R                  " US5      5      nX2SS2[         R                  4   -
  n[         R                  " US:  SS9R                  SS9R                  UR                  S   S-
  S9nUS-   nX%   nX&   nXs-
  Xx-
  -  n	[         R                  " U	SS5      n	SU	-
  U-  X-  -   n
U
R                  UR                  5      n
U
$ )at  
Convert sigma values to corresponding timestep values through interpolation.

Args:
    sigma (`np.ndarray`):
        The sigma value(s) to convert to timestep(s).
    log_sigmas (`np.ndarray`):
        The logarithm of the sigma schedule used for interpolation.

Returns:
    `np.ndarray`:
        The interpolated timestep value(s) corresponding to the input sigma(s).
g|=Nr   )axisr   )r   r   )	r   r$   maximumnewaxiscumsumargmaxclipr   r   )r   r   r   	log_sigmadistslow_idxhigh_idxlowhighwr   s              r   r   (DPMSolverSinglestepScheduler._sigma_to_t  s     FF2::eU34	 q"**}55 ))UaZq188a8@EE*JZJZ[\J]`aJaEbQ;!# _,GGAq! Ug,IIekk"r    c                 v    U R                   R                  (       a
  SU-
  nUnX#4$ SUS-  S-   S-  -  nX-  nX#4$ )z
Convert sigma values to alpha_t and sigma_t values.

Args:
    sigma (`torch.Tensor`):
        The sigma value(s) to convert.

Returns:
    `tuple[torch.Tensor, torch.Tensor]`:
        A tuple containing (alpha_t, sigma_t) values.
r   r   r"   )rs   r]   )r   r   r|   r}   s       r   _sigma_to_alpha_sigma_t4DPMSolverSinglestepScheduler._sigma_to_alpha_sigma_t  sS     ;;&&%iGG
  E1HqLS01GoGr    r   c                    [        U R                  S5      (       a  U R                  R                  nOSn[        U R                  S5      (       a  U R                  R                  nOSnUb  UOUS   R	                  5       nUb  UOUS   R	                  5       nSn[
        R                  " SSU5      nUSU-  -  nUSU-  -  nXXx-
  -  -   U-  n	U	$ )a  
Construct the noise schedule as proposed in [Elucidating the Design Space of Diffusion-Based Generative
Models](https://huggingface.co/papers/2206.00364).

Args:
    in_sigmas (`torch.Tensor`):
        The input sigma values to be converted.
    num_inference_steps (`int`):
        The number of inference steps to generate the noise schedule for.

Returns:
    `torch.Tensor`:
        The converted sigma values following the Karras noise schedule.
r`   N	sigma_maxrq   r   g      @r   )hasattrrs   r`   r   r   r   rv   )
r   r   r   r`   r   rhorampmin_inv_rhomax_inv_rhor   s
             r   r   /DPMSolverSinglestepScheduler._convert_to_karras  s    $ 4;;,,--II4;;,,--II!*!6IIbM<N<N<P	!*!6IIaL<M<M<O	{{1a!45AG,AG,(A BBsJr    c                    [        U R                  S5      (       a  U R                  R                  nOSn[        U R                  S5      (       a  U R                  R                  nOSnUb  UOUS   R	                  5       nUb  UOUS   R	                  5       n[
        R                  " [
        R                  " [        R                  " U5      [        R                  " U5      U5      5      nU$ )aP  
Construct an exponential noise schedule.

Args:
    in_sigmas (`torch.Tensor`):
        The input sigma values to be converted.
    num_inference_steps (`int`):
        The number of inference steps to generate the noise schedule for.

Returns:
    `torch.Tensor`:
        The converted sigma values following an exponential schedule.
r`   Nr   rq   r   )
r   rs   r`   r   r   r   r   rv   r   r$   )r   r   r   r`   r   r   s         r   r   4DPMSolverSinglestepScheduler._convert_to_exponentialE  s    " 4;;,,--II4;;,,--II!*!6IIbM<N<N<P	!*!6IIaL<M<M<O	DHHY$7)9LNabcr    alphabetac           
      J   [        U R                  S5      (       a  U R                  R                  nOSn[        U R                  S5      (       a  U R                  R                  nOSnUb  UOUS   R	                  5       nUb  UOUS   R	                  5       n[
        R                  " S[
        R                  " SSU5      -
   Vs/ s H-  n[        R                  R                  R                  XsU5      PM/     sn Vs/ s H  nXXXe-
  -  -   PM     sn5      n	U	$ s  snf s  snf )az  
Construct a beta noise schedule as proposed in [Beta Sampling is All You
Need](https://huggingface.co/papers/2407.12173).

Args:
    in_sigmas (`torch.Tensor`):
        The input sigma values to be converted.
    num_inference_steps (`int`):
        The number of inference steps to generate the noise schedule for.
    alpha (`float`, *optional*, defaults to `0.6`):
        The alpha parameter for the beta distribution.
    beta (`float`, *optional*, defaults to `0.6`):
        The beta parameter for the beta distribution.

Returns:
    `torch.Tensor`:
        The converted sigma values following a beta distribution schedule.
r`   Nr   rq   r   r   )r   rs   r`   r   r   r   r   rv   scipystatsr   ppf)
r   r   r   r   r   r`   r   timestepr   r   s
             r   r   -DPMSolverSinglestepScheduler._convert_to_betag  s   0 4;;,,--II4;;,,--II!*!6IIbM<N<N<P	!*!6IIaL<M<M<O	
 %&Aq:M(N$N$N KK$$(($?$NC I$9:;
 s   4D?D rL   model_outputc                   [        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        U R                  R
                  S	;   Gao  U R                  R                  S
:X  a\  U R                  R                  S;   a  USS2SS24   nU R                  U R                     nU R                  U5      u  pxX(U-  -
  U-  n	OU R                  R                  S:X  a  Un	OU R                  R                  S:X  a6  U R                  U R                     nU R                  U5      u  pxXr-  X-  -
  n	O^U R                  R                  S:X  a!  U R                  U R                     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  Gaf  U R                  R                  S
:X  a)  U R                  R                  S;   a  USS2SS24   n
OUn
OU R                  R                  S:X  a7  U R                  U R                     nU R                  U5      u  pxX'U-  -
  U-  n
OsU R                  R                  S:X  a6  U R                  U R                     nU R                  U5      u  pxXq-  X-  -   n
O#[        SU R                  R                   S35      eU R                  R                  (       aB  U R                  U   U R                  U   pX(U
-  -
  U-  n	U R                  U	5      n	X'U	-  -
  U-  n
U
$ g)a  
Convert the model output to the corresponding type the DPMSolver/DPMSolver++ algorithm needs. DPM-Solver is
designed to discretize an integral of the noise prediction model, and DPM-Solver++ is designed to discretize an
integral of the data prediction model.

> [!TIP] > The algorithm and model type are decoupled. You can use either DPMSolver or DPMSolver++ for both
noise > prediction and data prediction models.

Args:
    model_output (`torch.Tensor`):
        The direct output from the learned diffusion model.
    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   ri   Passing `timesteps` is deprecated and has no effect as model output conversion is now handled via an internal counter `self.step_index`rp   r<   rc   r   rL   rM   rN   zprediction_type given as zo must be one of `epsilon`, `sample`, `v_prediction`, or `flow_prediction` for the DPMSolverSinglestepScheduler.rT   z\ must be one of `epsilon`, `sample`, or `v_prediction` for the DPMSolverSinglestepScheduler.)r   popr,   r   rs   rR   rK   rb   r   r   r   rO   r   r|   r}   )r   r   rL   argskwargsr   r   r|   r}   x0_predr<   s              r   convert_model_output1DPMSolverSinglestepScheduler.convert_model_output  s8   2 "$i!m47J1M>4y1}a !RSS Z ;;%%)KK{{**i7;;,,0LL#/2A2#6LDOO4#'#?#?#F !l$::gE,,8&,,>DOO4#'#?#?#F !*W-CC,,0AA++doo6 \#99 /0K0K/L Ma a 
 {{''009N [['';6{{**i7;;,,0LL*1bqb51G*G,,8DOO4#'#?#?#F !l$::gE,,>DOO4#'#?#?#F !073CC /0K0K/L ML L 
 {{''#'<<#94<<;Q!g$55@009!g$55@N7 7r    rL   noiser   c          	         [        U5      S:  a  US   OUR                  SS5      n[        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        Ub  [        SS	S5        U R                  U R
                  S-      U R                  U R
                     pU R                  U5      u  pU R                  U	5      u  p[        R                  " U
5      [        R                  " U5      -
  n[        R                  " U5      [        R                  " U	5      -
  nX-
  nU R                  R                  S:X  a*  X-  U-  U
[        R                  " U* 5      S-
  -  U-  -
  nU$ U R                  R                  S:X  a)  X-  U-  U[        R                  " U5      S-
  -  U-  -
  nU$ U R                  R                  S:X  a~  Uc   eX-  [        R                  " U* 5      -  U-  U
S[        R                  " SU-  5      -
  -  U-  -   U[        R                  " S[        R                  " SU-  5      -
  5      -  U-  -   nW$ )a
  
One step for the first-order DPMSolver (equivalent to DDIM).

Args:
    model_output (`torch.Tensor`):
        The direct output from the learned diffusion model.
    timestep (`int`):
        The current discrete timestep in the diffusion chain.
    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.

Returns:
    `torch.Tensor`:
        The sample tensor at the previous timestep.
r   r   Nr   prev_timestepr   r   r   ri   r   Passing `prev_timestep` is deprecated and has no effect as model output conversion is now handled via an internal counter `self.step_index`r>   r=   rT   rU          )r   r   r,   r   r   r   r   r0   r$   rs   rR   r   r&   )r   r   rL   r   r   r   r   r  r}   sigma_sr|   alpha_sr~   lambda_shx_ts                   r   dpm_solver_first_order_update:DPMSolverSinglestepScheduler.dpm_solver_first_order_update  sR   2 "$i!m47J1M#&t9q=QfjjRV6W>4y1}a !RSS Z $ ^
  ;;t':;T[[=Y77@77@99W%		'(::99W%		'(::;;%%6$.'UYYr]S=P2QUa1aaC 
 [['';6$.'UYYq\C=O2PT`1``C 
 [[''+<<$$$"UYYr]2f<a%))D1H"556,FGEJJsUYYrAv->'>??%GH 
 
r    model_output_listc          	      p
   [        U5      S:  a  US   OUR                  SS5      n[        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        Ub  [        SSS
5        U R                  U R
                  S-      U R                  U R
                     U R                  U R
                  S-
     pnU R                  U5      u  pU R                  U	5      u  pU R                  U
5      u  p[        R                  " U5      [        R                  " U5      -
  n[        R                  " U5      [        R                  " U	5      -
  n[        R                  " U5      [        R                  " U
5      -
  nUS   US   nnUU-
  UU-
  nnUU-  nUSU-  UU-
  -  nnU R                  R                  S:X  a  U R                  R                  S:X  aN  X-  U-  U[        R                  " U* 5      S-
  -  U-  -
  SU[        R                  " U* 5      S-
  -  -  U-  -
  nU$ U R                  R                  S:X  aO  X-  U-  U[        R                  " U* 5      S-
  -  U-  -
  U[        R                  " U* 5      S-
  U-  S-   -  U-  -   nW$ U R                  R                  S:X  a  U R                  R                  S:X  aL  X-  U-  U[        R                  " U5      S-
  -  U-  -
  SU[        R                  " U5      S-
  -  -  U-  -
  nU$ U R                  R                  S:X  aM  X-  U-  U[        R                  " U5      S-
  -  U-  -
  U[        R                  " U5      S-
  U-  S-
  -  U-  -
  nW$ U R                  R                  S:X  Ga  Uc   eU R                  R                  S:X  a  X-  [        R                  " U* 5      -  U-  US[        R                  " SU-  5      -
  -  U-  -   SUS[        R                  " SU-  5      -
  -  -  U-  -   U[        R                  " S[        R                  " SU-  5      -
  5      -  U-  -   nU$ U R                  R                  S:X  a  X-  [        R                  " U* 5      -  U-  US[        R                  " SU-  5      -
  -  U-  -   US[        R                  " SU-  5      -
  SU-  -  S-   -  U-  -   U[        R                  " S[        R                  " SU-  5      -
  5      -  U-  -   nW$ )a  
One step for the second-order singlestep DPMSolver that computes the solution at time `prev_timestep` from the
time `timestep_list[-2]`.

Args:
    model_output_list (`list[torch.Tensor]`):
        The direct outputs from learned diffusion model at current and latter timesteps.
    timestep (`int`):
        The current and latter discrete timestep in the diffusion chain.
    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.

Returns:
    `torch.Tensor`:
        The sample tensor at the previous timestep.
r   timestep_listNr   r  r   r   ri   Passing `timestep_list` is deprecated and has no effect as model output conversion is now handled via an internal counter `self.step_index`r  rq   r  r=   r>   r?   r"   rX   rT   rU   r  r   r   r,   r   r   r   r   r0   r$   rs   rR   rV   r   r&   )r   r  rL   r   r   r   r  r  r}   sigma_s0sigma_s1r|   alpha_s0alpha_s1r~   	lambda_s0	lambda_s1m0m1r  h_0r0D0D1r	  s                            r   )singlestep_dpm_solver_second_order_updateFDPMSolverSinglestepScheduler.singlestep_dpm_solver_second_order_update7  sG   4 $'t9q=QfjjRV6W#&t9q=QfjjRV6W>4y1}a !RSS$ ^ $ ^ KK!+,KK(KK!+, $  77@!99(C!99(C99W%		'(::IIh'%))H*==	IIh'%))H*==	"2&(9"(=BI%y9'<31WcBh27+B;;%%6{{&&*4'61%))QB-#"56"<=W		1"(;<=BC R 
I ((F2'61%))QB-#"56"<=599aR=3#6!";c"ABbHI F 
= [['';6{{&&*4'61%))A,"45;<W		!s(:;<rAB 6 
- ((F2'61%))A,"45;<599Q<##5":S"@ARGH * 
! [[''+<<$$${{&&*4'%))QB-76A!eiiq&9"9:b@AWEIIdQh,?(?@ABFG 

3261B+B CCeKL  
 ((F2'%))QB-76A!eiiq&9"9:b@A34!8)<#<"JS"PQUWWX 

3261B+B CCeKL  
r    c          	         [        U5      S:  a  US   OUR                  SS5      n[        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        Ub  [        SSS
5        U R                  U R
                  S-      U R                  U R
                     U R                  U R
                  S-
     U R                  U R
                  S-
     4u  ppU R                  U5      u  pU R                  U	5      u  pU R                  U
5      u  pU R                  U5      u  p[        R                  " U5      [        R                  " U5      -
  n[        R                  " U5      [        R                  " U	5      -
  n[        R                  " U5      [        R                  " U
5      -
  n[        R                  " U5      [        R                  " U5      -
  nUS   US   US   nnnUU-
  UU-
  UU-
  nnnUU-  UU-  nnUnSU-  UU-
  -  SU-  UU-
  -  nnUU-  UU-  -
  UU-
  -  nSUU-
  -  UU-
  -  n U R                  R                  S:X  Ga  U R                  R                  S:X  aQ  X-  U-  U[        R                  " U* 5      S-
  -  U-  -
  U[        R                  " U* 5      S-
  U-  S-   -  U-  -   n!U!$ U R                  R                  S:X  a|  X-  U-  U[        R                  " U* 5      S-
  -  U-  -
  U[        R                  " U* 5      S-
  U-  S-   -  U-  -   U[        R                  " U* 5      S-
  U-   US-  -  S-
  -  U -  -
  n!W!$ U R                  R                  S:X  a  U R                  R                  S:X  aO  X-  U-  U[        R                  " U5      S-
  -  U-  -
  U[        R                  " U5      S-
  U-  S-
  -  U-  -
  n!U!$ U R                  R                  S:X  ay  X-  U-  U[        R                  " U5      S-
  -  U-  -
  U[        R                  " U5      S-
  U-  S-
  -  U-  -
  U[        R                  " U5      S-
  U-
  US-  -  S-
  -  U -  -
  n!W!$ U R                  R                  S:X  Ga  Uc   eU R                  R                  S:X  a  X-  [        R                  " U* 5      -  U-  US[        R                  " SU-  5      -
  -  U-  -   US[        R                  " SU-  5      -
  SU-  -  S-   -  U-  -   U[        R                  " S[        R                  " SU-  5      -
  5      -  U-  -   n!U!$ U R                  R                  S:X  a  X-  [        R                  " U* 5      -  U-  US[        R                  " SU-  5      -
  -  U-  -   US[        R                  " SU-  5      -
  SU-  -  S-   -  U-  -   US[        R                  " SU-  5      -
  SU-  -   SU-  S-  -  S-
  -  U -  -   U[        R                  " S[        R                  " SU-  5      -
  5      -  U-  -   n!W!$ )a  
One step for the third-order singlestep DPMSolver that computes the solution at time `prev_timestep` from the
time `timestep_list[-3]`.

Args:
    model_output_list (`list[torch.Tensor]`):
        The direct outputs from learned diffusion model at current and latter timesteps.
    timestep (`int`):
        The current and latter discrete timestep in the diffusion chain.
    prev_timestep (`int`):
        The previous discrete timestep in the diffusion chain.
    sample (`torch.Tensor`):
        A current instance of a sample created by diffusion process.

Returns:
    `torch.Tensor`:
        The sample tensor at the previous timestep.
r   r  Nr   r  r   r   ri   r  r  rq   r  r=   g       @r>   r?   rX   r"   rT   rU   r  r  )"r   r  rL   r   r   r   r  r  r}   r  r  sigma_s2r|   r  r  alpha_s2r~   r  r  	lambda_s2r  r  m2r  r  h_1r  r1r  D1_0D1_1r  D2r	  s"                                     r   (singlestep_dpm_solver_third_order_updateEDPMSolverSinglestepScheduler.singlestep_dpm_solver_third_order_update  s   6 $'t9q=QfjjRV6W#&t9q=QfjjRV6W>4y1}a !RSS$ ^ $ ^ KK!+,KK(KK!+,KK!+,	1
-8  77@!99(C!99(C!99(C99W%		'(::IIh'%))H*==	IIh'%))H*==	IIh'%))H*==	&r*,=b,ACTUWCXB*I	,A9yCX3q#'BBh27+cBh27-Cd4i"t)#R0D4K BG,;;%%6{{&&*4'61%))QB-#"56"<=599aR=3#6!";c"ABdJK X 
O ((F2'61%))QB-#"56"<=599aR=3#6!";c"ABbHI 599aR=3#6#:ad"BS"HIROP L 
A [['';6{{&&*4'61%))A,"45;<599Q<##5":S"@ATIJ : 
1 ((F2'61%))A,"45;<599Q<##5":S"@ARGH 599Q<##5#9QT"AC"GHBNO . 
# [[''+<<$$${{&&*4'%))QB-76A#		$((;";<BC34!8)<#<"JS"PQUYYZ 

3261B+B CCeKL  
 ((F2'%))QB-76A#		$((;";<BC34!8)<#<"JS"PQUWWX 34!8)<#<q#IdUVh[\_"\_b"bcgiij 

3261B+B CCeK	L  
r    rL   r   r   r   c                   [        U5      S:  a  US   OUR                  SS5      n[        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b  [        SS
S5        US:X  a  U R	                  US   X$S9$ US:X  a  U R                  XUS9$ US:X  a  U R                  XUS9$ [        SU 35      e)a]  
One step for the singlestep DPMSolver.

Args:
    model_output_list (`list[torch.Tensor]`):
        The direct outputs from learned diffusion model at current and latter timesteps.
    timestep (`int`):
        The current and latter discrete timestep in the diffusion chain.
    prev_timestep (`int`):
        The previous discrete timestep in the diffusion chain.
    sample (`torch.Tensor`):
        A current instance of a sample created by diffusion process.
    order (`int`):
        The solver order at this step.

Returns:
    `torch.Tensor`:
        The sample tensor at the previous timestep.
r   r  Nr   r  r   r   r   z.missing `order` as a required keyword argumentri   r  r  rq   r   zOrder must be 1, 2, 3, got )r   r   r,   r   r
  r  r*  )	r   r  rL   r   r   r   r   r  r  s	            r   singlestep_dpm_solver_update9DPMSolverSinglestepScheduler.singlestep_dpm_solver_update   s=   8 $'t9q=QfjjRV6W#&t9q=QfjjRV6W>4y1}a !RSS=4y1}Q !QRR$ ^ $ ^ A:556G6KTZ5hhaZAABSjoAppaZ@@ARin@oo:5'BCCr    r   schedule_timestepsc                    Uc  U R                   nX!:H  R                  5       n[        U5      S:X  a  [        U R                   5      S-
  nU$ [        U5      S:  a  US   R                  5       nU$ US   R                  5       nU$ )ab  
Find the index for a given timestep in the schedule.

Args:
    timestep (`int` or `torch.Tensor`):
        The timestep for which to find the index.
    schedule_timesteps (`torch.Tensor`, *optional*):
        The timestep schedule to search in. If `None`, uses `self.timesteps`.

Returns:
    `int`:
        The index of the timestep in the schedule.
r   r   )r   nonzeror   r   )r   r   r0  index_candidatesr   s        r   index_for_timestep/DPMSolverSinglestepScheduler.index_for_timestep`  s    $ %!%.:CCE A%T^^,q0J  !"Q&)!,113J  *!,113J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)z
Initialize the step_index counter for the scheduler.

Args:
    timestep (`int` or `torch.Tensor`):
        The current timestep for which to initialize the step index.
N)
r   
isinstancer0   Tensorr   r   r   r4  r   r   )r   r   s     r   _init_step_index-DPMSolverSinglestepScheduler._init_step_index  sZ     #(ELL11#;;t~~'<'<=#66x@D#00Dr    	generatorreturn_dictc                    U R                   c  [        S5      eU R                  c  U R                  U5        U R	                  XS9n[        U R                  R                  S-
  5       H"  nU R                  US-      U R                  U'   M$     XR                  S'   U R                  R                  S:X  a*  [        UR                  XAR                  UR                  S9nOSnU R                  U R                     nU R                  U*    c  US-  nU R                  U*    c  M  US:X  a  X0l        U R!                  U R                  U R                  XS9n	U =R"                  S-  sl        U(       d  U	4$ [%        U	S	9$ )
a  
Predict the sample from the previous timestep by reversing the SDE. This function propagates the sample with
the singlestep DPMSolver.

Args:
    model_output (`torch.Tensor`):
        The direct output from learned diffusion model.
    timestep (`int` or `torch.Tensor`):
        The current discrete timestep in the diffusion chain.
    sample (`torch.Tensor`):
        A current instance of a sample created by the diffusion process.
    generator (`torch.Generator`, *optional*):
        A random number generator for stochastic sampling.
    return_dict (`bool`, defaults to `True`):
        Whether or not to return a [`~schedulers.scheduling_utils.SchedulerOutput`] or `tuple`.

Returns:
    [`~schedulers.scheduling_utils.SchedulerOutput`] or `tuple`:
        If return_dict is `True`, [`~schedulers.scheduling_utils.SchedulerOutput`] is returned, otherwise a
        tuple is returned where the first element is the sample tensor.

NzaNumber of inference steps is 'None', you need to run 'set_timesteps' after creating the schedulerr   r   rq   rU   )r;  r   r+   r,  )prev_sample)r   r,   r   r9  r   r-   rs   rJ   r   rR   r
   r   r   r+   r   rL   r.  r   r   )
r   r   r   rL   r;  r<  r4   r   r   r>  s
             r   step!DPMSolverSinglestepScheduler.step  sx   < ##+s  ??"!!(+000Mt{{//!34A$($6$6q1u$=Dq! 5!-2;;%%):: ""i@S@S[g[m[mE E0   %(0QJE   %(0 A: K77t{{% 8 

 	A>!;77r    c                     U$ )z
Ensures interchangeability with schedulers that need to scale the denoising model input depending on the
current timestep.

Args:
    sample (`torch.Tensor`):
        The input sample.

Returns:
    `torch.Tensor`:
        A scaled input sample.
 )r   rL   r   r   s       r   scale_model_input.DPMSolverSinglestepScheduler.scale_model_input  s	     r    original_samplesc                 *   U R                   R                  UR                  UR                  S9nUR                  R                  S:X  av  [
        R                  " U5      (       a[  U R                  R                  UR                  [
        R                  S9nUR                  UR                  [
        R                  S9nO@U R                  R                  UR                  5      nUR                  UR                  5      nU R                  c!  U Vs/ s H  o`R                  Xe5      PM     nnOHU R                  b  U R                  /UR                  S   -  nOU R                  /UR                  S   -  nXG   R                  5       n[        UR                  5      [        UR                  5      :  a?  UR                  S5      n[        UR                  5      [        UR                  5      :  a  M?  U R!                  U5      u  pX-  X-  -   nU$ s  snf )a  
Add noise to the original samples according to the noise schedule at the specified timesteps.

Args:
    original_samples (`torch.Tensor`):
        The original samples without noise.
    noise (`torch.Tensor`):
        The noise to add to the samples.
    timesteps (`torch.IntTensor`):
        The timesteps at which to add noise to the samples.

Returns:
    `torch.Tensor`:
        The noisy samples.
r   mpsr*   r   rq   )r   r   r   r+   typer0   is_floating_pointr   r2   r   r4  r   r   flattenr   r   r   )r   rE  r   r   r   r0  r   step_indicesr   r|   r}   noisy_sampless               r   	add_noise&DPMSolverSinglestepScheduler.add_noise  s   , '7'>'>FVF\F\]""''50U5L5LY5W5W!%!2!23C3J3JRWR_R_!2!`!%5%<%<EMMRI!%!2!23C3J3J!K!%5%<%<=I #T]^T]q33AJT]L^L__( OO,yq/AAL !,,-	0BBL$,,.%++%5%;%;!<<OOB'E %++%5%;%;!<<  77>2W_D _s   Hc                 .    U R                   R                  $ N)rs   rC   r   s    r   __len__$DPMSolverSinglestepScheduler.__len__  s    {{...r    )r   r   r|   ry   r{   r3   r   r~   r   r   r   rL   r}   r   r   )r   )NNNN)333333?rS  rP  )NT)2__name__
__module____qualname____firstlineno____doc__r   name_compatiblesr   r   r   intr   r   ndarraylistboolr   r   propertyr   r   r   strr0   r   r   r8  r   r   tupler   r   r   r   r   r
  r  r*  r.  r4  r9  	Generatorr   r?  rC  	IntTensorrM  rQ  __static_attributes__).0es   00r   r9   r9   X   sK   FP %>>$=qFF$=>LE $("QY9=[d",1"%Q^3="'"'', % %:@%*5\MDH%*2?1V, V, V, 	V,
 MNV, zzDK/$6V, V, !!WXV, V, %*V,  V,   MNV, /0V,  V,  V,  !%!V," #V,$ %V,& 'V,( ##67)V,* "+V,, 9:TA-V,. #/V,0 !/1V,2 
3V, V,p*# *$s) *X  C     !S ! !(3 (t ( $(%)&*j, j, ell"j, DL	j,
 9t#j,Z) ) )X" " "

 "J U\\  eELLRWR^R^D^>_  ,$ELL $s $W\WcWc $N TW \a\h\h F dg..<?.HM.[`.	.h '+	^ll^ t#	^ 
^H '+%)>ll> t#	>
 ||d"> 
>H '+%)m-m t#	m
 ||d"m 
mf '+%)x-x t#	x
 ||d"x 
x| '+%)=D-=D t#	=D
 =D ||d"=D 
=DF 37"$" "LL4/" 
	"J1u||); 1 1* -1 G8llG8 $G8 	G8
 ??T)G8 G8 
5	 G8R %,,  /,,/ ||/ ??	/
 
/b/ /}# ?s   O8r9   )g+?r   )r   typingr   numpyr   r0   configuration_utilsr   r   utilsr   r   r	   utils.torch_utilsr
   scheduling_utilsr   r   r   scipy.statsr   
get_loggerrT  r   r[  r   r8  r7   r9   rB  r    r   <module>ro     s   "     A : : , X X 			H	% @H14 1414 ""<=14 \\	14hH/>; H/r    