






'''simple docstring'''



import inspect
import unittest
from math import floor

from transformers import CvtConfig
from transformers.file_utils import cached_property, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision, slow, torch_device

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 CvtForImageClassification, CvtModel
      from transformers.models.cvt.modeling_cvt import CVT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
      from PIL import Image

      from transformers import AutoImageProcessor
class UpperCAmelCase_       (     __A					):




      """simple docstring"""




      def 					A__   (			self      :		Tuple		)	->	List[str]:


       '''simple docstring'''

       lowercase       : Any						=self.config_class(**self.inputs_dict		)
       self.parent.assertTrue(hasattr(UpperCAmelCase  ,   '''embed_dim'''		)		)
       self.parent.assertTrue(hasattr(UpperCAmelCase  ,   '''num_heads'''		)		)





class UpperCAmelCase_       :




      """simple docstring"""




      def __init__(			self      :		Any  ,   UpperCAmelCase      :		Optional[int]  ,   UpperCAmelCase      :		Any=13  ,   UpperCAmelCase      :		Tuple=64  ,   UpperCAmelCase      :		int=3  ,   UpperCAmelCase      :		Dict=[16, 48, 96]  ,   UpperCAmelCase      :		Tuple=[1, 3, 6]  ,   UpperCAmelCase      :		Optional[int]=[1, 2, 10]  ,   UpperCAmelCase      :		List[str]=[7, 3, 3]  ,   UpperCAmelCase      :		Any=[4, 2, 2]  ,   UpperCAmelCase      :		Dict=[2, 1, 1]  ,   UpperCAmelCase      :		int=[2, 2, 2]  ,   UpperCAmelCase      :		str=[False, False, True]  ,   UpperCAmelCase      :		Tuple=[0.0, 0.0, 0.0]  ,   UpperCAmelCase      :		str=0.0_2  ,   UpperCAmelCase      :		Any=1e-12  ,   UpperCAmelCase      :		List[Any]=True  ,   UpperCAmelCase      :		Dict=True  ,   UpperCAmelCase      :		Optional[Any]=2  ,   )	->	List[str]:


       '''simple docstring'''

       lowercase       : int						=parent
       lowercase       : Tuple						=batch_size
       lowercase       : Optional[int]						=image_size
       lowercase       : Optional[Any]						=patch_sizes
       lowercase       : int						=patch_stride
       lowercase       : Optional[int]						=patch_padding
       lowercase       : Tuple						=is_training
       lowercase       : Union[str, Any]						=use_labels
       lowercase       : Optional[Any]						=num_labels
       lowercase       : Any						=num_channels
       lowercase       : Tuple						=embed_dim
       lowercase       : int						=num_heads
       lowercase       : Optional[Any]						=stride_kv
       lowercase       : List[str]						=depth
       lowercase       : Dict						=cls_token
       lowercase       : Dict						=attention_drop_rate
       lowercase       : List[Any]						=initializer_range
       lowercase       : Optional[int]						=layer_norm_eps






      def 					A__   (			self      :		str		)	->	List[Any]:


       '''simple docstring'''

       lowercase       : str						=floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

       lowercase       : List[Any]						=None
       if self.use_labels:
        lowercase       : List[str]						=ids_tensor([self.batch_size]  ,   self.num_labels		)

       lowercase       : int						=self.get_config()
       return config, pixel_values, labels






      def 					A__   (			self      :		Optional[int]		)	->	Optional[Any]:


       '''simple docstring'''

       return CvtConfig(
           image_size=self.image_size  ,   num_labels=self.num_labels  ,   num_channels=self.num_channels  ,   embed_dim=self.embed_dim  ,   num_heads=self.num_heads  ,   patch_sizes=self.patch_sizes  ,   patch_padding=self.patch_padding  ,   patch_stride=self.patch_stride  ,   stride_kv=self.stride_kv  ,   depth=self.depth  ,   cls_token=self.cls_token  ,   attention_drop_rate=self.attention_drop_rate  ,   initializer_range=self.initializer_range  ,   )






      def 					A__   (			self      :		List[Any]  ,   UpperCAmelCase      :		int  ,   UpperCAmelCase      :		List[str]  ,   UpperCAmelCase      :		Optional[Any]		)	->	List[Any]:


       '''simple docstring'''

       lowercase       : str						=CvtModel(config=UpperCAmelCase		)
       model.to(UpperCAmelCase		)
       model.eval()
       lowercase       : Optional[int]						=model(UpperCAmelCase		)
       lowercase       : str						=(self.image_size, self.image_size)
       lowercase	,		lowercase       : Any						=image_size[0], image_size[1]
       for i in range(len(self.depth		)		):
        lowercase       : str						=floor(((height + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1		)
        lowercase       : str						=floor(((width + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1		)
       self.parent.assertEqual(result.last_hidden_state.shape  ,   (self.batch_size, self.embed_dim[-1], height, width)		)






      def 					A__   (			self      :		List[Any]  ,   UpperCAmelCase      :		Any  ,   UpperCAmelCase      :		List[str]  ,   UpperCAmelCase      :		Tuple		)	->	str:


       '''simple docstring'''

       lowercase       : List[Any]						=self.num_labels
       lowercase       : str						=CvtForImageClassification(UpperCAmelCase		)
       model.to(UpperCAmelCase		)
       model.eval()
       lowercase       : int						=model(UpperCAmelCase  ,   labels=UpperCAmelCase		)
       self.parent.assertEqual(result.logits.shape  ,   (self.batch_size, self.num_labels)		)






      def 					A__   (			self      :		Any		)	->	Any:


       '''simple docstring'''

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





@require_torch
class UpperCAmelCase_       (     __A					,							__A					,							unittest.TestCase					):




      """simple docstring"""




      UpperCamelCase_             =      (CvtModel, CvtForImageClassification) if is_torch_available() else ()
      UpperCamelCase_             =      (
          {'''feature-extraction''': CvtModel, '''image-classification''': CvtForImageClassification}
          if is_torch_available()
          else {}
      )

      UpperCamelCase_             =      False
      UpperCamelCase_             =      False
      UpperCamelCase_             =      False
      UpperCamelCase_             =      False
      UpperCamelCase_             =      False






      def 					A__   (			self      :		Any		)	->	List[str]:


       '''simple docstring'''

       lowercase       : int						=CvtModelTester(self		)
       lowercase       : str						=ConfigTester(self  ,   config_class=UpperCAmelCase  ,   has_text_modality=UpperCAmelCase  ,   hidden_size=37		)






      def 					A__   (			self      :		Tuple		)	->	Tuple:


       '''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 					A__   (			self      :		Dict		)	->	Tuple:


       '''simple docstring'''

       return






      @unittest.skip(reason='''Cvt does not output attentions'''		)
      def 					A__   (			self      :		Union[str, Any]		)	->	Dict:


       '''simple docstring'''

       pass






      @unittest.skip(reason='''Cvt does not use inputs_embeds'''		)
      def 					A__   (			self      :		str		)	->	int:


       '''simple docstring'''

       pass






      @unittest.skip(reason='''Cvt does not support input and output embeddings'''		)
      def 					A__   (			self      :		Any		)	->	Dict:


       '''simple docstring'''

       pass






      def 					A__   (			self      :		List[str]		)	->	int:


       '''simple docstring'''

       lowercase	,		lowercase       : int						=self.model_tester.prepare_config_and_inputs_for_common()

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

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






      def 					A__   (			self      :		str		)	->	Dict:


       '''simple docstring'''

       lowercase       : str						=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*UpperCAmelCase		)






      def 					A__   (			self      :		Tuple		)	->	int:


       '''simple docstring'''

       def check_hidden_states_output(UpperCAmelCase      :		str  ,   UpperCAmelCase      :		Optional[int]  ,   UpperCAmelCase      :		List[Any]		):
        lowercase       : List[str]						=model_class(UpperCAmelCase		)
        model.to(UpperCAmelCase		)
        model.eval()

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

        lowercase       : List[str]						=outputs.hidden_states

        lowercase       : str						=len(self.model_tester.depth		)
        self.assertEqual(len(UpperCAmelCase		)  ,   UpperCAmelCase		)

        # verify the first hidden states (first block)
        self.assertListEqual(
            list(hidden_states[0].shape[-3:]		)  ,   [
                self.model_tester.embed_dim[0],
                self.model_tester.image_size // 4,
                self.model_tester.image_size // 4,
            ]  ,   )

       lowercase	,		lowercase       : str						=self.model_tester.prepare_config_and_inputs_for_common()

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

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

        check_hidden_states_output(UpperCAmelCase  ,   UpperCAmelCase  ,   UpperCAmelCase		)






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


       '''simple docstring'''

       lowercase       : Union[str, Any]						=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_classification(*UpperCAmelCase		)






      @unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''		)
      def 					A__   (			self      :		Tuple		)	->	Any:


       '''simple docstring'''

       pass






      @slow
      def 					A__   (			self      :		Dict		)	->	Tuple:


       '''simple docstring'''

       for model_name in CVT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        lowercase       : List[str]						=CvtModel.from_pretrained(UpperCAmelCase		)
        self.assertIsNotNone(UpperCAmelCase		)





def 				lowercase_					(     )							->   List[str]:



 """simple docstring"""




 lowercase       : Tuple						=Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''      )
 return image





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




      """simple docstring"""




      @cached_property
      def 					A__   (			self      :		Union[str, Any]		)	->	Any:


       '''simple docstring'''

       return AutoImageProcessor.from_pretrained(CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]		)






      @slow
      def 					A__   (			self      :		Optional[Any]		)	->	Union[str, Any]:


       '''simple docstring'''

       lowercase       : Any						=CvtForImageClassification.from_pretrained(CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]		).to(UpperCAmelCase		)

       lowercase       : Tuple						=self.default_image_processor
       lowercase       : str						=prepare_img()
       lowercase       : List[str]						=image_processor(images=UpperCAmelCase  ,   return_tensors='''pt'''		).to(UpperCAmelCase		)

       # forward pass
       with torch.no_grad():
        lowercase       : Optional[Any]						=model(**UpperCAmelCase		)

       # verify the logits
       lowercase       : List[str]						=torch.Size((1, 1000)		)
       self.assertEqual(outputs.logits.shape  ,   UpperCAmelCase		)

       lowercase       : Optional[int]						=torch.tensor([0.9_2_8_5, 0.9_0_1_5, -0.3_1_5_0]		).to(UpperCAmelCase		)

       self.assertTrue(torch.allclose(outputs.logits[0, :3]  ,   UpperCAmelCase  ,   atol=1e-4		)		)










import gc
import unittest

import numpy as np
import torch
from torch.backends.cuda import sdp_kernel

from diffusers import (
    CMStochasticIterativeScheduler,
    ConsistencyModelPipeline,
    UNetaDModel,
)
from diffusers.utils import randn_tensor, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_a, require_torch_gpu

from ..pipeline_params import UNCONDITIONAL_IMAGE_GENERATION_BATCH_PARAMS, UNCONDITIONAL_IMAGE_GENERATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()





class 				a			(      __lowercase   ,unittest.TestCase			):
				SCREAMING_SNAKE_CASE__     :   List[Any]		      =     ConsistencyModelPipeline
				SCREAMING_SNAKE_CASE__     :   Any		      =     UNCONDITIONAL_IMAGE_GENERATION_PARAMS
				SCREAMING_SNAKE_CASE__     :   str		      =     UNCONDITIONAL_IMAGE_GENERATION_BATCH_PARAMS

				# Override required_optional_params to remove num_images_per_prompt
				SCREAMING_SNAKE_CASE__     :   Optional[int]		      =     frozenset(
				    [
				        '''num_inference_steps''',
				        '''generator''',
				        '''latents''',
				        '''output_type''',
				        '''return_dict''',
				        '''callback''',
				        '''callback_steps''',
				    ]			)






				@property
				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				int           =   UNetaDModel.from_pretrained(
										    '''diffusers/consistency-models-test'''			, subfolder='''test_unet'''			, )
										return unet






				@property
				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				List[Any]           =   UNetaDModel.from_pretrained(
										    '''diffusers/consistency-models-test'''			, subfolder='''test_unet_class_cond'''			, )
										return unet






				def 			snake_case_    (  self			, _lowerCAmelCase=False					):

										"""simple docstring"""




										if class_cond:
																__SCREAMING_SNAKE_CASE:				List[Any]           =   self.dummy_cond_unet
										else:
																__SCREAMING_SNAKE_CASE:				Tuple           =   self.dummy_uncond_unet

										# Default to CM multistep sampler
										__SCREAMING_SNAKE_CASE:				Tuple           =   CMStochasticIterativeScheduler(
										    num_train_timesteps=40			, sigma_min=0.002			, sigma_max=80.0			, )

										__SCREAMING_SNAKE_CASE:				List[str]           =   {
										    '''unet''': unet,
										    '''scheduler''': scheduler,
										}

										return components






				def 			snake_case_    (  self			, _lowerCAmelCase			, _lowerCAmelCase=0					):

										"""simple docstring"""




										if str(_lowerCAmelCase					).startswith('''mps'''					):
																__SCREAMING_SNAKE_CASE:				List[str]           =   torch.manual_seed(_lowerCAmelCase					)
										else:
																__SCREAMING_SNAKE_CASE:				List[str]           =   torch.Generator(device=_lowerCAmelCase					).manual_seed(_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   {
										    '''batch_size''': 1,
										    '''num_inference_steps''': None,
										    '''timesteps''': [22, 0],
										    '''generator''': generator,
										    '''output_type''': '''np''',
										}

										return inputs






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Dict           =   '''cpu'''  # ensure determinism for the device-dependent torch.Generator
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   self.get_dummy_components()
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   ConsistencyModelPipeline(**_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Any           =   pipe.to(_lowerCAmelCase					)
										pipe.set_progress_bar_config(disable=_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				Optional[int]           =   self.get_dummy_inputs(_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Any           =   pipe(**_lowerCAmelCase					).images
										assert image.shape == (1, 32, 32, 3)

										__SCREAMING_SNAKE_CASE:				int           =   image[0, -3:, -3:, -1]
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   np.array([0.3572, 0.6273, 0.4031, 0.3961, 0.4321, 0.5730, 0.5266, 0.4780, 0.5004]					)

										assert np.abs(image_slice.flatten() - expected_slice					).max() < 1e-3






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Dict           =   '''cpu'''  # ensure determinism for the device-dependent torch.Generator
										__SCREAMING_SNAKE_CASE:				str           =   self.get_dummy_components(class_cond=_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Any           =   ConsistencyModelPipeline(**_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Any           =   pipe.to(_lowerCAmelCase					)
										pipe.set_progress_bar_config(disable=_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				Dict           =   self.get_dummy_inputs(_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Dict           =   0
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   pipe(**_lowerCAmelCase					).images
										assert image.shape == (1, 32, 32, 3)

										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   image[0, -3:, -3:, -1]
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   np.array([0.3572, 0.6273, 0.4031, 0.3961, 0.4321, 0.5730, 0.5266, 0.4780, 0.5004]					)

										assert np.abs(image_slice.flatten() - expected_slice					).max() < 1e-3






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Optional[int]           =   '''cpu'''  # ensure determinism for the device-dependent torch.Generator
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   self.get_dummy_components()
										__SCREAMING_SNAKE_CASE:				Tuple           =   ConsistencyModelPipeline(**_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				List[str]           =   pipe.to(_lowerCAmelCase					)
										pipe.set_progress_bar_config(disable=_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				List[Any]           =   self.get_dummy_inputs(_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				int           =   1
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   None
										__SCREAMING_SNAKE_CASE:				List[str]           =   pipe(**_lowerCAmelCase					).images
										assert image.shape == (1, 32, 32, 3)

										__SCREAMING_SNAKE_CASE:				Tuple           =   image[0, -3:, -3:, -1]
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   np.array([0.5004, 0.5004, 0.4994, 0.5008, 0.4976, 0.5018, 0.4990, 0.4982, 0.4987]					)

										assert np.abs(image_slice.flatten() - expected_slice					).max() < 1e-3






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				int           =   '''cpu'''  # ensure determinism for the device-dependent torch.Generator
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   self.get_dummy_components(class_cond=_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				List[Any]           =   ConsistencyModelPipeline(**_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				List[Any]           =   pipe.to(_lowerCAmelCase					)
										pipe.set_progress_bar_config(disable=_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				Tuple           =   self.get_dummy_inputs(_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Any           =   1
										__SCREAMING_SNAKE_CASE:				List[Any]           =   None
										__SCREAMING_SNAKE_CASE:				Tuple           =   0
										__SCREAMING_SNAKE_CASE:				List[str]           =   pipe(**_lowerCAmelCase					).images
										assert image.shape == (1, 32, 32, 3)

										__SCREAMING_SNAKE_CASE:				List[Any]           =   image[0, -3:, -3:, -1]
										__SCREAMING_SNAKE_CASE:				Any           =   np.array([0.5004, 0.5004, 0.4994, 0.5008, 0.4976, 0.5018, 0.4990, 0.4982, 0.4987]					)

										assert np.abs(image_slice.flatten() - expected_slice					).max() < 1e-3





@slow
@require_torch_gpu
class 				a			(      unittest.TestCase			):






				def 			snake_case_    (  self					):

										"""simple docstring"""




										super().tearDown()
										gc.collect()
										torch.cuda.empty_cache()






				def 			snake_case_    (  self			, _lowerCAmelCase=0			, _lowerCAmelCase=False			, _lowerCAmelCase="cpu"			, _lowerCAmelCase=torch.floataa			, _lowerCAmelCase=(1, 3, 64, 64)					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				str           =   torch.manual_seed(_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				Dict           =   {
										    '''num_inference_steps''': None,
										    '''timesteps''': [22, 0],
										    '''class_labels''': 0,
										    '''generator''': generator,
										    '''output_type''': '''np''',
										}

										if get_fixed_latents:
																__SCREAMING_SNAKE_CASE:				Dict           =   self.get_fixed_latents(seed=_lowerCAmelCase			, device=_lowerCAmelCase			, dtype=_lowerCAmelCase			, shape=_lowerCAmelCase					)
																__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   latents

										return inputs






				def 			snake_case_    (  self			, _lowerCAmelCase=0			, _lowerCAmelCase="cpu"			, _lowerCAmelCase=torch.floataa			, _lowerCAmelCase=(1, 3, 64, 64)					):

										"""simple docstring"""




										if type(_lowerCAmelCase					) == str:
																__SCREAMING_SNAKE_CASE:				List[Any]           =   torch.device(_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Dict           =   torch.Generator(device=_lowerCAmelCase					).manual_seed(_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				int           =   randn_tensor(_lowerCAmelCase			, generator=_lowerCAmelCase			, device=_lowerCAmelCase			, dtype=_lowerCAmelCase					)
										return latents






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   UNetaDModel.from_pretrained('''diffusers/consistency_models'''			, subfolder='''diffusers_cd_imagenet64_l2'''					)
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   CMStochasticIterativeScheduler(
										    num_train_timesteps=40			, sigma_min=0.002			, sigma_max=80.0			, )
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   ConsistencyModelPipeline(unet=_lowerCAmelCase			, scheduler=_lowerCAmelCase					)
										pipe.to(torch_device=_lowerCAmelCase					)
										pipe.set_progress_bar_config(disable=_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				int           =   self.get_inputs()
										__SCREAMING_SNAKE_CASE:				List[Any]           =   pipe(**_lowerCAmelCase					).images
										assert image.shape == (1, 64, 64, 3)

										__SCREAMING_SNAKE_CASE:				Dict           =   image[0, -3:, -3:, -1]

										__SCREAMING_SNAKE_CASE:				Any           =   np.array([0.0888, 0.0881, 0.0666, 0.0479, 0.0292, 0.0195, 0.0201, 0.0163, 0.0254]					)

										assert np.abs(image_slice.flatten() - expected_slice					).max() < 2e-2






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				List[Any]           =   UNetaDModel.from_pretrained('''diffusers/consistency_models'''			, subfolder='''diffusers_cd_imagenet64_l2'''					)
										__SCREAMING_SNAKE_CASE:				str           =   CMStochasticIterativeScheduler(
										    num_train_timesteps=40			, sigma_min=0.002			, sigma_max=80.0			, )
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   ConsistencyModelPipeline(unet=_lowerCAmelCase			, scheduler=_lowerCAmelCase					)
										pipe.to(torch_device=_lowerCAmelCase					)
										pipe.set_progress_bar_config(disable=_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				List[str]           =   self.get_inputs()
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   1
										__SCREAMING_SNAKE_CASE:				List[Any]           =   None
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   pipe(**_lowerCAmelCase					).images
										assert image.shape == (1, 64, 64, 3)

										__SCREAMING_SNAKE_CASE:				Dict           =   image[0, -3:, -3:, -1]

										__SCREAMING_SNAKE_CASE:				Any           =   np.array([0.0340, 0.0152, 0.0063, 0.0267, 0.0221, 0.0107, 0.0416, 0.0186, 0.0217]					)

										assert np.abs(image_slice.flatten() - expected_slice					).max() < 2e-2






				@require_torch_a
				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Tuple           =   UNetaDModel.from_pretrained('''diffusers/consistency_models'''			, subfolder='''diffusers_cd_imagenet64_l2'''					)
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   CMStochasticIterativeScheduler(
										    num_train_timesteps=40			, sigma_min=0.002			, sigma_max=80.0			, )
										__SCREAMING_SNAKE_CASE:				List[Any]           =   ConsistencyModelPipeline(unet=_lowerCAmelCase			, scheduler=_lowerCAmelCase					)
										pipe.to(torch_device=_lowerCAmelCase			, torch_dtype=torch.floataa					)
										pipe.set_progress_bar_config(disable=_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				int           =   self.get_inputs(get_fixed_latents=_lowerCAmelCase			, device=_lowerCAmelCase					)
										# Ensure usage of flash attention in torch 2.0
										with sdp_kernel(enable_flash=_lowerCAmelCase			, enable_math=_lowerCAmelCase			, enable_mem_efficient=_lowerCAmelCase					):
																__SCREAMING_SNAKE_CASE:				Dict           =   pipe(**_lowerCAmelCase					).images
										assert image.shape == (1, 64, 64, 3)

										__SCREAMING_SNAKE_CASE:				List[Any]           =   image[0, -3:, -3:, -1]

										__SCREAMING_SNAKE_CASE:				Optional[int]           =   np.array([0.1875, 0.1428, 0.1289, 0.2151, 0.2092, 0.1477, 0.1877, 0.1641, 0.1353]					)

										assert np.abs(image_slice.flatten() - expected_slice					).max() < 1e-3






				@require_torch_a
				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   UNetaDModel.from_pretrained('''diffusers/consistency_models'''			, subfolder='''diffusers_cd_imagenet64_l2'''					)
										__SCREAMING_SNAKE_CASE:				List[str]           =   CMStochasticIterativeScheduler(
										    num_train_timesteps=40			, sigma_min=0.002			, sigma_max=80.0			, )
										__SCREAMING_SNAKE_CASE:				List[Any]           =   ConsistencyModelPipeline(unet=_lowerCAmelCase			, scheduler=_lowerCAmelCase					)
										pipe.to(torch_device=_lowerCAmelCase			, torch_dtype=torch.floataa					)
										pipe.set_progress_bar_config(disable=_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				int           =   self.get_inputs(get_fixed_latents=_lowerCAmelCase			, device=_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   1
										__SCREAMING_SNAKE_CASE:				List[Any]           =   None
										# Ensure usage of flash attention in torch 2.0
										with sdp_kernel(enable_flash=_lowerCAmelCase			, enable_math=_lowerCAmelCase			, enable_mem_efficient=_lowerCAmelCase					):
																__SCREAMING_SNAKE_CASE:				Optional[int]           =   pipe(**_lowerCAmelCase					).images
										assert image.shape == (1, 64, 64, 3)

										__SCREAMING_SNAKE_CASE:				Tuple           =   image[0, -3:, -3:, -1]

										__SCREAMING_SNAKE_CASE:				Tuple           =   np.array([0.1663, 0.1948, 0.2275, 0.1680, 0.1204, 0.1245, 0.1858, 0.1338, 0.2095]					)

										assert np.abs(image_slice.flatten() - expected_slice					).max() < 1e-3



