





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							:       int					 =	get_tests_dir("""fixtures/dummy-config.json""")





class 				a			(      unittest.TestCase			):






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				str           =   0






				def 			snake_case_    (  self					):

										"""simple docstring"""




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






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   AutoConfig.from_pretrained('''bert-base-uncased'''					)
										self.assertIsInstance(__lowercase			, __lowercase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   AutoConfig.from_pretrained(__lowercase					)
										self.assertIsInstance(__lowercase			, __lowercase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Optional[int]           =   AutoConfig.from_pretrained(__lowercase					)
										self.assertIsInstance(__lowercase			, __lowercase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				List[Any]           =   AutoConfig.for_model('''roberta'''					)
										self.assertIsInstance(__lowercase			, __lowercase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




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






				def 			snake_case_    (  self					):

										"""simple docstring"""




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

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

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






				def 			snake_case_    (  self					):

										"""simple docstring"""




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






				def 			snake_case_    (  self					):

										"""simple docstring"""




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






				def 			snake_case_    (  self					):

										"""simple docstring"""




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






				def 			snake_case_    (  self					):

										"""simple docstring"""




										with self.assertRaises(__lowercase					):
																__SCREAMING_SNAKE_CASE:				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(__lowercase					):
																__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   AutoConfig.from_pretrained('''hf-internal-testing/test_dynamic_model'''			, trust_remote_code=__lowercase					)

										__SCREAMING_SNAKE_CASE:				Optional[int]           =   AutoConfig.from_pretrained('''hf-internal-testing/test_dynamic_model'''			, trust_remote_code=__lowercase					)
										self.assertEqual(config.__class__.__name__			, '''NewModelConfig'''					)

										# Test config can be reloaded.
										with tempfile.TemporaryDirectory() as tmp_dir:
																config.save_pretrained(__lowercase					)
																__SCREAMING_SNAKE_CASE:				str           =   AutoConfig.from_pretrained(__lowercase			, trust_remote_code=__lowercase					)
										self.assertEqual(reloaded_config.__class__.__name__			, '''NewModelConfig'''					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										class 				a			(      snake_case_			):
														SCREAMING_SNAKE_CASE__     :   Optional[int]		      =     '''new-model'''

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

																# If remote is enabled, we load from the Hub
																__SCREAMING_SNAKE_CASE:				str           =   AutoConfig.from_pretrained('''hf-internal-testing/test_dynamic_model'''			, trust_remote_code=__lowercase					)
																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       _lowercase							(					UpperCamelCase__							:       int,					UpperCamelCase__							:       int      ):
 return 1 if input_a == input_a else 0


def       _lowercase							(					):
 assert xnor_gate(0,					0      ) == 1
 assert xnor_gate(0,					1      ) == 0
 assert xnor_gate(1,					0      ) == 0
 assert xnor_gate(1,					1      ) == 1


if __name__ == "__main__":
 print(xnor_gate(0, 0))
 print(xnor_gate(0, 1))
 print(xnor_gate(1, 0))
 print(xnor_gate(1, 1))






