




import torch

from diffusers import HeunDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest
class      _UpperCamelCase (			SCREAMING_SNAKE_CASE__						):
						UpperCAmelCase_            =						(HeunDiscreteScheduler,)
						UpperCAmelCase_            =						10
						def 		UpperCAmelCase_  (     self				:str	, **lowerCamelCase				:List[Any] )       ->     Tuple:
							UpperCAmelCase__								=  {
							    "num_train_timesteps": 1100,
							    "beta_start": 0.00_01,
							    "beta_end": 0.02,
							    "beta_schedule": "linear",
							}

							config.update(**lowerCamelCase )
							return config
						def 		UpperCAmelCase_  (     self				:Tuple )       ->     Tuple:

							for timesteps in [10, 50, 100, 1000]:
								self.check_over_configs(num_train_timesteps=lowerCamelCase )
						def 		UpperCAmelCase_  (     self				:Optional[Any] )       ->     Dict:

							for beta_start, beta_end in zip([0.0_00_01, 0.00_01, 0.0_01]	, [0.00_02, 0.0_02, 0.02] ):
								self.check_over_configs(beta_start=lowerCamelCase	, beta_end=lowerCamelCase )
						def 		UpperCAmelCase_  (     self				:List[Any] )       ->     int:

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

							for clip_sample_range in [1.0, 2.0, 3.0]:
								self.check_over_configs(clip_sample_range=lowerCamelCase	, clip_sample=lowerCamelCase )
						def 		UpperCAmelCase_  (     self				:Optional[Any] )       ->     str:

							for prediction_type in ["epsilon", "v_prediction", "sample"]:
								self.check_over_configs(prediction_type=lowerCamelCase )
						def 		UpperCAmelCase_  (     self				:Any )       ->     int:
							UpperCAmelCase__								=  self.scheduler_classes[0]
							UpperCAmelCase__								=  self.get_scheduler_config()
							UpperCAmelCase__								=  scheduler_class(**lowerCamelCase )

							scheduler.set_timesteps(self.num_inference_steps )

							UpperCAmelCase__								=  self.dummy_model()
							UpperCAmelCase__								=  self.dummy_sample_deter * scheduler.init_noise_sigma
							UpperCAmelCase__								=  sample.to(lowerCamelCase )

							for i, t in enumerate(scheduler.timesteps ):
								UpperCAmelCase__								=  scheduler.scale_model_input(lowerCamelCase	, lowerCamelCase )

								UpperCAmelCase__								=  model(lowerCamelCase	, lowerCamelCase )

								UpperCAmelCase__								=  scheduler.step(lowerCamelCase	, lowerCamelCase	, lowerCamelCase )
								UpperCAmelCase__								=  output.prev_sample

							UpperCAmelCase__								=  torch.sum(torch.abs(lowerCamelCase ) )
							UpperCAmelCase__								=  torch.mean(torch.abs(lowerCamelCase ) )

							if torch_device in ["cpu", "mps"]:
								assert abs(result_sum.item() - 0.12_33 ) < 1e-2
								assert abs(result_mean.item() - 0.00_02 ) < 1e-3
							else:
								# CUDA
								assert abs(result_sum.item() - 0.12_33 ) < 1e-2
								assert abs(result_mean.item() - 0.00_02 ) < 1e-3
						def 		UpperCAmelCase_  (     self				:List[str] )       ->     Tuple:
							UpperCAmelCase__								=  self.scheduler_classes[0]
							UpperCAmelCase__								=  self.get_scheduler_config(prediction_type="v_prediction" )
							UpperCAmelCase__								=  scheduler_class(**lowerCamelCase )

							scheduler.set_timesteps(self.num_inference_steps )

							UpperCAmelCase__								=  self.dummy_model()
							UpperCAmelCase__								=  self.dummy_sample_deter * scheduler.init_noise_sigma
							UpperCAmelCase__								=  sample.to(lowerCamelCase )

							for i, t in enumerate(scheduler.timesteps ):
								UpperCAmelCase__								=  scheduler.scale_model_input(lowerCamelCase	, lowerCamelCase )

								UpperCAmelCase__								=  model(lowerCamelCase	, lowerCamelCase )

								UpperCAmelCase__								=  scheduler.step(lowerCamelCase	, lowerCamelCase	, lowerCamelCase )
								UpperCAmelCase__								=  output.prev_sample

							UpperCAmelCase__								=  torch.sum(torch.abs(lowerCamelCase ) )
							UpperCAmelCase__								=  torch.mean(torch.abs(lowerCamelCase ) )

							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.693428650170972e-07 ) < 1e-2
								assert abs(result_mean.item() - 0.00_02 ) < 1e-3
						def 		UpperCAmelCase_  (     self				:Optional[int] )       ->     List[str]:
							UpperCAmelCase__								=  self.scheduler_classes[0]
							UpperCAmelCase__								=  self.get_scheduler_config()
							UpperCAmelCase__								=  scheduler_class(**lowerCamelCase )

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

							UpperCAmelCase__								=  self.dummy_model()
							UpperCAmelCase__								=  self.dummy_sample_deter.to(lowerCamelCase ) * scheduler.init_noise_sigma

							for t in scheduler.timesteps:
								UpperCAmelCase__								=  scheduler.scale_model_input(lowerCamelCase	, lowerCamelCase )

								UpperCAmelCase__								=  model(lowerCamelCase	, lowerCamelCase )

								UpperCAmelCase__								=  scheduler.step(lowerCamelCase	, lowerCamelCase	, lowerCamelCase )
								UpperCAmelCase__								=  output.prev_sample

							UpperCAmelCase__								=  torch.sum(torch.abs(lowerCamelCase ) )
							UpperCAmelCase__								=  torch.mean(torch.abs(lowerCamelCase ) )

							if str(lowerCamelCase ).startswith("cpu" ):
								# The following sum varies between 148 and 156 on mps. Why?
								assert abs(result_sum.item() - 0.12_33 ) < 1e-2
								assert abs(result_mean.item() - 0.00_02 ) < 1e-3
							elif str(lowerCamelCase ).startswith("mps" ):
								# Larger tolerance on mps
								assert abs(result_mean.item() - 0.00_02 ) < 1e-2
							else:
								# CUDA
								assert abs(result_sum.item() - 0.12_33 ) < 1e-2
								assert abs(result_mean.item() - 0.00_02 ) < 1e-3







						def 		UpperCAmelCase_  (     self				:Optional[Any] )       ->     str:
							UpperCAmelCase__								=  self.scheduler_classes[0]
							UpperCAmelCase__								=  self.get_scheduler_config()
							UpperCAmelCase__								=  scheduler_class(**lowerCamelCase	, use_karras_sigmas=lowerCamelCase )

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

							UpperCAmelCase__								=  self.dummy_model()
							UpperCAmelCase__								=  self.dummy_sample_deter.to(lowerCamelCase ) * scheduler.init_noise_sigma
							UpperCAmelCase__								=  sample.to(lowerCamelCase )

							for t in scheduler.timesteps:
								UpperCAmelCase__								=  scheduler.scale_model_input(lowerCamelCase	, lowerCamelCase )

								UpperCAmelCase__								=  model(lowerCamelCase	, lowerCamelCase )

								UpperCAmelCase__								=  scheduler.step(lowerCamelCase	, lowerCamelCase	, lowerCamelCase )
								UpperCAmelCase__								=  output.prev_sample

							UpperCAmelCase__								=  torch.sum(torch.abs(lowerCamelCase ) )
							UpperCAmelCase__								=  torch.mean(torch.abs(lowerCamelCase ) )

							assert abs(result_sum.item() - 0.0_00_15 ) < 1e-2
							assert abs(result_mean.item() - 1.9869554535034695e-07 ) < 1e-2











def   lowerCAmelCase						(						_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int		):




 """simple docstring"""







 if a < b:
  return gcd(_lowerCAmelCase  ,							_lowerCAmelCase		)
 if a % b == 0:
  return b
 return gcd(_lowerCAmelCase  ,							a % b		)



def   lowerCAmelCase						(						_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int		):




 """simple docstring"""







 if y == 0:
  return 1
 UpperCAmelCase__								=  power(_lowerCAmelCase  ,							y // 2  ,							_lowerCAmelCase		) % mod
 UpperCAmelCase__								=  (temp * temp) % mod
 if y % 2 == 1:
  UpperCAmelCase__								=  (temp * x) % mod
 return temp



def   lowerCAmelCase						(						_lowerCAmelCase							:				int		):




 """simple docstring"""







 UpperCAmelCase__								=  2
 while b < n:
  if gcd(_lowerCAmelCase  ,							_lowerCAmelCase		) == 1 and power(_lowerCAmelCase  ,							n - 1  ,							_lowerCAmelCase		) != 1:
   return False
  b += 1
 return True


if __name__ == "__main__":
  _lowerCAmelCase  :				Dict						=				int(input("Enter number: ").strip())
  if is_carmichael_number(number):
    print(F'''{number} is a Carmichael Number.''')
  else:
    print(F'''{number} is not a Carmichael Number.''')





