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


        '''simple docstring'''


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

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


        '''simple docstring'''


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

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

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

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

        lowercase_			:       Union[str, 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     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,)			->   Optional[int]:


        '''simple docstring'''


        lowercase_			:       int									=			TFFunnelModel(config=__UpperCamelCase    )
        lowercase_			:       Union[str, Any]									=			{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
        lowercase_			:       Optional[Any]									=			model(__UpperCamelCase    )

        lowercase_			:       int									=			[input_ids, input_mask]
        lowercase_			:       Any									=			model(__UpperCamelCase    )

        lowercase_			:       List[Any]									=			model(__UpperCamelCase    )
        self.parent.assertEqual(result.last_hidden_state.shape  ,(self.batch_size, self.seq_length, self.d_model)    )

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

        lowercase_			:       int									=			False
        lowercase_			:       List[str]									=			TFFunnelModel(config=__UpperCamelCase    )
        lowercase_			:       str									=			model(__UpperCamelCase    )
        self.parent.assertEqual(result.last_hidden_state.shape  ,(self.batch_size, self.seq_length, self.d_model)    )
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,)			->   Tuple:


        '''simple docstring'''


        lowercase_			:       Dict									=			TFFunnelBaseModel(config=__UpperCamelCase    )
        lowercase_			:       Union[str, Any]									=			{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
        lowercase_			:       Dict									=			model(__UpperCamelCase    )

        lowercase_			:       Optional[Any]									=			[input_ids, input_mask]
        lowercase_			:       Optional[Any]									=			model(__UpperCamelCase    )

        lowercase_			:       Dict									=			model(__UpperCamelCase    )
        self.parent.assertEqual(result.last_hidden_state.shape  ,(self.batch_size, 2, self.d_model)    )

        lowercase_			:       Optional[int]									=			False
        lowercase_			:       Optional[int]									=			TFFunnelBaseModel(config=__UpperCamelCase    )
        lowercase_			:       str									=			model(__UpperCamelCase    )
        self.parent.assertEqual(result.last_hidden_state.shape  ,(self.batch_size, 3, self.d_model)    )

        lowercase_			:       int									=			False
        lowercase_			:       Optional[int]									=			TFFunnelBaseModel(config=__UpperCamelCase    )
        lowercase_			:       Optional[Any]									=			model(__UpperCamelCase    )
        self.parent.assertEqual(result.last_hidden_state.shape  ,(self.batch_size, 2, self.d_model)    )
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,)			->   Optional[int]:


        '''simple docstring'''


        lowercase_			:       Any									=			TFFunnelForPreTraining(config=__UpperCamelCase    )
        lowercase_			:       Union[str, Any]									=			{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
        lowercase_			:       str									=			model(__UpperCamelCase    )
        self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.seq_length)    )
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,)			->   Dict:


        '''simple docstring'''


        lowercase_			:       Tuple									=			TFFunnelForMaskedLM(config=__UpperCamelCase    )
        lowercase_			:       Dict									=			{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
        lowercase_			:       List[Any]									=			model(__UpperCamelCase    )
        self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.seq_length, self.vocab_size)    )
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,)			->   List[Any]:


        '''simple docstring'''


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


        '''simple docstring'''


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


        '''simple docstring'''


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


        '''simple docstring'''


        lowercase_			:       Tuple									=			TFFunnelForQuestionAnswering(config=__UpperCamelCase    )
        lowercase_			:       Tuple									=			{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
        lowercase_			:       List[Any]									=			model(__UpperCamelCase    )
        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    )			->   int:


        '''simple docstring'''


        lowercase_			:       Optional[int]									=			self.prepare_config_and_inputs()
        (
            lowercase_						
        )			:       Optional[int]									=			config_and_inputs
        lowercase_			:       Optional[Any]									=			{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
        return config, inputs_dict







@require_tf
class  UpperCamelCase	(    lowercase_		,   lowercase_		,   unittest.TestCase						):
   lowercase							=						(
       (
           TFFunnelModel,
           TFFunnelForMaskedLM,
           TFFunnelForPreTraining,
           TFFunnelForQuestionAnswering,
           TFFunnelForTokenClassification,
       )
       if is_tf_available()
       else ()
   )
   lowercase							=						(
       {
           'feature-extraction': (TFFunnelBaseModel, TFFunnelModel),
           'fill-mask': TFFunnelForMaskedLM,
           'question-answering': TFFunnelForQuestionAnswering,
           'text-classification': TFFunnelForSequenceClassification,
           'token-classification': TFFunnelForTokenClassification,
           'zero-shot': TFFunnelForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )
   lowercase							=						False
   lowercase							=						False
   def     _UpperCAmelCase     (    self    )			->   Any:


        '''simple docstring'''


        lowercase_			:       str									=			TFFunnelModelTester(self    )
        lowercase_			:       Dict									=			ConfigTester(self  ,config_class=__UpperCamelCase    )
   def     _UpperCAmelCase     (    self    )			->   Union[str, Any]:


        '''simple docstring'''


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


        '''simple docstring'''


        lowercase_			:       List[str]									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*__UpperCamelCase    )
   def     _UpperCAmelCase     (    self    )			->   Any:


        '''simple docstring'''


        lowercase_			:       Dict									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_pretraining(*__UpperCamelCase    )
   def     _UpperCAmelCase     (    self    )			->   List[str]:


        '''simple docstring'''


        lowercase_			:       Dict									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*__UpperCamelCase    )
   def     _UpperCAmelCase     (    self    )			->   Union[str, Any]:


        '''simple docstring'''


        lowercase_			:       Optional[int]									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*__UpperCamelCase    )







   def     _UpperCAmelCase     (    self    )			->   Optional[Any]:


        '''simple docstring'''


        lowercase_			:       Union[str, Any]									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*__UpperCamelCase    )







@require_tf
class  UpperCamelCase	(    lowercase_		,   unittest.TestCase						):
   lowercase							=						(
       (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
   )
   lowercase							=						False
   lowercase							=						False
   def     _UpperCAmelCase     (    self    )			->   Optional[Any]:


        '''simple docstring'''


        lowercase_			:       Optional[int]									=			TFFunnelModelTester(self  ,base=__UpperCamelCase    )
        lowercase_			:       Dict									=			ConfigTester(self  ,config_class=__UpperCamelCase    )
   def     _UpperCAmelCase     (    self    )			->   List[str]:


        '''simple docstring'''


        self.config_tester.run_common_tests()
   def     _UpperCAmelCase     (    self    )			->   Dict:


        '''simple docstring'''


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


        '''simple docstring'''


        lowercase_			:       List[str]									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*__UpperCamelCase    )







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


        '''simple docstring'''


        lowercase_			:       List[str]									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_multiple_choice(*__UpperCamelCase    )





"""simple docstring"""







import logging
import os
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


__SCREAMING_SNAKE_CASE								={
    "debug": logging.DEBUG,
    "info": logging.INFO,
    "warning": logging.WARNING,
    "error": logging.ERROR,
    "critical": logging.CRITICAL,
}

__SCREAMING_SNAKE_CASE								=logging.WARNING



def     lowercase__( ):
     lowercase_			:       List[Any]									=			os.getenv('DATASETS_VERBOSITY'  ,    __SCREAMING_SNAKE_CASE   )
     if env_level_str:
          if env_level_str in log_levels:
               return log_levels[env_level_str]
          else:
               logging.getLogger().warning(
                   F'''Unknown option DATASETS_VERBOSITY={env_level_str}, '''
                   F'''has to be one of: { ", ".join(log_levels.keys()   ) }'''   )
     return _default_log_level



def     lowercase__( ):
     return __name__.split('.'   )[0]



def     lowercase__( ):
     return logging.getLogger(_get_library_name()   )



def     lowercase__( ):
     # Apply our default configuration to the library root logger.
     lowercase_			:       Optional[int]									=			_get_library_root_logger()
     library_root_logger.setLevel(_get_default_logging_level()   )



def     lowercase__( ):
     lowercase_			:       int									=			_get_library_root_logger()
     library_root_logger.setLevel(logging.NOTSET   )



def     lowercase__( __SCREAMING_SNAKE_CASE							:  Optional[str] = None   ):
     if name is None:
          lowercase_			:       Union[str, Any]									=			_get_library_name()
     return logging.getLogger(__SCREAMING_SNAKE_CASE   )



def     lowercase__( ):
     return _get_library_root_logger().getEffectiveLevel()



def     lowercase__( __SCREAMING_SNAKE_CASE							:  int   ):
     _get_library_root_logger().setLevel(__SCREAMING_SNAKE_CASE   )



def     lowercase__( ):
     return set_verbosity(__SCREAMING_SNAKE_CASE   )



def     lowercase__( ):
     return set_verbosity(__SCREAMING_SNAKE_CASE   )



def     lowercase__( ):
     return set_verbosity(__SCREAMING_SNAKE_CASE   )



def     lowercase__( ):
     return set_verbosity(__SCREAMING_SNAKE_CASE   )



def     lowercase__( ):
     lowercase_			:       Tuple									=			False



def     lowercase__( ):
     lowercase_			:       Any									=			True


# Configure the library root logger at the module level (singleton-like)
_configure_library_root_logger()







class  UpperCamelCase	:
   def __init__(    self  ,*__UpperCamelCase  ,**__UpperCamelCase    )			->   int:  # pylint: disable=unused-argument


        '''simple docstring'''


        lowercase_			:       Optional[Any]									=			args[0] if args else None
   def __iter__(    self    )			->   Union[str, Any]:


        '''simple docstring'''


        return iter(self._iterator    )
   def __getattr__(    self  ,__UpperCamelCase    )			->   List[Any]:


        '''simple docstring'''


        def empty_fn(*__UpperCamelCase  ,**__UpperCamelCase    ):  # pylint: disable=unused-argument
             return

        return empty_fn
   def __enter__(    self    )			->   Optional[int]:


        '''simple docstring'''


        return self







   def __exit__(    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase    )			->   Dict:


        '''simple docstring'''


        return






__SCREAMING_SNAKE_CASE								=True







class  UpperCamelCase	:
   def __call__(    self  ,*__UpperCamelCase  ,__UpperCamelCase=False  ,**__UpperCamelCase    )			->   Tuple:


        '''simple docstring'''


        if _tqdm_active and not disable:
             return tqdm_lib.tqdm(*__UpperCamelCase  ,**__UpperCamelCase    )
        else:
             return EmptyTqdm(*__UpperCamelCase  ,**__UpperCamelCase    )
   def     _UpperCAmelCase     (    self  ,*__UpperCamelCase  ,**__UpperCamelCase    )			->   str:


        '''simple docstring'''


        lowercase_			:       Tuple									=			None
        if _tqdm_active:
             return tqdm_lib.tqdm.set_lock(*__UpperCamelCase  ,**__UpperCamelCase    )







   def     _UpperCAmelCase     (    self    )			->   Any:


        '''simple docstring'''


        if _tqdm_active:
             return tqdm_lib.tqdm.get_lock()






__SCREAMING_SNAKE_CASE								=_tqdm_cls()



def     lowercase__( ):
     global _tqdm_active
     return bool(_tqdm_active   )



def     lowercase__( ):
     global _tqdm_active
     lowercase_			:       Union[str, Any]									=			True







def     lowercase__( ):
     global _tqdm_active
     lowercase_			:       Optional[int]									=			False

