



'''simple docstring'''

from manim import *

class __snake_case(				_lowerCAmelCase ):


						'''simple docstring'''



						def     __snake_case   ( self				)     ->     Any:
							lowerCAmelCase   =     Rectangle(height=0.5     ,	width=0.5				)
							lowerCAmelCase   =     Rectangle(height=0.4_6     ,	width=0.4_6				).set_stroke(width=0				)

							lowerCAmelCase   =     Rectangle(height=0.2_5     ,	width=0.2_5				)

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

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

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

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

							lowerCAmelCase   =     []
							lowerCAmelCase   =     []

							for i, rect in enumerate(__a				):
								lowerCAmelCase   =     fill.copy().set_fill(__a     ,	opacity=0.8				)
								target.move_to(__a				)
								model_arr.append(__a				)

								lowerCAmelCase   =     Rectangle(height=0.4_6     ,	width=0.4_6				).set_stroke(width=0.0				).set_fill(__a     ,	opacity=0.8				)
								cpu_target.move_to(cpu_left_col_base[i]				)
								model_cpu_arr.append(__a				)

							self.add(*__a     ,	*__a				)

							lowerCAmelCase   =     [meta_mem.copy() for i in range(6				)]
							lowerCAmelCase   =     [meta_mem.copy() for i in range(6				)]
							lowerCAmelCase   =     VGroup(*__a				).arrange(__a     ,	buff=0				)
							lowerCAmelCase   =     VGroup(*__a				).arrange(__a     ,	buff=0				)
							lowerCAmelCase   =     VGroup(__a     ,	__a				).arrange(__a     ,	buff=0				)
							lowerCAmelCase   =     Text("""Disk"""     ,	font_size=24				)
							lowerCAmelCase   =     Group(__a     ,	__a				).arrange(__a     ,	buff=0.5     ,	aligned_edge=__a				)
							disk.move_to([-4, -1.2_5, 0]				)
							self.add(__a     ,	__a				)

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

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

							lowerCAmelCase   =     MarkupText(
							    f'<span fgcolor=\'{BLUE}\'>●</span> Checkpoint'     ,	font_size=18     ,	)

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

							lowerCAmelCase   =     MarkupText(
							    f'Now watch as an input is passed through the model\nand how the memory is utilized and handled.'     ,	font_size=24     ,	)
							step_a.move_to([2, 2, 0]				)

							self.play(Write(__a				)				)

							lowerCAmelCase   =     Square(0.3				)
							input.set_fill(__a     ,	opacity=1.0				)
							input.set_stroke(width=0.0				)
							input.next_to(model_base[0]     ,	__a     ,	buff=0.5				)

							self.play(Write(__a				)				)

							input.generate_target()
							input.target.next_to(model_arr[0]     ,	direction=__a     ,	buff=0.0_2				)
							self.play(MoveToTarget(__a				)				)

							self.play(FadeOut(__a				)				)

							lowerCAmelCase   =     Arrow(start=__a     ,	end=__a     ,	color=__a     ,	buff=0.5				)
							a.next_to(model_arr[0].get_left()     ,	__a     ,	buff=0.2				)

							model_cpu_arr[0].generate_target()
							model_cpu_arr[0].target.move_to(gpu_rect[0]				)

							lowerCAmelCase   =     MarkupText(
							    f'As the input reaches a layer, the hook triggers\nand weights are moved from the CPU\nto the GPU and back.'     ,	font_size=24     ,	)
							step_a.move_to([2, 2, 0]				)

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

							lowerCAmelCase   =     {"""run_time""": 1, """fade_in""": True, """fade_out""": True, """buff""": 0.0_2}

							self.play(
							    Write(__a				)     ,	Circumscribe(model_arr[0]     ,	color=__a     ,	**__a				)     ,	Circumscribe(model_cpu_arr[0]     ,	color=__a     ,	**__a				)     ,	Circumscribe(gpu_rect[0]     ,	color=__a     ,	**__a				)     ,	)
							self.play(MoveToTarget(model_cpu_arr[0]				)				)

							lowerCAmelCase   =     a.copy()
							for i in range(6				):
								a_c.next_to(model_arr[i].get_right() + 0.0_2     ,	__a     ,	buff=0.2				)

								input.generate_target()
								input.target.move_to(model_arr[i].get_right() + 0.0_2				)

								lowerCAmelCase   =     AnimationGroup(
								    FadeOut(__a     ,	run_time=0.5				)     ,	MoveToTarget(__a     ,	run_time=0.5				)     ,	FadeIn(__a     ,	run_time=0.5				)     ,	lag_ratio=0.2				)

								self.play(__a				)

								model_cpu_arr[i].generate_target()
								model_cpu_arr[i].target.move_to(cpu_left_col_base[i]				)

								if i < 5:
									model_cpu_arr[i + 1].generate_target()
									model_cpu_arr[i + 1].target.move_to(gpu_rect[0]				)
									if i >= 1:
										lowerCAmelCase   =     0.7

									self.play(
									    Circumscribe(model_arr[i]     ,	**__a				)     ,	Circumscribe(cpu_left_col_base[i]     ,	**__a				)     ,	Circumscribe(cpu_left_col_base[i + 1]     ,	color=__a     ,	**__a				)     ,	Circumscribe(gpu_rect[0]     ,	color=__a     ,	**__a				)     ,	Circumscribe(model_arr[i + 1]     ,	color=__a     ,	**__a				)     ,	)
									if i < 1:
										self.play(
										    MoveToTarget(model_cpu_arr[i]				)     ,	MoveToTarget(model_cpu_arr[i + 1]				)     ,	)
									else:
										self.play(
										    MoveToTarget(model_cpu_arr[i]     ,	run_time=0.7				)     ,	MoveToTarget(model_cpu_arr[i + 1]     ,	run_time=0.7				)     ,	)
								else:
									model_cpu_arr[i].generate_target()
									model_cpu_arr[i].target.move_to(cpu_left_col_base[-1]				)
									input.generate_target()
									input.target.next_to(model_arr[-1].get_right()     ,	RIGHT + 0.0_2     ,	buff=0.2				)

									self.play(
									    Circumscribe(model_arr[-1]     ,	color=__a     ,	**__a				)     ,	Circumscribe(cpu_left_col_base[-1]     ,	color=__a     ,	**__a				)     ,	Circumscribe(gpu_rect[0]     ,	color=__a     ,	**__a				)     ,	)

									self.play(MoveToTarget(model_cpu_arr[i]				)				)

								lowerCAmelCase   =     a_c
								lowerCAmelCase   =     a_c.copy()

							input.generate_target()
							input.target.next_to(model_base[-1]     ,	RIGHT + 0.0_2     ,	buff=0.5				)
							self.play(
							    FadeOut(__a				)     ,	FadeOut(__a     ,	run_time=0.5				)     ,	)

							lowerCAmelCase   =     MarkupText(f'Inference on a model too large for GPU memory\nis successfully completed.'     ,	font_size=24				)
							step_a.move_to([2, 2, 0]				)

							self.play(Write(__a     ,	run_time=3				)     ,	MoveToTarget(__a				)				)

							self.wait()




'''simple docstring'''

class __snake_case(				_lowerCAmelCase ):


						'''simple docstring'''



						pass







class __snake_case(				_lowerCAmelCase ):


						'''simple docstring'''



						pass







class __snake_case:


						'''simple docstring'''



						def __init__( self				)     ->     int:
							lowerCAmelCase   =     [
							    [],
							    [],
							    [],
							]


						def     __snake_case   ( self     ,	A_     ,	A_				)     ->     None:
							try:
								if len(self.queues[priority]				) >= 100:
									raise OverflowError("""Maximum queue size is 100"""				)
								self.queues[priority].append(A_				)
							except IndexError:
								raise ValueError("""Valid priorities are 0, 1, and 2"""				)


						def     __snake_case   ( self				)     ->     int:
							for queue in self.queues:
								if queue:
									return queue.pop(0				)
							raise UnderFlowError("""All queues are empty"""				)




						def __str__( self				)     ->     str:
							return "\n".join(f'Priority {i}: {q}' for i, q in enumerate(self.queues				)				)







class __snake_case:


						'''simple docstring'''



						def __init__( self				)     ->     Dict:
							lowerCAmelCase   =     []


						def     __snake_case   ( self     ,	A_				)     ->     None:
							if len(self.queue				) == 100:
								raise OverFlowError("""Maximum queue size is 100"""				)
							self.queue.append(A_				)


						def     __snake_case   ( self				)     ->     int:
							if not self.queue:
								raise UnderFlowError("""The queue is empty"""				)
							else:
								lowerCAmelCase   =     min(self.queue				)
								self.queue.remove(A_				)
								return data




						def __str__( self				)     ->     str:
							return str(self.queue				)







def 		_snake_case		( )      ->						Tuple:







	"""simple docstring"""
	lowerCAmelCase   =     FixedPriorityQueue()
	fpq.enqueue(0							,		10							)
	fpq.enqueue(1							,		70							)
	fpq.enqueue(0							,		100							)
	fpq.enqueue(2							,		1							)
	fpq.enqueue(2							,		5							)
	fpq.enqueue(1							,		7							)
	fpq.enqueue(2							,		4							)
	fpq.enqueue(1							,		64							)
	fpq.enqueue(0							,		128							)
	print(_SCREAMING_SNAKE_CASE							)
	print(fpq.dequeue()							)
	print(fpq.dequeue()							)
	print(fpq.dequeue()							)
	print(fpq.dequeue()							)
	print(fpq.dequeue()							)
	print(_SCREAMING_SNAKE_CASE							)
	print(fpq.dequeue()							)
	print(fpq.dequeue()							)
	print(fpq.dequeue()							)
	print(fpq.dequeue()							)
	print(fpq.dequeue()							)






def 		_snake_case		( )      ->						Optional[Any]:







	"""simple docstring"""
	lowerCAmelCase   =     ElementPriorityQueue()
	epq.enqueue(10							)
	epq.enqueue(70							)
	epq.enqueue(100							)
	epq.enqueue(1							)
	epq.enqueue(5							)
	epq.enqueue(7							)
	epq.enqueue(4							)
	epq.enqueue(64							)
	epq.enqueue(128							)
	print(_SCREAMING_SNAKE_CASE							)
	print(epq.dequeue()							)
	print(epq.dequeue()							)
	print(epq.dequeue()							)
	print(epq.dequeue()							)
	print(epq.dequeue()							)
	print(_SCREAMING_SNAKE_CASE							)
	print(epq.dequeue()							)
	print(epq.dequeue()							)
	print(epq.dequeue()							)
	print(epq.dequeue()							)
	print(epq.dequeue()							)


if __name__ == "__main__":
				fixed_priority_queue()
				element_priority_queue()