
"""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       __magic_name__							:
       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			,					)  ->						Optional[int]:





         """simple docstring"""




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

         # Used in the tests to check the size of the first attention layer
         _lowercase:      Optional[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:      Union[str, Any]   			=  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:      Optional[int]   			=  self.num_hidden_layers + 2
       def 				lowercase_				(  self							)  ->						Optional[int]:





         """simple docstring"""




         _lowercase:      List[str]   			=  ids_tensor([self.batch_size, self.seq_length]			,					self.vocab_size							)

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

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

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

         _lowercase:      str   			=  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			,					A_			,					A_			,					A_			,					A_			,					A_			,					A_			,					A_			,					)  ->						Optional[Any]:





         """simple docstring"""




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

         _lowercase:      Tuple   			=  [input_ids, input_mask]
         _lowercase:      Dict   			=  model(A_							)

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

         _lowercase:      Optional[int]   			=  False
         _lowercase:      Union[str, Any]   			=  TFFunnelModel(config=A_							)
         _lowercase:      Optional[int]   			=  model(A_							)
         self.parent.assertEqual(result.last_hidden_state.shape			,					(self.batch_size, self.seq_length, self.d_model)							)

         _lowercase:      Optional[int]   			=  False
         _lowercase:      Any   			=  TFFunnelModel(config=A_							)
         _lowercase:      str   			=  model(A_							)
         self.parent.assertEqual(result.last_hidden_state.shape			,					(self.batch_size, self.seq_length, self.d_model)							)
       def 				lowercase_				(  self			,					A_			,					A_			,					A_			,					A_			,					A_			,					A_			,					A_			,					)  ->						str:





         """simple docstring"""




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

         _lowercase:      Dict   			=  [input_ids, input_mask]
         _lowercase:      Any   			=  model(A_							)

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

         _lowercase:      Tuple   			=  False
         _lowercase:      Tuple   			=  TFFunnelBaseModel(config=A_							)
         _lowercase:      Any   			=  model(A_							)
         self.parent.assertEqual(result.last_hidden_state.shape			,					(self.batch_size, 3, self.d_model)							)

         _lowercase:      Dict   			=  False
         _lowercase:      Tuple   			=  TFFunnelBaseModel(config=A_							)
         _lowercase:      Optional[int]   			=  model(A_							)
         self.parent.assertEqual(result.last_hidden_state.shape			,					(self.batch_size, 2, self.d_model)							)
       def 				lowercase_				(  self			,					A_			,					A_			,					A_			,					A_			,					A_			,					A_			,					A_			,					)  ->						Optional[int]:





         """simple docstring"""




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





         """simple docstring"""




         _lowercase:      Tuple   			=  TFFunnelForMaskedLM(config=A_							)
         _lowercase:      Any   			=  {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
         _lowercase:      str   			=  model(A_							)
         self.parent.assertEqual(result.logits.shape			,					(self.batch_size, self.seq_length, self.vocab_size)							)
       def 				lowercase_				(  self			,					A_			,					A_			,					A_			,					A_			,					A_			,					A_			,					A_			,					)  ->						str:





         """simple docstring"""




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





         """simple docstring"""




         _lowercase:      int   			=  self.num_choices
         _lowercase:      Any   			=  TFFunnelForMultipleChoice(config=A_							)
         _lowercase:      List[Any]   			=  tf.tile(tf.expand_dims(A_			,					1							)			,					(1, self.num_choices, 1)							)
         _lowercase:      Union[str, Any]   			=  tf.tile(tf.expand_dims(A_			,					1							)			,					(1, self.num_choices, 1)							)
         _lowercase:      Union[str, Any]   			=  tf.tile(tf.expand_dims(A_			,					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:      int   			=  model(A_							)
         self.parent.assertEqual(result.logits.shape			,					(self.batch_size, self.num_choices)							)
       def 				lowercase_				(  self			,					A_			,					A_			,					A_			,					A_			,					A_			,					A_			,					A_			,					)  ->						Optional[Any]:





         """simple docstring"""




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





         """simple docstring"""




         _lowercase:      Optional[Any]   			=  TFFunnelForQuestionAnswering(config=A_							)
         _lowercase:      List[Any]   			=  {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
         _lowercase:      List[Any]   			=  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							)  ->						Optional[Any]:





         """simple docstring"""




         _lowercase:      List[str]   			=  self.prepare_config_and_inputs()
         (
             (
             _lowercase
         )			,					(
             _lowercase
         )			,					(
             _lowercase
         )			,					(
             _lowercase
         )			,					(
             _lowercase
         )			,					(
             _lowercase
         )			,					(
             _lowercase
         )			,					
         ):      str   			=  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       __magic_name__							(							SCREAMING_SNAKE_CASE__ ,       SCREAMING_SNAKE_CASE__ ,       unittest.TestCase			):
       UpperCamelCase_ =		(
           (
               TFFunnelModel,
               TFFunnelForMaskedLM,
               TFFunnelForPreTraining,
               TFFunnelForQuestionAnswering,
               TFFunnelForTokenClassification,
           )
           if is_tf_available()
           else ()
       )
       UpperCamelCase_ =		(
           {
               '''feature-extraction''': (TFFunnelBaseModel, TFFunnelModel),
               '''fill-mask''': TFFunnelForMaskedLM,
               '''question-answering''': TFFunnelForQuestionAnswering,
               '''text-classification''': TFFunnelForSequenceClassification,
               '''token-classification''': TFFunnelForTokenClassification,
               '''zero-shot''': TFFunnelForSequenceClassification,
           }
           if is_tf_available()
           else {}
       )
       UpperCamelCase_ =		False
       UpperCamelCase_ =		False
       def 				lowercase_				(  self							)  ->						Dict:





         """simple docstring"""




         _lowercase:      Optional[int]   			=  TFFunnelModelTester(self							)
         _lowercase:      Dict   			=  ConfigTester(self			,					config_class=A_							)
       def 				lowercase_				(  self							)  ->						str:





         """simple docstring"""




         self.config_tester.run_common_tests()
       def 				lowercase_				(  self							)  ->						List[str]:





         """simple docstring"""




         _lowercase:      str   			=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*A_							)
       def 				lowercase_				(  self							)  ->						int:





         """simple docstring"""




         _lowercase:      str   			=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_pretraining(*A_							)
       def 				lowercase_				(  self							)  ->						int:





         """simple docstring"""




         _lowercase:      Any   			=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*A_							)
       def 				lowercase_				(  self							)  ->						Any:





         """simple docstring"""




         _lowercase:      Optional[int]   			=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*A_							)



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





         """simple docstring"""




         _lowercase:      Any   			=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*A_							)


@require_tf
class       __magic_name__							(							SCREAMING_SNAKE_CASE__ ,       unittest.TestCase			):
       UpperCamelCase_ =		(
           (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
       )
       UpperCamelCase_ =		False
       UpperCamelCase_ =		False
       def 				lowercase_				(  self							)  ->						Tuple:





         """simple docstring"""




         _lowercase:      Optional[Any]   			=  TFFunnelModelTester(self			,					base=A_							)
         _lowercase:      str   			=  ConfigTester(self			,					config_class=A_							)
       def 				lowercase_				(  self							)  ->						Union[str, Any]:





         """simple docstring"""




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





         """simple docstring"""




         _lowercase:      Tuple   			=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_base_model(*A_							)
       def 				lowercase_				(  self							)  ->						Tuple:





         """simple docstring"""




         _lowercase:      Any   			=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*A_							)



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





         """simple docstring"""




         _lowercase:      Optional[Any]   			=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_multiple_choice(*A_							)


"""simple docstring"""




import warnings

from ...utils import logging
from .image_processing_segformer import SegformerImageProcessor


A__ :       List[Any]				= logging.get_logger(__name__)


class       __magic_name__							(							SCREAMING_SNAKE_CASE__			):
       def __init__(  self			,					*A_			,					**A_							)  ->						None:





         """simple docstring"""




         warnings.warn(
             '''The class SegformerFeatureExtractor is deprecated and will be removed in version 5 of Transformers.'''
             ''' Please use SegformerImageProcessor instead.'''			,					A_			,					)
         super().__init__(*A_			,					**A_							)
