


"""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 				_SCREAMING_SNAKE_CASE				:
   """simple docstring"""



   def __init__(						self ,     lowerCamelCase__ ,     lowerCamelCase__=13 ,     lowerCamelCase__=7 ,     lowerCamelCase__=True ,     lowerCamelCase__=True ,     lowerCamelCase__=True ,     lowerCamelCase__=True ,     lowerCamelCase__=99 ,     lowerCamelCase__=[1, 1, 2] ,     lowerCamelCase__=1 ,     lowerCamelCase__=32 ,     lowerCamelCase__=4 ,     lowerCamelCase__=8 ,     lowerCamelCase__=37 ,     lowerCamelCase__="gelu_new" ,     lowerCamelCase__=0.1 ,     lowerCamelCase__=0.1 ,     lowerCamelCase__=0.0 ,     lowerCamelCase__=512 ,     lowerCamelCase__=3 ,     lowerCamelCase__=0.02 ,     lowerCamelCase__=3 ,     lowerCamelCase__=4 ,     lowerCamelCase__=None ,     lowerCamelCase__=False ,     )      ->							Tuple:
    lowercase__       :       int				=						parent
    lowercase__       :       List[str]				=						batch_size
    lowercase__       :       List[Any]				=						seq_length
    lowercase__       :       Any				=						is_training
    lowercase__       :       List[Any]				=						use_input_mask
    lowercase__       :       Optional[int]				=						use_token_type_ids
    lowercase__       :       List[str]				=						use_labels
    lowercase__       :       List[str]				=						vocab_size
    lowercase__       :       Optional[Any]				=						block_sizes
    lowercase__       :       Optional[Any]				=						num_decoder_layers
    lowercase__       :       List[str]				=						d_model
    lowercase__       :       List[str]				=						n_head
    lowercase__       :       Any				=						d_head
    lowercase__       :       Optional[int]				=						d_inner
    lowercase__       :       Optional[int]				=						hidden_act
    lowercase__       :       Tuple				=						hidden_dropout
    lowercase__       :       List[str]				=						attention_dropout
    lowercase__       :       List[str]				=						activation_dropout
    lowercase__       :       Optional[int]				=						max_position_embeddings
    lowercase__       :       Any				=						type_vocab_size
    lowercase__       :       Dict				=						2
    lowercase__       :       List[Any]				=						num_labels
    lowercase__       :       List[str]				=						num_choices
    lowercase__       :       Dict				=						scope
    lowercase__       :       Optional[Any]				=						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__       :       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:
     lowercase__       :       str				=						self.num_hidden_layers + 2


   def 					UpperCAmelCase__(						self						)      ->							List[str]:
    lowercase__       :       Union[str, Any]				=						ids_tensor([self.batch_size, self.seq_length] ,     self.vocab_size						)

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

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

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

    lowercase__       :       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 					UpperCAmelCase__(						self ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     )      ->							str:
    lowercase__       :       Any				=						TFFunnelModel(config=lowerCamelCase__						)
    lowercase__       :       Tuple				=						{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
    lowercase__       :       Dict				=						model(lowerCamelCase__						)

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

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

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

    lowercase__       :       Any				=						False
    lowercase__       :       Any				=						TFFunnelModel(config=lowerCamelCase__						)
    lowercase__       :       Any				=						model(lowerCamelCase__						)
    self.parent.assertEqual(result.last_hidden_state.shape ,     (self.batch_size, self.seq_length, self.d_model)						)


   def 					UpperCAmelCase__(						self ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     )      ->							int:
    lowercase__       :       Optional[Any]				=						TFFunnelBaseModel(config=lowerCamelCase__						)
    lowercase__       :       Optional[int]				=						{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
    lowercase__       :       Tuple				=						model(lowerCamelCase__						)

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

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

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

    lowercase__       :       Any				=						False
    lowercase__       :       int				=						TFFunnelBaseModel(config=lowerCamelCase__						)
    lowercase__       :       Any				=						model(lowerCamelCase__						)
    self.parent.assertEqual(result.last_hidden_state.shape ,     (self.batch_size, 2, self.d_model)						)


   def 					UpperCAmelCase__(						self ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     )      ->							Dict:
    lowercase__       :       Tuple				=						TFFunnelForPreTraining(config=lowerCamelCase__						)
    lowercase__       :       Optional[int]				=						{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
    lowercase__       :       int				=						model(lowerCamelCase__						)
    self.parent.assertEqual(result.logits.shape ,     (self.batch_size, self.seq_length)						)


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


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


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


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


   def 					UpperCAmelCase__(						self ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     lowerCamelCase__ ,     )      ->							List[Any]:
    lowercase__       :       int				=						TFFunnelForQuestionAnswering(config=lowerCamelCase__						)
    lowercase__       :       Optional[int]				=						{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
    lowercase__       :       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 					UpperCAmelCase__(						self						)      ->							Optional[int]:
    lowercase__       :       Dict				=						self.prepare_config_and_inputs()
    (
        (
        lowercase__
    )	,       (
        lowercase__
    )	,       (
        lowercase__
    )	,       (
        lowercase__
    )	,       (
        lowercase__
    )	,       (
        lowercase__
    )	,       (
        lowercase__
    )	,       
    )       :       int				=						config_and_inputs
    lowercase__       :       List[Any]				=						{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
    return config, inputs_dict

@require_tf
class 				_SCREAMING_SNAKE_CASE				(							__UpperCAmelCase     ,   __UpperCAmelCase     ,   unittest.TestCase  ):
   """simple docstring"""



   _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 					UpperCAmelCase__(						self						)      ->							int:
    lowercase__       :       Tuple				=						TFFunnelModelTester(self						)
    lowercase__       :       Any				=						ConfigTester(self ,     config_class=lowerCamelCase__						)


   def 					UpperCAmelCase__(						self						)      ->							Any:
    self.config_tester.run_common_tests()


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


   def 					UpperCAmelCase__(						self						)      ->							Optional[Any]:
    lowercase__       :       Dict				=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_pretraining(*lowerCamelCase__						)


   def 					UpperCAmelCase__(						self						)      ->							Tuple:
    lowercase__       :       str				=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_masked_lm(*lowerCamelCase__						)


   def 					UpperCAmelCase__(						self						)      ->							Dict:
    lowercase__       :       Dict				=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_token_classification(*lowerCamelCase__						)







   def 					UpperCAmelCase__(						self						)      ->							Optional[Any]:
    lowercase__       :       List[Any]				=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_question_answering(*lowerCamelCase__						)

@require_tf
class 				_SCREAMING_SNAKE_CASE				(							__UpperCAmelCase     ,   unittest.TestCase  ):
   """simple docstring"""



   _a   :       int									=    (
       (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
   )
   _a   :       Tuple									=    False
   _a   :       List[str]									=    False


   def 					UpperCAmelCase__(						self						)      ->							int:
    lowercase__       :       Optional[Any]				=						TFFunnelModelTester(self ,     base=lowerCamelCase__						)
    lowercase__       :       Any				=						ConfigTester(self ,     config_class=lowerCamelCase__						)


   def 					UpperCAmelCase__(						self						)      ->							List[Any]:
    self.config_tester.run_common_tests()


   def 					UpperCAmelCase__(						self						)      ->							int:
    lowercase__       :       Union[str, Any]				=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_base_model(*lowerCamelCase__						)


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







   def 					UpperCAmelCase__(						self						)      ->							Dict:
    lowercase__       :       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

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__snake_case    					=					{
    'configuration_informer': [
        'INFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'InformerConfig',
    ],
}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   __snake_case    					=					[
       'INFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
       'InformerForPrediction',
       'InformerModel',
       'InformerPreTrainedModel',
   ]


if TYPE_CHECKING:
   from .configuration_informer import INFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, InformerConfig

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_informer import (
          INFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
          InformerForPrediction,
          InformerModel,
          InformerPreTrainedModel,
      )

else:
   import sys

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