
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		:
    def __init__(  self		,snake_case		,snake_case=13		,snake_case=7		,snake_case=True		,snake_case=True		,snake_case=True		,snake_case=True		,snake_case=99		,snake_case=[1, 1, 2]		,snake_case=1		,snake_case=32		,snake_case=4		,snake_case=8		,snake_case=37		,snake_case="gelu_new"		,snake_case=0.1		,snake_case=0.1		,snake_case=0.0		,snake_case=512		,snake_case=3		,snake_case=0.02		,snake_case=3		,snake_case=4		,snake_case=None		,snake_case=False		,):



           '''simple docstring'''







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

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



           '''simple docstring'''







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

           lowercase							:					Optional[int]	     =				None
           if self.use_input_mask:
                  lowercase							:					int	     =				random_attention_mask([self.batch_size, self.seq_length]				)

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

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

           lowercase							:					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 				_SCREAMING_SNAKE_CASE	(  self		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,):



           '''simple docstring'''







           lowercase							:					Optional[Any]	     =				TFFunnelModel(config=snake_case				)
           lowercase							:					Union[str, Any]	     =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
           lowercase							:					Tuple	     =				model(snake_case				)

           lowercase							:					Union[str, Any]	     =				[input_ids, input_mask]
           lowercase							:					int	     =				model(snake_case				)

           lowercase							:					List[str]	     =				model(snake_case				)
           self.parent.assertEqual(result.last_hidden_state.shape		,(self.batch_size, self.seq_length, self.d_model)				)

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

           lowercase							:					Tuple	     =				False
           lowercase							:					Union[str, Any]	     =				TFFunnelModel(config=snake_case				)
           lowercase							:					str	     =				model(snake_case				)
           self.parent.assertEqual(result.last_hidden_state.shape		,(self.batch_size, self.seq_length, self.d_model)				)
    def 				_SCREAMING_SNAKE_CASE	(  self		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,):



           '''simple docstring'''







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

           lowercase							:					Union[str, Any]	     =				[input_ids, input_mask]
           lowercase							:					Tuple	     =				model(snake_case				)

           lowercase							:					Optional[Any]	     =				model(snake_case				)
           self.parent.assertEqual(result.last_hidden_state.shape		,(self.batch_size, 2, self.d_model)				)

           lowercase							:					Any	     =				False
           lowercase							:					Optional[Any]	     =				TFFunnelBaseModel(config=snake_case				)
           lowercase							:					Any	     =				model(snake_case				)
           self.parent.assertEqual(result.last_hidden_state.shape		,(self.batch_size, 3, self.d_model)				)

           lowercase							:					Union[str, Any]	     =				False
           lowercase							:					Optional[int]	     =				TFFunnelBaseModel(config=snake_case				)
           lowercase							:					Tuple	     =				model(snake_case				)
           self.parent.assertEqual(result.last_hidden_state.shape		,(self.batch_size, 2, self.d_model)				)
    def 				_SCREAMING_SNAKE_CASE	(  self		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,):



           '''simple docstring'''







           lowercase							:					int	     =				TFFunnelForPreTraining(config=snake_case				)
           lowercase							:					int	     =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
           lowercase							:					List[Any]	     =				model(snake_case				)
           self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.seq_length)				)
    def 				_SCREAMING_SNAKE_CASE	(  self		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,):



           '''simple docstring'''







           lowercase							:					Any	     =				TFFunnelForMaskedLM(config=snake_case				)
           lowercase							:					Dict	     =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
           lowercase							:					Any	     =				model(snake_case				)
           self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.seq_length, self.vocab_size)				)
    def 				_SCREAMING_SNAKE_CASE	(  self		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,):



           '''simple docstring'''







           lowercase							:					int	     =				self.num_labels
           lowercase							:					Tuple	     =				TFFunnelForSequenceClassification(config=snake_case				)
           lowercase							:					List[Any]	     =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
           lowercase							:					Union[str, Any]	     =				model(snake_case				)
           self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.num_labels)				)
    def 				_SCREAMING_SNAKE_CASE	(  self		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,):



           '''simple docstring'''







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



           '''simple docstring'''







           lowercase							:					Any	     =				self.num_labels
           lowercase							:					Tuple	     =				TFFunnelForTokenClassification(config=snake_case				)
           lowercase							:					List[Any]	     =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
           lowercase							:					Union[str, Any]	     =				model(snake_case				)
           self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.seq_length, self.num_labels)				)
    def 				_SCREAMING_SNAKE_CASE	(  self		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,):



           '''simple docstring'''







           lowercase							:					Union[str, Any]	     =				TFFunnelForQuestionAnswering(config=snake_case				)
           lowercase							:					str	     =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
           lowercase							:					List[Any]	     =				model(snake_case				)
           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				):



           '''simple docstring'''







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






@require_tf
class __snake_case		(				snake_case_ ,     snake_case_ ,     unittest.TestCase					):
    _a		:						List[Any]=    (
        (
            TFFunnelModel,
            TFFunnelForMaskedLM,
            TFFunnelForPreTraining,
            TFFunnelForQuestionAnswering,
            TFFunnelForTokenClassification,
        )
        if is_tf_available()
        else ()
    )
    _a		:						str=    (
        {
            "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		:						Union[str, Any]=    False
    _a		:						Optional[int]=    False
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           lowercase							:					Tuple	     =				TFFunnelModelTester(self				)
           lowercase							:					List[str]	     =				ConfigTester(self		,config_class=snake_case				)
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           self.config_tester.run_common_tests()
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           lowercase							:					List[str]	     =				self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*snake_case				)
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           lowercase							:					Tuple	     =				self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_pretraining(*snake_case				)
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           lowercase							:					Optional[int]	     =				self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_lm(*snake_case				)
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           lowercase							:					Dict	     =				self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*snake_case				)
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           lowercase							:					Dict	     =				self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_question_answering(*snake_case				)






@require_tf
class __snake_case		(				snake_case_ ,     unittest.TestCase					):
    _a		:						Dict=    (
        (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
    )
    _a		:						Tuple=    False
    _a		:						Tuple=    False
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           lowercase							:					Tuple	     =				TFFunnelModelTester(self		,base=snake_case				)
           lowercase							:					str	     =				ConfigTester(self		,config_class=snake_case				)
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           self.config_tester.run_common_tests()
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           lowercase							:					List[str]	     =				self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_base_model(*snake_case				)
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           lowercase							:					str	     =				self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_sequence_classification(*snake_case				)
    def 				_SCREAMING_SNAKE_CASE	(  self				):



           '''simple docstring'''







           lowercase							:					Dict	     =				self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_multiple_choice(*snake_case				)


from ...processing_utils import ProcessorMixin

class __snake_case		(				lowerCAmelCase					):
    _a		:						Union[str, Any]=    "WhisperFeatureExtractor"
    _a		:						int=    "WhisperTokenizer"
    def __init__(  self		,snake_case		,snake_case				):



           '''simple docstring'''







           super().__init__(snake_case		,snake_case				)
           lowercase							:					Optional[int]	     =				self.feature_extractor
           lowercase							:					Tuple	     =				False
    def 				_SCREAMING_SNAKE_CASE	(  self		,snake_case=None		,snake_case=None		,snake_case=True				):



           '''simple docstring'''







           return self.tokenizer.get_decoder_prompt_ids(task=snake_case		,language=snake_case		,no_timestamps=snake_case				)
    def __call__(  self		,*snake_case		,**snake_case				):



           '''simple docstring'''







           if self._in_target_context_manager:
                  return self.current_processor(*snake_case		,**snake_case				)

           lowercase							:					Optional[Any]	     =				kwargs.pop("""audio"""		,snake_case				)
           lowercase							:					str	     =				kwargs.pop("""sampling_rate"""		,snake_case				)
           lowercase							:					Dict	     =				kwargs.pop("""text"""		,snake_case				)
           if len(snake_case				) > 0:
                  lowercase							:					List[Any]	     =				args[0]
                  lowercase							:					Tuple	     =				args[1:]

           if audio is None and text is None:
                  raise ValueError("""You need to specify either an `audio` or `text` input to process."""				)

           if audio is not None:
                  lowercase							:					Any	     =				self.feature_extractor(snake_case		,*snake_case		,sampling_rate=snake_case		,**snake_case				)
           if text is not None:
                  lowercase							:					str	     =				self.tokenizer(snake_case		,**snake_case				)

           if text is None:
                  return inputs

           elif audio is None:
                  return encodings
           else:
                  lowercase							:					List[Any]	     =				encodings["""input_ids"""]
                  return inputs
    def 				_SCREAMING_SNAKE_CASE	(  self		,*snake_case		,**snake_case				):



           '''simple docstring'''







           return self.tokenizer.batch_decode(*snake_case		,**snake_case				)
    def 				_SCREAMING_SNAKE_CASE	(  self		,*snake_case		,**snake_case				):



           '''simple docstring'''







           return self.tokenizer.decode(*snake_case		,**snake_case				)
    def 				_SCREAMING_SNAKE_CASE	(  self		,snake_case		,snake_case="np"				):



           '''simple docstring'''







           return self.tokenizer.get_prompt_ids(snake_case		,return_tensors=snake_case				)
