
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 					_lowerCamelCase			:





     """simple docstring"""







     def __init__(				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE=1_3    ,    __SCREAMING_SNAKE_CASE=7    ,    __SCREAMING_SNAKE_CASE=True    ,    __SCREAMING_SNAKE_CASE=True    ,    __SCREAMING_SNAKE_CASE=True    ,    __SCREAMING_SNAKE_CASE=True    ,    __SCREAMING_SNAKE_CASE=9_9    ,    __SCREAMING_SNAKE_CASE=[1, 1, 2]    ,    __SCREAMING_SNAKE_CASE=1    ,    __SCREAMING_SNAKE_CASE=3_2    ,    __SCREAMING_SNAKE_CASE=4    ,    __SCREAMING_SNAKE_CASE=8    ,    __SCREAMING_SNAKE_CASE=3_7    ,    __SCREAMING_SNAKE_CASE="gelu_new"    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE=0.0    ,    __SCREAMING_SNAKE_CASE=5_1_2    ,    __SCREAMING_SNAKE_CASE=3    ,    __SCREAMING_SNAKE_CASE=0.02    ,    __SCREAMING_SNAKE_CASE=3    ,    __SCREAMING_SNAKE_CASE=4    ,    __SCREAMING_SNAKE_CASE=None    ,    __SCREAMING_SNAKE_CASE=False    ,    )	-> Any:




           """simple docstring"""







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

           # Used in the tests to check the size of the first attention layer
           UpperCamelCase__     : Optional[int]											=					n_head
           # Used in the tests to check the size of the first hidden state
           UpperCamelCase__     : Union[str, Any]											=					self.d_model
           # Used in the tests to check the number of output hidden states/attentions
           UpperCamelCase__     : 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:
                 UpperCamelCase__     : Union[str, Any]											=					self.num_hidden_layers + 2






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




           """simple docstring"""







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

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

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

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

           UpperCamelCase__     : Dict											=					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    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    )	-> int:




           """simple docstring"""







           UpperCamelCase__     : Dict											=					TFFunnelModel(config=__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Any											=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           UpperCamelCase__     : Optional[int]											=					model(__SCREAMING_SNAKE_CASE	)

           UpperCamelCase__     : Optional[int]											=					[input_ids, input_mask]
           UpperCamelCase__     : List[str]											=					model(__SCREAMING_SNAKE_CASE	)

           UpperCamelCase__     : Optional[int]											=					model(__SCREAMING_SNAKE_CASE	)
           self.parent.assertEqual(result.last_hidden_state.shape    ,    (self.batch_size, self.seq_length, self.d_model)	)

           UpperCamelCase__     : List[str]											=					False
           UpperCamelCase__     : List[Any]											=					TFFunnelModel(config=__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : List[str]											=					model(__SCREAMING_SNAKE_CASE	)
           self.parent.assertEqual(result.last_hidden_state.shape    ,    (self.batch_size, self.seq_length, self.d_model)	)

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






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    )	-> Optional[Any]:




           """simple docstring"""







           UpperCamelCase__     : str											=					TFFunnelBaseModel(config=__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : List[str]											=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           UpperCamelCase__     : str											=					model(__SCREAMING_SNAKE_CASE	)

           UpperCamelCase__     : List[Any]											=					[input_ids, input_mask]
           UpperCamelCase__     : Dict											=					model(__SCREAMING_SNAKE_CASE	)

           UpperCamelCase__     : Optional[Any]											=					model(__SCREAMING_SNAKE_CASE	)
           self.parent.assertEqual(result.last_hidden_state.shape    ,    (self.batch_size, 2, self.d_model)	)

           UpperCamelCase__     : Union[str, Any]											=					False
           UpperCamelCase__     : Tuple											=					TFFunnelBaseModel(config=__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Dict											=					model(__SCREAMING_SNAKE_CASE	)
           self.parent.assertEqual(result.last_hidden_state.shape    ,    (self.batch_size, 3, self.d_model)	)

           UpperCamelCase__     : str											=					False
           UpperCamelCase__     : int											=					TFFunnelBaseModel(config=__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Dict											=					model(__SCREAMING_SNAKE_CASE	)
           self.parent.assertEqual(result.last_hidden_state.shape    ,    (self.batch_size, 2, self.d_model)	)






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




           """simple docstring"""







           UpperCamelCase__     : int											=					TFFunnelForPreTraining(config=__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Any											=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           UpperCamelCase__     : Dict											=					model(__SCREAMING_SNAKE_CASE	)
           self.parent.assertEqual(result.logits.shape    ,    (self.batch_size, self.seq_length)	)






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    )	-> str:




           """simple docstring"""







           UpperCamelCase__     : int											=					TFFunnelForMaskedLM(config=__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Any											=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           UpperCamelCase__     : Tuple											=					model(__SCREAMING_SNAKE_CASE	)
           self.parent.assertEqual(result.logits.shape    ,    (self.batch_size, self.seq_length, self.vocab_size)	)






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    )	-> Tuple:




           """simple docstring"""







           UpperCamelCase__     : List[Any]											=					self.num_labels
           UpperCamelCase__     : List[str]											=					TFFunnelForSequenceClassification(config=__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Dict											=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           UpperCamelCase__     : Union[str, Any]											=					model(__SCREAMING_SNAKE_CASE	)
           self.parent.assertEqual(result.logits.shape    ,    (self.batch_size, self.num_labels)	)






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    )	-> Optional[Any]:




           """simple docstring"""







           UpperCamelCase__     : str											=					self.num_choices
           UpperCamelCase__     : Optional[Any]											=					TFFunnelForMultipleChoice(config=__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Tuple											=					tf.tile(tf.expand_dims(__SCREAMING_SNAKE_CASE    ,    1	)    ,    (1, self.num_choices, 1)	)
           UpperCamelCase__     : Dict											=					tf.tile(tf.expand_dims(__SCREAMING_SNAKE_CASE    ,    1	)    ,    (1, self.num_choices, 1)	)
           UpperCamelCase__     : List[Any]											=					tf.tile(tf.expand_dims(__SCREAMING_SNAKE_CASE    ,    1	)    ,    (1, self.num_choices, 1)	)
           UpperCamelCase__     : Dict											=					{
               '''input_ids''': multiple_choice_inputs_ids,
               '''attention_mask''': multiple_choice_input_mask,
               '''token_type_ids''': multiple_choice_token_type_ids,
           }
           UpperCamelCase__     : Tuple											=					model(__SCREAMING_SNAKE_CASE	)
           self.parent.assertEqual(result.logits.shape    ,    (self.batch_size, self.num_choices)	)






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    )	-> Dict:




           """simple docstring"""







           UpperCamelCase__     : Union[str, Any]											=					self.num_labels
           UpperCamelCase__     : Any											=					TFFunnelForTokenClassification(config=__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : List[str]											=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           UpperCamelCase__     : List[str]											=					model(__SCREAMING_SNAKE_CASE	)
           self.parent.assertEqual(result.logits.shape    ,    (self.batch_size, self.seq_length, self.num_labels)	)






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    )	-> str:




           """simple docstring"""







           UpperCamelCase__     : str											=					TFFunnelForQuestionAnswering(config=__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Dict											=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
           UpperCamelCase__     : Optional[Any]											=					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  __SCREAMING_SNAKE_CASE      (				self	)	-> List[str]:




           """simple docstring"""







           UpperCamelCase__     : str											=					self.prepare_config_and_inputs()
           (
               (
               UpperCamelCase__
           )					,(
               UpperCamelCase__
           )					,(
               UpperCamelCase__
           )					,(
               UpperCamelCase__
           )					,(
               UpperCamelCase__
           )					,(
               UpperCamelCase__
           )					,(
               UpperCamelCase__
           )					,
           )     : List[str]											=					config_and_inputs
           UpperCamelCase__     : Dict											=					{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
           return config, inputs_dict




@require_tf
class 					_lowerCamelCase			(   UpperCamelCase_						,				UpperCamelCase_						,				unittest.TestCase			):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		 =	(
         (
             TFFunnelModel,
             TFFunnelForMaskedLM,
             TFFunnelForPreTraining,
             TFFunnelForQuestionAnswering,
             TFFunnelForTokenClassification,
         )
         if is_tf_available()
         else ()
     )
     SCREAMING_SNAKE_CASE_		 =	(
         {
             '''feature-extraction''': (TFFunnelBaseModel, TFFunnelModel),
             '''fill-mask''': TFFunnelForMaskedLM,
             '''question-answering''': TFFunnelForQuestionAnswering,
             '''text-classification''': TFFunnelForSequenceClassification,
             '''token-classification''': TFFunnelForTokenClassification,
             '''zero-shot''': TFFunnelForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )
     SCREAMING_SNAKE_CASE_		 =	False
     SCREAMING_SNAKE_CASE_		 =	False






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> Tuple:




           """simple docstring"""







           UpperCamelCase__     : Union[str, Any]											=					TFFunnelModelTester(self	)
           UpperCamelCase__     : Tuple											=					ConfigTester(self    ,    config_class=__SCREAMING_SNAKE_CASE	)






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> List[str]:




           """simple docstring"""







           self.config_tester.run_common_tests()






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> str:




           """simple docstring"""







           UpperCamelCase__     : List[str]											=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE	)






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> Any:




           """simple docstring"""







           UpperCamelCase__     : Tuple											=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_pretraining(*__SCREAMING_SNAKE_CASE	)






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> Any:




           """simple docstring"""







           UpperCamelCase__     : str											=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_lm(*__SCREAMING_SNAKE_CASE	)






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> List[str]:




           """simple docstring"""







           UpperCamelCase__     : Optional[int]											=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*__SCREAMING_SNAKE_CASE	)






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> Any:




           """simple docstring"""







           UpperCamelCase__     : Tuple											=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_question_answering(*__SCREAMING_SNAKE_CASE	)




@require_tf
class 					_lowerCamelCase			(   UpperCamelCase_						,				unittest.TestCase			):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		 =	(
         (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
     )
     SCREAMING_SNAKE_CASE_		 =	False
     SCREAMING_SNAKE_CASE_		 =	False






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> List[str]:




           """simple docstring"""







           UpperCamelCase__     : List[str]											=					TFFunnelModelTester(self    ,    base=__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : List[str]											=					ConfigTester(self    ,    config_class=__SCREAMING_SNAKE_CASE	)






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> List[str]:




           """simple docstring"""







           self.config_tester.run_common_tests()






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> int:




           """simple docstring"""







           UpperCamelCase__     : Tuple											=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_base_model(*__SCREAMING_SNAKE_CASE	)






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> int:




           """simple docstring"""







           UpperCamelCase__     : Tuple											=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_sequence_classification(*__SCREAMING_SNAKE_CASE	)






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




           """simple docstring"""







           UpperCamelCase__     : int											=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_multiple_choice(*__SCREAMING_SNAKE_CASE	)




def 				SCREAMING_SNAKE_CASE_   (      UpperCamelCase__ = 2_0_0_0_0_0_0		):
      UpperCamelCase__     : Dict											=					[0 for i in range(n + 1		)]
      UpperCamelCase__     : Any											=					1
      UpperCamelCase__     : int											=					1

      for i in range(2			,		int(n**0.5		) + 1		):
            if primality_list[i] == 0:
                  for j in range(i * i			,		n + 1			,		UpperCamelCase__		):
                        UpperCamelCase__     : Any											=					1
      UpperCamelCase__     : Optional[Any]											=					0
      for i in range(UpperCamelCase__		):
            if primality_list[i] == 0:
                  sum_of_primes += i
      return sum_of_primes


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


