


import copy
import tempfile
import unittest

from transformers import MaMaaaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device
from transformers.utils import cached_property

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import MaMaaaForConditionalGeneration, MaMaaaModel, MaMaaaTokenizer
			from transformers.models.mam_aaa.modeling_mam_aaa import MaMaaaDecoder, MaMaaaEncoder







def 				lowerCAmelCase_     (					__lowerCamelCase							,	__lowerCamelCase							,	__lowerCamelCase							,	__lowerCamelCase=None							,	__lowerCamelCase=None							,	__lowerCamelCase=None							,	__lowerCamelCase=None							,	__lowerCamelCase=None							,	):





							if attention_mask is None:
														__snake_case		:			List[Any]							 =   input_ids.ne(config.pad_token_id	)
							if decoder_attention_mask is None:
														__snake_case		:			Union[str, Any]							 =   decoder_input_ids.ne(config.pad_token_id	)
							if head_mask is None:
														__snake_case		:			List[Any]							 =   torch.ones(config.encoder_layers							,	config.encoder_attention_heads							,	device=_lowerCamelCase	)
							if decoder_head_mask is None:
														__snake_case		:			List[str]							 =   torch.ones(config.decoder_layers							,	config.decoder_attention_heads							,	device=_lowerCamelCase	)
							if cross_attn_head_mask is None:
														__snake_case		:			Dict							 =   torch.ones(config.decoder_layers							,	config.decoder_attention_heads							,	device=_lowerCamelCase	)
							return {
							    "input_ids": input_ids,
							    "decoder_input_ids": decoder_input_ids,
							    "attention_mask": attention_mask,
							    "decoder_attention_mask": attention_mask,
							    "head_mask": head_mask,
							    "decoder_head_mask": decoder_head_mask,
							    "cross_attn_head_mask": cross_attn_head_mask,
							}

class 				a		:




							"""simple docstring"""


							def __init__(							self       :  Optional[int]    ,	lowerCamelCase       :  Tuple    ,	lowerCamelCase       :  Optional[int]=13    ,	lowerCamelCase       :  Union[str, Any]=7    ,	lowerCamelCase       :  List[str]=True    ,	lowerCamelCase       :  Dict=False    ,	lowerCamelCase       :  str=99    ,	lowerCamelCase       :  Optional[Any]=16    ,	lowerCamelCase       :  Union[str, Any]=2    ,	lowerCamelCase       :  int=4    ,	lowerCamelCase       :  Dict=4    ,	lowerCamelCase       :  Tuple="relu"    ,	lowerCamelCase       :  Optional[Any]=0.1    ,	lowerCamelCase       :  List[str]=0.1    ,	lowerCamelCase       :  Union[str, Any]=0.0    ,	lowerCamelCase       :  Optional[int]=0.0    ,	lowerCamelCase       :  Any=20    ,	lowerCamelCase       :  int=2    ,	lowerCamelCase       :  Union[str, Any]=1    ,	lowerCamelCase       :  List[Any]=0    ,	)	->    Dict:
														__snake_case		:			List[str]							 =   parent
														__snake_case		:			Union[str, Any]							 =   batch_size
														__snake_case		:			List[Any]							 =   seq_length
														__snake_case		:			int							 =   is_training
														__snake_case		:			int							 =   use_labels
														__snake_case		:			Any							 =   vocab_size
														__snake_case		:			Any							 =   hidden_size
														__snake_case		:			Optional[int]							 =   num_hidden_layers
														__snake_case		:			Tuple							 =   num_attention_heads
														__snake_case		:			List[str]							 =   intermediate_size
														__snake_case		:			Any							 =   hidden_act
														__snake_case		:			Tuple							 =   hidden_dropout_prob
														__snake_case		:			str							 =   attention_probs_dropout_prob
														__snake_case		:			Tuple							 =   encoder_layerdrop
														__snake_case		:			List[str]							 =   decoder_layerdrop
														__snake_case		:			List[Any]							 =   max_position_embeddings
														__snake_case		:			List[Any]							 =   eos_token_id
														__snake_case		:			Optional[int]							 =   pad_token_id
														__snake_case		:			Union[str, Any]							 =   bos_token_id

							def     __snake_case					(							self       :  str				)	->    Optional[int]:
														__snake_case		:			Optional[Any]							 =   ids_tensor([self.batch_size, self.seq_length]    ,	self.vocab_size				)
														__snake_case		:			List[Any]							 =   self.eos_token_id  # Eos Token
														__snake_case		:			int							 =   ids_tensor([self.batch_size, self.seq_length]    ,	self.vocab_size				)

														# we need to clamp the input ids here to avoid having pad token in between
														# this is because for M2M100 the position_ids are prepared such that
														# all pad tokens have pos id = 2 and rest are between 2..seq_length
														# and the seq_length here is seq_length - num_pad_tokens
														# but when using past, there is no way of knowing if the past input ids had
														# pad tokens in them, which results in incorrect seq_lenth and which in turn results in
														# position_ids being off by num_pad_tokens in past input
														__snake_case		:			int							 =   input_ids.clamp(self.pad_token_id + 1				)
														__snake_case		:			int							 =   decoder_input_ids.clamp(self.pad_token_id + 1				)

														__snake_case		:			List[Any]							 =   self.get_config()
														__snake_case		:			int							 =   prepare_mam_aaa_inputs_dict(lowerCamelCase    ,	lowerCamelCase    ,	lowerCamelCase				)
														return config, inputs_dict

							def     __snake_case					(							self       :  Tuple				)	->    int:
														return MaMaaaConfig(
														    vocab_size=self.vocab_size    ,	d_model=self.hidden_size    ,	encoder_layers=self.num_hidden_layers    ,	decoder_layers=self.num_hidden_layers    ,	encoder_attention_heads=self.num_attention_heads    ,	decoder_attention_heads=self.num_attention_heads    ,	encoder_ffn_dim=self.intermediate_size    ,	decoder_ffn_dim=self.intermediate_size    ,	dropout=self.hidden_dropout_prob    ,	attention_dropout=self.attention_probs_dropout_prob    ,	encoder_layerdrop=self.encoder_layerdrop    ,	decoder_layerdrop=self.decoder_layerdrop    ,	max_position_embeddings=self.max_position_embeddings    ,	eos_token_id=self.eos_token_id    ,	bos_token_id=self.bos_token_id    ,	pad_token_id=self.pad_token_id    ,	)

							def     __snake_case					(							self       :  List[str]				)	->    str:
														__snake_case		:			int							 =   self.prepare_config_and_inputs()
														return config, inputs_dict

							def     __snake_case					(							self       :  Union[str, Any]    ,	lowerCamelCase       :  Optional[int]    ,	lowerCamelCase       :  Tuple				)	->    Dict:
														__snake_case		:			List[str]							 =   MaMaaaModel(config=lowerCamelCase				).get_decoder().to(lowerCamelCase				).eval()
														__snake_case		:			List[str]							 =   inputs_dict["input_ids"]
														__snake_case		:			int							 =   inputs_dict["attention_mask"]
														__snake_case		:			str							 =   inputs_dict["head_mask"]

														# first forward pass
														__snake_case		:			Union[str, Any]							 =   model(lowerCamelCase    ,	attention_mask=lowerCamelCase    ,	head_mask=lowerCamelCase    ,	use_cache=lowerCamelCase				)

														__snake_case		:			Tuple							 =   outputs.to_tuple()

														# create hypothetical multiple next token and extent to next_input_ids
														__snake_case		:			List[str]							 =   ids_tensor((self.batch_size, 3)    ,	config.vocab_size				)
														__snake_case		:			Union[str, Any]							 =   ids_tensor((self.batch_size, 3)    ,	2				)

														# append to next input_ids and
														__snake_case		:			Tuple							 =   torch.cat([input_ids, next_tokens]    ,	dim=-1				)
														__snake_case		:			List[Any]							 =   torch.cat([attention_mask, next_attn_mask]    ,	dim=-1				)

														__snake_case		:			str							 =   model(lowerCamelCase    ,	attention_mask=lowerCamelCase				)["last_hidden_state"]
														__snake_case		:			List[Any]							 =   model(lowerCamelCase    ,	attention_mask=lowerCamelCase    ,	past_key_values=lowerCamelCase				)[
														    "last_hidden_state"
														]

														# select random slice
														__snake_case		:			Optional[Any]							 =   ids_tensor((1,)    ,	output_from_past.shape[-1]				).item()
														__snake_case		:			Dict							 =   output_from_no_past[:, -3:, random_slice_idx].detach()
														__snake_case		:			Optional[int]							 =   output_from_past[:, :, random_slice_idx].detach()

														self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]				)

														# test that outputs are equal for slice
														self.parent.assertTrue(torch.allclose(lowerCamelCase    ,	lowerCamelCase    ,	atol=1E-2				)				)






							def     __snake_case					(							self       :  Optional[Any]    ,	lowerCamelCase       :  int    ,	lowerCamelCase       :  int				)	->    str:
														__snake_case		:			Tuple							 =   MaMaaaModel(config=lowerCamelCase				).to(lowerCamelCase				).eval()
														__snake_case		:			int							 =   model(**lowerCamelCase				)

														__snake_case		:			Tuple							 =   outputs.encoder_last_hidden_state
														__snake_case		:			str							 =   outputs.last_hidden_state

														with tempfile.TemporaryDirectory() as tmpdirname:
																					__snake_case		:			Union[str, Any]							 =   model.get_encoder()
																					encoder.save_pretrained(lowerCamelCase				)
																					__snake_case		:			int							 =   MaMaaaEncoder.from_pretrained(lowerCamelCase				).to(lowerCamelCase				)

														__snake_case		:			Optional[Any]							 =   encoder(inputs_dict["input_ids"]    ,	attention_mask=inputs_dict["attention_mask"]				)[
														    0
														]

														self.parent.assertTrue((encoder_last_hidden_state_a - encoder_last_hidden_state).abs().max().item() < 1E-3				)

														with tempfile.TemporaryDirectory() as tmpdirname:
																					__snake_case		:			List[Any]							 =   model.get_decoder()
																					decoder.save_pretrained(lowerCamelCase				)
																					__snake_case		:			List[Any]							 =   MaMaaaDecoder.from_pretrained(lowerCamelCase				).to(lowerCamelCase				)

														__snake_case		:			Union[str, Any]							 =   decoder(
														    input_ids=inputs_dict["decoder_input_ids"]    ,	attention_mask=inputs_dict["decoder_attention_mask"]    ,	encoder_hidden_states=lowerCamelCase    ,	encoder_attention_mask=inputs_dict["attention_mask"]    ,	)[0]

														self.parent.assertTrue((last_hidden_state_a - last_hidden_state).abs().max().item() < 1E-3				)

@require_torch
class 				a		(__lowercase     ,				__lowercase     ,				__lowercase     ,				unittest.TestCase      ):




							"""simple docstring"""


							__UpperCAmelCase    :							List[Any]       =  (
							    (
							        MaMaaaModel,
							        MaMaaaForConditionalGeneration,
							    )
							    if is_torch_available()
							    else ()
							)
							__UpperCAmelCase    :							Optional[int]       =  (MaMaaaForConditionalGeneration,) if is_torch_available() else ()
							__UpperCAmelCase    :							List[Any]       =  (
							    {
							        "conversational": MaMaaaForConditionalGeneration,
							        "feature-extraction": MaMaaaModel,
							        "summarization": MaMaaaForConditionalGeneration,
							        "text2text-generation": MaMaaaForConditionalGeneration,
							        "translation": MaMaaaForConditionalGeneration,
							    }
							    if is_torch_available()
							    else {}
							)
							__UpperCAmelCase    :							Optional[int]       =  True
							__UpperCAmelCase    :							Dict       =  True
							__UpperCAmelCase    :							Dict       =  False
							__UpperCAmelCase    :							List[Any]       =  False

							def     __snake_case					(							self       :  Optional[int]    ,	lowerCamelCase       :  List[str]    ,	lowerCamelCase       :  Tuple    ,	lowerCamelCase       :  Optional[int]    ,	lowerCamelCase       :  Union[str, Any]    ,	lowerCamelCase       :  Any				)	->    List[Any]:
														if pipeline_test_casse_name == "TranslationPipelineTests":
																					# Get `ValueError: Translation requires a `src_lang` and a `tgt_lang` for this model`.
																					# `M2M100Config` was never used in pipeline tests: cannot create a simple tokenizer.
																					return True

														return False

							def     __snake_case					(							self       :  Optional[int]				)	->    int:
														__snake_case		:			str							 =   MaMaaaModelTester(self				)
														__snake_case		:			Dict							 =   ConfigTester(self    ,	config_class=lowerCamelCase				)

							def     __snake_case					(							self       :  List[str]				)	->    Union[str, Any]:
														self.config_tester.run_common_tests()

							def     __snake_case					(							self       :  Any				)	->    str:
														__snake_case		:			Dict							 =   self.model_tester.prepare_config_and_inputs()
														for model_class in self.all_model_classes:
																					__snake_case		:			Optional[Any]							 =   model_class(lowerCamelCase				)

																					with tempfile.TemporaryDirectory() as tmpdirname:
																												model.save_pretrained(lowerCamelCase				)
																												__snake_case		:			int							 =   model_class.from_pretrained(lowerCamelCase    ,	output_loading_info=lowerCamelCase				)
																					self.assertEqual(info["missing_keys"]    ,	[]				)

							def     __snake_case					(							self       :  List[str]				)	->    Dict:
														__snake_case		:			Optional[Any]							 =   self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_decoder_model_past_large_inputs(*lowerCamelCase				)

							def     __snake_case					(							self       :  str				)	->    List[str]:
														__snake_case		:			Optional[Any]							 =   self.model_tester.prepare_config_and_inputs_for_common()
														self.model_tester.check_encoder_decoder_model_standalone(*lowerCamelCase				)

							def     __snake_case					(							self       :  Any				)	->    List[Any]:
														__snake_case		:			List[Any]							 =   self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in (MaMaaaModel, MaMaaaForConditionalGeneration):
																					__snake_case		:			Dict							 =   model_class(lowerCamelCase				)
																					model.to(lowerCamelCase				)
																					model.eval()

																					__snake_case		:			Union[str, Any]							 =   copy.deepcopy(self._prepare_for_class(lowerCamelCase    ,	lowerCamelCase				)				)

																					if not self.is_encoder_decoder:
																												__snake_case		:			Tuple							 =   inputs["input_ids"]
																												del inputs["input_ids"]
																					else:
																												__snake_case		:			Dict							 =   inputs["input_ids"]
																												__snake_case		:			Tuple							 =   inputs.get("decoder_input_ids"    ,	lowerCamelCase				)
																												del inputs["input_ids"]
																												inputs.pop("decoder_input_ids"    ,	lowerCamelCase				)

																					__snake_case		:			Optional[int]							 =   model.get_input_embeddings()
																					if not self.is_encoder_decoder:
																												__snake_case		:			Tuple							 =   wte(lowerCamelCase				)
																					else:
																												__snake_case		:			List[str]							 =   wte(lowerCamelCase				)
																												__snake_case		:			Optional[int]							 =   wte(lowerCamelCase				)

																					with torch.no_grad():
																												model(**lowerCamelCase				)[0]






							def     __snake_case					(							self       :  List[Any]				)	->    int:
														__snake_case		:			str							 =   self.model_tester.prepare_config_and_inputs()
														__snake_case		:			Dict							 =   input_dict["input_ids"]
														__snake_case		:			Optional[Any]							 =   input_ids.ne(1				).to(lowerCamelCase				)
														__snake_case		:			List[str]							 =   MaMaaaForConditionalGeneration(lowerCamelCase				).eval().to(lowerCamelCase				)
														if torch_device == "cuda":
																					model.half()
														model.generate(lowerCamelCase    ,	attention_mask=lowerCamelCase				)
														model.generate(num_beams=4    ,	do_sample=lowerCamelCase    ,	early_stopping=lowerCamelCase    ,	num_return_sequences=3				)







def 				lowerCAmelCase_     (					__lowerCamelCase	):
							return torch.tensor(_lowerCamelCase							,	dtype=torch.long							,	device=_lowerCamelCase	)


_snake_case     :		str						=				1E-4

@require_torch
@require_sentencepiece
@require_tokenizers
@slow
class 				a		(unittest.TestCase      ):




							"""simple docstring"""


							@cached_property
							def     __snake_case					(							self       :  List[str]				)	->    Optional[Any]:
														return MaMaaaTokenizer.from_pretrained("facebook/m2m100_418M"				)

							def     __snake_case					(							self       :  Any				)	->    str:
														__snake_case		:			List[str]							 =   MaMaaaModel.from_pretrained("facebook/m2m100_418M"				).to(lowerCamelCase				)
														__snake_case		:			List[Any]							 =   _long_tensor([[128028, 98, 12, 30527, 2732, 159, 7755, 61904, 39144, 38, 2]]				)
														__snake_case		:			Any							 =   _long_tensor([[2, 128028, 98, 12, 30527, 2732, 159, 7755, 61904, 39144, 38]]				)
														__snake_case		:			Any							 =   prepare_mam_aaa_inputs_dict(model.config    ,	lowerCamelCase    ,	lowerCamelCase				)
														with torch.no_grad():
																					__snake_case		:			Tuple							 =   model(**lowerCamelCase				)[0]
														__snake_case		:			int							 =   torch.Size((1, 11, 1024)				)
														self.assertEqual(output.shape    ,	lowerCamelCase				)
														# change to expected output here
														__snake_case		:			Union[str, Any]							 =   torch.tensor(
														    [[-0.77_80, -0.16_76, 0.10_38], [-6.75_56, -1.39_92, 0.05_67], [-7.53_83, -0.59_20, -0.27_79]]    ,	device=lowerCamelCase				)
														self.assertTrue(torch.allclose(output[:, :3, :3]    ,	lowerCamelCase    ,	atol=lowerCamelCase				)				)

							def     __snake_case					(							self       :  List[Any]				)	->    Tuple:
														__snake_case		:			Any							 =   MaMaaaForConditionalGeneration.from_pretrained("facebook/m2m100_418M"				).to(lowerCamelCase				)

														# change to intended input
														__snake_case		:			str							 =   _long_tensor([[128028, 98, 12, 30527, 2732, 159, 7755, 61904, 39144, 38, 2]]				)
														__snake_case		:			Any							 =   _long_tensor([[2, 128028, 98, 12, 30527, 2732, 159, 7755, 61904, 39144, 38]]				)
														__snake_case		:			str							 =   prepare_mam_aaa_inputs_dict(model.config    ,	lowerCamelCase    ,	lowerCamelCase				)
														with torch.no_grad():
																					__snake_case		:			int							 =   model(**lowerCamelCase				)[0]
														__snake_case		:			List[Any]							 =   torch.Size((1, 11, model.config.vocab_size)				)
														self.assertEqual(output.shape    ,	lowerCamelCase				)
														# change to expected output here
														__snake_case		:			Union[str, Any]							 =   torch.tensor(
														    [[-1.04_48, -1.04_11, 3.79_92], [-3.21_91, -3.23_86, -1.34_51], [-3.62_10, -3.59_93, 0.49_25]]    ,	device=lowerCamelCase				)
														self.assertTrue(torch.allclose(output[:, :3, :3]    ,	lowerCamelCase    ,	atol=lowerCamelCase				)				)






							def     __snake_case					(							self       :  List[Any]				)	->    Dict:
														__snake_case		:			Optional[Any]							 =   MaMaaaForConditionalGeneration.from_pretrained("facebook/m2m100_418M"				).to(lowerCamelCase				)
														__snake_case		:			Any							 =   MaMaaaTokenizer.from_pretrained("facebook/m2m100_418M"    ,	src_lang="fr"    ,	tgt_lang="en"				)

														__snake_case		:			List[str]							 =   [
														    "L'affaire NSA souligne l'absence totale de débat sur le renseignement",
														    "Selon moi, il y a deux niveaux de réponse de la part du gouvernement français.",
														    "Lorsque François Hollande téléphone à Barack Obama ou quand le ministre des affaires étrangères Laurent"
														    " Fabius convoque l'ambassadeur des Etats-Unis, ils réagissent à une vraie découverte, qui est celle de"
														    " l'ampleur de la surveillance américaine sur l'ensemble des communications en France.",
														]

														# The below article tests that we don't add any hypotheses outside of the top n_beams
														__snake_case		:			List[Any]							 =   tokenizer(lowerCamelCase    ,	padding=lowerCamelCase    ,	return_tensors="pt"				)

														__snake_case		:			Optional[Any]							 =   model.generate(
														    input_ids=dct["input_ids"].to(lowerCamelCase				)    ,	attention_mask=dct["attention_mask"].to(lowerCamelCase				)    ,	num_beams=5    ,	forced_bos_token_id=tokenizer.get_lang_id("en"				)    ,	)

														__snake_case		:			Tuple							 =   [
														    "The NSA case highlights the total absence of intelligence debate",
														    "I think there are two levels of response from the French government.",
														    "When François Hollande calls Barack Obama or when Foreign Minister Laurent Fabius calls the U.S."
														    " Ambassador, they respond to a real discovery, which is that of the scale of U.S. surveillance on all"
														    " communications in France.",
														]

														__snake_case		:			Optional[Any]							 =   tokenizer.batch_decode(
														    hypotheses_batch.tolist()    ,	clean_up_tokenization_spaces=lowerCamelCase    ,	skip_special_tokens=lowerCamelCase				)
														assert generated == expected_en



from __future__ import annotations

import inspect
import unittest

import numpy as np

from transformers import ResNetConfig
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 TFResNetForImageClassification, TFResNetModel
		from transformers.models.resnet.modeling_tf_resnet import TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
		from PIL import Image

		from transformers import AutoImageProcessor




class  lowerCamelCase__							:




	'''simple docstring'''




	def __init__(					self		:List[Any]     ,   a		:Dict     ,   a		:Any=3     ,   a		:Any=3_2     ,   a		:Optional[Any]=3     ,   a		:str=1_0     ,   a		:Union[str, Any]=[1_0, 2_0, 3_0, 4_0]     ,   a		:Optional[Any]=[1, 1, 2, 1]     ,   a		:Optional[Any]=True     ,   a		:Dict=True     ,   a		:Tuple="relu"     ,   a		:List[str]=3     ,   a		:Tuple=None     ,   )		-> Tuple:
								__UpperCamelCase	:   Optional[Any]			   =					parent
								__UpperCamelCase	:   Dict			   =					batch_size
								__UpperCamelCase	:   int			   =					image_size
								__UpperCamelCase	:   Dict			   =					num_channels
								__UpperCamelCase	:   Optional[int]			   =					embeddings_size
								__UpperCamelCase	:   List[Any]			   =					hidden_sizes
								__UpperCamelCase	:   Optional[Any]			   =					depths
								__UpperCamelCase	:   Optional[int]			   =					is_training
								__UpperCamelCase	:   Union[str, Any]			   =					use_labels
								__UpperCamelCase	:   Optional[int]			   =					hidden_act
								__UpperCamelCase	:   Tuple			   =					num_labels
								__UpperCamelCase	:   Tuple			   =					scope
								__UpperCamelCase	:   Dict			   =					len(a						)







	def    _lowerCamelCase				(					self		:Optional[int]						)		-> Any:
								__UpperCamelCase	:   List[str]			   =					floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

								__UpperCamelCase	:   List[str]			   =					None
								if self.use_labels:
															__UpperCamelCase	:   Tuple			   =					ids_tensor([self.batch_size]     ,   self.num_labels						)

								__UpperCamelCase	:   List[Any]			   =					self.get_config()

								return config, pixel_values, labels







	def    _lowerCamelCase				(					self		:Union[str, Any]						)		-> int:
								return ResNetConfig(
								    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     ,   image_size=self.image_size     ,   )







	def    _lowerCamelCase				(					self		:List[Any]     ,   a		:Dict     ,   a		:int     ,   a		:Optional[Any]						)		-> Tuple:
								__UpperCamelCase	:   str			   =					TFResNetModel(config=a						)
								__UpperCamelCase	:   Union[str, Any]			   =					model(a						)
								# 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 // 3_2, self.image_size // 3_2)     ,   )







	def    _lowerCamelCase				(					self		:Union[str, Any]     ,   a		:Optional[int]     ,   a		:List[str]     ,   a		:Optional[Any]						)		-> Any:
								__UpperCamelCase	:   str			   =					self.num_labels
								__UpperCamelCase	:   Optional[int]			   =					TFResNetForImageClassification(a						)
								__UpperCamelCase	:   List[str]			   =					model(a     ,   labels=a						)
								self.parent.assertEqual(result.logits.shape     ,   (self.batch_size, self.num_labels)						)







	def    _lowerCamelCase				(					self		:Optional[int]						)		-> List[str]:
								__UpperCamelCase	:   Optional[int]			   =					self.prepare_config_and_inputs()
								__UpperCamelCase   ,						__UpperCamelCase   ,						__UpperCamelCase	:   Union[str, Any]			   =					config_and_inputs
								__UpperCamelCase	:   List[str]			   =					{"pixel_values": pixel_values}
								return config, inputs_dict




@require_tf
class  lowerCamelCase__							(				__lowercase     ,						__lowercase     ,						unittest.TestCase):




	'''simple docstring'''




	_A								=     (TFResNetModel, TFResNetForImageClassification) if is_tf_available() else ()
	_A								=     (
	    {'feature-extraction': TFResNetModel, 'image-classification': TFResNetForImageClassification}
	    if is_tf_available()
	    else {}
	)

	_A								=     False
	_A								=     False
	_A								=     False
	_A								=     False
	_A								=     False







	def    _lowerCamelCase				(					self		:int						)		-> List[str]:
								__UpperCamelCase	:   Union[str, Any]			   =					TFResNetModelTester(self						)
								__UpperCamelCase	:   List[Any]			   =					ConfigTester(self     ,   config_class=a     ,   has_text_modality=a						)







	def    _lowerCamelCase				(					self		:int						)		-> Dict:
								self.create_and_test_config_common_properties()
								self.config_tester.create_and_test_config_to_json_string()
								self.config_tester.create_and_test_config_to_json_file()
								self.config_tester.create_and_test_config_from_and_save_pretrained()
								self.config_tester.create_and_test_config_with_num_labels()
								self.config_tester.check_config_can_be_init_without_params()
								self.config_tester.check_config_arguments_init()







	def    _lowerCamelCase				(					self		:str						)		-> Optional[Any]:
								return







	@unittest.skip(reason="ResNet does not use inputs_embeds"						)
	def    _lowerCamelCase				(					self		:Tuple						)		-> Tuple:
								pass







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







	def    _lowerCamelCase				(					self		:Optional[int]						)		-> Tuple:
								__UpperCamelCase   ,						__UpperCamelCase	:   Union[str, Any]			   =					self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
															__UpperCamelCase	:   Dict			   =					model_class(a						)
															__UpperCamelCase	:   Union[str, Any]			   =					inspect.signature(model.call						)
															# signature.parameters is an OrderedDict => so arg_names order is deterministic
															__UpperCamelCase	:   Dict			   =					[*signature.parameters.keys()]

															__UpperCamelCase	:   Union[str, Any]			   =					["pixel_values"]
															self.assertListEqual(arg_names[:1]     ,   a						)







	def    _lowerCamelCase				(					self		:List[str]						)		-> List[str]:
								__UpperCamelCase	:   Union[str, Any]			   =					self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*a						)







	def    _lowerCamelCase				(					self		:Optional[Any]						)		-> Tuple:
								def check_hidden_states_output(a		:Optional[Any]     ,   a		:Optional[int]     ,   a		:List[str]						):
															__UpperCamelCase	:   int			   =					model_class(a						)
															__UpperCamelCase	:   int			   =					model(**self._prepare_for_class(a     ,   a						)						)

															__UpperCamelCase	:   Optional[Any]			   =					outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

															__UpperCamelCase	:   Optional[int]			   =					self.model_tester.num_stages
															self.assertEqual(len(a						)     ,   expected_num_stages + 1						)

															# ResNet'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 // 4, self.model_tester.image_size // 4]     ,   )

								__UpperCamelCase   ,						__UpperCamelCase	:   Optional[Any]			   =					self.model_tester.prepare_config_and_inputs_for_common()
								__UpperCamelCase	:   str			   =					["basic", "bottleneck"]
								for model_class in self.all_model_classes:
															for layer_type in layers_type:
																						__UpperCamelCase	:   int			   =					layer_type
																						__UpperCamelCase	:   int			   =					True
																						check_hidden_states_output(a     ,   a     ,   a						)

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

																						check_hidden_states_output(a     ,   a     ,   a						)







	def    _lowerCamelCase				(					self		:Union[str, Any]						)		-> Dict:
								__UpperCamelCase	:   int			   =					self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_classification(*a						)







	@slow
	def    _lowerCamelCase				(					self		:Dict						)		-> Dict:
								for model_name in TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															__UpperCamelCase	:   Optional[Any]			   =					TFResNetModel.from_pretrained(a						)
															self.assertIsNotNone(a						)




def 	_SCREAMING_SNAKE_CASE					(		)					->    int:






							'''simple docstring'''





							__UpperCamelCase	:   Tuple			   =					Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png")
							return image




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




	'''simple docstring'''




	@cached_property
	def    _lowerCamelCase				(					self		:Optional[Any]						)		-> Tuple:
								return (
								    AutoImageProcessor.from_pretrained(TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]						)
								    if is_vision_available()
								    else None
								)







	@slow
	def    _lowerCamelCase				(					self		:Optional[int]						)		-> Optional[int]:
								__UpperCamelCase	:   int			   =					TFResNetForImageClassification.from_pretrained(TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]						)

								__UpperCamelCase	:   List[Any]			   =					self.default_image_processor
								__UpperCamelCase	:   List[str]			   =					prepare_img()
								__UpperCamelCase	:   List[str]			   =					image_processor(images=a     ,   return_tensors="tf"						)

								# forward pass
								__UpperCamelCase	:   Dict			   =					model(**a						)

								# verify the logits
								__UpperCamelCase	:   Dict			   =					tf.TensorShape((1, 1_0_0_0)						)
								self.assertEqual(outputs.logits.shape     ,   a						)

								__UpperCamelCase	:   Union[str, Any]			   =					tf.constant([-11.1069, -9.7877, -8.3777]						)

								self.assertTrue(np.allclose(outputs.logits[0, :3].numpy()     ,   a     ,   atol=1E-4						)						)