import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding




class    _UpperCamelCase      (						_UpperCAmelCase ):


			"""simple docstring"""






			__a  : Tuple			 =						['''image_processor''', '''tokenizer''']
			__a  : List[Any]			 =						'''ChineseCLIPImageProcessor'''
			__a  : Any			 =						('''BertTokenizer''', '''BertTokenizerFast''')





			def __init__(   self      ,   lowerCAmelCase__=None      ,   lowerCAmelCase__=None      ,   **lowerCAmelCase__						)     ->					Union[str, Any]:

							'''simple docstring'''


							__lowercase 			=							None
							if "feature_extractor" in kwargs:
											warnings.warn(
											    '''The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'''
											    ''' instead.'''      ,   lowerCAmelCase__      ,   )
											__lowercase 			=							kwargs.pop('''feature_extractor'''						)

							__lowercase 			=							image_processor if image_processor is not None else feature_extractor
							if image_processor is None:
											raise ValueError('''You need to specify an `image_processor`.'''						)
							if tokenizer is None:
											raise ValueError('''You need to specify a `tokenizer`.'''						)

							super().__init__(lowerCAmelCase__      ,   lowerCAmelCase__						)
							__lowercase 			=							self.image_processor





			def __call__(   self      ,   lowerCAmelCase__=None      ,   lowerCAmelCase__=None      ,   lowerCAmelCase__=None      ,   **lowerCAmelCase__						)     ->					List[Any]:

							'''simple docstring'''


							if text is None and images is None:
											raise ValueError('''You have to specify either text or images. Both cannot be none.'''						)

							if text is not None:
											__lowercase 			=							self.tokenizer(lowerCAmelCase__      ,   return_tensors=lowerCAmelCase__      ,   **lowerCAmelCase__						)

							if images is not None:
											__lowercase 			=							self.image_processor(lowerCAmelCase__      ,   return_tensors=lowerCAmelCase__      ,   **lowerCAmelCase__						)

							if text is not None and images is not None:
											__lowercase 			=							image_features.pixel_values
											return encoding
							elif text is not None:
											return encoding
							else:
											return BatchEncoding(data=dict(**lowerCAmelCase__						)      ,   tensor_type=lowerCAmelCase__						)





			def        _SCREAMING_SNAKE_CASE			(   self      ,   *lowerCAmelCase__      ,   **lowerCAmelCase__						)     ->					List[Any]:

							'''simple docstring'''


							return self.tokenizer.batch_decode(*lowerCAmelCase__      ,   **lowerCAmelCase__						)





			def        _SCREAMING_SNAKE_CASE			(   self      ,   *lowerCAmelCase__      ,   **lowerCAmelCase__						)     ->					Optional[int]:

							'''simple docstring'''


							return self.tokenizer.decode(*lowerCAmelCase__      ,   **lowerCAmelCase__						)





			@property
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Optional[Any]:

							'''simple docstring'''


							__lowercase 			=							self.tokenizer.model_input_names
							__lowercase 			=							self.image_processor.model_input_names
							return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names						)						)





			@property
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					str:

							'''simple docstring'''


							warnings.warn(
							    '''`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'''      ,   lowerCAmelCase__      ,   )
							return self.image_processor_class
import torch

from diffusers import KDPMaDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest




class    _UpperCamelCase      (						_UpperCAmelCase ):


			"""simple docstring"""






			__a  : Optional[Any]			 =						(KDPMaDiscreteScheduler,)
			__a  : Dict			 =						10





			def        _SCREAMING_SNAKE_CASE			(   self      ,   **lowerCAmelCase__						)     ->					int:

							'''simple docstring'''


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

							config.update(**lowerCAmelCase__						)
							return config





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

							'''simple docstring'''


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





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Any:

							'''simple docstring'''


							for beta_start, beta_end in zip([0.0_0001, 0.0001, 0.001]      ,   [0.0002, 0.002, 0.02]						):
											self.check_over_configs(beta_start=lowerCAmelCase__      ,   beta_end=lowerCAmelCase__						)





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

							'''simple docstring'''


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





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

							'''simple docstring'''


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





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Tuple:

							'''simple docstring'''


							__lowercase 			=							self.scheduler_classes[0]
							__lowercase 			=							self.get_scheduler_config(prediction_type='''v_prediction'''						)
							__lowercase 			=							scheduler_class(**lowerCAmelCase__						)

							scheduler.set_timesteps(self.num_inference_steps						)

							__lowercase 			=							self.dummy_model()
							__lowercase 			=							self.dummy_sample_deter * scheduler.init_noise_sigma
							__lowercase 			=							sample.to(lowerCAmelCase__						)

							for i, t in enumerate(scheduler.timesteps						):
											__lowercase 			=							scheduler.scale_model_input(lowerCAmelCase__      ,   lowerCAmelCase__						)

											__lowercase 			=							model(lowerCAmelCase__      ,   lowerCAmelCase__						)

											__lowercase 			=							scheduler.step(lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__						)
											__lowercase 			=							output.prev_sample

							__lowercase 			=							torch.sum(torch.abs(lowerCAmelCase__						)						)
							__lowercase 			=							torch.mean(torch.abs(lowerCAmelCase__						)						)

							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        _SCREAMING_SNAKE_CASE			(   self						)     ->					str:

							'''simple docstring'''


							if torch_device == "mps":
											return
							__lowercase 			=							self.scheduler_classes[0]
							__lowercase 			=							self.get_scheduler_config()
							__lowercase 			=							scheduler_class(**lowerCAmelCase__						)

							scheduler.set_timesteps(self.num_inference_steps						)

							__lowercase 			=							self.dummy_model()
							__lowercase 			=							self.dummy_sample_deter * scheduler.init_noise_sigma
							__lowercase 			=							sample.to(lowerCAmelCase__						)

							for i, t in enumerate(scheduler.timesteps						):
											__lowercase 			=							scheduler.scale_model_input(lowerCAmelCase__      ,   lowerCAmelCase__						)

											__lowercase 			=							model(lowerCAmelCase__      ,   lowerCAmelCase__						)

											__lowercase 			=							scheduler.step(lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__						)
											__lowercase 			=							output.prev_sample

							__lowercase 			=							torch.sum(torch.abs(lowerCAmelCase__						)						)
							__lowercase 			=							torch.mean(torch.abs(lowerCAmelCase__						)						)

							if torch_device in ["cpu", "mps"]:
											assert abs(result_sum.item() - 20.4125						) < 1E-2
											assert abs(result_mean.item() - 0.0266						) < 1E-3
							else:
											# CUDA
											assert abs(result_sum.item() - 20.4125						) < 1E-2
											assert abs(result_mean.item() - 0.0266						) < 1E-3





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Dict:

							'''simple docstring'''


							if torch_device == "mps":
											return
							__lowercase 			=							self.scheduler_classes[0]
							__lowercase 			=							self.get_scheduler_config()
							__lowercase 			=							scheduler_class(**lowerCAmelCase__						)

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

							__lowercase 			=							self.dummy_model()
							__lowercase 			=							self.dummy_sample_deter.to(lowerCAmelCase__						) * scheduler.init_noise_sigma

							for t in scheduler.timesteps:
											__lowercase 			=							scheduler.scale_model_input(lowerCAmelCase__      ,   lowerCAmelCase__						)

											__lowercase 			=							model(lowerCAmelCase__      ,   lowerCAmelCase__						)

											__lowercase 			=							scheduler.step(lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__						)
											__lowercase 			=							output.prev_sample

							__lowercase 			=							torch.sum(torch.abs(lowerCAmelCase__						)						)
							__lowercase 			=							torch.mean(torch.abs(lowerCAmelCase__						)						)

							if str(lowerCAmelCase__						).startswith('''cpu'''						):
											# The following sum varies between 148 and 156 on mps. Why?
											assert abs(result_sum.item() - 20.4125						) < 1E-2
											assert abs(result_mean.item() - 0.0266						) < 1E-3
							else:
											# CUDA
											assert abs(result_sum.item() - 20.4125						) < 1E-2
											assert abs(result_mean.item() - 0.0266						) < 1E-3