"""simple docstring"""







import itertools
import random
import unittest

import numpy as np

from transformers import is_speech_available
from transformers.testing_utils import require_torch, require_torchaudio

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_speech_available():
	from transformers import SpeechaTextFeatureExtractor

_a=			random.Random()
def   __UpperCAmelCase    (   UpperCAmelCase_   :    Optional[Any]      ,							UpperCAmelCase_   :    Optional[Any]=1.0      ,							UpperCAmelCase_   :    Optional[Any]=None      ,							UpperCAmelCase_   :    List[Any]=None  )							->      List[str]:

	'''simple docstring'''





	if rng is None:
		__snake_case      :							Union[str, Any]						=			global_rng

	__snake_case      :							Union[str, Any]						=			[]
	for batch_idx in range(shape[0]  ):
		values.append([]  )
		for _ in range(shape[1]  ):
			values[-1].append(rng.random() * scale  )

	return values

@require_torch
@require_torchaudio
class 		UpperCamelCase      (   unittest.TestCase						):



				def __init__(self    :				Any     ,  _A    :				str     ,  _A    :				Any=7     ,  _A    :				List[str]=4_00     ,  _A    :				Any=20_00     ,  _A    :				Optional[Any]=24     ,  _A    :				Dict=24     ,  _A    :				Optional[Any]=0.0     ,  _A    :				int=1_60_00     ,  _A    :				Tuple=True     ,  _A    :				str=True     ,  )   ->     Optional[int]:
					__snake_case      :							Tuple						=			parent
					__snake_case      :							Any						=			batch_size
					__snake_case      :							List[str]						=			min_seq_length
					__snake_case      :							Dict						=			max_seq_length
					__snake_case      :							List[str]						=			(self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
					__snake_case      :							Tuple						=			feature_size
					__snake_case      :							List[str]						=			num_mel_bins
					__snake_case      :							Optional[int]						=			padding_value
					__snake_case      :							Any						=			sampling_rate
					__snake_case      :							Optional[Any]						=			return_attention_mask
					__snake_case      :							List[Any]						=			do_normalize



				def  _lowercase					(self    :				List[str])   ->     Dict:
					return {
					    "feature_size": self.feature_size,
					    "num_mel_bins": self.num_mel_bins,
					    "padding_value": self.padding_value,
					    "sampling_rate": self.sampling_rate,
					    "return_attention_mask": self.return_attention_mask,
					    "do_normalize": self.do_normalize,
					}






				def  _lowercase					(self    :				Union[str, Any]     ,  _A    :				Union[str, Any]=False     ,  _A    :				List[str]=False)   ->     Union[str, Any]:
					def _flatten(_A    :				Optional[int]):
						return list(itertools.chain(*lowercase_))

					if equal_length:
						__snake_case      :							str						=			[floats_list((self.max_seq_length, self.feature_size)) for _ in range(self.batch_size)]
					else:
						# make sure that inputs increase in size
						__snake_case      :							Optional[Any]						=			[
						    floats_list((x, self.feature_size))
						    for x in range(self.min_seq_length     ,  self.max_seq_length     ,  self.seq_length_diff)
						]
					if numpify:
						__snake_case      :							Dict						=			[np.asarray(lowercase_) for x in speech_inputs]
					return speech_inputs







@require_torch
@require_torchaudio
class 		UpperCamelCase      (   lowercase__				,     unittest.TestCase						):
				UpperCAmelCase    :				List[Any]   =		SpeechaTextFeatureExtractor if is_speech_available() else None



				def  _lowercase					(self    :				Any)   ->     int:
					__snake_case      :							str						=			SpeechaTextFeatureExtractionTester(self)



				def  _lowercase					(self    :				Any     ,  _A    :				Optional[Any])   ->     Dict:
					self.assertTrue(np.all(np.mean(lowercase_     ,  axis=0) < 1E-3))
					self.assertTrue(np.all(np.abs(np.var(lowercase_     ,  axis=0) - 1) < 1E-3))



				def  _lowercase					(self    :				Any)   ->     Tuple:
					__snake_case      :							Optional[int]						=			self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
					# create three inputs of length 800, 1000, and 1200
					__snake_case      :							int						=			[floats_list((1, x))[0] for x in range(8_00     ,  14_00     ,  2_00)]
					__snake_case      :							List[str]						=			[np.asarray(lowercase_) for speech_input in speech_inputs]

					# Test feature size
					__snake_case      :							int						=			feature_extractor(lowercase_     ,  padding=lowercase_     ,  return_tensors='np').input_features
					self.assertTrue(input_features.ndim == 3)
					self.assertTrue(input_features.shape[-1] == feature_extractor.feature_size)

					# Test not batched input
					__snake_case      :							int						=			feature_extractor(speech_inputs[0]     ,  return_tensors='np').input_features
					__snake_case      :							Optional[int]						=			feature_extractor(np_speech_inputs[0]     ,  return_tensors='np').input_features
					self.assertTrue(np.allclose(lowercase_     ,  lowercase_     ,  atol=1E-3))

					# Test batched
					__snake_case      :							Dict						=			feature_extractor(lowercase_     ,  return_tensors='np').input_features
					__snake_case      :							Tuple						=			feature_extractor(lowercase_     ,  return_tensors='np').input_features
					for enc_seq_a, enc_seq_a in zip(lowercase_     ,  lowercase_):
						self.assertTrue(np.allclose(lowercase_     ,  lowercase_     ,  atol=1E-3))

					# Test 2-D numpy arrays are batched.
					__snake_case      :							List[Any]						=			[floats_list((1, x))[0] for x in (8_00, 8_00, 8_00)]
					__snake_case      :							Tuple						=			np.asarray(lowercase_)
					__snake_case      :							int						=			feature_extractor(lowercase_     ,  return_tensors='np').input_features
					__snake_case      :							str						=			feature_extractor(lowercase_     ,  return_tensors='np').input_features
					for enc_seq_a, enc_seq_a in zip(lowercase_     ,  lowercase_):
						self.assertTrue(np.allclose(lowercase_     ,  lowercase_     ,  atol=1E-3))



				def  _lowercase					(self    :				Union[str, Any])   ->     List[Any]:
					__snake_case      :							Union[str, Any]						=			self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
					__snake_case      :							Dict						=			[floats_list((1, x))[0] for x in range(8_00     ,  14_00     ,  2_00)]

					__snake_case      :							int						=			["longest", "max_length", "do_not_pad"]
					__snake_case      :							Optional[Any]						=			[None, 16, None]
					for max_length, padding in zip(lowercase_     ,  lowercase_):
						__snake_case      :							Dict						=			feature_extractor(
						    lowercase_     ,  padding=lowercase_     ,  max_length=lowercase_     ,  return_attention_mask=lowercase_)
						__snake_case      :							Any						=			inputs.input_features
						__snake_case      :							List[Any]						=			inputs.attention_mask
						__snake_case      :							Dict						=			[np.sum(lowercase_) for x in attention_mask]

						self._check_zero_mean_unit_variance(input_features[0][: fbank_feat_lengths[0]])
						self._check_zero_mean_unit_variance(input_features[1][: fbank_feat_lengths[1]])
						self._check_zero_mean_unit_variance(input_features[2][: fbank_feat_lengths[2]])



				def  _lowercase					(self    :				int)   ->     Dict:
					__snake_case      :							Tuple						=			self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
					__snake_case      :							Union[str, Any]						=			[floats_list((1, x))[0] for x in range(8_00     ,  14_00     ,  2_00)]

					__snake_case      :							Union[str, Any]						=			["longest", "max_length", "do_not_pad"]
					__snake_case      :							Optional[Any]						=			[None, 16, None]
					for max_length, padding in zip(lowercase_     ,  lowercase_):
						__snake_case      :							Optional[Any]						=			feature_extractor(
						    lowercase_     ,  max_length=lowercase_     ,  padding=lowercase_     ,  return_tensors='np'     ,  return_attention_mask=lowercase_)
						__snake_case      :							Optional[int]						=			inputs.input_features
						__snake_case      :							Union[str, Any]						=			inputs.attention_mask
						__snake_case      :							Union[str, Any]						=			[np.sum(lowercase_) for x in attention_mask]

						self._check_zero_mean_unit_variance(input_features[0][: fbank_feat_lengths[0]])
						self.assertTrue(input_features[0][fbank_feat_lengths[0] :].sum() < 1E-6)
						self._check_zero_mean_unit_variance(input_features[1][: fbank_feat_lengths[1]])
						self.assertTrue(input_features[0][fbank_feat_lengths[1] :].sum() < 1E-6)
						self._check_zero_mean_unit_variance(input_features[2][: fbank_feat_lengths[2]])



				def  _lowercase					(self    :				Optional[int])   ->     Dict:
					__snake_case      :							Optional[Any]						=			self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
					__snake_case      :							Any						=			[floats_list((1, x))[0] for x in range(8_00     ,  14_00     ,  2_00)]
					__snake_case      :							List[Any]						=			feature_extractor(
					    lowercase_     ,  padding='max_length'     ,  max_length=4     ,  truncation=lowercase_     ,  return_tensors='np'     ,  return_attention_mask=lowercase_     ,  )
					__snake_case      :							Dict						=			inputs.input_features
					__snake_case      :							Optional[int]						=			inputs.attention_mask
					__snake_case      :							int						=			np.sum(attention_mask == 1     ,  axis=1)

					self._check_zero_mean_unit_variance(input_features[0, : fbank_feat_lengths[0]])
					self._check_zero_mean_unit_variance(input_features[1])
					self._check_zero_mean_unit_variance(input_features[2])



				def  _lowercase					(self    :				List[Any])   ->     Dict:
					__snake_case      :							Union[str, Any]						=			self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
					__snake_case      :							Optional[int]						=			[floats_list((1, x))[0] for x in range(8_00     ,  14_00     ,  2_00)]
					__snake_case      :							Dict						=			feature_extractor(
					    lowercase_     ,  padding='longest'     ,  max_length=4     ,  truncation=lowercase_     ,  return_tensors='np'     ,  return_attention_mask=lowercase_     ,  )
					__snake_case      :							Tuple						=			inputs.input_features
					__snake_case      :							int						=			inputs.attention_mask
					__snake_case      :							List[Any]						=			np.sum(attention_mask == 1     ,  axis=1)

					self._check_zero_mean_unit_variance(input_features[0, : fbank_feat_lengths[0]])
					self._check_zero_mean_unit_variance(input_features[1, : fbank_feat_lengths[1]])
					self._check_zero_mean_unit_variance(input_features[2])

					# make sure that if max_length < longest -> then pad to max_length
					self.assertEqual(input_features.shape     ,  (3, 4, 24))

					__snake_case      :							Tuple						=			[floats_list((1, x))[0] for x in range(8_00     ,  14_00     ,  2_00)]
					__snake_case      :							Dict						=			feature_extractor(
					    lowercase_     ,  padding='longest'     ,  max_length=16     ,  truncation=lowercase_     ,  return_tensors='np'     ,  return_attention_mask=lowercase_     ,  )
					__snake_case      :							Dict						=			inputs.input_features
					__snake_case      :							int						=			inputs.attention_mask
					__snake_case      :							Any						=			np.sum(attention_mask == 1     ,  axis=1)

					self._check_zero_mean_unit_variance(input_features[0, : fbank_feat_lengths[0]])
					self._check_zero_mean_unit_variance(input_features[1, : fbank_feat_lengths[1]])
					self._check_zero_mean_unit_variance(input_features[2])

					# make sure that if max_length < longest -> then pad to max_length
					self.assertEqual(input_features.shape     ,  (3, 6, 24))



				def  _lowercase					(self    :				Dict)   ->     int:
					import torch

					__snake_case      :							Any						=			self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
					__snake_case      :							Union[str, Any]						=			np.random.rand(1_00     ,  32).astype(np.floataa)
					__snake_case      :							Tuple						=			np_speech_inputs.tolist()

					for inputs in [py_speech_inputs, np_speech_inputs]:
						__snake_case      :							Optional[int]						=			feature_extractor.pad([{'input_features': inputs}]     ,  return_tensors='np')
						self.assertTrue(np_processed.input_features.dtype == np.floataa)
						__snake_case      :							Dict						=			feature_extractor.pad([{'input_features': inputs}]     ,  return_tensors='pt')
						self.assertTrue(pt_processed.input_features.dtype == torch.floataa)



				def  _lowercase					(self    :				Any     ,  _A    :				str)   ->     int:
					from datasets import load_dataset

					__snake_case      :							Any						=			load_dataset('hf-internal-testing/librispeech_asr_dummy'     ,  'clean'     ,  split='validation')
					# automatic decoding with librispeech
					__snake_case      :							int						=			ds.sort('id').select(range(lowercase_))[:num_samples]["audio"]

					return [x["array"] for x in speech_samples]






				def  _lowercase					(self    :				List[str])   ->     Optional[Any]:
					__snake_case      :							List[Any]						=			np.array([
					    -1.5_745, -1.7_713, -1.7_020, -1.6_069, -1.2_250, -1.1_105, -0.9_072, -0.8_241,
					    -1.2_310, -0.8_098, -0.3_320, -0.4_101, -0.7_985, -0.4_996, -0.8_213, -0.9_128,
					    -1.0_420, -1.1_286, -1.0_440, -0.7_999, -0.8_405, -1.2_275, -1.5_443, -1.4_625,
					])
					# fmt: on

					__snake_case      :							List[Any]						=			self._load_datasamples(1)
					__snake_case      :							List[Any]						=			self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
					__snake_case      :							Optional[int]						=			feature_extractor(lowercase_     ,  return_tensors='pt').input_features
					self.assertEquals(input_features.shape     ,  (1, 5_84, 24))
					self.assertTrue(np.allclose(input_features[0, 0, :30]     ,  lowercase_     ,  atol=1E-4))






"""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 		UpperCamelCase      (   lowercase						):
				UpperCAmelCase    :				Optional[int]   =		"""new-model"""


if is_tf_available():

	class 		UpperCamelCase      (   lowercase						):
					UpperCAmelCase    :				List[str]   =		NewModelConfig

@require_tf
class 		UpperCamelCase      (   unittest.TestCase						):



				@slow
				def  _lowercase					(self    :				List[str])   ->     Dict:
					__snake_case      :							Any						=			'bert-base-cased'
					__snake_case      :							Optional[Any]						=			AutoConfig.from_pretrained(_A)
					self.assertIsNotNone(_A)
					self.assertIsInstance(_A     ,  _A)

					__snake_case      :							Union[str, Any]						=			TFAutoModel.from_pretrained(_A)
					self.assertIsNotNone(_A)
					self.assertIsInstance(_A     ,  _A)



				@slow
				def  _lowercase					(self    :				List[Any])   ->     str:
					__snake_case      :							Optional[int]						=			'bert-base-cased'
					__snake_case      :							List[Any]						=			AutoConfig.from_pretrained(_A)
					self.assertIsNotNone(_A)
					self.assertIsInstance(_A     ,  _A)

					__snake_case      :							Dict						=			TFAutoModelForPreTraining.from_pretrained(_A)
					self.assertIsNotNone(_A)
					self.assertIsInstance(_A     ,  _A)



				@slow
				def  _lowercase					(self    :				Any)   ->     List[str]:
					for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						__snake_case      :							str						=			AutoConfig.from_pretrained(_A)
						self.assertIsNotNone(_A)
						self.assertIsInstance(_A     ,  _A)

						__snake_case      :							List[str]						=			TFAutoModelForCausalLM.from_pretrained(_A)
						__snake_case		,    __snake_case      :							List[str]						=			TFAutoModelForCausalLM.from_pretrained(_A     ,  output_loading_info=_A)
						self.assertIsNotNone(_A)
						self.assertIsInstance(_A     ,  _A)



				@slow
				def  _lowercase					(self    :				Tuple)   ->     Dict:
					for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						__snake_case      :							Union[str, Any]						=			AutoConfig.from_pretrained(_A)
						self.assertIsNotNone(_A)
						self.assertIsInstance(_A     ,  _A)

						__snake_case      :							Union[str, Any]						=			TFAutoModelWithLMHead.from_pretrained(_A)
						self.assertIsNotNone(_A)
						self.assertIsInstance(_A     ,  _A)



				@slow
				def  _lowercase					(self    :				Union[str, Any])   ->     Optional[int]:
					for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						__snake_case      :							Union[str, Any]						=			AutoConfig.from_pretrained(_A)
						self.assertIsNotNone(_A)
						self.assertIsInstance(_A     ,  _A)

						__snake_case      :							Optional[Any]						=			TFAutoModelForMaskedLM.from_pretrained(_A)
						__snake_case		,    __snake_case      :							Optional[int]						=			TFAutoModelForMaskedLM.from_pretrained(_A     ,  output_loading_info=_A)
						self.assertIsNotNone(_A)
						self.assertIsInstance(_A     ,  _A)



				@slow
				def  _lowercase					(self    :				str)   ->     Union[str, Any]:
					for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						__snake_case      :							Dict						=			AutoConfig.from_pretrained(_A)
						self.assertIsNotNone(_A)
						self.assertIsInstance(_A     ,  _A)

						__snake_case      :							str						=			TFAutoModelForSeqaSeqLM.from_pretrained(_A)
						__snake_case		,    __snake_case      :							Union[str, Any]						=			TFAutoModelForSeqaSeqLM.from_pretrained(_A     ,  output_loading_info=_A)
						self.assertIsNotNone(_A)
						self.assertIsInstance(_A     ,  _A)



				@slow
				def  _lowercase					(self    :				str)   ->     str:
					# for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
					for model_name in ["bert-base-uncased"]:
						__snake_case      :							Tuple						=			AutoConfig.from_pretrained(_A)
						self.assertIsNotNone(_A)
						self.assertIsInstance(_A     ,  _A)

						__snake_case      :							Tuple						=			TFAutoModelForSequenceClassification.from_pretrained(_A)
						self.assertIsNotNone(_A)
						self.assertIsInstance(_A     ,  _A)



				@slow
				def  _lowercase					(self    :				Optional[Any])   ->     Optional[int]:
					# for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
					for model_name in ["bert-base-uncased"]:
						__snake_case      :							List[str]						=			AutoConfig.from_pretrained(_A)
						self.assertIsNotNone(_A)
						self.assertIsInstance(_A     ,  _A)

						__snake_case      :							Any						=			TFAutoModelForQuestionAnswering.from_pretrained(_A)
						self.assertIsNotNone(_A)
						self.assertIsInstance(_A     ,  _A)



				@slow
				@require_tensorflow_probability
				def  _lowercase					(self    :				List[Any])   ->     List[str]:
					for model_name in TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST[5:6]:
						__snake_case      :							Optional[Any]						=			AutoConfig.from_pretrained(_A)
						self.assertIsNotNone(_A)
						self.assertIsInstance(_A     ,  _A)

						__snake_case      :							int						=			TFAutoModelForTableQuestionAnswering.from_pretrained(_A)
						__snake_case		,    __snake_case      :							Dict						=			TFAutoModelForTableQuestionAnswering.from_pretrained(
						    _A     ,  output_loading_info=_A)
						self.assertIsNotNone(_A)
						self.assertIsInstance(_A     ,  _A)



				def  _lowercase					(self    :				Optional[Any])   ->     Optional[Any]:
					__snake_case      :							Optional[int]						=			TFAutoModelWithLMHead.from_pretrained(_A)
					self.assertIsInstance(_A     ,  _A)
					self.assertEqual(model.num_parameters()     ,  1_44_10)
					self.assertEqual(model.num_parameters(only_trainable=_A)     ,  1_44_10)



				def  _lowercase					(self    :				Any)   ->     List[str]:
					__snake_case      :							List[Any]						=			TFAutoModelWithLMHead.from_pretrained(_A)
					self.assertIsInstance(_A     ,  _A)
					self.assertEqual(model.num_parameters()     ,  1_44_10)
					self.assertEqual(model.num_parameters(only_trainable=_A)     ,  1_44_10)



				def  _lowercase					(self    :				Optional[Any])   ->     str:
					# For the auto model mapping, FunnelConfig has two models: FunnelModel and FunnelBaseModel
					__snake_case      :							Optional[Any]						=			TFAutoModel.from_pretrained('sgugger/funnel-random-tiny')
					self.assertIsInstance(_A     ,  _A)

					__snake_case      :							int						=			copy.deepcopy(model.config)
					__snake_case      :							int						=			['FunnelBaseModel']
					__snake_case      :							int						=			TFAutoModel.from_config(_A)
					self.assertIsInstance(_A     ,  _A)

					with tempfile.TemporaryDirectory() as tmp_dir:
						model.save_pretrained(_A)
						__snake_case      :							List[Any]						=			TFAutoModel.from_pretrained(_A)
						self.assertIsInstance(_A     ,  _A)



				def  _lowercase					(self    :				List[Any])   ->     int:
					try:
						AutoConfig.register('new-model'     ,  _A)

						__snake_case      :							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(_A):
									auto_class.register(_A     ,  _A)
								auto_class.register(_A     ,  _A)
								# Trying to register something existing in the Transformers library will raise an error
								with self.assertRaises(_A):
									auto_class.register(_A     ,  _A)

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

								with tempfile.TemporaryDirectory() as tmp_dir:
									model.save_pretrained(_A)
									__snake_case      :							Tuple						=			auto_class.from_pretrained(_A)
									self.assertIsInstance(_A     ,  _A)

					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  _lowercase					(self    :				Optional[int])   ->     Union[str, Any]:
					with self.assertRaisesRegex(
					    _A     ,  'bert-base is not a local folder and is not a valid model identifier'):
						__snake_case      :							Any						=			TFAutoModel.from_pretrained('bert-base')



				def  _lowercase					(self    :				str)   ->     str:
					with self.assertRaisesRegex(
					    _A     ,  r'aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'):
						__snake_case      :							Optional[Any]						=			TFAutoModel.from_pretrained(_A     ,  revision='aaaaaa')



				def  _lowercase					(self    :				int)   ->     Any:
					with self.assertRaisesRegex(
					    _A     ,  'hf-internal-testing/config-no-model does not appear to have a file named pytorch_model.bin'     ,  ):
						__snake_case      :							List[str]						=			TFAutoModel.from_pretrained('hf-internal-testing/config-no-model')



				def  _lowercase					(self    :				Optional[Any])   ->     Any:
					with self.assertRaisesRegex(_A     ,  'Use `from_pt=True` to load this model'):
						__snake_case      :							List[str]						=			TFAutoModel.from_pretrained('hf-internal-testing/tiny-bert-pt-only')






				def  _lowercase					(self    :				str)   ->     Any:
					# Make sure we have cached the model.
					__snake_case      :							str						=			TFAutoModel.from_pretrained('hf-internal-testing/tiny-random-bert')
					with RequestCounter() as counter:
						__snake_case      :							List[str]						=			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
					__snake_case      :							Optional[int]						=			TFAutoModel.from_pretrained('ArthurZ/tiny-random-bert-sharded')
					with RequestCounter() as counter:
						__snake_case      :							Any						=			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)





