'''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_       (		_UpperCamelCase    ,    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 	__UpperCAmelCase   (      self      :			Dict     )  ->			Tuple:
        return 32
   @property
   def 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			Any:
        return 32
   @property
   def 	__UpperCAmelCase   (      self      :			Optional[Any]     )  ->			str:
        return self.time_input_dim
   @property
   def 	__UpperCAmelCase   (      self      :			Optional[Any]     )  ->			Optional[Any]:
        return self.time_input_dim * 4
   @property
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Union[str, Any]:
        return 1_00
   @property
   def 	__UpperCAmelCase   (      self      :			List[Any]     )  ->			Optional[int]:
        _A    		=  CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'     )
        return tokenizer
   @property
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			Optional[Any]:
        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=37, layer_norm_eps=1e-05, num_attention_heads=4, num_hidden_layers=5, pad_token_id=1, vocab_size=10_00, )
        return CLIPTextModelWithProjection(UpperCamelCase__     )
   @property
   def 	__UpperCAmelCase   (      self      :			Optional[Any]     )  ->			Any:
        torch.manual_seed(0     )

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

        _A    		=  PriorTransformer(**UpperCamelCase__     )
        # 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 	__UpperCAmelCase   (      self      :			Dict     )  ->			Tuple:
        torch.manual_seed(0     )
        _A    		=  CLIPVisionConfig(
            hidden_size=self.text_embedder_hidden_size, image_size=2_24, projection_dim=self.text_embedder_hidden_size, intermediate_size=37, num_attention_heads=4, num_channels=3, num_hidden_layers=5, patch_size=14, )

        _A    		=  CLIPVisionModelWithProjection(UpperCamelCase__     )
        return model
   @property
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			List[Any]:
        _A    		=  CLIPImageProcessor(
            crop_size=2_24, do_center_crop=UpperCamelCase__, do_normalize=UpperCamelCase__, do_resize=UpperCamelCase__, 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_24, )

        return image_processor
   def 	__UpperCAmelCase   (      self      :			List[Any]     )  ->			Optional[int]:
        _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=10_00, clip_sample=UpperCamelCase__, 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 	__UpperCAmelCase   (      self      :			List[Any], UpperCamelCase__      :			List[Any], UpperCamelCase__      :			Tuple=0     )  ->			Optional[Any]:
        if str(UpperCamelCase__     ).startswith('mps'     ):
             _A    		=  torch.manual_seed(UpperCamelCase__     )
        else:
             _A    		=  torch.Generator(device=UpperCamelCase__     ).manual_seed(UpperCamelCase__     )
        _A    		=  {
            'prompt': 'horse',
            'generator': generator,
            'guidance_scale': 4.0,
            'num_inference_steps': 2,
            'output_type': 'np',
        }
        return inputs
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			str:
        _A    		=  'cpu'

        _A    		=  self.get_dummy_components()

        _A    		=  self.pipeline_class(**UpperCamelCase__     )
        _A    		=  pipe.to(UpperCamelCase__     )

        pipe.set_progress_bar_config(disable=UpperCamelCase__     )

        _A    		=  pipe(**self.get_dummy_inputs(UpperCamelCase__     )     )
        _A    		=  output.image_embeds

        _A    		=  pipe(
            **self.get_dummy_inputs(UpperCamelCase__     ), return_dict=UpperCamelCase__, )[0]

        _A    		=  image[0, -10:]
        _A    		=  image_from_tuple[0, -10:]

        assert image.shape == (1, 32)

        _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 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			Dict:
        _A    		=  torch_device == 'cpu'
        _A    		=  True
        _A    		=  False

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

   @skip_mps
   def 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			Union[str, Any]:
        _A    		=  torch_device == 'cpu'
        _A    		=  False

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










def 		_SCREAMING_SNAKE_CASE     ( lowerCAmelCase__=2_81_23						):
		lowerCamelCase_	:     Any 						=      [1] * (limit + 1)

		for i in range(2							,int(limit**0.5						) + 1						):
				sum_divs[i * i] += i
				for k in range(i + 1							,limit // i + 1						):
						sum_divs[k * i] += k + i

		lowerCamelCase_	:     List[str] 						=      set()
		lowerCamelCase_	:     List[str] 						=      0

		for n in range(1							,limit + 1						):
				if sum_divs[n] > n:
						abundants.add(lowerCAmelCase__						)

				if not any((n - a in abundants) for a in abundants						):
						res += n

		return res


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