



'''simple docstring'''

import gc
import random
import unittest

import numpy as np
import torch
from transformers import (
    CLIPImageProcessor,
    CLIPTextConfig,
    CLIPTextModelWithProjection,
    CLIPTokenizer,
    CLIPVisionConfig,
    CLIPVisionModelWithProjection,
)

from diffusers import (
    DiffusionPipeline,
    UnCLIPImageVariationPipeline,
    UnCLIPScheduler,
    UNetaDConditionModel,
    UNetaDModel,
)
from diffusers.pipelines.unclip.text_proj import UnCLIPTextProjModel
from diffusers.utils import floats_tensor, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, load_image, require_torch_gpu, skip_mps

from ..pipeline_params import IMAGE_VARIATION_BATCH_PARAMS, IMAGE_VARIATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference


enable_full_determinism()


class 	a__     (				_lowercase,			unittest.TestCase	):
	__magic_name__		:    Union[str, Any]	    =     UnCLIPImageVariationPipeline
	__magic_name__		:    Optional[int]	    =     IMAGE_VARIATION_PARAMS - {"height", "width", "guidance_scale"}
	__magic_name__		:    List[str]	    =     IMAGE_VARIATION_BATCH_PARAMS

	__magic_name__		:    Optional[int]	    =     [
	    "generator",
	    "return_dict",
	    "decoder_num_inference_steps",
	    "super_res_num_inference_steps",
	]
	__magic_name__		:    Optional[int]	    =     False


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

					"""simple docstring"""

					return 32


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

					"""simple docstring"""

					return 32


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

					"""simple docstring"""

					return self.time_input_dim


	@property
	def 				lowercase__  (self : int      )     ->			str:

					"""simple docstring"""

					return self.time_input_dim * 4


	@property
	def 				lowercase__  (self : Dict      )     ->			Union[str, Any]:

					"""simple docstring"""

					return 100


	@property
	def 				lowercase__  (self : List[Any]      )     ->			int:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Tuple      					= CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''      )
					return tokenizer


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

					"""simple docstring"""

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


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

					"""simple docstring"""

					torch.manual_seed(0      )
					SCREAMING_SNAKE_CASE  :						Any      					= CLIPVisionConfig(
					    hidden_size=self.text_embedder_hidden_size,					projection_dim=self.text_embedder_hidden_size,					num_hidden_layers=5,					num_attention_heads=4,					image_size=32,					intermediate_size=37,					patch_size=1,					)
					return CLIPVisionModelWithProjection(__UpperCAmelCase      )


	@property
	def 				lowercase__  (self : Dict      )     ->			Any:

					"""simple docstring"""

					torch.manual_seed(0      )

					SCREAMING_SNAKE_CASE  :						int      					= {
					    '''clip_embeddings_dim''': self.text_embedder_hidden_size,
					    '''time_embed_dim''': self.time_embed_dim,
					    '''cross_attention_dim''': self.cross_attention_dim,
					}

					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= UnCLIPTextProjModel(**__UpperCAmelCase      )
					return model


	@property
	def 				lowercase__  (self : Dict      )     ->			List[str]:

					"""simple docstring"""

					torch.manual_seed(0      )

					SCREAMING_SNAKE_CASE  :						Dict      					= {
					    '''sample_size''': 32,
					    # RGB in channels
					    '''in_channels''': 3,
					    # Out channels is double in channels because predicts mean and variance
					    '''out_channels''': 6,
					    '''down_block_types''': ('''ResnetDownsampleBlock2D''', '''SimpleCrossAttnDownBlock2D'''),
					    '''up_block_types''': ('''SimpleCrossAttnUpBlock2D''', '''ResnetUpsampleBlock2D'''),
					    '''mid_block_type''': '''UNetMidBlock2DSimpleCrossAttn''',
					    '''block_out_channels''': (self.block_out_channels_a, self.block_out_channels_a * 2),
					    '''layers_per_block''': 1,
					    '''cross_attention_dim''': self.cross_attention_dim,
					    '''attention_head_dim''': 4,
					    '''resnet_time_scale_shift''': '''scale_shift''',
					    '''class_embed_type''': '''identity''',
					}

					SCREAMING_SNAKE_CASE  :						int      					= UNetaDConditionModel(**__UpperCAmelCase      )
					return model


	@property
	def 				lowercase__  (self : Tuple      )     ->			Optional[int]:

					"""simple docstring"""

					return {
					    "sample_size": 64,
					    "layers_per_block": 1,
					    "down_block_types": ("ResnetDownsampleBlock2D", "ResnetDownsampleBlock2D"),
					    "up_block_types": ("ResnetUpsampleBlock2D", "ResnetUpsampleBlock2D"),
					    "block_out_channels": (self.block_out_channels_a, self.block_out_channels_a * 2),
					    "in_channels": 6,
					    "out_channels": 3,
					}


	@property
	def 				lowercase__  (self : Any      )     ->			List[str]:

					"""simple docstring"""

					torch.manual_seed(0      )

					SCREAMING_SNAKE_CASE  :						Optional[int]      					= UNetaDModel(**self.dummy_super_res_kwargs      )
					return model


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

					"""simple docstring"""

					torch.manual_seed(1      )

					SCREAMING_SNAKE_CASE  :						Dict      					= UNetaDModel(**self.dummy_super_res_kwargs      )
					return model


	def 				lowercase__  (self : int      )     ->			Optional[Any]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						List[str]      					= self.dummy_decoder
					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= self.dummy_text_proj
					SCREAMING_SNAKE_CASE  :						Tuple      					= self.dummy_text_encoder
					SCREAMING_SNAKE_CASE  :						Optional[int]      					= self.dummy_tokenizer
					SCREAMING_SNAKE_CASE  :						int      					= self.dummy_super_res_first
					SCREAMING_SNAKE_CASE  :						Dict      					= self.dummy_super_res_last

					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= UnCLIPScheduler(
					    variance_type='''learned_range''',					prediction_type='''epsilon''',					num_train_timesteps=1000,					)

					SCREAMING_SNAKE_CASE  :						Any      					= UnCLIPScheduler(
					    variance_type='''fixed_small_log''',					prediction_type='''epsilon''',					num_train_timesteps=1000,					)

					SCREAMING_SNAKE_CASE  :						Optional[int]      					= CLIPImageProcessor(crop_size=32,					size=32      )

					SCREAMING_SNAKE_CASE  :						Tuple      					= self.dummy_image_encoder

					return {
					    "decoder": decoder,
					    "text_encoder": text_encoder,
					    "tokenizer": tokenizer,
					    "text_proj": text_proj,
					    "feature_extractor": feature_extractor,
					    "image_encoder": image_encoder,
					    "super_res_first": super_res_first,
					    "super_res_last": super_res_last,
					    "decoder_scheduler": decoder_scheduler,
					    "super_res_scheduler": super_res_scheduler,
					}


	def 				lowercase__  (self : Tuple,					__UpperCAmelCase : str,					__UpperCAmelCase : Optional[Any]=0,					__UpperCAmelCase : int=True      )     ->			Any:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Dict      					= floats_tensor((1, 3, 32, 32),					rng=random.Random(__UpperCAmelCase      )      ).to(__UpperCAmelCase      )
					if str(__UpperCAmelCase      ).startswith('''mps'''      ):
									SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= torch.manual_seed(__UpperCAmelCase      )
					else:
									SCREAMING_SNAKE_CASE  :						Tuple      					= torch.Generator(device=__UpperCAmelCase      ).manual_seed(__UpperCAmelCase      )

					if pil_image:
									SCREAMING_SNAKE_CASE  :						List[str]      					= input_image * 0.5 + 0.5
									SCREAMING_SNAKE_CASE  :						Optional[Any]      					= input_image.clamp(0,					1      )
									SCREAMING_SNAKE_CASE  :						Any      					= input_image.cpu().permute(0,					2,					3,					1      ).float().numpy()
									SCREAMING_SNAKE_CASE  :						Optional[int]      					= DiffusionPipeline.numpy_to_pil(__UpperCAmelCase      )[0]

					return {
					    "image": input_image,
					    "generator": generator,
					    "decoder_num_inference_steps": 2,
					    "super_res_num_inference_steps": 2,
					    "output_type": "np",
					}


	def 				lowercase__  (self : Dict      )     ->			Tuple:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= '''cpu'''

					SCREAMING_SNAKE_CASE  :						Optional[int]      					= self.get_dummy_components()

					SCREAMING_SNAKE_CASE  :						str      					= self.pipeline_class(**__UpperCAmelCase      )
					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= pipe.to(__UpperCAmelCase      )

					pipe.set_progress_bar_config(disable=__UpperCAmelCase      )

					SCREAMING_SNAKE_CASE  :						Dict      					= self.get_dummy_inputs(__UpperCAmelCase,					pil_image=__UpperCAmelCase      )

					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= pipe(**__UpperCAmelCase      )
					SCREAMING_SNAKE_CASE  :						List[Any]      					= output.images

					SCREAMING_SNAKE_CASE  :						int      					= self.get_dummy_inputs(__UpperCAmelCase,					pil_image=__UpperCAmelCase      )

					SCREAMING_SNAKE_CASE  :						int      					= pipe(
					    **__UpperCAmelCase,					return_dict=__UpperCAmelCase,					)[0]

					SCREAMING_SNAKE_CASE  :						str      					= image[0, -3:, -3:, -1]
					SCREAMING_SNAKE_CASE  :						int      					= image_from_tuple[0, -3:, -3:, -1]

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

					SCREAMING_SNAKE_CASE  :						int      					= np.array(
					    [
					        0.9997,
					        0.0002,
					        0.9997,
					        0.9997,
					        0.9969,
					        0.0023,
					        0.9997,
					        0.9969,
					        0.9970,
					    ]      )

					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 				lowercase__  (self : Dict      )     ->			Optional[Any]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= '''cpu'''

					SCREAMING_SNAKE_CASE  :						Optional[int]      					= self.get_dummy_components()

					SCREAMING_SNAKE_CASE  :						List[Any]      					= self.pipeline_class(**__UpperCAmelCase      )
					SCREAMING_SNAKE_CASE  :						Dict      					= pipe.to(__UpperCAmelCase      )

					pipe.set_progress_bar_config(disable=__UpperCAmelCase      )

					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= self.get_dummy_inputs(__UpperCAmelCase,					pil_image=__UpperCAmelCase      )

					SCREAMING_SNAKE_CASE  :						str      					= pipe(**__UpperCAmelCase      )
					SCREAMING_SNAKE_CASE  :						Tuple      					= output.images

					SCREAMING_SNAKE_CASE  :						Tuple      					= self.get_dummy_inputs(__UpperCAmelCase,					pil_image=__UpperCAmelCase      )

					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= pipe(
					    **__UpperCAmelCase,					return_dict=__UpperCAmelCase,					)[0]

					SCREAMING_SNAKE_CASE  :						int      					= image[0, -3:, -3:, -1]
					SCREAMING_SNAKE_CASE  :						int      					= image_from_tuple[0, -3:, -3:, -1]

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

					SCREAMING_SNAKE_CASE  :						List[str]      					= np.array([0.9997, 0.0003, 0.9997, 0.9997, 0.9970, 0.0024, 0.9997, 0.9971, 0.9971]      )

					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 				lowercase__  (self : List[str]      )     ->			Any:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Dict      					= '''cpu'''

					SCREAMING_SNAKE_CASE  :						int      					= self.get_dummy_components()

					SCREAMING_SNAKE_CASE  :						Dict      					= self.pipeline_class(**__UpperCAmelCase      )
					SCREAMING_SNAKE_CASE  :						Any      					= pipe.to(__UpperCAmelCase      )

					pipe.set_progress_bar_config(disable=__UpperCAmelCase      )

					SCREAMING_SNAKE_CASE  :						int      					= self.get_dummy_inputs(__UpperCAmelCase,					pil_image=__UpperCAmelCase      )
					SCREAMING_SNAKE_CASE  :						List[str]      					= [
					    pipeline_inputs['''image'''],
					    pipeline_inputs['''image'''],
					]

					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= pipe(**__UpperCAmelCase      )
					SCREAMING_SNAKE_CASE  :						str      					= output.images

					SCREAMING_SNAKE_CASE  :						Optional[int]      					= self.get_dummy_inputs(__UpperCAmelCase,					pil_image=__UpperCAmelCase      )
					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= [
					    tuple_pipeline_inputs['''image'''],
					    tuple_pipeline_inputs['''image'''],
					]

					SCREAMING_SNAKE_CASE  :						Optional[int]      					= pipe(
					    **__UpperCAmelCase,					return_dict=__UpperCAmelCase,					)[0]

					SCREAMING_SNAKE_CASE  :						int      					= image[0, -3:, -3:, -1]
					SCREAMING_SNAKE_CASE  :						Optional[int]      					= image_from_tuple[0, -3:, -3:, -1]

					assert image.shape == (2, 64, 64, 3)

					SCREAMING_SNAKE_CASE  :						int      					= np.array(
					    [
					        0.9997,
					        0.9989,
					        0.0008,
					        0.0021,
					        0.9960,
					        0.0018,
					        0.0014,
					        0.0002,
					        0.9933,
					    ]      )

					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 				lowercase__  (self : Optional[Any]      )     ->			Tuple:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						List[Any]      					= torch.device('''cpu'''      )


					class 	a__     :
						__magic_name__		:    int	    =     1



					SCREAMING_SNAKE_CASE  :						Any      					= self.get_dummy_components()

					SCREAMING_SNAKE_CASE  :						Any      					= self.pipeline_class(**__UpperCAmelCase      )
					SCREAMING_SNAKE_CASE  :						Optional[int]      					= pipe.to(__UpperCAmelCase      )

					pipe.set_progress_bar_config(disable=__UpperCAmelCase      )

					SCREAMING_SNAKE_CASE  :						Dict      					= torch.Generator(device=__UpperCAmelCase      ).manual_seed(0      )
					SCREAMING_SNAKE_CASE  :						str      					= pipe.decoder.dtype
					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= 1

					SCREAMING_SNAKE_CASE  :						Optional[int]      					= (
					    batch_size,
					    pipe.decoder.config.in_channels,
					    pipe.decoder.config.sample_size,
					    pipe.decoder.config.sample_size,
					)
					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= pipe.prepare_latents(
					    __UpperCAmelCase,					dtype=__UpperCAmelCase,					device=__UpperCAmelCase,					generator=__UpperCAmelCase,					latents=__UpperCAmelCase,					scheduler=DummyScheduler()      )

					SCREAMING_SNAKE_CASE  :						Tuple      					= (
					    batch_size,
					    pipe.super_res_first.config.in_channels // 2,
					    pipe.super_res_first.config.sample_size,
					    pipe.super_res_first.config.sample_size,
					)
					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= pipe.prepare_latents(
					    __UpperCAmelCase,					dtype=__UpperCAmelCase,					device=__UpperCAmelCase,					generator=__UpperCAmelCase,					latents=__UpperCAmelCase,					scheduler=DummyScheduler()      )

					SCREAMING_SNAKE_CASE  :						Dict      					= self.get_dummy_inputs(__UpperCAmelCase,					pil_image=__UpperCAmelCase      )

					SCREAMING_SNAKE_CASE  :						List[Any]      					= pipe(
					    **__UpperCAmelCase,					decoder_latents=__UpperCAmelCase,					super_res_latents=__UpperCAmelCase      ).images

					SCREAMING_SNAKE_CASE  :						Tuple      					= self.get_dummy_inputs(__UpperCAmelCase,					pil_image=__UpperCAmelCase      )
					# Don't pass image, instead pass embedding
					SCREAMING_SNAKE_CASE  :						Dict      					= pipeline_inputs.pop('''image'''      )
					SCREAMING_SNAKE_CASE  :						List[str]      					= pipe.image_encoder(__UpperCAmelCase      ).image_embeds

					SCREAMING_SNAKE_CASE  :						Optional[int]      					= pipe(
					    **__UpperCAmelCase,					decoder_latents=__UpperCAmelCase,					super_res_latents=__UpperCAmelCase,					image_embeddings=__UpperCAmelCase,					).images

					# make sure passing text embeddings manually is identical
					assert np.abs(img_out_a - img_out_a      ).max() < 1e-4


	@skip_mps
	def 				lowercase__  (self : Tuple      )     ->			Union[str, Any]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= torch_device == '''cpu'''

					# Check is relaxed because there is not a torch 2.0 sliced attention added kv processor
					SCREAMING_SNAKE_CASE  :						Dict      					= 1e-2

					self._test_attention_slicing_forward_pass(
					    test_max_difference=__UpperCAmelCase,					expected_max_diff=__UpperCAmelCase      )


	@skip_mps
	def 				lowercase__  (self : List[Any]      )     ->			Optional[Any]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Any      					= torch_device == '''cpu'''
					SCREAMING_SNAKE_CASE  :						Any      					= True
					SCREAMING_SNAKE_CASE  :						Optional[int]      					= [
					    '''decoder_num_inference_steps''',
					    '''super_res_num_inference_steps''',
					]

					self._test_inference_batch_single_identical(
					    test_max_difference=__UpperCAmelCase,					relax_max_difference=__UpperCAmelCase,					additional_params_copy_to_batched_inputs=__UpperCAmelCase,					)


	def 				lowercase__  (self : Any      )     ->			Tuple:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Any      					= [
					    '''decoder_num_inference_steps''',
					    '''super_res_num_inference_steps''',
					]

					if torch_device == "mps":
									# TODO: MPS errors with larger batch sizes
									SCREAMING_SNAKE_CASE  :						Optional[Any]      					= [2, 3]
									self._test_inference_batch_consistent(
									    batch_sizes=__UpperCAmelCase,					additional_params_copy_to_batched_inputs=__UpperCAmelCase,					)
					else:
									self._test_inference_batch_consistent(
									    additional_params_copy_to_batched_inputs=__UpperCAmelCase      )


	@skip_mps
	def 				lowercase__  (self : Tuple      )     ->			int:

					"""simple docstring"""

					return super().test_dict_tuple_outputs_equivalent()


	@skip_mps
	def 				lowercase__  (self : Any      )     ->			Union[str, Any]:

					"""simple docstring"""

					return super().test_save_load_local()






	@skip_mps
	def 				lowercase__  (self : Optional[Any]      )     ->			Any:

					"""simple docstring"""

					return super().test_save_load_optional_components()



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


	def 				lowercase__  (self : Optional[Any]      )     ->			Optional[int]:

					"""simple docstring"""

					super().tearDown()
					gc.collect()
					torch.cuda.empty_cache()






	def 				lowercase__  (self : str      )     ->			Optional[int]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Optional[int]      					= load_image(
					    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/unclip/cat.png'''      )
					SCREAMING_SNAKE_CASE  :						Any      					= load_numpy(
					    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
					    '''/unclip/karlo_v1_alpha_cat_variation_fp16.npy'''      )

					SCREAMING_SNAKE_CASE  :						List[Any]      					= UnCLIPImageVariationPipeline.from_pretrained(
					    '''kakaobrain/karlo-v1-alpha-image-variations''',					torch_dtype=torch.floataa      )
					SCREAMING_SNAKE_CASE  :						List[Any]      					= pipeline.to(__UpperCAmelCase      )
					pipeline.set_progress_bar_config(disable=__UpperCAmelCase      )

					SCREAMING_SNAKE_CASE  :						List[Any]      					= torch.Generator(device='''cpu'''      ).manual_seed(0      )
					SCREAMING_SNAKE_CASE  :						Dict      					= pipeline(
					    __UpperCAmelCase,					generator=__UpperCAmelCase,					output_type='''np''',					)

					SCREAMING_SNAKE_CASE  :						Any      					= output.images[0]

					assert image.shape == (256, 256, 3)

					assert_mean_pixel_difference(__UpperCAmelCase,					__UpperCAmelCase,					15      )









'''simple docstring'''

from manim import *


class 	a__     (				_lowercase	):


	def 				lowercase__  (self : Optional[Any]      )     ->			str:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						List[Any]      					= Rectangle(height=0.5,					width=0.5      )
					SCREAMING_SNAKE_CASE  :						str      					= Rectangle(height=0.46,					width=0.46      ).set_stroke(width=0      )

					SCREAMING_SNAKE_CASE  :						List[str]      					= [mem.copy() for i in range(6      )]
					SCREAMING_SNAKE_CASE  :						Optional[int]      					= [mem.copy() for i in range(6      )]
					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= VGroup(*__UpperCAmelCase      ).arrange(__UpperCAmelCase,					buff=0      )
					SCREAMING_SNAKE_CASE  :						List[str]      					= VGroup(*__UpperCAmelCase      ).arrange(__UpperCAmelCase,					buff=0      )
					SCREAMING_SNAKE_CASE  :						List[Any]      					= VGroup(__UpperCAmelCase,					__UpperCAmelCase      ).arrange(__UpperCAmelCase,					buff=0      )
					SCREAMING_SNAKE_CASE  :						Tuple      					= Text('''CPU''',					font_size=24      )
					SCREAMING_SNAKE_CASE  :						Dict      					= Group(__UpperCAmelCase,					__UpperCAmelCase      ).arrange(__UpperCAmelCase,					buff=0.5,					aligned_edge=__UpperCAmelCase      )
					cpu.move_to([-2.5, -0.5, 0]      )
					self.add(__UpperCAmelCase      )

					SCREAMING_SNAKE_CASE  :						Any      					= [mem.copy() for i in range(1      )]
					SCREAMING_SNAKE_CASE  :						Dict      					= VGroup(*__UpperCAmelCase      ).arrange(__UpperCAmelCase,					buff=0      )
					SCREAMING_SNAKE_CASE  :						List[str]      					= Text('''GPU''',					font_size=24      )
					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= Group(__UpperCAmelCase,					__UpperCAmelCase      ).arrange(__UpperCAmelCase,					buff=0.5,					aligned_edge=__UpperCAmelCase      )
					gpu.align_to(__UpperCAmelCase,					__UpperCAmelCase      )
					gpu.set_x(gpu.get_x() - 1      )

					self.add(__UpperCAmelCase      )

					SCREAMING_SNAKE_CASE  :						List[Any]      					= [mem.copy() for i in range(6      )]
					SCREAMING_SNAKE_CASE  :						Any      					= VGroup(*__UpperCAmelCase      ).arrange(__UpperCAmelCase,					buff=0      )

					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= Text('''Model''',					font_size=24      )
					SCREAMING_SNAKE_CASE  :						Dict      					= Group(__UpperCAmelCase,					__UpperCAmelCase      ).arrange(__UpperCAmelCase,					buff=0.5,					aligned_edge=__UpperCAmelCase      )
					model.move_to([3, -1.0, 0]      )

					self.play(
					    Create(__UpperCAmelCase,					run_time=1      ),					Create(__UpperCAmelCase,					run_time=1      ),					Create(__UpperCAmelCase,					run_time=1      ),					)

					SCREAMING_SNAKE_CASE  :						Tuple      					= MarkupText(
					    F'''First, an empty model skeleton is loaded\ninto <span fgcolor=\'{YELLOW}\'>memory</span> without using much RAM.''',					font_size=24,					)

					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= Square(side_length=2.2      )
					key.move_to([-5, 2, 0]      )

					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= MarkupText(
					    F'''<b>Key:</b>\n\n<span fgcolor=\'{YELLOW}\'>●</span> Empty Model''',					font_size=18,					)

					key_text.move_to([-5, 2.4, 0]      )

					step_a.move_to([2, 2, 0]      )
					self.play(Write(__UpperCAmelCase,					run_time=2.5      ),					Write(__UpperCAmelCase      ),					Write(__UpperCAmelCase      )      )

					self.add(__UpperCAmelCase      )

					SCREAMING_SNAKE_CASE  :						List[str]      					= []
					SCREAMING_SNAKE_CASE  :						List[str]      					= []
					SCREAMING_SNAKE_CASE  :						Dict      					= []
					for i, rect in enumerate(__UpperCAmelCase      ):
									SCREAMING_SNAKE_CASE  :						Optional[int]      					= Rectangle(height=0.46,					width=0.46      ).set_stroke(width=0.0      ).set_fill(__UpperCAmelCase,					opacity=0.7      )
									cpu_target.move_to(__UpperCAmelCase      )
									cpu_target.generate_target()
									SCREAMING_SNAKE_CASE  :						List[str]      					= 0.46 / 4
									SCREAMING_SNAKE_CASE  :						Any      					= 0.46 / 3

									if i == 0:
													cpu_target.target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT      ),					buff=0.02,					direction=__UpperCAmelCase      )
													cpu_target.target.set_x(cpu_target.target.get_x() + 0.1      )
									elif i == 3:
													cpu_target.target.next_to(cpu_targs[0].target,					direction=__UpperCAmelCase,					buff=0.0      )
									else:
													cpu_target.target.next_to(cpu_targs[i - 1].target,					direction=__UpperCAmelCase,					buff=0.0      )
									cpu_targs.append(__UpperCAmelCase      )

									first_animations.append(rect.animate(run_time=0.5      ).set_stroke(__UpperCAmelCase      )      )
									second_animations.append(MoveToTarget(__UpperCAmelCase,					run_time=1.5      )      )

					self.play(*__UpperCAmelCase      )
					self.play(*__UpperCAmelCase      )

					self.wait()




