


'''simple docstring'''



from manim import *






class 	UpperCamelCase__(       lowerCAmelCase	):




				def 					a__(		self      :			List[str]				)->					Union[str, Any]:

										"""simple docstring"""




										UpperCAmelCase					    =     Rectangle(height=0.5				,   width=0.5				)
										UpperCAmelCase					    =     Rectangle(height=0.25				,   width=0.25				)
										UpperCAmelCase					    =     Rectangle(height=0.46				,   width=0.46				).set_stroke(width=0				)

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

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

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

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

										UpperCAmelCase					    =     []
										UpperCAmelCase					    =     []
										UpperCAmelCase					    =     []

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

																UpperCAmelCase					    =     Rectangle(height=0.46 / 4				,   width=0.46 / 3				).set_stroke(width=0.0				).set_fill(lowerCAmelCase				,   opacity=0.7				)

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

										self.add(*lowerCAmelCase				,   *lowerCAmelCase				,   *lowerCAmelCase				)

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

										UpperCAmelCase					    =     Text('''Loaded Checkpoint'''				,   font_size=24				)
										UpperCAmelCase					    =     Group(lowerCAmelCase				,   lowerCAmelCase				).arrange(lowerCAmelCase				,   buff=0.5				,   aligned_edge=lowerCAmelCase				)
										checkpoint.move_to([3, 0.5, 0]				)

										self.add(lowerCAmelCase				)

										UpperCAmelCase					    =     []
										UpperCAmelCase					    =     []

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

																UpperCAmelCase					    =     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(lowerCAmelCase				)
										self.add(*lowerCAmelCase				,   *lowerCAmelCase				)

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

										UpperCAmelCase					    =     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(lowerCAmelCase				,   lowerCAmelCase				)

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

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

										UpperCAmelCase					    =     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]				)

										UpperCAmelCase					    =     [meta_mem.copy() for i in range(6				)]
										UpperCAmelCase					    =     [meta_mem.copy() for i in range(6				)]
										UpperCAmelCase					    =     VGroup(*lowerCAmelCase				).arrange(lowerCAmelCase				,   buff=0				)
										UpperCAmelCase					    =     VGroup(*lowerCAmelCase				).arrange(lowerCAmelCase				,   buff=0				)
										UpperCAmelCase					    =     VGroup(lowerCAmelCase				,   lowerCAmelCase				).arrange(lowerCAmelCase				,   buff=0				)
										UpperCAmelCase					    =     Text('''Disk'''				,   font_size=24				)
										UpperCAmelCase					    =     Group(lowerCAmelCase				,   lowerCAmelCase				).arrange(lowerCAmelCase				,   buff=0.5				,   aligned_edge=lowerCAmelCase				)
										disk.move_to([-4.0, -1.25, 0]				)
										self.play(Write(lowerCAmelCase				,   run_time=3				)				,   Write(lowerCAmelCase				,   run_time=1				)				,   Create(lowerCAmelCase				,   run_time=1				)				)

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

										self.play(FadeOut(lowerCAmelCase				)				)

										UpperCAmelCase					    =     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(lowerCAmelCase				,   run_time=3				)				)

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

										self.wait()









'''simple docstring'''



from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any, ClassVar, Dict, List, Optional, Union

import pyarrow as pa


if TYPE_CHECKING:
	from .features import FeatureType






@dataclass
class 	UpperCamelCase__:
				__magic_name__    :				List[str]
				__magic_name__    :				Optional[str]  		=	None
				# Automatically constructed
				__magic_name__    :				ClassVar[str]  		=	"dict"
				__magic_name__    :				ClassVar[Any]  		=	None
				__magic_name__    :				str  		=	field(default="Translation"						,    init=lowerCAmelCase						,    repr=lowerCAmelCase	)




				def __call__(		self      :			Union[str, Any]				)->					str:

										"""simple docstring"""




										return pa.struct({lang: pa.string() for lang in sorted(self.languages				)}				)





				def 					a__(		self      :			int				)->					Union["FeatureType", Dict[str, "FeatureType"]]:

										"""simple docstring"""




										from .features import Value

										return {k: Value('''string'''				) for k in sorted(self.languages				)}







@dataclass
class 	UpperCamelCase__:
				__magic_name__    :				Optional[List]  		=	None
				__magic_name__    :				Optional[int]  		=	None
				__magic_name__    :				Optional[str]  		=	None
				# Automatically constructed
				__magic_name__    :				ClassVar[str]  		=	"dict"
				__magic_name__    :				ClassVar[Any]  		=	None
				__magic_name__    :				str  		=	field(default="TranslationVariableLanguages"						,    init=lowerCAmelCase						,    repr=lowerCAmelCase	)




				def 					a__(		self      :			Union[str, Any]				)->					Optional[Any]:

										"""simple docstring"""




										UpperCAmelCase					    =     sorted(set(self.languages				)				) if self.languages else None
										UpperCAmelCase					    =     len(self.languages				) if self.languages else None




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

										"""simple docstring"""




										return pa.struct({'''language''': pa.list_(pa.string()				), '''translation''': pa.list_(pa.string()				)}				)




				def 					a__(		self      :			Optional[int]				,   lowerCAmelCase      :			Dict				)->					Tuple:

										"""simple docstring"""




										UpperCAmelCase					    =     set(self.languages				)
										if self.languages and set(lowerCAmelCase				) - lang_set:
																raise ValueError(
																    F"""Some languages in example ({", ".join(sorted(set(lowerCAmelCase				) - lang_set				)				)}) are not in valid set ({", ".join(lowerCAmelCase				)})."""				)

										# Convert dictionary into tuples, splitting out cases where there are
										# multiple translations for a single language.
										UpperCAmelCase					    =     []
										for lang, text in translation_dict.items():
																if isinstance(lowerCAmelCase				,   lowerCAmelCase				):
																						translation_tuples.append((lang, text)				)
																else:
																						translation_tuples.extend([(lang, el) for el in text]				)

        # Ensure translations are in ascending order by language code.
										UpperCAmelCase    ,    UpperCAmelCase					    =     zip(*sorted(lowerCAmelCase				)				)

										return {"language": languages, "translation": translations}





				def 					a__(		self      :			Any				)->					Union["FeatureType", Dict[str, "FeatureType"]]:

										"""simple docstring"""




										from .features import Sequence, Value

										return {
										    "language": Sequence(Value('''string'''				)				),
										    "translation": Sequence(Value('''string'''				)				),
										}





