


'''simple docstring'''


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


  '''simple docstring'''







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

        '''simple docstring'''




        A_						:  Any          =				parent
        A_						:  List[Any]          =				batch_size
        A_						:  Union[str, Any]          =				seq_length
        A_						:  List[Any]          =				is_training
        A_						:  List[Any]          =				use_input_mask
        A_						:  Tuple          =				use_token_type_ids
        A_						:  Any          =				use_labels
        A_						:  str          =				vocab_size
        A_						:  int          =				block_sizes
        A_						:  Dict          =				num_decoder_layers
        A_						:  Dict          =				d_model
        A_						:  Tuple          =				n_head
        A_						:  Tuple          =				d_head
        A_						:  str          =				d_inner
        A_						:  Dict          =				hidden_act
        A_						:  List[Any]          =				hidden_dropout
        A_						:  Union[str, Any]          =				attention_dropout
        A_						:  int          =				activation_dropout
        A_						:  Any          =				max_position_embeddings
        A_						:  Any          =				type_vocab_size
        A_						:  Optional[Any]          =				2
        A_						:  Dict          =				num_labels
        A_						:  str          =				num_choices
        A_						:  int          =				scope
        A_						:  List[Any]          =				initializer_std

        # Used in the tests to check the size of the first attention layer
        A_						:  Optional[int]          =				n_head
        # Used in the tests to check the size of the first hidden state
        A_						:  List[str]          =				self.d_model
        # Used in the tests to check the number of output hidden states/attentions
        A_						:  List[Any]          =				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_						:  int          =				self.num_hidden_layers + 2






  def        _a							(							self :       Any ):

        '''simple docstring'''




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

        A_						:  int          =				None
        if self.use_input_mask:
              A_						:  Union[str, Any]          =				random_attention_mask([self.batch_size, self.seq_length] )

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

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

        A_						:  List[Any]          =				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        _a							(							self :       Dict	,_a :       Optional[int]	,_a :       List[Any]	,_a :       int	,_a :       Optional[int]	,_a :       List[str]	,_a :       List[str]	,_a :       List[Any]	,):

        '''simple docstring'''




        A_						:  Tuple          =				TFFunnelModel(config=_a )
        A_						:  Tuple          =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
        A_						:  int          =				model(_a )

        A_						:  Tuple          =				[input_ids, input_mask]
        A_						:  Dict          =				model(_a )

        A_						:  Optional[int]          =				model(_a )
        self.parent.assertEqual(result.last_hidden_state.shape	,(self.batch_size, self.seq_length, self.d_model) )

        A_						:  Optional[Any]          =				False
        A_						:  Tuple          =				TFFunnelModel(config=_a )
        A_						:  Union[str, Any]          =				model(_a )
        self.parent.assertEqual(result.last_hidden_state.shape	,(self.batch_size, self.seq_length, self.d_model) )

        A_						:  int          =				False
        A_						:  List[Any]          =				TFFunnelModel(config=_a )
        A_						:  Optional[int]          =				model(_a )
        self.parent.assertEqual(result.last_hidden_state.shape	,(self.batch_size, self.seq_length, self.d_model) )






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

        '''simple docstring'''




        A_						:  Dict          =				TFFunnelBaseModel(config=_a )
        A_						:  Optional[int]          =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
        A_						:  List[Any]          =				model(_a )

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

        A_						:  List[str]          =				model(_a )
        self.parent.assertEqual(result.last_hidden_state.shape	,(self.batch_size, 2, self.d_model) )

        A_						:  Dict          =				False
        A_						:  Union[str, Any]          =				TFFunnelBaseModel(config=_a )
        A_						:  Optional[Any]          =				model(_a )
        self.parent.assertEqual(result.last_hidden_state.shape	,(self.batch_size, 3, self.d_model) )

        A_						:  List[Any]          =				False
        A_						:  Any          =				TFFunnelBaseModel(config=_a )
        A_						:  Union[str, Any]          =				model(_a )
        self.parent.assertEqual(result.last_hidden_state.shape	,(self.batch_size, 2, self.d_model) )






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

        '''simple docstring'''




        A_						:  int          =				TFFunnelForPreTraining(config=_a )
        A_						:  List[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, self.seq_length) )






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

        '''simple docstring'''




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






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

        '''simple docstring'''




        A_						:  Union[str, Any]          =				self.num_labels
        A_						:  Any          =				TFFunnelForSequenceClassification(config=_a )
        A_						:  List[str]          =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
        A_						:  List[str]          =				model(_a )
        self.parent.assertEqual(result.logits.shape	,(self.batch_size, self.num_labels) )






  def        _a							(							self :       Tuple	,_a :       Optional[Any]	,_a :       Optional[Any]	,_a :       List[str]	,_a :       Tuple	,_a :       Tuple	,_a :       List[str]	,_a :       Any	,):

        '''simple docstring'''




        A_						:  Union[str, Any]          =				self.num_choices
        A_						:  Union[str, Any]          =				TFFunnelForMultipleChoice(config=_a )
        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]          =				tf.tile(tf.expand_dims(_a	,1 )	,(1, self.num_choices, 1) )
        A_						:  Tuple          =				{
            """input_ids""": multiple_choice_inputs_ids,
            """attention_mask""": multiple_choice_input_mask,
            """token_type_ids""": multiple_choice_token_type_ids,
        }
        A_						:  Tuple          =				model(_a )
        self.parent.assertEqual(result.logits.shape	,(self.batch_size, self.num_choices) )






  def        _a							(							self :       Tuple	,_a :       Dict	,_a :       Optional[int]	,_a :       str	,_a :       List[Any]	,_a :       Optional[int]	,_a :       Tuple	,_a :       Tuple	,):

        '''simple docstring'''




        A_						:  Tuple          =				self.num_labels
        A_						:  Union[str, Any]          =				TFFunnelForTokenClassification(config=_a )
        A_						:  str          =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
        A_						:  int          =				model(_a )
        self.parent.assertEqual(result.logits.shape	,(self.batch_size, self.seq_length, self.num_labels) )






  def        _a							(							self :       Any	,_a :       Optional[Any]	,_a :       int	,_a :       Union[str, Any]	,_a :       Dict	,_a :       Tuple	,_a :       Union[str, Any]	,_a :       Tuple	,):

        '''simple docstring'''




        A_						:  Optional[Any]          =				TFFunnelForQuestionAnswering(config=_a )
        A_						:  Optional[int]          =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
        A_						:  List[Any]          =				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        _a							(							self :       Optional[Any] ):

        '''simple docstring'''




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







@require_tf
class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE  , __SCREAMING_SNAKE_CASE  , unittest.TestCase    ):


  '''simple docstring'''







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






  def        _a							(							self :       Any ):

        '''simple docstring'''




        A_						:  int          =				TFFunnelModelTester(self )
        A_						:  List[Any]          =				ConfigTester(self	,config_class=_a )






  def        _a							(							self :       Optional[Any] ):

        '''simple docstring'''




        self.config_tester.run_common_tests()






  def        _a							(							self :       int ):

        '''simple docstring'''




        A_						:  Tuple          =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*_a )






  def        _a							(							self :       Optional[Any] ):

        '''simple docstring'''




        A_						:  str          =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_pretraining(*_a )






  def        _a							(							self :       List[str] ):

        '''simple docstring'''




        A_						:  Any          =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*_a )






  def        _a							(							self :       List[str] ):

        '''simple docstring'''




        A_						:  int          =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*_a )






  def        _a							(							self :       int ):

        '''simple docstring'''




        A_						:  List[str]          =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*_a )







@require_tf
class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE  , unittest.TestCase    ):


  '''simple docstring'''







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






  def        _a							(							self :       List[Any] ):

        '''simple docstring'''




        A_						:  Dict          =				TFFunnelModelTester(self	,base=_a )
        A_						:  List[Any]          =				ConfigTester(self	,config_class=_a )






  def        _a							(							self :       str ):

        '''simple docstring'''




        self.config_tester.run_common_tests()






  def        _a							(							self :       Tuple ):

        '''simple docstring'''




        A_						:  Dict          =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_base_model(*_a )






  def        _a							(							self :       List[str] ):

        '''simple docstring'''




        A_						:  List[Any]          =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*_a )






  def        _a							(							self :       Optional[Any] ):

        '''simple docstring'''




        A_						:  int          =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_multiple_choice(*_a )




'''simple docstring'''


import warnings

from ...utils import logging
from .image_processing_owlvit import OwlViTImageProcessor


__magic_name__			=      logging.get_logger(__name__)



class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  def __init__(							self :       Union[str, Any]	,*_a :       Optional[Any]	,**_a :       Optional[int] ):

        '''simple docstring'''




        warnings.warn(
            """The class OwlViTFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please"""
            """ use OwlViTImageProcessor instead."""	,_a	,)
        super().__init__(*_a	,**_a )
