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


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




class    _UpperCamelCase      (						unittest.TestCase ):


			"""simple docstring"""






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

							'''simple docstring'''


							__lowercase 			=							0





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					int:

							'''simple docstring'''


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





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Optional[Any]:

							'''simple docstring'''


							__lowercase 			=							AutoConfig.from_pretrained('''bert-base-uncased'''						)
							self.assertIsInstance(lowerCAmelCase__      ,   lowerCAmelCase__						)





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Tuple:

							'''simple docstring'''


							__lowercase 			=							AutoConfig.from_pretrained(lowerCAmelCase__						)
							self.assertIsInstance(lowerCAmelCase__      ,   lowerCAmelCase__						)





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

							'''simple docstring'''


							__lowercase 			=							AutoConfig.from_pretrained(lowerCAmelCase__						)
							self.assertIsInstance(lowerCAmelCase__      ,   lowerCAmelCase__						)





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Dict:

							'''simple docstring'''


							__lowercase 			=							AutoConfig.for_model('''roberta'''						)
							self.assertIsInstance(lowerCAmelCase__      ,   lowerCAmelCase__						)





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					str:

							'''simple docstring'''


							with tempfile.TemporaryDirectory() as tmp_dir:
											# This model name contains bert and roberta, but roberta ends up being picked.
											__lowercase 			=							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 			=							AutoConfig.from_pretrained(lowerCAmelCase__						)
											self.assertEqual(type(lowerCAmelCase__						)      ,   lowerCAmelCase__						)





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

							'''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 			=							CustomConfig()
											with tempfile.TemporaryDirectory() as tmp_dir:
															config.save_pretrained(lowerCAmelCase__						)
															__lowercase 			=							AutoConfig.from_pretrained(lowerCAmelCase__						)
															self.assertIsInstance(lowerCAmelCase__      ,   lowerCAmelCase__						)

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





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Tuple:

							'''simple docstring'''


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





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					int:

							'''simple docstring'''


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





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					List[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 			=							AutoConfig.from_pretrained('''hf-internal-testing/no-config-test-repo'''						)





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Tuple:

							'''simple docstring'''


							with self.assertRaises(lowerCAmelCase__						):
											__lowercase 			=							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 			=							AutoConfig.from_pretrained('''hf-internal-testing/test_dynamic_model'''      ,   trust_remote_code=lowerCAmelCase__						)

							__lowercase 			=							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 			=							AutoConfig.from_pretrained(lowerCAmelCase__      ,   trust_remote_code=lowerCAmelCase__						)
							self.assertEqual(reloaded_config.__class__.__name__      ,   '''NewModelConfig'''						)





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

							'''simple docstring'''


							class    _UpperCamelCase      (						_UpperCAmelCase ):


										"""simple docstring"""






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

							try:
											AutoConfig.register('''new-model'''      ,   lowerCAmelCase__						)
											# If remote code is not set, the default is to use local
											__lowercase 			=							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 			=							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 			=							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"]
from ...configuration_utils import PretrainedConfig
from ...utils import logging


__a  :     str       =  logging.get_logger(__name__)

__a  :     Optional[int]       =  {
    """google/vivit-b-16x2-kinetics400""": (
        """https://huggingface.co/google/vivit-b-16x2-kinetics400/resolve/main/config.json"""
    ),
    # See all Vivit models at https://huggingface.co/models?filter=vivit
}




class    _UpperCamelCase      (						_UpperCAmelCase ):


			"""simple docstring"""






			__a  : Tuple			 =						'''vivit'''





			def __init__(   self      ,   lowerCAmelCase__=2_24      ,   lowerCAmelCase__=32      ,   lowerCAmelCase__=[2, 16, 16]      ,   lowerCAmelCase__=3      ,   lowerCAmelCase__=7_68      ,   lowerCAmelCase__=12      ,   lowerCAmelCase__=12      ,   lowerCAmelCase__=30_72      ,   lowerCAmelCase__="gelu_fast"      ,   lowerCAmelCase__=0.0      ,   lowerCAmelCase__=0.0      ,   lowerCAmelCase__=0.02      ,   lowerCAmelCase__=1E-06      ,   lowerCAmelCase__=True      ,   **lowerCAmelCase__      ,   )     ->					int:

							'''simple docstring'''


							__lowercase 			=							hidden_size
							__lowercase 			=							num_hidden_layers
							__lowercase 			=							num_attention_heads
							__lowercase 			=							intermediate_size
							__lowercase 			=							hidden_act
							__lowercase 			=							hidden_dropout_prob
							__lowercase 			=							attention_probs_dropout_prob
							__lowercase 			=							initializer_range
							__lowercase 			=							layer_norm_eps

							__lowercase 			=							image_size
							__lowercase 			=							num_frames
							__lowercase 			=							tubelet_size
							__lowercase 			=							num_channels
							__lowercase 			=							qkv_bias

							super().__init__(**lowerCAmelCase__						)