

'''simple docstring'''







import torch

from diffusers import EulerDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest


class 					A__      (      _snake_case			):
    lowercase						=		(EulerDiscreteScheduler,)
    lowercase						=		10



    def 					snake_case_			(					self		,				**UpperCamelCase__       )						->      List[Any]:





           '''simple docstring'''
           A_						=      {
               """num_train_timesteps""": 1100,
               """beta_start""": 0.0001,
               """beta_end""": 0.02,
               """beta_schedule""": """linear""",
           }

           config.update(**UpperCamelCase__       )
           return config



    def 					snake_case_			(					self       )						->      str:





           '''simple docstring'''
           for timesteps in [10, 50, 100, 1000]:
                  self.check_over_configs(num_train_timesteps=UpperCamelCase__       )



    def 					snake_case_			(					self       )						->      List[str]:





           '''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 					snake_case_			(					self       )						->      int:





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



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





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



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





           '''simple docstring'''
           A_						=      self.scheduler_classes[0]
           A_						=      self.get_scheduler_config()
           A_						=      scheduler_class(**UpperCamelCase__       )

           scheduler.set_timesteps(self.num_inference_steps       )

           A_						=      torch.manual_seed(0       )

           A_						=      self.dummy_model()
           A_						=      self.dummy_sample_deter * scheduler.init_noise_sigma
           A_						=      sample.to(UpperCamelCase__       )

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

                  A_						=      model(UpperCamelCase__		,				UpperCamelCase__       )

                  A_						=      scheduler.step(UpperCamelCase__		,				UpperCamelCase__		,				UpperCamelCase__		,				generator=UpperCamelCase__       )
                  A_						=      output.prev_sample

           A_						=      torch.sum(torch.abs(UpperCamelCase__       )       )
           A_						=      torch.mean(torch.abs(UpperCamelCase__       )       )

           assert abs(result_sum.item() - 10.0807       ) < 1e-2
           assert abs(result_mean.item() - 0.0131       ) < 1e-3



    def 					snake_case_			(					self       )						->      List[str]:





           '''simple docstring'''
           A_						=      self.scheduler_classes[0]
           A_						=      self.get_scheduler_config(prediction_type="""v_prediction"""       )
           A_						=      scheduler_class(**UpperCamelCase__       )

           scheduler.set_timesteps(self.num_inference_steps       )

           A_						=      torch.manual_seed(0       )

           A_						=      self.dummy_model()
           A_						=      self.dummy_sample_deter * scheduler.init_noise_sigma
           A_						=      sample.to(UpperCamelCase__       )

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

                  A_						=      model(UpperCamelCase__		,				UpperCamelCase__       )

                  A_						=      scheduler.step(UpperCamelCase__		,				UpperCamelCase__		,				UpperCamelCase__		,				generator=UpperCamelCase__       )
                  A_						=      output.prev_sample

           A_						=      torch.sum(torch.abs(UpperCamelCase__       )       )
           A_						=      torch.mean(torch.abs(UpperCamelCase__       )       )

           assert abs(result_sum.item() - 0.0002       ) < 1e-2
           assert abs(result_mean.item() - 2.2_6_7_6e-0_6       ) < 1e-3



    def 					snake_case_			(					self       )						->      int:





           '''simple docstring'''
           A_						=      self.scheduler_classes[0]
           A_						=      self.get_scheduler_config()
           A_						=      scheduler_class(**UpperCamelCase__       )

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

           A_						=      torch.manual_seed(0       )

           A_						=      self.dummy_model()
           A_						=      self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
           A_						=      sample.to(UpperCamelCase__       )

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

                  A_						=      model(UpperCamelCase__		,				UpperCamelCase__       )

                  A_						=      scheduler.step(UpperCamelCase__		,				UpperCamelCase__		,				UpperCamelCase__		,				generator=UpperCamelCase__       )
                  A_						=      output.prev_sample

           A_						=      torch.sum(torch.abs(UpperCamelCase__       )       )
           A_						=      torch.mean(torch.abs(UpperCamelCase__       )       )

           assert abs(result_sum.item() - 10.0807       ) < 1e-2
           assert abs(result_mean.item() - 0.0131       ) < 1e-3







    def 					snake_case_			(					self       )						->      Any:





           '''simple docstring'''
           A_						=      self.scheduler_classes[0]
           A_						=      self.get_scheduler_config()
           A_						=      scheduler_class(**UpperCamelCase__		,				use_karras_sigmas=UpperCamelCase__       )

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

           A_						=      torch.manual_seed(0       )

           A_						=      self.dummy_model()
           A_						=      self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
           A_						=      sample.to(UpperCamelCase__       )

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

                  A_						=      model(UpperCamelCase__		,				UpperCamelCase__       )

                  A_						=      scheduler.step(UpperCamelCase__		,				UpperCamelCase__		,				UpperCamelCase__		,				generator=UpperCamelCase__       )
                  A_						=      output.prev_sample

           A_						=      torch.sum(torch.abs(UpperCamelCase__       )       )
           A_						=      torch.mean(torch.abs(UpperCamelCase__       )       )

           assert abs(result_sum.item() - 124.52299499511719       ) < 1e-2
           assert abs(result_mean.item() - 0.16213932633399963       ) < 1e-3



'''simple docstring'''







def       UpperCAmelCase__    (      UpperCAmelCase__				)			->			bool:
       if num < 0:
              return False

       A_						=      num
       A_						=      0
       while num > 0:
              A_						=      rev_num * 10 + (num % 10)
              num //= 10

       return num_copy == rev_num


if __name__ == "__main__":
      import doctest

      doctest.testmod()
