






"""simple docstring"""



import unittest

from diffusers import __version__
from diffusers.utils import deprecate




class 							__lowercase(							unittest.TestCase	):
						lowerCAmelCase_		:				List[str]=							""".""".join([str(int(__version__.split("""."""	)[0]	) + 1	)] + __version__.split("""."""	)[1:]	)
						lowerCAmelCase_		:				List[str]=							"""0.0.1"""






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




											"""simple docstring"""





											lowerCamelCase__					={'deprecated_arg': 4}

											with self.assertWarns(_SCREAMING_SNAKE_CASE) as warning:
																lowerCamelCase__					=deprecate('deprecated_arg'     ,    self.higher_version     ,    'message'     ,    take_from=_SCREAMING_SNAKE_CASE)

											assert output == 4
											assert (
											    str(warning.warning)
											    == F"The `deprecated_arg` argument is deprecated and will be removed in version {self.higher_version}."
											    " message"
											)






						def 		lowerCAmelCase (       self)      ->	str:




											"""simple docstring"""





											lowerCamelCase__					={'deprecated_arg': 4}

											with self.assertWarns(_SCREAMING_SNAKE_CASE) as warning:
																lowerCamelCase__					=deprecate(('deprecated_arg', self.higher_version, 'message')     ,    take_from=_SCREAMING_SNAKE_CASE)

											assert output == 4
											assert (
											    str(warning.warning)
											    == F"The `deprecated_arg` argument is deprecated and will be removed in version {self.higher_version}."
											    " message"
											)






						def 		lowerCAmelCase (       self)      ->	Optional[Any]:




											"""simple docstring"""





											lowerCamelCase__					={'deprecated_arg_1': 4, 'deprecated_arg_2': 8}
											with self.assertWarns(_SCREAMING_SNAKE_CASE) as warning:
																lowerCamelCase__					,  lowerCamelCase__					=deprecate(
																    ('deprecated_arg_1', self.higher_version, 'Hey')     ,    ('deprecated_arg_2', self.higher_version, 'Hey')     ,    take_from=_SCREAMING_SNAKE_CASE     ,    )
											assert output_a == 4
											assert output_a == 8
											assert (
											    str(warning.warnings[0].message)
											    == "The `deprecated_arg_1` argument is deprecated and will be removed in version"
											    F" {self.higher_version}. Hey"
											)
											assert (
											    str(warning.warnings[1].message)
											    == "The `deprecated_arg_2` argument is deprecated and will be removed in version"
											    F" {self.higher_version}. Hey"
											)






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




											"""simple docstring"""





											lowerCamelCase__					={'deprecated_arg': 4}

											with self.assertRaises(_SCREAMING_SNAKE_CASE) as error:
																deprecate(('wrong_arg', self.higher_version, 'message')     ,    take_from=_SCREAMING_SNAKE_CASE)

											assert "test_deprecate_function_incorrect_arg in" in str(error.exception)
											assert "line" in str(error.exception)
											assert "got an unexpected keyword argument `deprecated_arg`" in str(error.exception)






						def 		lowerCAmelCase (       self)      ->	Tuple:




											"""simple docstring"""





											with self.assertWarns(_SCREAMING_SNAKE_CASE) as warning:
																deprecate(('deprecated_arg', self.higher_version, 'message'))

											assert (
											    str(warning.warning)
											    == F"`deprecated_arg` is deprecated and will be removed in version {self.higher_version}. message"
											)






						def 		lowerCAmelCase (       self)      ->	List[Any]:




											"""simple docstring"""





											with self.assertWarns(_SCREAMING_SNAKE_CASE) as warning:
																deprecate(
																    ('deprecated_arg_1', self.higher_version, 'Hey')     ,    ('deprecated_arg_2', self.higher_version, 'Hey')     ,    )
											assert (
											    str(warning.warnings[0].message)
											    == F"`deprecated_arg_1` is deprecated and will be removed in version {self.higher_version}. Hey"
											)
											assert (
											    str(warning.warnings[1].message)
											    == F"`deprecated_arg_2` is deprecated and will be removed in version {self.higher_version}. Hey"
											)






						def 		lowerCAmelCase (       self)      ->	Optional[Any]:




											"""simple docstring"""





											class 							__lowercase:
																	lowerCAmelCase_		:				Any=							5

											with self.assertWarns(_SCREAMING_SNAKE_CASE) as warning:
																lowerCamelCase__					=deprecate(('arg', self.higher_version, 'message')     ,    take_from=Args())

											assert arg == 5
											assert (
											    str(warning.warning)
											    == F"The `arg` attribute is deprecated and will be removed in version {self.higher_version}. message"
											)






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




											"""simple docstring"""





											class 							__lowercase:
																	lowerCAmelCase_		:				Any=							5
																	lowerCAmelCase_		:				Tuple=							7

											with self.assertWarns(_SCREAMING_SNAKE_CASE) as warning:
																lowerCamelCase__					,  lowerCamelCase__					=deprecate(
																    ('arg', self.higher_version, 'message')     ,    ('foo', self.higher_version, 'message')     ,    ('does not exist', self.higher_version, 'message')     ,    take_from=Args()     ,    )

											assert arg_a == 5
											assert arg_a == 7
											assert (
											    str(warning.warning)
											    == F"The `arg` attribute is deprecated and will be removed in version {self.higher_version}. message"
											)
											assert (
											    str(warning.warnings[0].message)
											    == F"The `arg` attribute is deprecated and will be removed in version {self.higher_version}. message"
											)
											assert (
											    str(warning.warnings[1].message)
											    == F"The `foo` attribute is deprecated and will be removed in version {self.higher_version}. message"
											)






						def 		lowerCAmelCase (       self)      ->	Optional[Any]:




											"""simple docstring"""





											lowerCamelCase__					={'deprecated_arg': 4}

											with self.assertRaises(_SCREAMING_SNAKE_CASE) as error:
																deprecate(('wrong_arg', self.lower_version, 'message')     ,    take_from=_SCREAMING_SNAKE_CASE)

											assert (
											    str(error.exception)
											    == "The deprecation tuple ('wrong_arg', '0.0.1', 'message') should be removed since diffusers' version"
											    F" {__version__} is >= {self.lower_version}"
											)






						def 		lowerCAmelCase (       self)      ->	int:




											"""simple docstring"""





											with self.assertWarns(_SCREAMING_SNAKE_CASE) as warning:
																deprecate(('deprecated_arg', self.higher_version, 'This message is better!!!')     ,    standard_warn=_SCREAMING_SNAKE_CASE)

											assert str(warning.warning) == "This message is better!!!"






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




											"""simple docstring"""





											with self.assertWarns(_SCREAMING_SNAKE_CASE) as warning:
																deprecate(('deprecated_arg', self.higher_version, 'This message is better!!!')     ,    standard_warn=_SCREAMING_SNAKE_CASE)
											assert str(warning.warning) == "This message is better!!!"
											assert "diffusers/tests/others/test_utils.py" in warning.filename







"""simple docstring"""



import torch

from diffusers import EulerAncestralDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest




class 							__lowercase(							_UpperCamelCase	):
						lowerCAmelCase_		:				Dict=							(EulerAncestralDiscreteScheduler,)
						lowerCAmelCase_		:				int=							10






						def 		lowerCAmelCase (       self     ,    **_SCREAMING_SNAKE_CASE)      ->	List[str]:




											"""simple docstring"""





											lowerCamelCase__					={
											    'num_train_timesteps': 11_00,
											    'beta_start': 0.0001,
											    'beta_end': 0.02,
											    'beta_schedule': 'linear',
											}

											config.update(**_SCREAMING_SNAKE_CASE)
											return config






						def 		lowerCAmelCase (       self)      ->	List[Any]:




											"""simple docstring"""





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






						def 		lowerCAmelCase (       self)      ->	Tuple:




											"""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=_SCREAMING_SNAKE_CASE     ,    beta_end=_SCREAMING_SNAKE_CASE)






						def 		lowerCAmelCase (       self)      ->	List[Any]:




											"""simple docstring"""





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






						def 		lowerCAmelCase (       self)      ->	Dict:




											"""simple docstring"""





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






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




											"""simple docstring"""





											lowerCamelCase__					=self.scheduler_classes[0]
											lowerCamelCase__					=self.get_scheduler_config()
											lowerCamelCase__					=scheduler_class(**_SCREAMING_SNAKE_CASE)

											scheduler.set_timesteps(self.num_inference_steps)

											lowerCamelCase__					=torch.manual_seed(0)

											lowerCamelCase__					=self.dummy_model()
											lowerCamelCase__					=self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
											lowerCamelCase__					=sample.to(_SCREAMING_SNAKE_CASE)

											for i, t in enumerate(scheduler.timesteps):
																lowerCamelCase__					=scheduler.scale_model_input(_SCREAMING_SNAKE_CASE     ,    _SCREAMING_SNAKE_CASE)

																lowerCamelCase__					=model(_SCREAMING_SNAKE_CASE     ,    _SCREAMING_SNAKE_CASE)

																lowerCamelCase__					=scheduler.step(_SCREAMING_SNAKE_CASE     ,    _SCREAMING_SNAKE_CASE     ,    _SCREAMING_SNAKE_CASE     ,    generator=_SCREAMING_SNAKE_CASE)
																lowerCamelCase__					=output.prev_sample

											lowerCamelCase__					=torch.sum(torch.abs(_SCREAMING_SNAKE_CASE))
											lowerCamelCase__					=torch.mean(torch.abs(_SCREAMING_SNAKE_CASE))

											assert abs(result_sum.item() - 152.3192) < 1E-2
											assert abs(result_mean.item() - 0.1983) < 1E-3






						def 		lowerCAmelCase (       self)      ->	str:




											"""simple docstring"""





											lowerCamelCase__					=self.scheduler_classes[0]
											lowerCamelCase__					=self.get_scheduler_config(prediction_type='v_prediction')
											lowerCamelCase__					=scheduler_class(**_SCREAMING_SNAKE_CASE)

											scheduler.set_timesteps(self.num_inference_steps)

											lowerCamelCase__					=torch.manual_seed(0)

											lowerCamelCase__					=self.dummy_model()
											lowerCamelCase__					=self.dummy_sample_deter * scheduler.init_noise_sigma
											lowerCamelCase__					=sample.to(_SCREAMING_SNAKE_CASE)

											for i, t in enumerate(scheduler.timesteps):
																lowerCamelCase__					=scheduler.scale_model_input(_SCREAMING_SNAKE_CASE     ,    _SCREAMING_SNAKE_CASE)

																lowerCamelCase__					=model(_SCREAMING_SNAKE_CASE     ,    _SCREAMING_SNAKE_CASE)

																lowerCamelCase__					=scheduler.step(_SCREAMING_SNAKE_CASE     ,    _SCREAMING_SNAKE_CASE     ,    _SCREAMING_SNAKE_CASE     ,    generator=_SCREAMING_SNAKE_CASE)
																lowerCamelCase__					=output.prev_sample

											lowerCamelCase__					=torch.sum(torch.abs(_SCREAMING_SNAKE_CASE))
											lowerCamelCase__					=torch.mean(torch.abs(_SCREAMING_SNAKE_CASE))

											assert abs(result_sum.item() - 108.4439) < 1E-2
											assert abs(result_mean.item() - 0.1412) < 1E-3






						def 		lowerCAmelCase (       self)      ->	Any:




											"""simple docstring"""





											lowerCamelCase__					=self.scheduler_classes[0]
											lowerCamelCase__					=self.get_scheduler_config()
											lowerCamelCase__					=scheduler_class(**_SCREAMING_SNAKE_CASE)

											scheduler.set_timesteps(self.num_inference_steps     ,    device=_SCREAMING_SNAKE_CASE)
											lowerCamelCase__					=torch.manual_seed(0)

											lowerCamelCase__					=self.dummy_model()
											lowerCamelCase__					=self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
											lowerCamelCase__					=sample.to(_SCREAMING_SNAKE_CASE)

											for t in scheduler.timesteps:
																lowerCamelCase__					=scheduler.scale_model_input(_SCREAMING_SNAKE_CASE     ,    _SCREAMING_SNAKE_CASE)

																lowerCamelCase__					=model(_SCREAMING_SNAKE_CASE     ,    _SCREAMING_SNAKE_CASE)

																lowerCamelCase__					=scheduler.step(_SCREAMING_SNAKE_CASE     ,    _SCREAMING_SNAKE_CASE     ,    _SCREAMING_SNAKE_CASE     ,    generator=_SCREAMING_SNAKE_CASE)
																lowerCamelCase__					=output.prev_sample

											lowerCamelCase__					=torch.sum(torch.abs(_SCREAMING_SNAKE_CASE))
											lowerCamelCase__					=torch.mean(torch.abs(_SCREAMING_SNAKE_CASE))

											assert abs(result_sum.item() - 152.3192) < 1E-2
											assert abs(result_mean.item() - 0.1983) < 1E-3