





from __future__ import annotations

import unittest

from transformers import MobileBertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

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


if is_tf_available():
 import tensorflow as tf

 from transformers import (
     TF_MODEL_FOR_PRETRAINING_MAPPING,
     TFMobileBertForMaskedLM,
     TFMobileBertForMultipleChoice,
     TFMobileBertForNextSentencePrediction,
     TFMobileBertForPreTraining,
     TFMobileBertForQuestionAnswering,
     TFMobileBertForSequenceClassification,
     TFMobileBertForTokenClassification,
     TFMobileBertModel,
 )


@require_tf
class     __magic_name__     (							a_			, a_			, unittest.TestCase							):





     """simple docstring"""



     __UpperCamelCase    			=   (
         (
             TFMobileBertModel,
             TFMobileBertForMaskedLM,
             TFMobileBertForNextSentencePrediction,
             TFMobileBertForPreTraining,
             TFMobileBertForQuestionAnswering,
             TFMobileBertForSequenceClassification,
             TFMobileBertForTokenClassification,
             TFMobileBertForMultipleChoice,
         )
         if is_tf_available()
         else ()
     )
     __UpperCamelCase    			=   (
         {
             '''feature-extraction''': TFMobileBertModel,
             '''fill-mask''': TFMobileBertForMaskedLM,
             '''question-answering''': TFMobileBertForQuestionAnswering,
             '''text-classification''': TFMobileBertForSequenceClassification,
             '''token-classification''': TFMobileBertForTokenClassification,
             '''zero-shot''': TFMobileBertForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )
     __UpperCamelCase    			=   False
     __UpperCamelCase    			=   False



     def   SCREAMING_SNAKE_CASE						(							self				:Dict	,					snake_case				:Any	,					snake_case				:List[Any]	,					snake_case				:int=False     ):





        '''simple docstring'''




        A_    : Any								=	super()._prepare_for_class(_A	,					_A	,					return_labels=_A     )

        if return_labels:
           if model_class in get_values(_A     ):
              A_    : Optional[Any]								=	tf.zeros(self.model_tester.batch_size	,					dtype=tf.intaa     )

        return inputs_dict


     class     __magic_name__     (							a_							):





          """simple docstring"""



          def __init__(							self				:Any	,					snake_case				:Optional[Any]	,					snake_case				:Union[str, Any]=13	,					snake_case				:Any=7	,					snake_case				:List[Any]=True	,					snake_case				:str=True	,					snake_case				:List[Any]=True	,					snake_case				:Union[str, Any]=True	,					snake_case				:Tuple=99	,					snake_case				:str=32	,					snake_case				:Optional[Any]=32	,					snake_case				:List[str]=2	,					snake_case				:Dict=4	,					snake_case				:Optional[Any]=37	,					snake_case				:int="gelu"	,					snake_case				:List[str]=0.1	,					snake_case				:Dict=0.1	,					snake_case				:Tuple=512	,					snake_case				:List[Any]=16	,					snake_case				:List[str]=2	,					snake_case				:int=0.02	,					snake_case				:Dict=3	,					snake_case				:Optional[int]=4	,					snake_case				:List[Any]=None	,					):





             '''simple docstring'''




             A_    : List[str]								=	parent
             A_    : List[Any]								=	batch_size
             A_    : List[Any]								=	seq_length
             A_    : Dict								=	is_training
             A_    : Optional[Any]								=	use_input_mask
             A_    : Optional[Any]								=	use_token_type_ids
             A_    : Any								=	use_labels
             A_    : Optional[int]								=	vocab_size
             A_    : Union[str, Any]								=	hidden_size
             A_    : Union[str, Any]								=	num_hidden_layers
             A_    : List[Any]								=	num_attention_heads
             A_    : str								=	intermediate_size
             A_    : Dict								=	hidden_act
             A_    : str								=	hidden_dropout_prob
             A_    : Union[str, Any]								=	attention_probs_dropout_prob
             A_    : Union[str, Any]								=	max_position_embeddings
             A_    : List[str]								=	type_vocab_size
             A_    : Union[str, Any]								=	type_sequence_label_size
             A_    : Optional[Any]								=	initializer_range
             A_    : int								=	num_labels
             A_    : str								=	num_choices
             A_    : Any								=	scope
             A_    : Dict								=	embedding_size



          def   SCREAMING_SNAKE_CASE						(							self				:Any     ):





             '''simple docstring'''




             A_    : Any								=	ids_tensor([self.batch_size, self.seq_length]	,					self.vocab_size     )

             A_    : List[Any]								=	None
             if self.use_input_mask:
                A_    : Tuple								=	random_attention_mask([self.batch_size, self.seq_length]     )

             A_    : Tuple								=	None
             if self.use_token_type_ids:
                A_    : int								=	ids_tensor([self.batch_size, self.seq_length]	,					self.type_vocab_size     )

             A_    : Optional[int]								=	None
             A_    : Tuple								=	None
             A_    : Dict								=	None
             if self.use_labels:
                A_    : Any								=	ids_tensor([self.batch_size]	,					self.type_sequence_label_size     )
                A_    : Optional[Any]								=	ids_tensor([self.batch_size, self.seq_length]	,					self.num_labels     )
                A_    : List[Any]								=	ids_tensor([self.batch_size]	,					self.num_choices     )

             A_    : Any								=	MobileBertConfig(
                 vocab_size=self.vocab_size	,					hidden_size=self.hidden_size	,					num_hidden_layers=self.num_hidden_layers	,					num_attention_heads=self.num_attention_heads	,					intermediate_size=self.intermediate_size	,					hidden_act=self.hidden_act	,					hidden_dropout_prob=self.hidden_dropout_prob	,					attention_probs_dropout_prob=self.attention_probs_dropout_prob	,					max_position_embeddings=self.max_position_embeddings	,					type_vocab_size=self.type_vocab_size	,					initializer_range=self.initializer_range	,					embedding_size=self.embedding_size	,					)

             return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels



          def   SCREAMING_SNAKE_CASE						(							self				:Optional[Any]	,					snake_case				:Optional[Any]	,					snake_case				:Optional[int]	,					snake_case				:Optional[Any]	,					snake_case				:Tuple	,					snake_case				:List[Any]	,					snake_case				:str	,					snake_case				:str     ):





             '''simple docstring'''




             A_    : Dict								=	TFMobileBertModel(config=_A     )
             A_    : List[str]								=	{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
             A_    : List[Any]								=	model(_A     )

             A_    : List[Any]								=	[input_ids, input_mask]
             A_    : int								=	model(_A     )

             A_    : Tuple								=	model(_A     )

             self.parent.assertEqual(
                 result.last_hidden_state.shape	,					(self.batch_size, self.seq_length, self.hidden_size)     )
             self.parent.assertEqual(result.pooler_output.shape	,					(self.batch_size, self.hidden_size)     )



          def   SCREAMING_SNAKE_CASE						(							self				:List[Any]	,					snake_case				:int	,					snake_case				:str	,					snake_case				:str	,					snake_case				:Any	,					snake_case				:Any	,					snake_case				:Union[str, Any]	,					snake_case				:Optional[Any]     ):





             '''simple docstring'''




             A_    : str								=	TFMobileBertForMaskedLM(config=_A     )
             A_    : int								=	{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
             A_    : Optional[int]								=	model(_A     )
             self.parent.assertEqual(result.logits.shape	,					(self.batch_size, self.seq_length, self.vocab_size)     )



          def   SCREAMING_SNAKE_CASE						(							self				:Dict	,					snake_case				:str	,					snake_case				:Union[str, Any]	,					snake_case				:Dict	,					snake_case				:Dict	,					snake_case				:Tuple	,					snake_case				:str	,					snake_case				:List[Any]     ):





             '''simple docstring'''




             A_    : Any								=	TFMobileBertForNextSentencePrediction(config=_A     )
             A_    : Optional[Any]								=	{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
             A_    : Optional[int]								=	model(_A     )
             self.parent.assertEqual(result.logits.shape	,					(self.batch_size, 2)     )



          def   SCREAMING_SNAKE_CASE						(							self				:int	,					snake_case				:List[Any]	,					snake_case				:Any	,					snake_case				:List[Any]	,					snake_case				:Any	,					snake_case				:List[Any]	,					snake_case				:Any	,					snake_case				:Union[str, Any]     ):





             '''simple docstring'''




             A_    : str								=	TFMobileBertForPreTraining(config=_A     )
             A_    : Optional[int]								=	{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
             A_    : str								=	model(_A     )
             self.parent.assertEqual(
                 result.prediction_logits.shape	,					(self.batch_size, self.seq_length, self.vocab_size)     )
             self.parent.assertEqual(result.seq_relationship_logits.shape	,					(self.batch_size, 2)     )



          def   SCREAMING_SNAKE_CASE						(							self				:Any	,					snake_case				:List[str]	,					snake_case				:Tuple	,					snake_case				:Optional[Any]	,					snake_case				:Tuple	,					snake_case				:Optional[int]	,					snake_case				:Dict	,					snake_case				:Union[str, Any]     ):





             '''simple docstring'''




             A_    : Tuple								=	self.num_labels
             A_    : Optional[int]								=	TFMobileBertForSequenceClassification(config=_A     )
             A_    : str								=	{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
             A_    : Optional[int]								=	model(_A     )
             self.parent.assertEqual(result.logits.shape	,					(self.batch_size, self.num_labels)     )



          def   SCREAMING_SNAKE_CASE						(							self				:str	,					snake_case				:Optional[int]	,					snake_case				:Any	,					snake_case				:str	,					snake_case				:str	,					snake_case				:Union[str, Any]	,					snake_case				:Optional[Any]	,					snake_case				:Optional[int]     ):





             '''simple docstring'''




             A_    : Any								=	self.num_choices
             A_    : str								=	TFMobileBertForMultipleChoice(config=_A     )
             A_    : str								=	tf.tile(tf.expand_dims(_A	,					1     )	,					(1, self.num_choices, 1)     )
             A_    : Union[str, Any]								=	tf.tile(tf.expand_dims(_A	,					1     )	,					(1, self.num_choices, 1)     )
             A_    : int								=	tf.tile(tf.expand_dims(_A	,					1     )	,					(1, self.num_choices, 1)     )
             A_    : List[Any]								=	{
                 "input_ids": multiple_choice_inputs_ids,
                 "attention_mask": multiple_choice_input_mask,
                 "token_type_ids": multiple_choice_token_type_ids,
             }
             A_    : Dict								=	model(_A     )
             self.parent.assertEqual(result.logits.shape	,					(self.batch_size, self.num_choices)     )



          def   SCREAMING_SNAKE_CASE						(							self				:int	,					snake_case				:Any	,					snake_case				:Optional[int]	,					snake_case				:str	,					snake_case				:Optional[int]	,					snake_case				:List[str]	,					snake_case				:Dict	,					snake_case				:Optional[Any]     ):





             '''simple docstring'''




             A_    : Dict								=	self.num_labels
             A_    : Dict								=	TFMobileBertForTokenClassification(config=_A     )
             A_    : List[str]								=	{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
             A_    : Optional[Any]								=	model(_A     )
             self.parent.assertEqual(result.logits.shape	,					(self.batch_size, self.seq_length, self.num_labels)     )



          def   SCREAMING_SNAKE_CASE						(							self				:List[str]	,					snake_case				:Tuple	,					snake_case				:Tuple	,					snake_case				:Optional[int]	,					snake_case				:Tuple	,					snake_case				:str	,					snake_case				:Tuple	,					snake_case				:List[Any]     ):





             '''simple docstring'''




             A_    : Union[str, Any]								=	TFMobileBertForQuestionAnswering(config=_A     )
             A_    : List[str]								=	{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
             A_    : int								=	model(_A     )
             self.parent.assertEqual(result.start_logits.shape	,					(self.batch_size, self.seq_length)     )
             self.parent.assertEqual(result.end_logits.shape	,					(self.batch_size, self.seq_length)     )





          def   SCREAMING_SNAKE_CASE						(							self				:List[Any]     ):





             '''simple docstring'''




             A_    : Optional[Any]								=	self.prepare_config_and_inputs()
             (
                 (
                 A_			
             )					,  (
                 A_			
             )					,  (
                 A_			
             )					,  (
                 A_			
             )					,  (
                 A_			
             )					,  (
                 A_			
             )					,  (
                 A_			
             )					,  			
             )    : List[str]								=	config_and_inputs
             A_    : Tuple								=	{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
             return config, inputs_dict




     def   SCREAMING_SNAKE_CASE						(							self				:int     ):





        '''simple docstring'''




        A_    : Tuple								=	TFMobileBertModelTest.TFMobileBertModelTester(self     )
        A_    : Optional[int]								=	ConfigTester(self	,					config_class=_A	,					hidden_size=37     )



     def   SCREAMING_SNAKE_CASE						(							self				:str     ):





        '''simple docstring'''




        self.config_tester.run_common_tests()



     def   SCREAMING_SNAKE_CASE						(							self				:List[str]     ):





        '''simple docstring'''




        A_    : List[str]								=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mobilebert_model(*_A     )



     def   SCREAMING_SNAKE_CASE						(							self				:Dict     ):





        '''simple docstring'''




        A_    : Dict								=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mobilebert_for_masked_lm(*_A     )



     def   SCREAMING_SNAKE_CASE						(							self				:Tuple     ):





        '''simple docstring'''




        A_    : Tuple								=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mobilebert_for_multiple_choice(*_A     )



     def   SCREAMING_SNAKE_CASE						(							self				:Tuple     ):





        '''simple docstring'''




        A_    : Union[str, Any]								=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*_A     )



     def   SCREAMING_SNAKE_CASE						(							self				:List[str]     ):





        '''simple docstring'''




        A_    : int								=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mobilebert_for_pretraining(*_A     )



     def   SCREAMING_SNAKE_CASE						(							self				:str     ):





        '''simple docstring'''




        A_    : Tuple								=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mobilebert_for_question_answering(*_A     )



     def   SCREAMING_SNAKE_CASE						(							self				:Dict     ):





        '''simple docstring'''




        A_    : Optional[int]								=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mobilebert_for_sequence_classification(*_A     )



     def   SCREAMING_SNAKE_CASE						(							self				:List[Any]     ):





        '''simple docstring'''




        A_    : Optional[Any]								=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mobilebert_for_token_classification(*_A     )





     @slow
     def   SCREAMING_SNAKE_CASE						(							self				:List[str]     ):





        '''simple docstring'''




        for model_name in ["google/mobilebert-uncased"]:
           A_    : Union[str, Any]								=	TFMobileBertModel.from_pretrained(_A     )
           self.assertIsNotNone(_A     )




@require_tf
class     __magic_name__     (							unittest.TestCase							):





     """simple docstring"""



     @slow
     def   SCREAMING_SNAKE_CASE						(							self				:Tuple     ):





        '''simple docstring'''




        A_    : List[Any]								=	TFMobileBertForPreTraining.from_pretrained("google/mobilebert-uncased"     )
        A_    : Optional[Any]								=	tf.constant([[0, 1, 2, 3, 4, 5]]     )
        A_    : Optional[Any]								=	model(_A     )[0]

        A_    : Optional[int]								=	[1, 6, 30_522]
        self.assertEqual(output.shape	,					_A     )

        A_    : Optional[int]								=	tf.constant(
            [
                [
                    [-4.5919547, -9.248295, -9.645256],
                    [-6.7306175, -6.440284, -6.6052837],
                    [-7.2743506, -6.7847915, -6.024673],
                ]
            ]     )
        tf.debugging.assert_near(output[:, :3, :3]	,					_A	,					atol=1e-4     )







from __future__ import annotations

import inspect
import unittest

from transformers import ViTConfig
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 TFViTForImageClassification, TFViTModel


if is_vision_available():
				from PIL import Image

				from transformers import ViTImageProcessor

class 	A_       :
	def __init__(    self							,					_A							,					_A=1_3							,					_A=3_0							,					_A=2							,					_A=3							,					_A=True							,					_A=True							,					_A=3_2							,					_A=2							,					_A=4							,					_A=3_7							,					_A="gelu"							,					_A=0.1							,					_A=0.1							,					_A=1_0							,					_A=0.02							,					_A=3							,					_A=None							,					):






				'''simple docstring'''







				UpperCAmelCase   		=				parent
				UpperCAmelCase   		=				batch_size
				UpperCAmelCase   		=				image_size
				UpperCAmelCase   		=				patch_size
				UpperCAmelCase   		=				num_channels
				UpperCAmelCase   		=				is_training
				UpperCAmelCase   		=				use_labels
				UpperCAmelCase   		=				hidden_size
				UpperCAmelCase   		=				num_hidden_layers
				UpperCAmelCase   		=				num_attention_heads
				UpperCAmelCase   		=				intermediate_size
				UpperCAmelCase   		=				hidden_act
				UpperCAmelCase   		=				hidden_dropout_prob
				UpperCAmelCase   		=				attention_probs_dropout_prob
				UpperCAmelCase   		=				type_sequence_label_size
				UpperCAmelCase   		=				initializer_range
				UpperCAmelCase   		=				scope

				# in ViT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
				UpperCAmelCase   		=				(image_size // patch_size) ** 2
				UpperCAmelCase   		=				num_patches + 1
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

				UpperCAmelCase   		=				None
				if self.use_labels:
							UpperCAmelCase   		=				ids_tensor([self.batch_size]							,					self.type_sequence_label_size		)

				UpperCAmelCase   		=				self.get_config()

				return config, pixel_values, labels
	def      _lowercase				(    self		):






				'''simple docstring'''







				return ViTConfig(
				    image_size=self.image_size							,					patch_size=self.patch_size							,					num_channels=self.num_channels							,					hidden_size=self.hidden_size							,					num_hidden_layers=self.num_hidden_layers							,					num_attention_heads=self.num_attention_heads							,					intermediate_size=self.intermediate_size							,					hidden_act=self.hidden_act							,					hidden_dropout_prob=self.hidden_dropout_prob							,					attention_probs_dropout_prob=self.attention_probs_dropout_prob							,					is_decoder=_A							,					initializer_range=self.initializer_range							,					)
	def      _lowercase				(    self							,					_A							,					_A							,					_A		):






				'''simple docstring'''







				UpperCAmelCase   		=				TFViTModel(config=_A		)
				UpperCAmelCase   		=				model(_A							,					training=_A		)
				self.parent.assertEqual(result.last_hidden_state.shape							,					(self.batch_size, self.seq_length, self.hidden_size)		)

				# Test with an image with different size than the one specified in config.
				UpperCAmelCase   		=				self.image_size // 2
				UpperCAmelCase   		=				pixel_values[:, :, :image_size, :image_size]
				UpperCAmelCase   		=				model(_A							,					interpolate_pos_encoding=_A							,					training=_A		)
				UpperCAmelCase   		=				(image_size // self.patch_size) ** 2 + 1
				self.parent.assertEqual(result.last_hidden_state.shape							,					(self.batch_size, seq_length, self.hidden_size)		)
	def      _lowercase				(    self							,					_A							,					_A							,					_A		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.type_sequence_label_size
				UpperCAmelCase   		=				TFViTForImageClassification(_A		)
				UpperCAmelCase   		=				model(_A							,					labels=_A							,					training=_A		)
				self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.type_sequence_label_size)		)

				# Test with an image with different size than the one specified in config.
				UpperCAmelCase   		=				self.image_size // 2
				UpperCAmelCase   		=				pixel_values[:, :, :image_size, :image_size]
				UpperCAmelCase   		=				model(_A							,					interpolate_pos_encoding=_A							,					training=_A		)
				self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.type_sequence_label_size)		)

				# test greyscale images
				UpperCAmelCase   		=				1
				UpperCAmelCase   		=				TFViTForImageClassification(_A		)
				UpperCAmelCase   		=				floats_tensor([self.batch_size, 1, self.image_size, self.image_size]		)
				UpperCAmelCase   		=				model(_A		)
				self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.type_sequence_label_size)		)







	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.prepare_config_and_inputs()
				UpperCAmelCase		,			UpperCAmelCase		,			UpperCAmelCase   		=				config_and_inputs
				UpperCAmelCase   		=				{'''pixel_values''': pixel_values}
				return config, inputs_dict

@require_tf
class 	A_       (a_     ,							a_     ,							unittest.TestCase			):
	UpperCAmelCase__					=			(TFViTModel, TFViTForImageClassification) if is_tf_available() else ()
	UpperCAmelCase__					=			(
	    {'''feature-extraction''': TFViTModel, '''image-classification''': TFViTForImageClassification}
	    if is_tf_available()
	    else {}
	)

	UpperCAmelCase__					=			False
	UpperCAmelCase__					=			False
	UpperCAmelCase__					=			False
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				TFViTModelTester(self		)
				UpperCAmelCase   		=				ConfigTester(self							,					config_class=_A							,					has_text_modality=_A							,					hidden_size=3_7		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				self.config_tester.run_common_tests()
	@unittest.skip(reason='''ViT does not use inputs_embeds'''		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				pass
	@unittest.skip(reason='''ViT does not use inputs_embeds'''		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				pass
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase		,			UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
							UpperCAmelCase   		=				model_class(_A		)
							self.assertIsInstance(model.get_input_embeddings()							,					(tf.keras.layers.Layer)		)
							UpperCAmelCase   		=				model.get_output_embeddings()
							self.assertTrue(x is None or isinstance(_A							,					tf.keras.layers.Layer		)		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase		,			UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs_for_common()

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

							UpperCAmelCase   		=				['''pixel_values''']
							self.assertListEqual(arg_names[:1]							,					_A		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*_A		)
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_image_classification(*_A		)







	@slow
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				TFViTModel.from_pretrained('''google/vit-base-patch16-224'''		)
				self.assertIsNotNone(_A		)





def 						__SCREAMING_SNAKE_CASE  (				)  ->				Optional[Any]:







			'''simple docstring'''

			UpperCAmelCase   		=				Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png''' )
			return image






@require_tf
@require_vision
class 	A_       (unittest.TestCase			):
	@cached_property
	def      _lowercase				(    self		):






				'''simple docstring'''







				return ViTImageProcessor.from_pretrained('''google/vit-base-patch16-224'''		) if is_vision_available() else None







	@slow
	def      _lowercase				(    self		):






				'''simple docstring'''







				UpperCAmelCase   		=				TFViTForImageClassification.from_pretrained('''google/vit-base-patch16-224'''		)

				UpperCAmelCase   		=				self.default_image_processor
				UpperCAmelCase   		=				prepare_img()
				UpperCAmelCase   		=				image_processor(images=_A							,					return_tensors='''tf'''		)

				# forward pass
				UpperCAmelCase   		=				model(**_A		)

				# verify the logits
				UpperCAmelCase   		=				tf.TensorShape((1, 1_0_0_0)		)
				self.assertEqual(outputs.logits.shape							,					_A		)

				UpperCAmelCase   		=				tf.constant([-0.27_44, 0.82_15, -0.08_36]		)

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



