


'''simple docstring'''



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							:


     """simple docstring"""






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

          # Used in the tests to check the size of the first attention layer
          __UpperCAmelCase      :					Tuple    				=     n_head
          # Used in the tests to check the size of the first hidden state
          __UpperCAmelCase      :					Optional[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      :					str    				=     self.num_hidden_layers + 2

     def 					lowerCamelCase__					(							self	:						Dict     )		->				Tuple:
          __UpperCAmelCase      :					Optional[Any]    				=     ids_tensor([self.batch_size, self.seq_length]				,					self.vocab_size     )

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

          __UpperCAmelCase      :					Union[str, Any]    				=     None
          if self.use_token_type_ids:
               __UpperCAmelCase      :					Optional[int]    				=     ids_tensor([self.batch_size, self.seq_length]				,					self.type_vocab_size     )

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

          __UpperCAmelCase      :					List[str]    				=     self.get_config()

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

     def 					lowerCamelCase__					(							self	:						List[Any]     )		->				str:
          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 					lowerCamelCase__					(							self	:						int				,					snake_case	:						Union[str, Any]				,					snake_case	:						Tuple				,					snake_case	:						List[Any]				,					snake_case	:						Dict				,					snake_case	:						int				,					snake_case	:						List[str]				,					snake_case	:						Tuple				,					snake_case	:						Tuple				,					)		->				Tuple:
          __UpperCAmelCase      :					str    				=     FunnelModel(config=snake_case     )
          model.to(snake_case     )
          model.eval()
          __UpperCAmelCase      :					int    				=     model(snake_case				,					attention_mask=snake_case				,					token_type_ids=snake_case     )
          __UpperCAmelCase      :					Union[str, Any]    				=     model(snake_case				,					token_type_ids=snake_case     )
          __UpperCAmelCase      :					int    				=     model(snake_case     )
          self.parent.assertEqual(result.last_hidden_state.shape				,					(self.batch_size, self.seq_length, self.d_model)     )

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

          __UpperCAmelCase      :					Tuple    				=     False
          __UpperCAmelCase      :					Optional[int]    				=     model(snake_case     )
          self.parent.assertEqual(result.last_hidden_state.shape				,					(self.batch_size, self.seq_length, self.d_model)     )

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

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

          __UpperCAmelCase      :					Dict    				=     False
          __UpperCAmelCase      :					str    				=     model(snake_case     )
          self.parent.assertEqual(result.last_hidden_state.shape				,					(self.batch_size, 2, self.d_model)     )

     def 					lowerCamelCase__					(							self	:						List[str]				,					snake_case	:						Optional[Any]				,					snake_case	:						str				,					snake_case	:						Dict				,					snake_case	:						str				,					snake_case	:						List[Any]				,					snake_case	:						Optional[Any]				,					snake_case	:						Dict				,					snake_case	:						Dict				,					)		->				List[str]:
          __UpperCAmelCase      :					Dict    				=     self.num_labels
          __UpperCAmelCase      :					str    				=     FunnelForPreTraining(config=snake_case     )
          model.to(snake_case     )
          model.eval()
          __UpperCAmelCase      :					str    				=     model(snake_case				,					attention_mask=snake_case				,					token_type_ids=snake_case				,					labels=snake_case     )
          self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.seq_length)     )

     def 					lowerCamelCase__					(							self	:						List[str]				,					snake_case	:						Dict				,					snake_case	:						Dict				,					snake_case	:						Optional[int]				,					snake_case	:						List[str]				,					snake_case	:						str				,					snake_case	:						Union[str, Any]				,					snake_case	:						Dict				,					snake_case	:						Optional[int]				,					)		->				int:
          __UpperCAmelCase      :					Union[str, Any]    				=     FunnelForMaskedLM(config=snake_case     )
          model.to(snake_case     )
          model.eval()
          __UpperCAmelCase      :					Union[str, Any]    				=     model(snake_case				,					attention_mask=snake_case				,					token_type_ids=snake_case				,					labels=snake_case     )
          self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.seq_length, self.vocab_size)     )

     def 					lowerCamelCase__					(							self	:						Optional[Any]				,					snake_case	:						Any				,					snake_case	:						Any				,					snake_case	:						Union[str, Any]				,					snake_case	:						Optional[int]				,					snake_case	:						List[str]				,					snake_case	:						Union[str, Any]				,					snake_case	:						Optional[int]				,					snake_case	:						List[str]				,					)		->				List[Any]:
          __UpperCAmelCase      :					Optional[int]    				=     self.num_labels
          __UpperCAmelCase      :					Optional[Any]    				=     FunnelForSequenceClassification(snake_case     )
          model.to(snake_case     )
          model.eval()
          __UpperCAmelCase      :					str    				=     model(snake_case				,					attention_mask=snake_case				,					token_type_ids=snake_case				,					labels=snake_case     )
          self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.num_labels)     )

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

     def 					lowerCamelCase__					(							self	:						str				,					snake_case	:						str				,					snake_case	:						Optional[Any]				,					snake_case	:						Union[str, Any]				,					snake_case	:						List[str]				,					snake_case	:						Union[str, Any]				,					snake_case	:						Optional[Any]				,					snake_case	:						Dict				,					snake_case	:						List[Any]				,					)		->				Optional[Any]:
          __UpperCAmelCase      :					str    				=     self.num_labels
          __UpperCAmelCase      :					List[str]    				=     FunnelForTokenClassification(config=snake_case     )
          model.to(snake_case     )
          model.eval()
          __UpperCAmelCase      :					List[Any]    				=     model(snake_case				,					attention_mask=snake_case				,					token_type_ids=snake_case				,					labels=snake_case     )
          self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.seq_length, self.num_labels)     )

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



@require_torch
class       a							(						_a      ,    _a      ,    unittest.TestCase			):


     """simple docstring"""






     SCREAMING_SNAKE_CASE			:					Optional[Any]				  =  False
     SCREAMING_SNAKE_CASE			:					Tuple				  =  False
     SCREAMING_SNAKE_CASE			:					int				  =  (
         (
             FunnelModel,
             FunnelForMaskedLM,
             FunnelForPreTraining,
             FunnelForQuestionAnswering,
             FunnelForTokenClassification,
         )
         if is_torch_available()
         else ()
     )
     SCREAMING_SNAKE_CASE			:					str				  =  (
         {
             "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 					lowerCamelCase__					(							self	:						Optional[Any]				,					snake_case	:						List[str]				,					snake_case	:						List[str]				,					snake_case	:						Dict=False     )		->				Any:
          __UpperCAmelCase      :					Optional[int]    				=     super()._prepare_for_class(snake_case				,					snake_case				,					return_labels=snake_case     )

          if return_labels:
               if model_class in get_values(snake_case     ):
                    __UpperCAmelCase      :					Optional[int]    				=     torch.zeros(
                        (self.model_tester.batch_size, self.model_tester.seq_length)				,					dtype=torch.long				,					device=snake_case     )
          return inputs_dict

     def 					lowerCamelCase__					(							self	:						Union[str, Any]     )		->				str:
          __UpperCAmelCase      :					Optional[Any]    				=     FunnelModelTester(self     )
          __UpperCAmelCase      :					Optional[int]    				=     ConfigTester(self				,					config_class=snake_case     )

     def 					lowerCamelCase__					(							self	:						int     )		->				Optional[int]:
          self.config_tester.run_common_tests()

     def 					lowerCamelCase__					(							self	:						Any     )		->				Optional[int]:
          __UpperCAmelCase      :					Dict    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*snake_case     )

     def 					lowerCamelCase__					(							self	:						List[str]     )		->				int:
          __UpperCAmelCase      :					Union[str, Any]    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_pretraining(*snake_case     )

     def 					lowerCamelCase__					(							self	:						List[str]     )		->				Dict:
          __UpperCAmelCase      :					List[Any]    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_masked_lm(*snake_case     )

     def 					lowerCamelCase__					(							self	:						Optional[int]     )		->				List[str]:
          __UpperCAmelCase      :					List[str]    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_token_classification(*snake_case     )

     def 					lowerCamelCase__					(							self	:						Optional[int]     )		->				Tuple:
          __UpperCAmelCase      :					Tuple    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_question_answering(*snake_case     )






     def 					lowerCamelCase__					(							self	:						Union[str, Any]				,					snake_case	:						Dict     )		->				List[str]:
          if hasattr(snake_case				,					'''weight'''     ) and module.weight is not None:
               module.weight.data.fill_(3     )
          if hasattr(snake_case				,					'''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(snake_case				,					snake_case     ) and getattr(snake_case				,					snake_case     ) is not None:
                    __UpperCAmelCase      :					Optional[Any]    				=     getattr(snake_case				,					snake_case     )
                    weight.data.fill_(3     )



@require_torch
class       a							(						_a      ,    unittest.TestCase			):


     """simple docstring"""






     SCREAMING_SNAKE_CASE			:					Optional[Any]				  =  False
     SCREAMING_SNAKE_CASE			:					List[str]				  =  False
     SCREAMING_SNAKE_CASE			:					Tuple				  =  (
         (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
     )

     def 					lowerCamelCase__					(							self	:						Tuple     )		->				List[str]:
          __UpperCAmelCase      :					Dict    				=     FunnelModelTester(self				,					base=snake_case     )
          __UpperCAmelCase      :					str    				=     ConfigTester(self				,					config_class=snake_case     )

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

     def 					lowerCamelCase__					(							self	:						Tuple     )		->				Optional[int]:
          __UpperCAmelCase      :					Dict    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_base_model(*snake_case     )

     def 					lowerCamelCase__					(							self	:						str     )		->				Union[str, Any]:
          __UpperCAmelCase      :					int    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_sequence_classification(*snake_case     )

     def 					lowerCamelCase__					(							self	:						Optional[int]     )		->				Any:
          __UpperCAmelCase      :					List[Any]    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_multiple_choice(*snake_case     )

     def 					lowerCamelCase__					(							self	:						int     )		->				List[Any]:
          __UpperCAmelCase				,  __UpperCAmelCase      :					Optional[Any]    				=     self.model_tester.prepare_config_and_inputs_for_common()
          __UpperCAmelCase      :					str    				=     True

          for model_class in self.all_model_classes:
               if model_class.__name__ == "FunnelBaseModel":
                    continue
               __UpperCAmelCase      :					Union[str, Any]    				=     model_class(snake_case     )
               model.to(snake_case     )
               model.train()
               __UpperCAmelCase      :					Tuple    				=     self._prepare_for_class(snake_case				,					snake_case				,					return_labels=snake_case     )
               __UpperCAmelCase      :					List[str]    				=     model(**snake_case     ).loss
               loss.backward()






     def 					lowerCamelCase__					(							self	:						Union[str, Any]				,					snake_case	:						List[str]     )		->				Optional[Any]:
          if hasattr(snake_case				,					'''weight'''     ) and module.weight is not None:
               module.weight.data.fill_(3     )
          if hasattr(snake_case				,					'''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(snake_case				,					snake_case     ) and getattr(snake_case				,					snake_case     ) is not None:
                    __UpperCAmelCase      :					List[Any]    				=     getattr(snake_case				,					snake_case     )
                    weight.data.fill_(3     )



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


     """simple docstring"""






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

          __UpperCAmelCase      :					int    				=     FunnelModel.from_pretrained('''sgugger/funnel-random-tiny'''     )
          __UpperCAmelCase      :					Optional[Any]    				=     model(snake_case				,					token_type_ids=snake_case     )[0].abs()

          __UpperCAmelCase      :					int    				=     torch.tensor(2_344.8_352     )
          __UpperCAmelCase      :					int    				=     torch.tensor(0.8_052     )
          self.assertTrue(torch.allclose(output.sum()				,					snake_case				,					atol=1E-4     )     )
          self.assertTrue(torch.allclose(output.mean()				,					snake_case				,					atol=1E-4     )     )

          __UpperCAmelCase      :					Tuple    				=     torch.tensor([[1] * 7, [1] * 4 + [0] * 3] * 6 + [[0, 1, 1, 0, 0, 1, 1]]     )
          __UpperCAmelCase      :					Union[str, Any]    				=     model(snake_case				,					attention_mask=snake_case				,					token_type_ids=snake_case     )[0].abs()

          __UpperCAmelCase      :					Union[str, Any]    				=     torch.tensor(2_343.8_425     )
          __UpperCAmelCase      :					Tuple    				=     torch.tensor(0.8_049     )
          self.assertTrue(torch.allclose(output.sum()				,					snake_case				,					atol=1E-4     )     )
          self.assertTrue(torch.allclose(output.mean()				,					snake_case				,					atol=1E-4     )     )






     @slow
     def 					lowerCamelCase__					(							self	:						Tuple     )		->				Dict:
          __UpperCAmelCase      :					str    				=     FunnelTokenizer.from_pretrained('''huggingface/funnel-small'''     )
          __UpperCAmelCase      :					int    				=     FunnelModel.from_pretrained('''huggingface/funnel-small'''     )
          __UpperCAmelCase      :					Optional[int]    				=     tokenizer('''Hello! I am the Funnel Transformer model.'''				,					return_tensors='''pt'''     )
          __UpperCAmelCase      :					Tuple    				=     model(**snake_case     )[0]

          __UpperCAmelCase      :					Dict    				=     torch.tensor(235.7_246     )
          __UpperCAmelCase      :					int    				=     torch.tensor(0.0_256     )
          self.assertTrue(torch.allclose(output.sum()				,					snake_case				,					atol=1E-4     )     )
          self.assertTrue(torch.allclose(output.mean()				,					snake_case				,					atol=1E-4     )     )



'''simple docstring'''



import math
from decimal import Decimal, getcontext




def       _a      (		_lowercase   :      int = 4000000    ):





     '''simple docstring'''






     try:
          __UpperCAmelCase      :					List[str]    				=     int(_lowercase    )
     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      :					Tuple    				=     100
     __UpperCAmelCase      :					Optional[Any]    				=     (Decimal(5    ) ** Decimal(0.5    ) + 1) / Decimal(2    )

     __UpperCAmelCase      :					Tuple    				=     (math.floor(math.log(n * (phi + 2)     ,   _lowercase    ) - 1    ) // 3) * 3 + 2
     __UpperCAmelCase      :					List[Any]    				=     Decimal(round(phi ** Decimal(index + 1    )    )    ) / (phi + 2)
     __UpperCAmelCase      :					List[str]    				=     num // 2
     return int(_lowercase    )


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