





import unittest

from transformers import FunnelConfig, FunnelTokenizer, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch

  from transformers import (
      MODEL_FOR_PRETRAINING_MAPPING,
      FunnelBaseModel,
      FunnelForMaskedLM,
      FunnelForMultipleChoice,
      FunnelForPreTraining,
      FunnelForQuestionAnswering,
      FunnelForSequenceClassification,
      FunnelForTokenClassification,
      FunnelModel,
  )

class 		__a							:



       def __init__(     self	:   Optional[int]					,			UpperCAmelCase	:   List[Any]					,			UpperCAmelCase	:   Tuple=13					,			UpperCAmelCase	:   Optional[int]=7					,			UpperCAmelCase	:   List[str]=True					,			UpperCAmelCase	:   Union[str, Any]=True					,			UpperCAmelCase	:   Optional[int]=True					,			UpperCAmelCase	:   Dict=True					,			UpperCAmelCase	:   List[str]=99					,			UpperCAmelCase	:   str=[1, 1, 2]					,			UpperCAmelCase	:   List[str]=1					,			UpperCAmelCase	:   str=32					,			UpperCAmelCase	:   List[Any]=4					,			UpperCAmelCase	:   List[str]=8					,			UpperCAmelCase	:   str=37					,			UpperCAmelCase	:   Tuple="gelu_new"					,			UpperCAmelCase	:   Dict=0.1					,			UpperCAmelCase	:   Any=0.1					,			UpperCAmelCase	:   List[Any]=0.0					,			UpperCAmelCase	:   Tuple=5_12					,			UpperCAmelCase	:   Tuple=3					,			UpperCAmelCase	:   Dict=0.02					,			UpperCAmelCase	:   List[str]=3					,			UpperCAmelCase	:   List[str]=4					,			UpperCAmelCase	:   Tuple=None					,			UpperCAmelCase	:   Any=False					,			):
           lowerCAmelCase_					:	Dict						=   parent
           lowerCAmelCase_					:	str						=   batch_size
           lowerCAmelCase_					:	Union[str, Any]						=   seq_length
           lowerCAmelCase_					:	List[Any]						=   is_training
           lowerCAmelCase_					:	List[str]						=   use_input_mask
           lowerCAmelCase_					:	Optional[int]						=   use_token_type_ids
           lowerCAmelCase_					:	str						=   use_labels
           lowerCAmelCase_					:	Union[str, Any]						=   vocab_size
           lowerCAmelCase_					:	List[Any]						=   block_sizes
           lowerCAmelCase_					:	str						=   num_decoder_layers
           lowerCAmelCase_					:	Dict						=   d_model
           lowerCAmelCase_					:	List[str]						=   n_head
           lowerCAmelCase_					:	List[str]						=   d_head
           lowerCAmelCase_					:	Optional[Any]						=   d_inner
           lowerCAmelCase_					:	List[str]						=   hidden_act
           lowerCAmelCase_					:	Dict						=   hidden_dropout
           lowerCAmelCase_					:	Optional[Any]						=   attention_dropout
           lowerCAmelCase_					:	Optional[int]						=   activation_dropout
           lowerCAmelCase_					:	Union[str, Any]						=   max_position_embeddings
           lowerCAmelCase_					:	Optional[Any]						=   type_vocab_size
           lowerCAmelCase_					:	Optional[Any]						=   2
           lowerCAmelCase_					:	str						=   num_labels
           lowerCAmelCase_					:	Any						=   num_choices
           lowerCAmelCase_					:	List[str]						=   scope
           lowerCAmelCase_					:	Dict						=   initializer_std

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



       def  A							(     self	:   Tuple			):
           lowerCAmelCase_					:	str						=   ids_tensor([self.batch_size, self.seq_length]					,			self.vocab_size			)

           lowerCAmelCase_					:	Any						=   None
           if self.use_input_mask:
               lowerCAmelCase_					:	Union[str, Any]						=   ids_tensor([self.batch_size, self.seq_length]					,			vocab_size=2			)

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

           lowerCAmelCase_					:	int						=   None
           lowerCAmelCase_					:	Any						=   None
           lowerCAmelCase_					:	Optional[int]						=   None
           if self.use_labels:
               lowerCAmelCase_					:	Optional[Any]						=   ids_tensor([self.batch_size]					,			self.type_sequence_label_size			)
               lowerCAmelCase_					:	List[Any]						=   ids_tensor([self.batch_size, self.seq_length]					,			self.num_labels			)
               lowerCAmelCase_					:	Union[str, Any]						=   ids_tensor([self.batch_size]					,			self.num_choices			)
               lowerCAmelCase_					:	int						=   ids_tensor([self.batch_size, self.seq_length]					,			1			)

           lowerCAmelCase_					:	Dict						=   self.get_config()

           return (
               config,
               input_ids,
               token_type_ids,
               input_mask,
               sequence_labels,
               token_labels,
               choice_labels,
               fake_token_labels,
           )



       def  A							(     self	:   Any			):
           return 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					,			)



       def  A							(     self	:   Any					,			UpperCAmelCase	:   List[Any]					,			UpperCAmelCase	:   str					,			UpperCAmelCase	:   Tuple					,			UpperCAmelCase	:   str					,			UpperCAmelCase	:   int					,			UpperCAmelCase	:   Dict					,			UpperCAmelCase	:   List[str]					,			UpperCAmelCase	:   List[str]					,			):
           lowerCAmelCase_					:	str						=   FunnelModel(config=UpperCAmelCase			)
           model.to(UpperCAmelCase			)
           model.eval()
           lowerCAmelCase_					:	int						=   model(UpperCAmelCase					,			attention_mask=UpperCAmelCase					,			token_type_ids=UpperCAmelCase			)
           lowerCAmelCase_					:	str						=   model(UpperCAmelCase					,			token_type_ids=UpperCAmelCase			)
           lowerCAmelCase_					:	List[Any]						=   model(UpperCAmelCase			)
           self.parent.assertEqual(result.last_hidden_state.shape					,			(self.batch_size, self.seq_length, self.d_model)			)

           lowerCAmelCase_					:	List[str]						=   False
           lowerCAmelCase_					:	Dict						=   model(UpperCAmelCase			)
           self.parent.assertEqual(result.last_hidden_state.shape					,			(self.batch_size, self.seq_length, self.d_model)			)

           lowerCAmelCase_					:	Optional[Any]						=   False
           lowerCAmelCase_					:	Optional[Any]						=   model(UpperCAmelCase			)
           self.parent.assertEqual(result.last_hidden_state.shape					,			(self.batch_size, self.seq_length, self.d_model)			)



       def  A							(     self	:   Union[str, Any]					,			UpperCAmelCase	:   str					,			UpperCAmelCase	:   Any					,			UpperCAmelCase	:   Optional[int]					,			UpperCAmelCase	:   Dict					,			UpperCAmelCase	:   List[Any]					,			UpperCAmelCase	:   List[str]					,			UpperCAmelCase	:   List[str]					,			UpperCAmelCase	:   int					,			):
           lowerCAmelCase_					:	List[Any]						=   FunnelBaseModel(config=UpperCAmelCase			)
           model.to(UpperCAmelCase			)
           model.eval()
           lowerCAmelCase_					:	Tuple						=   model(UpperCAmelCase					,			attention_mask=UpperCAmelCase					,			token_type_ids=UpperCAmelCase			)
           lowerCAmelCase_					:	List[str]						=   model(UpperCAmelCase					,			token_type_ids=UpperCAmelCase			)
           lowerCAmelCase_					:	List[Any]						=   model(UpperCAmelCase			)
           self.parent.assertEqual(result.last_hidden_state.shape					,			(self.batch_size, 2, self.d_model)			)

           lowerCAmelCase_					:	int						=   False
           lowerCAmelCase_					:	Optional[Any]						=   model(UpperCAmelCase			)
           self.parent.assertEqual(result.last_hidden_state.shape					,			(self.batch_size, 3, self.d_model)			)

           lowerCAmelCase_					:	Optional[int]						=   False
           lowerCAmelCase_					:	Dict						=   model(UpperCAmelCase			)
           self.parent.assertEqual(result.last_hidden_state.shape					,			(self.batch_size, 2, self.d_model)			)



       def  A							(     self	:   Any					,			UpperCAmelCase	:   List[str]					,			UpperCAmelCase	:   Union[str, Any]					,			UpperCAmelCase	:   Tuple					,			UpperCAmelCase	:   Union[str, Any]					,			UpperCAmelCase	:   Union[str, Any]					,			UpperCAmelCase	:   List[str]					,			UpperCAmelCase	:   Optional[int]					,			UpperCAmelCase	:   Optional[Any]					,			):
           lowerCAmelCase_					:	Dict						=   self.num_labels
           lowerCAmelCase_					:	int						=   FunnelForPreTraining(config=UpperCAmelCase			)
           model.to(UpperCAmelCase			)
           model.eval()
           lowerCAmelCase_					:	str						=   model(UpperCAmelCase					,			attention_mask=UpperCAmelCase					,			token_type_ids=UpperCAmelCase					,			labels=UpperCAmelCase			)
           self.parent.assertEqual(result.logits.shape					,			(self.batch_size, self.seq_length)			)



       def  A							(     self	:   Tuple					,			UpperCAmelCase	:   Union[str, Any]					,			UpperCAmelCase	:   Optional[int]					,			UpperCAmelCase	:   int					,			UpperCAmelCase	:   int					,			UpperCAmelCase	:   Optional[int]					,			UpperCAmelCase	:   Dict					,			UpperCAmelCase	:   List[str]					,			UpperCAmelCase	:   int					,			):
           lowerCAmelCase_					:	Union[str, Any]						=   FunnelForMaskedLM(config=UpperCAmelCase			)
           model.to(UpperCAmelCase			)
           model.eval()
           lowerCAmelCase_					:	List[Any]						=   model(UpperCAmelCase					,			attention_mask=UpperCAmelCase					,			token_type_ids=UpperCAmelCase					,			labels=UpperCAmelCase			)
           self.parent.assertEqual(result.logits.shape					,			(self.batch_size, self.seq_length, self.vocab_size)			)



       def  A							(     self	:   List[Any]					,			UpperCAmelCase	:   Any					,			UpperCAmelCase	:   Optional[int]					,			UpperCAmelCase	:   List[str]					,			UpperCAmelCase	:   Any					,			UpperCAmelCase	:   Optional[int]					,			UpperCAmelCase	:   Optional[Any]					,			UpperCAmelCase	:   Optional[Any]					,			UpperCAmelCase	:   str					,			):
           lowerCAmelCase_					:	Tuple						=   self.num_labels
           lowerCAmelCase_					:	Optional[Any]						=   FunnelForSequenceClassification(UpperCAmelCase			)
           model.to(UpperCAmelCase			)
           model.eval()
           lowerCAmelCase_					:	Optional[Any]						=   model(UpperCAmelCase					,			attention_mask=UpperCAmelCase					,			token_type_ids=UpperCAmelCase					,			labels=UpperCAmelCase			)
           self.parent.assertEqual(result.logits.shape					,			(self.batch_size, self.num_labels)			)



       def  A							(     self	:   Any					,			UpperCAmelCase	:   List[Any]					,			UpperCAmelCase	:   Tuple					,			UpperCAmelCase	:   Tuple					,			UpperCAmelCase	:   Any					,			UpperCAmelCase	:   List[str]					,			UpperCAmelCase	:   Optional[Any]					,			UpperCAmelCase	:   List[str]					,			UpperCAmelCase	:   int					,			):
           lowerCAmelCase_					:	Dict						=   self.num_choices
           lowerCAmelCase_					:	Dict						=   FunnelForMultipleChoice(config=UpperCAmelCase			)
           model.to(UpperCAmelCase			)
           model.eval()
           lowerCAmelCase_					:	int						=   input_ids.unsqueeze(1			).expand(-1					,			self.num_choices					,			-1			).contiguous()
           lowerCAmelCase_					:	Tuple						=   token_type_ids.unsqueeze(1			).expand(-1					,			self.num_choices					,			-1			).contiguous()
           lowerCAmelCase_					:	Tuple						=   input_mask.unsqueeze(1			).expand(-1					,			self.num_choices					,			-1			).contiguous()
           lowerCAmelCase_					:	int						=   model(
               UpperCAmelCase					,			attention_mask=UpperCAmelCase					,			token_type_ids=UpperCAmelCase					,			labels=UpperCAmelCase					,			)
           self.parent.assertEqual(result.logits.shape					,			(self.batch_size, self.num_choices)			)



       def  A							(     self	:   Tuple					,			UpperCAmelCase	:   str					,			UpperCAmelCase	:   List[Any]					,			UpperCAmelCase	:   Dict					,			UpperCAmelCase	:   Any					,			UpperCAmelCase	:   Optional[int]					,			UpperCAmelCase	:   str					,			UpperCAmelCase	:   Optional[int]					,			UpperCAmelCase	:   Dict					,			):
           lowerCAmelCase_					:	List[Any]						=   self.num_labels
           lowerCAmelCase_					:	Any						=   FunnelForTokenClassification(config=UpperCAmelCase			)
           model.to(UpperCAmelCase			)
           model.eval()
           lowerCAmelCase_					:	List[Any]						=   model(UpperCAmelCase					,			attention_mask=UpperCAmelCase					,			token_type_ids=UpperCAmelCase					,			labels=UpperCAmelCase			)
           self.parent.assertEqual(result.logits.shape					,			(self.batch_size, self.seq_length, self.num_labels)			)



       def  A							(     self	:   Optional[int]					,			UpperCAmelCase	:   Union[str, Any]					,			UpperCAmelCase	:   Tuple					,			UpperCAmelCase	:   Optional[Any]					,			UpperCAmelCase	:   List[str]					,			UpperCAmelCase	:   List[Any]					,			UpperCAmelCase	:   List[Any]					,			UpperCAmelCase	:   str					,			UpperCAmelCase	:   List[Any]					,			):
           lowerCAmelCase_					:	Tuple						=   FunnelForQuestionAnswering(config=UpperCAmelCase			)
           model.to(UpperCAmelCase			)
           model.eval()
           lowerCAmelCase_					:	List[str]						=   model(
               UpperCAmelCase					,			attention_mask=UpperCAmelCase					,			token_type_ids=UpperCAmelCase					,			start_positions=UpperCAmelCase					,			end_positions=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  A							(     self	:   Optional[int]			):
           lowerCAmelCase_					:	Union[str, Any]						=   self.prepare_config_and_inputs()
           (
               (
               lowerCAmelCase_
           )		,		(
               lowerCAmelCase_
           )		,		(
               lowerCAmelCase_
           )		,		(
               lowerCAmelCase_
           )		,		(
               lowerCAmelCase_
           )		,		(
               lowerCAmelCase_
           )		,		(
               lowerCAmelCase_
           )		,		(
               lowerCAmelCase_
           )		,		
           )					:	Any						=   config_and_inputs
           lowerCAmelCase_					:	List[str]						=   {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
           return config, inputs_dict






@require_torch
class 		__a							(	__UpperCamelCase			,__UpperCamelCase			,unittest.TestCase      ):
       __snake_case						:   Optional[Any]      =		False
       __snake_case						:   int      =		False
       __snake_case						:   Tuple      =		(
           (
               FunnelModel,
               FunnelForMaskedLM,
               FunnelForPreTraining,
               FunnelForQuestionAnswering,
               FunnelForTokenClassification,
           )
           if is_torch_available()
           else ()
       )
       __snake_case						:   Any      =		(
           {
               """feature-extraction""": (FunnelBaseModel, FunnelModel),
               """fill-mask""": FunnelForMaskedLM,
               """question-answering""": FunnelForQuestionAnswering,
               """text-classification""": FunnelForSequenceClassification,
               """token-classification""": FunnelForTokenClassification,
               """zero-shot""": FunnelForSequenceClassification,
           }
           if is_torch_available()
           else {}
       )



       def  A							(     self	:   Optional[Any]					,			UpperCAmelCase	:   Tuple					,			UpperCAmelCase	:   Any					,			UpperCAmelCase	:   Tuple=False			):
           lowerCAmelCase_					:	Any						=   super()._prepare_for_class(UpperCAmelCase					,			UpperCAmelCase					,			return_labels=UpperCAmelCase			)

           if return_labels:
               if model_class in get_values(UpperCAmelCase			):
                   lowerCAmelCase_					:	int						=   torch.zeros(
                       (self.model_tester.batch_size, self.model_tester.seq_length)					,			dtype=torch.long					,			device=UpperCAmelCase			)
           return inputs_dict



       def  A							(     self	:   int			):
           lowerCAmelCase_					:	Optional[int]						=   FunnelModelTester(self			)
           lowerCAmelCase_					:	int						=   ConfigTester(self					,			config_class=UpperCAmelCase			)



       def  A							(     self	:   List[str]			):
           self.config_tester.run_common_tests()



       def  A							(     self	:   int			):
           lowerCAmelCase_					:	str						=   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*UpperCAmelCase			)



       def  A							(     self	:   List[str]			):
           lowerCAmelCase_					:	Union[str, Any]						=   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_pretraining(*UpperCAmelCase			)



       def  A							(     self	:   Optional[Any]			):
           lowerCAmelCase_					:	Union[str, Any]						=   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase			)



       def  A							(     self	:   List[Any]			):
           lowerCAmelCase_					:	Dict						=   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase			)



       def  A							(     self	:   List[str]			):
           lowerCAmelCase_					:	Dict						=   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase			)



       def  A							(     self	:   Union[str, Any]					,			UpperCAmelCase	:   List[Any]			):
           if hasattr(UpperCAmelCase					,			"""weight"""			) and module.weight is not None:
               module.weight.data.fill_(3			)
           if hasattr(UpperCAmelCase					,			"""bias"""			) and module.bias is not None:
               module.bias.data.fill_(3			)

           for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
               if hasattr(UpperCAmelCase					,			UpperCAmelCase			) and getattr(UpperCAmelCase					,			UpperCAmelCase			) is not None:
                   lowerCAmelCase_					:	Tuple						=   getattr(UpperCAmelCase					,			UpperCAmelCase			)
                   weight.data.fill_(3			)






@require_torch
class 		__a							(	__UpperCamelCase			,unittest.TestCase      ):
       __snake_case						:   Tuple      =		False
       __snake_case						:   Optional[Any]      =		False
       __snake_case						:   Tuple      =		(
           (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
       )



       def  A							(     self	:   List[Any]			):
           lowerCAmelCase_					:	List[Any]						=   FunnelModelTester(self					,			base=UpperCAmelCase			)
           lowerCAmelCase_					:	Optional[int]						=   ConfigTester(self					,			config_class=UpperCAmelCase			)



       def  A							(     self	:   List[Any]			):
           self.config_tester.run_common_tests()



       def  A							(     self	:   List[Any]			):
           lowerCAmelCase_					:	Optional[Any]						=   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_base_model(*UpperCAmelCase			)



       def  A							(     self	:   Union[str, Any]			):
           lowerCAmelCase_					:	Any						=   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase			)



       def  A							(     self	:   Optional[Any]			):
           lowerCAmelCase_					:	Union[str, Any]						=   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_multiple_choice(*UpperCAmelCase			)



       def  A							(     self	:   Union[str, Any]			):
           lowerCAmelCase_		,		lowerCAmelCase_					:	str						=   self.model_tester.prepare_config_and_inputs_for_common()
           lowerCAmelCase_					:	Tuple						=   True

           for model_class in self.all_model_classes:
               if model_class.__name__ == "FunnelBaseModel":
                   continue
               lowerCAmelCase_					:	Dict						=   model_class(UpperCAmelCase			)
               model.to(UpperCAmelCase			)
               model.train()
               lowerCAmelCase_					:	str						=   self._prepare_for_class(UpperCAmelCase					,			UpperCAmelCase					,			return_labels=UpperCAmelCase			)
               lowerCAmelCase_					:	int						=   model(**UpperCAmelCase			).loss
               loss.backward()



       def  A							(     self	:   str					,			UpperCAmelCase	:   Dict			):
           if hasattr(UpperCAmelCase					,			"""weight"""			) and module.weight is not None:
               module.weight.data.fill_(3			)
           if hasattr(UpperCAmelCase					,			"""bias"""			) and module.bias is not None:
               module.bias.data.fill_(3			)

           for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
               if hasattr(UpperCAmelCase					,			UpperCAmelCase			) and getattr(UpperCAmelCase					,			UpperCAmelCase			) is not None:
                   lowerCAmelCase_					:	List[str]						=   getattr(UpperCAmelCase					,			UpperCAmelCase			)
                   weight.data.fill_(3			)






@require_torch
@require_sentencepiece
@require_tokenizers
class 		__a							(	unittest.TestCase      ):



       def  A							(     self	:   Any			):
           lowerCAmelCase_					:	Tuple						=   13
           lowerCAmelCase_					:	Optional[int]						=   7
           lowerCAmelCase_					:	List[str]						=   torch.arange(0					,			batch_size * sequence_length			).long().reshape(UpperCAmelCase					,			UpperCAmelCase			)
           lowerCAmelCase_					:	Optional[int]						=   [0, 1, 2, 3, 4, 5, 6, 4, 1, 3, 5, 0, 1]
           lowerCAmelCase_					:	Union[str, Any]						=   torch.tensor([[2] + [0] * a + [1] * (sequence_length - a - 1) for a in lengths]			)

           lowerCAmelCase_					:	Dict						=   FunnelModel.from_pretrained("""sgugger/funnel-random-tiny"""			)
           lowerCAmelCase_					:	Dict						=   model(UpperCAmelCase					,			token_type_ids=UpperCAmelCase			)[0].abs()

           lowerCAmelCase_					:	Optional[int]						=   torch.tensor(2344.8352			)
           lowerCAmelCase_					:	str						=   torch.tensor(0.8052			)
           self.assertTrue(torch.allclose(output.sum()					,			UpperCAmelCase					,			atol=1e-4			)			)
           self.assertTrue(torch.allclose(output.mean()					,			UpperCAmelCase					,			atol=1e-4			)			)

           lowerCAmelCase_					:	List[str]						=   torch.tensor([[1] * 7, [1] * 4 + [0] * 3] * 6 + [[0, 1, 1, 0, 0, 1, 1]]			)
           lowerCAmelCase_					:	Optional[int]						=   model(UpperCAmelCase					,			attention_mask=UpperCAmelCase					,			token_type_ids=UpperCAmelCase			)[0].abs()

           lowerCAmelCase_					:	List[str]						=   torch.tensor(2343.8425			)
           lowerCAmelCase_					:	Optional[int]						=   torch.tensor(0.8049			)
           self.assertTrue(torch.allclose(output.sum()					,			UpperCAmelCase					,			atol=1e-4			)			)
           self.assertTrue(torch.allclose(output.mean()					,			UpperCAmelCase					,			atol=1e-4			)			)



       @slow
       def  A							(     self	:   Optional[int]			):
           lowerCAmelCase_					:	Optional[int]						=   FunnelTokenizer.from_pretrained("""huggingface/funnel-small"""			)
           lowerCAmelCase_					:	int						=   FunnelModel.from_pretrained("""huggingface/funnel-small"""			)
           lowerCAmelCase_					:	str						=   tokenizer("""Hello! I am the Funnel Transformer model."""					,			return_tensors="""pt"""			)
           lowerCAmelCase_					:	Optional[int]						=   model(**UpperCAmelCase			)[0]

           lowerCAmelCase_					:	Union[str, Any]						=   torch.tensor(235.7246			)
           lowerCAmelCase_					:	str						=   torch.tensor(0.0256			)
           self.assertTrue(torch.allclose(output.sum()					,			UpperCAmelCase					,			atol=1e-4			)			)
           self.assertTrue(torch.allclose(output.mean()					,			UpperCAmelCase					,			atol=1e-4			)			)









import math
def 			__UpperCamelCase				(			lowercase__	:       int		)	->      list:
    '''simple docstring'''





    if n <= 0:
        raise ValueError("""Only positive integers have prime factors"""		)
    lowerCAmelCase_					:	str						=   []
    while n % 2 == 0:
        pf.append(2		)
        lowerCAmelCase_					:	str						=   int(n / 2		)
    for i in range(3		,    int(math.sqrt(lowercase__		)		) + 1		,    2		):
        while n % i == 0:
            pf.append(lowercase__		)
            lowerCAmelCase_					:	List[Any]						=   int(n / i		)
    if n > 2:
        pf.append(lowercase__		)
    return pf
def 			__UpperCamelCase				(			lowercase__	:       int		)	->      int:
    '''simple docstring'''





    if n <= 0:
        raise ValueError("""Only positive numbers are accepted"""		)
    lowerCAmelCase_					:	Union[str, Any]						=   1
    lowerCAmelCase_					:	str						=   1
    while n % 2 == 0:
        temp += 1
        lowerCAmelCase_					:	Optional[Any]						=   int(n / 2		)
    div *= temp
    for i in range(3		,    int(math.sqrt(lowercase__		)		) + 1		,    2		):
        lowerCAmelCase_					:	Tuple						=   1
        while n % i == 0:
            temp += 1
            lowerCAmelCase_					:	Any						=   int(n / i		)
        div *= temp
    if n > 1:
        div *= 2
    return div
def 			__UpperCamelCase				(			lowercase__	:       int		)	->      int:
    '''simple docstring'''





    if n <= 0:
        raise ValueError("""Only positive numbers are accepted"""		)
    lowerCAmelCase_					:	Tuple						=   1
    lowerCAmelCase_					:	str						=   1
    while n % 2 == 0:
        temp += 1
        lowerCAmelCase_					:	Optional[int]						=   int(n / 2		)
    if temp > 1:
        s *= (2**temp - 1) / (2 - 1)
    for i in range(3		,    int(math.sqrt(lowercase__		)		) + 1		,    2		):
        lowerCAmelCase_					:	int						=   1
        while n % i == 0:
            temp += 1
            lowerCAmelCase_					:	Any						=   int(n / i		)
        if temp > 1:
            s *= (i**temp - 1) / (i - 1)
    return int(lowercase__		)
def 			__UpperCamelCase				(			lowercase__	:       int		)	->      int:
    '''simple docstring'''





    lowerCAmelCase_					:	str						=   n
    for x in set(prime_factors(lowercase__		)		):
        s *= (x - 1) / x
    return int(lowercase__		)


if __name__ == "__main__":
  import doctest

  doctest.testmod()


