


from __future__ import annotations

import unittest

from transformers import FunnelConfig, is_tf_available
from transformers.testing_utils import require_tf

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 (
      TFFunnelBaseModel,
      TFFunnelForMaskedLM,
      TFFunnelForMultipleChoice,
      TFFunnelForPreTraining,
      TFFunnelForQuestionAnswering,
      TFFunnelForSequenceClassification,
      TFFunnelForTokenClassification,
      TFFunnelModel,
  )


class        UpperCamelCase_					:

    '''simple docstring'''






    def __init__(    self   :			List[str]      ,				UpperCAmelCase__   :			int      ,				UpperCAmelCase__   :			Optional[int]=13      ,				UpperCAmelCase__   :			Tuple=7      ,				UpperCAmelCase__   :			Any=True      ,				UpperCAmelCase__   :			int=True      ,				UpperCAmelCase__   :			List[str]=True      ,				UpperCAmelCase__   :			Dict=True      ,				UpperCAmelCase__   :			Dict=99      ,				UpperCAmelCase__   :			Union[str, Any]=[1, 1, 2]      ,				UpperCAmelCase__   :			List[Any]=1      ,				UpperCAmelCase__   :			int=32      ,				UpperCAmelCase__   :			Union[str, Any]=4      ,				UpperCAmelCase__   :			Optional[int]=8      ,				UpperCAmelCase__   :			List[Any]=37      ,				UpperCAmelCase__   :			str="gelu_new"      ,				UpperCAmelCase__   :			Optional[Any]=0.1      ,				UpperCAmelCase__   :			Optional[Any]=0.1      ,				UpperCAmelCase__   :			List[str]=0.0      ,				UpperCAmelCase__   :			str=512      ,				UpperCAmelCase__   :			Optional[int]=3      ,				UpperCAmelCase__   :			str=0.02      ,				UpperCAmelCase__   :			List[str]=3      ,				UpperCAmelCase__   :			Any=4      ,				UpperCAmelCase__   :			List[str]=None      ,				UpperCAmelCase__   :			Dict=False      ,				)		->Optional[int]:





           '''simple docstring'''

           A__   				=					parent
           A__   				=					batch_size
           A__   				=					seq_length
           A__   				=					is_training
           A__   				=					use_input_mask
           A__   				=					use_token_type_ids
           A__   				=					use_labels
           A__   				=					vocab_size
           A__   				=					block_sizes
           A__   				=					num_decoder_layers
           A__   				=					d_model
           A__   				=					n_head
           A__   				=					d_head
           A__   				=					d_inner
           A__   				=					hidden_act
           A__   				=					hidden_dropout
           A__   				=					attention_dropout
           A__   				=					activation_dropout
           A__   				=					max_position_embeddings
           A__   				=					type_vocab_size
           A__   				=					2
           A__   				=					num_labels
           A__   				=					num_choices
           A__   				=					scope
           A__   				=					initializer_std

           # Used in the tests to check the size of the first attention layer
           A__   				=					n_head
           # Used in the tests to check the size of the first hidden state
           A__   				=					self.d_model
           # Used in the tests to check the number of output hidden states/attentions
           A__   				=					sum(self.block_sizes) + (0 if base else self.num_decoder_layers)
           # FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
           # the last hidden state of the first block (which is the first hidden state of the decoder).
           if not base:
                  A__   				=					self.num_hidden_layers + 2


    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[int])		->Dict:





           '''simple docstring'''

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

           A__   				=					None
           if self.use_input_mask:
                  A__   				=					random_attention_mask([self.batch_size, self.seq_length])

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

           A__   				=					None
           A__   				=					None
           A__   				=					None
           if self.use_labels:
                  A__   				=					ids_tensor([self.batch_size]      ,				self.type_sequence_label_size)
                  A__   				=					ids_tensor([self.batch_size, self.seq_length]      ,				self.num_labels)
                  A__   				=					ids_tensor([self.batch_size]      ,				self.num_choices)

           A__   				=					FunnelConfig(
               vocab_size=self.vocab_size      ,				block_sizes=self.block_sizes      ,				num_decoder_layers=self.num_decoder_layers      ,				d_model=self.d_model      ,				n_head=self.n_head      ,				d_head=self.d_head      ,				d_inner=self.d_inner      ,				hidden_act=self.hidden_act      ,				hidden_dropout=self.hidden_dropout      ,				attention_dropout=self.attention_dropout      ,				activation_dropout=self.activation_dropout      ,				max_position_embeddings=self.max_position_embeddings      ,				type_vocab_size=self.type_vocab_size      ,				initializer_std=self.initializer_std      ,				)

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


    def  SCREAMING_SNAKE_CASE							(    self   :			str      ,				UpperCAmelCase__   :			Optional[int]      ,				UpperCAmelCase__   :			List[str]      ,				UpperCAmelCase__   :			Optional[Any]      ,				UpperCAmelCase__   :			int      ,				UpperCAmelCase__   :			int      ,				UpperCAmelCase__   :			List[str]      ,				UpperCAmelCase__   :			List[Any]      ,				)		->Optional[Any]:





           '''simple docstring'''

           A__   				=					TFFunnelModel(config=UpperCamelCase__)
           A__   				=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           A__   				=					model(UpperCamelCase__)

           A__   				=					[input_ids, input_mask]
           A__   				=					model(UpperCamelCase__)

           A__   				=					model(UpperCamelCase__)
           self.parent.assertEqual(result.last_hidden_state.shape      ,				(self.batch_size, self.seq_length, self.d_model))

           A__   				=					False
           A__   				=					TFFunnelModel(config=UpperCamelCase__)
           A__   				=					model(UpperCamelCase__)
           self.parent.assertEqual(result.last_hidden_state.shape      ,				(self.batch_size, self.seq_length, self.d_model))

           A__   				=					False
           A__   				=					TFFunnelModel(config=UpperCamelCase__)
           A__   				=					model(UpperCamelCase__)
           self.parent.assertEqual(result.last_hidden_state.shape      ,				(self.batch_size, self.seq_length, self.d_model))


    def  SCREAMING_SNAKE_CASE							(    self   :			Dict      ,				UpperCAmelCase__   :			Dict      ,				UpperCAmelCase__   :			Union[str, Any]      ,				UpperCAmelCase__   :			Union[str, Any]      ,				UpperCAmelCase__   :			Tuple      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			Tuple      ,				UpperCAmelCase__   :			List[Any]      ,				)		->Dict:





           '''simple docstring'''

           A__   				=					TFFunnelBaseModel(config=UpperCamelCase__)
           A__   				=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           A__   				=					model(UpperCamelCase__)

           A__   				=					[input_ids, input_mask]
           A__   				=					model(UpperCamelCase__)

           A__   				=					model(UpperCamelCase__)
           self.parent.assertEqual(result.last_hidden_state.shape      ,				(self.batch_size, 2, self.d_model))

           A__   				=					False
           A__   				=					TFFunnelBaseModel(config=UpperCamelCase__)
           A__   				=					model(UpperCamelCase__)
           self.parent.assertEqual(result.last_hidden_state.shape      ,				(self.batch_size, 3, self.d_model))

           A__   				=					False
           A__   				=					TFFunnelBaseModel(config=UpperCamelCase__)
           A__   				=					model(UpperCamelCase__)
           self.parent.assertEqual(result.last_hidden_state.shape      ,				(self.batch_size, 2, self.d_model))


    def  SCREAMING_SNAKE_CASE							(    self   :			int      ,				UpperCAmelCase__   :			Union[str, Any]      ,				UpperCAmelCase__   :			List[Any]      ,				UpperCAmelCase__   :			Tuple      ,				UpperCAmelCase__   :			List[str]      ,				UpperCAmelCase__   :			List[str]      ,				UpperCAmelCase__   :			List[str]      ,				UpperCAmelCase__   :			List[str]      ,				)		->List[Any]:





           '''simple docstring'''

           A__   				=					TFFunnelForPreTraining(config=UpperCamelCase__)
           A__   				=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           A__   				=					model(UpperCamelCase__)
           self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.seq_length))


    def  SCREAMING_SNAKE_CASE							(    self   :			List[Any]      ,				UpperCAmelCase__   :			int      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			List[str]      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			Optional[Any]      ,				UpperCAmelCase__   :			Optional[int]      ,				UpperCAmelCase__   :			Any      ,				)		->Optional[Any]:





           '''simple docstring'''

           A__   				=					TFFunnelForMaskedLM(config=UpperCamelCase__)
           A__   				=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           A__   				=					model(UpperCamelCase__)
           self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.seq_length, self.vocab_size))


    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[int]      ,				UpperCAmelCase__   :			Tuple      ,				UpperCAmelCase__   :			Union[str, Any]      ,				UpperCAmelCase__   :			int      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			List[str]      ,				UpperCAmelCase__   :			Optional[int]      ,				)		->List[str]:





           '''simple docstring'''

           A__   				=					self.num_labels
           A__   				=					TFFunnelForSequenceClassification(config=UpperCamelCase__)
           A__   				=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           A__   				=					model(UpperCamelCase__)
           self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.num_labels))


    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[int]      ,				UpperCAmelCase__   :			Tuple      ,				UpperCAmelCase__   :			Optional[Any]      ,				UpperCAmelCase__   :			Dict      ,				UpperCAmelCase__   :			Dict      ,				UpperCAmelCase__   :			str      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			str      ,				)		->Optional[int]:





           '''simple docstring'''

           A__   				=					self.num_choices
           A__   				=					TFFunnelForMultipleChoice(config=UpperCamelCase__)
           A__   				=					tf.tile(tf.expand_dims(UpperCamelCase__      ,				1)      ,				(1, self.num_choices, 1))
           A__   				=					tf.tile(tf.expand_dims(UpperCamelCase__      ,				1)      ,				(1, self.num_choices, 1))
           A__   				=					tf.tile(tf.expand_dims(UpperCamelCase__      ,				1)      ,				(1, self.num_choices, 1))
           A__   				=					{
               '''input_ids''': multiple_choice_inputs_ids,
               '''attention_mask''': multiple_choice_input_mask,
               '''token_type_ids''': multiple_choice_token_type_ids,
           }
           A__   				=					model(UpperCamelCase__)
           self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.num_choices))


    def  SCREAMING_SNAKE_CASE							(    self   :			List[str]      ,				UpperCAmelCase__   :			Tuple      ,				UpperCAmelCase__   :			int      ,				UpperCAmelCase__   :			List[str]      ,				UpperCAmelCase__   :			str      ,				UpperCAmelCase__   :			int      ,				UpperCAmelCase__   :			Dict      ,				UpperCAmelCase__   :			Tuple      ,				)		->Optional[int]:





           '''simple docstring'''

           A__   				=					self.num_labels
           A__   				=					TFFunnelForTokenClassification(config=UpperCamelCase__)
           A__   				=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           A__   				=					model(UpperCamelCase__)
           self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.seq_length, self.num_labels))


    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[int]      ,				UpperCAmelCase__   :			str      ,				UpperCAmelCase__   :			List[Any]      ,				UpperCAmelCase__   :			str      ,				UpperCAmelCase__   :			List[str]      ,				UpperCAmelCase__   :			Tuple      ,				UpperCAmelCase__   :			Optional[int]      ,				UpperCAmelCase__   :			int      ,				)		->str:





           '''simple docstring'''

           A__   				=					TFFunnelForQuestionAnswering(config=UpperCamelCase__)
           A__   				=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           A__   				=					model(UpperCamelCase__)
           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   :			Optional[Any])		->int:





           '''simple docstring'''

           A__   				=					self.prepare_config_and_inputs()
           (
               (
               A__					
           )				,							(
               A__					
           )				,							(
               A__					
           )				,							(
               A__					
           )				,							(
               A__					
           )				,							(
               A__					
           )				,							(
               A__					
           )				,												
           )   				=					config_and_inputs
           A__   				=					{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
           return config, inputs_dict


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

    '''simple docstring'''






    UpperCAmelCase__													=   (
        (
            TFFunnelModel,
            TFFunnelForMaskedLM,
            TFFunnelForPreTraining,
            TFFunnelForQuestionAnswering,
            TFFunnelForTokenClassification,
        )
        if is_tf_available()
        else ()
    )
    UpperCAmelCase__													=   (
        {
            '''feature-extraction''': (TFFunnelBaseModel, TFFunnelModel),
            '''fill-mask''': TFFunnelForMaskedLM,
            '''question-answering''': TFFunnelForQuestionAnswering,
            '''text-classification''': TFFunnelForSequenceClassification,
            '''token-classification''': TFFunnelForTokenClassification,
            '''zero-shot''': TFFunnelForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )
    UpperCAmelCase__													=   False
    UpperCAmelCase__													=   False


    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[int])		->str:





           '''simple docstring'''

           A__   				=					TFFunnelModelTester(self)
           A__   				=					ConfigTester(self      ,				config_class=UpperCamelCase__)


    def  SCREAMING_SNAKE_CASE							(    self   :			Tuple)		->Any:





           '''simple docstring'''

           self.config_tester.run_common_tests()


    def  SCREAMING_SNAKE_CASE							(    self   :			Any)		->Union[str, Any]:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*UpperCamelCase__)


    def  SCREAMING_SNAKE_CASE							(    self   :			List[str])		->Optional[Any]:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_pretraining(*UpperCamelCase__)


    def  SCREAMING_SNAKE_CASE							(    self   :			Tuple)		->Union[str, Any]:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase__)


    def  SCREAMING_SNAKE_CASE							(    self   :			Dict)		->int:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*UpperCamelCase__)





    def  SCREAMING_SNAKE_CASE							(    self   :			Any)		->Union[str, Any]:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_question_answering(*UpperCamelCase__)


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

    '''simple docstring'''






    UpperCAmelCase__													=   (
        (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
    )
    UpperCAmelCase__													=   False
    UpperCAmelCase__													=   False


    def  SCREAMING_SNAKE_CASE							(    self   :			Union[str, Any])		->Tuple:





           '''simple docstring'''

           A__   				=					TFFunnelModelTester(self      ,				base=UpperCamelCase__)
           A__   				=					ConfigTester(self      ,				config_class=UpperCamelCase__)


    def  SCREAMING_SNAKE_CASE							(    self   :			Dict)		->Any:





           '''simple docstring'''

           self.config_tester.run_common_tests()


    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[int])		->Optional[int]:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_base_model(*UpperCamelCase__)


    def  SCREAMING_SNAKE_CASE							(    self   :			List[str])		->Any:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase__)





    def  SCREAMING_SNAKE_CASE							(    self   :			int)		->Dict:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_multiple_choice(*UpperCamelCase__)








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        UpperCamelCase_					:

    '''simple docstring'''






    def __init__(    self   :			Dict      ,				UpperCAmelCase__   :			Optional[Any]      ,				UpperCAmelCase__   :			str=13      ,				UpperCAmelCase__   :			Union[str, Any]=30      ,				UpperCAmelCase__   :			List[str]=2      ,				UpperCAmelCase__   :			List[Any]=3      ,				UpperCAmelCase__   :			int=True      ,				UpperCAmelCase__   :			Tuple=True      ,				UpperCAmelCase__   :			Optional[int]=32      ,				UpperCAmelCase__   :			Tuple=2      ,				UpperCAmelCase__   :			Optional[Any]=4      ,				UpperCAmelCase__   :			Any=37      ,				UpperCAmelCase__   :			List[Any]="gelu"      ,				UpperCAmelCase__   :			Dict=0.1      ,				UpperCAmelCase__   :			List[Any]=0.1      ,				UpperCAmelCase__   :			Union[str, Any]=10      ,				UpperCAmelCase__   :			int=0.02      ,				UpperCAmelCase__   :			Optional[Any]=3      ,				UpperCAmelCase__   :			List[Any]=None      ,				)		->Dict:





           '''simple docstring'''

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

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


    def  SCREAMING_SNAKE_CASE							(    self   :			List[Any])		->List[Any]:





           '''simple docstring'''

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

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

           A__   				=					self.get_config()

           return config, pixel_values, labels


    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[Any])		->Optional[int]:





           '''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=UpperCAmelCase__      ,				initializer_range=self.initializer_range      ,				)


    def  SCREAMING_SNAKE_CASE							(    self   :			List[Any]      ,				UpperCAmelCase__   :			List[str]      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			str)		->Tuple:





           '''simple docstring'''

           A__   				=					TFViTModel(config=UpperCAmelCase__)
           A__   				=					model(UpperCAmelCase__      ,				training=UpperCAmelCase__)
           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.
           A__   				=					self.image_size // 2
           A__   				=					pixel_values[:, :, :image_size, :image_size]
           A__   				=					model(UpperCAmelCase__      ,				interpolate_pos_encoding=UpperCAmelCase__      ,				training=UpperCAmelCase__)
           A__   				=					(image_size // self.patch_size) ** 2 + 1
           self.parent.assertEqual(result.last_hidden_state.shape      ,				(self.batch_size, seq_length, self.hidden_size))


    def  SCREAMING_SNAKE_CASE							(    self   :			Any      ,				UpperCAmelCase__   :			Tuple      ,				UpperCAmelCase__   :			List[Any]      ,				UpperCAmelCase__   :			List[str])		->List[str]:





           '''simple docstring'''

           A__   				=					self.type_sequence_label_size
           A__   				=					TFViTForImageClassification(UpperCAmelCase__)
           A__   				=					model(UpperCAmelCase__      ,				labels=UpperCAmelCase__      ,				training=UpperCAmelCase__)
           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.
           A__   				=					self.image_size // 2
           A__   				=					pixel_values[:, :, :image_size, :image_size]
           A__   				=					model(UpperCAmelCase__      ,				interpolate_pos_encoding=UpperCAmelCase__      ,				training=UpperCAmelCase__)
           self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.type_sequence_label_size))

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





    def  SCREAMING_SNAKE_CASE							(    self   :			List[Any])		->int:





           '''simple docstring'''

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


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

    '''simple docstring'''






    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  SCREAMING_SNAKE_CASE							(    self   :			int)		->Optional[int]:





           '''simple docstring'''

           A__   				=					TFViTModelTester(self)
           A__   				=					ConfigTester(self      ,				config_class=UpperCAmelCase__      ,				has_text_modality=UpperCAmelCase__      ,				hidden_size=37)


    def  SCREAMING_SNAKE_CASE							(    self   :			str)		->List[str]:





           '''simple docstring'''

           self.config_tester.run_common_tests()


    @unittest.skip(reason='''ViT does not use inputs_embeds''')
    def  SCREAMING_SNAKE_CASE							(    self   :			List[Any])		->Tuple:





           '''simple docstring'''

           pass


    @unittest.skip(reason='''ViT does not use inputs_embeds''')
    def  SCREAMING_SNAKE_CASE							(    self   :			int)		->Optional[Any]:





           '''simple docstring'''

           pass


    def  SCREAMING_SNAKE_CASE							(    self   :			int)		->List[Any]:





           '''simple docstring'''

           A__				,							A__   				=					self.model_tester.prepare_config_and_inputs_for_common()

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


    def  SCREAMING_SNAKE_CASE							(    self   :			int)		->Any:





           '''simple docstring'''

           A__				,							A__   				=					self.model_tester.prepare_config_and_inputs_for_common()

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

                  A__   				=					['''pixel_values''']
                  self.assertListEqual(arg_names[:1]      ,				UpperCAmelCase__)


    def  SCREAMING_SNAKE_CASE							(    self   :			List[Any])		->Optional[int]:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*UpperCAmelCase__)


    def  SCREAMING_SNAKE_CASE							(    self   :			Dict)		->Optional[Any]:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_image_classification(*UpperCAmelCase__)





    @slow
    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[int])		->List[Any]:





           '''simple docstring'''

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







def SCREAMING_SNAKE_CASE       ( )     -> int:



       """simple docstring"""

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


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

    '''simple docstring'''






    @cached_property
    def  SCREAMING_SNAKE_CASE							(    self   :			Dict)		->Optional[Any]:





           '''simple docstring'''

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





    @slow
    def  SCREAMING_SNAKE_CASE							(    self   :			Any)		->int:





           '''simple docstring'''

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

           A__   				=					self.default_image_processor
           A__   				=					prepare_img()
           A__   				=					image_processor(images=UpperCAmelCase__      ,				return_tensors='''tf''')

           # forward pass
           A__   				=					model(**UpperCAmelCase__)

           # verify the logits
           A__   				=					tf.TensorShape((1, 1_000))
           self.assertEqual(outputs.logits.shape      ,				UpperCAmelCase__)

           A__   				=					tf.constant([-0.2744, 0.8215, -0.0836])

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


