



"""simple docstring"""






from manim import *

class 			__SCREAMING_SNAKE_CASE      ( __SCREAMING_SNAKE_CASE  ):


					'''simple docstring'''





					def 						snake_case			(			self				:    Union[str, Any]	)->   List[Any]:
								lowerCamelCase__						:						Tuple						      =Rectangle(height=0.5,    width=0.5	)
								lowerCamelCase__						:						int						      =Rectangle(height=0.46,    width=0.46	).set_stroke(width=0	)
								lowerCamelCase__						:						List[str]						      =Rectangle(height=0.25,    width=0.25	)

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

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

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

								lowerCamelCase__						:						int						      =Text('''Model''',    font_size=24	)
								lowerCamelCase__						:						Any						      =Group(lowerCamelCase_,    lowerCamelCase_	).arrange(lowerCamelCase_,    buff=0.5,    aligned_edge=lowerCamelCase_	)
								model.move_to([3, -1.0, 0]	)
								self.add(lowerCamelCase_	)

								lowerCamelCase__						:						List[Any]						      =[]
								lowerCamelCase__						:						str						      =[]

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

											lowerCamelCase__						:						int						      =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__						:						str						      =[meta_mem.copy() for i in range(6	)]
								lowerCamelCase__						:						Optional[int]						      =[meta_mem.copy() for i in range(6	)]
								lowerCamelCase__						:						Tuple						      =VGroup(*lowerCamelCase_	).arrange(lowerCamelCase_,    buff=0	)
								lowerCamelCase__						:						Dict						      =VGroup(*lowerCamelCase_	).arrange(lowerCamelCase_,    buff=0	)
								lowerCamelCase__						:						Optional[Any]						      =VGroup(lowerCamelCase_,    lowerCamelCase_	).arrange(lowerCamelCase_,    buff=0	)
								lowerCamelCase__						:						Optional[Any]						      =Text('''Disk''',    font_size=24	)
								lowerCamelCase__						:						str						      =Group(lowerCamelCase_,    lowerCamelCase_	).arrange(lowerCamelCase_,    buff=0.5,    aligned_edge=lowerCamelCase_	)
								disk.move_to([-4.0, -1.25, 0]	)
								self.add(lowerCamelCase_,    lowerCamelCase_	)

								lowerCamelCase__						:						Union[str, Any]						      =[]

								for i in range(6	):
											lowerCamelCase__						:						Dict						      =fill.copy().set_fill(lowerCamelCase_,    opacity=0.8	)
											target.move_to(disk_left_col_base[i]	).scale(0.5	)
											cpu_disk_arr.append(lowerCamelCase_	)

								self.add(*lowerCamelCase_	)

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

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

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

								self.add(lowerCamelCase_,    lowerCamelCase_	)

								lowerCamelCase__						:						Dict						      =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_	)

								lowerCamelCase__						:						Dict						      =MarkupText(F'''The offloaded weights are all sent to the CPU.''',    font_size=24	)
								step_a.move_to([2, 2, 0]	)

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

								for i in range(6	):
											lowerCamelCase__						:						Tuple						      =cpu_disk_arr[i]
											lowerCamelCase__						:						List[Any]						      =rect.copy().set_fill(lowerCamelCase_,    opacity=0.8	).scale(2.0	)
											cpa.generate_target()
											cpa.target.move_to(model_base[i]	)

											if i == 0:
														rect.set_fill(lowerCamelCase_,    opacity=0.8	)
														rect.generate_target()
														rect.target.move_to(cpu_left_col_base[0]	).scale(2.0	)

														self.remove(
														    *lowerCamelCase_,    *lowerCamelCase_,    )

											else:
														rect.generate_target()
														rect.target.move_to(cpu_left_col_base[i]	).scale(2.0	)
											self.play(MoveToTarget(lowerCamelCase_	),    MoveToTarget(lowerCamelCase_	),    model_base[i].animate.set_stroke(lowerCamelCase_	)	)
								self.play(FadeOut(lowerCamelCase_	)	)

								lowerCamelCase__						:						Optional[Any]						      =MarkupText(
								    F'''Finally, hooks are added to each weight in the model\nto transfer the weights from CPU to GPU\n\t\tand back when needed.''',    font_size=24,    )
								step_a.move_to([2, 2, 0]	)

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

								lowerCamelCase__						:						Union[str, Any]						      =[]
								lowerCamelCase__						:						List[Any]						      =[]
								for i in range(6	):
											lowerCamelCase__						:						Any						      =Arrow(start=lowerCamelCase_,    end=lowerCamelCase_,    color=lowerCamelCase_,    buff=0.5	)
											a.next_to(model_base[i].get_left(),    lowerCamelCase_,    buff=0.2	)
											arrows.append(lowerCamelCase_	)
											animations.append(Write(lowerCamelCase_	)	)
								self.play(*lowerCamelCase_	)
								self.wait()








"""simple docstring"""







from __future__ import annotations






def        a__			(							_UpperCamelCase			):





						"""simple docstring"""

						UpperCAmelCase__												=     sorted(_UpperCamelCase			)
						UpperCAmelCase__												=     len(_UpperCamelCase			)
						UpperCAmelCase__												=     length >> 1
						return (
						    (sorted_list[mid_index] + sorted_list[mid_index - 1]) / 2
						    if length % 2 == 0
						    else sorted_list[mid_index]
						)






def        a__			(							):





						"""simple docstring"""

						import doctest

						doctest.testmod()


if __name__ == "__main__":
						main()