






"""simple docstring"""
from manim import *







class     UpperCamelCase_ (__A  ):





	def   _SCREAMING_SNAKE_CASE   (   self      :				Dict		)		->    List[str]:
				UpperCAmelCase_  :				str      =      Rectangle(height=0.5			,			width=0.5		)
				UpperCAmelCase_  :				Optional[int]      =      Rectangle(height=0.2_5			,			width=0.2_5		)
				UpperCAmelCase_  :				int      =      Rectangle(height=0.4_6			,			width=0.4_6		).set_stroke(width=0		)

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

				UpperCAmelCase_  :				str      =      [mem.copy() for i in range(4		)]
				UpperCAmelCase_  :				Union[str, Any]      =      VGroup(*lowerCAmelCase_		).arrange(lowerCAmelCase_			,			buff=0		)
				UpperCAmelCase_  :				Dict      =      Text("GPU"			,			font_size=24		)
				UpperCAmelCase_  :				Optional[Any]      =      Group(lowerCAmelCase_			,			lowerCAmelCase_		).arrange(lowerCAmelCase_			,			buff=0.5			,			aligned_edge=lowerCAmelCase_		)
				gpu.move_to([-1, -1, 0]		)
				self.add(lowerCAmelCase_		)

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

				UpperCAmelCase_  :				str      =      Text("Model"			,			font_size=24		)
				UpperCAmelCase_  :				Optional[Any]      =      Group(lowerCAmelCase_			,			lowerCAmelCase_		).arrange(lowerCAmelCase_			,			buff=0.5			,			aligned_edge=lowerCAmelCase_		)
				model.move_to([3, -1.0, 0]		)
				self.add(lowerCAmelCase_		)

				UpperCAmelCase_  :				Optional[int]      =      []
				UpperCAmelCase_  :				List[Any]      =      []
				UpperCAmelCase_  :				Optional[int]      =      []

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

							UpperCAmelCase_  :				Optional[Any]      =      Rectangle(height=0.4_6 / 4			,			width=0.4_6 / 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.0_2			,			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_		)

				UpperCAmelCase_  :				List[Any]      =      [mem.copy() for i in range(6		)]
				UpperCAmelCase_  :				Tuple      =      VGroup(*lowerCAmelCase_		).arrange(lowerCAmelCase_			,			buff=0		)

				UpperCAmelCase_  :				Union[str, Any]      =      Text("Loaded Checkpoint"			,			font_size=24		)
				UpperCAmelCase_  :				Optional[Any]      =      Group(lowerCAmelCase_			,			lowerCAmelCase_		).arrange(lowerCAmelCase_			,			buff=0.5			,			aligned_edge=lowerCAmelCase_		)
				checkpoint.move_to([3, 0.5, 0]		)

				self.add(lowerCAmelCase_		)

				UpperCAmelCase_  :				Union[str, Any]      =      []
				UpperCAmelCase_  :				Optional[Any]      =      []

				for i, rect in enumerate(lowerCAmelCase_		):
							UpperCAmelCase_  :				List[str]      =      fill.copy().set_fill(lowerCAmelCase_			,			opacity=0.7		)
							target.move_to(lowerCAmelCase_		)
							ckpt_arr.append(lowerCAmelCase_		)

							UpperCAmelCase_  :				List[str]      =      target.copy()
							if i < 5:
										cpu_target.move_to(cpu_left_col_base[i + 1]		)
							else:
										cpu_target.move_to(cpu_right_col_base[i - 5]		)
							ckpt_cpu_arr.append(lowerCAmelCase_		)
				self.add(*lowerCAmelCase_			,			*lowerCAmelCase_		)

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

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

				UpperCAmelCase_  :				Any      =      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_		)

				UpperCAmelCase_  :				Tuple      =      MarkupText(
				    f"""Based on the passed in configuration, weights are stored in\na variety of np.memmaps on disk or to a particular device."""			,			font_size=24			,			)
				step_a.move_to([2, 2, 0]		)

				UpperCAmelCase_  :				Optional[int]      =      [meta_mem.copy() for i in range(6		)]
				UpperCAmelCase_  :				Dict      =      [meta_mem.copy() for i in range(6		)]
				UpperCAmelCase_  :				int      =      VGroup(*lowerCAmelCase_		).arrange(lowerCAmelCase_			,			buff=0		)
				UpperCAmelCase_  :				Dict      =      VGroup(*lowerCAmelCase_		).arrange(lowerCAmelCase_			,			buff=0		)
				UpperCAmelCase_  :				str      =      VGroup(lowerCAmelCase_			,			lowerCAmelCase_		).arrange(lowerCAmelCase_			,			buff=0		)
				UpperCAmelCase_  :				int      =      Text("Disk"			,			font_size=24		)
				UpperCAmelCase_  :				Any      =      Group(lowerCAmelCase_			,			lowerCAmelCase_		).arrange(lowerCAmelCase_			,			buff=0.5			,			aligned_edge=lowerCAmelCase_		)
				disk.move_to([-4.0, -1.2_5, 0]		)
				self.play(Write(lowerCAmelCase_			,			run_time=3		)			,			Write(lowerCAmelCase_			,			run_time=1		)			,			Create(lowerCAmelCase_			,			run_time=1		)		)

				UpperCAmelCase_  :				Dict      =      []
				for i, rect in enumerate(lowerCAmelCase_		):
							UpperCAmelCase_  :				Optional[int]      =      rect.copy()
							target.generate_target()
							target.target.move_to(disk_left_col_base[i]		).scale(0.5		)
							animations.append(MoveToTarget(lowerCAmelCase_			,			run_time=1.5		)		)
				self.play(*lowerCAmelCase_		)

				self.play(FadeOut(lowerCAmelCase_		)		)

				UpperCAmelCase_  :				Optional[int]      =      MarkupText(f"""Then, the checkpoint is removed from memory\nthrough garbage collection."""			,			font_size=24		)
				step_a.move_to([2, 2, 0]		)

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

				self.play(
				    FadeOut(lowerCAmelCase_			,			lowerCAmelCase_			,			*lowerCAmelCase_			,			*lowerCAmelCase_		)			,			)

				self.wait()











"""simple docstring"""
import doctest
import logging
import os
import unittest
from pathlib import Path
from typing import List, Union

import transformers
from transformers.testing_utils import require_tf, require_torch, slow


lowerCamelCase_       			=   logging.getLogger()







@unittest.skip('''Temporarily disable the doc tests.'''  )
@require_torch
@require_tf
@slow
class     UpperCamelCase_ (unittest.TestCase  ):





	def   _SCREAMING_SNAKE_CASE   (   self      :				Union[str, Any]			,			lowerCAmelCase_      :				Path			,			lowerCAmelCase_      :				Union[str, None] = None			,			lowerCAmelCase_      :				Union[List[str], None] = None			,			lowerCAmelCase_      :				Union[str, List[str], None] = None			,			lowerCAmelCase_      :				bool = True			,			)		->    Tuple:
				UpperCAmelCase_  :				Optional[Any]      =      [file for file in os.listdir(lowerCAmelCase_		) if os.path.isfile(os.path.join(lowerCAmelCase_			,			lowerCAmelCase_		)		)]

				if identifier is not None:
							UpperCAmelCase_  :				Optional[int]      =      [file for file in files if identifier in file]

				if n_identifier is not None:
							if isinstance(lowerCAmelCase_			,			lowerCAmelCase_		):
										for n_ in n_identifier:
													UpperCAmelCase_  :				List[Any]      =      [file for file in files if n_ not in file]
							else:
										UpperCAmelCase_  :				Optional[Any]      =      [file for file in files if n_identifier not in file]

				UpperCAmelCase_  :				List[Any]      =      ignore_files or []
				ignore_files.append("__init__.py"		)
				UpperCAmelCase_  :				Optional[Any]      =      [file for file in files if file not in ignore_files]

				for file in files:
							# Open all files
							print("Testing"			,			lowerCAmelCase_		)

							if only_modules:
										UpperCAmelCase_  :				str      =      file.split("."		)[0]
										try:
													UpperCAmelCase_  :				Tuple      =      getattr(lowerCAmelCase_			,			lowerCAmelCase_		)
													UpperCAmelCase_  :				int      =      doctest.DocTestSuite(lowerCAmelCase_		)
													UpperCAmelCase_  :				str      =      unittest.TextTestRunner().run(lowerCAmelCase_		)
													self.assertIs(len(result.failures		)			,			0		)
										except AttributeError:
													logger.info(f"""{module_identifier} is not a module."""		)
							else:
										UpperCAmelCase_  :				List[Any]      =      doctest.testfile(str(".." / directory / file		)			,			optionflags=doctest.ELLIPSIS		)
										self.assertIs(result.failed			,			0		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Optional[int]		)		->    List[Any]:
				UpperCAmelCase_  :				Optional[int]      =      Path("src/transformers"		)
				UpperCAmelCase_  :				List[Any]      =      "modeling"
				UpperCAmelCase_  :				Tuple      =      [
				    "modeling_ctrl.py",
				    "modeling_tf_ctrl.py",
				]
				self.analyze_directory(lowerCAmelCase_			,			identifier=lowerCAmelCase_			,			ignore_files=lowerCAmelCase_		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Union[str, Any]		)		->    List[Any]:
				UpperCAmelCase_  :				List[str]      =      Path("src/transformers"		)
				UpperCAmelCase_  :				int      =      "tokenization"
				self.analyze_directory(lowerCAmelCase_			,			identifier=lowerCAmelCase_		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Optional[Any]		)		->    Optional[Any]:
				UpperCAmelCase_  :				int      =      Path("src/transformers"		)
				UpperCAmelCase_  :				Any      =      "configuration"
				self.analyze_directory(lowerCAmelCase_			,			identifier=lowerCAmelCase_		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Any		)		->    Any:
				UpperCAmelCase_  :				int      =      Path("src/transformers"		)
				UpperCAmelCase_  :				List[Any]      =      ["configuration", "modeling", "tokenization"]
				self.analyze_directory(lowerCAmelCase_			,			n_identifier=lowerCAmelCase_		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				List[str]		)		->    Dict:
				UpperCAmelCase_  :				List[str]      =      Path("docs/source"		)
				UpperCAmelCase_  :				int      =      ["favicon.ico"]
				self.analyze_directory(lowerCAmelCase_			,			ignore_files=lowerCAmelCase_			,			only_modules=lowerCAmelCase_		)



