






"""simple docstring"""







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_	:    Optional[int]            =      get_tests_dir('''fixtures/dummy-config.json''')





class   UpperCamelCase_ (       unittest.TestCase  ):



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



         """simple docstring"""





         UpperCAmelCase	    =			0



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



         """simple docstring"""





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



  def 		UpperCamelCase_				(      self				)			->			Any:



         """simple docstring"""





         UpperCAmelCase	    =			AutoConfig.from_pretrained("""bert-base-uncased"""				)
         self.assertIsInstance(snake_case__ ,		snake_case__				)



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



         """simple docstring"""





         UpperCAmelCase	    =			AutoConfig.from_pretrained(snake_case__				)
         self.assertIsInstance(snake_case__ ,		snake_case__				)



  def 		UpperCamelCase_				(      self				)			->			Dict:



         """simple docstring"""





         UpperCAmelCase	    =			AutoConfig.from_pretrained(snake_case__				)
         self.assertIsInstance(snake_case__ ,		snake_case__				)



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



         """simple docstring"""





         UpperCAmelCase	    =			AutoConfig.for_model("""roberta"""				)
         self.assertIsInstance(snake_case__ ,		snake_case__				)



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



         """simple docstring"""





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



  def 		UpperCamelCase_				(      self				)			->			str:



         """simple docstring"""





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

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

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



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



         """simple docstring"""





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



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



         """simple docstring"""





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



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



         """simple docstring"""





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



  def 		UpperCamelCase_				(      self				)			->			Any:



         """simple docstring"""





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

         UpperCAmelCase	    =			AutoConfig.from_pretrained("""hf-internal-testing/test_dynamic_model""" ,		trust_remote_code=snake_case__				)
         self.assertEqual(config.__class__.__name__ ,		"""NewModelConfig"""				)

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



  def 		UpperCamelCase_				(      self				)			->			Dict:



         """simple docstring"""





         class   UpperCamelCase_ (       a_  ):
           _A       :					Tuple				=	'new-model'

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

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

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








"""simple docstring"""







from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowerCAmelCase_	:    Tuple            =      logging.get_logger(__name__)

lowerCAmelCase_	:    List[str]            =      {
    '''google/bigbird-roberta-base''': '''https://huggingface.co/google/bigbird-roberta-base/resolve/main/config.json''',
    '''google/bigbird-roberta-large''': '''https://huggingface.co/google/bigbird-roberta-large/resolve/main/config.json''',
    '''google/bigbird-base-trivia-itc''': '''https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/config.json''',
    # See all BigBird models at https://huggingface.co/models?filter=big_bird
}





class   UpperCamelCase_ (       a_  ):
  _A       :					Any				=	'big_bird'



  def __init__(      self ,		snake_case__=5_03_58 ,		snake_case__=7_68 ,		snake_case__=12 ,		snake_case__=12 ,		snake_case__=30_72 ,		snake_case__="gelu_new" ,		snake_case__=0.1 ,		snake_case__=0.1 ,		snake_case__=40_96 ,		snake_case__=2 ,		snake_case__=0.02 ,		snake_case__=1e-12 ,		snake_case__=True ,		snake_case__=0 ,		snake_case__=1 ,		snake_case__=2 ,		snake_case__=66 ,		snake_case__="block_sparse" ,		snake_case__=True ,		snake_case__=False ,		snake_case__=64 ,		snake_case__=3 ,		snake_case__=None ,		**snake_case__ ,		)			->			List[str]:



         """simple docstring"""





         super().__init__(
             pad_token_id=snake_case__ ,		bos_token_id=snake_case__ ,		eos_token_id=snake_case__ ,		sep_token_id=snake_case__ ,		**snake_case__ ,		)

         UpperCAmelCase	    =			vocab_size
         UpperCAmelCase	    =			max_position_embeddings
         UpperCAmelCase	    =			hidden_size
         UpperCAmelCase	    =			num_hidden_layers
         UpperCAmelCase	    =			num_attention_heads
         UpperCAmelCase	    =			intermediate_size
         UpperCAmelCase	    =			hidden_act
         UpperCAmelCase	    =			hidden_dropout_prob
         UpperCAmelCase	    =			attention_probs_dropout_prob
         UpperCAmelCase	    =			initializer_range
         UpperCAmelCase	    =			type_vocab_size
         UpperCAmelCase	    =			layer_norm_eps
         UpperCAmelCase	    =			use_cache

         UpperCAmelCase	    =			rescale_embeddings
         UpperCAmelCase	    =			attention_type
         UpperCAmelCase	    =			use_bias
         UpperCAmelCase	    =			block_size
         UpperCAmelCase	    =			num_random_blocks
         UpperCAmelCase	    =			classifier_dropout





class   UpperCamelCase_ (       a_  ):



  @property
  def 		UpperCamelCase_				(      self				)			->			Mapping[str, Mapping[int, str]]:



         """simple docstring"""





         if self.task == "multiple-choice":
                UpperCAmelCase	    =			{0: """batch""", 1: """choice""", 2: """sequence"""}
         else:
                UpperCAmelCase	    =			{0: """batch""", 1: """sequence"""}
         return OrderedDict(
             [
                 ("""input_ids""", dynamic_axis),
                 ("""attention_mask""", dynamic_axis),
             ]				)
