


import copy
import tempfile
import unittest

from transformers import MaMaaaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device
from transformers.utils import cached_property

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import MaMaaaForConditionalGeneration, MaMaaaModel, MaMaaaTokenizer
			from transformers.models.mam_aaa.modeling_mam_aaa import MaMaaaDecoder, MaMaaaEncoder



def     __lowerCAmelCase						(							snake_case	:    int						,      snake_case	:    int						,      snake_case	:    List[Any]						,      snake_case	:    List[Any]=None						,      snake_case	:    Union[str, Any]=None						,      snake_case	:    List[str]=None						,      snake_case	:    List[str]=None						,      snake_case	:    List[Any]=None						,      )       ->							Optional[int]:
			if attention_mask is None:
						__lowerCamelCase:				Optional[int]     =	input_ids.ne(config.pad_token_id )
			if decoder_attention_mask is None:
						__lowerCamelCase:				Tuple     =	decoder_input_ids.ne(config.pad_token_id )
			if head_mask is None:
						__lowerCamelCase:				Dict     =	torch.ones(config.encoder_layers						,      config.encoder_attention_heads						,      device=snake_case )
			if decoder_head_mask is None:
						__lowerCamelCase:				Optional[Any]     =	torch.ones(config.decoder_layers						,      config.decoder_attention_heads						,      device=snake_case )
			if cross_attn_head_mask is None:
						__lowerCamelCase:				str     =	torch.ones(config.decoder_layers						,      config.decoder_attention_heads						,      device=snake_case )
			return {
			    "input_ids": input_ids,
			    "decoder_input_ids": decoder_input_ids,
			    "attention_mask": attention_mask,
			    "decoder_attention_mask": attention_mask,
			    "head_mask": head_mask,
			    "decoder_head_mask": decoder_head_mask,
			    "cross_attn_head_mask": cross_attn_head_mask,
			}



class        a					:





					def __init__(    self					:				Any    ,	SCREAMING_SNAKE_CASE_					:				Tuple    ,	SCREAMING_SNAKE_CASE_					:				str=13    ,	SCREAMING_SNAKE_CASE_					:				Any=7    ,	SCREAMING_SNAKE_CASE_					:				Tuple=True    ,	SCREAMING_SNAKE_CASE_					:				Tuple=False    ,	SCREAMING_SNAKE_CASE_					:				Tuple=99    ,	SCREAMING_SNAKE_CASE_					:				Any=16    ,	SCREAMING_SNAKE_CASE_					:				str=2    ,	SCREAMING_SNAKE_CASE_					:				Optional[Any]=4    ,	SCREAMING_SNAKE_CASE_					:				Optional[Any]=4    ,	SCREAMING_SNAKE_CASE_					:				Dict="relu"    ,	SCREAMING_SNAKE_CASE_					:				Union[str, Any]=0.1    ,	SCREAMING_SNAKE_CASE_					:				str=0.1    ,	SCREAMING_SNAKE_CASE_					:				Any=0.0    ,	SCREAMING_SNAKE_CASE_					:				int=0.0    ,	SCREAMING_SNAKE_CASE_					:				Dict=20    ,	SCREAMING_SNAKE_CASE_					:				str=2    ,	SCREAMING_SNAKE_CASE_					:				int=1    ,	SCREAMING_SNAKE_CASE_					:				Optional[Any]=0    ,	):
								__lowerCamelCase:				Dict     =	parent
								__lowerCamelCase:				List[Any]     =	batch_size
								__lowerCamelCase:				str     =	seq_length
								__lowerCamelCase:				List[str]     =	is_training
								__lowerCamelCase:				str     =	use_labels
								__lowerCamelCase:				List[Any]     =	vocab_size
								__lowerCamelCase:				str     =	hidden_size
								__lowerCamelCase:				Optional[Any]     =	num_hidden_layers
								__lowerCamelCase:				Optional[int]     =	num_attention_heads
								__lowerCamelCase:				Tuple     =	intermediate_size
								__lowerCamelCase:				str     =	hidden_act
								__lowerCamelCase:				Optional[int]     =	hidden_dropout_prob
								__lowerCamelCase:				Tuple     =	attention_probs_dropout_prob
								__lowerCamelCase:				Union[str, Any]     =	encoder_layerdrop
								__lowerCamelCase:				List[str]     =	decoder_layerdrop
								__lowerCamelCase:				Optional[Any]     =	max_position_embeddings
								__lowerCamelCase:				Any     =	eos_token_id
								__lowerCamelCase:				Optional[int]     =	pad_token_id
								__lowerCamelCase:				Union[str, Any]     =	bos_token_id





					def  SCREAMING_SNAKE_CASE__       (    self					:				Union[str, Any]							):
								__lowerCamelCase:				Union[str, Any]     =	ids_tensor([self.batch_size, self.seq_length]    ,	self.vocab_size							)
								__lowerCamelCase:				str     =	self.eos_token_id  # Eos Token
								__lowerCamelCase:				Optional[int]     =	ids_tensor([self.batch_size, self.seq_length]    ,	self.vocab_size							)

								# we need to clamp the input ids here to avoid having pad token in between
								# this is because for M2M100 the position_ids are prepared such that
								# all pad tokens have pos id = 2 and rest are between 2..seq_length
								# and the seq_length here is seq_length - num_pad_tokens
								# but when using past, there is no way of knowing if the past input ids had
								# pad tokens in them, which results in incorrect seq_lenth and which in turn results in
								# position_ids being off by num_pad_tokens in past input
								__lowerCamelCase:				Optional[int]     =	input_ids.clamp(self.pad_token_id + 1							)
								__lowerCamelCase:				List[Any]     =	decoder_input_ids.clamp(self.pad_token_id + 1							)

								__lowerCamelCase:				Any     =	self.get_config()
								__lowerCamelCase:				Optional[Any]     =	prepare_mam_aaa_inputs_dict(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							)
								return config, inputs_dict





					def  SCREAMING_SNAKE_CASE__       (    self					:				Optional[Any]							):
								return MaMaaaConfig(
								    vocab_size=self.vocab_size    ,	d_model=self.hidden_size    ,	encoder_layers=self.num_hidden_layers    ,	decoder_layers=self.num_hidden_layers    ,	encoder_attention_heads=self.num_attention_heads    ,	decoder_attention_heads=self.num_attention_heads    ,	encoder_ffn_dim=self.intermediate_size    ,	decoder_ffn_dim=self.intermediate_size    ,	dropout=self.hidden_dropout_prob    ,	attention_dropout=self.attention_probs_dropout_prob    ,	encoder_layerdrop=self.encoder_layerdrop    ,	decoder_layerdrop=self.decoder_layerdrop    ,	max_position_embeddings=self.max_position_embeddings    ,	eos_token_id=self.eos_token_id    ,	bos_token_id=self.bos_token_id    ,	pad_token_id=self.pad_token_id    ,	)





					def  SCREAMING_SNAKE_CASE__       (    self					:				Tuple							):
								__lowerCamelCase:				Tuple     =	self.prepare_config_and_inputs()
								return config, inputs_dict





					def  SCREAMING_SNAKE_CASE__       (    self					:				Optional[Any]    ,	SCREAMING_SNAKE_CASE_					:				Tuple    ,	SCREAMING_SNAKE_CASE_					:				Union[str, Any]							):
								__lowerCamelCase:				Tuple     =	MaMaaaModel(config=SCREAMING_SNAKE_CASE_							).get_decoder().to(SCREAMING_SNAKE_CASE_							).eval()
								__lowerCamelCase:				Tuple     =	inputs_dict["""input_ids"""]
								__lowerCamelCase:				Tuple     =	inputs_dict["""attention_mask"""]
								__lowerCamelCase:				List[str]     =	inputs_dict["""head_mask"""]

								# first forward pass
								__lowerCamelCase:				int     =	model(SCREAMING_SNAKE_CASE_    ,	attention_mask=SCREAMING_SNAKE_CASE_    ,	head_mask=SCREAMING_SNAKE_CASE_    ,	use_cache=SCREAMING_SNAKE_CASE_							)

								__lowerCamelCase:				Union[str, Any]     =	outputs.to_tuple()

								# create hypothetical multiple next token and extent to next_input_ids
								__lowerCamelCase:				List[str]     =	ids_tensor((self.batch_size, 3)    ,	config.vocab_size							)
								__lowerCamelCase:				List[Any]     =	ids_tensor((self.batch_size, 3)    ,	2							)

								# append to next input_ids and
								__lowerCamelCase:				Union[str, Any]     =	torch.cat([input_ids, next_tokens]    ,	dim=-1							)
								__lowerCamelCase:				Optional[Any]     =	torch.cat([attention_mask, next_attn_mask]    ,	dim=-1							)

								__lowerCamelCase:				List[str]     =	model(SCREAMING_SNAKE_CASE_    ,	attention_mask=SCREAMING_SNAKE_CASE_							)["""last_hidden_state"""]
								__lowerCamelCase:				str     =	model(SCREAMING_SNAKE_CASE_    ,	attention_mask=SCREAMING_SNAKE_CASE_    ,	past_key_values=SCREAMING_SNAKE_CASE_							)[
								    """last_hidden_state"""
								]

								# select random slice
								__lowerCamelCase:				Tuple     =	ids_tensor((1,)    ,	output_from_past.shape[-1]							).item()
								__lowerCamelCase:				Optional[int]     =	output_from_no_past[:, -3:, random_slice_idx].detach()
								__lowerCamelCase:				Any     =	output_from_past[:, :, random_slice_idx].detach()

								self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]							)

								# test that outputs are equal for slice
								self.parent.assertTrue(torch.allclose(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_    ,	atol=1E-2							)							)







					def  SCREAMING_SNAKE_CASE__       (    self					:				List[Any]    ,	SCREAMING_SNAKE_CASE_					:				List[Any]    ,	SCREAMING_SNAKE_CASE_					:				Tuple							):
								__lowerCamelCase:				Optional[int]     =	MaMaaaModel(config=SCREAMING_SNAKE_CASE_							).to(SCREAMING_SNAKE_CASE_							).eval()
								__lowerCamelCase:				str     =	model(**SCREAMING_SNAKE_CASE_							)

								__lowerCamelCase:				List[Any]     =	outputs.encoder_last_hidden_state
								__lowerCamelCase:				str     =	outputs.last_hidden_state

								with tempfile.TemporaryDirectory() as tmpdirname:
											__lowerCamelCase:				Any     =	model.get_encoder()
											encoder.save_pretrained(SCREAMING_SNAKE_CASE_							)
											__lowerCamelCase:				List[Any]     =	MaMaaaEncoder.from_pretrained(SCREAMING_SNAKE_CASE_							).to(SCREAMING_SNAKE_CASE_							)

								__lowerCamelCase:				List[Any]     =	encoder(inputs_dict["""input_ids"""]    ,	attention_mask=inputs_dict["""attention_mask"""]							)[
								    0
								]

								self.parent.assertTrue((encoder_last_hidden_state_a - encoder_last_hidden_state).abs().max().item() < 1E-3							)

								with tempfile.TemporaryDirectory() as tmpdirname:
											__lowerCamelCase:				List[Any]     =	model.get_decoder()
											decoder.save_pretrained(SCREAMING_SNAKE_CASE_							)
											__lowerCamelCase:				str     =	MaMaaaDecoder.from_pretrained(SCREAMING_SNAKE_CASE_							).to(SCREAMING_SNAKE_CASE_							)

								__lowerCamelCase:				str     =	decoder(
								    input_ids=inputs_dict["""decoder_input_ids"""]    ,	attention_mask=inputs_dict["""decoder_attention_mask"""]    ,	encoder_hidden_states=SCREAMING_SNAKE_CASE_    ,	encoder_attention_mask=inputs_dict["""attention_mask"""]    ,	)[0]

								self.parent.assertTrue((last_hidden_state_a - last_hidden_state).abs().max().item() < 1E-3							)



@require_torch
class        a					(			_UpperCAmelCase     ,_UpperCAmelCase     ,_UpperCAmelCase     ,unittest.TestCase   ):
					UpperCAmelCase__ :  List[str]						      =	(
					    (
					        MaMaaaModel,
					        MaMaaaForConditionalGeneration,
					    )
					    if is_torch_available()
					    else ()
					)
					UpperCAmelCase__ :  str						      =	(MaMaaaForConditionalGeneration,) if is_torch_available() else ()
					UpperCAmelCase__ :  Any						      =	(
					    {
					        "conversational": MaMaaaForConditionalGeneration,
					        "feature-extraction": MaMaaaModel,
					        "summarization": MaMaaaForConditionalGeneration,
					        "text2text-generation": MaMaaaForConditionalGeneration,
					        "translation": MaMaaaForConditionalGeneration,
					    }
					    if is_torch_available()
					    else {}
					)
					UpperCAmelCase__ :  Optional[int]						      =	True
					UpperCAmelCase__ :  List[str]						      =	True
					UpperCAmelCase__ :  Dict						      =	False
					UpperCAmelCase__ :  Optional[int]						      =	False





					def  SCREAMING_SNAKE_CASE__       (    self					:				Optional[int]    ,	SCREAMING_SNAKE_CASE_					:				Dict    ,	SCREAMING_SNAKE_CASE_					:				int    ,	SCREAMING_SNAKE_CASE_					:				str    ,	SCREAMING_SNAKE_CASE_					:				Optional[Any]    ,	SCREAMING_SNAKE_CASE_					:				Any							):
								if pipeline_test_casse_name == "TranslationPipelineTests":
											# Get `ValueError: Translation requires a `src_lang` and a `tgt_lang` for this model`.
											# `M2M100Config` was never used in pipeline tests: cannot create a simple tokenizer.
											return True

								return False





					def  SCREAMING_SNAKE_CASE__       (    self					:				str							):
								__lowerCamelCase:				Optional[int]     =	MaMaaaModelTester(self							)
								__lowerCamelCase:				Union[str, Any]     =	ConfigTester(self    ,	config_class=SCREAMING_SNAKE_CASE_							)





					def  SCREAMING_SNAKE_CASE__       (    self					:				str							):
								self.config_tester.run_common_tests()





					def  SCREAMING_SNAKE_CASE__       (    self					:				Dict							):
								__lowerCamelCase:				Any     =	self.model_tester.prepare_config_and_inputs()
								for model_class in self.all_model_classes:
											__lowerCamelCase:				str     =	model_class(SCREAMING_SNAKE_CASE_							)

											with tempfile.TemporaryDirectory() as tmpdirname:
														model.save_pretrained(SCREAMING_SNAKE_CASE_							)
														__lowerCamelCase:				Tuple     =	model_class.from_pretrained(SCREAMING_SNAKE_CASE_    ,	output_loading_info=SCREAMING_SNAKE_CASE_							)
											self.assertEqual(info["""missing_keys"""]    ,	[]							)





					def  SCREAMING_SNAKE_CASE__       (    self					:				Optional[int]							):
								__lowerCamelCase:				List[str]     =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_decoder_model_past_large_inputs(*SCREAMING_SNAKE_CASE_							)





					def  SCREAMING_SNAKE_CASE__       (    self					:				Tuple							):
								__lowerCamelCase:				Union[str, Any]     =	self.model_tester.prepare_config_and_inputs_for_common()
								self.model_tester.check_encoder_decoder_model_standalone(*SCREAMING_SNAKE_CASE_							)





					def  SCREAMING_SNAKE_CASE__       (    self					:				Any							):
								__lowerCamelCase:				int     =	self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in (MaMaaaModel, MaMaaaForConditionalGeneration):
											__lowerCamelCase:				str     =	model_class(SCREAMING_SNAKE_CASE_							)
											model.to(SCREAMING_SNAKE_CASE_							)
											model.eval()

											__lowerCamelCase:				str     =	copy.deepcopy(self._prepare_for_class(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							)							)

											if not self.is_encoder_decoder:
														__lowerCamelCase:				str     =	inputs["""input_ids"""]
														del inputs["input_ids"]
											else:
														__lowerCamelCase:				Tuple     =	inputs["""input_ids"""]
														__lowerCamelCase:				str     =	inputs.get("""decoder_input_ids"""    ,	SCREAMING_SNAKE_CASE_							)
														del inputs["input_ids"]
														inputs.pop("""decoder_input_ids"""    ,	SCREAMING_SNAKE_CASE_							)

											__lowerCamelCase:				List[str]     =	model.get_input_embeddings()
											if not self.is_encoder_decoder:
														__lowerCamelCase:				int     =	wte(SCREAMING_SNAKE_CASE_							)
											else:
														__lowerCamelCase:				Tuple     =	wte(SCREAMING_SNAKE_CASE_							)
														__lowerCamelCase:				Optional[Any]     =	wte(SCREAMING_SNAKE_CASE_							)

											with torch.no_grad():
														model(**SCREAMING_SNAKE_CASE_							)[0]







					def  SCREAMING_SNAKE_CASE__       (    self					:				List[str]							):
								__lowerCamelCase:				Tuple     =	self.model_tester.prepare_config_and_inputs()
								__lowerCamelCase:				Optional[int]     =	input_dict["""input_ids"""]
								__lowerCamelCase:				List[Any]     =	input_ids.ne(1							).to(SCREAMING_SNAKE_CASE_							)
								__lowerCamelCase:				Dict     =	MaMaaaForConditionalGeneration(SCREAMING_SNAKE_CASE_							).eval().to(SCREAMING_SNAKE_CASE_							)
								if torch_device == "cuda":
											model.half()
								model.generate(SCREAMING_SNAKE_CASE_    ,	attention_mask=SCREAMING_SNAKE_CASE_							)
								model.generate(num_beams=4    ,	do_sample=SCREAMING_SNAKE_CASE_    ,	early_stopping=SCREAMING_SNAKE_CASE_    ,	num_return_sequences=3							)



def     __lowerCAmelCase						(							snake_case	:    Optional[Any] )       ->							Dict:
			return torch.tensor(snake_case						,      dtype=torch.long						,      device=snake_case )


_A		:				Optional[int]									=       1e-4







@require_torch
@require_sentencepiece
@require_tokenizers
@slow
class        a					(			unittest.TestCase   ):





					@cached_property
					def  SCREAMING_SNAKE_CASE__       (    self					:				str							):
								return MaMaaaTokenizer.from_pretrained("""facebook/m2m100_418M"""							)





					def  SCREAMING_SNAKE_CASE__       (    self					:				Tuple							):
								__lowerCamelCase:				Any     =	MaMaaaModel.from_pretrained("""facebook/m2m100_418M"""							).to(SCREAMING_SNAKE_CASE_							)
								__lowerCamelCase:				int     =	_long_tensor([[128028, 98, 12, 30527, 2732, 159, 7755, 61904, 39144, 38, 2]]							)
								__lowerCamelCase:				Union[str, Any]     =	_long_tensor([[2, 128028, 98, 12, 30527, 2732, 159, 7755, 61904, 39144, 38]]							)
								__lowerCamelCase:				Any     =	prepare_mam_aaa_inputs_dict(model.config    ,	SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							)
								with torch.no_grad():
											__lowerCamelCase:				Union[str, Any]     =	model(**SCREAMING_SNAKE_CASE_							)[0]
								__lowerCamelCase:				Optional[Any]     =	torch.Size((1, 11, 1024)							)
								self.assertEqual(output.shape    ,	SCREAMING_SNAKE_CASE_							)
								# change to expected output here
								__lowerCamelCase:				Dict     =	torch.tensor(
								    [[-0.7780, -0.1676, 0.1038], [-6.7556, -1.3992, 0.0567], [-7.5383, -0.5920, -0.2779]]    ,	device=SCREAMING_SNAKE_CASE_							)
								self.assertTrue(torch.allclose(output[:, :3, :3]    ,	SCREAMING_SNAKE_CASE_    ,	atol=SCREAMING_SNAKE_CASE_							)							)





					def  SCREAMING_SNAKE_CASE__       (    self					:				str							):
								__lowerCamelCase:				int     =	MaMaaaForConditionalGeneration.from_pretrained("""facebook/m2m100_418M"""							).to(SCREAMING_SNAKE_CASE_							)

								# change to intended input
								__lowerCamelCase:				Tuple     =	_long_tensor([[128028, 98, 12, 30527, 2732, 159, 7755, 61904, 39144, 38, 2]]							)
								__lowerCamelCase:				Union[str, Any]     =	_long_tensor([[2, 128028, 98, 12, 30527, 2732, 159, 7755, 61904, 39144, 38]]							)
								__lowerCamelCase:				Union[str, Any]     =	prepare_mam_aaa_inputs_dict(model.config    ,	SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							)
								with torch.no_grad():
											__lowerCamelCase:				Any     =	model(**SCREAMING_SNAKE_CASE_							)[0]
								__lowerCamelCase:				Union[str, Any]     =	torch.Size((1, 11, model.config.vocab_size)							)
								self.assertEqual(output.shape    ,	SCREAMING_SNAKE_CASE_							)
								# change to expected output here
								__lowerCamelCase:				List[Any]     =	torch.tensor(
								    [[-1.0448, -1.0411, 3.7992], [-3.2191, -3.2386, -1.3451], [-3.6210, -3.5993, 0.4925]]    ,	device=SCREAMING_SNAKE_CASE_							)
								self.assertTrue(torch.allclose(output[:, :3, :3]    ,	SCREAMING_SNAKE_CASE_    ,	atol=SCREAMING_SNAKE_CASE_							)							)







					def  SCREAMING_SNAKE_CASE__       (    self					:				int							):
								__lowerCamelCase:				List[str]     =	MaMaaaForConditionalGeneration.from_pretrained("""facebook/m2m100_418M"""							).to(SCREAMING_SNAKE_CASE_							)
								__lowerCamelCase:				Union[str, Any]     =	MaMaaaTokenizer.from_pretrained("""facebook/m2m100_418M"""    ,	src_lang="""fr"""    ,	tgt_lang="""en"""							)

								__lowerCamelCase:				Union[str, Any]     =	[
								    """L'affaire NSA souligne l'absence totale de débat sur le renseignement""",
								    """Selon moi, il y a deux niveaux de réponse de la part du gouvernement français.""",
								    """Lorsque François Hollande téléphone à Barack Obama ou quand le ministre des affaires étrangères Laurent"""
								    """ Fabius convoque l'ambassadeur des Etats-Unis, ils réagissent à une vraie découverte, qui est celle de"""
								    """ l'ampleur de la surveillance américaine sur l'ensemble des communications en France.""",
								]

								# The below article tests that we don't add any hypotheses outside of the top n_beams
								__lowerCamelCase:				List[Any]     =	tokenizer(SCREAMING_SNAKE_CASE_    ,	padding=SCREAMING_SNAKE_CASE_    ,	return_tensors="""pt"""							)

								__lowerCamelCase:				Dict     =	model.generate(
								    input_ids=dct["""input_ids"""].to(SCREAMING_SNAKE_CASE_							)    ,	attention_mask=dct["""attention_mask"""].to(SCREAMING_SNAKE_CASE_							)    ,	num_beams=5    ,	forced_bos_token_id=tokenizer.get_lang_id("""en"""							)    ,	)

								__lowerCamelCase:				Dict     =	[
								    """The NSA case highlights the total absence of intelligence debate""",
								    """I think there are two levels of response from the French government.""",
								    """When François Hollande calls Barack Obama or when Foreign Minister Laurent Fabius calls the U.S."""
								    """ Ambassador, they respond to a real discovery, which is that of the scale of U.S. surveillance on all"""
								    """ communications in France.""",
								]

								__lowerCamelCase:				Any     =	tokenizer.batch_decode(
								    hypotheses_batch.tolist()    ,	clean_up_tokenization_spaces=SCREAMING_SNAKE_CASE_    ,	skip_special_tokens=SCREAMING_SNAKE_CASE_							)
								assert generated == expected_en






from manim import *



class        a					(			_UpperCAmelCase   ):





     def  SCREAMING_SNAKE_CASE__       (    self					:				int							):
        __lowerCamelCase:				int     =	Rectangle(height=0.5    ,	width=0.5							)
        __lowerCamelCase:				List[str]     =	Rectangle(height=0.25    ,	width=0.25							)
        __lowerCamelCase:				Optional[int]     =	Rectangle(height=0.46    ,	width=0.46							).set_stroke(width=0							)

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

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

        __lowerCamelCase:				Any     =	[mem.copy() for i in range(6							)]
        __lowerCamelCase:				Dict     =	VGroup(*SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0							)

        __lowerCamelCase:				List[Any]     =	Text("""Model"""    ,	font_size=24							)
        __lowerCamelCase:				Any     =	Group(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0.5    ,	aligned_edge=SCREAMING_SNAKE_CASE_							)
        model.move_to([3, -1.0, 0]							)
        self.add(SCREAMING_SNAKE_CASE_							)

        __lowerCamelCase:				Tuple     =	[]
        __lowerCamelCase:				Any     =	[]
        __lowerCamelCase:				int     =	[]

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

           __lowerCamelCase:				int     =	Rectangle(height=0.46 / 4    ,	width=0.46 / 3							).set_stroke(width=0.0							).set_fill(SCREAMING_SNAKE_CASE_    ,	opacity=0.7							)

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

        self.add(*SCREAMING_SNAKE_CASE_    ,	*SCREAMING_SNAKE_CASE_    ,	*SCREAMING_SNAKE_CASE_							)

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

        __lowerCamelCase:				Tuple     =	Text("""Loaded Checkpoint"""    ,	font_size=24							)
        __lowerCamelCase:				Tuple     =	Group(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0.5    ,	aligned_edge=SCREAMING_SNAKE_CASE_							)
        checkpoint.move_to([3, 0.5, 0]							)

        self.add(SCREAMING_SNAKE_CASE_							)

        __lowerCamelCase:				List[Any]     =	[]
        __lowerCamelCase:				Optional[int]     =	[]

        for i, rect in enumerate(SCREAMING_SNAKE_CASE_							):
           __lowerCamelCase:				Optional[int]     =	fill.copy().set_fill(SCREAMING_SNAKE_CASE_    ,	opacity=0.7							)
           target.move_to(SCREAMING_SNAKE_CASE_							)
           ckpt_arr.append(SCREAMING_SNAKE_CASE_							)

           __lowerCamelCase:				List[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(SCREAMING_SNAKE_CASE_							)
        self.add(*SCREAMING_SNAKE_CASE_    ,	*SCREAMING_SNAKE_CASE_							)

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

        __lowerCamelCase:				Dict     =	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(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							)

        __lowerCamelCase:				Optional[int]     =	MarkupText(
            F'<span fgcolor=\'{BLUE}\'>●</span> Checkpoint'    ,	font_size=18    ,	)

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

        __lowerCamelCase:				Tuple     =	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=24    ,	)
        step_a.move_to([2, 2, 0]							)

        __lowerCamelCase:				List[Any]     =	[meta_mem.copy() for i in range(6							)]
        __lowerCamelCase:				Optional[int]     =	[meta_mem.copy() for i in range(6							)]
        __lowerCamelCase:				str     =	VGroup(*SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0							)
        __lowerCamelCase:				Optional[int]     =	VGroup(*SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0							)
        __lowerCamelCase:				List[str]     =	VGroup(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0							)
        __lowerCamelCase:				Dict     =	Text("""Disk"""    ,	font_size=24							)
        __lowerCamelCase:				Any     =	Group(SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_							).arrange(SCREAMING_SNAKE_CASE_    ,	buff=0.5    ,	aligned_edge=SCREAMING_SNAKE_CASE_							)
        disk.move_to([-4.0, -1.25, 0]							)
        self.play(Write(SCREAMING_SNAKE_CASE_    ,	run_time=3							)    ,	Write(SCREAMING_SNAKE_CASE_    ,	run_time=1							)    ,	Create(SCREAMING_SNAKE_CASE_    ,	run_time=1							)							)

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

        self.play(FadeOut(SCREAMING_SNAKE_CASE_							)							)

        __lowerCamelCase:				List[Any]     =	MarkupText(F'Then, the checkpoint is removed from memory\nthrough garbage collection.'    ,	font_size=24							)
        step_a.move_to([2, 2, 0]							)

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

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

        self.wait()


