code: 
  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 						lowerCamelCase			(					__lowerCamelCase   ,		unittest.TestCase				):
  	UpperCamelCase_     :				int								=  KandinskyPriorPipeline
  	UpperCamelCase_     :				Any								=  ['prompt']
  	UpperCamelCase_     :				List[Any]								=  ['prompt', 'negative_prompt']
  	UpperCamelCase_     :				List[str]								=  [
  	    'num_images_per_prompt',
  	    'generator',
  	    'num_inference_steps',
  	    'latents',
  	    'negative_prompt',
  	    'guidance_scale',
  	    'output_type',
  	    'return_dict',
  	]
  	UpperCamelCase_     :				Any								=  False
  
  
  
  
  
  
  
  	@property
  	def    snake_case__    (    self			:Tuple )		->			str:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				return 3_2
  
  
  
  
  
  
  
  	@property
  	def    snake_case__    (    self			:Optional[int] )		->			Optional[int]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				return 3_2
  
  
  
  
  
  
  
  	@property
  	def    snake_case__    (    self			:List[str] )		->			Optional[Any]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				return self.time_input_dim
  
  
  
  
  
  
  
  	@property
  	def    snake_case__    (    self			:Optional[Any] )		->			Union[str, Any]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				return self.time_input_dim * 4
  
  
  
  
  
  
  
  	@property
  	def    snake_case__    (    self			:Optional[int] )		->			Optional[int]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				return 1_0_0
  
  
  
  
  
  
  
  	@property
  	def    snake_case__    (    self			:Tuple )		->			int:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE    	=   CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip''' )
  				return tokenizer
  
  
  
  
  
  
  
  	@property
  	def    snake_case__    (    self			:str )		->			Dict:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				torch.manual_seed(0 )
  				SCREAMING_SNAKE_CASE    	=   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    snake_case__    (    self			:str )		->			List[Any]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				torch.manual_seed(0 )
  
  				SCREAMING_SNAKE_CASE    	=   {
  				    '''num_attention_heads''': 2,
  				    '''attention_head_dim''': 1_2,
  				    '''embedding_dim''': self.text_embedder_hidden_size,
  				    '''num_layers''': 1,
  				}
  
  				SCREAMING_SNAKE_CASE    	=   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
  				SCREAMING_SNAKE_CASE    	=   nn.Parameter(torch.ones(model.clip_std.shape ) )
  				return model
  
  
  
  
  
  
  
  	@property
  	def    snake_case__    (    self			:List[Any] )		->			Optional[Any]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				torch.manual_seed(0 )
  				SCREAMING_SNAKE_CASE    	=   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      ,    )
  
  				SCREAMING_SNAKE_CASE    	=   CLIPVisionModelWithProjection(lowercase )
  				return model
  
  
  
  
  
  
  
  	@property
  	def    snake_case__    (    self			:int )		->			str:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE    	=   CLIPImageProcessor(
  				    crop_size=2_2_4      ,    do_center_crop=lowercase      ,    do_normalize=lowercase      ,    do_resize=lowercase      ,    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=2_2_4      ,    )
  
  				return image_processor
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:List[str] )		->			Union[str, Any]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE    	=   self.dummy_prior
  				SCREAMING_SNAKE_CASE    	=   self.dummy_image_encoder
  				SCREAMING_SNAKE_CASE    	=   self.dummy_text_encoder
  				SCREAMING_SNAKE_CASE    	=   self.dummy_tokenizer
  				SCREAMING_SNAKE_CASE    	=   self.dummy_image_processor
  
  				SCREAMING_SNAKE_CASE    	=   UnCLIPScheduler(
  				    variance_type='''fixed_small_log'''      ,    prediction_type='''sample'''      ,    num_train_timesteps=1_0_0_0      ,    clip_sample=lowercase      ,    clip_sample_range=10.0      ,    )
  
  				SCREAMING_SNAKE_CASE    	=   {
  				    '''prior''': prior,
  				    '''image_encoder''': image_encoder,
  				    '''text_encoder''': text_encoder,
  				    '''tokenizer''': tokenizer,
  				    '''scheduler''': scheduler,
  				    '''image_processor''': image_processor,
  				}
  
  				return components
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:str      ,    lowercase			:int      ,    lowercase			:Optional[int]=0 )		->			int:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				if str(lowercase ).startswith('''mps''' ):
  							SCREAMING_SNAKE_CASE    	=   torch.manual_seed(lowercase )
  				else:
  							SCREAMING_SNAKE_CASE    	=   torch.Generator(device=lowercase ).manual_seed(lowercase )
  				SCREAMING_SNAKE_CASE    	=   {
  				    '''prompt''': '''horse''',
  				    '''generator''': generator,
  				    '''guidance_scale''': 4.0,
  				    '''num_inference_steps''': 2,
  				    '''output_type''': '''np''',
  				}
  				return inputs
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:Union[str, Any] )		->			int:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE    	=   '''cpu'''
  
  				SCREAMING_SNAKE_CASE    	=   self.get_dummy_components()
  
  				SCREAMING_SNAKE_CASE    	=   self.pipeline_class(**lowercase )
  				SCREAMING_SNAKE_CASE    	=   pipe.to(lowercase )
  
  				pipe.set_progress_bar_config(disable=lowercase )
  
  				SCREAMING_SNAKE_CASE    	=   pipe(**self.get_dummy_inputs(lowercase ) )
  				SCREAMING_SNAKE_CASE    	=   output.image_embeds
  
  				SCREAMING_SNAKE_CASE    	=   pipe(
  				    **self.get_dummy_inputs(lowercase )      ,    return_dict=lowercase      ,    )[0]
  
  				SCREAMING_SNAKE_CASE    	=   image[0, -1_0:]
  				SCREAMING_SNAKE_CASE    	=   image_from_tuple[0, -1_0:]
  
  				assert image.shape == (1, 3_2)
  
  				SCREAMING_SNAKE_CASE    	=   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    snake_case__    (    self			:Tuple )		->			Optional[Any]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE    	=   torch_device == '''cpu'''
  				SCREAMING_SNAKE_CASE    	=   True
  				SCREAMING_SNAKE_CASE    	=   False
  
  				self._test_inference_batch_single_identical(
  				    test_max_difference=lowercase      ,    relax_max_difference=lowercase      ,    test_mean_pixel_difference=lowercase      ,    )
  
  
  
  
  
  
  
  	@skip_mps
  	def    snake_case__    (    self			:Optional[Any] )		->			List[str]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE    	=   torch_device == '''cpu'''
  				SCREAMING_SNAKE_CASE    	=   False
  
  				self._test_attention_slicing_forward_pass(
  				    test_max_difference=lowercase      ,    test_mean_pixel_difference=lowercase      ,    )
style_context: 
  from __future__ import annotations
  
  
  def       a			(   a		,	a  )    ->str:
  
  
  
  
  			'''simple docstring'''
  
  
  			SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE    	=   '''''', '''''', ''''''
  			SCREAMING_SNAKE_CASE    	=   []
  
  			for character in message_part:
  						tmp.append(character_to_number[character]  )
  
  			for each in tmp:
  						one += each[0]
  						two += each[1]
  						three += each[2]
  
  			return one + two + three
  
  
  def       a			(   a		,	a  )    ->tuple[str, str, str]:
  
  
  
  
  			'''simple docstring'''
  
  
  			SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE    	=   '''''', ''''''
  			SCREAMING_SNAKE_CASE    	=   []
  
  			for character in message_part:
  						this_part += character_to_number[character]
  
  			for digit in this_part:
  						tmp += digit
  						if len(a  ) == len(a  ):
  									result.append(a  )
  									SCREAMING_SNAKE_CASE    	=   ''''''
  
  			return result[0], result[1], result[2]
  
  
  def       a			(   a		,	a  )    ->tuple[str, str, dict[str, str], dict[str, str]]:
  
  
  
  
  			'''simple docstring'''
  
  
  			SCREAMING_SNAKE_CASE    	=   alphabet.replace(''' '''		,	''''''  ).upper()
  			SCREAMING_SNAKE_CASE    	=   message.replace(''' '''		,	''''''  ).upper()
  
  			# Check length and characters
  			if len(a  ) != 27:
  						raise KeyError('''Length of alphabet has to be 27.'''  )
  			for each in message:
  						if each not in alphabet:
  									raise ValueError('''Each message character has to be included in alphabet!'''  )
  
      # Generate dictionares
  			SCREAMING_SNAKE_CASE    	=   (
  			    '''111''',
  			    '''112''',
  			    '''113''',
  			    '''121''',
  			    '''122''',
  			    '''123''',
  			    '''131''',
  			    '''132''',
  			    '''133''',
  			    '''211''',
  			    '''212''',
  			    '''213''',
  			    '''221''',
  			    '''222''',
  			    '''223''',
  			    '''231''',
  			    '''232''',
  			    '''233''',
  			    '''311''',
  			    '''312''',
  			    '''313''',
  			    '''321''',
  			    '''322''',
  			    '''323''',
  			    '''331''',
  			    '''332''',
  			    '''333''',
  			)
  			SCREAMING_SNAKE_CASE    	=   {}
  			SCREAMING_SNAKE_CASE    	=   {}
  			for letter, number in zip(a		,	a  ):
  						SCREAMING_SNAKE_CASE    	=   number
  						SCREAMING_SNAKE_CASE    	=   letter
  
  			return message, alphabet, character_to_number, number_to_character
  
  
  def       a			(   a		,	a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ."		,	a = 5  )    ->str:
  
  
  
  
  			'''simple docstring'''
  
  
  			SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE    	=   __prepare(
  			    a		,	a  )
  			SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE    	=   '''''', ''''''
  
  			for i in range(0		,	len(a  ) + 1		,	a  ):
  						encrypted_numeric += __encrypt_part(
  						    message[i : i + period]		,	a  )
  
  			for i in range(0		,	len(a  )		,	3  ):
  						encrypted += number_to_character[encrypted_numeric[i : i + 3]]
  
  			return encrypted
  
  
  def       a			(   a		,	a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ."		,	a = 5  )    ->str:
  
  
  
  
  			'''simple docstring'''
  
  
  			SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE    	=   __prepare(
  			    a		,	a  )
  			SCREAMING_SNAKE_CASE    	=   []
  			SCREAMING_SNAKE_CASE    	=   ''''''
  
  			for i in range(0		,	len(a  ) + 1		,	a  ):
  						SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE    	=   __decrypt_part(message[i : i + period]		,	a  )
  
  						for j in range(0		,	len(a  )  ):
  									decrypted_numeric.append(a[j] + b[j] + c[j]  )
  
  			for each in decrypted_numeric:
  						decrypted += number_to_character[each]
  
  			return decrypted
  
  
  if __name__ == "__main__":
  							__lowerCAmelCase				      =					'DEFEND THE EAST WALL OF THE CASTLE.'
  							__lowerCAmelCase				      =					encrypt_message(msg, 'EPSDUCVWYM.ZLKXNBTFGORIJHAQ')
  							__lowerCAmelCase				      =					decrypt_message(encrypted, 'EPSDUCVWYM.ZLKXNBTFGORIJHAQ')
  							print(F'''Encrypted: {encrypted}\nDecrypted: {decrypted}''')