



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 						snake_case  (		SCREAMING_SNAKE_CASE_   ,unittest.TestCase					):



   '''simple docstring'''






   snake_case_   :	Any       =						KandinskyPriorPipeline
   snake_case_   :	Any       =						["""prompt"""]
   snake_case_   :	Tuple       =						["""prompt""", """negative_prompt"""]
   snake_case_   :	int       =						[
       """num_images_per_prompt""",
       """generator""",
       """num_inference_steps""",
       """latents""",
       """negative_prompt""",
       """guidance_scale""",
       """output_type""",
       """return_dict""",
   ]
   snake_case_   :	List[Any]       =						False

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

    """simple docstring"""







    return 32

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

    """simple docstring"""







    return 32

   @property
   def        UpperCamelCase_					(   self							:     Any)			->			str:

    """simple docstring"""







    return self.time_input_dim

   @property
   def        UpperCamelCase_					(   self							:     str)			->			Optional[int]:

    """simple docstring"""







    return self.time_input_dim * 4

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

    """simple docstring"""







    return 100

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

    """simple docstring"""







    _snake_case      :					List[Any]					=   CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip""")
    return tokenizer

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

    """simple docstring"""







    torch.manual_seed(0)
    _snake_case      :					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=37			,						layer_norm_eps=1E-05			,						num_attention_heads=4			,						num_hidden_layers=5			,						pad_token_id=1			,						vocab_size=1000			,						)
    return CLIPTextModelWithProjection(lowerCAmelCase)

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

    """simple docstring"""







    torch.manual_seed(0)

    _snake_case      :					Dict					=   {
        """num_attention_heads""": 2,
        """attention_head_dim""": 12,
        """embedding_dim""": self.text_embedder_hidden_size,
        """num_layers""": 1,
    }

    _snake_case      :					List[str]					=   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
    _snake_case      :					int					=   nn.Parameter(torch.ones(model.clip_std.shape))
    return model

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

    """simple docstring"""







    torch.manual_seed(0)
    _snake_case      :					Tuple					=   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			,						)

    _snake_case      :					Union[str, Any]					=   CLIPVisionModelWithProjection(lowerCAmelCase)
    return model

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

    """simple docstring"""







    _snake_case      :					Optional[Any]					=   CLIPImageProcessor(
        crop_size=224			,						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=224			,						)

    return image_processor

   def        UpperCamelCase_					(   self							:     List[str])			->			Any:

    """simple docstring"""







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

    _snake_case      :					str					=   UnCLIPScheduler(
        variance_type="""fixed_small_log"""			,						prediction_type="""sample"""			,						num_train_timesteps=1000			,						clip_sample=lowerCAmelCase			,						clip_sample_range=10.0			,						)

    _snake_case      :					Optional[int]					=   {
        """prior""": prior,
        """image_encoder""": image_encoder,
        """text_encoder""": text_encoder,
        """tokenizer""": tokenizer,
        """scheduler""": scheduler,
        """image_processor""": image_processor,
    }

    return components

   def        UpperCamelCase_					(   self							:     Optional[int]			,						lowerCAmelCase							:     List[str]			,						lowerCAmelCase							:     Optional[Any]=0)			->			List[Any]:

    """simple docstring"""







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

   def        UpperCamelCase_					(   self							:     Tuple)			->			Any:

    """simple docstring"""







    _snake_case      :					Optional[Any]					=   """cpu"""

    _snake_case      :					Any					=   self.get_dummy_components()

    _snake_case      :					Dict					=   self.pipeline_class(**lowerCAmelCase)
    _snake_case      :					Tuple					=   pipe.to(lowerCAmelCase)

    pipe.set_progress_bar_config(disable=lowerCAmelCase)

    _snake_case      :					Dict					=   pipe(**self.get_dummy_inputs(lowerCAmelCase))
    _snake_case      :					Union[str, Any]					=   output.image_embeds

    _snake_case      :					int					=   pipe(
        **self.get_dummy_inputs(lowerCAmelCase)			,						return_dict=lowerCAmelCase			,						)[0]

    _snake_case      :					Any					=   image[0, -10:]
    _snake_case      :					int					=   image_from_tuple[0, -10:]

    assert image.shape == (1, 32)

    _snake_case      :					Any					=   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							:     List[Any])			->			Optional[Any]:

    """simple docstring"""







    _snake_case      :					int					=   torch_device == """cpu"""
    _snake_case      :					str					=   True
    _snake_case      :					int					=   False

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


   @skip_mps
   def        UpperCamelCase_					(   self							:     Optional[int])			->			str:

    """simple docstring"""







    _snake_case      :					Optional[int]					=   torch_device == """cpu"""
    _snake_case      :					List[Any]					=   False

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





def  lowercase    (				SCREAMING_SNAKE_CASE__    :		Any			)					->       Optional[int]:
 _snake_case      :					Any					=   [701, 301, 132, 57, 23, 10, 4, 1]
 for gap in gaps:
  for i in range(SCREAMING_SNAKE_CASE__			,    len(SCREAMING_SNAKE_CASE__			)			):
   _snake_case      :					List[Any]					=   collection[i]
   _snake_case      :					List[str]					=   i
   while j >= gap and collection[j - gap] > insert_value:
    _snake_case      :					int					=   collection[j - gap]
    j -= gap
   if j != i:
    _snake_case      :					Tuple					=   insert_value
 return collection


if __name__ == "__main__":
  from doctest import testmod

  testmod()
  a__      =		input("""Enter numbers separated by a comma:\n""").strip()
  a__      =		[int(item) for item in user_input.split(""",""")]
  print(shell_sort(unsorted))
