
"""simple docstring"""







from __future__ import annotations

import copy
import tempfile
import unittest

from transformers import CONFIG_MAPPING, AutoConfig, BertConfig, GPTaConfig, TaConfig, TapasConfig, is_tf_available
from transformers.testing_utils import (
    DUMMY_UNKNOWN_IDENTIFIER,
    SMALL_MODEL_IDENTIFIER,
    RequestCounter,
    require_tensorflow_probability,
    require_tf,
    slow,
)

from ..bert.test_modeling_bert import BertModelTester


if is_tf_available():
							from transformers import (
							    TFAutoModel,
							    TFAutoModelForCausalLM,
							    TFAutoModelForMaskedLM,
							    TFAutoModelForPreTraining,
							    TFAutoModelForQuestionAnswering,
							    TFAutoModelForSeqaSeqLM,
							    TFAutoModelForSequenceClassification,
							    TFAutoModelForTableQuestionAnswering,
							    TFAutoModelForTokenClassification,
							    TFAutoModelWithLMHead,
							    TFBertForMaskedLM,
							    TFBertForPreTraining,
							    TFBertForQuestionAnswering,
							    TFBertForSequenceClassification,
							    TFBertModel,
							    TFFunnelBaseModel,
							    TFFunnelModel,
							    TFGPTaLMHeadModel,
							    TFRobertaForMaskedLM,
							    TFTaForConditionalGeneration,
							    TFTapasForQuestionAnswering,
							)
							from transformers.models.auto.modeling_tf_auto import (
							    TF_MODEL_FOR_CAUSAL_LM_MAPPING,
							    TF_MODEL_FOR_MASKED_LM_MAPPING,
							    TF_MODEL_FOR_PRETRAINING_MAPPING,
							    TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING,
							    TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
							    TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
							    TF_MODEL_MAPPING,
							)
							from transformers.models.bert.modeling_tf_bert import TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST
							from transformers.models.gpta.modeling_tf_gpta import TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST
							from transformers.models.ta.modeling_tf_ta import TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST
							from transformers.models.tapas.modeling_tf_tapas import TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST




class 			A__	(     _lowerCamelCase):
		A_						:	Tuple           =     'new-model'


if is_tf_available():




							class 			A__	(     _lowerCamelCase):
									A_						:	str           =     NewModelConfig




@require_tf
class 			A__	(     unittest.TestCase):

		@slow
		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						List[str]						      =				'bert-base-cased'
			__lowerCAmelCase      :						Any						      =				AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE			)
			self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
			self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

			__lowerCAmelCase      :						Optional[Any]						      =				TFAutoModel.from_pretrained(_SCREAMING_SNAKE_CASE			)
			self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
			self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

		@slow
		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Tuple						      =				'bert-base-cased'
			__lowerCAmelCase      :						Tuple						      =				AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE			)
			self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
			self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

			__lowerCAmelCase      :						Tuple						      =				TFAutoModelForPreTraining.from_pretrained(_SCREAMING_SNAKE_CASE			)
			self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
			self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

		@slow
		def 							__lowerCamelCase							(				self			):
			for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
				__lowerCAmelCase      :						List[str]						      =				AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE			)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

				__lowerCAmelCase      :						Any						      =				TFAutoModelForCausalLM.from_pretrained(_SCREAMING_SNAKE_CASE			)
				__lowerCAmelCase      ,       __lowerCAmelCase      :						List[str]						      =				TFAutoModelForCausalLM.from_pretrained(_SCREAMING_SNAKE_CASE	,		output_loading_info=_SCREAMING_SNAKE_CASE			)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

		@slow
		def 							__lowerCamelCase							(				self			):
			for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
				__lowerCAmelCase      :						Optional[Any]						      =				AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE			)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

				__lowerCAmelCase      :						int						      =				TFAutoModelWithLMHead.from_pretrained(_SCREAMING_SNAKE_CASE			)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

		@slow
		def 							__lowerCamelCase							(				self			):
			for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
				__lowerCAmelCase      :						Optional[int]						      =				AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE			)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

				__lowerCAmelCase      :						int						      =				TFAutoModelForMaskedLM.from_pretrained(_SCREAMING_SNAKE_CASE			)
				__lowerCAmelCase      ,       __lowerCAmelCase      :						List[str]						      =				TFAutoModelForMaskedLM.from_pretrained(_SCREAMING_SNAKE_CASE	,		output_loading_info=_SCREAMING_SNAKE_CASE			)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

		@slow
		def 							__lowerCamelCase							(				self			):
			for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
				__lowerCAmelCase      :						str						      =				AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE			)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

				__lowerCAmelCase      :						List[str]						      =				TFAutoModelForSeqaSeqLM.from_pretrained(_SCREAMING_SNAKE_CASE			)
				__lowerCAmelCase      ,       __lowerCAmelCase      :						List[str]						      =				TFAutoModelForSeqaSeqLM.from_pretrained(_SCREAMING_SNAKE_CASE	,		output_loading_info=_SCREAMING_SNAKE_CASE			)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

		@slow
		def 							__lowerCamelCase							(				self			):
			# for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
			for model_name in ["bert-base-uncased"]:
				__lowerCAmelCase      :						Optional[int]						      =				AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE			)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

				__lowerCAmelCase      :						Union[str, Any]						      =				TFAutoModelForSequenceClassification.from_pretrained(_SCREAMING_SNAKE_CASE			)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

		@slow
		def 							__lowerCamelCase							(				self			):
			# for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
			for model_name in ["bert-base-uncased"]:
				__lowerCAmelCase      :						Optional[Any]						      =				AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE			)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

				__lowerCAmelCase      :						int						      =				TFAutoModelForQuestionAnswering.from_pretrained(_SCREAMING_SNAKE_CASE			)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

		@slow
		@require_tensorflow_probability
		def 							__lowerCamelCase							(				self			):
			for model_name in TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST[5:6]:
				__lowerCAmelCase      :						List[Any]						      =				AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE			)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

				__lowerCAmelCase      :						str						      =				TFAutoModelForTableQuestionAnswering.from_pretrained(_SCREAMING_SNAKE_CASE			)
				__lowerCAmelCase      ,       __lowerCAmelCase      :						Any						      =				TFAutoModelForTableQuestionAnswering.from_pretrained(
				    _SCREAMING_SNAKE_CASE	,		output_loading_info=_SCREAMING_SNAKE_CASE			)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Optional[Any]						      =				TFAutoModelWithLMHead.from_pretrained(_SCREAMING_SNAKE_CASE			)
			self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)
			self.assertEqual(model.num_parameters()	,		1_44_10			)
			self.assertEqual(model.num_parameters(only_trainable=_SCREAMING_SNAKE_CASE			)	,		1_44_10			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Tuple						      =				TFAutoModelWithLMHead.from_pretrained(_SCREAMING_SNAKE_CASE			)
			self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)
			self.assertEqual(model.num_parameters()	,		1_44_10			)
			self.assertEqual(model.num_parameters(only_trainable=_SCREAMING_SNAKE_CASE			)	,		1_44_10			)

		def 							__lowerCamelCase							(				self			):
			# For the auto model mapping, FunnelConfig has two models: FunnelModel and FunnelBaseModel
			__lowerCAmelCase      :						Any						      =				TFAutoModel.from_pretrained('sgugger/funnel-random-tiny'			)
			self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

			__lowerCAmelCase      :						Any						      =				copy.deepcopy(model.config			)
			__lowerCAmelCase      :						Tuple						      =				['FunnelBaseModel']
			__lowerCAmelCase      :						Union[str, Any]						      =				TFAutoModel.from_config(_SCREAMING_SNAKE_CASE			)
			self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

			with tempfile.TemporaryDirectory() as tmp_dir:
				model.save_pretrained(_SCREAMING_SNAKE_CASE			)
				__lowerCAmelCase      :						Optional[Any]						      =				TFAutoModel.from_pretrained(_SCREAMING_SNAKE_CASE			)
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

		def 							__lowerCamelCase							(				self			):
			try:
				AutoConfig.register('new-model'	,		_SCREAMING_SNAKE_CASE			)

				__lowerCAmelCase      :						Optional[int]						      =				[
				    TFAutoModel,
				    TFAutoModelForCausalLM,
				    TFAutoModelForMaskedLM,
				    TFAutoModelForPreTraining,
				    TFAutoModelForQuestionAnswering,
				    TFAutoModelForSequenceClassification,
				    TFAutoModelForTokenClassification,
				]

				for auto_class in auto_classes:
					with self.subTest(auto_class.__name__			):
						# Wrong config class will raise an error
						with self.assertRaises(_SCREAMING_SNAKE_CASE			):
							auto_class.register(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)
						auto_class.register(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)
						# Trying to register something existing in the Transformers library will raise an error
						with self.assertRaises(_SCREAMING_SNAKE_CASE			):
							auto_class.register(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

						# Now that the config is registered, it can be used as any other config with the auto-API
						__lowerCAmelCase      :						Optional[Any]						      =				BertModelTester(self			).get_config()
						__lowerCAmelCase      :						Any						      =				NewModelConfig(**tiny_config.to_dict()			)
						__lowerCAmelCase      :						Tuple						      =				auto_class.from_config(_SCREAMING_SNAKE_CASE			)
						self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

						with tempfile.TemporaryDirectory() as tmp_dir:
							model.save_pretrained(_SCREAMING_SNAKE_CASE			)
							__lowerCAmelCase      :						Any						      =				auto_class.from_pretrained(_SCREAMING_SNAKE_CASE			)
							self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			)

			finally:
				if "new-model" in CONFIG_MAPPING._extra_content:
					del CONFIG_MAPPING._extra_content["new-model"]
				for mapping in (
				    TF_MODEL_MAPPING,
				    TF_MODEL_FOR_PRETRAINING_MAPPING,
				    TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING,
				    TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
				    TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
				    TF_MODEL_FOR_CAUSAL_LM_MAPPING,
				    TF_MODEL_FOR_MASKED_LM_MAPPING,
				):
					if NewModelConfig in mapping._extra_content:
						del mapping._extra_content[NewModelConfig]

		def 							__lowerCamelCase							(				self			):
			with self.assertRaisesRegex(
			    _SCREAMING_SNAKE_CASE	,		'bert-base is not a local folder and is not a valid model identifier'			):
				__lowerCAmelCase      :						Any						      =				TFAutoModel.from_pretrained('bert-base'			)

		def 							__lowerCamelCase							(				self			):
			with self.assertRaisesRegex(
			    _SCREAMING_SNAKE_CASE	,		R'aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'			):
				__lowerCAmelCase      :						List[str]						      =				TFAutoModel.from_pretrained(_SCREAMING_SNAKE_CASE	,		revision='aaaaaa'			)

		def 							__lowerCamelCase							(				self			):
			with self.assertRaisesRegex(
			    _SCREAMING_SNAKE_CASE	,		'hf-internal-testing/config-no-model does not appear to have a file named pytorch_model.bin'	,		):
				__lowerCAmelCase      :						Tuple						      =				TFAutoModel.from_pretrained('hf-internal-testing/config-no-model'			)

		def 							__lowerCamelCase							(				self			):
			with self.assertRaisesRegex(_SCREAMING_SNAKE_CASE	,		'Use `from_pt=True` to load this model'			):
				__lowerCAmelCase      :						Dict						      =				TFAutoModel.from_pretrained('hf-internal-testing/tiny-bert-pt-only'			)







		def 							__lowerCamelCase							(				self			):
			# Make sure we have cached the model.
			__lowerCAmelCase      :						Optional[int]						      =				TFAutoModel.from_pretrained('hf-internal-testing/tiny-random-bert'			)
			with RequestCounter() as counter:
				__lowerCAmelCase      :						Optional[Any]						      =				TFAutoModel.from_pretrained('hf-internal-testing/tiny-random-bert'			)
				self.assertEqual(counter.get_request_count	,		0			)
				self.assertEqual(counter.head_request_count	,		1			)
				self.assertEqual(counter.other_request_count	,		0			)

			# With a sharded checkpoint
			__lowerCAmelCase      :						Dict						      =				TFAutoModel.from_pretrained('ArthurZ/tiny-random-bert-sharded'			)
			with RequestCounter() as counter:
				__lowerCAmelCase      :						int						      =				TFAutoModel.from_pretrained('ArthurZ/tiny-random-bert-sharded'			)
				self.assertEqual(counter.get_request_count	,		0			)
				self.assertEqual(counter.head_request_count	,		1			)
				self.assertEqual(counter.other_request_count	,		0			)

"""simple docstring"""







from __future__ import annotations
def    __lowerCAmelCase    (_UpperCamelCase		):
	__lowerCAmelCase      :						List[str]						      =				str(_UpperCamelCase		)
	return len(_UpperCamelCase		) == 9 and set(_UpperCamelCase		) == set('123456789'		)
def    __lowerCAmelCase    ():
	for base_num in range(9999	,  4999	,  -1		):
		__lowerCAmelCase      :						Union[str, Any]						      =				10_0002 * base_num
		if is_9_pandigital(_UpperCamelCase		):
			return candidate

	for base_num in range(333	,  99	,  -1		):
		__lowerCAmelCase      :						Dict						      =				100_2003 * base_num
		if is_9_pandigital(_UpperCamelCase		):
			return candidate

	return None


if __name__ == "__main__":
							print(f'{solution() = }')