




"""simple docstring"""

import torch

from diffusers import HeunDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest

class 							lowercase   (     SCREAMING_SNAKE_CASE__):
				__lowerCAmelCase     :     Any								= (HeunDiscreteScheduler,)
				__lowerCAmelCase     :     Optional[int]								= 10







				def        a_	(				self :       Dict   ,  **_lowerCamelCase :       int							):



					"""simple docstring"""

					A_	:					List[Any]						 =		{
					    "num_train_timesteps": 11_00,
					    "beta_start": 0.0001,
					    "beta_end": 0.02,
					    "beta_schedule": "linear",
					}

					config.update(**_UpperCAmelCase							)
					return config







				def        a_	(				self :       Tuple							):



					"""simple docstring"""

					for timesteps in [10, 50, 1_00, 10_00]:
						self.check_over_configs(num_train_timesteps=_UpperCAmelCase							)







				def        a_	(				self :       Optional[Any]							):



					"""simple docstring"""

					for beta_start, beta_end in zip([0.00001, 0.0001, 0.001]   ,  [0.0002, 0.002, 0.02]							):
						self.check_over_configs(beta_start=_UpperCAmelCase   ,  beta_end=_UpperCAmelCase							)







				def        a_	(				self :       int							):



					"""simple docstring"""

					for schedule in ["linear", "scaled_linear", "exp"]:
						self.check_over_configs(beta_schedule=_UpperCAmelCase							)







				def        a_	(				self :       Any							):



					"""simple docstring"""

					for clip_sample_range in [1.0, 2.0, 3.0]:
						self.check_over_configs(clip_sample_range=_UpperCAmelCase   ,  clip_sample=_UpperCAmelCase							)







				def        a_	(				self :       Union[str, Any]							):



					"""simple docstring"""

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







				def        a_	(				self :       List[str]							):



					"""simple docstring"""

					A_	:					Any						 =		self.scheduler_classes[0]
					A_	:					List[Any]						 =		self.get_scheduler_config()
					A_	:					Optional[int]						 =		scheduler_class(**_UpperCAmelCase							)

					scheduler.set_timesteps(self.num_inference_steps							)

					A_	:					Optional[int]						 =		self.dummy_model()
					A_	:					Union[str, Any]						 =		self.dummy_sample_deter * scheduler.init_noise_sigma
					A_	:					List[Any]						 =		sample.to(_UpperCAmelCase							)

					for i, t in enumerate(scheduler.timesteps							):
						A_	:					Dict						 =		scheduler.scale_model_input(_UpperCAmelCase   ,  _UpperCAmelCase							)

						A_	:					Union[str, Any]						 =		model(_UpperCAmelCase   ,  _UpperCAmelCase							)

						A_	:					Any						 =		scheduler.step(_UpperCAmelCase   ,  _UpperCAmelCase   ,  _UpperCAmelCase							)
						A_	:					Optional[int]						 =		output.prev_sample

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

					if torch_device in ["cpu", "mps"]:
						assert abs(result_sum.item() - 0.1233							) < 1E-2
						assert abs(result_mean.item() - 0.0002							) < 1E-3
					else:
						# CUDA
						assert abs(result_sum.item() - 0.1233							) < 1E-2
						assert abs(result_mean.item() - 0.0002							) < 1E-3







				def        a_	(				self :       Dict							):



					"""simple docstring"""

					A_	:					Union[str, Any]						 =		self.scheduler_classes[0]
					A_	:					int						 =		self.get_scheduler_config(prediction_type='''v_prediction'''							)
					A_	:					Tuple						 =		scheduler_class(**_UpperCAmelCase							)

					scheduler.set_timesteps(self.num_inference_steps							)

					A_	:					Any						 =		self.dummy_model()
					A_	:					str						 =		self.dummy_sample_deter * scheduler.init_noise_sigma
					A_	:					List[Any]						 =		sample.to(_UpperCAmelCase							)

					for i, t in enumerate(scheduler.timesteps							):
						A_	:					Optional[Any]						 =		scheduler.scale_model_input(_UpperCAmelCase   ,  _UpperCAmelCase							)

						A_	:					str						 =		model(_UpperCAmelCase   ,  _UpperCAmelCase							)

						A_	:					List[Any]						 =		scheduler.step(_UpperCAmelCase   ,  _UpperCAmelCase   ,  _UpperCAmelCase							)
						A_	:					List[Any]						 =		output.prev_sample

					A_	:					Any						 =		torch.sum(torch.abs(_UpperCAmelCase							)							)
					A_	:					Any						 =		torch.mean(torch.abs(_UpperCAmelCase							)							)

					if torch_device in ["cpu", "mps"]:
						assert abs(result_sum.item() - 4.69_34E-07							) < 1E-2
						assert abs(result_mean.item() - 6.11_12E-10							) < 1E-3
					else:
						# CUDA
						assert abs(result_sum.item() - 4.6_93_42_86_50_17_09_72E-07							) < 1E-2
						assert abs(result_mean.item() - 0.0002							) < 1E-3







				def        a_	(				self :       int							):



					"""simple docstring"""

					A_	:					Union[str, Any]						 =		self.scheduler_classes[0]
					A_	:					Optional[int]						 =		self.get_scheduler_config()
					A_	:					Dict						 =		scheduler_class(**_UpperCAmelCase							)

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

					A_	:					int						 =		self.dummy_model()
					A_	:					Optional[Any]						 =		self.dummy_sample_deter.to(_UpperCAmelCase							) * scheduler.init_noise_sigma

					for t in scheduler.timesteps:
						A_	:					Optional[int]						 =		scheduler.scale_model_input(_UpperCAmelCase   ,  _UpperCAmelCase							)

						A_	:					Optional[Any]						 =		model(_UpperCAmelCase   ,  _UpperCAmelCase							)

						A_	:					str						 =		scheduler.step(_UpperCAmelCase   ,  _UpperCAmelCase   ,  _UpperCAmelCase							)
						A_	:					List[str]						 =		output.prev_sample

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

					if str(_UpperCAmelCase							).startswith('''cpu'''							):
						# The following sum varies between 148 and 156 on mps. Why?
						assert abs(result_sum.item() - 0.1233							) < 1E-2
						assert abs(result_mean.item() - 0.0002							) < 1E-3
					elif str(_UpperCAmelCase							).startswith('''mps'''							):
						# Larger tolerance on mps
						assert abs(result_mean.item() - 0.0002							) < 1E-2
					else:
						# CUDA
						assert abs(result_sum.item() - 0.1233							) < 1E-2
						assert abs(result_mean.item() - 0.0002							) < 1E-3







				def        a_	(				self :       List[Any]							):



					"""simple docstring"""

					A_	:					Tuple						 =		self.scheduler_classes[0]
					A_	:					Any						 =		self.get_scheduler_config()
					A_	:					Optional[int]						 =		scheduler_class(**_UpperCAmelCase   ,  use_karras_sigmas=_UpperCAmelCase							)

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

					A_	:					Optional[Any]						 =		self.dummy_model()
					A_	:					Tuple						 =		self.dummy_sample_deter.to(_UpperCAmelCase							) * scheduler.init_noise_sigma
					A_	:					Optional[Any]						 =		sample.to(_UpperCAmelCase							)

					for t in scheduler.timesteps:
						A_	:					Dict						 =		scheduler.scale_model_input(_UpperCAmelCase   ,  _UpperCAmelCase							)

						A_	:					Dict						 =		model(_UpperCAmelCase   ,  _UpperCAmelCase							)

						A_	:					str						 =		scheduler.step(_UpperCAmelCase   ,  _UpperCAmelCase   ,  _UpperCAmelCase							)
						A_	:					int						 =		output.prev_sample

					A_	:					Optional[Any]						 =		torch.sum(torch.abs(_UpperCAmelCase							)							)
					A_	:					Any						 =		torch.mean(torch.abs(_UpperCAmelCase							)							)

					assert abs(result_sum.item() - 0.00015							) < 1E-2
					assert abs(result_mean.item() - 1.98_69_55_45_35_03_46_95E-07							) < 1E-2











'''simple docstring'''






import itertools

def      __lowerCAmelCase   (       snake_case__		):
			return (
			    int("".join(combination[0:2]		)		) * int("".join(combination[2:5]		)		)
			    == int("".join(combination[5:9]		)		)
			) or (
			    int("".join(combination[0]		)		) * int("".join(combination[1:5]		)		)
			    == int("".join(combination[5:9]		)		)
			)

def      __lowerCAmelCase   (       ):
			return sum(
			    {
			        int("".join(pandigital[5:9]		)		)
			        for pandigital in itertools.permutations("123456789"		)
			        if is_combination_valid(snake_case__		)
			    }		)


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



