




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




              """simple docstring"""


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

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

       def lowercase (		self: str		)       -> Optional[int]:




              """simple docstring"""


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

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

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

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

              UpperCamelCase_          =  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: Any					,   _SCREAMING_SNAKE_CASE: Optional[Any]					,   _SCREAMING_SNAKE_CASE: Tuple					,   _SCREAMING_SNAKE_CASE: Optional[Any]					,   _SCREAMING_SNAKE_CASE: int					,   _SCREAMING_SNAKE_CASE: List[str]					,   _SCREAMING_SNAKE_CASE: Optional[Any]					,   _SCREAMING_SNAKE_CASE: Tuple					,   )       -> List[str]:




              """simple docstring"""


              UpperCamelCase_          =  TFFunnelModel(config=_SCREAMING_SNAKE_CASE		)
              UpperCamelCase_          =  {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
              UpperCamelCase_          =  model(_SCREAMING_SNAKE_CASE		)

              UpperCamelCase_          =  [input_ids, input_mask]
              UpperCamelCase_          =  model(_SCREAMING_SNAKE_CASE		)

              UpperCamelCase_          =  model(_SCREAMING_SNAKE_CASE		)
              self.parent.assertEqual(result.last_hidden_state.shape					,   (self.batch_size, self.seq_length, self.d_model)		)

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

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

       def lowercase (		self: Union[str, Any]					,   _SCREAMING_SNAKE_CASE: Dict					,   _SCREAMING_SNAKE_CASE: int					,   _SCREAMING_SNAKE_CASE: List[str]					,   _SCREAMING_SNAKE_CASE: Tuple					,   _SCREAMING_SNAKE_CASE: str					,   _SCREAMING_SNAKE_CASE: Tuple					,   _SCREAMING_SNAKE_CASE: Dict					,   )       -> List[str]:




              """simple docstring"""


              UpperCamelCase_          =  TFFunnelBaseModel(config=_SCREAMING_SNAKE_CASE		)
              UpperCamelCase_          =  {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
              UpperCamelCase_          =  model(_SCREAMING_SNAKE_CASE		)

              UpperCamelCase_          =  [input_ids, input_mask]
              UpperCamelCase_          =  model(_SCREAMING_SNAKE_CASE		)

              UpperCamelCase_          =  model(_SCREAMING_SNAKE_CASE		)
              self.parent.assertEqual(result.last_hidden_state.shape					,   (self.batch_size, 2, self.d_model)		)

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

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

       def lowercase (		self: Optional[int]					,   _SCREAMING_SNAKE_CASE: Union[str, Any]					,   _SCREAMING_SNAKE_CASE: List[Any]					,   _SCREAMING_SNAKE_CASE: int					,   _SCREAMING_SNAKE_CASE: Union[str, Any]					,   _SCREAMING_SNAKE_CASE: Optional[Any]					,   _SCREAMING_SNAKE_CASE: Dict					,   _SCREAMING_SNAKE_CASE: Any					,   )       -> Any:




              """simple docstring"""


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

       def lowercase (		self: Any					,   _SCREAMING_SNAKE_CASE: Optional[Any]					,   _SCREAMING_SNAKE_CASE: Dict					,   _SCREAMING_SNAKE_CASE: int					,   _SCREAMING_SNAKE_CASE: List[str]					,   _SCREAMING_SNAKE_CASE: Optional[Any]					,   _SCREAMING_SNAKE_CASE: List[str]					,   _SCREAMING_SNAKE_CASE: Union[str, Any]					,   )       -> str:




              """simple docstring"""


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

       def lowercase (		self: Union[str, Any]					,   _SCREAMING_SNAKE_CASE: Optional[int]					,   _SCREAMING_SNAKE_CASE: Union[str, Any]					,   _SCREAMING_SNAKE_CASE: str					,   _SCREAMING_SNAKE_CASE: List[str]					,   _SCREAMING_SNAKE_CASE: Optional[Any]					,   _SCREAMING_SNAKE_CASE: Tuple					,   _SCREAMING_SNAKE_CASE: str					,   )       -> List[Any]:




              """simple docstring"""


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

       def lowercase (		self: Dict					,   _SCREAMING_SNAKE_CASE: Union[str, Any]					,   _SCREAMING_SNAKE_CASE: str					,   _SCREAMING_SNAKE_CASE: Union[str, Any]					,   _SCREAMING_SNAKE_CASE: str					,   _SCREAMING_SNAKE_CASE: Tuple					,   _SCREAMING_SNAKE_CASE: Optional[Any]					,   _SCREAMING_SNAKE_CASE: str					,   )       -> Union[str, Any]:




              """simple docstring"""


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

       def lowercase (		self: Optional[Any]					,   _SCREAMING_SNAKE_CASE: Union[str, Any]					,   _SCREAMING_SNAKE_CASE: List[Any]					,   _SCREAMING_SNAKE_CASE: Tuple					,   _SCREAMING_SNAKE_CASE: List[str]					,   _SCREAMING_SNAKE_CASE: Union[str, Any]					,   _SCREAMING_SNAKE_CASE: Union[str, Any]					,   _SCREAMING_SNAKE_CASE: str					,   )       -> Any:




              """simple docstring"""


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

       def lowercase (		self: Tuple					,   _SCREAMING_SNAKE_CASE: Optional[Any]					,   _SCREAMING_SNAKE_CASE: str					,   _SCREAMING_SNAKE_CASE: int					,   _SCREAMING_SNAKE_CASE: str					,   _SCREAMING_SNAKE_CASE: int					,   _SCREAMING_SNAKE_CASE: str					,   _SCREAMING_SNAKE_CASE: List[Any]					,   )       -> str:




              """simple docstring"""


              UpperCamelCase_          =  TFFunnelForQuestionAnswering(config=_SCREAMING_SNAKE_CASE		)
              UpperCamelCase_          =  {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
              UpperCamelCase_          =  model(_SCREAMING_SNAKE_CASE		)
              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: List[str]		)       -> List[Any]:




              """simple docstring"""


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



@require_tf
class 							_UpperCamelCase					(	lowerCAmelCase_  ,						lowerCAmelCase_  ,						unittest.TestCase     ):
       _UpperCamelCase				:					List[str]         =   (
           (
               TFFunnelModel,
               TFFunnelForMaskedLM,
               TFFunnelForPreTraining,
               TFFunnelForQuestionAnswering,
               TFFunnelForTokenClassification,
           )
           if is_tf_available()
           else ()
       )
       _UpperCamelCase				:					List[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 {}
       )
       _UpperCamelCase				:					Any         =   False
       _UpperCamelCase				:					Union[str, Any]         =   False

       def lowercase (		self: str		)       -> Tuple:




              """simple docstring"""


              UpperCamelCase_          =  TFFunnelModelTester(self		)
              UpperCamelCase_          =  ConfigTester(self					,   config_class=_SCREAMING_SNAKE_CASE		)

       def lowercase (		self: Tuple		)       -> Optional[int]:




              """simple docstring"""


              self.config_tester.run_common_tests()

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




              """simple docstring"""


              UpperCamelCase_          =  self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE		)

       def lowercase (		self: List[str]		)       -> Dict:




              """simple docstring"""


              UpperCamelCase_          =  self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_pretraining(*_SCREAMING_SNAKE_CASE		)

       def lowercase (		self: int		)       -> Dict:




              """simple docstring"""


              UpperCamelCase_          =  self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_masked_lm(*_SCREAMING_SNAKE_CASE		)

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




              """simple docstring"""


              UpperCamelCase_          =  self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_token_classification(*_SCREAMING_SNAKE_CASE		)



       def lowercase (		self: Union[str, Any]		)       -> Optional[int]:




              """simple docstring"""


              UpperCamelCase_          =  self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_question_answering(*_SCREAMING_SNAKE_CASE		)



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

       def lowercase (		self: Optional[int]		)       -> List[str]:




              """simple docstring"""


              UpperCamelCase_          =  TFFunnelModelTester(self					,   base=_SCREAMING_SNAKE_CASE		)
              UpperCamelCase_          =  ConfigTester(self					,   config_class=_SCREAMING_SNAKE_CASE		)

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




              """simple docstring"""


              self.config_tester.run_common_tests()

       def lowercase (		self: Any		)       -> str:




              """simple docstring"""


              UpperCamelCase_          =  self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_base_model(*_SCREAMING_SNAKE_CASE		)

       def lowercase (		self: Dict		)       -> List[Any]:




              """simple docstring"""


              UpperCamelCase_          =  self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_sequence_classification(*_SCREAMING_SNAKE_CASE		)



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




              """simple docstring"""


              UpperCamelCase_          =  self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_multiple_choice(*_SCREAMING_SNAKE_CASE		)








import random
from typing import Any




def  lowerCAmelCase_ (							UpperCamelCase_  )     ->		list[Any]:
       for _ in range(len(UpperCamelCase_  )  ):
              UpperCamelCase_          =  random.randint(0					,		len(UpperCamelCase_  ) - 1  )
              UpperCamelCase_          =  random.randint(0					,		len(UpperCamelCase_  ) - 1  )
              UpperCamelCase_       , UpperCamelCase_          =  data[b], data[a]
       return data


if __name__ == "__main__":
     _UpperCAmelCase        =				[0, 1, 2, 3, 4, 5, 6, 7]
     _UpperCAmelCase        =				['python', 'says', 'hello', '!']
     print('Fisher-Yates Shuffle:')
     print('List', integers, strings)
     print('FY Shuffle', fisher_yates_shuffle(integers), fisher_yates_shuffle(strings))

