


'''simple docstring'''

from dataclasses import dataclass, field
from typing import Tuple

from ..utils import cached_property, is_torch_available, is_torch_tpu_available, logging, requires_backends
from .benchmark_args_utils import BenchmarkArguments


if is_torch_available():
	import torch

if is_torch_tpu_available(check_device=False):
	import torch_xla.core.xla_model as xm


_UpperCAmelCase				: Tuple							    =				logging.get_logger(__name__)


@dataclass
class       a__				( a__      ):







				"""simple docstring"""



				__UpperCamelCase    :		Any	=	[
				    """no_inference""",
				    """no_cuda""",
				    """no_tpu""",
				    """no_speed""",
				    """no_memory""",
				    """no_env_print""",
				    """no_multi_process""",
				]




				def __init__(self       ,			**__lowercase		):





										for deprecated_arg in self.deprecated_args:
																if deprecated_arg in kwargs:
																						__lowerCAmelCase							       =				deprecated_arg[3:]
																						setattr(self       ,			lowercase__       ,			not kwargs.pop(lowercase__		)		)
																						logger.warning(
																						    F"""{deprecated_arg} is depreciated. Please use --no_{positive_arg} or"""
																						    F""" {positive_arg}={kwargs[positive_arg]}"""		)

										__lowerCAmelCase							       =				kwargs.pop('''torchscript'''       ,			self.torchscript		)
										__lowerCAmelCase							       =				kwargs.pop('''torch_xla_tpu_print_metrics'''       ,			self.torch_xla_tpu_print_metrics		)
										__lowerCAmelCase							       =				kwargs.pop('''fp16_opt_level'''       ,			self.fpaa_opt_level		)
										super().__init__(**lowercase__		)

				__UpperCamelCase    :		bool	=	field(default=a__							,						metadata={'help': 'Trace the models using torchscript'}      )
				__UpperCamelCase    :		bool	=	field(default=a__							,						metadata={'help': 'Print Xla/PyTorch tpu metrics'}      )
				__UpperCamelCase    :		str	=	field(
				    default='O1'							,						metadata={
				        'help': (
				            'For fp16: Apex AMP optimization level selected in [\'O0\', \'O1\', \'O2\', and \'O3\']. '
				            'See details at https://nvidia.github.io/apex/amp.html'
				        )
				    }							,						)




				@cached_property
				def 					_snake_case  (self		):
										requires_backends(self       ,			['''torch''']		)
										logger.info('''PyTorch: setting up devices'''		)
										if not self.cuda:
																__lowerCAmelCase							       =				torch.device('''cpu'''		)
																__lowerCAmelCase							       =				0
										elif is_torch_tpu_available():
																__lowerCAmelCase							       =				xm.xla_device()
																__lowerCAmelCase							       =				0
										else:
																__lowerCAmelCase							       =				torch.device('''cuda''' if torch.cuda.is_available() else '''cpu'''		)
																__lowerCAmelCase							       =				torch.cuda.device_count()
										return device, n_gpu




				@property
				def 					_snake_case  (self		):
										return is_torch_tpu_available() and self.tpu




				@property
				def 					_snake_case  (self		):
										requires_backends(self       ,			['''torch''']		)
										# TODO(PVP): currently only single GPU is supported
										return torch.cuda.current_device()




				@property
				def 					_snake_case  (self		):
										requires_backends(self       ,			['''torch''']		)
										return self._setup_devices[0]




				@property
				def 					_snake_case  (self		):
										requires_backends(self       ,			['''torch''']		)
										return self._setup_devices[1]




				@property
				def 					_snake_case  (self		):
										return self.n_gpu > 0





'''simple docstring'''

from manim import *


class       a__				( __A      ):







				"""simple docstring"""



				def 					_snake_case  (self		):
										__lowerCAmelCase							       =				Rectangle(height=0.5       ,			width=0.5		)
										__lowerCAmelCase							       =				Rectangle(height=0.4_6       ,			width=0.4_6		).set_stroke(width=0		)

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

										__lowerCAmelCase							       =				[mem.copy() for i in range(1		)]
										__lowerCAmelCase							       =				VGroup(*__lowercase		).arrange(__lowercase       ,			buff=0		)
										__lowerCAmelCase							       =				Text('''GPU'''       ,			font_size=24		)
										__lowerCAmelCase							       =				Group(__lowercase       ,			__lowercase		).arrange(__lowercase       ,			buff=0.5       ,			aligned_edge=__lowercase		)
										gpu.align_to(__lowercase       ,			__lowercase		)
										gpu.set_x(gpu.get_x() - 1		)

										self.add(__lowercase		)

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

										__lowerCAmelCase							       =				Text('''Model'''       ,			font_size=24		)
										__lowerCAmelCase							       =				Group(__lowercase       ,			__lowercase		).arrange(__lowercase       ,			buff=0.5       ,			aligned_edge=__lowercase		)
										model.move_to([3, -1.0, 0]		)

										self.play(
										    Create(__lowercase       ,			run_time=1		)       ,			Create(__lowercase       ,			run_time=1		)       ,			Create(__lowercase       ,			run_time=1		)       ,			)

										__lowerCAmelCase							       =				MarkupText(
										    F"""First, an empty model skeleton is loaded\ninto <span fgcolor='{YELLOW}'>memory</span> without using much RAM."""       ,			font_size=24       ,			)

										__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]		)

										step_a.move_to([2, 2, 0]		)
										self.play(Write(__lowercase       ,			run_time=2.5		)       ,			Write(__lowercase		)       ,			Write(__lowercase		)		)

										self.add(__lowercase		)

										__lowerCAmelCase							       =				[]
										__lowerCAmelCase							       =				[]
										__lowerCAmelCase							       =				[]
										for i, rect in enumerate(__lowercase		):
																__lowerCAmelCase							       =				Rectangle(height=0.4_6       ,			width=0.4_6		).set_stroke(width=0.0		).set_fill(__lowercase       ,			opacity=0.7		)
																cpu_target.move_to(__lowercase		)
																cpu_target.generate_target()
																__lowerCAmelCase							       =				0.4_6 / 4
																__lowerCAmelCase							       =				0.4_6 / 3

																if i == 0:
																						cpu_target.target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT		)       ,			buff=0.0_2       ,			direction=__lowercase		)
																						cpu_target.target.set_x(cpu_target.target.get_x() + 0.1		)
																elif i == 3:
																						cpu_target.target.next_to(cpu_targs[0].target       ,			direction=__lowercase       ,			buff=0.0		)
																else:
																						cpu_target.target.next_to(cpu_targs[i - 1].target       ,			direction=__lowercase       ,			buff=0.0		)
																cpu_targs.append(__lowercase		)

																first_animations.append(rect.animate(run_time=0.5		).set_stroke(__lowercase		)		)
																second_animations.append(MoveToTarget(__lowercase       ,			run_time=1.5		)		)

										self.play(*__lowercase		)
										self.play(*__lowercase		)

										self.wait()

