




class 	lowerCamelCase_							:


	'''simple docstring'''







	def __init__(							self  :		str						):
							SCREAMING_SNAKE_CASE_     						=      0
							SCREAMING_SNAKE_CASE_     						=      0
							SCREAMING_SNAKE_CASE_     						=      {}



	def 				lowerCAmelCase_  (							self  :		Optional[Any]    ,    _lowerCAmelCase  :		List[Any]						):
							if vertex not in self.adjacency:
													SCREAMING_SNAKE_CASE_     						=      {}
													self.num_vertices += 1



	def 				lowerCAmelCase_  (							self  :		Union[str, Any]    ,    _lowerCAmelCase  :		List[Any]    ,    _lowerCAmelCase  :		Tuple    ,    _lowerCAmelCase  :		Tuple						):
							self.add_vertex(_lowerCAmelCase						)
							self.add_vertex(_lowerCAmelCase						)

							if head == tail:
													return

							SCREAMING_SNAKE_CASE_     						=      weight
							SCREAMING_SNAKE_CASE_     						=      weight



	def 				lowerCAmelCase_  (							self  :		Any						):
							SCREAMING_SNAKE_CASE_     						=      self.get_edges()
							for edge in edges:
													SCREAMING_SNAKE_CASE_						,			SCREAMING_SNAKE_CASE_						,			SCREAMING_SNAKE_CASE_     						=      edge
													edges.remove((tail, head, weight)						)
							for i in range(len(_lowerCAmelCase						)						):
													SCREAMING_SNAKE_CASE_     						=      list(edges[i]						)

							edges.sort(key=lambda _lowerCAmelCase						: e[2]						)
							for i in range(len(_lowerCAmelCase						) - 1						):
													if edges[i][2] >= edges[i + 1][2]:
																			SCREAMING_SNAKE_CASE_     						=      edges[i][2] + 1
							for edge in edges:
													SCREAMING_SNAKE_CASE_						,			SCREAMING_SNAKE_CASE_						,			SCREAMING_SNAKE_CASE_     						=      edge
													SCREAMING_SNAKE_CASE_     						=      weight
													SCREAMING_SNAKE_CASE_     						=      weight



	def __str__(							self  :		Dict						):
							SCREAMING_SNAKE_CASE_     						=      ''
							for tail in self.adjacency:
													for head in self.adjacency[tail]:
																			SCREAMING_SNAKE_CASE_     						=      self.adjacency[head][tail]
																			string += F"{head} -> {tail} == {weight}\n"
							return string.rstrip('\n'						)



	def 				lowerCAmelCase_  (							self  :		Tuple						):
							SCREAMING_SNAKE_CASE_     						=      []
							for tail in self.adjacency:
													for head in self.adjacency[tail]:
																			output.append((tail, head, self.adjacency[head][tail])						)
							return output



	def 				lowerCAmelCase_  (							self  :		Any						):
							return self.adjacency.keys()



	@staticmethod
	def 				lowerCAmelCase_  (							_lowerCAmelCase  :		int=None    ,    _lowerCAmelCase  :		Dict=None						):
							SCREAMING_SNAKE_CASE_     						=      Graph()
							if vertices is None:
													SCREAMING_SNAKE_CASE_     						=      []
							if edges is None:
													SCREAMING_SNAKE_CASE_     						=      []
							for vertex in vertices:
													g.add_vertex(_lowerCAmelCase						)
							for edge in edges:
													g.add_edge(*_lowerCAmelCase						)
							return g





	class 	lowerCamelCase_							:


		'''simple docstring'''







		def __init__(							self  :		Optional[Any]						):
								SCREAMING_SNAKE_CASE_     						=      {}
								SCREAMING_SNAKE_CASE_     						=      {}



		def __len__(							self  :		Dict						):
								return len(self.parent						)



		def 				lowerCAmelCase_  (							self  :		Tuple    ,    _lowerCAmelCase  :		str						):
								if item in self.parent:
														return self.find(_lowerCAmelCase						)

								SCREAMING_SNAKE_CASE_     						=      item
								SCREAMING_SNAKE_CASE_     						=      0
								return item



		def 				lowerCAmelCase_  (							self  :		int    ,    _lowerCAmelCase  :		List[Any]						):
								if item not in self.parent:
														return self.make_set(_lowerCAmelCase						)
								if item != self.parent[item]:
														SCREAMING_SNAKE_CASE_     						=      self.find(self.parent[item]						)
								return self.parent[item]




		def 				lowerCAmelCase_  (							self  :		Optional[int]    ,    _lowerCAmelCase  :		Optional[Any]    ,    _lowerCAmelCase  :		Tuple						):
								SCREAMING_SNAKE_CASE_     						=      self.find(_lowerCAmelCase						)
								SCREAMING_SNAKE_CASE_     						=      self.find(_lowerCAmelCase						)

								if roota == roota:
														return roota

								if self.rank[roota] > self.rank[roota]:
														SCREAMING_SNAKE_CASE_     						=      roota
														return roota

								if self.rank[roota] < self.rank[roota]:
														SCREAMING_SNAKE_CASE_     						=      roota
														return roota

								if self.rank[roota] == self.rank[roota]:
														self.rank[roota] += 1
														SCREAMING_SNAKE_CASE_     						=      roota
														return roota
								return None



	@staticmethod
	def 				lowerCAmelCase_  (							_lowerCAmelCase  :		str						):
							SCREAMING_SNAKE_CASE_     						=      graph.num_vertices

							SCREAMING_SNAKE_CASE_     						=      Graph.UnionFind()
							SCREAMING_SNAKE_CASE_     						=      []
							while num_components > 1:
													SCREAMING_SNAKE_CASE_     						=      {}
													for vertex in graph.get_vertices():
																			SCREAMING_SNAKE_CASE_     						=      -1

													SCREAMING_SNAKE_CASE_     						=      graph.get_edges()
													for edge in edges:
																			SCREAMING_SNAKE_CASE_						,			SCREAMING_SNAKE_CASE_						,			SCREAMING_SNAKE_CASE_     						=      edge
																			edges.remove((tail, head, weight)						)
													for edge in edges:
																			SCREAMING_SNAKE_CASE_						,			SCREAMING_SNAKE_CASE_						,			SCREAMING_SNAKE_CASE_     						=      edge
																			SCREAMING_SNAKE_CASE_     						=      union_find.find(_lowerCAmelCase						)
																			SCREAMING_SNAKE_CASE_     						=      union_find.find(_lowerCAmelCase						)
																			if seta != seta:
																									if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
																															SCREAMING_SNAKE_CASE_     						=      [head, tail, weight]

																									if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
																															SCREAMING_SNAKE_CASE_     						=      [head, tail, weight]
													for vertex in cheap_edge:
																			if cheap_edge[vertex] != -1:
																									SCREAMING_SNAKE_CASE_						,			SCREAMING_SNAKE_CASE_						,			SCREAMING_SNAKE_CASE_     						=      cheap_edge[vertex]
																									if union_find.find(_lowerCAmelCase						) != union_find.find(_lowerCAmelCase						):
																															union_find.union(_lowerCAmelCase    ,    _lowerCAmelCase						)
																															mst_edges.append(cheap_edge[vertex]						)
																															SCREAMING_SNAKE_CASE_     						=      num_components - 1
							SCREAMING_SNAKE_CASE_     						=      Graph.build(edges=_lowerCAmelCase						)
							return mst





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__			:       str         =							get_tests_dir('fixtures/dummy-config.json')





class 	lowerCamelCase_							(				unittest.TestCase ):


 '''simple docstring'''







 def 				lowerCAmelCase_  (							self  :		Dict						):
       SCREAMING_SNAKE_CASE_     						=      0



 def 				lowerCAmelCase_  (							self  :		Optional[int]						):
       self.assertIsNotNone(transformers.models.auto.__spec__						)
       self.assertIsNotNone(importlib.util.find_spec('transformers.models.auto'						)						)



 def 				lowerCAmelCase_  (							self  :		Any						):
       SCREAMING_SNAKE_CASE_     						=      AutoConfig.from_pretrained('bert-base-uncased'						)
       self.assertIsInstance(_lowerCAmelCase    ,    _lowerCAmelCase						)



 def 				lowerCAmelCase_  (							self  :		Union[str, Any]						):
       SCREAMING_SNAKE_CASE_     						=      AutoConfig.from_pretrained(_lowerCAmelCase						)
       self.assertIsInstance(_lowerCAmelCase    ,    _lowerCAmelCase						)



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



 def 				lowerCAmelCase_  (							self  :		Dict						):
       SCREAMING_SNAKE_CASE_     						=      AutoConfig.for_model('roberta'						)
       self.assertIsInstance(_lowerCAmelCase    ,    _lowerCAmelCase						)



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



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

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



 def 				lowerCAmelCase_  (							self  :		Optional[int]						):
       with self.assertRaisesRegex(
           _lowerCAmelCase    ,    'bert-base is not a local folder and is not a valid model identifier'						):
             SCREAMING_SNAKE_CASE_     						=      AutoConfig.from_pretrained('bert-base'						)



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



 def 				lowerCAmelCase_  (							self  :		Tuple						):
       with self.assertRaisesRegex(
           _lowerCAmelCase    ,    'hf-internal-testing/no-config-test-repo does not appear to have a file named config.json.'    ,    ):
             SCREAMING_SNAKE_CASE_     						=      AutoConfig.from_pretrained('hf-internal-testing/no-config-test-repo'						)



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

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




 def 				lowerCAmelCase_  (							self  :		Any						):





       class 	lowerCamelCase_							(				_SCREAMING_SNAKE_CASE ):


        '''simple docstring'''







        lowercase_       =   "new-model"

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