



"""simple docstring"""


import inspect
import unittest

from transformers import ConvNextVaConfig
from transformers.models.auto import get_values
from transformers.models.auto.modeling_auto import MODEL_FOR_BACKBONE_MAPPING_NAMES, MODEL_MAPPING_NAMES
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

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


if is_torch_available():
		import torch

		from transformers import ConvNextVaBackbone, ConvNextVaForImageClassification, ConvNextVaModel
		from transformers.models.convnextva.modeling_convnextva import CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
		from PIL import Image

		from transformers import AutoImageProcessor







class 				A_      :



						"""simple docstring"""






						def __init__( self			:str       ,  lowercase_			:Optional[Any]       ,  lowercase_			:str=13       ,  lowercase_			:Dict=32       ,  lowercase_			:Any=3       ,  lowercase_			:str=4       ,  lowercase_			:str=[10, 20, 30, 40]       ,  lowercase_			:List[str]=[2, 2, 3, 2]       ,  lowercase_			:Tuple=True       ,  lowercase_			:int=True       ,  lowercase_			:Tuple=37       ,  lowercase_			:List[str]="gelu"       ,  lowercase_			:Optional[int]=10       ,  lowercase_			:str=0.02       ,  lowercase_			:Union[str, Any]=["stage2", "stage3", "stage4"]       ,  lowercase_			:int=[2, 3, 4]       ,  lowercase_			:List[str]=None       ,  )    ->      Optional[Any]:
												UpperCAmelCase					=			parent
												UpperCAmelCase					=			batch_size
												UpperCAmelCase					=			image_size
												UpperCAmelCase					=			num_channels
												UpperCAmelCase					=			num_stages
												UpperCAmelCase					=			hidden_sizes
												UpperCAmelCase					=			depths
												UpperCAmelCase					=			is_training
												UpperCAmelCase					=			use_labels
												UpperCAmelCase					=			intermediate_size
												UpperCAmelCase					=			hidden_act
												UpperCAmelCase					=			num_labels
												UpperCAmelCase					=			initializer_range
												UpperCAmelCase					=			out_features
												UpperCAmelCase					=			out_indices
												UpperCAmelCase					=			scope






						def      UpperCAmelCase__					( self			:List[str] )    ->      str:
												UpperCAmelCase					=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size] )

												UpperCAmelCase					=			None
												if self.use_labels:
																		UpperCAmelCase					=			ids_tensor([self.batch_size]       ,  self.num_labels )

												UpperCAmelCase					=			self.get_config()

												return config, pixel_values, labels






						def      UpperCAmelCase__					( self			:Tuple )    ->      str:
												return ConvNextVaConfig(
												    num_channels=self.num_channels       ,  hidden_sizes=self.hidden_sizes       ,  depths=self.depths       ,  num_stages=self.num_stages       ,  hidden_act=self.hidden_act       ,  is_decoder=lowercase_       ,  initializer_range=self.initializer_range       ,  out_features=self.out_features       ,  out_indices=self.out_indices       ,  num_labels=self.num_labels       ,  )






						def      UpperCAmelCase__					( self			:Optional[int]       ,  lowercase_			:Optional[int]       ,  lowercase_			:List[str]       ,  lowercase_			:Optional[int] )    ->      List[str]:
												UpperCAmelCase					=			ConvNextVaModel(config=lowercase_ )
												model.to(lowercase_ )
												model.eval()
												UpperCAmelCase					=			model(lowercase_ )
												# expected last hidden states: B, C, H // 32, W // 32
												self.parent.assertEqual(
												    result.last_hidden_state.shape       ,  (self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)       ,  )






						def      UpperCAmelCase__					( self			:List[Any]       ,  lowercase_			:Tuple       ,  lowercase_			:Any       ,  lowercase_			:Union[str, Any] )    ->      int:
												UpperCAmelCase					=			ConvNextVaForImageClassification(lowercase_ )
												model.to(lowercase_ )
												model.eval()
												UpperCAmelCase					=			model(lowercase_       ,  labels=lowercase_ )
												self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.num_labels) )






						def      UpperCAmelCase__					( self			:Dict       ,  lowercase_			:Optional[int]       ,  lowercase_			:Tuple       ,  lowercase_			:str )    ->      Dict:
												UpperCAmelCase					=			ConvNextVaBackbone(config=lowercase_ )
												model.to(lowercase_ )
												model.eval()
												UpperCAmelCase					=			model(lowercase_ )

												# verify hidden states
												self.parent.assertEqual(len(result.feature_maps )       ,  len(config.out_features ) )
												self.parent.assertListEqual(list(result.feature_maps[0].shape )       ,  [self.batch_size, self.hidden_sizes[1], 4, 4] )

												# verify channels
												self.parent.assertEqual(len(model.channels )       ,  len(config.out_features ) )
												self.parent.assertListEqual(model.channels       ,  config.hidden_sizes[1:] )

												# verify backbone works with out_features=None
												UpperCAmelCase					=			None
												UpperCAmelCase					=			ConvNextVaBackbone(config=lowercase_ )
												model.to(lowercase_ )
												model.eval()
												UpperCAmelCase					=			model(lowercase_ )

												# verify feature maps
												self.parent.assertEqual(len(result.feature_maps )       ,  1 )
												self.parent.assertListEqual(list(result.feature_maps[0].shape )       ,  [self.batch_size, self.hidden_sizes[-1], 1, 1] )

												# verify channels
												self.parent.assertEqual(len(model.channels )       ,  1 )
												self.parent.assertListEqual(model.channels       ,  [config.hidden_sizes[-1]] )






						def      UpperCAmelCase__					( self			:Optional[int] )    ->      int:
												UpperCAmelCase					=			self.prepare_config_and_inputs()
												UpperCAmelCase				,   UpperCAmelCase				,   UpperCAmelCase					=			config_and_inputs
												UpperCAmelCase					=			{'pixel_values': pixel_values}
												return config, inputs_dict






						def      UpperCAmelCase__					( self			:Union[str, Any] )    ->      Tuple:
												UpperCAmelCase					=			self.prepare_config_and_inputs()
												UpperCAmelCase				,   UpperCAmelCase				,   UpperCAmelCase					=			config_and_inputs
												UpperCAmelCase					=			{'pixel_values': pixel_values, 'labels': labels}
												return config, inputs_dict







@require_torch
class 				A_      (					SCREAMING_SNAKE_CASE_     ,       SCREAMING_SNAKE_CASE_     ,       unittest.TestCase    ):



						"""simple docstring"""
						__UpperCamelCase		    =							(
						    (
						        ConvNextVaModel,
						        ConvNextVaForImageClassification,
						        ConvNextVaBackbone,
						    )
						    if is_torch_available()
						    else ()
						)
						__UpperCamelCase		    =							(
						    {"""feature-extraction""": ConvNextVaModel, """image-classification""": ConvNextVaForImageClassification}
						    if is_torch_available()
						    else {}
						)

						__UpperCamelCase		    =							False
						__UpperCamelCase		    =							False
						__UpperCamelCase		    =							False
						__UpperCamelCase		    =							False
						__UpperCamelCase		    =							False






						def      UpperCAmelCase__					( self			:Optional[Any] )    ->      Any:
												UpperCAmelCase					=			ConvNextVaModelTester(self )
												UpperCAmelCase					=			ConfigTester(self       ,  config_class=lowercase_       ,  has_text_modality=lowercase_       ,  hidden_size=37 )






						def      UpperCAmelCase__					( self			:Dict )    ->      Dict:
												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      UpperCAmelCase__					( self			:Union[str, Any] )    ->      List[str]:
												return






						@unittest.skip(reason='ConvNextV2 does not use inputs_embeds' )
						def      UpperCAmelCase__					( self			:int )    ->      Any:
												pass






						@unittest.skip(reason='ConvNextV2 does not support input and output embeddings' )
						def      UpperCAmelCase__					( self			:List[Any] )    ->      int:
												pass






						@unittest.skip(reason='ConvNextV2 does not use feedforward chunking' )
						def      UpperCAmelCase__					( self			:List[Any] )    ->      List[str]:
												pass






						def      UpperCAmelCase__					( self			:Any )    ->      Optional[int]:
												if not self.model_tester.is_training:
																		return

												for model_class in self.all_model_classes:
																		UpperCAmelCase				,   UpperCAmelCase					=			self.model_tester.prepare_config_and_inputs_with_labels()
																		UpperCAmelCase					=			True

																		if model_class.__name__ in [
																		    *get_values(lowercase_ ),
																		    *get_values(lowercase_ ),
																		]:
																								continue

																		UpperCAmelCase					=			model_class(lowercase_ )
																		model.to(lowercase_ )
																		model.train()
																		UpperCAmelCase					=			self._prepare_for_class(lowercase_       ,  lowercase_       ,  return_labels=lowercase_ )
																		UpperCAmelCase					=			model(**lowercase_ ).loss
																		loss.backward()






						def      UpperCAmelCase__					( self			:Tuple )    ->      Optional[int]:
												if not self.model_tester.is_training:
																		return

												for model_class in self.all_model_classes:
																		UpperCAmelCase				,   UpperCAmelCase					=			self.model_tester.prepare_config_and_inputs_with_labels()
																		UpperCAmelCase					=			False
																		UpperCAmelCase					=			True

																		if (
																		    model_class.__name__
																		    in [*get_values(lowercase_ ), *get_values(lowercase_ )]
																		    or not model_class.supports_gradient_checkpointing
																		):
																								continue

																		UpperCAmelCase					=			model_class(lowercase_ )
																		model.to(lowercase_ )
																		model.gradient_checkpointing_enable()
																		model.train()
																		UpperCAmelCase					=			self._prepare_for_class(lowercase_       ,  lowercase_       ,  return_labels=lowercase_ )
																		UpperCAmelCase					=			model(**lowercase_ ).loss
																		loss.backward()






						def      UpperCAmelCase__					( self			:str )    ->      Union[str, Any]:
												UpperCAmelCase				,   UpperCAmelCase					=			self.model_tester.prepare_config_and_inputs_for_common()

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

																		UpperCAmelCase					=			['pixel_values']
																		self.assertListEqual(arg_names[:1]       ,  lowercase_ )






						def      UpperCAmelCase__					( self			:Union[str, Any] )    ->      Dict:
												UpperCAmelCase					=			self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*lowercase_ )






						def      UpperCAmelCase__					( self			:Optional[int] )    ->      Optional[Any]:
												def check_hidden_states_output(lowercase_			:Optional[int]       ,  lowercase_			:Optional[Any]       ,  lowercase_			:List[Any] ):
																		UpperCAmelCase					=			model_class(lowercase_ )
																		model.to(lowercase_ )
																		model.eval()

																		with torch.no_grad():
																								UpperCAmelCase					=			model(**self._prepare_for_class(lowercase_       ,  lowercase_ ) )

																		UpperCAmelCase					=			outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

																		UpperCAmelCase					=			self.model_tester.num_stages
																		self.assertEqual(len(lowercase_ )       ,  expected_num_stages + 1 )

																		# ConvNextV2'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]       ,  )

												UpperCAmelCase				,   UpperCAmelCase					=			self.model_tester.prepare_config_and_inputs_for_common()

												for model_class in self.all_model_classes:
																		UpperCAmelCase					=			True
																		check_hidden_states_output(lowercase_       ,  lowercase_       ,  lowercase_ )

																		# check that output_hidden_states also work using config
																		del inputs_dict["output_hidden_states"]
																		UpperCAmelCase					=			True

																		check_hidden_states_output(lowercase_       ,  lowercase_       ,  lowercase_ )






						def      UpperCAmelCase__					( self			:Any )    ->      Union[str, Any]:
												UpperCAmelCase					=			self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_image_classification(*lowercase_ )






						@slow
						def      UpperCAmelCase__					( self			:Optional[int] )    ->      Optional[Any]:
												for model_name in CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		UpperCAmelCase					=			ConvNextVaModel.from_pretrained(lowercase_ )
																		self.assertIsNotNone(lowercase_ )


def 			_lowerCAmelCase				(       ):
						UpperCAmelCase					=			Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'						)
						return image







@require_torch
@require_vision
class 				A_      (					unittest.TestCase    ):



						"""simple docstring"""






						@cached_property
						def      UpperCAmelCase__					( self			:Dict )    ->      str:
												return AutoImageProcessor.from_pretrained('facebook/convnextv2-tiny-1k-224' ) if is_vision_available() else None






						@slow
						def      UpperCAmelCase__					( self			:Dict )    ->      int:
												UpperCAmelCase					=			ConvNextVaForImageClassification.from_pretrained('facebook/convnextv2-tiny-1k-224' ).to(lowercase_ )

												UpperCAmelCase					=			self.default_image_processor
												UpperCAmelCase					=			prepare_img()
												UpperCAmelCase					=			preprocessor(images=lowercase_       ,  return_tensors='pt' ).to(lowercase_ )

												# forward pass
												with torch.no_grad():
																		UpperCAmelCase					=			model(**lowercase_ )

												# verify the logits
												UpperCAmelCase					=			torch.Size((1, 10_00) )
												self.assertEqual(outputs.logits.shape       ,  lowercase_ )

												UpperCAmelCase					=			torch.tensor([0.9996, 0.1966, -0.4386] ).to(lowercase_ )
												self.assertTrue(torch.allclose(outputs.logits[0, :3]       ,  lowercase_       ,  atol=1E-4 ) )










"""simple docstring"""


import tempfile

import torch

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

from .test_schedulers import SchedulerCommonTest







class 				A_      (					SCREAMING_SNAKE_CASE_    ):



						"""simple docstring"""
						__UpperCamelCase		    =							(UniPCMultistepScheduler,)
						__UpperCamelCase		    =							(("""num_inference_steps""", 25),)






						def      UpperCAmelCase__					( self			:Any       ,  **lowercase_			:Optional[Any] )    ->      Dict:
												UpperCAmelCase					=			{
												    'num_train_timesteps': 10_00,
												    'beta_start': 0.0001,
												    'beta_end': 0.02,
												    'beta_schedule': 'linear',
												    'solver_order': 2,
												    'solver_type': 'bh2',
												}

												config.update(**lowercase_ )
												return config






						def      UpperCAmelCase__					( self			:Optional[Any]       ,  lowercase_			:Optional[int]=0       ,  **lowercase_			:Optional[Any] )    ->      List[str]:
												UpperCAmelCase					=			dict(self.forward_default_kwargs )
												UpperCAmelCase					=			kwargs.pop('num_inference_steps'       ,  lowercase_ )
												UpperCAmelCase					=			self.dummy_sample
												UpperCAmelCase					=			0.1 * sample
												UpperCAmelCase					=			[residual + 0.2, residual + 0.15, residual + 0.10]

												for scheduler_class in self.scheduler_classes:
																		UpperCAmelCase					=			self.get_scheduler_config(**lowercase_ )
																		UpperCAmelCase					=			scheduler_class(**lowercase_ )
																		scheduler.set_timesteps(lowercase_ )
																		# copy over dummy past residuals
																		UpperCAmelCase					=			dummy_past_residuals[: scheduler.config.solver_order]

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

																		UpperCAmelCase				,   UpperCAmelCase					=			sample, sample
																		for t in range(lowercase_       ,  time_step + scheduler.config.solver_order + 1 ):
																								UpperCAmelCase					=			scheduler.step(lowercase_       ,  lowercase_       ,  lowercase_       ,  **lowercase_ ).prev_sample
																								UpperCAmelCase					=			new_scheduler.step(lowercase_       ,  lowercase_       ,  lowercase_       ,  **lowercase_ ).prev_sample

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






						def      UpperCAmelCase__					( self			:List[Any]       ,  lowercase_			:Dict=0       ,  **lowercase_			:Optional[int] )    ->      List[str]:
												UpperCAmelCase					=			dict(self.forward_default_kwargs )
												UpperCAmelCase					=			kwargs.pop('num_inference_steps'       ,  lowercase_ )
												UpperCAmelCase					=			self.dummy_sample
												UpperCAmelCase					=			0.1 * sample
												UpperCAmelCase					=			[residual + 0.2, residual + 0.15, residual + 0.10]

												for scheduler_class in self.scheduler_classes:
																		UpperCAmelCase					=			self.get_scheduler_config()
																		UpperCAmelCase					=			scheduler_class(**lowercase_ )
																		scheduler.set_timesteps(lowercase_ )

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

																		with tempfile.TemporaryDirectory() as tmpdirname:
																								scheduler.save_config(lowercase_ )
																								UpperCAmelCase					=			scheduler_class.from_pretrained(lowercase_ )
																								# copy over dummy past residuals
																								new_scheduler.set_timesteps(lowercase_ )

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

																		UpperCAmelCase					=			scheduler.step(lowercase_       ,  lowercase_       ,  lowercase_       ,  **lowercase_ ).prev_sample
																		UpperCAmelCase					=			new_scheduler.step(lowercase_       ,  lowercase_       ,  lowercase_       ,  **lowercase_ ).prev_sample

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






						def      UpperCAmelCase__					( self			:List[Any]       ,  lowercase_			:Optional[int]=None       ,  **lowercase_			:str )    ->      Dict:
												if scheduler is None:
																		UpperCAmelCase					=			self.scheduler_classes[0]
																		UpperCAmelCase					=			self.get_scheduler_config(**lowercase_ )
																		UpperCAmelCase					=			scheduler_class(**lowercase_ )

												UpperCAmelCase					=			self.scheduler_classes[0]
												UpperCAmelCase					=			self.get_scheduler_config(**lowercase_ )
												UpperCAmelCase					=			scheduler_class(**lowercase_ )

												UpperCAmelCase					=			10
												UpperCAmelCase					=			self.dummy_model()
												UpperCAmelCase					=			self.dummy_sample_deter
												scheduler.set_timesteps(lowercase_ )

												for i, t in enumerate(scheduler.timesteps ):
																		UpperCAmelCase					=			model(lowercase_       ,  lowercase_ )
																		UpperCAmelCase					=			scheduler.step(lowercase_       ,  lowercase_       ,  lowercase_ ).prev_sample

												return sample






						def      UpperCAmelCase__					( self			:Union[str, Any] )    ->      Tuple:
												UpperCAmelCase					=			dict(self.forward_default_kwargs )

												UpperCAmelCase					=			kwargs.pop('num_inference_steps'       ,  lowercase_ )

												for scheduler_class in self.scheduler_classes:
																		UpperCAmelCase					=			self.get_scheduler_config()
																		UpperCAmelCase					=			scheduler_class(**lowercase_ )

																		UpperCAmelCase					=			self.dummy_sample
																		UpperCAmelCase					=			0.1 * sample

																		if num_inference_steps is not None and hasattr(lowercase_       ,  'set_timesteps' ):
																								scheduler.set_timesteps(lowercase_ )
																		elif num_inference_steps is not None and not hasattr(lowercase_       ,  'set_timesteps' ):
																								UpperCAmelCase					=			num_inference_steps

																		# copy over dummy past residuals (must be done after set_timesteps)
																		UpperCAmelCase					=			[residual + 0.2, residual + 0.15, residual + 0.10]
																		UpperCAmelCase					=			dummy_past_residuals[: scheduler.config.solver_order]

																		UpperCAmelCase					=			scheduler.timesteps[5]
																		UpperCAmelCase					=			scheduler.timesteps[6]

																		UpperCAmelCase					=			scheduler.step(lowercase_       ,  lowercase_       ,  lowercase_       ,  **lowercase_ ).prev_sample
																		UpperCAmelCase					=			scheduler.step(lowercase_       ,  lowercase_       ,  lowercase_       ,  **lowercase_ ).prev_sample

																		self.assertEqual(output_a.shape       ,  sample.shape )
																		self.assertEqual(output_a.shape       ,  output_a.shape )






						def      UpperCAmelCase__					( self			:Optional[int] )    ->      Optional[Any]:
												# make sure that iterating over schedulers with same config names gives same results
												# for defaults
												UpperCAmelCase					=			UniPCMultistepScheduler(**self.get_scheduler_config() )
												UpperCAmelCase					=			self.full_loop(scheduler=lowercase_ )
												UpperCAmelCase					=			torch.mean(torch.abs(lowercase_ ) )

												assert abs(result_mean.item() - 0.2464 ) < 1E-3

												UpperCAmelCase					=			DPMSolverSinglestepScheduler.from_config(scheduler.config )
												UpperCAmelCase					=			DEISMultistepScheduler.from_config(scheduler.config )
												UpperCAmelCase					=			DPMSolverMultistepScheduler.from_config(scheduler.config )
												UpperCAmelCase					=			UniPCMultistepScheduler.from_config(scheduler.config )

												UpperCAmelCase					=			self.full_loop(scheduler=lowercase_ )
												UpperCAmelCase					=			torch.mean(torch.abs(lowercase_ ) )

												assert abs(result_mean.item() - 0.2464 ) < 1E-3






						def      UpperCAmelCase__					( self			:Optional[int] )    ->      List[str]:
												for timesteps in [25, 50, 1_00, 9_99, 10_00]:
																		self.check_over_configs(num_train_timesteps=lowercase_ )






						def      UpperCAmelCase__					( self			:int )    ->      str:
												self.check_over_configs(thresholding=lowercase_ )
												for order in [1, 2, 3]:
																		for solver_type in ["bh1", "bh2"]:
																								for threshold in [0.5, 1.0, 2.0]:
																														for prediction_type in ["epsilon", "sample"]:
																																				self.check_over_configs(
																																				    thresholding=lowercase_       ,  prediction_type=lowercase_       ,  sample_max_value=lowercase_       ,  solver_order=lowercase_       ,  solver_type=lowercase_       ,  )






						def      UpperCAmelCase__					( self			:Any )    ->      str:
												for prediction_type in ["epsilon", "v_prediction"]:
																		self.check_over_configs(prediction_type=lowercase_ )






						def      UpperCAmelCase__					( self			:str )    ->      Optional[Any]:
												for solver_type in ["bh1", "bh2"]:
																		for order in [1, 2, 3]:
																								for prediction_type in ["epsilon", "sample"]:
																														self.check_over_configs(
																														    solver_order=lowercase_       ,  solver_type=lowercase_       ,  prediction_type=lowercase_       ,  )
																														UpperCAmelCase					=			self.full_loop(
																														    solver_order=lowercase_       ,  solver_type=lowercase_       ,  prediction_type=lowercase_       ,  )
																														assert not torch.isnan(lowercase_ ).any(), "Samples have nan numbers"






						def      UpperCAmelCase__					( self			:Dict )    ->      List[Any]:
												self.check_over_configs(lower_order_final=lowercase_ )
												self.check_over_configs(lower_order_final=lowercase_ )






						def      UpperCAmelCase__					( self			:Any )    ->      List[Any]:
												for num_inference_steps in [1, 2, 3, 5, 10, 50, 1_00, 9_99, 10_00]:
																		self.check_over_forward(num_inference_steps=lowercase_       ,  time_step=0 )






						def      UpperCAmelCase__					( self			:int )    ->      Union[str, Any]:
												UpperCAmelCase					=			self.full_loop()
												UpperCAmelCase					=			torch.mean(torch.abs(lowercase_ ) )

												assert abs(result_mean.item() - 0.2464 ) < 1E-3






						def      UpperCAmelCase__					( self			:Optional[int] )    ->      str:
												UpperCAmelCase					=			self.full_loop(prediction_type='v_prediction' )
												UpperCAmelCase					=			torch.mean(torch.abs(lowercase_ ) )

												assert abs(result_mean.item() - 0.1014 ) < 1E-3






						def      UpperCAmelCase__					( self			:Tuple )    ->      Tuple:
												UpperCAmelCase					=			self.scheduler_classes[0]
												UpperCAmelCase					=			self.get_scheduler_config(thresholding=lowercase_       ,  dynamic_thresholding_ratio=0 )
												UpperCAmelCase					=			scheduler_class(**lowercase_ )

												UpperCAmelCase					=			10
												UpperCAmelCase					=			self.dummy_model()
												UpperCAmelCase					=			self.dummy_sample_deter.half()
												scheduler.set_timesteps(lowercase_ )

												for i, t in enumerate(scheduler.timesteps ):
																		UpperCAmelCase					=			model(lowercase_       ,  lowercase_ )
																		UpperCAmelCase					=			scheduler.step(lowercase_       ,  lowercase_       ,  lowercase_ ).prev_sample

												assert sample.dtype == torch.floataa






						def      UpperCAmelCase__					( self			:List[Any]       ,  **lowercase_			:Optional[Any] )    ->      Dict:
												for scheduler_class in self.scheduler_classes:
																		UpperCAmelCase					=			self.get_scheduler_config(**lowercase_ )
																		UpperCAmelCase					=			scheduler_class(**lowercase_ )

																		scheduler.set_timesteps(scheduler.config.num_train_timesteps )
																		assert len(scheduler.timesteps.unique() ) == scheduler.num_inference_steps





