


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


UpperCAmelCase__  			=				get_tests_dir('''fixtures/dummy-config.json''')
class 						a__					(					unittest.TestCase   ):





			'''simple docstring'''

			def 					lowerCAmelCase     (  self							:			List[Any]	)      ->		Optional[Any]:
						__A=	0
			def 					lowerCAmelCase     (  self							:			List[str]	)      ->		Tuple:
						self.assertIsNotNone(transformers.models.auto.__spec__	)
						self.assertIsNotNone(importlib.util.find_spec('transformers.models.auto'	)	)
			def 					lowerCAmelCase     (  self							:			Optional[Any]	)      ->		Any:
						__A=	AutoConfig.from_pretrained('bert-base-uncased'	)
						self.assertIsInstance(lowerCAmelCase_			,    lowerCAmelCase_	)
			def 					lowerCAmelCase     (  self							:			Any	)      ->		Union[str, Any]:
						__A=	AutoConfig.from_pretrained(lowerCAmelCase_	)
						self.assertIsInstance(lowerCAmelCase_			,    lowerCAmelCase_	)
			def 					lowerCAmelCase     (  self							:			List[str]	)      ->		List[str]:
						__A=	AutoConfig.from_pretrained(lowerCAmelCase_	)
						self.assertIsInstance(lowerCAmelCase_			,    lowerCAmelCase_	)
			def 					lowerCAmelCase     (  self							:			Dict	)      ->		Any:
						__A=	AutoConfig.for_model('roberta'	)
						self.assertIsInstance(lowerCAmelCase_			,    lowerCAmelCase_	)
			def 					lowerCAmelCase     (  self							:			Optional[Any]	)      ->		List[str]:
						with tempfile.TemporaryDirectory() as tmp_dir:
									# This model name contains bert and roberta, but roberta ends up being picked.
									__A=	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({}	)	)
									__A=	AutoConfig.from_pretrained(lowerCAmelCase_	)
									self.assertEqual(type(lowerCAmelCase_	)			,    lowerCAmelCase_	)
			def 					lowerCAmelCase     (  self							:			List[str]	)      ->		Union[str, 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
									__A=	CustomConfig()
									with tempfile.TemporaryDirectory() as tmp_dir:
												config.save_pretrained(lowerCAmelCase_	)
												__A=	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[Any]	)      ->		Tuple:
						with self.assertRaisesRegex(
						    lowerCAmelCase_			,    'bert-base is not a local folder and is not a valid model identifier'	):
									__A=	AutoConfig.from_pretrained('bert-base'	)
			def 					lowerCAmelCase     (  self							:			Optional[int]	)      ->		Tuple:
						with self.assertRaisesRegex(
						    lowerCAmelCase_			,    r'aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'	):
									__A=	AutoConfig.from_pretrained(lowerCAmelCase_			,    revision='aaaaaa'	)
			def 					lowerCAmelCase     (  self							:			int	)      ->		Any:
						with self.assertRaisesRegex(
						    lowerCAmelCase_			,    'hf-internal-testing/no-config-test-repo does not appear to have a file named config.json.'			,    ):
									__A=	AutoConfig.from_pretrained('hf-internal-testing/no-config-test-repo'	)
			def 					lowerCAmelCase     (  self							:			str	)      ->		Tuple:
						# If remote code is not set, we will time out when asking whether to load the model.
						with self.assertRaises(lowerCAmelCase_	):
									__A=	AutoConfig.from_pretrained('hf-internal-testing/test_dynamic_model'	)
						# If remote code is disabled, we can't load this config.
						with self.assertRaises(lowerCAmelCase_	):
									__A=	AutoConfig.from_pretrained('hf-internal-testing/test_dynamic_model'			,    trust_remote_code=lowerCAmelCase_	)

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

			def 					lowerCAmelCase     (  self							:			Any	)      ->		Union[str, Any]:
						class 						a__					(					a_   ):





									'''simple docstring'''

									A						:				int					      =			'''new-model'''

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







'''simple docstring'''





import math






def 						UpperCAmelCase__(				_SCREAMING_SNAKE_CASE					: int ):






			"""simple docstring"""




			if not isinstance(_SCREAMING_SNAKE_CASE,_SCREAMING_SNAKE_CASE ):
						__A=	f"""Input value of [number={number}] must be an integer"""
						raise TypeError(_SCREAMING_SNAKE_CASE )

			if number < 1:
						__A=	f"""Input value of [number={number}] must be > 0"""
						raise ValueError(_SCREAMING_SNAKE_CASE )
			elif number == 1:
						return 3
			elif number == 2:
						return 5
			else:
						__A=	int(math.log(number // 3,2 ) ) + 2

						__A=	[3, 5]
						__A=	2
						__A=	3
						for block in range(1,_SCREAMING_SNAKE_CASE ):
									for _ in range(_SCREAMING_SNAKE_CASE ):
												proth_list.append(2 ** (block + 1) + proth_list[proth_index - 1] )
												proth_index += 1
									increment *= 2

			return proth_list[number - 1]


if __name__ == "__main__":
					import doctest

					doctest.testmod()

					for number in range(1_1):
										UpperCAmelCase__  			=				0
										try:
															UpperCAmelCase__  			=				proth(number)
										except ValueError:
															print(F"""ValueError: there is no {number}th Proth number""")
															continue

										print(F"""The {number}th Proth number: {value}""")



