


"""simple docstring"""


from __future__ import annotations

import collections
import tempfile
import unittest

import numpy as np

from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import is_tf_available, is_vision_available

from ...test_modeling_tf_common import floats_tensor, ids_tensor, random_attention_mask
from ..bert.test_modeling_tf_bert import TFBertModelTester
from ..clip.test_modeling_tf_clip import TFCLIPVisionModelTester
from ..deit.test_modeling_tf_deit import TFDeiTModelTester
from ..roberta.test_modeling_tf_roberta import TFRobertaModelTester
from ..vit.test_modeling_tf_vit import TFViTModelTester


if is_tf_available():
	from transformers import (
	    TFBertModel,
	    TFCLIPVisionModel,
	    TFDeiTModel,
	    TFRobertaModel,
	    TFVisionTextDualEncoderModel,
	    TFViTModel,
	    VisionTextDualEncoderConfig,
	)

if is_vision_available():
	from PIL import Image

	from transformers import VisionTextDualEncoderProcessor


def _lowerCamelCase			(	_UpperCamelCase   ):

			'''simple docstring'''




			if isinstance(_UpperCamelCase					,				collections.abc.Iterable   ):
						return x
			return (x, x)
@require_tf
class 						_UpperCamelCase						:
							'''simple docstring'''







							def     snake_case       (  self					,     __a					,     __a			):
										pass

							def     snake_case       (  self			):
										pass

							def     snake_case       (  self			):
										pass

							def     snake_case       (  self					,     __a					,     __a					,     __a					,     __a					,     __a=None					,     **__a			):
										__lowerCAmelCase       					=    VisionTextDualEncoderConfig.from_vision_text_configs(__a					,     __a			)

										__lowerCAmelCase       					=    TFVisionTextDualEncoderModel(__a			)

										__lowerCAmelCase       					=    model(input_ids=__a					,     pixel_values=__a					,     attention_mask=__a			)

										self.assertEqual(output["text_embeds"].shape					,     (input_ids.shape[0], config.projection_dim)			)
										self.assertEqual(output["image_embeds"].shape					,     (pixel_values.shape[0], config.projection_dim)			)

							def     snake_case       (  self					,     __a					,     __a					,     __a					,     __a					,     __a=None					,     **__a			):
										__lowerCAmelCase					,			__lowerCAmelCase       					=    self.get_vision_text_model(__a					,     __a			)
										__lowerCAmelCase       					=    TFVisionTextDualEncoderModel(vision_model=__a					,     text_model=__a			)

										__lowerCAmelCase       					=    model(input_ids=__a					,     pixel_values=__a					,     attention_mask=__a			)

										self.assertEqual(output["text_embeds"].shape					,     (input_ids.shape[0], model.config.projection_dim)			)
										self.assertEqual(output["image_embeds"].shape					,     (pixel_values.shape[0], model.config.projection_dim)			)

							def     snake_case       (  self					,     __a					,     __a					,     __a					,     __a					,     __a=None					,     **__a			):
										__lowerCAmelCase					,			__lowerCAmelCase       					=    self.get_vision_text_model(__a					,     __a			)
										__lowerCAmelCase       					=    {"vision_model": vision_model, "text_model": text_model}
										__lowerCAmelCase       					=    TFVisionTextDualEncoderModel.from_vision_text_pretrained(**__a			)

										__lowerCAmelCase       					=    model(input_ids=__a					,     pixel_values=__a					,     attention_mask=__a			)

										self.assertEqual(output["text_embeds"].shape					,     (input_ids.shape[0], model.config.projection_dim)			)
										self.assertEqual(output["image_embeds"].shape					,     (pixel_values.shape[0], model.config.projection_dim)			)

							def     snake_case       (  self					,     __a					,     __a					,     __a					,     __a					,     __a=None					,     **__a			):
										__lowerCAmelCase					,			__lowerCAmelCase       					=    self.get_vision_text_model(__a					,     __a			)
										__lowerCAmelCase       					=    TFVisionTextDualEncoderModel(vision_model=__a					,     text_model=__a			)

										__lowerCAmelCase       					=    model(input_ids=__a					,     pixel_values=__a					,     attention_mask=__a			)
										__lowerCAmelCase       					=    output[0].numpy()

										with tempfile.TemporaryDirectory() as tmpdirname:
													model.save_pretrained(__a			)
													__lowerCAmelCase       					=    TFVisionTextDualEncoderModel.from_pretrained(__a			)

													__lowerCAmelCase       					=    model(input_ids=__a					,     pixel_values=__a					,     attention_mask=__a			)
													__lowerCAmelCase       					=    after_output[0].numpy()
													__lowerCAmelCase       					=    np.amax(np.abs(out_a - out_a			)			)
													self.assertLessEqual(__a					,     1e-5			)

							def     snake_case       (  self					,     __a					,     __a					,     __a					,     __a					,     __a=None					,     **__a			):
										__lowerCAmelCase					,			__lowerCAmelCase       					=    self.get_vision_text_model(__a					,     __a			)
										__lowerCAmelCase       					=    TFVisionTextDualEncoderModel(vision_model=__a					,     text_model=__a			)

										__lowerCAmelCase       					=    model(
										    input_ids=__a					,     pixel_values=__a					,     attention_mask=__a					,     output_attentions=__a			)

										__lowerCAmelCase       					=    output.vision_model_output.attentions
										self.assertEqual(len(__a			)					,     vision_config.num_hidden_layers			)

										# in ViT, the seq_len equals the number of patches + 1 (we add 1 for the [CLS] token)
										__lowerCAmelCase       					=    to_atuple(vision_model.config.image_size			)
										__lowerCAmelCase       					=    to_atuple(vision_model.config.patch_size			)
										__lowerCAmelCase       					=    (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
										__lowerCAmelCase       					=    num_patches + 1
										self.assertEqual(vision_attentions[0].shape[-3:]					,     (vision_config.num_attention_heads, seq_len, seq_len)			)

										__lowerCAmelCase       					=    output.text_model_output.attentions
										self.assertEqual(len(__a			)					,     text_config.num_hidden_layers			)

										self.assertEqual(
										    text_attentions[0].shape[-3:]					,     (text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])					,     )

							def     snake_case       (  self					,     __a					,     __a					,     __a			):
										__lowerCAmelCase       					=    np.abs((a - b)			).max()
										self.assertLessEqual(__a					,     __a					,     f"Difference between torch and flax is {diff} (>= {tol})."			)

							def     snake_case       (  self			):
										__lowerCAmelCase       					=    self.prepare_config_and_inputs()
										self.check_vision_text_dual_encoder_model(**__a			)

							def     snake_case       (  self			):
										__lowerCAmelCase       					=    self.prepare_config_and_inputs()
										self.check_model_from_pretrained_configs(**__a			)

							def     snake_case       (  self			):
										__lowerCAmelCase       					=    self.prepare_config_and_inputs()
										self.check_vision_text_dual_encoder_from_pretrained(**__a			)

							def     snake_case       (  self			):
										__lowerCAmelCase       					=    self.prepare_config_and_inputs()
										self.check_save_load(**__a			)

							def     snake_case       (  self			):
										__lowerCAmelCase       					=    self.prepare_config_and_inputs()
										self.check_vision_text_output_attention(**__a			)



							@slow
							def     snake_case       (  self			):
										__lowerCAmelCase					,			__lowerCAmelCase       					=    self.get_pretrained_model_and_inputs()

										__lowerCAmelCase       					=    model_a(**__a			)
										__lowerCAmelCase       					=    outputs[0].numpy()

										with tempfile.TemporaryDirectory() as tmp_dirname:
													model_a.save_pretrained(__a			)
													__lowerCAmelCase       					=    TFVisionTextDualEncoderModel.from_pretrained(__a			)

													__lowerCAmelCase       					=    model_a(**__a			)
													__lowerCAmelCase       					=    after_outputs[0].numpy()
													__lowerCAmelCase       					=    np.amax(np.abs(out_a - out_a			)			)
													self.assertLessEqual(__a					,     1e-5			)
@require_tf
class 						_UpperCamelCase						(     lowerCAmelCase__ ,unittest.TestCase	):
							'''simple docstring'''







							def     snake_case       (  self			):
										__lowerCAmelCase       					=    TFVisionTextDualEncoderModel.from_vision_text_pretrained(
										    "hf-internal-testing/tiny-random-vit"					,     "hf-internal-testing/tiny-random-bert"			)
										__lowerCAmelCase       					=    13
										__lowerCAmelCase       					=    floats_tensor(
										    [
										        batch_size,
										        model.vision_model.config.num_channels,
										        model.vision_model.config.image_size,
										        model.vision_model.config.image_size,
										    ]			)
										__lowerCAmelCase       					=    ids_tensor([batch_size, 4]					,     model.text_model.config.vocab_size			)
										__lowerCAmelCase       					=    random_attention_mask([batch_size, 4]			)
										__lowerCAmelCase       					=    {"pixel_values": pixel_values, "input_ids": input_ids, "attention_mask": attention_mask}

										return model, inputs

							def     snake_case       (  self					,     __a					,     __a			):
										__lowerCAmelCase       					=    TFViTModel(__a					,     name="vision_model"			)
										__lowerCAmelCase       					=    TFBertModel(__a					,     name="text_model"			)
										return vision_model, text_model



							def     snake_case       (  self			):
										__lowerCAmelCase       					=    TFViTModelTester(self			)
										__lowerCAmelCase       					=    TFBertModelTester(self			)
										__lowerCAmelCase       					=    vit_model_tester.prepare_config_and_inputs()
										__lowerCAmelCase       					=    bert_model_tester.prepare_config_and_inputs()

										__lowerCAmelCase					,			__lowerCAmelCase					,			__lowerCAmelCase       					=    vision_config_and_inputs

										(
										    (
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,						
										)       					=    text_config_and_inputs

										return {
										    "text_config": text_config,
										    "vision_config": vision_config,
										    "pixel_values": pixel_values,
										    "attention_mask": input_mask,
										    "input_ids": input_ids,
										    "text_token_type_ids": token_type_ids,
										    "text_sequence_labels": sequence_labels,
										    "text_token_labels": token_labels,
										    "text_choice_labels": choice_labels,
										}
@require_tf
class 						_UpperCamelCase						(     lowerCAmelCase__ ,unittest.TestCase	):
							'''simple docstring'''







							def     snake_case       (  self			):
										# DeiT repo doesn't have TF weights, but we don't actually use the weights at all so let's
										# just reinitialize it.
										__lowerCAmelCase       					=    TFVisionTextDualEncoderModel.from_vision_text_pretrained(
										    "Rocketknight1/tiny-random-deit-tf"					,     "hf-internal-testing/tiny-random-roberta"			)
										__lowerCAmelCase       					=    13
										__lowerCAmelCase       					=    floats_tensor(
										    [
										        batch_size,
										        model.vision_model.config.num_channels,
										        model.vision_model.config.image_size,
										        model.vision_model.config.image_size,
										    ]			)
										__lowerCAmelCase       					=    ids_tensor([batch_size, 4]					,     model.text_model.config.vocab_size			)
										__lowerCAmelCase       					=    random_attention_mask([batch_size, 4]			)
										__lowerCAmelCase       					=    {"pixel_values": pixel_values, "input_ids": input_ids, "attention_mask": attention_mask}

										return model, inputs

							def     snake_case       (  self					,     __a					,     __a					,     __a					,     __a					,     __a=None					,     **__a			):
										__lowerCAmelCase					,			__lowerCAmelCase       					=    self.get_vision_text_model(__a					,     __a			)
										__lowerCAmelCase       					=    TFVisionTextDualEncoderModel(vision_model=__a					,     text_model=__a			)

										__lowerCAmelCase       					=    model(
										    input_ids=__a					,     pixel_values=__a					,     attention_mask=__a					,     output_attentions=__a			)

										__lowerCAmelCase       					=    output.vision_model_output.attentions
										self.assertEqual(len(__a			)					,     vision_config.num_hidden_layers			)

										# in DEiT, the seq_len equals the number of patches + 2 (we add 2 for the [CLS] and distillation tokens)
										__lowerCAmelCase       					=    to_atuple(vision_model.config.image_size			)
										__lowerCAmelCase       					=    to_atuple(vision_model.config.patch_size			)
										__lowerCAmelCase       					=    (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
										__lowerCAmelCase       					=    num_patches + 2
										self.assertEqual(vision_attentions[0].shape[-3:]					,     (vision_config.num_attention_heads, seq_len, seq_len)			)

										__lowerCAmelCase       					=    output.text_model_output.attentions
										self.assertEqual(len(__a			)					,     text_config.num_hidden_layers			)

										self.assertEqual(
										    text_attentions[0].shape[-3:]					,     (text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])					,     )

							def     snake_case       (  self					,     __a					,     __a			):
										__lowerCAmelCase       					=    TFDeiTModel(__a					,     name="vision_model"			)
										__lowerCAmelCase       					=    TFRobertaModel(__a					,     name="text_model"			)
										return vision_model, text_model



							def     snake_case       (  self			):
										__lowerCAmelCase       					=    TFDeiTModelTester(self			)
										__lowerCAmelCase       					=    TFRobertaModelTester(self			)
										__lowerCAmelCase       					=    vit_model_tester.prepare_config_and_inputs()
										__lowerCAmelCase       					=    bert_model_tester.prepare_config_and_inputs()

										__lowerCAmelCase					,			__lowerCAmelCase					,			__lowerCAmelCase       					=    vision_config_and_inputs

										(
										    (
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,						
										)       					=    text_config_and_inputs

										return {
										    "text_config": text_config,
										    "vision_config": vision_config,
										    "pixel_values": pixel_values,
										    "attention_mask": input_mask,
										    "input_ids": input_ids,
										    "text_token_type_ids": token_type_ids,
										    "text_sequence_labels": sequence_labels,
										    "text_token_labels": token_labels,
										    "text_choice_labels": choice_labels,
										}
@require_tf
class 						_UpperCamelCase						(     lowerCAmelCase__ ,unittest.TestCase	):
							'''simple docstring'''







							def     snake_case       (  self			):
										__lowerCAmelCase       					=    TFVisionTextDualEncoderModel.from_vision_text_pretrained(
										    "Rocketknight1/tiny-random-clip-tf"					,     "hf-internal-testing/tiny-random-bert"			)
										__lowerCAmelCase       					=    13
										__lowerCAmelCase       					=    floats_tensor(
										    [
										        batch_size,
										        model.vision_model.config.num_channels,
										        model.vision_model.config.image_size,
										        model.vision_model.config.image_size,
										    ]			)
										__lowerCAmelCase       					=    ids_tensor([batch_size, 4]					,     model.text_model.config.vocab_size			)
										__lowerCAmelCase       					=    random_attention_mask([batch_size, 4]			)
										__lowerCAmelCase       					=    {"pixel_values": pixel_values, "input_ids": input_ids, "attention_mask": attention_mask}

										return model, inputs

							def     snake_case       (  self					,     __a					,     __a			):
										__lowerCAmelCase       					=    TFCLIPVisionModel(__a					,     name="vision_model"			)
										__lowerCAmelCase       					=    TFBertModel(__a					,     name="text_model"			)
										return vision_model, text_model



							def     snake_case       (  self			):
										__lowerCAmelCase       					=    TFCLIPVisionModelTester(self			)
										__lowerCAmelCase       					=    TFBertModelTester(self			)
										__lowerCAmelCase       					=    clip_model_tester.prepare_config_and_inputs()
										__lowerCAmelCase       					=    bert_model_tester.prepare_config_and_inputs()

										__lowerCAmelCase					,			__lowerCAmelCase       					=    vision_config_and_inputs

										(
										    (
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,			(
										    __lowerCAmelCase			
										)					,						
										)       					=    text_config_and_inputs

										return {
										    "text_config": text_config,
										    "vision_config": vision_config,
										    "pixel_values": pixel_values,
										    "attention_mask": input_mask,
										    "input_ids": input_ids,
										    "text_token_type_ids": token_type_ids,
										    "text_sequence_labels": sequence_labels,
										    "text_token_labels": token_labels,
										    "text_choice_labels": choice_labels,
										}
@require_vision
@require_tf
class 						_UpperCamelCase						(     unittest.TestCase	):
							'''simple docstring'''







							@slow
							def     snake_case       (  self			):
										__lowerCAmelCase       					=    TFVisionTextDualEncoderModel.from_pretrained(
										    "clip-italian/clip-italian"					,     logit_scale_init_value=1.0					,     from_pt=__a			)
										__lowerCAmelCase       					=    VisionTextDualEncoderProcessor.from_pretrained("clip-italian/clip-italian"			)

										__lowerCAmelCase       					=    Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"			)
										__lowerCAmelCase       					=    processor(
										    text=["una foto di un gatto", "una foto di un cane"]					,     images=__a					,     padding=__a					,     return_tensors="np"			)

										__lowerCAmelCase       					=    model(**__a			)

										# verify the logits
										self.assertEqual(outputs.logits_per_image.shape					,     (inputs.pixel_values.shape[0], inputs.input_ids.shape[0])			)
										self.assertEqual(
										    outputs.logits_per_text.shape					,     (inputs.input_ids.shape[0], inputs.pixel_values.shape[0])					,     )

										__lowerCAmelCase       					=    np.array([[1.2_2_8_4_7_2_7, 0.3_1_0_4_1_2_2]]			)

										self.assertTrue(np.allclose(outputs.logits_per_image.numpy()					,     __a					,     atol=1e-3			)			)








"""simple docstring"""


from manim import *
class 						_UpperCamelCase						(     lowerCAmelCase__	):
							'''simple docstring'''







							def     snake_case       (  self			):
										__lowerCAmelCase       					=    Rectangle(height=0.5					,     width=0.5			)
										__lowerCAmelCase       					=    Rectangle(height=0.4_6					,     width=0.4_6			).set_stroke(width=0			)

										__lowerCAmelCase       					=    Rectangle(height=0.2_5					,     width=0.2_5			)

										__lowerCAmelCase       					=    [mem.copy() for i in range(6			)]
										__lowerCAmelCase       					=    [mem.copy() for i in range(6			)]
										__lowerCAmelCase       					=    VGroup(*__a			).arrange(__a					,     buff=0			)
										__lowerCAmelCase       					=    VGroup(*__a			).arrange(__a					,     buff=0			)
										__lowerCAmelCase       					=    VGroup(__a					,     __a			).arrange(__a					,     buff=0			)
										__lowerCAmelCase       					=    Text("CPU"					,     font_size=24			)
										__lowerCAmelCase       					=    Group(__a					,     __a			).arrange(__a					,     buff=0.5					,     aligned_edge=__a			)
										cpu.move_to([-2.5, -0.5, 0]			)
										self.add(__a			)

										__lowerCAmelCase       					=    [mem.copy() for i in range(4			)]
										__lowerCAmelCase       					=    VGroup(*__a			).arrange(__a					,     buff=0			)
										__lowerCAmelCase       					=    Text("GPU"					,     font_size=24			)
										__lowerCAmelCase       					=    Group(__a					,     __a			).arrange(__a					,     buff=0.5					,     aligned_edge=__a			)
										gpu.move_to([-1, -1, 0]			)
										self.add(__a			)

										__lowerCAmelCase       					=    [mem.copy() for i in range(6			)]
										__lowerCAmelCase       					=    VGroup(*__a			).arrange(__a					,     buff=0			)

										__lowerCAmelCase       					=    Text("Model"					,     font_size=24			)
										__lowerCAmelCase       					=    Group(__a					,     __a			).arrange(__a					,     buff=0.5					,     aligned_edge=__a			)
										model.move_to([3, -1.0, 0]			)
										self.add(__a			)

										__lowerCAmelCase       					=    []
										__lowerCAmelCase       					=    []

										for i, rect in enumerate(__a			):
													__lowerCAmelCase       					=    fill.copy().set_fill(__a					,     opacity=0.8			)
													target.move_to(__a			)
													model_arr.append(__a			)

													__lowerCAmelCase       					=    Rectangle(height=0.4_6					,     width=0.4_6			).set_stroke(width=0.0			).set_fill(__a					,     opacity=0.8			)
													cpu_target.move_to(cpu_left_col_base[i]			)
													model_cpu_arr.append(__a			)

										self.add(*__a					,     *__a			)

										__lowerCAmelCase       					=    [meta_mem.copy() for i in range(6			)]
										__lowerCAmelCase       					=    [meta_mem.copy() for i in range(6			)]
										__lowerCAmelCase       					=    VGroup(*__a			).arrange(__a					,     buff=0			)
										__lowerCAmelCase       					=    VGroup(*__a			).arrange(__a					,     buff=0			)
										__lowerCAmelCase       					=    VGroup(__a					,     __a			).arrange(__a					,     buff=0			)
										__lowerCAmelCase       					=    Text("Disk"					,     font_size=24			)
										__lowerCAmelCase       					=    Group(__a					,     __a			).arrange(__a					,     buff=0.5					,     aligned_edge=__a			)
										disk.move_to([-4, -1.2_5, 0]			)
										self.add(__a					,     __a			)

										__lowerCAmelCase       					=    Square(side_length=2.2			)
										key.move_to([-5, 2, 0]			)

										__lowerCAmelCase       					=    MarkupText(
										    f"<b>Key:</b>\n\n<span fgcolor='{YELLOW}'>●</span> Empty Model"					,     font_size=18					,     )

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

										self.add(__a					,     __a			)

										__lowerCAmelCase       					=    MarkupText(
										    f"<span fgcolor='{BLUE}'>●</span> Checkpoint"					,     font_size=18					,     )

										blue_text.next_to(__a					,     DOWN * 2.4					,     aligned_edge=key_text.get_left()			)
										self.add(__a			)

										__lowerCAmelCase       					=    MarkupText(
										    f"Now watch as an input is passed through the model\nand how the memory is utilized and handled."					,     font_size=24					,     )
										step_a.move_to([2, 2, 0]			)

										self.play(Write(__a			)			)

										__lowerCAmelCase       					=    Square(0.3			)
										input.set_fill(__a					,     opacity=1.0			)
										input.set_stroke(width=0.0			)
										input.next_to(model_base[0]					,     __a					,     buff=0.5			)

										self.play(Write(__a			)			)

										input.generate_target()
										input.target.next_to(model_arr[0]					,     direction=__a					,     buff=0.0_2			)
										self.play(MoveToTarget(__a			)			)

										self.play(FadeOut(__a			)			)

										__lowerCAmelCase       					=    Arrow(start=__a					,     end=__a					,     color=__a					,     buff=0.5			)
										a.next_to(model_arr[0].get_left()					,     __a					,     buff=0.2			)

										model_cpu_arr[0].generate_target()
										model_cpu_arr[0].target.move_to(gpu_rect[0]			)

										__lowerCAmelCase       					=    MarkupText(
										    f"As the input reaches a layer, the hook triggers\nand weights are moved from the CPU\nto the GPU and back."					,     font_size=24					,     )
										step_a.move_to([2, 2, 0]			)

										self.play(Write(__a					,     run_time=3			)			)

										__lowerCAmelCase       					=    {"run_time": 1, "fade_in": True, "fade_out": True, "buff": 0.0_2}

										self.play(
										    Write(__a			)					,     Circumscribe(model_arr[0]					,     color=__a					,     **__a			)					,     Circumscribe(model_cpu_arr[0]					,     color=__a					,     **__a			)					,     Circumscribe(gpu_rect[0]					,     color=__a					,     **__a			)					,     )
										self.play(MoveToTarget(model_cpu_arr[0]			)			)

										__lowerCAmelCase       					=    a.copy()
										for i in range(6			):
													a_c.next_to(model_arr[i].get_right() + 0.0_2					,     __a					,     buff=0.2			)

													input.generate_target()
													input.target.move_to(model_arr[i].get_right() + 0.0_2			)

													__lowerCAmelCase       					=    AnimationGroup(
													    FadeOut(__a					,     run_time=0.5			)					,     MoveToTarget(__a					,     run_time=0.5			)					,     FadeIn(__a					,     run_time=0.5			)					,     lag_ratio=0.2			)

													self.play(__a			)

													model_cpu_arr[i].generate_target()
													model_cpu_arr[i].target.move_to(cpu_left_col_base[i]			)

													if i < 5:
																model_cpu_arr[i + 1].generate_target()
																model_cpu_arr[i + 1].target.move_to(gpu_rect[0]			)
																if i >= 1:
																			__lowerCAmelCase       					=    0.7

																self.play(
																    Circumscribe(model_arr[i]					,     **__a			)					,     Circumscribe(cpu_left_col_base[i]					,     **__a			)					,     Circumscribe(cpu_left_col_base[i + 1]					,     color=__a					,     **__a			)					,     Circumscribe(gpu_rect[0]					,     color=__a					,     **__a			)					,     Circumscribe(model_arr[i + 1]					,     color=__a					,     **__a			)					,     )
																if i < 1:
																			self.play(
																			    MoveToTarget(model_cpu_arr[i]			)					,     MoveToTarget(model_cpu_arr[i + 1]			)					,     )
																else:
																			self.play(
																			    MoveToTarget(model_cpu_arr[i]					,     run_time=0.7			)					,     MoveToTarget(model_cpu_arr[i + 1]					,     run_time=0.7			)					,     )
													else:
																model_cpu_arr[i].generate_target()
																model_cpu_arr[i].target.move_to(cpu_left_col_base[-1]			)
																input.generate_target()
																input.target.next_to(model_arr[-1].get_right()					,     RIGHT + 0.0_2					,     buff=0.2			)

																self.play(
																    Circumscribe(model_arr[-1]					,     color=__a					,     **__a			)					,     Circumscribe(cpu_left_col_base[-1]					,     color=__a					,     **__a			)					,     Circumscribe(gpu_rect[0]					,     color=__a					,     **__a			)					,     )

																self.play(MoveToTarget(model_cpu_arr[i]			)			)

													__lowerCAmelCase       					=    a_c
													__lowerCAmelCase       					=    a_c.copy()

										input.generate_target()
										input.target.next_to(model_base[-1]					,     RIGHT + 0.0_2					,     buff=0.5			)
										self.play(
										    FadeOut(__a			)					,     FadeOut(__a					,     run_time=0.5			)					,     )

										__lowerCAmelCase       					=    MarkupText(f"Inference on a model too large for GPU memory\nis successfully completed."					,     font_size=24			)
										step_a.move_to([2, 2, 0]			)

										self.play(Write(__a					,     run_time=3			)					,     MoveToTarget(__a			)			)

										self.wait()




