





from manim import *
class       UpperCamelCase_		(	_lowerCamelCase       ):




					def 						lowerCAmelCase      (		self	)		->				Union[str, Any]:
										_snake_case						=					Rectangle(height=0.5					,    width=0.5	)
										_snake_case						=					Rectangle(height=0.46					,    width=0.46	).set_stroke(width=0	)
										_snake_case						=					Rectangle(height=0.25					,    width=0.25	)

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

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

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

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

										_snake_case						=					[]
										_snake_case						=					[]

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

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

										_snake_case						=					[meta_mem.copy() for i in range(6	)]
										_snake_case						=					[meta_mem.copy() for i in range(6	)]
										_snake_case						=					VGroup(*lowerCAmelCase_	).arrange(lowerCAmelCase_					,    buff=0	)
										_snake_case						=					VGroup(*lowerCAmelCase_	).arrange(lowerCAmelCase_					,    buff=0	)
										_snake_case						=					VGroup(lowerCAmelCase_					,    lowerCAmelCase_	).arrange(lowerCAmelCase_					,    buff=0	)
										_snake_case						=					Text('Disk'					,    font_size=24	)
										_snake_case						=					Group(lowerCAmelCase_					,    lowerCAmelCase_	).arrange(lowerCAmelCase_					,    buff=0.5					,    aligned_edge=lowerCAmelCase_	)
										disk.move_to([-4.0, -1.25, 0]	)
										self.add(lowerCAmelCase_					,    lowerCAmelCase_	)

										_snake_case						=					[]

										for i in range(6	):
															_snake_case						=					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_	)

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

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

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

										_snake_case						=					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	):
															_snake_case						=					cpu_disk_arr[i]
															_snake_case						=					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_	)	)

										_snake_case						=					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	)	)

										_snake_case						=					[]
										_snake_case						=					[]
										for i in range(6	):
															_snake_case						=					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()










import unittest

from transformers import is_torch_available, load_tool

from .test_tools_common import ToolTesterMixin


if is_torch_available():
					import torch
class       UpperCamelCase_		(	unittest.TestCase				,	_lowerCamelCase       ):




					def 						lowerCAmelCase      (		self	)		->				str:
										_snake_case						=					load_tool('speech-to-text'	)
										self.tool.setup()




					def 						lowerCAmelCase      (		self	)		->				Optional[Any]:
										_snake_case						=					self.tool(torch.ones(3000	)	)
										self.assertEqual(lowerCAmelCase_					,    ' you'	)






					def 						lowerCAmelCase      (		self	)		->				Optional[int]:
										_snake_case						=					self.tool(audio=torch.ones(3000	)	)
										self.assertEqual(lowerCAmelCase_					,    ' you'	)



