
from manim import *






class 							SCREAMING_SNAKE_CASE__     (				SCREAMING_SNAKE_CASE_     ):

							"""simple docstring"""






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





													'''simple docstring'''






													__UpperCamelCase  	=      Rectangle(height=0.5  ,						width=0.5      )
													__UpperCamelCase  	=      Rectangle(height=0.4_6  ,						width=0.4_6      ).set_stroke(width=0      )
													__UpperCamelCase  	=      Rectangle(height=0.2_5  ,						width=0.2_5      )

													__UpperCamelCase  	=      [mem.copy() for i in range(6      )]
													__UpperCamelCase  	=      [mem.copy() for i in range(6      )]
													__UpperCamelCase  	=      VGroup(*SCREAMING_SNAKE_CASE_      ).arrange(SCREAMING_SNAKE_CASE_  ,						buff=0      )
													__UpperCamelCase  	=      VGroup(*SCREAMING_SNAKE_CASE_      ).arrange(SCREAMING_SNAKE_CASE_  ,						buff=0      )
													__UpperCamelCase  	=      VGroup(SCREAMING_SNAKE_CASE_  ,						SCREAMING_SNAKE_CASE_      ).arrange(SCREAMING_SNAKE_CASE_  ,						buff=0      )
													__UpperCamelCase  	=      Text('''CPU'''  ,						font_size=24      )
													__UpperCamelCase  	=      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_      )

													__UpperCamelCase  	=      [mem.copy() for i in range(4      )]
													__UpperCamelCase  	=      VGroup(*SCREAMING_SNAKE_CASE_      ).arrange(SCREAMING_SNAKE_CASE_  ,						buff=0      )
													__UpperCamelCase  	=      Text('''GPU'''  ,						font_size=24      )
													__UpperCamelCase  	=      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_      )

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

													__UpperCamelCase  	=      Text('''Model'''  ,						font_size=24      )
													__UpperCamelCase  	=      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_      )

													__UpperCamelCase  	=      []
													__UpperCamelCase  	=      []

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

																			__UpperCamelCase  	=      Rectangle(height=0.4_6 / 4  ,						width=0.4_6 / 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.0_2  ,						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_      )

													__UpperCamelCase  	=      [meta_mem.copy() for i in range(6      )]
													__UpperCamelCase  	=      [meta_mem.copy() for i in range(6      )]
													__UpperCamelCase  	=      VGroup(*SCREAMING_SNAKE_CASE_      ).arrange(SCREAMING_SNAKE_CASE_  ,						buff=0      )
													__UpperCamelCase  	=      VGroup(*SCREAMING_SNAKE_CASE_      ).arrange(SCREAMING_SNAKE_CASE_  ,						buff=0      )
													__UpperCamelCase  	=      VGroup(SCREAMING_SNAKE_CASE_  ,						SCREAMING_SNAKE_CASE_      ).arrange(SCREAMING_SNAKE_CASE_  ,						buff=0      )
													__UpperCamelCase  	=      Text('''Disk'''  ,						font_size=24      )
													__UpperCamelCase  	=      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.2_5, 0]      )
													self.add(SCREAMING_SNAKE_CASE_  ,						SCREAMING_SNAKE_CASE_      )

													__UpperCamelCase  	=      []

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

													self.add(*SCREAMING_SNAKE_CASE_      )

													__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(SCREAMING_SNAKE_CASE_  ,						SCREAMING_SNAKE_CASE_      )

													__UpperCamelCase  	=      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_      )

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

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

													for i in range(6      ):
																			__UpperCamelCase  	=      cpu_disk_arr[i]
																			__UpperCamelCase  	=      rect.copy().set_fill(SCREAMING_SNAKE_CASE_  ,						opacity=0.8      ).scale(2.0      )
																			cpa.generate_target()
																			cpa.target.move_to(model_base[i]      )

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

																									self.remove(
																									    *SCREAMING_SNAKE_CASE_  ,						*SCREAMING_SNAKE_CASE_  ,						)

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

													__UpperCamelCase  	=      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(SCREAMING_SNAKE_CASE_  ,						run_time=3      )      )

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












__lowerCamelCase						= {0: [1, 2], 1: [0, 3], 2: [0], 3: [1], 4: [5, 6], 5: [4, 6], 6: [4, 5]}

__lowerCamelCase						= {0: [1, 2, 3], 1: [0, 3], 2: [0], 3: [0, 1], 4: [], 5: []}






def    UpperCamelCase__  (   UpperCAmelCase    ,	UpperCAmelCase    ,	UpperCAmelCase     )     ->		list:







							"""simple docstring"""





							_a  :    List[Any]			=						True
							_a  :    Optional[Any]			=						[]

							for neighbour in graph[vert]:
														if not visited[neighbour]:
																					connected_verts += dfs(UpperCAmelCase    ,	UpperCAmelCase    ,	UpperCAmelCase     )

							return [vert, *connected_verts]






def    UpperCamelCase__  (   UpperCAmelCase     )     ->		list:







							"""simple docstring"""





							_a  :    Optional[int]			=						len(UpperCAmelCase     )
							_a  :    Optional[Any]			=						graph_size * [False]
							_a  :    Optional[int]			=						[]

							for i in range(UpperCAmelCase     ):
														if not visited[i]:
																					_a  :    List[str]			=						dfs(UpperCAmelCase    ,	UpperCAmelCase    ,	UpperCAmelCase     )
																					components_list.append(UpperCAmelCase     )

							return components_list


if __name__ == "__main__":
						import doctest

						doctest.testmod()