



"""simple docstring"""
import contextlib
import copy
import random
from typing import Any, Dict, Iterable, Optional, Union

import numpy as np
import torch

from .utils import deprecate, is_transformers_available


if is_transformers_available():
						import transformers
def    A_  (			_lowercase	):







						'''simple docstring'''


						random.seed(_lowercase	)
						np.random.seed(_lowercase	)
						torch.manual_seed(_lowercase	)
						torch.cuda.manual_seed_all(_lowercase	)
						# ^^ safe to call this function even if cuda is not available

class 				lowerCamelCase  :






					'''simple docstring'''





					def __init__(       self:							List[Any]						,     snake_case:							Iterable[torch.nn.Parameter]						,     snake_case:							float = 0.9_9_9_9						,     snake_case:							float = 0.0						,     snake_case:							int = 0						,     snake_case:							bool = False						,     snake_case:							Union[float, int] = 1.0						,     snake_case:							Union[float, int] = 2 / 3						,     snake_case:							Optional[Any] = None						,     snake_case:							Dict[str, Any] = None						,     **snake_case:							Union[str, Any]						,     )   ->	str:

											if isinstance(snake_case						,     torch.nn.Module						):
																	snake_case_ :List[str]						=			(
																	    """Passing a `torch.nn.Module` to `ExponentialMovingAverage` is deprecated. """
																	    """Please pass the parameters of the module instead."""
																	)
																	deprecate(
																	    """passing a `torch.nn.Module` to `ExponentialMovingAverage`"""						,     """1.0.0"""						,     snake_case						,     standard_warn=snake_case						,     )
																	snake_case_ :Any						=			parameters.parameters()

																	# set use_ema_warmup to True if a torch.nn.Module is passed for backwards compatibility
																	snake_case_ :Optional[Any]						=			True

											if kwargs.get("""max_value"""						,     snake_case						) is not None:
																	snake_case_ :str						=			"""The `max_value` argument is deprecated. Please use `decay` instead."""
																	deprecate("""max_value"""						,     """1.0.0"""						,     snake_case						,     standard_warn=snake_case						)
																	snake_case_ :Union[str, Any]						=			kwargs["""max_value"""]

											if kwargs.get("""min_value"""						,     snake_case						) is not None:
																	snake_case_ :Dict						=			"""The `min_value` argument is deprecated. Please use `min_decay` instead."""
																	deprecate("""min_value"""						,     """1.0.0"""						,     snake_case						,     standard_warn=snake_case						)
																	snake_case_ :str						=			kwargs["""min_value"""]

											snake_case_ :str						=			list(snake_case						)
											snake_case_ :Optional[Any]						=			[p.clone().detach() for p in parameters]

											if kwargs.get("""device"""						,     snake_case						) is not None:
																	snake_case_ :Union[str, Any]						=			"""The `device` argument is deprecated. Please use `to` instead."""
																	deprecate("""device"""						,     """1.0.0"""						,     snake_case						,     standard_warn=snake_case						)
																	self.to(device=kwargs["""device"""]						)

											snake_case_ :Any						=			None

											snake_case_ :Optional[Any]						=			decay
											snake_case_ :Any						=			min_decay
											snake_case_ :List[Any]						=			update_after_step
											snake_case_ :Optional[Any]						=			use_ema_warmup
											snake_case_ :Optional[Any]						=			inv_gamma
											snake_case_ :int						=			power
											snake_case_ :int						=			0
											snake_case_ :Dict						=			None  # set in `step()`

											snake_case_ :Dict						=			model_cls
											snake_case_ :List[Any]						=			model_config






					@classmethod
					def    lowerCAmelCase_				(       cls:							Optional[int]						,     snake_case:							Tuple						,     snake_case:							Dict						)   ->	"EMAModel":
											snake_case_,       snake_case_ :Union[str, Any]						=			model_cls.load_config(snake_case						,     return_unused_kwargs=snake_case						)
											snake_case_ :Tuple						=			model_cls.from_pretrained(snake_case						)

											snake_case_ :Any						=			cls(model.parameters()						,     model_cls=snake_case						,     model_config=model.config						)

											ema_model.load_state_dict(snake_case						)
											return ema_model






					def    lowerCAmelCase_				(       self:							Optional[Any]						,     snake_case:							List[Any]						)   ->	str:
											if self.model_cls is None:
																	raise ValueError("""`save_pretrained` can only be used if `model_cls` was defined at __init__."""						)

											if self.model_config is None:
																	raise ValueError("""`save_pretrained` can only be used if `model_config` was defined at __init__."""						)

											snake_case_ :List[str]						=			self.model_cls.from_config(self.model_config						)
											snake_case_ :List[str]						=			self.state_dict()
											state_dict.pop("""shadow_params"""						,     snake_case						)

											model.register_to_config(**snake_case						)
											self.copy_to(model.parameters()						)
											model.save_pretrained(snake_case						)






					def    lowerCAmelCase_				(       self:							Dict						,     snake_case:							int						)   ->	float:
											snake_case_ :List[str]						=			max(0						,     optimization_step - self.update_after_step - 1						)

											if step <= 0:
																	return 0.0

											if self.use_ema_warmup:
																	snake_case_ :Any						=			1 - (1 + step / self.inv_gamma) ** -self.power
											else:
																	snake_case_ :int						=			(1 + step) / (10 + step)

											snake_case_ :Optional[Any]						=			min(snake_case						,     self.decay						)
											# make sure decay is not smaller than min_decay
											snake_case_ :Optional[int]						=			max(snake_case						,     self.min_decay						)
											return cur_decay_value






					@torch.no_grad()
					def    lowerCAmelCase_				(       self:							int						,     snake_case:							Iterable[torch.nn.Parameter]						)   ->	Optional[int]:
											if isinstance(snake_case						,     torch.nn.Module						):
																	snake_case_ :Tuple						=			(
																	    """Passing a `torch.nn.Module` to `ExponentialMovingAverage.step` is deprecated. """
																	    """Please pass the parameters of the module instead."""
																	)
																	deprecate(
																	    """passing a `torch.nn.Module` to `ExponentialMovingAverage.step`"""						,     """1.0.0"""						,     snake_case						,     standard_warn=snake_case						,     )
																	snake_case_ :Any						=			parameters.parameters()

											snake_case_ :str						=			list(snake_case						)

											self.optimization_step += 1

											# Compute the decay factor for the exponential moving average.
											snake_case_ :Union[str, Any]						=			self.get_decay(self.optimization_step						)
											snake_case_ :Optional[Any]						=			decay
											snake_case_ :Union[str, Any]						=			1 - decay

											snake_case_ :Tuple						=			contextlib.nullcontext
											if is_transformers_available() and transformers.deepspeed.is_deepspeed_zeroa_enabled():
																	import deepspeed

											for s_param, param in zip(self.shadow_params						,     snake_case						):
																	if is_transformers_available() and transformers.deepspeed.is_deepspeed_zeroa_enabled():
																							snake_case_ :List[Any]						=			deepspeed.zero.GatheredParameters(snake_case						,     modifier_rank=snake_case						)

																	with context_manager():
																							if param.requires_grad:
																													s_param.sub_(one_minus_decay * (s_param - param)						)
																							else:
																													s_param.copy_(snake_case						)






					def    lowerCAmelCase_				(       self:							int						,     snake_case:							Iterable[torch.nn.Parameter]						)   ->	None:
											snake_case_ :int						=			list(snake_case						)
											for s_param, param in zip(self.shadow_params						,     snake_case						):
																	param.data.copy_(s_param.to(param.device						).data						)






					def    lowerCAmelCase_				(       self:							str						,     snake_case:							Optional[Any]=None						,     snake_case:							List[str]=None						)   ->	None:
											snake_case_ :List[str]						=			[
											    p.to(device=snake_case						,     dtype=snake_case						) if p.is_floating_point() else p.to(device=snake_case						)
											    for p in self.shadow_params
											]






					def    lowerCAmelCase_				(       self:							Union[str, Any]						)   ->	dict:
											return {
											    "decay": self.decay,
											    "min_decay": self.min_decay,
											    "optimization_step": self.optimization_step,
											    "update_after_step": self.update_after_step,
											    "use_ema_warmup": self.use_ema_warmup,
											    "inv_gamma": self.inv_gamma,
											    "power": self.power,
											    "shadow_params": self.shadow_params,
											}






					def    lowerCAmelCase_				(       self:							List[Any]						,     snake_case:							Iterable[torch.nn.Parameter]						)   ->	None:
											snake_case_ :Optional[Any]						=			[param.detach().cpu().clone() for param in parameters]






					def    lowerCAmelCase_				(       self:							int						,     snake_case:							Iterable[torch.nn.Parameter]						)   ->	None:
											if self.temp_stored_params is None:
																	raise RuntimeError("""This ExponentialMovingAverage has no `store()`ed weights """ """to `restore()`"""						)
											for c_param, param in zip(self.temp_stored_params						,     snake_case						):
																	param.data.copy_(c_param.data						)

											# Better memory-wise.
											snake_case_ :Optional[int]						=			None






					def    lowerCAmelCase_				(       self:							Tuple						,     snake_case:							dict						)   ->	None:
											snake_case_ :Optional[Any]						=			copy.deepcopy(snake_case						)

											snake_case_ :Tuple						=			state_dict.get("""decay"""						,     self.decay						)
											if self.decay < 0.0 or self.decay > 1.0:
																	raise ValueError("""Decay must be between 0 and 1"""						)

											snake_case_ :Union[str, Any]						=			state_dict.get("""min_decay"""						,     self.min_decay						)
											if not isinstance(self.min_decay						,     snake_case						):
																	raise ValueError("""Invalid min_decay"""						)

											snake_case_ :List[str]						=			state_dict.get("""optimization_step"""						,     self.optimization_step						)
											if not isinstance(self.optimization_step						,     snake_case						):
																	raise ValueError("""Invalid optimization_step"""						)

											snake_case_ :Union[str, Any]						=			state_dict.get("""update_after_step"""						,     self.update_after_step						)
											if not isinstance(self.update_after_step						,     snake_case						):
																	raise ValueError("""Invalid update_after_step"""						)

											snake_case_ :str						=			state_dict.get("""use_ema_warmup"""						,     self.use_ema_warmup						)
											if not isinstance(self.use_ema_warmup						,     snake_case						):
																	raise ValueError("""Invalid use_ema_warmup"""						)

											snake_case_ :int						=			state_dict.get("""inv_gamma"""						,     self.inv_gamma						)
											if not isinstance(self.inv_gamma						,     (float, int)						):
																	raise ValueError("""Invalid inv_gamma"""						)

											snake_case_ :Union[str, Any]						=			state_dict.get("""power"""						,     self.power						)
											if not isinstance(self.power						,     (float, int)						):
																	raise ValueError("""Invalid power"""						)

											snake_case_ :Optional[int]						=			state_dict.get("""shadow_params"""						,     snake_case						)
											if shadow_params is not None:
																	snake_case_ :Tuple						=			shadow_params
																	if not isinstance(self.shadow_params						,     snake_case						):
																							raise ValueError("""shadow_params must be a list"""						)
																	if not all(isinstance(snake_case						,     torch.Tensor						) for p in self.shadow_params						):
																							raise ValueError("""shadow_params must all be Tensors"""						)




"""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 (							__snake_case				):






		'''simple docstring'''

		lowerCamelCase__				='new-model'


if is_tf_available():



			class 			_UpperCAmelCase (							__snake_case				):






					'''simple docstring'''

					lowerCamelCase__				=NewModelConfig



@require_tf
class 			_UpperCAmelCase (							unittest.TestCase				):






		'''simple docstring'''

		@slow
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						Optional[int]						=				'''bert-base-cased'''
			__snake_case	:						Dict						=				AutoConfig.from_pretrained(a_					)
			self.assertIsNotNone(a_					)
			self.assertIsInstance(a_				,       a_					)

			__snake_case	:						int						=				TFAutoModel.from_pretrained(a_					)
			self.assertIsNotNone(a_					)
			self.assertIsInstance(a_				,       a_					)



		@slow
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						Optional[int]						=				'''bert-base-cased'''
			__snake_case	:						Optional[Any]						=				AutoConfig.from_pretrained(a_					)
			self.assertIsNotNone(a_					)
			self.assertIsInstance(a_				,       a_					)

			__snake_case	:						List[Any]						=				TFAutoModelForPreTraining.from_pretrained(a_					)
			self.assertIsNotNone(a_					)
			self.assertIsInstance(a_				,       a_					)



		@slow
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
				__snake_case	:						int						=				AutoConfig.from_pretrained(a_					)
				self.assertIsNotNone(a_					)
				self.assertIsInstance(a_				,       a_					)

				__snake_case	:						Dict						=				TFAutoModelForCausalLM.from_pretrained(a_					)
				__snake_case	,							__snake_case	:						int						=				TFAutoModelForCausalLM.from_pretrained(a_				,       output_loading_info=a_					)
				self.assertIsNotNone(a_					)
				self.assertIsInstance(a_				,       a_					)



		@slow
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
				__snake_case	:						Tuple						=				AutoConfig.from_pretrained(a_					)
				self.assertIsNotNone(a_					)
				self.assertIsInstance(a_				,       a_					)

				__snake_case	:						Tuple						=				TFAutoModelWithLMHead.from_pretrained(a_					)
				self.assertIsNotNone(a_					)
				self.assertIsInstance(a_				,       a_					)



		@slow
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
				__snake_case	:						List[str]						=				AutoConfig.from_pretrained(a_					)
				self.assertIsNotNone(a_					)
				self.assertIsInstance(a_				,       a_					)

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



		@slow
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
				__snake_case	:						int						=				AutoConfig.from_pretrained(a_					)
				self.assertIsNotNone(a_					)
				self.assertIsInstance(a_				,       a_					)

				__snake_case	:						List[Any]						=				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 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			for model_name in ["bert-base-uncased"]:
				__snake_case	:						Any						=				AutoConfig.from_pretrained(a_					)
				self.assertIsNotNone(a_					)
				self.assertIsInstance(a_				,       a_					)

				__snake_case	:						Dict						=				TFAutoModelForSequenceClassification.from_pretrained(a_					)
				self.assertIsNotNone(a_					)
				self.assertIsInstance(a_				,       a_					)



		@slow
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			for model_name in ["bert-base-uncased"]:
				__snake_case	:						Optional[int]						=				AutoConfig.from_pretrained(a_					)
				self.assertIsNotNone(a_					)
				self.assertIsInstance(a_				,       a_					)

				__snake_case	:						Optional[Any]						=				TFAutoModelForQuestionAnswering.from_pretrained(a_					)
				self.assertIsNotNone(a_					)
				self.assertIsInstance(a_				,       a_					)



		@slow
		@require_tensorflow_probability
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			for model_name in TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST[5:6]:
				__snake_case	:						Dict						=				AutoConfig.from_pretrained(a_					)
				self.assertIsNotNone(a_					)
				self.assertIsInstance(a_				,       a_					)

				__snake_case	:						List[str]						=				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 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						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 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						Union[str, 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 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						Dict						=				TFAutoModel.from_pretrained('''sgugger/funnel-random-tiny'''					)
			self.assertIsInstance(a_				,       a_					)

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

			with tempfile.TemporaryDirectory() as tmp_dir:
				model.save_pretrained(a_					)
				__snake_case	:						Dict						=				TFAutoModel.from_pretrained(a_					)
				self.assertIsInstance(a_				,       a_					)



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			try:
				AutoConfig.register('''new-model'''				,       a_					)

				__snake_case	:						List[str]						=				[
				    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	:						str						=				NewModelConfig(**tiny_config.to_dict()					)
						__snake_case	:						Optional[int]						=				auto_class.from_config(a_					)
						self.assertIsInstance(a_				,       a_					)

						with tempfile.TemporaryDirectory() as tmp_dir:
							model.save_pretrained(a_					)
							__snake_case	:						Optional[int]						=				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 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			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 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			with self.assertRaisesRegex(
			    a_				,       R'''aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'''					):
				__snake_case	:						Dict						=				TFAutoModel.from_pretrained(a_				,       revision='''aaaaaa'''					)



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			with self.assertRaisesRegex(
			    a_				,       '''hf-internal-testing/config-no-model does not appear to have a file named pytorch_model.bin'''				,       ):
				__snake_case	:						Any						=				TFAutoModel.from_pretrained('''hf-internal-testing/config-no-model'''					)



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

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



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						Optional[Any]						=				TFAutoModel.from_pretrained('''hf-internal-testing/tiny-random-bert'''					)
			with RequestCounter() as counter:
				__snake_case	:						List[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
			__snake_case	:						Dict						=				TFAutoModel.from_pretrained('''ArthurZ/tiny-random-bert-sharded'''					)
			with RequestCounter() as counter:
				__snake_case	:						Dict						=				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					)





