






'''simple docstring'''


from math import factorial

lowerCamelCase_				: List[Any]    	=							{str(d): factorial(d) for d in range(10)}







def 	__magic_name__( _A					):
						'''simple docstring'''





						return sum(DIGIT_FACTORIAL[d] for d in str(_A					)					)







def 	__magic_name__( ):
						'''simple docstring'''





						UpperCamelCase__         = 7 * factorial(9					) + 1
						return sum(i for i in range(3						,      _A					) if sum_of_digit_factorial(_A					) == i					)


if __name__ == "__main__":
					print(f"""{solution() = }""")








'''simple docstring'''


import tempfile

import torch

from diffusers import (
    DEISMultistepScheduler,
    DPMSolverMultistepScheduler,
    DPMSolverSinglestepScheduler,
    UniPCMultistepScheduler,
)

from .test_schedulers import SchedulerCommonTest
class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''





			__a							:							Dict					     =					(DPMSolverSinglestepScheduler,)
			__a							:							List[Any]					     =					(("num_inference_steps", 25),)






			def 				A      (   self							:						List[Any] ,      **lowercase							:						Any			)							->    Optional[int]:

									'''simple docstring'''







									UpperCamelCase__         = {
									    """num_train_timesteps""": 1_0_0_0,
									    """beta_start""": 0.0_0_0_1,
									    """beta_end""": 0.0_2,
									    """beta_schedule""": """linear""",
									    """solver_order""": 2,
									    """prediction_type""": """epsilon""",
									    """thresholding""": False,
									    """sample_max_value""": 1.0,
									    """algorithm_type""": """dpmsolver++""",
									    """solver_type""": """midpoint""",
									    """lambda_min_clipped""": -float("""inf"""			),
									    """variance_type""": None,
									}

									config.update(**lowercase			)
									return config






			def 				A      (   self							:						List[Any] ,      lowercase							:						Tuple=0 ,      **lowercase							:						Optional[Any]			)							->    Any:

									'''simple docstring'''







									UpperCamelCase__         = dict(self.forward_default_kwargs			)
									UpperCamelCase__         = kwargs.pop("""num_inference_steps""" ,      lowercase			)
									UpperCamelCase__         = self.dummy_sample
									UpperCamelCase__         = 0.1 * sample
									UpperCamelCase__         = [residual + 0.2, residual + 0.1_5, residual + 0.1_0]

									for scheduler_class in self.scheduler_classes:
															UpperCamelCase__         = self.get_scheduler_config(**lowercase			)
															UpperCamelCase__         = scheduler_class(**lowercase			)
															scheduler.set_timesteps(lowercase			)
															# copy over dummy past residuals
															UpperCamelCase__         = dummy_past_residuals[: scheduler.config.solver_order]

															with tempfile.TemporaryDirectory() as tmpdirname:
																					scheduler.save_config(lowercase			)
																					UpperCamelCase__         = scheduler_class.from_pretrained(lowercase			)
																					new_scheduler.set_timesteps(lowercase			)
																					# copy over dummy past residuals
																					UpperCamelCase__         = dummy_past_residuals[: new_scheduler.config.solver_order]

															UpperCamelCase__    ,   UpperCamelCase__         = sample, sample
															for t in range(lowercase ,      time_step + scheduler.config.solver_order + 1			):
																					UpperCamelCase__         = scheduler.step(lowercase ,      lowercase ,      lowercase ,      **lowercase			).prev_sample
																					UpperCamelCase__         = new_scheduler.step(lowercase ,      lowercase ,      lowercase ,      **lowercase			).prev_sample

																					assert torch.sum(torch.abs(output - new_output			)			) < 1e-5, "Scheduler outputs are not identical"






			def 				A      (   self							:						List[str]			)							->    Any:

									'''simple docstring'''







									pass






			def 				A      (   self							:						Any ,      lowercase							:						List[Any]=0 ,      **lowercase							:						Optional[int]			)							->    Optional[int]:

									'''simple docstring'''







									UpperCamelCase__         = dict(self.forward_default_kwargs			)
									UpperCamelCase__         = kwargs.pop("""num_inference_steps""" ,      lowercase			)
									UpperCamelCase__         = self.dummy_sample
									UpperCamelCase__         = 0.1 * sample
									UpperCamelCase__         = [residual + 0.2, residual + 0.1_5, residual + 0.1_0]

									for scheduler_class in self.scheduler_classes:
															UpperCamelCase__         = self.get_scheduler_config()
															UpperCamelCase__         = scheduler_class(**lowercase			)
															scheduler.set_timesteps(lowercase			)

															# copy over dummy past residuals (must be after setting timesteps)
															UpperCamelCase__         = dummy_past_residuals[: scheduler.config.solver_order]

															with tempfile.TemporaryDirectory() as tmpdirname:
																					scheduler.save_config(lowercase			)
																					UpperCamelCase__         = scheduler_class.from_pretrained(lowercase			)
																					# copy over dummy past residuals
																					new_scheduler.set_timesteps(lowercase			)

																					# copy over dummy past residual (must be after setting timesteps)
																					UpperCamelCase__         = dummy_past_residuals[: new_scheduler.config.solver_order]

															UpperCamelCase__         = scheduler.step(lowercase ,      lowercase ,      lowercase ,      **lowercase			).prev_sample
															UpperCamelCase__         = new_scheduler.step(lowercase ,      lowercase ,      lowercase ,      **lowercase			).prev_sample

															assert torch.sum(torch.abs(output - new_output			)			) < 1e-5, "Scheduler outputs are not identical"






			def 				A      (   self							:						Union[str, Any] ,      lowercase							:						Any=None ,      **lowercase							:						List[Any]			)							->    Dict:

									'''simple docstring'''







									if scheduler is None:
															UpperCamelCase__         = self.scheduler_classes[0]
															UpperCamelCase__         = self.get_scheduler_config(**lowercase			)
															UpperCamelCase__         = scheduler_class(**lowercase			)

									UpperCamelCase__         = self.scheduler_classes[0]
									UpperCamelCase__         = self.get_scheduler_config(**lowercase			)
									UpperCamelCase__         = scheduler_class(**lowercase			)

									UpperCamelCase__         = 1_0
									UpperCamelCase__         = self.dummy_model()
									UpperCamelCase__         = self.dummy_sample_deter
									scheduler.set_timesteps(lowercase			)

									for i, t in enumerate(scheduler.timesteps			):
															UpperCamelCase__         = model(lowercase ,      lowercase			)
															UpperCamelCase__         = scheduler.step(lowercase ,      lowercase ,      lowercase			).prev_sample

									return sample






			def 				A      (   self							:						Any			)							->    List[Any]:

									'''simple docstring'''







									UpperCamelCase__         = DPMSolverSinglestepScheduler(**self.get_scheduler_config()			)
									UpperCamelCase__         = 5_0
									UpperCamelCase__         = self.dummy_model()
									UpperCamelCase__         = self.dummy_sample_deter
									scheduler.set_timesteps(lowercase			)

									# make sure that the first t is uneven
									for i, t in enumerate(scheduler.timesteps[3:]			):
															UpperCamelCase__         = model(lowercase ,      lowercase			)
															UpperCamelCase__         = scheduler.step(lowercase ,      lowercase ,      lowercase			).prev_sample

									UpperCamelCase__         = torch.mean(torch.abs(lowercase			)			)

									assert abs(result_mean.item() - 0.2_5_7_4			) < 1e-3






			def 				A      (   self							:						int			)							->    Union[str, Any]:

									'''simple docstring'''







									for timesteps in [2_5, 5_0, 1_0_0, 9_9_9, 1_0_0_0]:
															self.check_over_configs(num_train_timesteps=lowercase			)






			def 				A      (   self							:						Optional[int]			)							->    List[Any]:

									'''simple docstring'''







									UpperCamelCase__         = DPMSolverSinglestepScheduler(**self.get_scheduler_config()			)
									UpperCamelCase__         = self.full_loop(scheduler=lowercase			)
									UpperCamelCase__         = torch.mean(torch.abs(lowercase			)			)

									assert abs(result_mean.item() - 0.2_7_9_1			) < 1e-3

									UpperCamelCase__         = DEISMultistepScheduler.from_config(scheduler.config			)
									UpperCamelCase__         = DPMSolverMultistepScheduler.from_config(scheduler.config			)
									UpperCamelCase__         = UniPCMultistepScheduler.from_config(scheduler.config			)
									UpperCamelCase__         = DPMSolverSinglestepScheduler.from_config(scheduler.config			)

									UpperCamelCase__         = self.full_loop(scheduler=lowercase			)
									UpperCamelCase__         = torch.mean(torch.abs(lowercase			)			)

									assert abs(result_mean.item() - 0.2_7_9_1			) < 1e-3






			def 				A      (   self							:						Tuple			)							->    Union[str, Any]:

									'''simple docstring'''







									self.check_over_configs(thresholding=lowercase			)
									for order in [1, 2, 3]:
															for solver_type in ["midpoint", "heun"]:
																					for threshold in [0.5, 1.0, 2.0]:
																											for prediction_type in ["epsilon", "sample"]:
																																	self.check_over_configs(
																																	    thresholding=lowercase ,      prediction_type=lowercase ,      sample_max_value=lowercase ,      algorithm_type="""dpmsolver++""" ,      solver_order=lowercase ,      solver_type=lowercase ,      )






			def 				A      (   self							:						Optional[int]			)							->    Tuple:

									'''simple docstring'''







									for prediction_type in ["epsilon", "v_prediction"]:
															self.check_over_configs(prediction_type=lowercase			)






			def 				A      (   self							:						Optional[int]			)							->    int:

									'''simple docstring'''







									for algorithm_type in ["dpmsolver", "dpmsolver++"]:
															for solver_type in ["midpoint", "heun"]:
																					for order in [1, 2, 3]:
																											for prediction_type in ["epsilon", "sample"]:
																																	self.check_over_configs(
																																	    solver_order=lowercase ,      solver_type=lowercase ,      prediction_type=lowercase ,      algorithm_type=lowercase ,      )
																																	UpperCamelCase__         = self.full_loop(
																																	    solver_order=lowercase ,      solver_type=lowercase ,      prediction_type=lowercase ,      algorithm_type=lowercase ,      )
																																	assert not torch.isnan(lowercase			).any(), "Samples have nan numbers"






			def 				A      (   self							:						List[str]			)							->    Union[str, Any]:

									'''simple docstring'''







									self.check_over_configs(lower_order_final=lowercase			)
									self.check_over_configs(lower_order_final=lowercase			)






			def 				A      (   self							:						Tuple			)							->    Optional[int]:

									'''simple docstring'''







									self.check_over_configs(lambda_min_clipped=-float("""inf"""			)			)
									self.check_over_configs(lambda_min_clipped=-5.1			)






			def 				A      (   self							:						List[Any]			)							->    int:

									'''simple docstring'''







									self.check_over_configs(variance_type=lowercase			)
									self.check_over_configs(variance_type="""learned_range"""			)






			def 				A      (   self							:						Tuple			)							->    int:

									'''simple docstring'''







									for num_inference_steps in [1, 2, 3, 5, 1_0, 5_0, 1_0_0, 9_9_9, 1_0_0_0]:
															self.check_over_forward(num_inference_steps=lowercase ,      time_step=0			)






			def 				A      (   self							:						List[str]			)							->    Optional[int]:

									'''simple docstring'''







									UpperCamelCase__         = self.full_loop()
									UpperCamelCase__         = torch.mean(torch.abs(lowercase			)			)

									assert abs(result_mean.item() - 0.2_7_9_1			) < 1e-3






			def 				A      (   self							:						str			)							->    int:

									'''simple docstring'''







									UpperCamelCase__         = self.full_loop(use_karras_sigmas=lowercase			)
									UpperCamelCase__         = torch.mean(torch.abs(lowercase			)			)

									assert abs(result_mean.item() - 0.2_2_4_8			) < 1e-3






			def 				A      (   self							:						List[Any]			)							->    List[str]:

									'''simple docstring'''







									UpperCamelCase__         = self.full_loop(prediction_type="""v_prediction"""			)
									UpperCamelCase__         = torch.mean(torch.abs(lowercase			)			)

									assert abs(result_mean.item() - 0.1_4_5_3			) < 1e-3






			def 				A      (   self							:						int			)							->    int:

									'''simple docstring'''







									UpperCamelCase__         = self.full_loop(prediction_type="""v_prediction""" ,      use_karras_sigmas=lowercase			)
									UpperCamelCase__         = torch.mean(torch.abs(lowercase			)			)

									assert abs(result_mean.item() - 0.0_6_4_9			) < 1e-3







			def 				A      (   self							:						Optional[Any]			)							->    Union[str, Any]:

									'''simple docstring'''







									UpperCamelCase__         = self.scheduler_classes[0]
									UpperCamelCase__         = self.get_scheduler_config(thresholding=lowercase ,      dynamic_thresholding_ratio=0			)
									UpperCamelCase__         = scheduler_class(**lowercase			)

									UpperCamelCase__         = 1_0
									UpperCamelCase__         = self.dummy_model()
									UpperCamelCase__         = self.dummy_sample_deter.half()
									scheduler.set_timesteps(lowercase			)

									for i, t in enumerate(scheduler.timesteps			):
															UpperCamelCase__         = model(lowercase ,      lowercase			)
															UpperCamelCase__         = scheduler.step(lowercase ,      lowercase ,      lowercase			).prev_sample

									assert sample.dtype == torch.floataa
