



'''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 __A    :



 '''simple docstring'''







 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=512				,     A=3				,     A=0.02				,     A=3				,     A=4				,     A=None				,     A=False				,     )					->  Tuple:


      """simple docstring"""



      _a											=						parent
      _a											=						batch_size
      _a											=						seq_length
      _a											=						is_training
      _a											=						use_input_mask
      _a											=						use_token_type_ids
      _a											=						use_labels
      _a											=						vocab_size
      _a											=						block_sizes
      _a											=						num_decoder_layers
      _a											=						d_model
      _a											=						n_head
      _a											=						d_head
      _a											=						d_inner
      _a											=						hidden_act
      _a											=						hidden_dropout
      _a											=						attention_dropout
      _a											=						activation_dropout
      _a											=						max_position_embeddings
      _a											=						type_vocab_size
      _a											=						2
      _a											=						num_labels
      _a											=						num_choices
      _a											=						scope
      _a											=						initializer_std

      # Used in the tests to check the size of the first attention layer
      _a											=						n_head
      # Used in the tests to check the size of the first hidden state
      _a											=						self.d_model
      # Used in the tests to check the number of output hidden states/attentions
      _a											=						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											=						self.num_hidden_layers + 2



 def       a__						(self )					->  Optional[int]:


      """simple docstring"""



      _a											=						ids_tensor([self.batch_size, self.seq_length]				,     self.vocab_size )

      _a											=						None
      if self.use_input_mask:
           _a											=						random_attention_mask([self.batch_size, self.seq_length] )

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

      _a											=						None
      _a											=						None
      _a											=						None
      if self.use_labels:
           _a											=						ids_tensor([self.batch_size]				,     self.type_sequence_label_size )
           _a											=						ids_tensor([self.batch_size, self.seq_length]				,     self.num_labels )
           _a											=						ids_tensor([self.batch_size]				,     self.num_choices )

      _a											=						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				,     A				,     A				,     A				,     A				,     A				,     A				,     A				,     )					->  int:


      """simple docstring"""



      _a											=						TFFunnelModel(config=A )
      _a											=						{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
      _a											=						model(A )

      _a											=						[input_ids, input_mask]
      _a											=						model(A )

      _a											=						model(A )
      self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, self.seq_length, self.d_model) )

      _a											=						False
      _a											=						TFFunnelModel(config=A )
      _a											=						model(A )
      self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, self.seq_length, self.d_model) )

      _a											=						False
      _a											=						TFFunnelModel(config=A )
      _a											=						model(A )
      self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, self.seq_length, self.d_model) )



 def       a__						(self				,     A				,     A				,     A				,     A				,     A				,     A				,     A				,     )					->  List[str]:


      """simple docstring"""



      _a											=						TFFunnelBaseModel(config=A )
      _a											=						{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
      _a											=						model(A )

      _a											=						[input_ids, input_mask]
      _a											=						model(A )

      _a											=						model(A )
      self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, 2, self.d_model) )

      _a											=						False
      _a											=						TFFunnelBaseModel(config=A )
      _a											=						model(A )
      self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, 3, self.d_model) )

      _a											=						False
      _a											=						TFFunnelBaseModel(config=A )
      _a											=						model(A )
      self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, 2, self.d_model) )



 def       a__						(self				,     A				,     A				,     A				,     A				,     A				,     A				,     A				,     )					->  List[Any]:


      """simple docstring"""



      _a											=						TFFunnelForPreTraining(config=A )
      _a											=						{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
      _a											=						model(A )
      self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.seq_length) )



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


      """simple docstring"""



      _a											=						TFFunnelForMaskedLM(config=A )
      _a											=						{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
      _a											=						model(A )
      self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.seq_length, self.vocab_size) )



 def       a__						(self				,     A				,     A				,     A				,     A				,     A				,     A				,     A				,     )					->  List[str]:


      """simple docstring"""



      _a											=						self.num_labels
      _a											=						TFFunnelForSequenceClassification(config=A )
      _a											=						{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
      _a											=						model(A )
      self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.num_labels) )



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


      """simple docstring"""



      _a											=						self.num_choices
      _a											=						TFFunnelForMultipleChoice(config=A )
      _a											=						tf.tile(tf.expand_dims(A				,     1 )				,     (1, self.num_choices, 1) )
      _a											=						tf.tile(tf.expand_dims(A				,     1 )				,     (1, self.num_choices, 1) )
      _a											=						tf.tile(tf.expand_dims(A				,     1 )				,     (1, self.num_choices, 1) )
      _a											=						{
          '''input_ids''': multiple_choice_inputs_ids,
          '''attention_mask''': multiple_choice_input_mask,
          '''token_type_ids''': multiple_choice_token_type_ids,
      }
      _a											=						model(A )
      self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.num_choices) )



 def       a__						(self				,     A				,     A				,     A				,     A				,     A				,     A				,     A				,     )					->  Any:


      """simple docstring"""



      _a											=						self.num_labels
      _a											=						TFFunnelForTokenClassification(config=A )
      _a											=						{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
      _a											=						model(A )
      self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.seq_length, self.num_labels) )



 def       a__						(self				,     A				,     A				,     A				,     A				,     A				,     A				,     A				,     )					->  List[str]:


      """simple docstring"""



      _a											=						TFFunnelForQuestionAnswering(config=A )
      _a											=						{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
      _a											=						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[int]:


      """simple docstring"""



      _a											=						self.prepare_config_and_inputs()
      (
          (
          _a
      )						,					(
          _a
      )						,					(
          _a
      )						,					(
          _a
      )						,					(
          _a
      )						,					(
          _a
      )						,					(
          _a
      )						,					
      )											=						config_and_inputs
      _a											=						{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
      return config, inputs_dict






@require_tf
class __A    (						A     ,     A     ,     unittest.TestCase		):



 '''simple docstring'''







 __lowerCamelCase					: str    = (
     (
         TFFunnelModel,
         TFFunnelForMaskedLM,
         TFFunnelForPreTraining,
         TFFunnelForQuestionAnswering,
         TFFunnelForTokenClassification,
     )
     if is_tf_available()
     else ()
 )
 __lowerCamelCase					: List[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 {}
 )
 __lowerCamelCase					: Optional[int]    = False
 __lowerCamelCase					: List[Any]    = False



 def       a__						(self )					->  str:


      """simple docstring"""



      _a											=						TFFunnelModelTester(self )
      _a											=						ConfigTester(self				,     config_class=A )



 def       a__						(self )					->  int:


      """simple docstring"""



      self.config_tester.run_common_tests()



 def       a__						(self )					->  Optional[int]:


      """simple docstring"""



      _a											=						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*A )



 def       a__						(self )					->  Optional[int]:


      """simple docstring"""



      _a											=						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_pretraining(*A )



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


      """simple docstring"""



      _a											=						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_lm(*A )



 def       a__						(self )					->  Any:


      """simple docstring"""



      _a											=						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*A )



 def       a__						(self )					->  int:


      """simple docstring"""



      _a											=						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*A )






@require_tf
class __A    (						A     ,     unittest.TestCase		):



 '''simple docstring'''







 __lowerCamelCase					: Tuple    = (
     (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
 )
 __lowerCamelCase					: Dict    = False
 __lowerCamelCase					: Optional[int]    = False



 def       a__						(self )					->  Tuple:


      """simple docstring"""



      _a											=						TFFunnelModelTester(self				,     base=A )
      _a											=						ConfigTester(self				,     config_class=A )



 def       a__						(self )					->  str:


      """simple docstring"""



      self.config_tester.run_common_tests()



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


      """simple docstring"""



      _a											=						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_base_model(*A )



 def       a__						(self )					->  Optional[int]:


      """simple docstring"""



      _a											=						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*A )



 def       a__						(self )					->  Dict:


      """simple docstring"""



      _a											=						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_multiple_choice(*A )








'''simple docstring'''





import pytest

import datasets


# Import fixture modules as plugins
lowercase_	 =						["tests.fixtures.files", "tests.fixtures.hub", "tests.fixtures.fsspec"]




def lowerCAmelCase						(__A						,			__A):



     """simple docstring"""



     for item in items:
          if any(marker in item.keywords for marker in ['''integration''', '''unit''']):
               continue
          item.add_marker(pytest.mark.unit)




def lowerCAmelCase						(__A):



     """simple docstring"""



     config.addinivalue_line('''markers'''						,			'''torchaudio_latest: mark test to run with torchaudio>=0.12''')




@pytest.fixture(autouse=__A)
def lowerCAmelCase						(__A						,			__A):



     """simple docstring"""



     _a											=						tmp_path_factory.getbasetemp() / '''cache'''
     _a											=						test_hf_cache_home / '''datasets'''
     _a											=						test_hf_cache_home / '''metrics'''
     _a											=						test_hf_cache_home / '''modules'''
     monkeypatch.setattr('''datasets.config.HF_DATASETS_CACHE'''						,			str(__A))
     monkeypatch.setattr('''datasets.config.HF_METRICS_CACHE'''						,			str(__A))
     monkeypatch.setattr('''datasets.config.HF_MODULES_CACHE'''						,			str(__A))
     _a											=						test_hf_datasets_cache / '''downloads'''
     monkeypatch.setattr('''datasets.config.DOWNLOADED_DATASETS_PATH'''						,			str(__A))
     _a											=						test_hf_datasets_cache / '''downloads''' / '''extracted'''
     monkeypatch.setattr('''datasets.config.EXTRACTED_DATASETS_PATH'''						,			str(__A))




@pytest.fixture(autouse=__A						,			scope='''session''')
def lowerCAmelCase						():



     """simple docstring"""



     datasets.disable_progress_bar()




@pytest.fixture(autouse=__A)
def lowerCAmelCase						(__A):



     """simple docstring"""



     monkeypatch.setattr('''datasets.config.HF_UPDATE_DOWNLOAD_COUNTS'''						,			__A)




@pytest.fixture
def lowerCAmelCase						(__A):



     """simple docstring"""



     monkeypatch.setattr('''sqlalchemy.util.deprecations.SILENCE_UBER_WARNING'''						,			__A)



