






"""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_       (__A     ):
	__magic_name__	      =				'''new-model'''


if is_tf_available():







			class 			UpperCamelCase_       (__A     ):
				__magic_name__	      =				NewModelConfig







@require_tf
class 			UpperCamelCase_       (unittest.TestCase     ):





	@slow
	def      _SCREAMING_SNAKE_CASE      (      self					: Tuple						)						->			Tuple:
				UpperCAmelCase_     : Optional[int]			     =					"bert-base-cased"
				UpperCAmelCase_     : Dict			     =					AutoConfig.from_pretrained(lowerCAmelCase_						)
				self.assertIsNotNone(lowerCAmelCase_						)
				self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)

				UpperCAmelCase_     : Tuple			     =					TFAutoModel.from_pretrained(lowerCAmelCase_						)
				self.assertIsNotNone(lowerCAmelCase_						)
				self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)





	@slow
	def      _SCREAMING_SNAKE_CASE      (      self					: str						)						->			str:
				UpperCAmelCase_     : str			     =					"bert-base-cased"
				UpperCAmelCase_     : Any			     =					AutoConfig.from_pretrained(lowerCAmelCase_						)
				self.assertIsNotNone(lowerCAmelCase_						)
				self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)

				UpperCAmelCase_     : Dict			     =					TFAutoModelForPreTraining.from_pretrained(lowerCAmelCase_						)
				self.assertIsNotNone(lowerCAmelCase_						)
				self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)





	@slow
	def      _SCREAMING_SNAKE_CASE      (      self					: Union[str, Any]						)						->			List[Any]:
				for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							UpperCAmelCase_     : List[str]			     =					AutoConfig.from_pretrained(lowerCAmelCase_						)
							self.assertIsNotNone(lowerCAmelCase_						)
							self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)

							UpperCAmelCase_     : Optional[Any]			     =					TFAutoModelForCausalLM.from_pretrained(lowerCAmelCase_						)
							UpperCAmelCase_     ,	UpperCAmelCase_     : Dict			     =					TFAutoModelForCausalLM.from_pretrained(lowerCAmelCase_	,	output_loading_info=lowerCAmelCase_						)
							self.assertIsNotNone(lowerCAmelCase_						)
							self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)





	@slow
	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]						)						->			Tuple:
				for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							UpperCAmelCase_     : Any			     =					AutoConfig.from_pretrained(lowerCAmelCase_						)
							self.assertIsNotNone(lowerCAmelCase_						)
							self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)

							UpperCAmelCase_     : List[Any]			     =					TFAutoModelWithLMHead.from_pretrained(lowerCAmelCase_						)
							self.assertIsNotNone(lowerCAmelCase_						)
							self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)





	@slow
	def      _SCREAMING_SNAKE_CASE      (      self					: str						)						->			List[str]:
				for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							UpperCAmelCase_     : Optional[int]			     =					AutoConfig.from_pretrained(lowerCAmelCase_						)
							self.assertIsNotNone(lowerCAmelCase_						)
							self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)

							UpperCAmelCase_     : Optional[int]			     =					TFAutoModelForMaskedLM.from_pretrained(lowerCAmelCase_						)
							UpperCAmelCase_     ,	UpperCAmelCase_     : Optional[int]			     =					TFAutoModelForMaskedLM.from_pretrained(lowerCAmelCase_	,	output_loading_info=lowerCAmelCase_						)
							self.assertIsNotNone(lowerCAmelCase_						)
							self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)





	@slow
	def      _SCREAMING_SNAKE_CASE      (      self					: int						)						->			Dict:
				for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							UpperCAmelCase_     : int			     =					AutoConfig.from_pretrained(lowerCAmelCase_						)
							self.assertIsNotNone(lowerCAmelCase_						)
							self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)

							UpperCAmelCase_     : Any			     =					TFAutoModelForSeqaSeqLM.from_pretrained(lowerCAmelCase_						)
							UpperCAmelCase_     ,	UpperCAmelCase_     : List[Any]			     =					TFAutoModelForSeqaSeqLM.from_pretrained(lowerCAmelCase_	,	output_loading_info=lowerCAmelCase_						)
							self.assertIsNotNone(lowerCAmelCase_						)
							self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)





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

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





	@slow
	def      _SCREAMING_SNAKE_CASE      (      self					: str						)						->			List[str]:
				# for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
				for model_name in ["bert-base-uncased"]:
							UpperCAmelCase_     : int			     =					AutoConfig.from_pretrained(lowerCAmelCase_						)
							self.assertIsNotNone(lowerCAmelCase_						)
							self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)

							UpperCAmelCase_     : List[Any]			     =					TFAutoModelForQuestionAnswering.from_pretrained(lowerCAmelCase_						)
							self.assertIsNotNone(lowerCAmelCase_						)
							self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)





	@slow
	@require_tensorflow_probability
	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]						)						->			Dict:
				for model_name in TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST[5:6]:
							UpperCAmelCase_     : Dict			     =					AutoConfig.from_pretrained(lowerCAmelCase_						)
							self.assertIsNotNone(lowerCAmelCase_						)
							self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)

							UpperCAmelCase_     : int			     =					TFAutoModelForTableQuestionAnswering.from_pretrained(lowerCAmelCase_						)
							UpperCAmelCase_     ,	UpperCAmelCase_     : List[Any]			     =					TFAutoModelForTableQuestionAnswering.from_pretrained(
							    lowerCAmelCase_	,	output_loading_info=lowerCAmelCase_						)
							self.assertIsNotNone(lowerCAmelCase_						)
							self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: str						)						->			Tuple:
				UpperCAmelCase_     : str			     =					TFAutoModelWithLMHead.from_pretrained(lowerCAmelCase_						)
				self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)
				self.assertEqual(model.num_parameters()	,	14_410						)
				self.assertEqual(model.num_parameters(only_trainable=lowerCAmelCase_						)	,	14_410						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Tuple						)						->			int:
				UpperCAmelCase_     : str			     =					TFAutoModelWithLMHead.from_pretrained(lowerCAmelCase_						)
				self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)
				self.assertEqual(model.num_parameters()	,	14_410						)
				self.assertEqual(model.num_parameters(only_trainable=lowerCAmelCase_						)	,	14_410						)





	def      _SCREAMING_SNAKE_CASE      (      self					: List[Any]						)						->			Tuple:
				# For the auto model mapping, FunnelConfig has two models: FunnelModel and FunnelBaseModel
				UpperCAmelCase_     : Union[str, Any]			     =					TFAutoModel.from_pretrained("sgugger/funnel-random-tiny"						)
				self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)

				UpperCAmelCase_     : Any			     =					copy.deepcopy(model.config						)
				UpperCAmelCase_     : Dict			     =					["FunnelBaseModel"]
				UpperCAmelCase_     : Union[str, Any]			     =					TFAutoModel.from_config(lowerCAmelCase_						)
				self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)

				with tempfile.TemporaryDirectory() as tmp_dir:
							model.save_pretrained(lowerCAmelCase_						)
							UpperCAmelCase_     : Any			     =					TFAutoModel.from_pretrained(lowerCAmelCase_						)
							self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: List[Any]						)						->			Any:
				try:
							AutoConfig.register("new-model"	,	lowerCAmelCase_						)

							UpperCAmelCase_     : Union[str, Any]			     =					[
							    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(lowerCAmelCase_						):
																auto_class.register(lowerCAmelCase_	,	lowerCAmelCase_						)
													auto_class.register(lowerCAmelCase_	,	lowerCAmelCase_						)
													# Trying to register something existing in the Transformers library will raise an error
													with self.assertRaises(lowerCAmelCase_						):
																auto_class.register(lowerCAmelCase_	,	lowerCAmelCase_						)

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

													with tempfile.TemporaryDirectory() as tmp_dir:
																model.save_pretrained(lowerCAmelCase_						)
																UpperCAmelCase_     : Dict			     =					auto_class.from_pretrained(lowerCAmelCase_						)
																self.assertIsInstance(lowerCAmelCase_	,	lowerCAmelCase_						)

				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					: str						)						->			Optional[int]:
				with self.assertRaisesRegex(
				    lowerCAmelCase_	,	"bert-base is not a local folder and is not a valid model identifier"						):
							UpperCAmelCase_     : str			     =					TFAutoModel.from_pretrained("bert-base"						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[Any]						)						->			List[Any]:
				with self.assertRaisesRegex(
				    lowerCAmelCase_	,	R"aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"						):
							UpperCAmelCase_     : Union[str, Any]			     =					TFAutoModel.from_pretrained(lowerCAmelCase_	,	revision="aaaaaa"						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]						)						->			Union[str, Any]:
				with self.assertRaisesRegex(
				    lowerCAmelCase_	,	"hf-internal-testing/config-no-model does not appear to have a file named pytorch_model.bin"	,	):
							UpperCAmelCase_     : List[Any]			     =					TFAutoModel.from_pretrained("hf-internal-testing/config-no-model"						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Dict						)						->			List[Any]:
				with self.assertRaisesRegex(lowerCAmelCase_	,	"Use `from_pt=True` to load this model"						):
							UpperCAmelCase_     : Union[str, Any]			     =					TFAutoModel.from_pretrained("hf-internal-testing/tiny-bert-pt-only"						)





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

import inspect
import unittest
from typing import List, Tuple

from transformers import RegNetConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
			import tensorflow as tf

			from transformers import TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST, TFRegNetForImageClassification, TFRegNetModel


if is_vision_available():
			from PIL import Image

			from transformers import AutoImageProcessor







class 			UpperCamelCase_       :





	def __init__(      self					: Optional[Any]	,	lowerCAmelCase_					: Optional[Any]	,	lowerCAmelCase_					: Optional[int]=3	,	lowerCAmelCase_					: Optional[int]=32	,	lowerCAmelCase_					: List[Any]=3	,	lowerCAmelCase_					: List[Any]=10	,	lowerCAmelCase_					: Any=[10, 20, 30, 40]	,	lowerCAmelCase_					: Any=[1, 1, 2, 1]	,	lowerCAmelCase_					: Union[str, Any]=True	,	lowerCAmelCase_					: Union[str, Any]=True	,	lowerCAmelCase_					: int="relu"	,	lowerCAmelCase_					: Tuple=3	,	lowerCAmelCase_					: Optional[int]=None	,	)						->			str:
				UpperCAmelCase_     : Tuple			     =					parent
				UpperCAmelCase_     : int			     =					batch_size
				UpperCAmelCase_     : str			     =					image_size
				UpperCAmelCase_     : List[Any]			     =					num_channels
				UpperCAmelCase_     : Tuple			     =					embeddings_size
				UpperCAmelCase_     : Union[str, Any]			     =					hidden_sizes
				UpperCAmelCase_     : int			     =					depths
				UpperCAmelCase_     : Optional[Any]			     =					is_training
				UpperCAmelCase_     : Dict			     =					use_labels
				UpperCAmelCase_     : str			     =					hidden_act
				UpperCAmelCase_     : str			     =					num_labels
				UpperCAmelCase_     : str			     =					scope
				UpperCAmelCase_     : str			     =					len(lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Tuple						)						->			Dict:
				UpperCAmelCase_     : Any			     =					floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

				UpperCAmelCase_     : Union[str, Any]			     =					None
				if self.use_labels:
							UpperCAmelCase_     : List[str]			     =					ids_tensor([self.batch_size]	,	self.num_labels						)

				UpperCAmelCase_     : Optional[Any]			     =					self.get_config()
				return config, pixel_values, labels





	def      _SCREAMING_SNAKE_CASE      (      self					: List[str]						)						->			Union[str, Any]:
				return RegNetConfig(
				    num_channels=self.num_channels	,	embeddings_size=self.embeddings_size	,	hidden_sizes=self.hidden_sizes	,	depths=self.depths	,	hidden_act=self.hidden_act	,	num_labels=self.num_labels	,	)





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]	,	lowerCAmelCase_					: Union[str, Any]	,	lowerCAmelCase_					: str	,	lowerCAmelCase_					: Dict						)						->			str:
				UpperCAmelCase_     : List[Any]			     =					TFRegNetModel(config=lowerCAmelCase_						)
				UpperCAmelCase_     : List[Any]			     =					model(lowerCAmelCase_	,	training=lowerCAmelCase_						)
				# expected last hidden states: B, C, H // 32, W // 32
				self.parent.assertEqual(
				    result.last_hidden_state.shape	,	(self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)	,	)





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]	,	lowerCAmelCase_					: Tuple	,	lowerCAmelCase_					: Tuple	,	lowerCAmelCase_					: List[Any]						)						->			Optional[Any]:
				UpperCAmelCase_     : Union[str, Any]			     =					self.num_labels
				UpperCAmelCase_     : List[Any]			     =					TFRegNetForImageClassification(lowerCAmelCase_						)
				UpperCAmelCase_     : Optional[int]			     =					model(lowerCAmelCase_	,	labels=lowerCAmelCase_	,	training=lowerCAmelCase_						)
				self.parent.assertEqual(result.logits.shape	,	(self.batch_size, self.num_labels)						)





	def      _SCREAMING_SNAKE_CASE      (      self					: List[Any]						)						->			Dict:
				UpperCAmelCase_     : Any			     =					self.prepare_config_and_inputs()
				UpperCAmelCase_     ,	UpperCAmelCase_     ,	UpperCAmelCase_     : Dict			     =					config_and_inputs
				UpperCAmelCase_     : List[str]			     =					{"pixel_values": pixel_values}
				return config, inputs_dict







@require_tf
class 			UpperCamelCase_       (__A				,						__A				,						unittest.TestCase     ):
	__magic_name__	      =				(TFRegNetModel, TFRegNetForImageClassification) if is_tf_available() else ()
	__magic_name__	      =				(
	    {'''feature-extraction''': TFRegNetModel, '''image-classification''': TFRegNetForImageClassification}
	    if is_tf_available()
	    else {}
	)

	__magic_name__	      =				False
	__magic_name__	      =				False
	__magic_name__	      =				False
	__magic_name__	      =				False
	__magic_name__	      =				False





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]						)						->			Union[str, Any]:
				UpperCAmelCase_     : Optional[int]			     =					TFRegNetModelTester(self						)
				UpperCAmelCase_     : Optional[Any]			     =					ConfigTester(self	,	config_class=lowerCAmelCase_	,	has_text_modality=lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: List[str]						)						->			Optional[int]:
				return





	@unittest.skip(reason="RegNet does not use inputs_embeds"						)
	def      _SCREAMING_SNAKE_CASE      (      self					: List[str]						)						->			Union[str, Any]:
				pass





	@unittest.skipIf(
	    not is_tf_available() or len(tf.config.list_physical_devices("GPU"						)						) == 0	,	reason="TF does not support backprop for grouped convolutions on CPU."	,	)
	@slow
	def      _SCREAMING_SNAKE_CASE      (      self					: List[str]						)						->			Dict:
				super().test_keras_fit()





	@unittest.skip(reason="RegNet does not support input and output embeddings"						)
	def      _SCREAMING_SNAKE_CASE      (      self					: List[str]						)						->			Any:
				pass





	def      _SCREAMING_SNAKE_CASE      (      self					: int						)						->			List[str]:
				UpperCAmelCase_     ,	UpperCAmelCase_     : Tuple			     =					self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
							UpperCAmelCase_     : Dict			     =					model_class(lowerCAmelCase_						)
							UpperCAmelCase_     : Tuple			     =					inspect.signature(model.call						)
							# signature.parameters is an OrderedDict => so arg_names order is deterministic
							UpperCAmelCase_     : List[Any]			     =					[*signature.parameters.keys()]

							UpperCAmelCase_     : int			     =					["pixel_values"]
							self.assertListEqual(arg_names[:1]	,	lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Union[str, Any]						)						->			Union[str, Any]:
				UpperCAmelCase_     : List[Any]			     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[Any]						)						->			Optional[int]:
				def check_hidden_states_output(lowerCAmelCase_					: Optional[int]	,	lowerCAmelCase_					: Dict	,	lowerCAmelCase_					: int						):
							UpperCAmelCase_     : str			     =					model_class(lowerCAmelCase_						)
							UpperCAmelCase_     : Any			     =					model(**self._prepare_for_class(lowerCAmelCase_	,	lowerCAmelCase_						)	,	training=lowerCAmelCase_						)

							UpperCAmelCase_     : str			     =					outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

							UpperCAmelCase_     : Optional[Any]			     =					self.model_tester.num_stages
							self.assertEqual(len(lowerCAmelCase_						)	,	expected_num_stages + 1						)

							# RegNet's feature maps are of shape (batch_size, num_channels, height, width)
							self.assertListEqual(
							    list(hidden_states[0].shape[-2:]						)	,	[self.model_tester.image_size // 2, self.model_tester.image_size // 2]	,	)

				UpperCAmelCase_     ,	UpperCAmelCase_     : List[str]			     =					self.model_tester.prepare_config_and_inputs_for_common()
				UpperCAmelCase_     : Tuple			     =					["basic", "bottleneck"]
				for model_class in self.all_model_classes:
							for layer_type in layers_type:
										UpperCAmelCase_     : List[Any]			     =					layer_type
										UpperCAmelCase_     : int			     =					True
										check_hidden_states_output(lowerCAmelCase_	,	lowerCAmelCase_	,	lowerCAmelCase_						)

										# check that output_hidden_states also work using config
										del inputs_dict["output_hidden_states"]
										UpperCAmelCase_     : Optional[int]			     =					True

										check_hidden_states_output(lowerCAmelCase_	,	lowerCAmelCase_	,	lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Union[str, Any]						)						->			Any:
				UpperCAmelCase_     ,	UpperCAmelCase_     : Any			     =					self.model_tester.prepare_config_and_inputs_for_common()

				def check_equivalence(lowerCAmelCase_					: Optional[Any]	,	lowerCAmelCase_					: Tuple	,	lowerCAmelCase_					: Optional[Any]	,	lowerCAmelCase_					: List[str]={}						):
							UpperCAmelCase_     : Tuple			     =					model(lowerCAmelCase_	,	return_dict=lowerCAmelCase_	,	**lowerCAmelCase_						)
							UpperCAmelCase_     : Optional[Any]			     =					model(lowerCAmelCase_	,	return_dict=lowerCAmelCase_	,	**lowerCAmelCase_						).to_tuple()

							def recursive_check(lowerCAmelCase_					: List[Any]	,	lowerCAmelCase_					: Any						):
										if isinstance(lowerCAmelCase_	,	(List, Tuple)						):
													for tuple_iterable_value, dict_iterable_value in zip(lowerCAmelCase_	,	lowerCAmelCase_						):
																recursive_check(lowerCAmelCase_	,	lowerCAmelCase_						)
										elif tuple_object is None:
													return
										else:
													self.assertTrue(
													    all(tf.equal(lowerCAmelCase_	,	lowerCAmelCase_						)						)	,	msg=(
													        "Tuple and dict output are not equal. Difference:"
													        f""" {tf.math.reduce_max(tf.abs(tuple_object - dict_object						)						)}"""
													    )	,	)

										recursive_check(lowerCAmelCase_	,	lowerCAmelCase_						)

				for model_class in self.all_model_classes:
							UpperCAmelCase_     : Union[str, Any]			     =					model_class(lowerCAmelCase_						)

							UpperCAmelCase_     : List[Any]			     =					self._prepare_for_class(lowerCAmelCase_	,	lowerCAmelCase_						)
							UpperCAmelCase_     : str			     =					self._prepare_for_class(lowerCAmelCase_	,	lowerCAmelCase_						)
							check_equivalence(lowerCAmelCase_	,	lowerCAmelCase_	,	lowerCAmelCase_						)

							UpperCAmelCase_     : Any			     =					self._prepare_for_class(lowerCAmelCase_	,	lowerCAmelCase_	,	return_labels=lowerCAmelCase_						)
							UpperCAmelCase_     : List[Any]			     =					self._prepare_for_class(lowerCAmelCase_	,	lowerCAmelCase_	,	return_labels=lowerCAmelCase_						)
							check_equivalence(lowerCAmelCase_	,	lowerCAmelCase_	,	lowerCAmelCase_						)

							UpperCAmelCase_     : Union[str, Any]			     =					self._prepare_for_class(lowerCAmelCase_	,	lowerCAmelCase_						)
							UpperCAmelCase_     : str			     =					self._prepare_for_class(lowerCAmelCase_	,	lowerCAmelCase_						)
							check_equivalence(lowerCAmelCase_	,	lowerCAmelCase_	,	lowerCAmelCase_	,	{"output_hidden_states": True}						)

							UpperCAmelCase_     : List[str]			     =					self._prepare_for_class(lowerCAmelCase_	,	lowerCAmelCase_	,	return_labels=lowerCAmelCase_						)
							UpperCAmelCase_     : Tuple			     =					self._prepare_for_class(lowerCAmelCase_	,	lowerCAmelCase_	,	return_labels=lowerCAmelCase_						)
							check_equivalence(lowerCAmelCase_	,	lowerCAmelCase_	,	lowerCAmelCase_	,	{"output_hidden_states": True}						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Union[str, Any]						)						->			str:
				UpperCAmelCase_     : List[str]			     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_image_classification(*lowerCAmelCase_						)





	@slow
	def      _SCREAMING_SNAKE_CASE      (      self					: str						)						->			Union[str, Any]:
				for model_name in TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							UpperCAmelCase_     : Any			     =					TFRegNetModel.from_pretrained(lowerCAmelCase_						)
							self.assertIsNotNone(lowerCAmelCase_						)





def 				snake_case      (   ):
			UpperCAmelCase_     : Dict			     =					Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"						)
			return image







@require_tf
@require_vision
class 			UpperCamelCase_       (unittest.TestCase     ):





	@cached_property
	def      _SCREAMING_SNAKE_CASE      (      self					: List[Any]						)						->			List[Any]:
				return (
				    AutoImageProcessor.from_pretrained(TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]						)
				    if is_vision_available()
				    else None
				)





	@slow
	def      _SCREAMING_SNAKE_CASE      (      self					: Tuple						)						->			Dict:
				UpperCAmelCase_     : Any			     =					TFRegNetForImageClassification.from_pretrained(TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]						)

				UpperCAmelCase_     : Union[str, Any]			     =					self.default_image_processor
				UpperCAmelCase_     : int			     =					prepare_img()
				UpperCAmelCase_     : List[Any]			     =					image_processor(images=lowerCAmelCase_	,	return_tensors="tf"						)

				# forward pass
				UpperCAmelCase_     : Tuple			     =					model(**lowerCAmelCase_	,	training=lowerCAmelCase_						)

				# verify the logits
				UpperCAmelCase_     : List[str]			     =					tf.TensorShape((1, 1_000)						)
				self.assertEqual(outputs.logits.shape	,	lowerCAmelCase_						)

				UpperCAmelCase_     : Optional[Any]			     =					tf.constant([-0.4_1_8_0, -1.5_0_5_1, -3.4_8_3_6]						)

				tf.debugging.assert_near(outputs.logits[0, :3]	,	lowerCAmelCase_	,	atol=1e-4						)



