




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


lowerCamelCase       :	Dict									=     get_tests_dir("fixtures/dummy-config.json")







class 						A(		unittest.TestCase     ):



 '''simple docstring'''


 def        a__				(       self      :						Dict						)     ->			Tuple:

       """simple docstring"""






       lowerCamelCase_	  =					0

 def        a__				(       self      :						Any						)     ->			int:

       """simple docstring"""






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

 def        a__				(       self      :						Any						)     ->			str:

       """simple docstring"""






       lowerCamelCase_	  =					AutoConfig.from_pretrained('bert-base-uncased'						)
       self.assertIsInstance(A_		,							A_						)

 def        a__				(       self      :						str						)     ->			str:

       """simple docstring"""






       lowerCamelCase_	  =					AutoConfig.from_pretrained(A_						)
       self.assertIsInstance(A_		,							A_						)

 def        a__				(       self      :						List[Any]						)     ->			int:

       """simple docstring"""






       lowerCamelCase_	  =					AutoConfig.from_pretrained(A_						)
       self.assertIsInstance(A_		,							A_						)

 def        a__				(       self      :						Union[str, Any]						)     ->			List[Any]:

       """simple docstring"""






       lowerCamelCase_	  =					AutoConfig.for_model('roberta'						)
       self.assertIsInstance(A_		,							A_						)

 def        a__				(       self      :						Dict						)     ->			List[str]:

       """simple docstring"""






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

 def        a__				(       self      :						Any						)     ->			Optional[int]:

       """simple docstring"""






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

             # Now that the config is registered, it can be used as any other config with the auto-API
             lowerCamelCase_	  =					CustomConfig()
             with tempfile.TemporaryDirectory() as tmp_dir:
                   config.save_pretrained(A_						)
                   lowerCamelCase_	  =					AutoConfig.from_pretrained(A_						)
                   self.assertIsInstance(A_		,							A_						)

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

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

       """simple docstring"""






       with self.assertRaisesRegex(
           A_		,							'bert-base is not a local folder and is not a valid model identifier'						):
             lowerCamelCase_	  =					AutoConfig.from_pretrained('bert-base'						)

 def        a__				(       self      :						Any						)     ->			List[Any]:

       """simple docstring"""






       with self.assertRaisesRegex(
           A_		,							r'aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'						):
             lowerCamelCase_	  =					AutoConfig.from_pretrained(A_		,							revision='aaaaaa'						)

 def        a__				(       self      :						int						)     ->			List[str]:

       """simple docstring"""






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

 def        a__				(       self      :						Optional[int]						)     ->			Optional[int]:

       """simple docstring"""






       with self.assertRaises(A_						):
             lowerCamelCase_	  =					AutoConfig.from_pretrained('hf-internal-testing/test_dynamic_model'						)
       # If remote code is disabled, we can't load this config.
       with self.assertRaises(A_						):
             lowerCamelCase_	  =					AutoConfig.from_pretrained('hf-internal-testing/test_dynamic_model'		,							trust_remote_code=A_						)

       lowerCamelCase_	  =					AutoConfig.from_pretrained('hf-internal-testing/test_dynamic_model'		,							trust_remote_code=A_						)
       self.assertEqual(config.__class__.__name__		,							'NewModelConfig'						)

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





 def        a__				(       self      :						List[str]						)     ->			str:

       """simple docstring"""






       class 						A(		UpperCamelCase     ):



        '''simple docstring'''


        UpperCamelCase		     =		'''new-model'''

       try:
             AutoConfig.register('new-model'		,							A_						)
             # If remote code is not set, the default is to use local
             lowerCamelCase_	  =					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.
             lowerCamelCase_	  =					AutoConfig.from_pretrained('hf-internal-testing/test_dynamic_model'		,							trust_remote_code=A_						)
             self.assertEqual(config.__class__.__name__		,							'NewModelConfigLocal'						)

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

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









from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCamelCase       :	str									=     logging.get_logger(__name__)

lowerCamelCase       :	List[str]									=     {
    "abeja/gpt-neox-japanese-2.7b": "https://huggingface.co/abeja/gpt-neox-japanese-2.7b/resolve/main/config.json",
}







class 						A(		UpperCamelCase     ):



 '''simple docstring'''


 UpperCamelCase		     =		'''gpt_neox_japanese'''

 def __init__(       self      :						int		,							A_      :						Dict=32000		,							A_      :						List[Any]=2560		,							A_      :						Dict=32		,							A_      :						Union[str, Any]=32		,							A_      :						List[Any]=4		,							A_      :						List[str]="gelu"		,							A_      :						Dict=1.00		,							A_      :						int=10000		,							A_      :						Dict=2048		,							A_      :						Dict=0.02		,							A_      :						Any=1E-5		,							A_      :						Union[str, Any]=True		,							A_      :						int=31996		,							A_      :						List[str]=31999		,							A_      :						List[Any]=0.1		,							A_      :						List[Any]=0.0		,							**A_      :						Tuple		,							)     ->			Dict:

       """simple docstring"""






       super().__init__(bos_token_id=A_		,							eos_token_id=A_		,							**A_						)
       lowerCamelCase_	  =					vocab_size
       lowerCamelCase_	  =					max_position_embeddings
       lowerCamelCase_	  =					hidden_size
       lowerCamelCase_	  =					num_hidden_layers
       lowerCamelCase_	  =					num_attention_heads
       lowerCamelCase_	  =					intermediate_multiple_size
       lowerCamelCase_	  =					hidden_act
       lowerCamelCase_	  =					rotary_pct
       lowerCamelCase_	  =					rotary_emb_base
       lowerCamelCase_	  =					initializer_range
       lowerCamelCase_	  =					layer_norm_eps
       lowerCamelCase_	  =					use_cache
       lowerCamelCase_	  =					attention_dropout
       lowerCamelCase_	  =					hidden_dropout



