


import copy
import unittest

from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch

						from transformers import (
						    MODEL_FOR_MULTIPLE_CHOICE_MAPPING,
						    MODEL_FOR_QUESTION_ANSWERING_MAPPING,
						    MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
						    MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
						    LayoutLMvaConfig,
						    LayoutLMvaForQuestionAnswering,
						    LayoutLMvaForSequenceClassification,
						    LayoutLMvaForTokenClassification,
						    LayoutLMvaModel,
						)
						from transformers.models.layoutlmva.modeling_layoutlmva import LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
						from PIL import Image

						from transformers import LayoutLMvaImageProcessor







class 				snake_case__:







						'''simple docstring'''




						def __init__(				self   ,						__lowercase   ,						__lowercase=2   ,						__lowercase=3   ,						__lowercase=4   ,						__lowercase=2   ,						__lowercase=7   ,						__lowercase=True   ,						__lowercase=True   ,						__lowercase=True   ,						__lowercase=True   ,						__lowercase=9_9   ,						__lowercase=3_6   ,						__lowercase=3   ,						__lowercase=4   ,						__lowercase=3_7   ,						__lowercase="gelu"   ,						__lowercase=0.1   ,						__lowercase=0.1   ,						__lowercase=5_1_2   ,						__lowercase=1_6   ,						__lowercase=2   ,						__lowercase=0.02   ,						__lowercase=6   ,						__lowercase=6   ,						__lowercase=3   ,						__lowercase=4   ,						__lowercase=None   ,						__lowercase=1_0_0_0   ,						)					->    Tuple:
										lowerCAmelCase_ :      List[Any]    				=				parent
										lowerCAmelCase_ :      Optional[int]    				=				batch_size
										lowerCAmelCase_ :      Union[str, Any]    				=				num_channels
										lowerCAmelCase_ :      str    				=				image_size
										lowerCAmelCase_ :      int    				=				patch_size
										lowerCAmelCase_ :      List[Any]    				=				text_seq_length
										lowerCAmelCase_ :      str    				=				is_training
										lowerCAmelCase_ :      Any    				=				use_input_mask
										lowerCAmelCase_ :      int    				=				use_token_type_ids
										lowerCAmelCase_ :      str    				=				use_labels
										lowerCAmelCase_ :      Optional[Any]    				=				vocab_size
										lowerCAmelCase_ :      int    				=				hidden_size
										lowerCAmelCase_ :      List[str]    				=				num_hidden_layers
										lowerCAmelCase_ :      Any    				=				num_attention_heads
										lowerCAmelCase_ :      Optional[int]    				=				intermediate_size
										lowerCAmelCase_ :      int    				=				hidden_act
										lowerCAmelCase_ :      List[str]    				=				hidden_dropout_prob
										lowerCAmelCase_ :      List[str]    				=				attention_probs_dropout_prob
										lowerCAmelCase_ :      Union[str, Any]    				=				max_position_embeddings
										lowerCAmelCase_ :      Dict    				=				type_vocab_size
										lowerCAmelCase_ :      Union[str, Any]    				=				type_sequence_label_size
										lowerCAmelCase_ :      Union[str, Any]    				=				initializer_range
										lowerCAmelCase_ :      int    				=				coordinate_size
										lowerCAmelCase_ :      List[Any]    				=				shape_size
										lowerCAmelCase_ :      Union[str, Any]    				=				num_labels
										lowerCAmelCase_ :      str    				=				num_choices
										lowerCAmelCase_ :      List[Any]    				=				scope
										lowerCAmelCase_ :      int    				=				range_bbox

										# LayoutLMv3's sequence length equals the number of text tokens + number of patches + 1 (we add 1 for the CLS token)
										lowerCAmelCase_ :      Any    				=				text_seq_length
										lowerCAmelCase_ :      str    				=				(image_size // patch_size) ** 2 + 1
										lowerCAmelCase_ :      Optional[Any]    				=				self.text_seq_length + self.image_seq_length




						def 						lowercase_ (				self							)					->    str:
										lowerCAmelCase_ :      Dict    				=				ids_tensor([self.batch_size, self.text_seq_length]   ,						self.vocab_size							)

										lowerCAmelCase_ :      str    				=				ids_tensor([self.batch_size, self.text_seq_length, 4]   ,						self.range_bbox							)
										# Ensure that bbox is legal
										for i in range(bbox.shape[0]							):
														for j in range(bbox.shape[1]							):
																		if bbox[i, j, 3] < bbox[i, j, 1]:
																						lowerCAmelCase_ :      Optional[int]    				=				bbox[i, j, 3]
																						lowerCAmelCase_ :      List[Any]    				=				bbox[i, j, 1]
																						lowerCAmelCase_ :      int    				=				t
																		if bbox[i, j, 2] < bbox[i, j, 0]:
																						lowerCAmelCase_ :      int    				=				bbox[i, j, 2]
																						lowerCAmelCase_ :      Optional[int]    				=				bbox[i, j, 0]
																						lowerCAmelCase_ :      List[str]    				=				t

										lowerCAmelCase_ :      List[Any]    				=				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

										lowerCAmelCase_ :      Union[str, Any]    				=				None
										if self.use_input_mask:
														lowerCAmelCase_ :      Tuple    				=				random_attention_mask([self.batch_size, self.text_seq_length]							)

										lowerCAmelCase_ :      Union[str, Any]    				=				None
										if self.use_token_type_ids:
														lowerCAmelCase_ :      List[Any]    				=				ids_tensor([self.batch_size, self.text_seq_length]   ,						self.type_vocab_size							)

										lowerCAmelCase_ :      Any    				=				None
										lowerCAmelCase_ :      int    				=				None
										if self.use_labels:
														lowerCAmelCase_ :      Union[str, Any]    				=				ids_tensor([self.batch_size]   ,						self.type_sequence_label_size							)
														lowerCAmelCase_ :      int    				=				ids_tensor([self.batch_size, self.text_seq_length]   ,						self.num_labels							)

										lowerCAmelCase_ :      Optional[int]    				=				LayoutLMvaConfig(
										    vocab_size=self.vocab_size   ,						hidden_size=self.hidden_size   ,						num_hidden_layers=self.num_hidden_layers   ,						num_attention_heads=self.num_attention_heads   ,						intermediate_size=self.intermediate_size   ,						hidden_act=self.hidden_act   ,						hidden_dropout_prob=self.hidden_dropout_prob   ,						attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,						max_position_embeddings=self.max_position_embeddings   ,						type_vocab_size=self.type_vocab_size   ,						initializer_range=self.initializer_range   ,						coordinate_size=self.coordinate_size   ,						shape_size=self.shape_size   ,						input_size=self.image_size   ,						patch_size=self.patch_size   ,						)

										return config, input_ids, bbox, pixel_values, token_type_ids, input_mask, sequence_labels, token_labels




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase							)					->    int:
										lowerCAmelCase_ :      str    				=				LayoutLMvaModel(config=__lowercase							)
										model.to(__lowercase							)
										model.eval()

										# text + image
										lowerCAmelCase_ :      Optional[Any]    				=				model(__lowercase   ,						pixel_values=__lowercase							)
										lowerCAmelCase_ :      Dict    				=				model(
										    __lowercase   ,						bbox=__lowercase   ,						pixel_values=__lowercase   ,						attention_mask=__lowercase   ,						token_type_ids=__lowercase							)
										lowerCAmelCase_ :      Dict    				=				model(__lowercase   ,						bbox=__lowercase   ,						pixel_values=__lowercase   ,						token_type_ids=__lowercase							)
										lowerCAmelCase_ :      List[str]    				=				model(__lowercase   ,						bbox=__lowercase   ,						pixel_values=__lowercase							)

										self.parent.assertEqual(result.last_hidden_state.shape   ,						(self.batch_size, self.seq_length, self.hidden_size)							)

										# text only
										lowerCAmelCase_ :      Optional[Any]    				=				model(__lowercase							)
										self.parent.assertEqual(
										    result.last_hidden_state.shape   ,						(self.batch_size, self.text_seq_length, self.hidden_size)							)

										# image only
										lowerCAmelCase_ :      Tuple    				=				model(pixel_values=__lowercase							)
										self.parent.assertEqual(
										    result.last_hidden_state.shape   ,						(self.batch_size, self.image_seq_length, self.hidden_size)							)




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase							)					->    List[Any]:
										lowerCAmelCase_ :      Dict    				=				self.num_labels
										lowerCAmelCase_ :      str    				=				LayoutLMvaForSequenceClassification(__lowercase							)
										model.to(__lowercase							)
										model.eval()
										lowerCAmelCase_ :      List[Any]    				=				model(
										    __lowercase   ,						bbox=__lowercase   ,						pixel_values=__lowercase   ,						attention_mask=__lowercase   ,						token_type_ids=__lowercase   ,						labels=__lowercase   ,						)
										self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.num_labels)							)




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase							)					->    Optional[int]:
										lowerCAmelCase_ :      Optional[Any]    				=				self.num_labels
										lowerCAmelCase_ :      Union[str, Any]    				=				LayoutLMvaForTokenClassification(config=__lowercase							)
										model.to(__lowercase							)
										model.eval()
										lowerCAmelCase_ :      Tuple    				=				model(
										    __lowercase   ,						bbox=__lowercase   ,						pixel_values=__lowercase   ,						attention_mask=__lowercase   ,						token_type_ids=__lowercase   ,						labels=__lowercase   ,						)
										self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.text_seq_length, self.num_labels)							)




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase							)					->    Any:
										lowerCAmelCase_ :      List[Any]    				=				LayoutLMvaForQuestionAnswering(config=__lowercase							)
										model.to(__lowercase							)
										model.eval()
										lowerCAmelCase_ :      Optional[Any]    				=				model(
										    __lowercase   ,						bbox=__lowercase   ,						pixel_values=__lowercase   ,						attention_mask=__lowercase   ,						token_type_ids=__lowercase   ,						start_positions=__lowercase   ,						end_positions=__lowercase   ,						)
										self.parent.assertEqual(result.start_logits.shape   ,						(self.batch_size, self.seq_length)							)
										self.parent.assertEqual(result.end_logits.shape   ,						(self.batch_size, self.seq_length)							)




						def 						lowercase_ (				self							)					->    Tuple:
										lowerCAmelCase_ :      Optional[int]    				=				self.prepare_config_and_inputs()
										(
										    (
										    lowerCAmelCase_       
										)				,  (
										    lowerCAmelCase_       
										)				,  (
										    lowerCAmelCase_       
										)				,  (
										    lowerCAmelCase_       
										)				,  (
										    lowerCAmelCase_       
										)				,  (
										    lowerCAmelCase_       
										)				,  (
										    lowerCAmelCase_       
										)				,  (
										    lowerCAmelCase_       
										)				,         
										) :      Any    				=				config_and_inputs
										lowerCAmelCase_ :      Optional[int]    				=				{
										    '''input_ids''': input_ids,
										    '''bbox''': bbox,
										    '''pixel_values''': pixel_values,
										    '''token_type_ids''': token_type_ids,
										    '''attention_mask''': input_mask,
										}
										return config, inputs_dict







@require_torch
class 				snake_case__(							UpperCamelCase__,						UpperCamelCase__,						unittest.TestCase							):







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__      :  Dict					=							False
						SCREAMING_SNAKE_CASE__      :  List[Any]					=							False
						SCREAMING_SNAKE_CASE__      :  Optional[Any]					=							False

						SCREAMING_SNAKE_CASE__      :  Optional[int]					=							(
						    (
						        LayoutLMvaModel,
						        LayoutLMvaForSequenceClassification,
						        LayoutLMvaForTokenClassification,
						        LayoutLMvaForQuestionAnswering,
						    )
						    if is_torch_available()
						    else ()
						)
						SCREAMING_SNAKE_CASE__      :  List[str]					=							(
						    {"""document-question-answering""": LayoutLMvaForQuestionAnswering, """feature-extraction""": LayoutLMvaModel}
						    if is_torch_available()
						    else {}
						)




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase   ,						__lowercase							)					->    Tuple:
										# `DocumentQuestionAnsweringPipeline` is expected to work with this model, but it combines the text and visual
										# embedding along the sequence dimension (dim 1), which causes an error during post-processing as `p_mask` has
										# the sequence dimension of the text embedding only.
										# (see the line `embedding_output = torch.cat([embedding_output, visual_embeddings], dim=1)`)
										return True




						def 						lowercase_ (				self							)					->    List[str]:
										lowerCAmelCase_ :      Optional[int]    				=				LayoutLMvaModelTester(self							)
										lowerCAmelCase_ :      List[str]    				=				ConfigTester(self   ,						config_class=__lowercase   ,						hidden_size=3_7							)




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase   ,						__lowercase=False							)					->    str:
										lowerCAmelCase_ :      Any    				=				copy.deepcopy(__lowercase							)
										if model_class in get_values(__lowercase							):
														lowerCAmelCase_ :      List[str]    				=				{
														    k: v.unsqueeze(1							).expand(-1   ,						self.model_tester.num_choices   ,						-1							).contiguous()
														    if isinstance(__lowercase   ,						torch.Tensor							) and v.ndim > 1
														    else v
														    for k, v in inputs_dict.items()
														}
										if return_labels:
														if model_class in get_values(__lowercase							):
																		lowerCAmelCase_ :      Dict    				=				torch.ones(self.model_tester.batch_size   ,						dtype=torch.long   ,						device=__lowercase							)
														elif model_class in get_values(__lowercase							):
																		lowerCAmelCase_ :      Tuple    				=				torch.zeros(
																		    self.model_tester.batch_size   ,						dtype=torch.long   ,						device=__lowercase							)
																		lowerCAmelCase_ :      List[str]    				=				torch.zeros(
																		    self.model_tester.batch_size   ,						dtype=torch.long   ,						device=__lowercase							)
														elif model_class in [
														    *get_values(__lowercase							),
														]:
																		lowerCAmelCase_ :      List[Any]    				=				torch.zeros(
																		    self.model_tester.batch_size   ,						dtype=torch.long   ,						device=__lowercase							)
														elif model_class in [
														    *get_values(__lowercase							),
														]:
																		lowerCAmelCase_ :      Any    				=				torch.zeros(
																		    (self.model_tester.batch_size, self.model_tester.text_seq_length)   ,						dtype=torch.long   ,						device=__lowercase   ,						)

										return inputs_dict




						def 						lowercase_ (				self							)					->    List[str]:
										self.config_tester.run_common_tests()




						def 						lowercase_ (				self							)					->    Union[str, Any]:
										lowerCAmelCase_ :      Union[str, Any]    				=				self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*__lowercase							)




						def 						lowercase_ (				self							)					->    Dict:
										lowerCAmelCase_ :      Dict    				=				self.model_tester.prepare_config_and_inputs()
										for type in ["absolute", "relative_key", "relative_key_query"]:
														lowerCAmelCase_ :      str    				=				type
														self.model_tester.create_and_check_model(*__lowercase							)




						def 						lowercase_ (				self							)					->    Any:
										lowerCAmelCase_ :      Dict    				=				self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_sequence_classification(*__lowercase							)




						def 						lowercase_ (				self							)					->    Any:
										lowerCAmelCase_ :      Optional[Any]    				=				self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_token_classification(*__lowercase							)




						def 						lowercase_ (				self							)					->    Union[str, Any]:
										lowerCAmelCase_ :      Dict    				=				self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_question_answering(*__lowercase							)




						@slow
						def 						lowercase_ (				self							)					->    Any:
										for model_name in LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
														lowerCAmelCase_ :      Dict    				=				LayoutLMvaModel.from_pretrained(__lowercase							)
														self.assertIsNotNone(__lowercase							)






def 			lowerCAmelCase (		):
				lowerCAmelCase_ :      str    				=				Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png''' )
				return image







@require_torch
class 				snake_case__(							unittest.TestCase							):







						'''simple docstring'''




						@cached_property
						def 						lowercase_ (				self							)					->    Tuple:
										return LayoutLMvaImageProcessor(apply_ocr=__lowercase							) if is_vision_available() else None




						@slow
						def 						lowercase_ (				self							)					->    int:
										lowerCAmelCase_ :      str    				=				LayoutLMvaModel.from_pretrained('''microsoft/layoutlmv3-base'''							).to(__lowercase							)

										lowerCAmelCase_ :      Any    				=				self.default_image_processor
										lowerCAmelCase_ :      Optional[Any]    				=				prepare_img()
										lowerCAmelCase_ :      Optional[int]    				=				image_processor(images=__lowercase   ,						return_tensors='''pt'''							).pixel_values.to(__lowercase							)

										lowerCAmelCase_ :      List[Any]    				=				torch.tensor([[1, 2]]							)
										lowerCAmelCase_ :      Dict    				=				torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8]]							).unsqueeze(0							)

										# forward pass
										lowerCAmelCase_ :      Dict    				=				model(
										    input_ids=input_ids.to(__lowercase							)   ,						bbox=bbox.to(__lowercase							)   ,						pixel_values=pixel_values.to(__lowercase							)   ,						)

										# verify the logits
										lowerCAmelCase_ :      Dict    				=				torch.Size((1, 1_9_9, 7_6_8)							)
										self.assertEqual(outputs.last_hidden_state.shape   ,						__lowercase							)

										lowerCAmelCase_ :      Tuple    				=				torch.tensor(
										    [[-0.05_29, 0.36_18, 0.16_32], [-0.15_87, -0.16_67, -0.04_00], [-0.15_57, -0.16_71, -0.05_05]]							).to(__lowercase							)

										self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :3, :3]   ,						__lowercase   ,						atol=1e-4							)							)



from manim import *







class 				snake_case__(							UpperCAmelCase__							):







						'''simple docstring'''




						def 						lowercase_ (				self							)					->    Tuple:
										lowerCAmelCase_ :      Dict    				=				Rectangle(height=0.5   ,						width=0.5							)
										lowerCAmelCase_ :      Tuple    				=				Rectangle(height=0.25   ,						width=0.25							)
										lowerCAmelCase_ :      Tuple    				=				Rectangle(height=0.46   ,						width=0.46							).set_stroke(width=0							)

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

										lowerCAmelCase_ :      List[str]    				=				[mem.copy() for i in range(4							)]
										lowerCAmelCase_ :      Any    				=				VGroup(*__lowercase							).arrange(__lowercase   ,						buff=0							)
										lowerCAmelCase_ :      List[Any]    				=				Text('''GPU'''   ,						font_size=2_4							)
										lowerCAmelCase_ :      int    				=				Group(__lowercase   ,						__lowercase							).arrange(__lowercase   ,						buff=0.5   ,						aligned_edge=__lowercase							)
										gpu.move_to([-1, -1, 0]							)
										self.add(__lowercase							)

										lowerCAmelCase_ :      str    				=				[mem.copy() for i in range(6							)]
										lowerCAmelCase_ :      Dict    				=				VGroup(*__lowercase							).arrange(__lowercase   ,						buff=0							)

										lowerCAmelCase_ :      Dict    				=				Text('''Model'''   ,						font_size=2_4							)
										lowerCAmelCase_ :      str    				=				Group(__lowercase   ,						__lowercase							).arrange(__lowercase   ,						buff=0.5   ,						aligned_edge=__lowercase							)
										model.move_to([3, -1.0, 0]							)
										self.add(__lowercase							)

										lowerCAmelCase_ :      int    				=				[]
										lowerCAmelCase_ :      int    				=				[]
										lowerCAmelCase_ :      Dict    				=				[]

										for i, rect in enumerate(__lowercase							):
														rect.set_stroke(__lowercase							)

														lowerCAmelCase_ :      Any    				=				Rectangle(height=0.46 / 4   ,						width=0.46 / 3							).set_stroke(width=0.0							).set_fill(__lowercase   ,						opacity=0.7							)

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

										self.add(*__lowercase   ,						*__lowercase   ,						*__lowercase							)

										lowerCAmelCase_ :      Union[str, Any]    				=				[mem.copy() for i in range(6							)]
										lowerCAmelCase_ :      List[str]    				=				VGroup(*__lowercase							).arrange(__lowercase   ,						buff=0							)

										lowerCAmelCase_ :      Union[str, Any]    				=				Text('''Loaded Checkpoint'''   ,						font_size=2_4							)
										lowerCAmelCase_ :      int    				=				Group(__lowercase   ,						__lowercase							).arrange(__lowercase   ,						buff=0.5   ,						aligned_edge=__lowercase							)
										checkpoint.move_to([3, 0.5, 0]							)

										self.add(__lowercase							)

										lowerCAmelCase_ :      Optional[Any]    				=				[]
										lowerCAmelCase_ :      Dict    				=				[]

										for i, rect in enumerate(__lowercase							):
														lowerCAmelCase_ :      str    				=				fill.copy().set_fill(__lowercase   ,						opacity=0.7							)
														target.move_to(__lowercase							)
														ckpt_arr.append(__lowercase							)

														lowerCAmelCase_ :      Union[str, Any]    				=				target.copy()
														if i < 5:
																		cpu_target.move_to(cpu_left_col_base[i + 1]							)
														else:
																		cpu_target.move_to(cpu_right_col_base[i - 5]							)
														ckpt_cpu_arr.append(__lowercase							)
										self.add(*__lowercase   ,						*__lowercase							)

										lowerCAmelCase_ :      Union[str, Any]    				=				Square(side_length=2.2							)
										key.move_to([-5, 2, 0]							)

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

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

										self.add(__lowercase   ,						__lowercase							)

										lowerCAmelCase_ :      str    				=				MarkupText(
										    f"""<span fgcolor='{BLUE}'>●</span> Checkpoint"""   ,						font_size=1_8   ,						)

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

										lowerCAmelCase_ :      str    				=				MarkupText(
										    f"""Based on the passed in configuration, weights are stored in\na variety of np.memmaps on disk or to a particular device."""   ,						font_size=2_4   ,						)
										step_a.move_to([2, 2, 0]							)

										lowerCAmelCase_ :      List[Any]    				=				[meta_mem.copy() for i in range(6							)]
										lowerCAmelCase_ :      Any    				=				[meta_mem.copy() for i in range(6							)]
										lowerCAmelCase_ :      Any    				=				VGroup(*__lowercase							).arrange(__lowercase   ,						buff=0							)
										lowerCAmelCase_ :      Union[str, Any]    				=				VGroup(*__lowercase							).arrange(__lowercase   ,						buff=0							)
										lowerCAmelCase_ :      int    				=				VGroup(__lowercase   ,						__lowercase							).arrange(__lowercase   ,						buff=0							)
										lowerCAmelCase_ :      List[str]    				=				Text('''Disk'''   ,						font_size=2_4							)
										lowerCAmelCase_ :      Optional[int]    				=				Group(__lowercase   ,						__lowercase							).arrange(__lowercase   ,						buff=0.5   ,						aligned_edge=__lowercase							)
										disk.move_to([-4.0, -1.25, 0]							)
										self.play(Write(__lowercase   ,						run_time=3							)   ,						Write(__lowercase   ,						run_time=1							)   ,						Create(__lowercase   ,						run_time=1							)							)

										lowerCAmelCase_ :      int    				=				[]
										for i, rect in enumerate(__lowercase							):
														lowerCAmelCase_ :      int    				=				rect.copy()
														target.generate_target()
														target.target.move_to(disk_left_col_base[i]							).scale(0.5							)
														animations.append(MoveToTarget(__lowercase   ,						run_time=1.5							)							)
										self.play(*__lowercase							)

										self.play(FadeOut(__lowercase							)							)

										lowerCAmelCase_ :      Union[str, Any]    				=				MarkupText(f"""Then, the checkpoint is removed from memory\nthrough garbage collection."""   ,						font_size=2_4							)
										step_a.move_to([2, 2, 0]							)

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

										self.play(
										    FadeOut(__lowercase   ,						__lowercase   ,						*__lowercase   ,						*__lowercase							)   ,						)

										self.wait()