




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   __a(					_a    ,						unittest.TestCase       ):






    """simple docstring"""





    lowerCAmelCase        =				KandinskyVaaPriorPipeline
    lowerCAmelCase        =				['''prompt''']
    lowerCAmelCase        =				['''prompt''', '''negative_prompt''']
    lowerCAmelCase        =				[
        '''num_images_per_prompt''',
        '''generator''',
        '''num_inference_steps''',
        '''latents''',
        '''negative_prompt''',
        '''guidance_scale''',
        '''output_type''',
        '''return_dict''',
    ]
    lowerCAmelCase        =				False





    @property
    def 							a__				(				self  )			->		Dict:
         return 32





    @property
    def 							a__				(				self  )			->		Tuple:
         return 32





    @property
    def 							a__				(				self  )			->		str:
         return self.time_input_dim





    @property
    def 							a__				(				self  )			->		int:
         return self.time_input_dim * 4





    @property
    def 							a__				(				self  )			->		List[str]:
         return 100





    @property
    def 							a__				(				self  )			->		Any:
         UpperCAmelCase_      :							Any       =      CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''  )
         return tokenizer





    @property
    def 							a__				(				self  )			->		str:
         torch.manual_seed(0  )
         UpperCAmelCase_      :							Union[str, Any]       =      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=37       ,layer_norm_eps=1e-05       ,num_attention_heads=4       ,num_hidden_layers=5       ,pad_token_id=1       ,vocab_size=1_000       ,)
         return CLIPTextModelWithProjection(_SCREAMING_SNAKE_CASE  )





    @property
    def 							a__				(				self  )			->		str:
         torch.manual_seed(0  )

         UpperCAmelCase_      :							Any       =      {
             '''num_attention_heads''': 2,
             '''attention_head_dim''': 12,
             '''embedding_dim''': self.text_embedder_hidden_size,
             '''num_layers''': 1,
         }

         UpperCAmelCase_      :							Union[str, Any]       =      PriorTransformer(**_SCREAMING_SNAKE_CASE  )
         # 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
         UpperCAmelCase_      :							Union[str, Any]       =      nn.Parameter(torch.ones(model.clip_std.shape  )  )
         return model





    @property
    def 							a__				(				self  )			->		Tuple:
         torch.manual_seed(0  )
         UpperCAmelCase_      :							Any       =      CLIPVisionConfig(
             hidden_size=self.text_embedder_hidden_size       ,image_size=224       ,projection_dim=self.text_embedder_hidden_size       ,intermediate_size=37       ,num_attention_heads=4       ,num_channels=3       ,num_hidden_layers=5       ,patch_size=14       ,)

         UpperCAmelCase_      :							Optional[Any]       =      CLIPVisionModelWithProjection(_SCREAMING_SNAKE_CASE  )
         return model





    @property
    def 							a__				(				self  )			->		List[Any]:
         UpperCAmelCase_      :							Dict       =      CLIPImageProcessor(
             crop_size=224       ,do_center_crop=_SCREAMING_SNAKE_CASE       ,do_normalize=_SCREAMING_SNAKE_CASE       ,do_resize=_SCREAMING_SNAKE_CASE       ,image_mean=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]       ,image_std=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]       ,resample=3       ,size=224       ,)

         return image_processor





    def 							a__				(				self  )			->		int:
         UpperCAmelCase_      :							Union[str, Any]       =      self.dummy_prior
         UpperCAmelCase_      :							Any       =      self.dummy_image_encoder
         UpperCAmelCase_      :							List[Any]       =      self.dummy_text_encoder
         UpperCAmelCase_      :							Optional[int]       =      self.dummy_tokenizer
         UpperCAmelCase_      :							Optional[int]       =      self.dummy_image_processor

         UpperCAmelCase_      :							Dict       =      UnCLIPScheduler(
             variance_type='''fixed_small_log'''       ,prediction_type='''sample'''       ,num_train_timesteps=1_000       ,clip_sample=_SCREAMING_SNAKE_CASE       ,clip_sample_range=10.0       ,)

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

         return components





    def 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE=0  )			->		Any:
         if str(_SCREAMING_SNAKE_CASE  ).startswith('''mps'''  ):
              UpperCAmelCase_      :							int       =      torch.manual_seed(_SCREAMING_SNAKE_CASE  )
         else:
              UpperCAmelCase_      :							int       =      torch.Generator(device=_SCREAMING_SNAKE_CASE  ).manual_seed(_SCREAMING_SNAKE_CASE  )
         UpperCAmelCase_      :							Any       =      {
             '''prompt''': '''horse''',
             '''generator''': generator,
             '''guidance_scale''': 4.0,
             '''num_inference_steps''': 2,
             '''output_type''': '''np''',
         }
         return inputs





    def 							a__				(				self  )			->		List[Any]:
         UpperCAmelCase_      :							Optional[int]       =      '''cpu'''

         UpperCAmelCase_      :							Any       =      self.get_dummy_components()

         UpperCAmelCase_      :							Tuple       =      self.pipeline_class(**_SCREAMING_SNAKE_CASE  )
         UpperCAmelCase_      :							Dict       =      pipe.to(_SCREAMING_SNAKE_CASE  )

         pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							str       =      pipe(**self.get_dummy_inputs(_SCREAMING_SNAKE_CASE  )  )
         UpperCAmelCase_      :							List[str]       =      output.image_embeds

         UpperCAmelCase_      :							str       =      pipe(
             **self.get_dummy_inputs(_SCREAMING_SNAKE_CASE  )       ,return_dict=_SCREAMING_SNAKE_CASE       ,)[0]

         UpperCAmelCase_      :							Tuple       =      image[0, -10:]
         UpperCAmelCase_      :							Dict       =      image_from_tuple[0, -10:]

         assert image.shape == (1, 32)

         UpperCAmelCase_      :							Optional[int]       =      np.array(
             [-0.05_32, 1.71_20, 0.36_56, -1.08_52, -0.89_46, -1.17_56, 0.43_48, 0.24_82, 0.51_46, -0.11_56]  )

         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  )			->		str:
         UpperCAmelCase_      :							Union[str, Any]       =      torch_device == '''cpu'''
         UpperCAmelCase_      :							int       =      True
         UpperCAmelCase_      :							Union[str, Any]       =      False

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





    @skip_mps
    def 							a__				(				self  )			->		Any:
         UpperCAmelCase_      :							List[Any]       =      torch_device == '''cpu'''
         UpperCAmelCase_      :							Optional[Any]       =      False

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





from __future__ import annotations

from fractions import Fraction







def lowerCamelCase__       (      _lowercase			,						_lowercase				):

     '''simple docstring'''


     return (
         num != den and num % 10 == den // 10 and (num // 10) / (den % 10) == num / den
     )







def lowerCamelCase__       (      _lowercase				):

     '''simple docstring'''


     UpperCAmelCase_      :							Optional[int]       =      []
     UpperCAmelCase_      :							Tuple       =      11
     UpperCAmelCase_      :							int       =      int('''1''' + '''0''' * digit_len				)
     for num in range(_lowercase			,						_lowercase				):
          while den <= 99:
               if (num != den) and (num % 10 == den // 10) and (den % 10 != 0):
                    if is_digit_cancelling(_lowercase			,						_lowercase				):
                         solutions.append(f'''{num}/{den}'''				)
               den += 1
          num += 1
          UpperCAmelCase_      :							Any       =      10
     return solutions







def lowerCamelCase__       (      _lowercase = 2				):

     '''simple docstring'''


     UpperCAmelCase_      :							Tuple       =      1.0
     for fraction in fraction_list(_lowercase				):
          UpperCAmelCase_      :							Optional[Any]       =      Fraction(_lowercase				)
          result *= frac.denominator / frac.numerator
     return int(_lowercase				)


if __name__ == "__main__":
     print(solution())