@@ -264,6 +264,10 @@ def get_order_list(self, num_inference_steps: int) -> List[int]:
264264 orders = [1 , 2 ] * (steps // 2 )
265265 elif order == 1 :
266266 orders = [1 ] * steps
267+
268+ if self .config .final_sigmas_type == "zero" :
269+ orders [- 1 ] = 1
270+
267271 return orders
268272
269273 @property
@@ -812,6 +816,7 @@ def singlestep_dpm_solver_third_order_update(
812816 model_output_list : List [torch .Tensor ],
813817 * args ,
814818 sample : torch .Tensor = None ,
819+ noise : Optional [torch .Tensor ] = None ,
815820 ** kwargs ,
816821 ) -> torch .Tensor :
817822 """
@@ -909,6 +914,23 @@ def singlestep_dpm_solver_third_order_update(
909914 - (sigma_t * ((torch .exp (h ) - 1.0 ) / h - 1.0 )) * D1
910915 - (sigma_t * ((torch .exp (h ) - 1.0 - h ) / h ** 2 - 0.5 )) * D2
911916 )
917+ elif self .config .algorithm_type == "sde-dpmsolver++" :
918+ assert noise is not None
919+ if self .config .solver_type == "midpoint" :
920+ x_t = (
921+ (sigma_t / sigma_s2 * torch .exp (- h )) * sample
922+ + (alpha_t * (1.0 - torch .exp (- 2.0 * h ))) * D0
923+ + (alpha_t * ((1.0 - torch .exp (- 2.0 * h )) / (- 2.0 * h ) + 1.0 )) * D1_1
924+ + sigma_t * torch .sqrt (1.0 - torch .exp (- 2 * h )) * noise
925+ )
926+ elif self .config .solver_type == "heun" :
927+ x_t = (
928+ (sigma_t / sigma_s2 * torch .exp (- h )) * sample
929+ + (alpha_t * (1.0 - torch .exp (- 2.0 * h ))) * D0
930+ + (alpha_t * ((1.0 - torch .exp (- 2.0 * h )) / (- 2.0 * h ) + 1.0 )) * D1
931+ + (alpha_t * ((1.0 - torch .exp (- 2.0 * h ) + (- 2.0 * h )) / (- 2.0 * h ) ** 2 - 0.5 )) * D2
932+ + sigma_t * torch .sqrt (1.0 - torch .exp (- 2 * h )) * noise
933+ )
912934 return x_t
913935
914936 def singlestep_dpm_solver_update (
@@ -970,7 +992,7 @@ def singlestep_dpm_solver_update(
970992 elif order == 2 :
971993 return self .singlestep_dpm_solver_second_order_update (model_output_list , sample = sample , noise = noise )
972994 elif order == 3 :
973- return self .singlestep_dpm_solver_third_order_update (model_output_list , sample = sample )
995+ return self .singlestep_dpm_solver_third_order_update (model_output_list , sample = sample , noise = noise )
974996 else :
975997 raise ValueError (f"Order must be 1, 2, 3, got { order } " )
976998
0 commit comments