

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






				'''simple docstring'''







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

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






				'''simple docstring'''







				_UpperCAmelCase     :				Union[str, Any]          =       ids_tensor([self.batch_size, self.seq_length]   ,		self.vocab_size  )

				_UpperCAmelCase     :				int          =       None
				if self.use_input_mask:
					_UpperCAmelCase     :				List[Any]          =       random_attention_mask([self.batch_size, self.seq_length]  )

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

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

				_UpperCAmelCase     :				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 				__snake_case			(		self   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		)     ->     str:






				'''simple docstring'''







				_UpperCAmelCase     :				Any          =       TFFunnelModel(config=lowerCamelCase__  )
				_UpperCAmelCase     :				Tuple          =       {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
				_UpperCAmelCase     :				Dict          =       model(lowerCamelCase__  )

				_UpperCAmelCase     :				List[Any]          =       [input_ids, input_mask]
				_UpperCAmelCase     :				Dict          =       model(lowerCamelCase__  )

				_UpperCAmelCase     :				Union[str, Any]          =       model(lowerCamelCase__  )
				self.parent.assertEqual(result.last_hidden_state.shape   ,		(self.batch_size, self.seq_length, self.d_model)  )

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

				_UpperCAmelCase     :				Any          =       False
				_UpperCAmelCase     :				Any          =       TFFunnelModel(config=lowerCamelCase__  )
				_UpperCAmelCase     :				Any          =       model(lowerCamelCase__  )
				self.parent.assertEqual(result.last_hidden_state.shape   ,		(self.batch_size, self.seq_length, self.d_model)  )
			def 				__snake_case			(		self   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		)     ->     int:






				'''simple docstring'''







				_UpperCAmelCase     :				Optional[Any]          =       TFFunnelBaseModel(config=lowerCamelCase__  )
				_UpperCAmelCase     :				Optional[int]          =       {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
				_UpperCAmelCase     :				Tuple          =       model(lowerCamelCase__  )

				_UpperCAmelCase     :				List[str]          =       [input_ids, input_mask]
				_UpperCAmelCase     :				List[str]          =       model(lowerCamelCase__  )

				_UpperCAmelCase     :				Optional[int]          =       model(lowerCamelCase__  )
				self.parent.assertEqual(result.last_hidden_state.shape   ,		(self.batch_size, 2, self.d_model)  )

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

				_UpperCAmelCase     :				Any          =       False
				_UpperCAmelCase     :				int          =       TFFunnelBaseModel(config=lowerCamelCase__  )
				_UpperCAmelCase     :				Any          =       model(lowerCamelCase__  )
				self.parent.assertEqual(result.last_hidden_state.shape   ,		(self.batch_size, 2, self.d_model)  )
			def 				__snake_case			(		self   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		)     ->     Dict:






				'''simple docstring'''







				_UpperCAmelCase     :				Tuple          =       TFFunnelForPreTraining(config=lowerCamelCase__  )
				_UpperCAmelCase     :				Optional[int]          =       {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
				_UpperCAmelCase     :				int          =       model(lowerCamelCase__  )
				self.parent.assertEqual(result.logits.shape   ,		(self.batch_size, self.seq_length)  )
			def 				__snake_case			(		self   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		)     ->     Union[str, Any]:






				'''simple docstring'''







				_UpperCAmelCase     :				Union[str, Any]          =       TFFunnelForMaskedLM(config=lowerCamelCase__  )
				_UpperCAmelCase     :				int          =       {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
				_UpperCAmelCase     :				Optional[Any]          =       model(lowerCamelCase__  )
				self.parent.assertEqual(result.logits.shape   ,		(self.batch_size, self.seq_length, self.vocab_size)  )
			def 				__snake_case			(		self   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		)     ->     Tuple:






				'''simple docstring'''







				_UpperCAmelCase     :				Union[str, Any]          =       self.num_labels
				_UpperCAmelCase     :				int          =       TFFunnelForSequenceClassification(config=lowerCamelCase__  )
				_UpperCAmelCase     :				Tuple          =       {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
				_UpperCAmelCase     :				List[str]          =       model(lowerCamelCase__  )
				self.parent.assertEqual(result.logits.shape   ,		(self.batch_size, self.num_labels)  )
			def 				__snake_case			(		self   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		)     ->     List[str]:






				'''simple docstring'''







				_UpperCAmelCase     :				Union[str, Any]          =       self.num_choices
				_UpperCAmelCase     :				int          =       TFFunnelForMultipleChoice(config=lowerCamelCase__  )
				_UpperCAmelCase     :				Any          =       tf.tile(tf.expand_dims(lowerCamelCase__   ,		1  )   ,		(1, self.num_choices, 1)  )
				_UpperCAmelCase     :				Any          =       tf.tile(tf.expand_dims(lowerCamelCase__   ,		1  )   ,		(1, self.num_choices, 1)  )
				_UpperCAmelCase     :				str          =       tf.tile(tf.expand_dims(lowerCamelCase__   ,		1  )   ,		(1, self.num_choices, 1)  )
				_UpperCAmelCase     :				str          =       {
				    """input_ids""": multiple_choice_inputs_ids,
				    """attention_mask""": multiple_choice_input_mask,
				    """token_type_ids""": multiple_choice_token_type_ids,
				}
				_UpperCAmelCase     :				List[Any]          =       model(lowerCamelCase__  )
				self.parent.assertEqual(result.logits.shape   ,		(self.batch_size, self.num_choices)  )
			def 				__snake_case			(		self   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		)     ->     List[Any]:






				'''simple docstring'''







				_UpperCAmelCase     :				Dict          =       self.num_labels
				_UpperCAmelCase     :				str          =       TFFunnelForTokenClassification(config=lowerCamelCase__  )
				_UpperCAmelCase     :				Dict          =       {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
				_UpperCAmelCase     :				Optional[int]          =       model(lowerCamelCase__  )
				self.parent.assertEqual(result.logits.shape   ,		(self.batch_size, self.seq_length, self.num_labels)  )
			def 				__snake_case			(		self   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A   ,		)     ->     List[Any]:






				'''simple docstring'''







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






				'''simple docstring'''







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






@require_tf
class      _UpperCAmelCase      (		__UpperCAmelCase     ,  __UpperCAmelCase     ,  unittest.TestCase):
			__a			:							List[Any]					       =				(
			    (
			        TFFunnelModel,
			        TFFunnelForMaskedLM,
			        TFFunnelForPreTraining,
			        TFFunnelForQuestionAnswering,
			        TFFunnelForTokenClassification,
			    )
			    if is_tf_available()
			    else ()
			)
			__a			:							Dict					       =				(
			    {
			        '''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			:							str					       =				False
			__a			:							Optional[int]					       =				False
			def 				__snake_case			(		self  )     ->     int:






				'''simple docstring'''







				_UpperCAmelCase     :				Tuple          =       TFFunnelModelTester(self  )
				_UpperCAmelCase     :				Any          =       ConfigTester(self   ,		config_class=lowerCamelCase__  )
			def 				__snake_case			(		self  )     ->     Any:






				'''simple docstring'''







				self.config_tester.run_common_tests()
			def 				__snake_case			(		self  )     ->     Optional[Any]:






				'''simple docstring'''







				_UpperCAmelCase     :				Optional[Any]          =       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*lowerCamelCase__  )
			def 				__snake_case			(		self  )     ->     Optional[Any]:






				'''simple docstring'''







				_UpperCAmelCase     :				Dict          =       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_pretraining(*lowerCamelCase__  )
			def 				__snake_case			(		self  )     ->     Tuple:






				'''simple docstring'''







				_UpperCAmelCase     :				str          =       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_masked_lm(*lowerCamelCase__  )
			def 				__snake_case			(		self  )     ->     Dict:






				'''simple docstring'''







				_UpperCAmelCase     :				Dict          =       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_token_classification(*lowerCamelCase__  )
			def 				__snake_case			(		self  )     ->     Optional[Any]:






				'''simple docstring'''







				_UpperCAmelCase     :				List[Any]          =       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_question_answering(*lowerCamelCase__  )






@require_tf
class      _UpperCAmelCase      (		__UpperCAmelCase     ,  unittest.TestCase):
			__a			:							int					       =				(
			    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
			)
			__a			:							Tuple					       =				False
			__a			:							List[str]					       =				False
			def 				__snake_case			(		self  )     ->     int:






				'''simple docstring'''







				_UpperCAmelCase     :				Optional[Any]          =       TFFunnelModelTester(self   ,		base=lowerCamelCase__  )
				_UpperCAmelCase     :				Any          =       ConfigTester(self   ,		config_class=lowerCamelCase__  )
			def 				__snake_case			(		self  )     ->     List[Any]:






				'''simple docstring'''







				self.config_tester.run_common_tests()
			def 				__snake_case			(		self  )     ->     int:






				'''simple docstring'''







				_UpperCAmelCase     :				Union[str, Any]          =       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_base_model(*lowerCamelCase__  )
			def 				__snake_case			(		self  )     ->     Dict:






				'''simple docstring'''







				_UpperCAmelCase     :				Optional[Any]          =       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_sequence_classification(*lowerCamelCase__  )
			def 				__snake_case			(		self  )     ->     Dict:






				'''simple docstring'''







				_UpperCAmelCase     :				int          =       self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_multiple_choice(*lowerCamelCase__  )









"""simple docstring"""


from typing import TYPE_CHECKING

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__snake_case    					=					{'configuration_mmbt': ['MMBTConfig']}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   __snake_case    					=					['MMBTForClassification', 'MMBTModel', 'ModalEmbeddings']


if TYPE_CHECKING:
   from .configuration_mmbt import MMBTConfig

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_mmbt import MMBTForClassification, MMBTModel, ModalEmbeddings

else:
   import sys

   __snake_case    					=					_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)