






'''simple docstring'''





import torch

from diffusers import HeunDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest


class 				snake_case__     (			UpperCamelCase):
					a_       =			(HeunDiscreteScheduler,)
					a_       =			10




					def 						A     (       self       :						List[str]							,				**_A       :						str     )  ->    Dict:
								UpperCAmelCase_     :   Tuple       =   {
								    '''num_train_timesteps''': 11_00,
								    '''beta_start''': 0.0_001,
								    '''beta_end''': 0.02,
								    '''beta_schedule''': '''linear''',
								}

								config.update(**_A     )
								return config




					def 						A     (       self       :						Any     )  ->    List[Any]:
								for timesteps in [10, 50, 1_00, 10_00]:
											self.check_over_configs(num_train_timesteps=_A     )




					def 						A     (       self       :						Optional[Any]     )  ->    int:
								for beta_start, beta_end in zip([0.00_001, 0.0_001, 0.001]							,				[0.0_002, 0.002, 0.02]     ):
											self.check_over_configs(beta_start=_A							,				beta_end=_A     )




					def 						A     (       self       :						int     )  ->    List[Any]:
								for schedule in ["linear", "scaled_linear", "exp"]:
											self.check_over_configs(beta_schedule=_A     )




					def 						A     (       self       :						List[str]     )  ->    int:
								for clip_sample_range in [1.0, 2.0, 3.0]:
											self.check_over_configs(clip_sample_range=_A							,				clip_sample=_A     )




					def 						A     (       self       :						List[str]     )  ->    List[Any]:
								for prediction_type in ["epsilon", "v_prediction", "sample"]:
											self.check_over_configs(prediction_type=_A     )




					def 						A     (       self       :						Union[str, Any]     )  ->    str:
								UpperCAmelCase_     :   Dict       =   self.scheduler_classes[0]
								UpperCAmelCase_     :   Optional[Any]       =   self.get_scheduler_config()
								UpperCAmelCase_     :   Dict       =   scheduler_class(**_A     )

								scheduler.set_timesteps(self.num_inference_steps     )

								UpperCAmelCase_     :   Optional[int]       =   self.dummy_model()
								UpperCAmelCase_     :   Any       =   self.dummy_sample_deter * scheduler.init_noise_sigma
								UpperCAmelCase_     :   List[Any]       =   sample.to(_A     )

								for i, t in enumerate(scheduler.timesteps     ):
											UpperCAmelCase_     :   Tuple       =   scheduler.scale_model_input(_A							,				_A     )

											UpperCAmelCase_     :   List[str]       =   model(_A							,				_A     )

											UpperCAmelCase_     :   str       =   scheduler.step(_A							,				_A							,				_A     )
											UpperCAmelCase_     :   Optional[Any]       =   output.prev_sample

								UpperCAmelCase_     :   Dict       =   torch.sum(torch.abs(_A     )     )
								UpperCAmelCase_     :   Optional[Any]       =   torch.mean(torch.abs(_A     )     )

								if torch_device in ["cpu", "mps"]:
											assert abs(result_sum.item() - 0.1_233     ) < 1e-2
											assert abs(result_mean.item() - 0.0_002     ) < 1e-3
								else:
											# CUDA
											assert abs(result_sum.item() - 0.1_233     ) < 1e-2
											assert abs(result_mean.item() - 0.0_002     ) < 1e-3




					def 						A     (       self       :						Union[str, Any]     )  ->    List[Any]:
								UpperCAmelCase_     :   Dict       =   self.scheduler_classes[0]
								UpperCAmelCase_     :   str       =   self.get_scheduler_config(prediction_type='''v_prediction'''     )
								UpperCAmelCase_     :   Optional[Any]       =   scheduler_class(**_A     )

								scheduler.set_timesteps(self.num_inference_steps     )

								UpperCAmelCase_     :   List[str]       =   self.dummy_model()
								UpperCAmelCase_     :   List[str]       =   self.dummy_sample_deter * scheduler.init_noise_sigma
								UpperCAmelCase_     :   Optional[int]       =   sample.to(_A     )

								for i, t in enumerate(scheduler.timesteps     ):
											UpperCAmelCase_     :   Any       =   scheduler.scale_model_input(_A							,				_A     )

											UpperCAmelCase_     :   Any       =   model(_A							,				_A     )

											UpperCAmelCase_     :   List[str]       =   scheduler.step(_A							,				_A							,				_A     )
											UpperCAmelCase_     :   Union[str, Any]       =   output.prev_sample

								UpperCAmelCase_     :   Union[str, Any]       =   torch.sum(torch.abs(_A     )     )
								UpperCAmelCase_     :   Optional[Any]       =   torch.mean(torch.abs(_A     )     )

								if torch_device in ["cpu", "mps"]:
											assert abs(result_sum.item() - 4.6934e-07     ) < 1e-2
											assert abs(result_mean.item() - 6.1112e-10     ) < 1e-3
								else:
											# CUDA
											assert abs(result_sum.item() - 4.693_4286_5017_0972e-07     ) < 1e-2
											assert abs(result_mean.item() - 0.0_002     ) < 1e-3




					def 						A     (       self       :						Union[str, Any]     )  ->    str:
								UpperCAmelCase_     :   Any       =   self.scheduler_classes[0]
								UpperCAmelCase_     :   Optional[Any]       =   self.get_scheduler_config()
								UpperCAmelCase_     :   Tuple       =   scheduler_class(**_A     )

								scheduler.set_timesteps(self.num_inference_steps							,				device=_A     )

								UpperCAmelCase_     :   str       =   self.dummy_model()
								UpperCAmelCase_     :   Any       =   self.dummy_sample_deter.to(_A     ) * scheduler.init_noise_sigma

								for t in scheduler.timesteps:
											UpperCAmelCase_     :   Union[str, Any]       =   scheduler.scale_model_input(_A							,				_A     )

											UpperCAmelCase_     :   Union[str, Any]       =   model(_A							,				_A     )

											UpperCAmelCase_     :   int       =   scheduler.step(_A							,				_A							,				_A     )
											UpperCAmelCase_     :   int       =   output.prev_sample

								UpperCAmelCase_     :   str       =   torch.sum(torch.abs(_A     )     )
								UpperCAmelCase_     :   Optional[int]       =   torch.mean(torch.abs(_A     )     )

								if str(_A     ).startswith('''cpu'''     ):
											# The following sum varies between 148 and 156 on mps. Why?
											assert abs(result_sum.item() - 0.1_233     ) < 1e-2
											assert abs(result_mean.item() - 0.0_002     ) < 1e-3
								elif str(_A     ).startswith('''mps'''     ):
											# Larger tolerance on mps
											assert abs(result_mean.item() - 0.0_002     ) < 1e-2
								else:
											# CUDA
											assert abs(result_sum.item() - 0.1_233     ) < 1e-2
											assert abs(result_mean.item() - 0.0_002     ) < 1e-3





					def 						A     (       self       :						Optional[Any]     )  ->    Dict:
								UpperCAmelCase_     :   Any       =   self.scheduler_classes[0]
								UpperCAmelCase_     :   Union[str, Any]       =   self.get_scheduler_config()
								UpperCAmelCase_     :   Union[str, Any]       =   scheduler_class(**_A							,				use_karras_sigmas=_A     )

								scheduler.set_timesteps(self.num_inference_steps							,				device=_A     )

								UpperCAmelCase_     :   Dict       =   self.dummy_model()
								UpperCAmelCase_     :   Optional[int]       =   self.dummy_sample_deter.to(_A     ) * scheduler.init_noise_sigma
								UpperCAmelCase_     :   Any       =   sample.to(_A     )

								for t in scheduler.timesteps:
											UpperCAmelCase_     :   List[str]       =   scheduler.scale_model_input(_A							,				_A     )

											UpperCAmelCase_     :   List[Any]       =   model(_A							,				_A     )

											UpperCAmelCase_     :   List[str]       =   scheduler.step(_A							,				_A							,				_A     )
											UpperCAmelCase_     :   Any       =   output.prev_sample

								UpperCAmelCase_     :   Union[str, Any]       =   torch.sum(torch.abs(_A     )     )
								UpperCAmelCase_     :   Optional[int]       =   torch.mean(torch.abs(_A     )     )

								assert abs(result_sum.item() - 0.00_015     ) < 1e-2
								assert abs(result_mean.item() - 1.9869_5545_3503_4695e-07     ) < 1e-2










'''simple docstring'''





def __UpperCAmelCase (			)  -> Optional[Any]:
			UpperCAmelCase_     :   Union[str, Any]       =   1

			while True:
						if (
						    sorted(str(A						)						)
						    == sorted(str(2 * i						)						)
						    == sorted(str(3 * i						)						)
						    == sorted(str(4 * i						)						)
						    == sorted(str(5 * i						)						)
						    == sorted(str(6 * i						)						)
						):
									return i

						i += 1


if __name__ == "__main__":
						print(solution())


