


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


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



class 	lowerCamelCase__			(      unittest.TestCase      ):




   def 							lowerCamelCase_   (   self						:						str							):




         '''simple docstring'''







         lowerCamelCase__:						List[Any]							   = 0




   def 							lowerCamelCase_   (   self						:						int							):




         '''simple docstring'''







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




   def 							lowerCamelCase_   (   self						:						Optional[Any]							):




         '''simple docstring'''







         lowerCamelCase__:						Any							   = AutoConfig.from_pretrained("""bert-base-uncased"""							)
         self.assertIsInstance(_SCREAMING_SNAKE_CASE    ,    _SCREAMING_SNAKE_CASE							)




   def 							lowerCamelCase_   (   self						:						Dict							):




         '''simple docstring'''







         lowerCamelCase__:						Dict							   = AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE							)
         self.assertIsInstance(_SCREAMING_SNAKE_CASE    ,    _SCREAMING_SNAKE_CASE							)




   def 							lowerCamelCase_   (   self						:						str							):




         '''simple docstring'''







         lowerCamelCase__:						Union[str, Any]							   = AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE							)
         self.assertIsInstance(_SCREAMING_SNAKE_CASE    ,    _SCREAMING_SNAKE_CASE							)




   def 							lowerCamelCase_   (   self						:						Dict							):




         '''simple docstring'''







         lowerCamelCase__:						Dict							   = AutoConfig.for_model("""roberta"""							)
         self.assertIsInstance(_SCREAMING_SNAKE_CASE    ,    _SCREAMING_SNAKE_CASE							)




   def 							lowerCamelCase_   (   self						:						List[Any]							):




         '''simple docstring'''







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




   def 							lowerCamelCase_   (   self						:						Dict							):




         '''simple docstring'''







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

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

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




   def 							lowerCamelCase_   (   self						:						str							):




         '''simple docstring'''







         with self.assertRaisesRegex(
             _SCREAMING_SNAKE_CASE    ,    """bert-base is not a local folder and is not a valid model identifier"""							):
               lowerCamelCase__:						Dict							   = AutoConfig.from_pretrained("""bert-base"""							)




   def 							lowerCamelCase_   (   self						:						Optional[int]							):




         '''simple docstring'''







         with self.assertRaisesRegex(
             _SCREAMING_SNAKE_CASE    ,    R"""aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"""							):
               lowerCamelCase__:						Optional[int]							   = AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE    ,    revision="""aaaaaa"""							)




   def 							lowerCamelCase_   (   self						:						Optional[Any]							):




         '''simple docstring'''







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




   def 							lowerCamelCase_   (   self						:						Optional[Any]							):




         '''simple docstring'''







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

         lowerCamelCase__:						str							   = AutoConfig.from_pretrained("""hf-internal-testing/test_dynamic_model"""    ,    trust_remote_code=_SCREAMING_SNAKE_CASE							)
         self.assertEqual(config.__class__.__name__    ,    """NewModelConfig"""							)

         # Test config can be reloaded.
         with tempfile.TemporaryDirectory() as tmp_dir:
               config.save_pretrained(_SCREAMING_SNAKE_CASE							)
               lowerCamelCase__:						int							   = AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE    ,    trust_remote_code=_SCREAMING_SNAKE_CASE							)
         self.assertEqual(reloaded_config.__class__.__name__    ,    """NewModelConfig"""							)




   def 							lowerCamelCase_   (   self						:						List[Any]							):




         '''simple docstring'''







         class 	lowerCamelCase__			(      _a      ):
            __lowerCamelCase			      =  """new-model"""

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

               # If remote is enabled, we load from the Hub
               lowerCamelCase__:						Union[str, Any]							   = AutoConfig.from_pretrained("""hf-internal-testing/test_dynamic_model"""    ,    trust_remote_code=_SCREAMING_SNAKE_CASE							)
               self.assertEqual(config.__class__.__name__    ,    """NewModelConfig"""							)

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












import warnings

from ...utils import logging
from .image_processing_clip import CLIPImageProcessor


__a							     =					logging.get_logger(__name__)

class     __a(	_a  ):






    """simple docstring"""





    def __init__( self  ,*_SCREAMING_SNAKE_CASE  ,**_SCREAMING_SNAKE_CASE    )					->						None:
         warnings.warn(
             '''The class CLIPFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please'''
             ''' use CLIPImageProcessor instead.'''  ,_SCREAMING_SNAKE_CASE  ,)
         super().__init__(*_SCREAMING_SNAKE_CASE  ,**_SCREAMING_SNAKE_CASE    )