

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


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






class      lowerCamelCase_      (	unittest.TestCase	):




	def        lowerCAmelCase_       (     self						:     Optional[int]							):
		__A :			str		    =			0




	def        lowerCAmelCase_       (     self						:     List[str]							):
		self.assertIsNotNone(transformers.models.auto.__spec__							)
		self.assertIsNotNone(importlib.util.find_spec("""transformers.models.auto"""							)							)




	def        lowerCAmelCase_       (     self						:     Tuple							):
		__A :			List[str]		    =			AutoConfig.from_pretrained("""bert-base-uncased"""							)
		self.assertIsInstance(__A					,      __A							)




	def        lowerCAmelCase_       (     self						:     Union[str, Any]							):
		__A :			Optional[int]		    =			AutoConfig.from_pretrained(__A							)
		self.assertIsInstance(__A					,      __A							)




	def        lowerCAmelCase_       (     self						:     Dict							):
		__A :			Optional[Any]		    =			AutoConfig.from_pretrained(__A							)
		self.assertIsInstance(__A					,      __A							)




	def        lowerCAmelCase_       (     self						:     str							):
		__A :			Union[str, Any]		    =			AutoConfig.for_model("""roberta"""							)
		self.assertIsInstance(__A					,      __A							)




	def        lowerCAmelCase_       (     self						:     int							):
		with tempfile.TemporaryDirectory() as tmp_dir:
			# This model name contains bert and roberta, but roberta ends up being picked.
			__A :			Dict		    =			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({}							)							)
			__A :			Optional[Any]		    =			AutoConfig.from_pretrained(__A							)
			self.assertEqual(type(__A							)					,      __A							)




	def        lowerCAmelCase_       (     self						:     Dict							):
		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
			__A :			Any		    =			CustomConfig()
			with tempfile.TemporaryDirectory() as tmp_dir:
				config.save_pretrained(__A							)
				__A :			List[str]		    =			AutoConfig.from_pretrained(__A							)
				self.assertIsInstance(__A					,      __A							)

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




	def        lowerCAmelCase_       (     self						:     Tuple							):
		with self.assertRaisesRegex(
		    __A					,      """bert-base is not a local folder and is not a valid model identifier"""							):
			__A :			int		    =			AutoConfig.from_pretrained("""bert-base"""							)




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




	def        lowerCAmelCase_       (     self						:     List[Any]							):
		with self.assertRaisesRegex(
		    __A					,      """hf-internal-testing/no-config-test-repo does not appear to have a file named config.json."""					,      ):
			__A :			Dict		    =			AutoConfig.from_pretrained("""hf-internal-testing/no-config-test-repo"""							)




	def        lowerCAmelCase_       (     self						:     List[Any]							):
		# If remote code is not set, we will time out when asking whether to load the model.
		with self.assertRaises(__A							):
			__A :			List[str]		    =			AutoConfig.from_pretrained("""hf-internal-testing/test_dynamic_model"""							)
		# If remote code is disabled, we can't load this config.
		with self.assertRaises(__A							):
			__A :			Optional[Any]		    =			AutoConfig.from_pretrained("""hf-internal-testing/test_dynamic_model"""					,      trust_remote_code=__A							)

		__A :			str		    =			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							)
			__A :			str		    =			AutoConfig.from_pretrained(__A					,      trust_remote_code=__A							)
		self.assertEqual(reloaded_config.__class__.__name__					,      """NewModelConfig"""							)




	def        lowerCAmelCase_       (     self						:     Optional[int]							):






		class      lowerCamelCase_      (	_lowercase	):
			_lowercase		:   Tuple     					=				'''new-model'''

		try:
			AutoConfig.register("""new-model"""					,      __A							)
			# If remote code is not set, the default is to use local
			__A :			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.
			__A :			Union[str, Any]		    =			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
			__A :			List[Any]		    =			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"]









"""simple docstring"""






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


UpperCamelCase__				:str			   =	logging.get_logger(__name__)

UpperCamelCase__				:Optional[int]			   =	{
    """microsoft/markuplm-base""": """https://huggingface.co/microsoft/markuplm-base/resolve/main/config.json""",
    """microsoft/markuplm-large""": """https://huggingface.co/microsoft/markuplm-large/resolve/main/config.json""",
}






class      A(  lowerCamelCase__		):

		"""simple docstring"""





		A    =							"markuplm"
		def __init__( self					,				SCREAMING_SNAKE_CASE__=3_05_22					,				SCREAMING_SNAKE_CASE__=7_68					,				SCREAMING_SNAKE_CASE__=12					,				SCREAMING_SNAKE_CASE__=12					,				SCREAMING_SNAKE_CASE__=30_72					,				SCREAMING_SNAKE_CASE__="gelu"					,				SCREAMING_SNAKE_CASE__=0.1					,				SCREAMING_SNAKE_CASE__=0.1					,				SCREAMING_SNAKE_CASE__=5_12					,				SCREAMING_SNAKE_CASE__=2					,				SCREAMING_SNAKE_CASE__=0.0_2					,				SCREAMING_SNAKE_CASE__=1E-12					,				SCREAMING_SNAKE_CASE__=0					,				SCREAMING_SNAKE_CASE__=0					,				SCREAMING_SNAKE_CASE__=2					,				SCREAMING_SNAKE_CASE__=2_56					,				SCREAMING_SNAKE_CASE__=10_24					,				SCREAMING_SNAKE_CASE__=2_16					,				SCREAMING_SNAKE_CASE__=10_01					,				SCREAMING_SNAKE_CASE__=32					,				SCREAMING_SNAKE_CASE__=50					,				SCREAMING_SNAKE_CASE__="absolute"					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__=None					,				**SCREAMING_SNAKE_CASE__					,				)      ->	Optional[Any]:

					"""simple docstring"""



					super().__init__(
					    pad_token_id=SCREAMING_SNAKE_CASE__					,				bos_token_id=SCREAMING_SNAKE_CASE__					,				eos_token_id=SCREAMING_SNAKE_CASE__					,				**SCREAMING_SNAKE_CASE__					,				)
					_UpperCamelCase					:Any					     =	vocab_size
					_UpperCamelCase					:Union[str, Any]					     =	hidden_size
					_UpperCamelCase					:List[Any]					     =	num_hidden_layers
					_UpperCamelCase					:int					     =	num_attention_heads
					_UpperCamelCase					:Tuple					     =	hidden_act
					_UpperCamelCase					:str					     =	intermediate_size
					_UpperCamelCase					:Optional[int]					     =	hidden_dropout_prob
					_UpperCamelCase					:Any					     =	attention_probs_dropout_prob
					_UpperCamelCase					:Union[str, Any]					     =	max_position_embeddings
					_UpperCamelCase					:Dict					     =	type_vocab_size
					_UpperCamelCase					:int					     =	initializer_range
					_UpperCamelCase					:Optional[int]					     =	layer_norm_eps
					_UpperCamelCase					:Any					     =	position_embedding_type
					_UpperCamelCase					:Any					     =	use_cache
					_UpperCamelCase					:List[str]					     =	classifier_dropout
					# additional properties
					_UpperCamelCase					:Union[str, Any]					     =	max_depth
					_UpperCamelCase					:Union[str, Any]					     =	max_xpath_tag_unit_embeddings
					_UpperCamelCase					:Optional[Any]					     =	max_xpath_subs_unit_embeddings
					_UpperCamelCase					:int					     =	tag_pad_id
					_UpperCamelCase					:str					     =	subs_pad_id
					_UpperCamelCase					:List[str]					     =	xpath_unit_hidden_size

