


'''simple docstring'''

import copy
import json
import os
import tempfile

from transformers import is_torch_available

from .test_configuration_utils import config_common_kwargs


class       a__				( __A      ):







				"""simple docstring"""



				def __init__(self       ,			__lowercase       ,			__lowercase=None       ,			__lowercase=True       ,			__lowercase=None       ,			**__lowercase		):
										__lowerCAmelCase							       =				parent
										__lowerCAmelCase							       =				config_class
										__lowerCAmelCase							       =				has_text_modality
										__lowerCAmelCase							       =				kwargs
										__lowerCAmelCase							       =				common_properties




				def 					_snake_case  (self		):
										__lowerCAmelCase							       =				self.config_class(**self.inputs_dict		)
										__lowerCAmelCase							       =				(
										    ['''hidden_size''', '''num_attention_heads''', '''num_hidden_layers''']
										    if self.common_properties is None
										    else self.common_properties
										)

										# Add common fields for text models
										if self.has_text_modality:
																common_properties.extend(['''vocab_size''']		)

										# Test that config has the common properties as getters
										for prop in common_properties:
																self.parent.assertTrue(hasattr(__lowercase       ,			__lowercase		)       ,			msg=F"""`{prop}` does not exist"""		)

										# Test that config has the common properties as setter
										for idx, name in enumerate(__lowercase		):
																try:
																						setattr(__lowercase       ,			__lowercase       ,			__lowercase		)
																						self.parent.assertEqual(
																						    getattr(__lowercase       ,			__lowercase		)       ,			__lowercase       ,			msg=F"""`{name} value {idx} expected, but was {getattr(__lowercase       ,			__lowercase		)}"""		)
																except NotImplementedError:
																						# Some models might not be able to implement setters for common_properties
																						# In that case, a NotImplementedError is raised
																						pass

        # Test if config class can be called with Config(prop_name=..)
										for idx, name in enumerate(__lowercase		):
																try:
																						__lowerCAmelCase							       =				self.config_class(**{name: idx}		)
																						self.parent.assertEqual(
																						    getattr(__lowercase       ,			__lowercase		)       ,			__lowercase       ,			msg=F"""`{name} value {idx} expected, but was {getattr(__lowercase       ,			__lowercase		)}"""		)
																except NotImplementedError:
																						# Some models might not be able to implement setters for common_properties
																						# In that case, a NotImplementedError is raised
																						pass




				def 					_snake_case  (self		):
										__lowerCAmelCase							       =				self.config_class(**self.inputs_dict		)
										__lowerCAmelCase							       =				json.loads(config.to_json_string()		)
										for key, value in self.inputs_dict.items():
																self.parent.assertEqual(obj[key]       ,			__lowercase		)




				def 					_snake_case  (self		):
										__lowerCAmelCase							       =				self.config_class(**self.inputs_dict		)

										with tempfile.TemporaryDirectory() as tmpdirname:
																__lowerCAmelCase							       =				os.path.join(__lowercase       ,			'''config.json'''		)
																config_first.to_json_file(__lowercase		)
																__lowerCAmelCase							       =				self.config_class.from_json_file(__lowercase		)

										self.parent.assertEqual(config_second.to_dict()       ,			config_first.to_dict()		)




				def 					_snake_case  (self		):
										__lowerCAmelCase							       =				self.config_class(**self.inputs_dict		)

										with tempfile.TemporaryDirectory() as tmpdirname:
																config_first.save_pretrained(__lowercase		)
																__lowerCAmelCase							       =				self.config_class.from_pretrained(__lowercase		)

										self.parent.assertEqual(config_second.to_dict()       ,			config_first.to_dict()		)




				def 					_snake_case  (self		):
										__lowerCAmelCase							       =				self.config_class(**self.inputs_dict		)

										__lowerCAmelCase							       =				'''test'''
										with tempfile.TemporaryDirectory() as tmpdirname:
																__lowerCAmelCase							       =				os.path.join(__lowercase       ,			__lowercase		)
																config_first.save_pretrained(__lowercase		)
																__lowerCAmelCase							       =				self.config_class.from_pretrained(__lowercase       ,			subfolder=__lowercase		)

										self.parent.assertEqual(config_second.to_dict()       ,			config_first.to_dict()		)




				def 					_snake_case  (self		):
										__lowerCAmelCase							       =				self.config_class(**self.inputs_dict       ,			num_labels=5		)
										self.parent.assertEqual(len(config.idalabel		)       ,			5		)
										self.parent.assertEqual(len(config.labelaid		)       ,			5		)

										__lowerCAmelCase							       =				3
										self.parent.assertEqual(len(config.idalabel		)       ,			3		)
										self.parent.assertEqual(len(config.labelaid		)       ,			3		)




				def 					_snake_case  (self		):
										if self.config_class.is_composition:
																return
										__lowerCAmelCase							       =				self.config_class()
										self.parent.assertIsNotNone(__lowercase		)




				def 					_snake_case  (self		):
										__lowerCAmelCase							       =				copy.deepcopy(__lowercase		)
										__lowerCAmelCase							       =				self.config_class(**__lowercase		)
										__lowerCAmelCase							       =				[]
										for key, value in config_common_kwargs.items():
																if key == "torch_dtype":
																						if not is_torch_available():
																												continue
																						else:
																												import torch

																												if config.torch_dtype != torch.floataa:
																																		wrong_values.append(('''torch_dtype''', config.torch_dtype, torch.floataa)		)
																elif getattr(__lowercase       ,			__lowercase		) != value:
																						wrong_values.append((key, getattr(__lowercase       ,			__lowercase		), value)		)

										if len(__lowercase		) > 0:
																__lowerCAmelCase							       =				'''\n'''.join([F"""- {v[0]}: got {v[1]} instead of {v[2]}""" for v in wrong_values]		)
																raise ValueError(F"""The following keys were not properly set in the config:\n{errors}"""		)




				def 					_snake_case  (self		):
										self.create_and_test_config_common_properties()
										self.create_and_test_config_to_json_string()
										self.create_and_test_config_to_json_file()
										self.create_and_test_config_from_and_save_pretrained()
										self.create_and_test_config_from_and_save_pretrained_subfolder()
										self.create_and_test_config_with_num_labels()
										self.check_config_can_be_init_without_params()
										self.check_config_arguments_init()





'''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()

