





'''simple docstring'''




import inspect
import unittest

from huggingface_hub import hf_hub_download

from transformers import ConvNextConfig, UperNetConfig
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import UperNetForSemanticSegmentation
							from transformers.models.upernet.modeling_upernet import UPERNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
							from PIL import Image

							from transformers import AutoImageProcessor




class      UpperCamelCase__					:




					"""simple docstring"""


					def __init__(						self				:			Union[str, Any]      ,						lowerCamelCase_				:			str      ,						lowerCamelCase_				:			Dict=13      ,						lowerCamelCase_				:			Optional[Any]=32      ,						lowerCamelCase_				:			Union[str, Any]=3      ,						lowerCamelCase_				:			Tuple=4      ,						lowerCamelCase_				:			List[str]=[10, 20, 30, 40]      ,						lowerCamelCase_				:			List[Any]=[2, 2, 3, 2]      ,						lowerCamelCase_				:			str=True      ,						lowerCamelCase_				:			Tuple=True      ,						lowerCamelCase_				:			Union[str, Any]=37      ,						lowerCamelCase_				:			str="gelu"      ,						lowerCamelCase_				:			int=10      ,						lowerCamelCase_				:			Any=0.02      ,						lowerCamelCase_				:			Dict=["stage2", "stage3", "stage4"]      ,						lowerCamelCase_				:			str=3      ,						lowerCamelCase_				:			List[str]=None      ,						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			parent
							SCREAMING_SNAKE_CASE :				int		=			batch_size
							SCREAMING_SNAKE_CASE :				Any		=			image_size
							SCREAMING_SNAKE_CASE :				str		=			num_channels
							SCREAMING_SNAKE_CASE :				Tuple		=			num_stages
							SCREAMING_SNAKE_CASE :				List[str]		=			hidden_sizes
							SCREAMING_SNAKE_CASE :				List[str]		=			depths
							SCREAMING_SNAKE_CASE :				Any		=			is_training
							SCREAMING_SNAKE_CASE :				Dict		=			use_labels
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			intermediate_size
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			hidden_act
							SCREAMING_SNAKE_CASE :				str		=			type_sequence_label_size
							SCREAMING_SNAKE_CASE :				List[str]		=			initializer_range
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			out_features
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			num_labels
							SCREAMING_SNAKE_CASE :				str		=			scope
							SCREAMING_SNAKE_CASE :				List[Any]		=			num_stages


					def lowerCamelCase_			(						self				:			Any						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Dict		=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

							SCREAMING_SNAKE_CASE :				Optional[int]		=			None
							if self.use_labels:
									SCREAMING_SNAKE_CASE :				int		=			ids_tensor([self.batch_size]      ,						self.type_sequence_label_size						)

							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			self.get_config()

							return config, pixel_values, labels


					def lowerCamelCase_			(						self				:			Optional[int]						):

							'''simple docstring'''



							return ConvNextConfig(
							    num_channels=self.num_channels      ,						num_stages=self.num_stages      ,						hidden_sizes=self.hidden_sizes      ,						depths=self.depths      ,						is_training=self.is_training      ,						intermediate_size=self.intermediate_size      ,						hidden_act=self.hidden_act      ,						out_features=self.out_features      ,						)


					def lowerCamelCase_			(						self				:			Optional[int]						):

							'''simple docstring'''



							return UperNetConfig(
							    backbone_config=self.get_backbone_config()      ,						hidden_size=5_12      ,						pool_scales=[1, 2, 3, 6]      ,						use_auxiliary_head=lowerCamelCase_      ,						auxiliary_loss_weight=0.4      ,						auxiliary_in_channels=40      ,						auxiliary_channels=2_56      ,						auxiliary_num_convs=1      ,						auxiliary_concat_input=lowerCamelCase_      ,						loss_ignore_index=2_55      ,						num_labels=self.num_labels      ,						)


					def lowerCamelCase_			(						self				:			Optional[Any]      ,						lowerCamelCase_				:			Union[str, Any]      ,						lowerCamelCase_				:			int      ,						lowerCamelCase_				:			Tuple						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Any		=			UperNetForSemanticSegmentation(config=lowerCamelCase_						)
							model.to(lowerCamelCase_						)
							model.eval()
							SCREAMING_SNAKE_CASE :				List[Any]		=			model(lowerCamelCase_						)
							self.parent.assertEqual(
							    result.logits.shape      ,						(self.batch_size, self.num_labels, self.image_size, self.image_size)						)



					def lowerCamelCase_			(						self				:			Optional[int]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Optional[int]		=			self.prepare_config_and_inputs()
							(
							    (
							    SCREAMING_SNAKE_CASE
							),							(
							    SCREAMING_SNAKE_CASE
							),							(
							    SCREAMING_SNAKE_CASE
							),							
							) :				Any		=			config_and_inputs
							SCREAMING_SNAKE_CASE :				Tuple		=			{"""pixel_values""": pixel_values}
							return config, inputs_dict







@require_torch
class      UpperCamelCase__					(					lowercase_						,					lowercase_						,					unittest.TestCase			):




					"""simple docstring"""
					SCREAMING_SNAKE_CASE__				=	(UperNetForSemanticSegmentation,) if is_torch_available() else ()
					SCREAMING_SNAKE_CASE__				=	{'''image-segmentation''': UperNetForSemanticSegmentation} if is_torch_available() else {}
					SCREAMING_SNAKE_CASE__				=	False
					SCREAMING_SNAKE_CASE__				=	False
					SCREAMING_SNAKE_CASE__				=	False
					SCREAMING_SNAKE_CASE__				=	False
					SCREAMING_SNAKE_CASE__				=	False
					SCREAMING_SNAKE_CASE__				=	False


					def lowerCamelCase_			(						self				:			List[str]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			UperNetModelTester(self						)
							SCREAMING_SNAKE_CASE :				Dict		=			ConfigTester(self      ,						config_class=lowerCamelCase_      ,						has_text_modality=lowerCamelCase_      ,						hidden_size=37						)


					def lowerCamelCase_			(						self				:			List[Any]						):

							'''simple docstring'''



							self.create_and_test_config_common_properties()
							self.config_tester.create_and_test_config_to_json_string()
							self.config_tester.create_and_test_config_to_json_file()
							self.config_tester.create_and_test_config_from_and_save_pretrained()
							self.config_tester.create_and_test_config_with_num_labels()
							self.config_tester.check_config_can_be_init_without_params()
							self.config_tester.check_config_arguments_init()


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

							'''simple docstring'''



							return


					def lowerCamelCase_			(						self				:			List[str]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE,							SCREAMING_SNAKE_CASE :				Optional[Any]		=			self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
									SCREAMING_SNAKE_CASE :				Optional[int]		=			model_class(lowerCamelCase_						)
									SCREAMING_SNAKE_CASE :				Optional[Any]		=			inspect.signature(model.forward						)
									# signature.parameters is an OrderedDict => so arg_names order is deterministic
									SCREAMING_SNAKE_CASE :				Optional[Any]		=			[*signature.parameters.keys()]

									SCREAMING_SNAKE_CASE :				int		=			["""pixel_values"""]
									self.assertListEqual(arg_names[:1]      ,						lowerCamelCase_						)


					def lowerCamelCase_			(						self				:			Optional[Any]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Optional[Any]		=			self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_semantic_segmentation(*lowerCamelCase_						)


					@unittest.skip(reason="""UperNet does not use inputs_embeds"""						)
					def lowerCamelCase_			(						self				:			Optional[Any]						):

							'''simple docstring'''



							pass


					@unittest.skip(reason="""UperNet does not support input and output embeddings"""						)
					def lowerCamelCase_			(						self				:			str						):

							'''simple docstring'''



							pass


					@unittest.skip(reason="""UperNet does not have a base model"""						)
					def lowerCamelCase_			(						self				:			Tuple						):

							'''simple docstring'''



							pass


					@unittest.skip(reason="""UperNet does not have a base model"""						)
					def lowerCamelCase_			(						self				:			Tuple						):

							'''simple docstring'''



							pass


					@require_torch_multi_gpu
					@unittest.skip(reason="""UperNet has some layers using `add_module` which doesn't work well with `nn.DataParallel`"""						)
					def lowerCamelCase_			(						self				:			List[str]						):

							'''simple docstring'''



							pass


					@unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""						)
					def lowerCamelCase_			(						self				:			List[str]						):

							'''simple docstring'''



							pass


					def lowerCamelCase_			(						self				:			int						):

							'''simple docstring'''



							def check_hidden_states_output(lowerCamelCase_				:			Dict      ,						lowerCamelCase_				:			int      ,						lowerCamelCase_				:			str						):
									SCREAMING_SNAKE_CASE :				Union[str, Any]		=			model_class(lowerCamelCase_						)
									model.to(lowerCamelCase_						)
									model.eval()

									with torch.no_grad():
											SCREAMING_SNAKE_CASE :				Tuple		=			model(**self._prepare_for_class(lowerCamelCase_      ,						lowerCamelCase_						)						)

									SCREAMING_SNAKE_CASE :				Dict		=			outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

									SCREAMING_SNAKE_CASE :				str		=			self.model_tester.num_stages
									self.assertEqual(len(lowerCamelCase_						)      ,						expected_num_stages + 1						)

									# ConvNext's feature maps are of shape (batch_size, num_channels, height, width)
									self.assertListEqual(
									    list(hidden_states[0].shape[-2:]						)      ,						[self.model_tester.image_size // 4, self.model_tester.image_size // 4]      ,						)

							SCREAMING_SNAKE_CASE,							SCREAMING_SNAKE_CASE :				Optional[int]		=			self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
									SCREAMING_SNAKE_CASE :				Any		=			True
									check_hidden_states_output(lowerCamelCase_      ,						lowerCamelCase_      ,						lowerCamelCase_						)

									# check that output_hidden_states also work using config
									del inputs_dict["output_hidden_states"]
									SCREAMING_SNAKE_CASE :				Any		=			True

									check_hidden_states_output(lowerCamelCase_      ,						lowerCamelCase_      ,						lowerCamelCase_						)


					def lowerCamelCase_			(						self				:			str						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE,							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			self.model_tester.prepare_config_and_inputs_for_common()

							SCREAMING_SNAKE_CASE :				str		=			_config_zero_init(lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Tuple		=			_config_zero_init(configs_no_init.backbone_config						)
							for model_class in self.all_model_classes:
									SCREAMING_SNAKE_CASE :				Any		=			model_class(config=lowerCamelCase_						)
									for name, param in model.named_parameters():
											if param.requires_grad:
													self.assertIn(
													    ((param.data.mean() * 1e9).round() / 1e9).item()      ,						[0.0, 1.0]      ,						msg=f'''Parameter {name} of model {model_class} seems not properly initialized'''      ,						)


					@unittest.skip(reason="""UperNet does not have tied weights"""						)
					def lowerCamelCase_			(						self				:			str						):

							'''simple docstring'''



							pass



					@slow
					def lowerCamelCase_			(						self				:			str						):

							'''simple docstring'''



							for model_name in UPERNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									SCREAMING_SNAKE_CASE :				List[str]		=			UperNetForSemanticSegmentation.from_pretrained(lowerCamelCase_						)
									self.assertIsNotNone(lowerCamelCase_						)







def 		__A		(  ):


		"""simple docstring"""



		SCREAMING_SNAKE_CASE :				int		=			hf_hub_download(
		    repo_id="""hf-internal-testing/fixtures_ade20k"""			,			repo_type="""dataset"""			,			filename="""ADE_val_00000001.jpg"""	)
		SCREAMING_SNAKE_CASE :				List[Any]		=			Image.open(lowerCamelCase_	).convert("""RGB"""	)
		return image




@require_torch
@require_vision
@slow
class      UpperCamelCase__					(					unittest.TestCase			):




					"""simple docstring"""


					def lowerCamelCase_			(						self				:			List[Any]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Optional[Any]		=			AutoImageProcessor.from_pretrained("""openmmlab/upernet-swin-tiny"""						)
							SCREAMING_SNAKE_CASE :				Tuple		=			UperNetForSemanticSegmentation.from_pretrained("""openmmlab/upernet-swin-tiny"""						).to(lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				Tuple		=			prepare_img()
							SCREAMING_SNAKE_CASE :				List[Any]		=			processor(images=lowerCamelCase_      ,						return_tensors="""pt"""						).to(lowerCamelCase_						)

							with torch.no_grad():
									SCREAMING_SNAKE_CASE :				Optional[Any]		=			model(**lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				Optional[int]		=			torch.Size((1, model.config.num_labels, 5_12, 5_12)						)
							self.assertEqual(outputs.logits.shape      ,						lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				Optional[int]		=			torch.tensor(
							    [[-7.5_958, -7.5_958, -7.4_302], [-7.5_958, -7.5_958, -7.4_302], [-7.4_797, -7.4_797, -7.3_068]]						).to(lowerCamelCase_						)
							self.assertTrue(torch.allclose(outputs.logits[0, 0, :3, :3]      ,						lowerCamelCase_      ,						atol=1e-4						)						)



					def lowerCamelCase_			(						self				:			Any						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Dict		=			AutoImageProcessor.from_pretrained("""openmmlab/upernet-convnext-tiny"""						)
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			UperNetForSemanticSegmentation.from_pretrained("""openmmlab/upernet-convnext-tiny"""						).to(lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				str		=			prepare_img()
							SCREAMING_SNAKE_CASE :				Any		=			processor(images=lowerCamelCase_      ,						return_tensors="""pt"""						).to(lowerCamelCase_						)

							with torch.no_grad():
									SCREAMING_SNAKE_CASE :				str		=			model(**lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				Optional[Any]		=			torch.Size((1, model.config.num_labels, 5_12, 5_12)						)
							self.assertEqual(outputs.logits.shape      ,						lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				List[Any]		=			torch.tensor(
							    [[-8.8_110, -8.8_110, -8.6_521], [-8.8_110, -8.8_110, -8.6_521], [-8.7_746, -8.7_746, -8.6_130]]						).to(lowerCamelCase_						)
							self.assertTrue(torch.allclose(outputs.logits[0, 0, :3, :3]      ,						lowerCamelCase_      ,						atol=1e-4						)						)










'''simple docstring'''




import tempfile

import torch

from diffusers import (
    DEISMultistepScheduler,
    DPMSolverMultistepScheduler,
    DPMSolverSinglestepScheduler,
    UniPCMultistepScheduler,
)

from .test_schedulers import SchedulerCommonTest




class      UpperCamelCase__					(					lowercase_			):




					"""simple docstring"""
					SCREAMING_SNAKE_CASE__				=	(DPMSolverSinglestepScheduler,)
					SCREAMING_SNAKE_CASE__				=	(('''num_inference_steps''', 25),)


					def lowerCamelCase_			(						self				:			Any      ,						**lowerCamelCase_				:			List[Any]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				str		=			{
							    """num_train_timesteps""": 10_00,
							    """beta_start""": 0.0_001,
							    """beta_end""": 0.02,
							    """beta_schedule""": """linear""",
							    """solver_order""": 2,
							    """prediction_type""": """epsilon""",
							    """thresholding""": False,
							    """sample_max_value""": 1.0,
							    """algorithm_type""": """dpmsolver++""",
							    """solver_type""": """midpoint""",
							    """lambda_min_clipped""": -float("""inf"""						),
							    """variance_type""": None,
							}

							config.update(**lowerCamelCase_						)
							return config


					def lowerCamelCase_			(						self				:			Any      ,						lowerCamelCase_				:			List[str]=0      ,						**lowerCamelCase_				:			Optional[Any]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				int		=			dict(self.forward_default_kwargs						)
							SCREAMING_SNAKE_CASE :				List[str]		=			kwargs.pop("""num_inference_steps"""      ,						lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			self.dummy_sample
							SCREAMING_SNAKE_CASE :				str		=			0.1 * sample
							SCREAMING_SNAKE_CASE :				Any		=			[residual + 0.2, residual + 0.15, residual + 0.10]

							for scheduler_class in self.scheduler_classes:
									SCREAMING_SNAKE_CASE :				Tuple		=			self.get_scheduler_config(**lowerCamelCase_						)
									SCREAMING_SNAKE_CASE :				Optional[Any]		=			scheduler_class(**lowerCamelCase_						)
									scheduler.set_timesteps(lowerCamelCase_						)
									# copy over dummy past residuals
									SCREAMING_SNAKE_CASE :				Any		=			dummy_past_residuals[: scheduler.config.solver_order]

									with tempfile.TemporaryDirectory() as tmpdirname:
											scheduler.save_config(lowerCamelCase_						)
											SCREAMING_SNAKE_CASE :				int		=			scheduler_class.from_pretrained(lowerCamelCase_						)
											new_scheduler.set_timesteps(lowerCamelCase_						)
											# copy over dummy past residuals
											SCREAMING_SNAKE_CASE :				Optional[int]		=			dummy_past_residuals[: new_scheduler.config.solver_order]

									SCREAMING_SNAKE_CASE,							SCREAMING_SNAKE_CASE :				str		=			sample, sample
									for t in range(lowerCamelCase_      ,						time_step + scheduler.config.solver_order + 1						):
											SCREAMING_SNAKE_CASE :				Union[str, Any]		=			scheduler.step(lowerCamelCase_      ,						lowerCamelCase_      ,						lowerCamelCase_      ,						**lowerCamelCase_						).prev_sample
											SCREAMING_SNAKE_CASE :				Optional[int]		=			new_scheduler.step(lowerCamelCase_      ,						lowerCamelCase_      ,						lowerCamelCase_      ,						**lowerCamelCase_						).prev_sample

											assert torch.sum(torch.abs(output - new_output						)						) < 1e-5, "Scheduler outputs are not identical"


					def lowerCamelCase_			(						self				:			List[str]						):

							'''simple docstring'''



							pass


					def lowerCamelCase_			(						self				:			str      ,						lowerCamelCase_				:			Union[str, Any]=0      ,						**lowerCamelCase_				:			Tuple						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				List[str]		=			dict(self.forward_default_kwargs						)
							SCREAMING_SNAKE_CASE :				List[Any]		=			kwargs.pop("""num_inference_steps"""      ,						lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Tuple		=			self.dummy_sample
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			0.1 * sample
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			[residual + 0.2, residual + 0.15, residual + 0.10]

							for scheduler_class in self.scheduler_classes:
									SCREAMING_SNAKE_CASE :				int		=			self.get_scheduler_config()
									SCREAMING_SNAKE_CASE :				Any		=			scheduler_class(**lowerCamelCase_						)
									scheduler.set_timesteps(lowerCamelCase_						)

									# copy over dummy past residuals (must be after setting timesteps)
									SCREAMING_SNAKE_CASE :				int		=			dummy_past_residuals[: scheduler.config.solver_order]

									with tempfile.TemporaryDirectory() as tmpdirname:
											scheduler.save_config(lowerCamelCase_						)
											SCREAMING_SNAKE_CASE :				List[str]		=			scheduler_class.from_pretrained(lowerCamelCase_						)
											# copy over dummy past residuals
											new_scheduler.set_timesteps(lowerCamelCase_						)

											# copy over dummy past residual (must be after setting timesteps)
											SCREAMING_SNAKE_CASE :				Dict		=			dummy_past_residuals[: new_scheduler.config.solver_order]

									SCREAMING_SNAKE_CASE :				Union[str, Any]		=			scheduler.step(lowerCamelCase_      ,						lowerCamelCase_      ,						lowerCamelCase_      ,						**lowerCamelCase_						).prev_sample
									SCREAMING_SNAKE_CASE :				Dict		=			new_scheduler.step(lowerCamelCase_      ,						lowerCamelCase_      ,						lowerCamelCase_      ,						**lowerCamelCase_						).prev_sample

									assert torch.sum(torch.abs(output - new_output						)						) < 1e-5, "Scheduler outputs are not identical"


					def lowerCamelCase_			(						self				:			Dict      ,						lowerCamelCase_				:			int=None      ,						**lowerCamelCase_				:			Union[str, Any]						):

							'''simple docstring'''



							if scheduler is None:
									SCREAMING_SNAKE_CASE :				Tuple		=			self.scheduler_classes[0]
									SCREAMING_SNAKE_CASE :				int		=			self.get_scheduler_config(**lowerCamelCase_						)
									SCREAMING_SNAKE_CASE :				List[str]		=			scheduler_class(**lowerCamelCase_						)

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

							SCREAMING_SNAKE_CASE :				Optional[Any]		=			10
							SCREAMING_SNAKE_CASE :				Any		=			self.dummy_model()
							SCREAMING_SNAKE_CASE :				Any		=			self.dummy_sample_deter
							scheduler.set_timesteps(lowerCamelCase_						)

							for i, t in enumerate(scheduler.timesteps						):
									SCREAMING_SNAKE_CASE :				Dict		=			model(lowerCamelCase_      ,						lowerCamelCase_						)
									SCREAMING_SNAKE_CASE :				Union[str, Any]		=			scheduler.step(lowerCamelCase_      ,						lowerCamelCase_      ,						lowerCamelCase_						).prev_sample

							return sample


					def lowerCamelCase_			(						self				:			Dict						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Tuple		=			DPMSolverSinglestepScheduler(**self.get_scheduler_config()						)
							SCREAMING_SNAKE_CASE :				List[Any]		=			50
							SCREAMING_SNAKE_CASE :				Dict		=			self.dummy_model()
							SCREAMING_SNAKE_CASE :				Any		=			self.dummy_sample_deter
							scheduler.set_timesteps(lowerCamelCase_						)

							# make sure that the first t is uneven
							for i, t in enumerate(scheduler.timesteps[3:]						):
									SCREAMING_SNAKE_CASE :				str		=			model(lowerCamelCase_      ,						lowerCamelCase_						)
									SCREAMING_SNAKE_CASE :				Optional[Any]		=			scheduler.step(lowerCamelCase_      ,						lowerCamelCase_      ,						lowerCamelCase_						).prev_sample

							SCREAMING_SNAKE_CASE :				Any		=			torch.mean(torch.abs(lowerCamelCase_						)						)

							assert abs(result_mean.item() - 0.2_574						) < 1e-3


					def lowerCamelCase_			(						self				:			str						):

							'''simple docstring'''



							for timesteps in [25, 50, 1_00, 9_99, 10_00]:
									self.check_over_configs(num_train_timesteps=lowerCamelCase_						)


					def lowerCamelCase_			(						self				:			str						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				List[Any]		=			DPMSolverSinglestepScheduler(**self.get_scheduler_config()						)
							SCREAMING_SNAKE_CASE :				int		=			self.full_loop(scheduler=lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			torch.mean(torch.abs(lowerCamelCase_						)						)

							assert abs(result_mean.item() - 0.2_791						) < 1e-3

							SCREAMING_SNAKE_CASE :				List[str]		=			DEISMultistepScheduler.from_config(scheduler.config						)
							SCREAMING_SNAKE_CASE :				Optional[int]		=			DPMSolverMultistepScheduler.from_config(scheduler.config						)
							SCREAMING_SNAKE_CASE :				Any		=			UniPCMultistepScheduler.from_config(scheduler.config						)
							SCREAMING_SNAKE_CASE :				Optional[int]		=			DPMSolverSinglestepScheduler.from_config(scheduler.config						)

							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			self.full_loop(scheduler=lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				List[str]		=			torch.mean(torch.abs(lowerCamelCase_						)						)

							assert abs(result_mean.item() - 0.2_791						) < 1e-3


					def lowerCamelCase_			(						self				:			str						):

							'''simple docstring'''



							self.check_over_configs(thresholding=lowerCamelCase_						)
							for order in [1, 2, 3]:
									for solver_type in ["midpoint", "heun"]:
											for threshold in [0.5, 1.0, 2.0]:
													for prediction_type in ["epsilon", "sample"]:
															self.check_over_configs(
															    thresholding=lowerCamelCase_      ,						prediction_type=lowerCamelCase_      ,						sample_max_value=lowerCamelCase_      ,						algorithm_type="""dpmsolver++"""      ,						solver_order=lowerCamelCase_      ,						solver_type=lowerCamelCase_      ,						)


					def lowerCamelCase_			(						self				:			Dict						):

							'''simple docstring'''



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


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

							'''simple docstring'''



							for algorithm_type in ["dpmsolver", "dpmsolver++"]:
									for solver_type in ["midpoint", "heun"]:
											for order in [1, 2, 3]:
													for prediction_type in ["epsilon", "sample"]:
															self.check_over_configs(
															    solver_order=lowerCamelCase_      ,						solver_type=lowerCamelCase_      ,						prediction_type=lowerCamelCase_      ,						algorithm_type=lowerCamelCase_      ,						)
															SCREAMING_SNAKE_CASE :				int		=			self.full_loop(
															    solver_order=lowerCamelCase_      ,						solver_type=lowerCamelCase_      ,						prediction_type=lowerCamelCase_      ,						algorithm_type=lowerCamelCase_      ,						)
															assert not torch.isnan(lowerCamelCase_						).any(), "Samples have nan numbers"


					def lowerCamelCase_			(						self				:			Optional[Any]						):

							'''simple docstring'''



							self.check_over_configs(lower_order_final=lowerCamelCase_						)
							self.check_over_configs(lower_order_final=lowerCamelCase_						)


					def lowerCamelCase_			(						self				:			Tuple						):

							'''simple docstring'''



							self.check_over_configs(lambda_min_clipped=-float("""inf"""						)						)
							self.check_over_configs(lambda_min_clipped=-5.1						)


					def lowerCamelCase_			(						self				:			int						):

							'''simple docstring'''



							self.check_over_configs(variance_type=lowerCamelCase_						)
							self.check_over_configs(variance_type="""learned_range"""						)


					def lowerCamelCase_			(						self				:			List[str]						):

							'''simple docstring'''



							for num_inference_steps in [1, 2, 3, 5, 10, 50, 1_00, 9_99, 10_00]:
									self.check_over_forward(num_inference_steps=lowerCamelCase_      ,						time_step=0						)


					def lowerCamelCase_			(						self				:			str						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				str		=			self.full_loop()
							SCREAMING_SNAKE_CASE :				Any		=			torch.mean(torch.abs(lowerCamelCase_						)						)

							assert abs(result_mean.item() - 0.2_791						) < 1e-3


					def lowerCamelCase_			(						self				:			List[Any]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Any		=			self.full_loop(use_karras_sigmas=lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				List[Any]		=			torch.mean(torch.abs(lowerCamelCase_						)						)

							assert abs(result_mean.item() - 0.2_248						) < 1e-3


					def lowerCamelCase_			(						self				:			List[str]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				List[str]		=			self.full_loop(prediction_type="""v_prediction"""						)
							SCREAMING_SNAKE_CASE :				int		=			torch.mean(torch.abs(lowerCamelCase_						)						)

							assert abs(result_mean.item() - 0.1_453						) < 1e-3


					def lowerCamelCase_			(						self				:			int						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Tuple		=			self.full_loop(prediction_type="""v_prediction"""      ,						use_karras_sigmas=lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				str		=			torch.mean(torch.abs(lowerCamelCase_						)						)

							assert abs(result_mean.item() - 0.0_649						) < 1e-3



					def lowerCamelCase_			(						self				:			str						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				int		=			self.scheduler_classes[0]
							SCREAMING_SNAKE_CASE :				List[str]		=			self.get_scheduler_config(thresholding=lowerCamelCase_      ,						dynamic_thresholding_ratio=0						)
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			scheduler_class(**lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				Any		=			10
							SCREAMING_SNAKE_CASE :				List[Any]		=			self.dummy_model()
							SCREAMING_SNAKE_CASE :				int		=			self.dummy_sample_deter.half()
							scheduler.set_timesteps(lowerCamelCase_						)

							for i, t in enumerate(scheduler.timesteps						):
									SCREAMING_SNAKE_CASE :				List[Any]		=			model(lowerCamelCase_      ,						lowerCamelCase_						)
									SCREAMING_SNAKE_CASE :				Any		=			scheduler.step(lowerCamelCase_      ,						lowerCamelCase_      ,						lowerCamelCase_						).prev_sample

							assert sample.dtype == torch.floataa



