





"""simple docstring"""




from manim import *




class 					_a		( _lowerCAmelCase							):






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




										'''simple docstring'''



										_UpperCamelCase     :   Optional[Any]      =       Rectangle(height=0.5,					width=0.5				)
										_UpperCamelCase     :   List[str]      =       Rectangle(height=0.46,					width=0.46				).set_stroke(width=0				)
										_UpperCamelCase     :   Tuple      =       Rectangle(height=0.25,					width=0.25				)

										_UpperCamelCase     :   str      =       [mem.copy() for i in range(6				)]
										_UpperCamelCase     :   Optional[int]      =       [mem.copy() for i in range(6				)]
										_UpperCamelCase     :   List[Any]      =       VGroup(*lowerCAmelCase__				).arrange(lowerCAmelCase__,					buff=0				)
										_UpperCamelCase     :   int      =       VGroup(*lowerCAmelCase__				).arrange(lowerCAmelCase__,					buff=0				)
										_UpperCamelCase     :   Optional[Any]      =       VGroup(lowerCAmelCase__,					lowerCAmelCase__				).arrange(lowerCAmelCase__,					buff=0				)
										_UpperCamelCase     :   Union[str, Any]      =       Text('''CPU''',					font_size=2_4				)
										_UpperCamelCase     :   Optional[Any]      =       Group(lowerCAmelCase__,					lowerCAmelCase__				).arrange(lowerCAmelCase__,					buff=0.5,					aligned_edge=lowerCAmelCase__				)
										cpu.move_to([-2.5, -0.5, 0]				)
										self.add(lowerCAmelCase__				)

										_UpperCamelCase     :   Union[str, Any]      =       [mem.copy() for i in range(4				)]
										_UpperCamelCase     :   List[str]      =       VGroup(*lowerCAmelCase__				).arrange(lowerCAmelCase__,					buff=0				)
										_UpperCamelCase     :   Optional[int]      =       Text('''GPU''',					font_size=2_4				)
										_UpperCamelCase     :   List[str]      =       Group(lowerCAmelCase__,					lowerCAmelCase__				).arrange(lowerCAmelCase__,					buff=0.5,					aligned_edge=lowerCAmelCase__				)
										gpu.move_to([-1, -1, 0]				)
										self.add(lowerCAmelCase__				)

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

										_UpperCamelCase     :   Any      =       Text('''Model''',					font_size=2_4				)
										_UpperCamelCase     :   List[str]      =       Group(lowerCAmelCase__,					lowerCAmelCase__				).arrange(lowerCAmelCase__,					buff=0.5,					aligned_edge=lowerCAmelCase__				)
										model.move_to([3, -1.0, 0]				)
										self.add(lowerCAmelCase__				)

										_UpperCamelCase     :   str      =       []
										_UpperCamelCase     :   Union[str, Any]      =       []

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

																_UpperCamelCase     :   Any      =       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__				)

										_UpperCamelCase     :   Optional[Any]      =       [meta_mem.copy() for i in range(6				)]
										_UpperCamelCase     :   int      =       [meta_mem.copy() for i in range(6				)]
										_UpperCamelCase     :   Tuple      =       VGroup(*lowerCAmelCase__				).arrange(lowerCAmelCase__,					buff=0				)
										_UpperCamelCase     :   Any      =       VGroup(*lowerCAmelCase__				).arrange(lowerCAmelCase__,					buff=0				)
										_UpperCamelCase     :   Any      =       VGroup(lowerCAmelCase__,					lowerCAmelCase__				).arrange(lowerCAmelCase__,					buff=0				)
										_UpperCamelCase     :   List[Any]      =       Text('''Disk''',					font_size=2_4				)
										_UpperCamelCase     :   int      =       Group(lowerCAmelCase__,					lowerCAmelCase__				).arrange(lowerCAmelCase__,					buff=0.5,					aligned_edge=lowerCAmelCase__				)
										disk.move_to([-4.0, -1.25, 0]				)
										self.add(lowerCAmelCase__,					lowerCAmelCase__				)

										_UpperCamelCase     :   List[str]      =       []

										for i in range(6				):
																_UpperCamelCase     :   str      =       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__				)

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

										_UpperCamelCase     :   int      =       MarkupText(
										    f"""<b>Key:</b>\n\n<span fgcolor='{YELLOW}'>●</span> Empty Model""",					font_size=1_8,					)

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

										self.add(lowerCAmelCase__,					lowerCAmelCase__				)

										_UpperCamelCase     :   str      =       MarkupText(
										    f"""<span fgcolor='{BLUE}'>●</span> Checkpoint""",					font_size=1_8,					)

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

										_UpperCamelCase     :   Any      =       MarkupText(f"""The offloaded weights are all sent to the CPU.""",					font_size=2_4				)
										step_a.move_to([2, 2, 0]				)

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

										for i in range(6				):
																_UpperCamelCase     :   Any      =       cpu_disk_arr[i]
																_UpperCamelCase     :   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__				)				)

										_UpperCamelCase     :   Dict      =       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=2_4,					)
										step_a.move_to([2, 2, 0]				)

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

										_UpperCamelCase     :   Dict      =       []
										_UpperCamelCase     :   Any      =       []
										for i in range(6				):
																_UpperCamelCase     :   Optional[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'''

import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding




class 		SCREAMING_SNAKE_CASE_					(_UpperCAmelCase      ):



			"""simple docstring"""






			__magic_name__ :				Dict   							=       ["""image_processor""", """tokenizer"""]
			__magic_name__ :				Union[str, Any]   							=       """VideoMAEImageProcessor"""
			__magic_name__ :				List[str]   							=       ("""CLIPTokenizer""", """CLIPTokenizerFast""")



			def __init__(							self				,			snake_case_=None				,			snake_case_=None				,			**snake_case_					):
									snake_case :       int				=    None
									if "feature_extractor" in kwargs:
															warnings.warn(
															    "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
															    " instead."				,			snake_case_				,			)
															snake_case :       Optional[int]				=    kwargs.pop("feature_extractor"					)

									snake_case :       Union[str, Any]				=    image_processor if image_processor is not None else feature_extractor
									if image_processor is None:
															raise ValueError("You need to specify an `image_processor`."					)
									if tokenizer is None:
															raise ValueError("You need to specify a `tokenizer`."					)

									super().__init__(snake_case_				,			snake_case_					)
									snake_case :       List[Any]				=    self.image_processor



			def __call__(							self				,			snake_case_=None				,			snake_case_=None				,			snake_case_=None				,			**snake_case_					):

									if text is None and videos is None:
															raise ValueError("You have to specify either text or videos. Both cannot be none."					)

									if text is not None:
															snake_case :       List[Any]				=    self.tokenizer(snake_case_				,			return_tensors=snake_case_				,			**snake_case_					)

									if videos is not None:
															snake_case :       List[Any]				=    self.image_processor(snake_case_				,			return_tensors=snake_case_				,			**snake_case_					)

									if text is not None and videos is not None:
															snake_case :       Tuple				=    image_features.pixel_values
															return encoding
									elif text is not None:
															return encoding
									else:
															return BatchEncoding(data=dict(**snake_case_					)				,			tensor_type=snake_case_					)



			def   lowerCamelCase (							self				,			*snake_case_				,			**snake_case_					):
									return self.tokenizer.batch_decode(*snake_case_				,			**snake_case_					)



			def   lowerCamelCase (							self				,			*snake_case_				,			**snake_case_					):
									return self.tokenizer.decode(*snake_case_				,			**snake_case_					)



			@property
			def   lowerCamelCase (							self					):
									return ["input_ids", "attention_mask", "position_ids", "pixel_values"]



			@property
			def   lowerCamelCase (							self					):
									warnings.warn(
									    "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."				,			snake_case_				,			)
									return self.image_processor_class






			@property
			def   lowerCamelCase (							self					):
									warnings.warn(
									    "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."				,			snake_case_				,			)
									return self.image_processor





