


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


SCREAMING_SNAKE_CASE :   List[Any]							      =				get_tests_dir("fixtures/dummy-config.json")






class _lowerCamelCase(		unittest.TestCase     ):
       def     UpperCamelCase  (      self) ->     Optional[int]:




           """simple docstring"""

           _lowercase :							List[Any]   	=	0
       def     UpperCamelCase  (      self) ->     str:




           """simple docstring"""

           self.assertIsNotNone(transformers.models.auto.__spec__)
           self.assertIsNotNone(importlib.util.find_spec('transformers.models.auto'))
       def     UpperCamelCase  (      self) ->     Union[str, Any]:




           """simple docstring"""

           _lowercase :							str   	=	AutoConfig.from_pretrained('bert-base-uncased')
           self.assertIsInstance(lowerCamelCase,   lowerCamelCase)
       def     UpperCamelCase  (      self) ->     Optional[int]:




           """simple docstring"""

           _lowercase :							Tuple   	=	AutoConfig.from_pretrained(lowerCamelCase)
           self.assertIsInstance(lowerCamelCase,   lowerCamelCase)
       def     UpperCamelCase  (      self) ->     Optional[int]:




           """simple docstring"""

           _lowercase :							Optional[Any]   	=	AutoConfig.from_pretrained(lowerCamelCase)
           self.assertIsInstance(lowerCamelCase,   lowerCamelCase)
       def     UpperCamelCase  (      self) ->     Optional[Any]:




           """simple docstring"""

           _lowercase :							Tuple   	=	AutoConfig.for_model('roberta')
           self.assertIsInstance(lowerCamelCase,   lowerCamelCase)
       def     UpperCamelCase  (      self) ->     str:




           """simple docstring"""

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




           """simple docstring"""

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

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

           finally:
               if "custom" in CONFIG_MAPPING._extra_content:
                   del CONFIG_MAPPING._extra_content["custom"]
       def     UpperCamelCase  (      self) ->     Optional[Any]:




           """simple docstring"""

           with self.assertRaisesRegex(
               lowerCamelCase,   'bert-base is not a local folder and is not a valid model identifier'):
               _lowercase :							Any   	=	AutoConfig.from_pretrained('bert-base')
       def     UpperCamelCase  (      self) ->     List[Any]:




           """simple docstring"""

           with self.assertRaisesRegex(
               lowerCamelCase,   R'aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'):
               _lowercase :							Optional[Any]   	=	AutoConfig.from_pretrained(lowerCamelCase,   revision='aaaaaa')
       def     UpperCamelCase  (      self) ->     str:




           """simple docstring"""

           with self.assertRaisesRegex(
               lowerCamelCase,   'hf-internal-testing/no-config-test-repo does not appear to have a file named config.json.',   ):
               _lowercase :							Optional[int]   	=	AutoConfig.from_pretrained('hf-internal-testing/no-config-test-repo')
       def     UpperCamelCase  (      self) ->     Union[str, Any]:




           """simple docstring"""

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

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

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




       def     UpperCamelCase  (      self) ->     Any:




           """simple docstring"""

           class _lowerCamelCase(		_a     ):
                  lowercase_				:			List[str]									=    """new-model"""

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

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

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






def        UpperCamelCase_(   lowerCamelCase_				)					->		int:
    assert (
        isinstance(lowerCamelCase_							,				lowerCamelCase_				) and number_of_steps > 0
    ), F'''number_of_steps needs to be positive integer, your input {number_of_steps}'''
    if number_of_steps == 1:
        return 1
    _lowercase	,       _lowercase :							Dict   	=	1, 1
    for _ in range(number_of_steps - 1				):
        _lowercase	,       _lowercase :							Tuple   	=	current + previous, current
    return current


if __name__ == "__main__":
 import doctest

 doctest.testmod()


