





"""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 		__snake_case :





 """simple docstring"""


 def __init__(   self ,						__lowerCamelCase ,						__lowerCamelCase=13 ,						__lowerCamelCase=7 ,						__lowerCamelCase=True ,						__lowerCamelCase=True ,						__lowerCamelCase=True ,						__lowerCamelCase=True ,						__lowerCamelCase=99 ,						__lowerCamelCase=[1, 1, 2] ,						__lowerCamelCase=1 ,						__lowerCamelCase=32 ,						__lowerCamelCase=4 ,						__lowerCamelCase=8 ,						__lowerCamelCase=37 ,						__lowerCamelCase="gelu_new" ,						__lowerCamelCase=0.1 ,						__lowerCamelCase=0.1 ,						__lowerCamelCase=0.0 ,						__lowerCamelCase=512 ,						__lowerCamelCase=3 ,						__lowerCamelCase=0.0_2 ,						__lowerCamelCase=3 ,						__lowerCamelCase=4 ,						__lowerCamelCase=None ,						__lowerCamelCase=False ,						):



     '''simple docstring'''




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

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

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Optional[int]									=					ids_tensor([self.batch_size, self.seq_length] ,						self.vocab_size  )

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

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

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

     __A   :						Optional[int]									=					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  UpperCamelCase__(   self ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						):



     '''simple docstring'''




     __A   :						Any									=					TFFunnelModel(config=__lowerCamelCase  )
     __A   :						Dict									=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
     __A   :						List[str]									=					model(__lowerCamelCase  )

     __A   :						Optional[int]									=					[input_ids, input_mask]
     __A   :						Tuple									=					model(__lowerCamelCase  )

     __A   :						Any									=					model(__lowerCamelCase  )
     self.parent.assertEqual(result.last_hidden_state.shape ,						(self.batch_size, self.seq_length, self.d_model)  )

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

     __A   :						Union[str, Any]									=					False
     __A   :						List[str]									=					TFFunnelModel(config=__lowerCamelCase  )
     __A   :						Union[str, Any]									=					model(__lowerCamelCase  )
     self.parent.assertEqual(result.last_hidden_state.shape ,						(self.batch_size, self.seq_length, self.d_model)  )

 def  UpperCamelCase__(   self ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						):



     '''simple docstring'''




     __A   :						Optional[Any]									=					TFFunnelBaseModel(config=__lowerCamelCase  )
     __A   :						Union[str, Any]									=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
     __A   :						Any									=					model(__lowerCamelCase  )

     __A   :						Tuple									=					[input_ids, input_mask]
     __A   :						Tuple									=					model(__lowerCamelCase  )

     __A   :						Any									=					model(__lowerCamelCase  )
     self.parent.assertEqual(result.last_hidden_state.shape ,						(self.batch_size, 2, self.d_model)  )

     __A   :						Optional[int]									=					False
     __A   :						List[Any]									=					TFFunnelBaseModel(config=__lowerCamelCase  )
     __A   :						int									=					model(__lowerCamelCase  )
     self.parent.assertEqual(result.last_hidden_state.shape ,						(self.batch_size, 3, self.d_model)  )

     __A   :						Optional[int]									=					False
     __A   :						List[Any]									=					TFFunnelBaseModel(config=__lowerCamelCase  )
     __A   :						int									=					model(__lowerCamelCase  )
     self.parent.assertEqual(result.last_hidden_state.shape ,						(self.batch_size, 2, self.d_model)  )

 def  UpperCamelCase__(   self ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						):



     '''simple docstring'''




     __A   :						str									=					TFFunnelForPreTraining(config=__lowerCamelCase  )
     __A   :						Optional[Any]									=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
     __A   :						Optional[int]									=					model(__lowerCamelCase  )
     self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.seq_length)  )

 def  UpperCamelCase__(   self ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						):



     '''simple docstring'''




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

 def  UpperCamelCase__(   self ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						):



     '''simple docstring'''




     __A   :						int									=					self.num_labels
     __A   :						int									=					TFFunnelForSequenceClassification(config=__lowerCamelCase  )
     __A   :						Tuple									=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
     __A   :						Dict									=					model(__lowerCamelCase  )
     self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.num_labels)  )

 def  UpperCamelCase__(   self ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						):



     '''simple docstring'''




     __A   :						Dict									=					self.num_choices
     __A   :						Any									=					TFFunnelForMultipleChoice(config=__lowerCamelCase  )
     __A   :						Union[str, Any]									=					tf.tile(tf.expand_dims(__lowerCamelCase ,						1  ) ,						(1, self.num_choices, 1)  )
     __A   :						str									=					tf.tile(tf.expand_dims(__lowerCamelCase ,						1  ) ,						(1, self.num_choices, 1)  )
     __A   :						int									=					tf.tile(tf.expand_dims(__lowerCamelCase ,						1  ) ,						(1, self.num_choices, 1)  )
     __A   :						Any									=					{
         '''input_ids''': multiple_choice_inputs_ids,
         '''attention_mask''': multiple_choice_input_mask,
         '''token_type_ids''': multiple_choice_token_type_ids,
     }
     __A   :						str									=					model(__lowerCamelCase  )
     self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.num_choices)  )

 def  UpperCamelCase__(   self ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						):



     '''simple docstring'''




     __A   :						Any									=					self.num_labels
     __A   :						Optional[int]									=					TFFunnelForTokenClassification(config=__lowerCamelCase  )
     __A   :						Any									=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
     __A   :						Any									=					model(__lowerCamelCase  )
     self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.seq_length, self.num_labels)  )

 def  UpperCamelCase__(   self ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						):



     '''simple docstring'''




     __A   :						int									=					TFFunnelForQuestionAnswering(config=__lowerCamelCase  )
     __A   :						str									=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
     __A   :						str									=					model(__lowerCamelCase  )
     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  UpperCamelCase__(   self  ):



     '''simple docstring'''




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






@require_tf
class 		__snake_case (		SCREAMING_SNAKE_CASE__							,							SCREAMING_SNAKE_CASE__							,							unittest.TestCase					):





 """simple docstring"""


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

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Union[str, Any]									=					TFFunnelModelTester(self  )
     __A   :						Union[str, Any]									=					ConfigTester(self ,						config_class=__lowerCamelCase  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     self.config_tester.run_common_tests()

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						int									=					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*__lowerCamelCase  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						List[str]									=					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_pretraining(*__lowerCamelCase  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						List[Any]									=					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_masked_lm(*__lowerCamelCase  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						int									=					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_token_classification(*__lowerCamelCase  )







 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						List[str]									=					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_question_answering(*__lowerCamelCase  )






@require_tf
class 		__snake_case (		SCREAMING_SNAKE_CASE__							,							unittest.TestCase					):





 """simple docstring"""


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

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Any									=					TFFunnelModelTester(self ,						base=__lowerCamelCase  )
     __A   :						Union[str, Any]									=					ConfigTester(self ,						config_class=__lowerCamelCase  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     self.config_tester.run_common_tests()

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						str									=					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_base_model(*__lowerCamelCase  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						Dict									=					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_sequence_classification(*__lowerCamelCase  )







 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						List[Any]									=					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_multiple_choice(*__lowerCamelCase  )











"""simple docstring"""



# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


a_			=      {
    """configuration_vivit""": ["""VIVIT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """VivitConfig"""],
}
try:
       if not is_vision_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       a_			=      ["""VivitImageProcessor"""]


try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       a_			=      [
           """VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """VivitModel""",
           """VivitPreTrainedModel""",
           """VivitForVideoClassification""",
       ]


if TYPE_CHECKING:
       from .configuration_vivit import VIVIT_PRETRAINED_CONFIG_ARCHIVE_MAP, VivitConfig

       try:
              if not is_vision_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .image_processing_vivit import VivitImageProcessor

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_vivit import (
                  VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
                  VivitForVideoClassification,
                  VivitModel,
                  VivitPreTrainedModel,
              )


else:
       import sys

       a_			=      _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)




