

"""simple docstring"""


import torch

from diffusers import HeunDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest





class 					snake_case			(       __snake_case						):
				SCREAMING_SNAKE_CASE_     :   int        =						(HeunDiscreteScheduler,)
				SCREAMING_SNAKE_CASE_     :   Dict        =						10

				def 							lowercase_  (			self							:       int  ,						**UpperCamelCase__							:       List[Any])->     Tuple:



						'''simple docstring'''


						__lowerCAmelCase: Optional[int]					   =    {
						    "num_train_timesteps": 1_1_0_0,
						    "beta_start": 0.0001,
						    "beta_end": 0.02,
						    "beta_schedule": "linear",
						}

						config.update(**UpperCamelCase__)
						return config

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



						'''simple docstring'''


						for timesteps in [1_0, 5_0, 1_0_0, 1_0_0_0]:
								self.check_over_configs(num_train_timesteps=UpperCamelCase__)

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



						'''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 							lowercase_  (			self							:       Optional[int])->     int:



						'''simple docstring'''


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

				def 							lowercase_  (			self							:       Optional[Any])->     Union[str, 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 							lowercase_  (			self							:       int)->     Any:



						'''simple docstring'''


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

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



						'''simple docstring'''


						__lowerCAmelCase: Tuple					   =    self.scheduler_classes[0]
						__lowerCAmelCase: List[Any]					   =    self.get_scheduler_config()
						__lowerCAmelCase: List[Any]					   =    scheduler_class(**UpperCamelCase__)

						scheduler.set_timesteps(self.num_inference_steps)

						__lowerCAmelCase: Any					   =    self.dummy_model()
						__lowerCAmelCase: Any					   =    self.dummy_sample_deter * scheduler.init_noise_sigma
						__lowerCAmelCase: List[Any]					   =    sample.to(UpperCamelCase__)

						for i, t in enumerate(scheduler.timesteps):
								__lowerCAmelCase: Any					   =    scheduler.scale_model_input(UpperCamelCase__  ,						UpperCamelCase__)

								__lowerCAmelCase: Dict					   =    model(UpperCamelCase__  ,						UpperCamelCase__)

								__lowerCAmelCase: Dict					   =    scheduler.step(UpperCamelCase__  ,						UpperCamelCase__  ,						UpperCamelCase__)
								__lowerCAmelCase: List[Any]					   =    output.prev_sample

						__lowerCAmelCase: Optional[int]					   =    torch.sum(torch.abs(UpperCamelCase__))
						__lowerCAmelCase: str					   =    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 							lowercase_  (			self							:       List[Any])->     int:



						'''simple docstring'''


						__lowerCAmelCase: Dict					   =    self.scheduler_classes[0]
						__lowerCAmelCase: Any					   =    self.get_scheduler_config(prediction_type="v_prediction")
						__lowerCAmelCase: int					   =    scheduler_class(**UpperCamelCase__)

						scheduler.set_timesteps(self.num_inference_steps)

						__lowerCAmelCase: Dict					   =    self.dummy_model()
						__lowerCAmelCase: List[str]					   =    self.dummy_sample_deter * scheduler.init_noise_sigma
						__lowerCAmelCase: Optional[Any]					   =    sample.to(UpperCamelCase__)

						for i, t in enumerate(scheduler.timesteps):
								__lowerCAmelCase: List[Any]					   =    scheduler.scale_model_input(UpperCamelCase__  ,						UpperCamelCase__)

								__lowerCAmelCase: Optional[int]					   =    model(UpperCamelCase__  ,						UpperCamelCase__)

								__lowerCAmelCase: Optional[Any]					   =    scheduler.step(UpperCamelCase__  ,						UpperCamelCase__  ,						UpperCamelCase__)
								__lowerCAmelCase: List[str]					   =    output.prev_sample

						__lowerCAmelCase: Tuple					   =    torch.sum(torch.abs(UpperCamelCase__))
						__lowerCAmelCase: int					   =    torch.mean(torch.abs(UpperCamelCase__))

						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.0002) < 1e-3

				def 							lowercase_  (			self							:       Dict)->     List[Any]:



						'''simple docstring'''


						__lowerCAmelCase: Any					   =    self.scheduler_classes[0]
						__lowerCAmelCase: Any					   =    self.get_scheduler_config()
						__lowerCAmelCase: List[Any]					   =    scheduler_class(**UpperCamelCase__)

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

						__lowerCAmelCase: Optional[Any]					   =    self.dummy_model()
						__lowerCAmelCase: Dict					   =    self.dummy_sample_deter.to(UpperCamelCase__) * scheduler.init_noise_sigma

						for t in scheduler.timesteps:
								__lowerCAmelCase: str					   =    scheduler.scale_model_input(UpperCamelCase__  ,						UpperCamelCase__)

								__lowerCAmelCase: Union[str, Any]					   =    model(UpperCamelCase__  ,						UpperCamelCase__)

								__lowerCAmelCase: List[Any]					   =    scheduler.step(UpperCamelCase__  ,						UpperCamelCase__  ,						UpperCamelCase__)
								__lowerCAmelCase: List[Any]					   =    output.prev_sample

						__lowerCAmelCase: Any					   =    torch.sum(torch.abs(UpperCamelCase__))
						__lowerCAmelCase: List[str]					   =    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 							lowercase_  (			self							:       Dict)->     str:



						'''simple docstring'''


						__lowerCAmelCase: Union[str, Any]					   =    self.scheduler_classes[0]
						__lowerCAmelCase: Dict					   =    self.get_scheduler_config()
						__lowerCAmelCase: List[Any]					   =    scheduler_class(**UpperCamelCase__  ,						use_karras_sigmas=UpperCamelCase__)

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

						__lowerCAmelCase: Any					   =    self.dummy_model()
						__lowerCAmelCase: Any					   =    self.dummy_sample_deter.to(UpperCamelCase__) * scheduler.init_noise_sigma
						__lowerCAmelCase: Union[str, Any]					   =    sample.to(UpperCamelCase__)

						for t in scheduler.timesteps:
								__lowerCAmelCase: Optional[Any]					   =    scheduler.scale_model_input(UpperCamelCase__  ,						UpperCamelCase__)

								__lowerCAmelCase: Optional[Any]					   =    model(UpperCamelCase__  ,						UpperCamelCase__)

								__lowerCAmelCase: Optional[Any]					   =    scheduler.step(UpperCamelCase__  ,						UpperCamelCase__  ,						UpperCamelCase__)
								__lowerCAmelCase: Optional[int]					   =    output.prev_sample

						__lowerCAmelCase: int					   =    torch.sum(torch.abs(UpperCamelCase__))
						__lowerCAmelCase: Union[str, Any]					   =    torch.mean(torch.abs(UpperCamelCase__))

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





"""simple docstring"""


def 					a__					(					__SCREAMING_SNAKE_CASE = 1_0_0_0				)			->			int:
		__lowerCAmelCase: int					   =    0
		__lowerCAmelCase: Optional[int]					   =    0
		while 1:
				num += 3
				if num >= n:
						break
				total += num
				num += 2
				if num >= n:
						break
				total += num
				num += 1
				if num >= n:
						break
				total += num
				num += 3
				if num >= n:
						break
				total += num
				num += 1
				if num >= n:
						break
				total += num
				num += 2
				if num >= n:
						break
				total += num
				num += 3
				if num >= n:
						break
				total += num
		return total


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


