

'''simple docstring'''


import unittest

from diffusers import __version__
from diffusers.utils import deprecate



class        lowercase    (	unittest.TestCase			):
							_lowerCamelCase		:   str= '.'.join([str(int(__version__.split("."			)[0]			) + 1			)] + __version__.split("."			)[1:]			)
							_lowerCamelCase		:   Any= '0.0.1'


							def     _snake_case				(      self)				->					List[Any]:
								UpperCAmelCase_		:   int													=       {'deprecated_arg': 4}

								with self.assertWarns(lowerCamelCase_) as warning:
									UpperCAmelCase_		:   Optional[int]													=       deprecate('deprecated_arg'     ,      self.higher_version     ,      'message'     ,      take_from=lowerCamelCase_)

								assert output == 4
								assert (
								    str(warning.warning)
								    == F"""The `deprecated_arg` argument is deprecated and will be removed in version {self.higher_version}."""
								    " message"
								)


							def     _snake_case				(      self)				->					int:
								UpperCAmelCase_		:   Optional[Any]													=       {'deprecated_arg': 4}

								with self.assertWarns(lowerCamelCase_) as warning:
									UpperCAmelCase_		:   int													=       deprecate(('deprecated_arg', self.higher_version, 'message')     ,      take_from=lowerCamelCase_)

								assert output == 4
								assert (
								    str(warning.warning)
								    == F"""The `deprecated_arg` argument is deprecated and will be removed in version {self.higher_version}."""
								    " message"
								)


							def     _snake_case				(      self)				->					Optional[int]:
								UpperCAmelCase_		:   Tuple													=       {'deprecated_arg_1': 4, 'deprecated_arg_2': 8}
								with self.assertWarns(lowerCamelCase_) as warning:
									UpperCAmelCase_		:   str													=       deprecate(
									    ('deprecated_arg_1', self.higher_version, 'Hey')     ,      ('deprecated_arg_2', self.higher_version, 'Hey')     ,      take_from=lowerCamelCase_     ,      )
								assert output_a == 4
								assert output_a == 8
								assert (
								    str(warning.warnings[0].message)
								    == "The `deprecated_arg_1` argument is deprecated and will be removed in version"
								    F""" {self.higher_version}. Hey"""
								)
								assert (
								    str(warning.warnings[1].message)
								    == "The `deprecated_arg_2` argument is deprecated and will be removed in version"
								    F""" {self.higher_version}. Hey"""
								)


							def     _snake_case				(      self)				->					Dict:
								UpperCAmelCase_		:   Optional[Any]													=       {'deprecated_arg': 4}

								with self.assertRaises(lowerCamelCase_) as error:
									deprecate(('wrong_arg', self.higher_version, 'message')     ,      take_from=lowerCamelCase_)

								assert "test_deprecate_function_incorrect_arg in" in str(error.exception)
								assert "line" in str(error.exception)
								assert "got an unexpected keyword argument `deprecated_arg`" in str(error.exception)


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



								with self.assertWarns(lowerCamelCase_) as warning:
									deprecate(('deprecated_arg', self.higher_version, 'message'))

								assert (
								    str(warning.warning)
								    == F"""`deprecated_arg` is deprecated and will be removed in version {self.higher_version}. message"""
								)


							def     _snake_case				(      self)				->					List[Any]:



								with self.assertWarns(lowerCamelCase_) as warning:
									deprecate(
									    ('deprecated_arg_1', self.higher_version, 'Hey')     ,      ('deprecated_arg_2', self.higher_version, 'Hey')     ,      )
								assert (
								    str(warning.warnings[0].message)
								    == F"""`deprecated_arg_1` is deprecated and will be removed in version {self.higher_version}. Hey"""
								)
								assert (
								    str(warning.warnings[1].message)
								    == F"""`deprecated_arg_2` is deprecated and will be removed in version {self.higher_version}. Hey"""
								)


							def     _snake_case				(      self)				->					Any:



								class        lowercase    :
															_lowerCamelCase		:   int= 5

								with self.assertWarns(lowerCamelCase_) as warning:
									UpperCAmelCase_		:   Optional[Any]													=       deprecate(('arg', self.higher_version, 'message')     ,      take_from=Args())

								assert arg == 5
								assert (
								    str(warning.warning)
								    == F"""The `arg` attribute is deprecated and will be removed in version {self.higher_version}. message"""
								)


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



								class        lowercase    :
															_lowerCamelCase		:   Optional[Any]= 5
															_lowerCamelCase		:   str= 7

								with self.assertWarns(lowerCamelCase_) as warning:
									UpperCAmelCase_		:   Dict													=       deprecate(
									    ('arg', self.higher_version, 'message')     ,      ('foo', self.higher_version, 'message')     ,      ('does not exist', self.higher_version, 'message')     ,      take_from=Args()     ,      )

								assert arg_a == 5
								assert arg_a == 7
								assert (
								    str(warning.warning)
								    == F"""The `arg` attribute is deprecated and will be removed in version {self.higher_version}. message"""
								)
								assert (
								    str(warning.warnings[0].message)
								    == F"""The `arg` attribute is deprecated and will be removed in version {self.higher_version}. message"""
								)
								assert (
								    str(warning.warnings[1].message)
								    == F"""The `foo` attribute is deprecated and will be removed in version {self.higher_version}. message"""
								)


							def     _snake_case				(      self)				->					Any:
								UpperCAmelCase_		:   str													=       {'deprecated_arg': 4}

								with self.assertRaises(lowerCamelCase_) as error:
									deprecate(('wrong_arg', self.lower_version, 'message')     ,      take_from=lowerCamelCase_)

								assert (
								    str(error.exception)
								    == "The deprecation tuple ('wrong_arg', '0.0.1', 'message') should be removed since diffusers' version"
								    F""" {__version__} is >= {self.lower_version}"""
								)


							def     _snake_case				(      self)				->					Any:



								with self.assertWarns(lowerCamelCase_) as warning:
									deprecate(('deprecated_arg', self.higher_version, 'This message is better!!!')     ,      standard_warn=lowerCamelCase_)

								assert str(warning.warning) == "This message is better!!!"





							def     _snake_case				(      self)				->					str:



								with self.assertWarns(lowerCamelCase_) as warning:
									deprecate(('deprecated_arg', self.higher_version, 'This message is better!!!')     ,      standard_warn=lowerCamelCase_)
								assert str(warning.warning) == "This message is better!!!"
								assert "diffusers/tests/others/test_utils.py" in warning.filename














"""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 KandinskyPriorPipeline, 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 						a_ (      snake_case_    ,		unittest.TestCase					):







      '''simple docstring'''

      lowerCamelCase__			:							Optional[Any]					=      KandinskyPriorPipeline
      lowerCamelCase__			:							Any					=      ['prompt']
      lowerCamelCase__			:							Any					=      ['prompt', 'negative_prompt']
      lowerCamelCase__			:							str					=      [
          'num_images_per_prompt',
          'generator',
          'num_inference_steps',
          'latents',
          'negative_prompt',
          'guidance_scale',
          'output_type',
          'return_dict',
      ]
      lowerCamelCase__			:							Dict					=      False




      @property
      def      a__				(self   ):

       '''simple docstring'''



       return 3_2




      @property
      def      a__				(self   ):

       '''simple docstring'''



       return 3_2




      @property
      def      a__				(self   ):

       '''simple docstring'''



       return self.time_input_dim




      @property
      def      a__				(self   ):

       '''simple docstring'''



       return self.time_input_dim * 4




      @property
      def      a__				(self   ):

       '''simple docstring'''



       return 1_0_0




      @property
      def      a__				(self   ):

       '''simple docstring'''



       lowerCamelCase__	:     Any								=		CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'   )
       return tokenizer




      @property
      def      a__				(self   ):

       '''simple docstring'''



       torch.manual_seed(0   )
       lowerCamelCase__	:     int								=		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(lowerCamelCase_   )




      @property
      def      a__				(self   ):

       '''simple docstring'''



       torch.manual_seed(0   )

       lowerCamelCase__	:     Optional[int]								=		{
           'num_attention_heads': 2,
           'attention_head_dim': 1_2,
           'embedding_dim': self.text_embedder_hidden_size,
           'num_layers': 1,
       }

       lowerCamelCase__	:     Optional[int]								=		PriorTransformer(**lowerCamelCase_   )
       # 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
       lowerCamelCase__	:     Dict								=		nn.Parameter(torch.ones(model.clip_std.shape   )   )
       return model




      @property
      def      a__				(self   ):

       '''simple docstring'''



       torch.manual_seed(0   )
       lowerCamelCase__	:     List[str]								=		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,	)

       lowerCamelCase__	:     int								=		CLIPVisionModelWithProjection(lowerCamelCase_   )
       return model




      @property
      def      a__				(self   ):

       '''simple docstring'''



       lowerCamelCase__	:     Union[str, Any]								=		CLIPImageProcessor(
           crop_size=2_2_4,	do_center_crop=lowerCamelCase_,	do_normalize=lowerCamelCase_,	do_resize=lowerCamelCase_,	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      a__				(self   ):

       '''simple docstring'''



       lowerCamelCase__	:     str								=		self.dummy_prior
       lowerCamelCase__	:     Optional[Any]								=		self.dummy_image_encoder
       lowerCamelCase__	:     Optional[Any]								=		self.dummy_text_encoder
       lowerCamelCase__	:     Union[str, Any]								=		self.dummy_tokenizer
       lowerCamelCase__	:     List[Any]								=		self.dummy_image_processor

       lowerCamelCase__	:     List[Any]								=		UnCLIPScheduler(
           variance_type='fixed_small_log',	prediction_type='sample',	num_train_timesteps=1_0_0_0,	clip_sample=lowerCamelCase_,	clip_sample_range=10.0,	)

       lowerCamelCase__	:     Union[str, Any]								=		{
           'prior': prior,
           'image_encoder': image_encoder,
           'text_encoder': text_encoder,
           'tokenizer': tokenizer,
           'scheduler': scheduler,
           'image_processor': image_processor,
       }

       return components




      def      a__				(self,	lowerCamelCase_,	lowerCamelCase_=0   ):

       '''simple docstring'''



       if str(lowerCamelCase_   ).startswith('mps'   ):
        lowerCamelCase__	:     List[Any]								=		torch.manual_seed(lowerCamelCase_   )
       else:
        lowerCamelCase__	:     Optional[int]								=		torch.Generator(device=lowerCamelCase_   ).manual_seed(lowerCamelCase_   )
       lowerCamelCase__	:     List[Any]								=		{
           'prompt': 'horse',
           'generator': generator,
           'guidance_scale': 4.0,
           'num_inference_steps': 2,
           'output_type': 'np',
       }
       return inputs




      def      a__				(self   ):

       '''simple docstring'''



       lowerCamelCase__	:     List[str]								=		'cpu'

       lowerCamelCase__	:     str								=		self.get_dummy_components()

       lowerCamelCase__	:     Any								=		self.pipeline_class(**lowerCamelCase_   )
       lowerCamelCase__	:     Dict								=		pipe.to(lowerCamelCase_   )

       pipe.set_progress_bar_config(disable=lowerCamelCase_   )

       lowerCamelCase__	:     Tuple								=		pipe(**self.get_dummy_inputs(lowerCamelCase_   )   )
       lowerCamelCase__	:     Dict								=		output.image_embeds

       lowerCamelCase__	:     Optional[Any]								=		pipe(
           **self.get_dummy_inputs(lowerCamelCase_   ),	return_dict=lowerCamelCase_,	)[0]

       lowerCamelCase__	:     Dict								=		image[0, -1_0:]
       lowerCamelCase__	:     Tuple								=		image_from_tuple[0, -1_0:]

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

       lowerCamelCase__	:     Dict								=		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      a__				(self   ):

       '''simple docstring'''



       lowerCamelCase__	:     Optional[int]								=		torch_device == 'cpu'
       lowerCamelCase__	:     Any								=		True
       lowerCamelCase__	:     List[Any]								=		False

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





      @skip_mps
      def      a__				(self   ):

       '''simple docstring'''



       lowerCamelCase__	:     str								=		torch_device == 'cpu'
       lowerCamelCase__	:     int								=		False

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

