
"""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 	__a	:






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







              """simple docstring"""
              UpperCamelCase       			=		TFFunnelModel(config=UpperCAmelCase_      )
              UpperCamelCase       			=		{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
              UpperCamelCase       			=		model(UpperCAmelCase_      )

              UpperCamelCase       			=		[input_ids, input_mask]
              UpperCamelCase       			=		model(UpperCAmelCase_      )

              UpperCamelCase       			=		model(UpperCAmelCase_      )
              self.parent.assertEqual(result.last_hidden_state.shape							,   (self.batch_size, self.seq_length, self.d_model)      )

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

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






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







              """simple docstring"""
              UpperCamelCase       			=		TFFunnelBaseModel(config=UpperCAmelCase_      )
              UpperCamelCase       			=		{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
              UpperCamelCase       			=		model(UpperCAmelCase_      )

              UpperCamelCase       			=		[input_ids, input_mask]
              UpperCamelCase       			=		model(UpperCAmelCase_      )

              UpperCamelCase       			=		model(UpperCAmelCase_      )
              self.parent.assertEqual(result.last_hidden_state.shape							,   (self.batch_size, 2, self.d_model)      )

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

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






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







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






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







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






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







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






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







              """simple docstring"""
              UpperCamelCase       			=		self.num_choices
              UpperCamelCase       			=		TFFunnelForMultipleChoice(config=UpperCAmelCase_      )
              UpperCamelCase       			=		tf.tile(tf.expand_dims(UpperCAmelCase_							,   1      )							,   (1, self.num_choices, 1)      )
              UpperCamelCase       			=		tf.tile(tf.expand_dims(UpperCAmelCase_							,   1      )							,   (1, self.num_choices, 1)      )
              UpperCamelCase       			=		tf.tile(tf.expand_dims(UpperCAmelCase_							,   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(UpperCAmelCase_      )
              self.parent.assertEqual(result.logits.shape							,   (self.batch_size, self.num_choices)      )






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







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






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







              """simple docstring"""
              UpperCamelCase       			=		TFFunnelForQuestionAnswering(config=UpperCAmelCase_      )
              UpperCamelCase       			=		{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
              UpperCamelCase       			=		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 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[Any]      )->	Tuple:







              """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 	__a	(   _lowerCAmelCase     ,  _lowerCAmelCase     ,  unittest.TestCase						):
       UpperCamelCase_		:       Tuple				=      (
           (
               TFFunnelModel,
               TFFunnelForMaskedLM,
               TFFunnelForPreTraining,
               TFFunnelForQuestionAnswering,
               TFFunnelForTokenClassification,
           )
           if is_tf_available()
           else ()
       )
       UpperCamelCase_		:       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_		:       Optional[Any]				=      False
       UpperCamelCase_		:       int				=      False






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[Any]      )->	int:







              """simple docstring"""
              UpperCamelCase       			=		TFFunnelModelTester(self      )
              UpperCamelCase       			=		ConfigTester(self							,   config_class=UpperCAmelCase_      )






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







              """simple docstring"""
              self.config_tester.run_common_tests()






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[int]      )->	Optional[Any]:







              """simple docstring"""
              UpperCamelCase       			=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_model(*UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[Any]      )->	Dict:







              """simple docstring"""
              UpperCamelCase       			=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_pretraining(*UpperCAmelCase_      )






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







              """simple docstring"""
              UpperCamelCase       			=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase_      )






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







              """simple docstring"""
              UpperCamelCase       			=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				int      )->	int:







              """simple docstring"""
              UpperCamelCase       			=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase_      )





@require_tf
class 	__a	(   _lowerCAmelCase     ,  unittest.TestCase						):
       UpperCamelCase_		:       List[str]				=      (
           (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
       )
       UpperCamelCase_		:       List[Any]				=      False
       UpperCamelCase_		:       Union[str, Any]				=      False






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[Any]      )->	int:







              """simple docstring"""
              UpperCamelCase       			=		TFFunnelModelTester(self							,   base=UpperCAmelCase_      )
              UpperCamelCase       			=		ConfigTester(self							,   config_class=UpperCAmelCase_      )






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







              """simple docstring"""
              self.config_tester.run_common_tests()






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Any      )->	Any:







              """simple docstring"""
              UpperCamelCase       			=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_base_model(*UpperCAmelCase_      )






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







              """simple docstring"""
              UpperCamelCase       			=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				str      )->	Any:







              """simple docstring"""
              UpperCamelCase       			=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_multiple_choice(*UpperCAmelCase_      )







"""simple docstring"""


def 						lowerCamelCase__      (				UpperCAmelCase_ = 60_08_51_47_51_43					)->				int:







       """simple docstring"""

       try:
              UpperCamelCase       			=		int(UpperCAmelCase_					)
       except (TypeError, ValueError):
              raise TypeError("Parameter n must be int or castable to int."					)
       if n <= 0:
              raise ValueError("Parameter n must be greater than or equal to one."					)
       UpperCamelCase       			=		2
       UpperCamelCase       			=		0
       if n == 2:
              return 2
       while n > 2:
              while n % i != 0:
                     i += 1
              UpperCamelCase       			=		i
              while n % i == 0:
                     UpperCamelCase       			=		n // i
              i += 1
       return int(UpperCAmelCase_					)


if __name__ == "__main__":
      print(F'''{solution() = }''')





