






"""simple docstring"""




from __future__ import annotations

import unittest

from transformers import LEDConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

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


if is_tf_available():
							import tensorflow as tf

							from transformers import TFLEDForConditionalGeneration, TFLEDModel


@require_tf
class 	__UpperCAmelCase		:


	'''simple docstring'''





	lowercase		:	Optional[int]							     =				LEDConfig
	lowercase		:	List[str]							     =				{}
	lowercase		:	Union[str, Any]							     =				"gelu"


	def __init__(     self      ,      _A      ,      _A=1_3      ,      _A=7      ,      _A=True      ,      _A=False      ,      _A=9_9      ,      _A=3_2      ,      _A=2      ,      _A=4      ,      _A=3_7      ,      _A=0.1      ,      _A=0.1      ,      _A=2_0      ,      _A=2      ,      _A=1      ,      _A=0      ,      _A=4      ,      ):



		'''simple docstring'''

		_SCREAMING_SNAKE_CASE						=parent
		_SCREAMING_SNAKE_CASE						=batch_size
		_SCREAMING_SNAKE_CASE						=seq_length
		_SCREAMING_SNAKE_CASE						=is_training
		_SCREAMING_SNAKE_CASE						=use_labels
		_SCREAMING_SNAKE_CASE						=vocab_size
		_SCREAMING_SNAKE_CASE						=hidden_size
		_SCREAMING_SNAKE_CASE						=num_hidden_layers
		_SCREAMING_SNAKE_CASE						=num_attention_heads
		_SCREAMING_SNAKE_CASE						=intermediate_size

		_SCREAMING_SNAKE_CASE						=hidden_dropout_prob
		_SCREAMING_SNAKE_CASE						=attention_probs_dropout_prob
		_SCREAMING_SNAKE_CASE						=max_position_embeddings
		_SCREAMING_SNAKE_CASE						=eos_token_id
		_SCREAMING_SNAKE_CASE						=pad_token_id
		_SCREAMING_SNAKE_CASE						=bos_token_id
		_SCREAMING_SNAKE_CASE						=attention_window

		# `ModelTesterMixin.test_attention_outputs` is expecting attention tensors to be of size
		# [num_attention_heads, encoder_seq_length, encoder_key_length], but TFLongformerSelfAttention
		# returns attention of shape [num_attention_heads, encoder_seq_length, self.attention_window + 1]
		# because its local attention only attends to `self.attention_window` and one before and one after
		_SCREAMING_SNAKE_CASE						=self.attention_window + 2

		# because of padding `encoder_seq_length`, is different from `seq_length`. Relevant for
		# the `test_attention_outputs` and `test_hidden_states_output` tests
		_SCREAMING_SNAKE_CASE						=(
		    self.seq_length + (self.attention_window - self.seq_length % self.attention_window) % self.attention_window
		)


	def 				UpperCamelCase_  (     self					):



		'''simple docstring'''

		_SCREAMING_SNAKE_CASE						=ids_tensor([self.batch_size, self.seq_length - 1]      ,      self.vocab_size					)
		_SCREAMING_SNAKE_CASE						=tf.expand_dims(tf.constant([self.eos_token_id] * self.batch_size					)      ,      1					)
		_SCREAMING_SNAKE_CASE						=tf.concat([input_ids, eos_tensor]      ,      axis=1					)

		_SCREAMING_SNAKE_CASE						=ids_tensor([self.batch_size, self.seq_length]      ,      self.vocab_size					)

		_SCREAMING_SNAKE_CASE						=self.config_cls(
		    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      ,      max_position_embeddings=self.max_position_embeddings      ,      eos_token_ids=[2]      ,      bos_token_id=self.bos_token_id      ,      pad_token_id=self.pad_token_id      ,      decoder_start_token_id=self.pad_token_id      ,      attention_window=self.attention_window      ,      **self.config_updates      ,      )
		_SCREAMING_SNAKE_CASE						=prepare_led_inputs_dict(_A      ,      _A      ,      _A					)
		_SCREAMING_SNAKE_CASE						=tf.concat(
		    [tf.zeros_like(_A					)[:, :-1], tf.ones_like(_A					)[:, -1:]]      ,      axis=-1      ,      )
		_SCREAMING_SNAKE_CASE						=global_attention_mask
		return config, inputs_dict







	def 				UpperCamelCase_  (     self      ,      _A      ,      _A					):



		'''simple docstring'''

		_SCREAMING_SNAKE_CASE						=TFLEDModel(config=_A					).get_decoder()
		_SCREAMING_SNAKE_CASE						=inputs_dict['''input_ids''']

		_SCREAMING_SNAKE_CASE						=input_ids[:1, :]
		_SCREAMING_SNAKE_CASE						=inputs_dict['''attention_mask'''][:1, :]
		_SCREAMING_SNAKE_CASE						=1

		# first forward pass
		_SCREAMING_SNAKE_CASE						=model(_A      ,      attention_mask=_A      ,      use_cache=_A					)

		_SCREAMING_SNAKE_CASE		,     _SCREAMING_SNAKE_CASE						=outputs.to_tuple()

		# create hypothetical next token and extent to next_input_ids
		_SCREAMING_SNAKE_CASE						=ids_tensor((self.batch_size, 3)      ,      config.vocab_size					)
		_SCREAMING_SNAKE_CASE						=tf.cast(ids_tensor((self.batch_size, 3)      ,      2					)      ,      tf.inta					)

		# append to next input_ids and
		_SCREAMING_SNAKE_CASE						=tf.concat([input_ids, next_tokens]      ,      axis=-1					)
		_SCREAMING_SNAKE_CASE						=tf.concat([attention_mask, next_attn_mask]      ,      axis=-1					)

		_SCREAMING_SNAKE_CASE						=model(_A      ,      attention_mask=_A					)[0]
		_SCREAMING_SNAKE_CASE						=model(_A      ,      attention_mask=_A      ,      past_key_values=_A					)[0]

		self.parent.assertEqual(next_tokens.shape[1]      ,      output_from_past.shape[1]					)

		# select random slice
		_SCREAMING_SNAKE_CASE						=int(ids_tensor((1,)      ,      output_from_past.shape[-1]					)					)
		_SCREAMING_SNAKE_CASE						=output_from_no_past[:, -3:, random_slice_idx]
		_SCREAMING_SNAKE_CASE						=output_from_past[:, :, random_slice_idx]

		# test that outputs are equal for slice
		tf.debugging.assert_near(_A      ,      _A      ,      rtol=1E-3					)






def 					_lowerCAmelCase(a   :    Optional[int]			,      a   :    Optional[Any]			,      a   :    Union[str, Any]			,      a   :    str=None			,      a   :    str=None			,      a   :    str=None			,      a   :    List[str]=None			,      )      ->       Tuple:
	if attention_mask is None:
		_SCREAMING_SNAKE_CASE						=tf.cast(tf.math.not_equal(a_			,      config.pad_token_id  )			,      tf.inta  )
	if decoder_attention_mask is None:
		_SCREAMING_SNAKE_CASE						=tf.concat(
		    [
		        tf.ones(decoder_input_ids[:, :1].shape			,      dtype=tf.inta  ),
		        tf.cast(tf.math.not_equal(decoder_input_ids[:, 1:]			,      config.pad_token_id  )			,      tf.inta  ),
		    ]			,      axis=-1			,      )
	if head_mask is None:
		_SCREAMING_SNAKE_CASE						=tf.ones((config.encoder_layers, config.encoder_attention_heads)  )
	if decoder_head_mask is None:
		_SCREAMING_SNAKE_CASE						=tf.ones((config.decoder_layers, config.decoder_attention_heads)  )
	return {
	    "input_ids": input_ids,
	    "attention_mask": attention_mask,
	    "decoder_input_ids": decoder_input_ids,
	    "decoder_attention_mask": decoder_attention_mask,
	    "head_mask": head_mask,
	    "decoder_head_mask": decoder_head_mask,
	}


@require_tf
class 	__UpperCAmelCase		(				snake_case_,  snake_case_,  unittest.TestCase	):


	'''simple docstring'''





	lowercase		:	Any							     =				(TFLEDForConditionalGeneration, TFLEDModel) if is_tf_available() else ()
	lowercase		:	List[str]							     =				(TFLEDForConditionalGeneration,) if is_tf_available() else ()
	lowercase		:	Optional[int]							     =				(
	    {
	        "conversational": TFLEDForConditionalGeneration,
	        "feature-extraction": TFLEDModel,
	        "summarization": TFLEDForConditionalGeneration,
	        "text2text-generation": TFLEDForConditionalGeneration,
	        "translation": TFLEDForConditionalGeneration,
	    }
	    if is_tf_available()
	    else {}
	)
	lowercase		:	Dict							     =				True
	lowercase		:	Optional[int]							     =				False
	lowercase		:	Optional[int]							     =				False
	lowercase		:	List[str]							     =				False


	def 				UpperCamelCase_  (     self					):



		'''simple docstring'''

		_SCREAMING_SNAKE_CASE						=TFLEDModelTester(self					)
		_SCREAMING_SNAKE_CASE						=ConfigTester(self      ,      config_class=_A					)


	def 				UpperCamelCase_  (     self					):



		'''simple docstring'''

		self.config_tester.run_common_tests()


	def 				UpperCamelCase_  (     self					):



		'''simple docstring'''

		_SCREAMING_SNAKE_CASE						=self.model_tester.prepare_config_and_inputs_for_common()
		self.model_tester.check_decoder_model_past_large_inputs(*_A					)


	def 				UpperCamelCase_  (     self					):



		'''simple docstring'''

		_SCREAMING_SNAKE_CASE		,     _SCREAMING_SNAKE_CASE						=self.model_tester.prepare_config_and_inputs_for_common()
		_SCREAMING_SNAKE_CASE						=tf.zeros_like(inputs_dict['''attention_mask''']					)
		_SCREAMING_SNAKE_CASE						=2
		_SCREAMING_SNAKE_CASE						=tf.where(
		    tf.range(self.model_tester.seq_length					)[None, :] < num_global_attn_indices      ,      1      ,      inputs_dict['''global_attention_mask''']      ,      )

		_SCREAMING_SNAKE_CASE						=True
		_SCREAMING_SNAKE_CASE						=self.model_tester.seq_length
		_SCREAMING_SNAKE_CASE						=self.model_tester.encoder_seq_length

		def check_decoder_attentions_output(_A					):
			_SCREAMING_SNAKE_CASE						=outputs.decoder_attentions
			self.assertEqual(len(_A					)      ,      self.model_tester.num_hidden_layers					)
			self.assertListEqual(
			    list(decoder_attentions[0].shape[-3:]					)      ,      [self.model_tester.num_attention_heads, seq_length, seq_length]      ,      )

		def check_encoder_attentions_output(_A					):
			_SCREAMING_SNAKE_CASE						=[t.numpy() for t in outputs.encoder_attentions]
			_SCREAMING_SNAKE_CASE						=[t.numpy() for t in outputs.encoder_global_attentions]
			self.assertEqual(len(_A					)      ,      self.model_tester.num_hidden_layers					)
			self.assertEqual(len(_A					)      ,      self.model_tester.num_hidden_layers					)
			self.assertListEqual(
			    list(attentions[0].shape[-3:]					)      ,      [self.model_tester.num_attention_heads, seq_length, seq_length]      ,      )
			self.assertListEqual(
			    list(global_attentions[0].shape[-3:]					)      ,      [self.model_tester.num_attention_heads, encoder_seq_length, num_global_attn_indices]      ,      )

		for model_class in self.all_model_classes:
			_SCREAMING_SNAKE_CASE						=True
			_SCREAMING_SNAKE_CASE						=False
			_SCREAMING_SNAKE_CASE						=False
			_SCREAMING_SNAKE_CASE						=model_class(_A					)
			_SCREAMING_SNAKE_CASE						=model(self._prepare_for_class(_A      ,      _A					)					)
			_SCREAMING_SNAKE_CASE						=len(_A					)
			self.assertEqual(config.output_hidden_states      ,      _A					)
			check_encoder_attentions_output(_A					)

			if self.is_encoder_decoder:
				_SCREAMING_SNAKE_CASE						=model_class(_A					)
				_SCREAMING_SNAKE_CASE						=model(self._prepare_for_class(_A      ,      _A					)					)
				self.assertEqual(config.output_hidden_states      ,      _A					)
				check_decoder_attentions_output(_A					)

			# Check that output attentions can also be changed via the config
			del inputs_dict["output_attentions"]
			_SCREAMING_SNAKE_CASE						=True
			_SCREAMING_SNAKE_CASE						=model_class(_A					)
			_SCREAMING_SNAKE_CASE						=model(self._prepare_for_class(_A      ,      _A					)					)
			self.assertEqual(config.output_hidden_states      ,      _A					)
			check_encoder_attentions_output(_A					)

			# Check attention is always last and order is fine
			_SCREAMING_SNAKE_CASE						=True
			_SCREAMING_SNAKE_CASE						=True
			_SCREAMING_SNAKE_CASE						=model_class(_A					)
			_SCREAMING_SNAKE_CASE						=model(self._prepare_for_class(_A      ,      _A					)					)

			self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1)      ,      len(_A					)					)
			self.assertEqual(model.config.output_hidden_states      ,      _A					)
			check_encoder_attentions_output(_A					)


	@unittest.skip('''LED keeps using potentially symbolic tensors in conditionals and breaks tracing.'''					)
	def 				UpperCamelCase_  (     self					):



		'''simple docstring'''

		pass







	def 				UpperCamelCase_  (     self					):



		'''simple docstring'''

		pass






def 					_lowerCAmelCase(a   :    Tuple  )      ->       Optional[int]:
	return tf.constant(a_			,      dtype=tf.intaa  )


UpperCAmelCase_       :							Dict             =				1E-4






@slow
@require_tf
class 	__UpperCAmelCase		(				unittest.TestCase	):


	'''simple docstring'''





	def 				UpperCamelCase_  (     self					):



		'''simple docstring'''

		_SCREAMING_SNAKE_CASE						=TFLEDForConditionalGeneration.from_pretrained('''allenai/led-base-16384'''					).led

		# change to intended input here
		_SCREAMING_SNAKE_CASE						=_long_tensor([5_1_2 * [0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9]]					)
		_SCREAMING_SNAKE_CASE						=_long_tensor([1_2_8 * [0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9]]					)
		_SCREAMING_SNAKE_CASE						=prepare_led_inputs_dict(model.config      ,      _A      ,      _A					)
		_SCREAMING_SNAKE_CASE						=model(**_A					)[0]
		_SCREAMING_SNAKE_CASE						=(1, 1_0_2_4, 7_6_8)
		self.assertEqual(output.shape      ,      _A					)
		# change to expected output here
		_SCREAMING_SNAKE_CASE						=tf.convert_to_tensor(
		    [[2.3050, 2.8279, 0.6531], [-1.8457, -0.1455, -3.5661], [-1.0186, 0.4586, -2.2043]]      ,      )
		tf.debugging.assert_near(output[:, :3, :3]      ,      _A      ,      atol=1E-3					)







	def 				UpperCamelCase_  (     self					):



		'''simple docstring'''

		_SCREAMING_SNAKE_CASE						=TFLEDForConditionalGeneration.from_pretrained('''allenai/led-base-16384'''					)

		# change to intended input here
		_SCREAMING_SNAKE_CASE						=_long_tensor([5_1_2 * [0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9]]					)
		_SCREAMING_SNAKE_CASE						=_long_tensor([1_2_8 * [0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9]]					)
		_SCREAMING_SNAKE_CASE						=prepare_led_inputs_dict(model.config      ,      _A      ,      _A					)
		_SCREAMING_SNAKE_CASE						=model(**_A					)[0]
		_SCREAMING_SNAKE_CASE						=(1, 1_0_2_4, model.config.vocab_size)
		self.assertEqual(output.shape      ,      _A					)
		# change to expected output here
		_SCREAMING_SNAKE_CASE						=tf.convert_to_tensor(
		    [[33.6507, 6.4572, 16.8089], [5.8739, -2.4238, 11.2902], [-3.2139, -4.3149, 4.2783]]      ,      )
		tf.debugging.assert_near(output[:, :3, :3]      ,      _A      ,      atol=1E-3      ,      rtol=1E-3					)












from __future__ import annotations

import inspect
import unittest
from math import floor

import numpy as np

from transformers import CvtConfig
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 TFCvtForImageClassification, TFCvtModel
	from transformers.models.cvt.modeling_tf_cvt import TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
	from PIL import Image

	from transformers import AutoImageProcessor




class 					UpperCamelCase_ (     snake_case_							):



	'''simple docstring'''




	def 				_UpperCamelCase     (			self   )			->       Any:
								snake_case_           =				self.config_class(**self.inputs_dict   )
								self.parent.assertTrue(hasattr(a			,     'embed_dim'   )   )
								self.parent.assertTrue(hasattr(a			,     'num_heads'   )   )






class 					UpperCamelCase_ :



	'''simple docstring'''




	def __init__(			self			,     a			,     a=13			,     a=64			,     a=3			,     a=[16, 48, 96]			,     a=[1, 3, 6]			,     a=[1, 2, 10]			,     a=[7, 3, 3]			,     a=[4, 2, 2]			,     a=[2, 1, 1]			,     a=[2, 2, 2]			,     a=[False, False, True]			,     a=[0.0, 0.0, 0.0]			,     a=0.02			,     a=1E-12			,     a=True			,     a=True			,     a=2			,     )			->       List[Any]:
								snake_case_           =				parent
								snake_case_           =				batch_size
								snake_case_           =				image_size
								snake_case_           =				patch_sizes
								snake_case_           =				patch_stride
								snake_case_           =				patch_padding
								snake_case_           =				is_training
								snake_case_           =				use_labels
								snake_case_           =				num_labels
								snake_case_           =				num_channels
								snake_case_           =				embed_dim
								snake_case_           =				num_heads
								snake_case_           =				stride_kv
								snake_case_           =				depth
								snake_case_           =				cls_token
								snake_case_           =				attention_drop_rate
								snake_case_           =				initializer_range
								snake_case_           =				layer_norm_eps




	def 				_UpperCamelCase     (			self   )			->       Dict:
								snake_case_           =				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]   )

								snake_case_           =				None
								if self.use_labels:
															# create a random int32 tensor of given shape
															snake_case_           =				ids_tensor([self.batch_size]			,     self.num_labels   )

								snake_case_           =				self.get_config()
								return config, pixel_values, labels




	def 				_UpperCamelCase     (			self   )			->       Dict:
								return CvtConfig(
								    image_size=self.image_size			,     num_labels=self.num_labels			,     num_channels=self.num_channels			,     embed_dim=self.embed_dim			,     num_heads=self.num_heads			,     patch_sizes=self.patch_sizes			,     patch_padding=self.patch_padding			,     patch_stride=self.patch_stride			,     stride_kv=self.stride_kv			,     depth=self.depth			,     cls_token=self.cls_token			,     attention_drop_rate=self.attention_drop_rate			,     initializer_range=self.initializer_range			,     )




	def 				_UpperCamelCase     (			self			,     a			,     a			,     a   )			->       int:
								snake_case_           =				TFCvtModel(config=a   )
								snake_case_           =				model(a			,     training=a   )
								snake_case_           =				(self.image_size, self.image_size)
								snake_case_     ,						snake_case_           =				image_size[0], image_size[1]
								for i in range(len(self.depth   )   ):
															snake_case_           =				floor(((height + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1   )
															snake_case_           =				floor(((width + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1   )
								self.parent.assertEqual(result.last_hidden_state.shape			,     (self.batch_size, self.embed_dim[-1], height, width)   )




	def 				_UpperCamelCase     (			self			,     a			,     a			,     a   )			->       Dict:
								snake_case_           =				self.num_labels
								snake_case_           =				TFCvtForImageClassification(a   )
								snake_case_           =				model(a			,     labels=a			,     training=a   )
								self.parent.assertEqual(result.logits.shape			,     (self.batch_size, self.num_labels)   )






	def 				_UpperCamelCase     (			self   )			->       Tuple:
								snake_case_           =				self.prepare_config_and_inputs()
								snake_case_     ,						snake_case_     ,						snake_case_           =				config_and_inputs
								snake_case_           =				{'pixel_values': pixel_values}
								return config, inputs_dict






@require_tf
class 					UpperCamelCase_ (     snake_case_			,   snake_case_			,   unittest.TestCase							):



	'''simple docstring'''




	lowerCAmelCase						=					(TFCvtModel, TFCvtForImageClassification) if is_tf_available() else ()
	lowerCAmelCase						=					(
	    {'''feature-extraction''': TFCvtModel, '''image-classification''': TFCvtForImageClassification}
	    if is_tf_available()
	    else {}
	)
	lowerCAmelCase						=					False
	lowerCAmelCase						=					False
	lowerCAmelCase						=					False
	lowerCAmelCase						=					False
	lowerCAmelCase						=					False




	def 				_UpperCamelCase     (			self   )			->       Optional[int]:
								snake_case_           =				TFCvtModelTester(self   )
								snake_case_           =				TFCvtConfigTester(self			,     config_class=a			,     has_text_modality=a			,     hidden_size=37   )




	def 				_UpperCamelCase     (			self   )			->       Optional[int]:
								self.config_tester.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()




	@unittest.skip(reason='Cvt does not output attentions'   )
	def 				_UpperCamelCase     (			self   )			->       Dict:
								pass




	@unittest.skip(reason='Cvt does not use inputs_embeds'   )
	def 				_UpperCamelCase     (			self   )			->       List[str]:
								pass




	@unittest.skip(reason='Cvt does not support input and output embeddings'   )
	def 				_UpperCamelCase     (			self   )			->       Optional[int]:
								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.'			,     )
	def 				_UpperCamelCase     (			self   )			->       Dict:
								super().test_dataset_conversion()




	@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 				_UpperCamelCase     (			self   )			->       Dict:
								super().test_keras_fit()




	@unittest.skip(reason='Get `Failed to determine best cudnn convolution algo.` error after using TF 2.12+cuda 11.8'   )
	def 				_UpperCamelCase     (			self   )			->       List[str]:
								snake_case_           =				tf.keras.mixed_precision.Policy('mixed_float16'   )
								tf.keras.mixed_precision.set_global_policy(a   )
								super().test_keras_fit()
								tf.keras.mixed_precision.set_global_policy('float32'   )




	def 				_UpperCamelCase     (			self   )			->       Optional[int]:
								snake_case_     ,						snake_case_           =				self.model_tester.prepare_config_and_inputs_for_common()

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

															snake_case_           =				['pixel_values']
															self.assertListEqual(arg_names[:1]			,     a   )




	def 				_UpperCamelCase     (			self   )			->       Optional[Any]:
								def check_hidden_states_output(a			,     a			,     a   ):
															snake_case_           =				model_class(a   )

															snake_case_           =				model(**self._prepare_for_class(a			,     a   )   )
															snake_case_           =				outputs.hidden_states

															snake_case_           =				len(self.model_tester.depth   )
															self.assertEqual(len(a   )			,     a   )

															# verify the first hidden states (first block)
															self.assertListEqual(
															    list(hidden_states[0].shape[-3:]   )			,     [
															        self.model_tester.embed_dim[0],
															        self.model_tester.image_size // 4,
															        self.model_tester.image_size // 4,
															    ]			,     )

								snake_case_     ,						snake_case_           =				self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
															snake_case_           =				True
															check_hidden_states_output(a			,     a			,     a   )

															# check that output_hidden_states also work using config
															del inputs_dict["output_hidden_states"]
															snake_case_           =				True

															check_hidden_states_output(a			,     a			,     a   )




	def 				_UpperCamelCase     (			self   )			->       List[Any]:
								snake_case_           =				self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*a   )




	def 				_UpperCamelCase     (			self   )			->       List[str]:
								snake_case_           =				self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_classification(*a   )






	@slow
	def 				_UpperCamelCase     (			self   )			->       int:
								for model_name in TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															snake_case_           =				TFCvtModel.from_pretrained(a   )
															self.assertIsNotNone(a   )






def 		__UpperCAmelCase     (	):
							snake_case_           =				Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png')
							return image




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



	'''simple docstring'''




	@cached_property
	def 				_UpperCamelCase     (			self   )			->       Any:
								return AutoImageProcessor.from_pretrained(TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]   )






	@slow
	def 				_UpperCamelCase     (			self   )			->       Dict:
								snake_case_           =				TFCvtForImageClassification.from_pretrained(TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]   )

								snake_case_           =				self.default_image_processor
								snake_case_           =				prepare_img()
								snake_case_           =				image_processor(images=a			,     return_tensors='tf'   )

								# forward pass
								snake_case_           =				model(**a   )

								# verify the logits
								snake_case_           =				tf.TensorShape((1, 10_00)   )
								self.assertEqual(outputs.logits.shape			,     a   )

								snake_case_           =				tf.constant([0.9_285, 0.9_015, -0.3_150]   )
								self.assertTrue(np.allclose(outputs.logits[0, :3].numpy()			,     a			,     atol=1E-4   )   )





