





'''simple docstring'''

from manim import *
class 							__lowerCAmelCase	(       __magic_name__					):






       """simple docstring"""





       def snake_case__		(				self  :						Optional[Any]	)       ->	List[str]:

            '''simple docstring'''




            _UpperCamelCase							       =			Rectangle(height=0.5			,					width=0.5	)
            _UpperCamelCase							       =			Rectangle(height=0.46			,					width=0.46	).set_stroke(width=0	)

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

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

            self.add(lowerCAmelCase__	)

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

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

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

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

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

            _UpperCamelCase							       =			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(lowerCAmelCase__			,					run_time=2.5	)			,					Write(lowerCAmelCase__	)			,					Write(lowerCAmelCase__	)	)

            self.add(lowerCAmelCase__	)

            _UpperCamelCase							       =			[]
            _UpperCamelCase							       =			[]
            _UpperCamelCase							       =			[]
            for i, rect in enumerate(lowerCAmelCase__	):
                 _UpperCamelCase							       =			Rectangle(height=0.46			,					width=0.46	).set_stroke(width=0.0	).set_fill(lowerCAmelCase__			,					opacity=0.7	)
                 cpu_target.move_to(lowerCAmelCase__	)
                 cpu_target.generate_target()
                 _UpperCamelCase							       =			0.46 / 4
                 _UpperCamelCase							       =			0.46 / 3

                 if i == 0:
                      cpu_target.target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT	)			,					buff=0.02			,					direction=lowerCAmelCase__	)
                      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=lowerCAmelCase__			,					buff=0.0	)
                 else:
                      cpu_target.target.next_to(cpu_targs[i - 1].target			,					direction=lowerCAmelCase__			,					buff=0.0	)
                 cpu_targs.append(lowerCAmelCase__	)

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

            self.play(*lowerCAmelCase__	)
            self.play(*lowerCAmelCase__	)

            self.wait()




import importlib
import json
import os
import sys
import tempfile
import unittest
from pathlib import Path

import transformers
import transformers.models.auto
from transformers.models.auto.configuration_auto import CONFIG_MAPPING, AutoConfig
from transformers.models.bert.configuration_bert import BertConfig
from transformers.models.roberta.configuration_roberta import RobertaConfig
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, get_tests_dir


sys.path.append(str(Path(__file__).parent.parent.parent.parent / '''utils'''))

from test_module.custom_configuration import CustomConfig  # noqa E402


UpperCAmelCase_           =				get_tests_dir('''fixtures/dummy-config.json''')




class 			__magic_name__	(		unittest.TestCase     ):





   """simple docstring"""




   def 	lowerCAmelCase    (						self       :	str				):



    """simple docstring"""



    _UpperCamelCase:  Dict    						=			0



   def 	lowerCAmelCase    (						self       :	Any				):



    """simple docstring"""



    self.assertIsNotNone(transformers.models.auto.__spec__				)
    self.assertIsNotNone(importlib.util.find_spec('''transformers.models.auto'''				)				)



   def 	lowerCAmelCase    (						self       :	Union[str, Any]				):



    """simple docstring"""



    _UpperCamelCase:  List[str]    						=			AutoConfig.from_pretrained('''bert-base-uncased'''				)
    self.assertIsInstance(_lowercase		,	_lowercase				)



   def 	lowerCAmelCase    (						self       :	int				):



    """simple docstring"""



    _UpperCamelCase:  int    						=			AutoConfig.from_pretrained(_lowercase				)
    self.assertIsInstance(_lowercase		,	_lowercase				)



   def 	lowerCAmelCase    (						self       :	List[Any]				):



    """simple docstring"""



    _UpperCamelCase:  List[Any]    						=			AutoConfig.from_pretrained(_lowercase				)
    self.assertIsInstance(_lowercase		,	_lowercase				)



   def 	lowerCAmelCase    (						self       :	Optional[int]				):



    """simple docstring"""



    _UpperCamelCase:  List[str]    						=			AutoConfig.for_model('''roberta'''				)
    self.assertIsInstance(_lowercase		,	_lowercase				)



   def 	lowerCAmelCase    (						self       :	List[str]				):



    """simple docstring"""



    with tempfile.TemporaryDirectory() as tmp_dir:
     # This model name contains bert and roberta, but roberta ends up being picked.
     _UpperCamelCase:  Union[str, Any]    						=			os.path.join(_lowercase		,	'''fake-roberta'''				)
     os.makedirs(_lowercase		,	exist_ok=_lowercase				)
     with open(os.path.join(_lowercase		,	'''config.json'''				)		,	'''w'''				) as f:
      f.write(json.dumps({}				)				)
     _UpperCamelCase:  Union[str, Any]    						=			AutoConfig.from_pretrained(_lowercase				)
     self.assertEqual(type(_lowercase				)		,	_lowercase				)



   def 	lowerCAmelCase    (						self       :	Dict				):



    """simple docstring"""



    try:
     AutoConfig.register('''custom'''		,	_lowercase				)
     # Wrong model type will raise an error
     with self.assertRaises(_lowercase				):
      AutoConfig.register('''model'''		,	_lowercase				)
     # Trying to register something existing in the Transformers library will raise an error
     with self.assertRaises(_lowercase				):
      AutoConfig.register('''bert'''		,	_lowercase				)

     # Now that the config is registered, it can be used as any other config with the auto-API
     _UpperCamelCase:  Union[str, Any]    						=			CustomConfig()
     with tempfile.TemporaryDirectory() as tmp_dir:
      config.save_pretrained(_lowercase				)
      _UpperCamelCase:  Any    						=			AutoConfig.from_pretrained(_lowercase				)
      self.assertIsInstance(_lowercase		,	_lowercase				)

    finally:
     if "custom" in CONFIG_MAPPING._extra_content:
      del CONFIG_MAPPING._extra_content["custom"]



   def 	lowerCAmelCase    (						self       :	Optional[int]				):



    """simple docstring"""



    with self.assertRaisesRegex(
        _lowercase		,	'''bert-base is not a local folder and is not a valid model identifier'''				):
     _UpperCamelCase:  Optional[int]    						=			AutoConfig.from_pretrained('''bert-base'''				)



   def 	lowerCAmelCase    (						self       :	Tuple				):



    """simple docstring"""



    with self.assertRaisesRegex(
        _lowercase		,	R'''aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'''				):
     _UpperCamelCase:  str    						=			AutoConfig.from_pretrained(_lowercase		,	revision='''aaaaaa'''				)



   def 	lowerCAmelCase    (						self       :	Union[str, Any]				):



    """simple docstring"""



    with self.assertRaisesRegex(
        _lowercase		,	'''hf-internal-testing/no-config-test-repo does not appear to have a file named config.json.'''		,	):
     _UpperCamelCase:  int    						=			AutoConfig.from_pretrained('''hf-internal-testing/no-config-test-repo'''				)



   def 	lowerCAmelCase    (						self       :	Dict				):



    """simple docstring"""



    with self.assertRaises(_lowercase				):
     _UpperCamelCase:  List[str]    						=			AutoConfig.from_pretrained('''hf-internal-testing/test_dynamic_model'''				)
    # If remote code is disabled, we can't load this config.
    with self.assertRaises(_lowercase				):
     _UpperCamelCase:  Optional[int]    						=			AutoConfig.from_pretrained('''hf-internal-testing/test_dynamic_model'''		,	trust_remote_code=_lowercase				)

    _UpperCamelCase:  Union[str, Any]    						=			AutoConfig.from_pretrained('''hf-internal-testing/test_dynamic_model'''		,	trust_remote_code=_lowercase				)
    self.assertEqual(config.__class__.__name__		,	'''NewModelConfig'''				)

    # Test config can be reloaded.
    with tempfile.TemporaryDirectory() as tmp_dir:
     config.save_pretrained(_lowercase				)
     _UpperCamelCase:  str    						=			AutoConfig.from_pretrained(_lowercase		,	trust_remote_code=_lowercase				)
    self.assertEqual(reloaded_config.__class__.__name__		,	'''NewModelConfig'''				)



   def 	lowerCAmelCase    (						self       :	Any				):



    """simple docstring"""



    class 			__magic_name__	(		__a     ):





       """simple docstring"""




       lowerCAmelCase   :     List[Any]	      = '''new-model'''

    try:
     AutoConfig.register('''new-model'''		,	_lowercase				)
     # If remote code is not set, the default is to use local
     _UpperCamelCase:  List[Any]    						=			AutoConfig.from_pretrained('''hf-internal-testing/test_dynamic_model'''				)
     self.assertEqual(config.__class__.__name__		,	'''NewModelConfigLocal'''				)

     # If remote code is disabled, we load the local one.
     _UpperCamelCase:  Union[str, Any]    						=			AutoConfig.from_pretrained('''hf-internal-testing/test_dynamic_model'''		,	trust_remote_code=_lowercase				)
     self.assertEqual(config.__class__.__name__		,	'''NewModelConfigLocal'''				)

     # If remote is enabled, we load from the Hub
     _UpperCamelCase:  Any    						=			AutoConfig.from_pretrained('''hf-internal-testing/test_dynamic_model'''		,	trust_remote_code=_lowercase				)
     self.assertEqual(config.__class__.__name__		,	'''NewModelConfig'''				)

    finally:
     if "new-model" in CONFIG_MAPPING._extra_content:
      del CONFIG_MAPPING._extra_content["new-model"]