






"""simple docstring"""




import unittest

import numpy as np
import torch
from torch import nn
from transformers import (
    CLIPImageProcessor,
    CLIPTextConfig,
    CLIPTextModelWithProjection,
    CLIPTokenizer,
    CLIPVisionConfig,
    CLIPVisionModelWithProjection,
)

from diffusers import KandinskyVaaPriorPipeline, PriorTransformer, UnCLIPScheduler
from diffusers.utils import torch_device
from diffusers.utils.testing_utils import enable_full_determinism, skip_mps

from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()




class    lowercase_    (a__,    unittest.TestCase     ):
						A__	:		Optional[int]       			=				KandinskyVaaPriorPipeline
						A__	:		Optional[int]       			=				["""prompt"""]
						A__	:		Union[str, Any]       			=				["""prompt""", """negative_prompt"""]
						A__	:		Dict       			=				[
						    """num_images_per_prompt""",
						    """generator""",
						    """num_inference_steps""",
						    """latents""",
						    """negative_prompt""",
						    """guidance_scale""",
						    """output_type""",
						    """return_dict""",
						]
						A__	:		List[str]       			=				False






						@property
						def 			lowerCamelCase__    (    self	)	->Tuple:







								'''simple docstring'''


								return 3_2






						@property
						def 			lowerCamelCase__    (    self	)	->Tuple:







								'''simple docstring'''


								return 3_2






						@property
						def 			lowerCamelCase__    (    self	)	->List[str]:







								'''simple docstring'''


								return self.time_input_dim






						@property
						def 			lowerCamelCase__    (    self	)	->List[str]:







								'''simple docstring'''


								return self.time_input_dim * 4






						@property
						def 			lowerCamelCase__    (    self	)	->Tuple:







								'''simple docstring'''


								return 1_0_0






						@property
						def 			lowerCamelCase__    (    self	)	->str:







								'''simple docstring'''


								_a							=	CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"	)
								return tokenizer






						@property
						def 			lowerCamelCase__    (    self	)	->Union[str, Any]:







								'''simple docstring'''


								torch.manual_seed(0	)
								_a							=	CLIPTextConfig(
								    bos_token_id=0     ,     eos_token_id=2     ,     hidden_size=self.text_embedder_hidden_size     ,     projection_dim=self.text_embedder_hidden_size     ,     intermediate_size=3_7     ,     layer_norm_eps=1E-05     ,     num_attention_heads=4     ,     num_hidden_layers=5     ,     pad_token_id=1     ,     vocab_size=1_0_0_0     ,     )
								return CLIPTextModelWithProjection(lowercase__	)






						@property
						def 			lowerCamelCase__    (    self	)	->List[str]:







								'''simple docstring'''


								torch.manual_seed(0	)

								_a							=	{
								    '''num_attention_heads''': 2,
								    '''attention_head_dim''': 1_2,
								    '''embedding_dim''': self.text_embedder_hidden_size,
								    '''num_layers''': 1,
								}

								_a							=	PriorTransformer(**lowercase__	)
								# clip_std and clip_mean is initialized to be 0 so PriorTransformer.post_process_latents will always return 0 - set clip_std to be 1 so it won't return 0
								_a							=	nn.Parameter(torch.ones(model.clip_std.shape	)	)
								return model






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







								'''simple docstring'''


								torch.manual_seed(0	)
								_a							=	CLIPVisionConfig(
								    hidden_size=self.text_embedder_hidden_size     ,     image_size=2_2_4     ,     projection_dim=self.text_embedder_hidden_size     ,     intermediate_size=3_7     ,     num_attention_heads=4     ,     num_channels=3     ,     num_hidden_layers=5     ,     patch_size=1_4     ,     )

								_a							=	CLIPVisionModelWithProjection(lowercase__	)
								return model






						@property
						def 			lowerCamelCase__    (    self	)	->List[Any]:







								'''simple docstring'''


								_a							=	CLIPImageProcessor(
								    crop_size=2_2_4     ,     do_center_crop=lowercase__     ,     do_normalize=lowercase__     ,     do_resize=lowercase__     ,     image_mean=[0.48_145_466, 0.4_578_275, 0.40_821_073]     ,     image_std=[0.26_862_954, 0.26_130_258, 0.27_577_711]     ,     resample=3     ,     size=2_2_4     ,     )

								return image_processor






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







								'''simple docstring'''


								_a							=	self.dummy_prior
								_a							=	self.dummy_image_encoder
								_a							=	self.dummy_text_encoder
								_a							=	self.dummy_tokenizer
								_a							=	self.dummy_image_processor

								_a							=	UnCLIPScheduler(
								    variance_type="fixed_small_log"     ,     prediction_type="sample"     ,     num_train_timesteps=1_0_0_0     ,     clip_sample=lowercase__     ,     clip_sample_range=10.0     ,     )

								_a							=	{
								    '''prior''': prior,
								    '''image_encoder''': image_encoder,
								    '''text_encoder''': text_encoder,
								    '''tokenizer''': tokenizer,
								    '''scheduler''': scheduler,
								    '''image_processor''': image_processor,
								}

								return components






						def 			lowerCamelCase__    (    self     ,     a_     ,     a_=0	)	->List[str]:







								'''simple docstring'''


								if str(lowercase__	).startswith("mps"	):
										_a							=	torch.manual_seed(lowercase__	)
								else:
										_a							=	torch.Generator(device=lowercase__	).manual_seed(lowercase__	)
								_a							=	{
								    '''prompt''': '''horse''',
								    '''generator''': generator,
								    '''guidance_scale''': 4.0,
								    '''num_inference_steps''': 2,
								    '''output_type''': '''np''',
								}
								return inputs






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







								'''simple docstring'''


								_a							=	'''cpu'''

								_a							=	self.get_dummy_components()

								_a							=	self.pipeline_class(**lowercase__	)
								_a							=	pipe.to(lowercase__	)

								pipe.set_progress_bar_config(disable=lowercase__	)

								_a							=	pipe(**self.get_dummy_inputs(lowercase__	)	)
								_a							=	output.image_embeds

								_a							=	pipe(
								    **self.get_dummy_inputs(lowercase__	)     ,     return_dict=lowercase__     ,     )[0]

								_a							=	image[0, -1_0:]
								_a							=	image_from_tuple[0, -1_0:]

								assert image.shape == (1, 3_2)

								_a							=	np.array(
								    [-0.0_532, 1.7_120, 0.3_656, -1.0_852, -0.8_946, -1.1_756, 0.4_348, 0.2_482, 0.5_146, -0.1_156]	)

								assert np.abs(image_slice.flatten() - expected_slice	).max() < 1E-2
								assert np.abs(image_from_tuple_slice.flatten() - expected_slice	).max() < 1E-2






						@skip_mps
						def 			lowerCamelCase__    (    self	)	->int:







								'''simple docstring'''


								_a							=	torch_device == '''cpu'''
								_a							=	True
								_a							=	False

								self._test_inference_batch_single_identical(
								    test_max_difference=lowercase__     ,     relax_max_difference=lowercase__     ,     test_mean_pixel_difference=lowercase__     ,     )






						@skip_mps
						def 			lowerCamelCase__    (    self	)	->Optional[Any]:







								'''simple docstring'''


								_a							=	torch_device == '''cpu'''
								_a							=	False

								self._test_attention_slicing_forward_pass(
								    test_max_difference=lowercase__     ,     test_mean_pixel_difference=lowercase__     ,     )










"""simple docstring"""




import warnings

from ...utils import logging
from .image_processing_yolos import YolosImageProcessor


UpperCamelCase							       =    logging.get_logger(__name__)




class    lowercase_    (_UpperCAmelCase     ):






      def __init__(    self     ,     *a_     ,     **a_	)	->None:







        '''simple docstring'''


        warnings.warn(
            "The class YolosFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please"
            " use YolosImageProcessor instead."     ,     a_     ,     )
        super().__init__(*a_     ,     **a_	)


