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



      def __init__(						self    ,			lowercase    ,			lowercase=13    ,			lowercase=7    ,			lowercase=True    ,			lowercase=True    ,			lowercase=True    ,			lowercase=True    ,			lowercase=99    ,			lowercase=[1, 1, 2]    ,			lowercase=1    ,			lowercase=32    ,			lowercase=4    ,			lowercase=8    ,			lowercase=37    ,			lowercase="gelu_new"    ,			lowercase=0.1    ,			lowercase=0.1    ,			lowercase=0.0    ,			lowercase=5_12    ,			lowercase=3    ,			lowercase=0.02    ,			lowercase=3    ,			lowercase=4    ,			lowercase=None    ,			lowercase=False    ,			)	->			Tuple:





        '''simple docstring'''





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

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



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





        '''simple docstring'''





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

        a__:     Dict										=	None
        if self.use_input_mask:
          a__:     Any										=	random_attention_mask([self.batch_size, self.seq_length])

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

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

        a__:     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   lowerCamelCase_   (						self    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			)	->			Optional[int]:





        '''simple docstring'''





        a__:     Union[str, Any]										=	TFFunnelModel(config=lowercase)
        a__:     List[str]										=	{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
        a__:     List[Any]										=	model(lowercase)

        a__:     int										=	[input_ids, input_mask]
        a__:     Dict										=	model(lowercase)

        a__:     Dict										=	model(lowercase)
        self.parent.assertEqual(result.last_hidden_state.shape    ,			(self.batch_size, self.seq_length, self.d_model))

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

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



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





        '''simple docstring'''





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

        a__:     List[Any]										=	[input_ids, input_mask]
        a__:     str										=	model(lowercase)

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

        a__:     str										=	False
        a__:     Any										=	TFFunnelBaseModel(config=lowercase)
        a__:     int										=	model(lowercase)
        self.parent.assertEqual(result.last_hidden_state.shape    ,			(self.batch_size, 3, self.d_model))

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



      def   lowerCamelCase_   (						self    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			)	->			str:





        '''simple docstring'''





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



      def   lowerCamelCase_   (						self    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			)	->			Dict:





        '''simple docstring'''





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



      def   lowerCamelCase_   (						self    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			)	->			Any:





        '''simple docstring'''





        a__:     int										=	self.num_labels
        a__:     Tuple										=	TFFunnelForSequenceClassification(config=lowercase)
        a__:     Tuple										=	{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
        a__:     Optional[Any]										=	model(lowercase)
        self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.num_labels))



      def   lowerCamelCase_   (						self    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			)	->			List[Any]:





        '''simple docstring'''





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



      def   lowerCamelCase_   (						self    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			)	->			str:





        '''simple docstring'''





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



      def   lowerCamelCase_   (						self    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			)	->			List[Any]:





        '''simple docstring'''





        a__:     Tuple										=	TFFunnelForQuestionAnswering(config=lowercase)
        a__:     str										=	{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
        a__:     Optional[Any]										=	model(lowercase)
        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   lowerCamelCase_   (						self)	->			List[Any]:





        '''simple docstring'''





        a__:     Any										=	self.prepare_config_and_inputs()
        (
            (
            a__
        )							,    (
            a__
        )							,    (
            a__
        )							,    (
            a__
        )							,    (
            a__
        )							,    (
            a__
        )							,    (
            a__
        )							,    
        ):     int										=	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       (     __lowerCAmelCase       ,      __lowerCAmelCase       ,      unittest.TestCase				):
      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   lowerCamelCase_   (						self)	->			Any:





        '''simple docstring'''





        a__:     Tuple										=	TFFunnelModelTester(self)
        a__:     Tuple										=	ConfigTester(self    ,			config_class=lowercase)



      def   lowerCamelCase_   (						self)	->			str:





        '''simple docstring'''





        self.config_tester.run_common_tests()



      def   lowerCamelCase_   (						self)	->			str:





        '''simple docstring'''





        a__:     Any										=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*lowercase)



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





        '''simple docstring'''





        a__:     Optional[int]										=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_pretraining(*lowercase)



      def   lowerCamelCase_   (						self)	->			Dict:





        '''simple docstring'''





        a__:     int										=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*lowercase)



      def   lowerCamelCase_   (						self)	->			Any:





        '''simple docstring'''





        a__:     Dict										=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*lowercase)



      def   lowerCamelCase_   (						self)	->			Dict:





        '''simple docstring'''





        a__:     List[str]										=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*lowercase)







@require_tf
class    __snake_case       (     __lowerCAmelCase       ,      unittest.TestCase				):
      a__        =		(
          (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
      )
      a__        =		False
      a__        =		False



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





        '''simple docstring'''





        a__:     List[Any]										=	TFFunnelModelTester(self    ,			base=lowercase)
        a__:     int										=	ConfigTester(self    ,			config_class=lowercase)



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





        '''simple docstring'''





        self.config_tester.run_common_tests()



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





        '''simple docstring'''





        a__:     Tuple										=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_base_model(*lowercase)



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





        '''simple docstring'''





        a__:     int										=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*lowercase)



      def   lowerCamelCase_   (						self)	->			int:





        '''simple docstring'''





        a__:     List[Any]										=	self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_multiple_choice(*lowercase)



"""simple docstring"""
from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowercase__					       =	logging.get_logger(__name__)

lowercase__					       =	{
    'MIT/ast-finetuned-audioset-10-10-0.4593': (
        'https://huggingface.co/MIT/ast-finetuned-audioset-10-10-0.4593/resolve/main/config.json'
    ),
}




class    __snake_case       (     __lowerCAmelCase				):
      a__        =		"""audio-spectrogram-transformer"""



      def __init__(						self    ,			lowercase=7_68    ,			lowercase=12    ,			lowercase=12    ,			lowercase=30_72    ,			lowercase="gelu"    ,			lowercase=0.0    ,			lowercase=0.0    ,			lowercase=0.02    ,			lowercase=1e-12    ,			lowercase=16    ,			lowercase=True    ,			lowercase=10    ,			lowercase=10    ,			lowercase=10_24    ,			lowercase=1_28    ,			**lowercase    ,			)	->			str:





        '''simple docstring'''





        super().__init__(**lowercase)

        a__:     Any										=	hidden_size
        a__:     int										=	num_hidden_layers
        a__:     Union[str, Any]										=	num_attention_heads
        a__:     Any										=	intermediate_size
        a__:     Union[str, Any]										=	hidden_act
        a__:     int										=	hidden_dropout_prob
        a__:     str										=	attention_probs_dropout_prob
        a__:     str										=	initializer_range
        a__:     Tuple										=	layer_norm_eps
        a__:     Any										=	patch_size
        a__:     int										=	qkv_bias
        a__:     Optional[Any]										=	frequency_stride
        a__:     int										=	time_stride
        a__:     List[str]										=	max_length
        a__:     Tuple										=	num_mel_bins


