"""simple docstring"""





import gc
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import TransformeraDModel, VQDiffusionPipeline, VQDiffusionScheduler, VQModel
from diffusers.pipelines.vq_diffusion.pipeline_vq_diffusion import LearnedClassifierFreeSamplingEmbeddings
from diffusers.utils import load_numpy, slow, torch_device
from diffusers.utils.testing_utils import require_torch_gpu


__A  =				False
class  _snake_case     (					unittest.TestCase		):






						def       lowerCamelCase__     (       self      :			List[Any]    ):
													# clean up the VRAM after each test
													super().tearDown()
													gc.collect()
													torch.cuda.empty_cache()






						@property
						def       lowerCamelCase__     (       self      :			int    ):
													return 12






						@property
						def       lowerCamelCase__     (       self      :			List[Any]    ):
													return 12






						@property
						def       lowerCamelCase__     (       self      :			Union[str, Any]    ):
													return 32






						@property
						def       lowerCamelCase__     (       self      :			Optional[int]    ):
													torch.manual_seed(0    )
													__lowerCamelCase					:		int		   =     VQModel(
													    block_out_channels=[32, 64]							,					in_channels=3							,					out_channels=3							,					down_block_types=["DownEncoderBlock2D", "DownEncoderBlock2D"]							,					up_block_types=["UpDecoderBlock2D", "UpDecoderBlock2D"]							,					latent_channels=3							,					num_vq_embeddings=self.num_embed							,					vq_embed_dim=3							,					)
													return model






						@property
						def       lowerCamelCase__     (       self      :			str    ):
													__lowerCamelCase					:		Tuple		   =     CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"    )
													return tokenizer






						@property
						def       lowerCamelCase__     (       self      :			List[Any]    ):
													torch.manual_seed(0    )
													__lowerCamelCase					:		List[Any]		   =     CLIPTextConfig(
													    bos_token_id=0							,					eos_token_id=2							,					hidden_size=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 CLIPTextModel(UpperCAmelCase    )






						@property
						def       lowerCamelCase__     (       self      :			List[str]    ):
													torch.manual_seed(0    )

													__lowerCamelCase					:		List[Any]		   =     12
													__lowerCamelCase					:		Tuple		   =     12

													__lowerCamelCase					:		List[Any]		   =     {
													    "attention_bias": True,
													    "cross_attention_dim": 32,
													    "attention_head_dim": height * width,
													    "num_attention_heads": 1,
													    "num_vector_embeds": self.num_embed,
													    "num_embeds_ada_norm": self.num_embeds_ada_norm,
													    "norm_num_groups": 32,
													    "sample_size": width,
													    "activation_fn": "geglu-approximate",
													}

													__lowerCamelCase					:		Dict		   =     TransformeraDModel(**UpperCAmelCase    )
													return model






						def       lowerCamelCase__     (       self      :			Tuple    ):
													__lowerCamelCase					:		int		   =     "cpu"

													__lowerCamelCase					:		str		   =     self.dummy_vqvae
													__lowerCamelCase					:		List[str]		   =     self.dummy_text_encoder
													__lowerCamelCase					:		str		   =     self.dummy_tokenizer
													__lowerCamelCase					:		Any		   =     self.dummy_transformer
													__lowerCamelCase					:		Any		   =     VQDiffusionScheduler(self.num_embed    )
													__lowerCamelCase					:		str		   =     LearnedClassifierFreeSamplingEmbeddings(learnable=UpperCAmelCase    )

													__lowerCamelCase					:		Any		   =     VQDiffusionPipeline(
													    vqvae=UpperCAmelCase							,					text_encoder=UpperCAmelCase							,					tokenizer=UpperCAmelCase							,					transformer=UpperCAmelCase							,					scheduler=UpperCAmelCase							,					learned_classifier_free_sampling_embeddings=UpperCAmelCase							,					)
													__lowerCamelCase					:		int		   =     pipe.to(UpperCAmelCase    )
													pipe.set_progress_bar_config(disable=UpperCAmelCase    )

													__lowerCamelCase					:		Tuple		   =     "teddy bear playing in the pool"

													__lowerCamelCase					:		Any		   =     torch.Generator(device=UpperCAmelCase    ).manual_seed(0    )
													__lowerCamelCase					:		Tuple		   =     pipe([prompt]							,					generator=UpperCAmelCase							,					num_inference_steps=2							,					output_type="np"    )
													__lowerCamelCase					:		str		   =     output.images

													__lowerCamelCase					:		Optional[int]		   =     torch.Generator(device=UpperCAmelCase    ).manual_seed(0    )
													__lowerCamelCase					:		Any		   =     pipe(
													    [prompt]							,					generator=UpperCAmelCase							,					output_type="np"							,					return_dict=UpperCAmelCase							,					num_inference_steps=2    )[0]

													__lowerCamelCase					:		str		   =     image[0, -3:, -3:, -1]
													__lowerCamelCase					:		Union[str, Any]		   =     image_from_tuple[0, -3:, -3:, -1]

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

													__lowerCamelCase					:		int		   =     np.array([0.6_5_5_1, 0.6_1_6_8, 0.5_0_0_8, 0.5_6_7_6, 0.5_6_5_9, 0.4_2_9_5, 0.6_0_7_3, 0.5_5_9_9, 0.4_9_9_2]    )

													assert np.abs(image_slice.flatten() - expected_slice    ).max() < 1E-2
													assert np.abs(image_from_tuple_slice.flatten() - expected_slice    ).max() < 1E-2







						def       lowerCamelCase__     (       self      :			List[Any]    ):
													__lowerCamelCase					:		List[str]		   =     "cpu"

													__lowerCamelCase					:		str		   =     self.dummy_vqvae
													__lowerCamelCase					:		Tuple		   =     self.dummy_text_encoder
													__lowerCamelCase					:		str		   =     self.dummy_tokenizer
													__lowerCamelCase					:		Optional[int]		   =     self.dummy_transformer
													__lowerCamelCase					:		Tuple		   =     VQDiffusionScheduler(self.num_embed    )
													__lowerCamelCase					:		Any		   =     LearnedClassifierFreeSamplingEmbeddings(
													    learnable=UpperCAmelCase							,					hidden_size=self.text_embedder_hidden_size							,					length=tokenizer.model_max_length    )

													__lowerCamelCase					:		int		   =     VQDiffusionPipeline(
													    vqvae=UpperCAmelCase							,					text_encoder=UpperCAmelCase							,					tokenizer=UpperCAmelCase							,					transformer=UpperCAmelCase							,					scheduler=UpperCAmelCase							,					learned_classifier_free_sampling_embeddings=UpperCAmelCase							,					)
													__lowerCamelCase					:		Tuple		   =     pipe.to(UpperCAmelCase    )
													pipe.set_progress_bar_config(disable=UpperCAmelCase    )

													__lowerCamelCase					:		Any		   =     "teddy bear playing in the pool"

													__lowerCamelCase					:		Union[str, Any]		   =     torch.Generator(device=UpperCAmelCase    ).manual_seed(0    )
													__lowerCamelCase					:		Any		   =     pipe([prompt]							,					generator=UpperCAmelCase							,					num_inference_steps=2							,					output_type="np"    )
													__lowerCamelCase					:		Optional[int]		   =     output.images

													__lowerCamelCase					:		List[Any]		   =     torch.Generator(device=UpperCAmelCase    ).manual_seed(0    )
													__lowerCamelCase					:		Tuple		   =     pipe(
													    [prompt]							,					generator=UpperCAmelCase							,					output_type="np"							,					return_dict=UpperCAmelCase							,					num_inference_steps=2    )[0]

													__lowerCamelCase					:		Any		   =     image[0, -3:, -3:, -1]
													__lowerCamelCase					:		Tuple		   =     image_from_tuple[0, -3:, -3:, -1]

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

													__lowerCamelCase					:		str		   =     np.array([0.6_6_9_3, 0.6_0_7_5, 0.4_9_5_9, 0.5_7_0_1, 0.5_5_8_3, 0.4_3_3_3, 0.6_1_7_1, 0.5_6_8_4, 0.4_9_8_8]    )

													assert np.abs(image_slice.flatten() - expected_slice    ).max() < 2.0
													assert np.abs(image_from_tuple_slice.flatten() - expected_slice    ).max() < 1E-2

@slow
@require_torch_gpu
class  _snake_case     (					unittest.TestCase		):






						def       lowerCamelCase__     (       self      :			Dict    ):
													# clean up the VRAM after each test
													super().tearDown()
													gc.collect()
													torch.cuda.empty_cache()







						def       lowerCamelCase__     (       self      :			List[str]    ):
													__lowerCamelCase					:		Optional[int]		   =     load_numpy(
													    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
													    "/vq_diffusion/teddy_bear_pool_classifier_free_sampling.npy"    )

													__lowerCamelCase					:		List[str]		   =     VQDiffusionPipeline.from_pretrained("microsoft/vq-diffusion-ithq"    )
													__lowerCamelCase					:		Union[str, Any]		   =     pipeline.to(UpperCAmelCase    )
													pipeline.set_progress_bar_config(disable=UpperCAmelCase    )

													# requires GPU generator for gumbel softmax
													# don't use GPU generator in tests though
													__lowerCamelCase					:		int		   =     torch.Generator(device=UpperCAmelCase    ).manual_seed(0    )
													__lowerCamelCase					:		Any		   =     pipeline(
													    "teddy bear playing in the pool"							,					num_images_per_prompt=1							,					generator=UpperCAmelCase							,					output_type="np"							,					)

													__lowerCamelCase					:		Optional[int]		   =     output.images[0]

													assert image.shape == (256, 256, 3)
													assert np.abs(expected_image - image    ).max() < 2.0
"""simple docstring"""





from functools import lru_cache


def    lowercase_   (   _lowerCamelCase:	int      ) ->      set:



							'''simple docstring'''

							__lowerCamelCase					:		Optional[Any]		   =     2
							__lowerCamelCase					:		Tuple		   =     set()
							while i * i <= n:
														if n % i:
																					i += 1
														else:
																					n //= i
																					factors.add(_lowerCamelCase      )
							if n > 1:
														factors.add(_lowerCamelCase      )
							return factors


@lru_cache
def    lowercase_   (   _lowerCamelCase:	int      ) ->      int:



							'''simple docstring'''

							return len(unique_prime_factors(_lowerCamelCase      )      )


def    lowercase_   (   _lowerCamelCase:	list      ) ->      bool:



							'''simple docstring'''

							return len(set(_lowerCamelCase      )      ) in (0, 1)


def    lowercase_   (   _lowerCamelCase:	int      ) ->      list:



							'''simple docstring'''

							__lowerCamelCase					:		str		   =     2

							while True:
														# Increment each value of a generated range
														__lowerCamelCase					:		int		   =     [base + i for i in range(_lowerCamelCase      )]

														# Run elements through out unique_prime_factors function
														# Append our target number to the end.
														__lowerCamelCase					:		Dict		   =     [upf_len(_lowerCamelCase      ) for x in group]
														checker.append(_lowerCamelCase      )

														# If all numbers in the list are equal, return the group variable.
														if equality(_lowerCamelCase      ):
																					return group

														# Increment our base variable by 1
														base += 1


def    lowercase_   (   _lowerCamelCase:	int = 4      ) ->      int:



							'''simple docstring'''

							__lowerCamelCase					:		Any		   =     run(_lowerCamelCase      )
							return results[0] if len(_lowerCamelCase      ) else None


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