




'''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,						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.0_2,						lowerCAmelCase=3,						lowerCAmelCase=4,						lowerCAmelCase=None,						lowerCAmelCase=False,						):



              """simple docstring"""







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

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






       def 	lowercase__	(				self    ):



              """simple docstring"""







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

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

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

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

              lowerCamelCase_				=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 	lowercase__	(				self,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						):



              """simple docstring"""







              lowerCamelCase_				=TFFunnelModel(config=a_    )
              lowerCamelCase_				={"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
              lowerCamelCase_				=model(a_    )

              lowerCamelCase_				=[input_ids, input_mask]
              lowerCamelCase_				=model(a_    )

              lowerCamelCase_				=model(a_    )
              self.parent.assertEqual(result.last_hidden_state.shape,						(self.batch_size, self.seq_length, self.d_model)    )

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

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






       def 	lowercase__	(				self,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						):



              """simple docstring"""







              lowerCamelCase_				=TFFunnelBaseModel(config=a_    )
              lowerCamelCase_				={"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
              lowerCamelCase_				=model(a_    )

              lowerCamelCase_				=[input_ids, input_mask]
              lowerCamelCase_				=model(a_    )

              lowerCamelCase_				=model(a_    )
              self.parent.assertEqual(result.last_hidden_state.shape,						(self.batch_size, 2, self.d_model)    )

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

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






       def 	lowercase__	(				self,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						):



              """simple docstring"""







              lowerCamelCase_				=TFFunnelForPreTraining(config=a_    )
              lowerCamelCase_				={"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
              lowerCamelCase_				=model(a_    )
              self.parent.assertEqual(result.logits.shape,						(self.batch_size, self.seq_length)    )






       def 	lowercase__	(				self,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						):



              """simple docstring"""







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






       def 	lowercase__	(				self,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						):



              """simple docstring"""







              lowerCamelCase_				=self.num_labels
              lowerCamelCase_				=TFFunnelForSequenceClassification(config=a_    )
              lowerCamelCase_				={"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
              lowerCamelCase_				=model(a_    )
              self.parent.assertEqual(result.logits.shape,						(self.batch_size, self.num_labels)    )






       def 	lowercase__	(				self,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						):



              """simple docstring"""







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






       def 	lowercase__	(				self,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						):



              """simple docstring"""







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






       def 	lowercase__	(				self,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						lowerCAmelCase,						):



              """simple docstring"""







              lowerCamelCase_				=TFFunnelForQuestionAnswering(config=a_    )
              lowerCamelCase_				={"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
              lowerCamelCase_				=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 	lowercase__	(				self    ):



              """simple docstring"""







              lowerCamelCase_				=self.prepare_config_and_inputs()
              (
                  lowerCamelCase_	
              )				=config_and_inputs
              lowerCamelCase_				={"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							):
       lowercase      :       Optional[int] 		=(
           (
               TFFunnelModel,
               TFFunnelForMaskedLM,
               TFFunnelForPreTraining,
               TFFunnelForQuestionAnswering,
               TFFunnelForTokenClassification,
           )
           if is_tf_available()
           else ()
       )
       lowercase      :       Union[str, Any] 		=(
           {
               "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      :       List[Any] 		=False
       lowercase      :       Optional[int] 		=False






       def 	lowercase__	(				self    ):



              """simple docstring"""







              lowerCamelCase_				=TFFunnelModelTester(self    )
              lowerCamelCase_				=ConfigTester(self,						config_class=a_    )






       def 	lowercase__	(				self    ):



              """simple docstring"""







              self.config_tester.run_common_tests()






       def 	lowercase__	(				self    ):



              """simple docstring"""







              lowerCamelCase_				=self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_model(*a_    )






       def 	lowercase__	(				self    ):



              """simple docstring"""







              lowerCamelCase_				=self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_pretraining(*a_    )






       def 	lowercase__	(				self    ):



              """simple docstring"""







              lowerCamelCase_				=self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_masked_lm(*a_    )






       def 	lowercase__	(				self    ):



              """simple docstring"""







              lowerCamelCase_				=self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_token_classification(*a_    )






       def 	lowercase__	(				self    ):



              """simple docstring"""







              lowerCamelCase_				=self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_question_answering(*a_    )





@require_tf
class     __UpperCamelCase			(					_UpperCamelCase     ,   unittest.TestCase							):
       lowercase      :       Optional[Any] 		=(
           (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
       )
       lowercase      :       Any 		=False
       lowercase      :       Optional[int] 		=False






       def 	lowercase__	(				self    ):



              """simple docstring"""







              lowerCamelCase_				=TFFunnelModelTester(self,						base=a_    )
              lowerCamelCase_				=ConfigTester(self,						config_class=a_    )






       def 	lowercase__	(				self    ):



              """simple docstring"""







              self.config_tester.run_common_tests()






       def 	lowercase__	(				self    ):



              """simple docstring"""







              lowerCamelCase_				=self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_base_model(*a_    )






       def 	lowercase__	(				self    ):



              """simple docstring"""







              lowerCamelCase_				=self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_sequence_classification(*a_    )






       def 	lowercase__	(				self    ):



              """simple docstring"""







              lowerCamelCase_				=self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_multiple_choice(*a_    )











"""simple docstring"""






from typing import TYPE_CHECKING

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


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

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__UpperCAmelCase						=			[
		    '''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

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