
'''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


__A	:	Optional[Any]     =     get_tests_dir('fixtures/dummy-config.json')
class 						__UpperCamelCase	(						unittest.TestCase							):





							def 		a__   (  self		:Union[str, Any]			):
									snake_case_		:							str			       =						0





							def 		a__   (  self		:int			):
									self.assertIsNotNone(transformers.models.auto.__spec__			)
									self.assertIsNotNone(importlib.util.find_spec("""transformers.models.auto"""			)			)





							def 		a__   (  self		:Dict			):
									snake_case_		:							Tuple			       =						AutoConfig.from_pretrained("""bert-base-uncased"""			)
									self.assertIsInstance(_A  ,_A			)





							def 		a__   (  self		:Dict			):
									snake_case_		:							int			       =						AutoConfig.from_pretrained(_A			)
									self.assertIsInstance(_A  ,_A			)





							def 		a__   (  self		:Dict			):
									snake_case_		:							Optional[Any]			       =						AutoConfig.from_pretrained(_A			)
									self.assertIsInstance(_A  ,_A			)





							def 		a__   (  self		:List[str]			):
									snake_case_		:							str			       =						AutoConfig.for_model("""roberta"""			)
									self.assertIsInstance(_A  ,_A			)





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





							def 		a__   (  self		:Any			):
									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
											snake_case_		:							Optional[Any]			       =						CustomConfig()
											with tempfile.TemporaryDirectory() as tmp_dir:
													config.save_pretrained(_A			)
													snake_case_		:							List[Any]			       =						AutoConfig.from_pretrained(_A			)
													self.assertIsInstance(_A  ,_A			)

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





							def 		a__   (  self		:Dict			):
									with self.assertRaisesRegex(
									    _A  ,"""bert-base is not a local folder and is not a valid model identifier"""			):
											snake_case_		:							Tuple			       =						AutoConfig.from_pretrained("""bert-base"""			)





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





							def 		a__   (  self		:Any			):
									with self.assertRaisesRegex(
									    _A  ,"""hf-internal-testing/no-config-test-repo does not appear to have a file named config.json."""  ,):
											snake_case_		:							Union[str, Any]			       =						AutoConfig.from_pretrained("""hf-internal-testing/no-config-test-repo"""			)





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

									snake_case_		:							int			       =						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			)
											snake_case_		:							Union[str, Any]			       =						AutoConfig.from_pretrained(_A  ,trust_remote_code=_A			)
									self.assertEqual(reloaded_config.__class__.__name__  ,"""NewModelConfig"""			)





							def 		a__   (  self		:List[Any]			):
									class 						__UpperCamelCase	(						__lowercase							):
																lowercase			:		Tuple   		=  'new-model'

									try:
											AutoConfig.register("""new-model"""  ,_A			)
											# If remote code is not set, the default is to use local
											snake_case_		:							int			       =						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.
											snake_case_		:							Tuple			       =						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
											snake_case_		:							Tuple			       =						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'''






def      UpperCAmelCase      (		lowerCamelCase_  :int ):







		'''simple docstring'''
		if num < 0:
				return False

		snake_case_		:							int			       =						num
		snake_case_		:							int			       =						0
		while num > 0:
				snake_case_		:							Tuple			       =						rev_num * 10 + (num % 10)
				num //= 10

		return num_copy == rev_num


if __name__ == "__main__":
							import doctest

							doctest.testmod()