

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




 def __init__(			self  ,  _UpperCAmelCase  ,  _UpperCAmelCase=13  ,  _UpperCAmelCase=7  ,  _UpperCAmelCase=True  ,  _UpperCAmelCase=True  ,  _UpperCAmelCase=True  ,  _UpperCAmelCase=True  ,  _UpperCAmelCase=99  ,  _UpperCAmelCase=[1, 1, 2]  ,  _UpperCAmelCase=1  ,  _UpperCAmelCase=32  ,  _UpperCAmelCase=4  ,  _UpperCAmelCase=8  ,  _UpperCAmelCase=37  ,  _UpperCAmelCase="gelu_new"  ,  _UpperCAmelCase=0.1  ,  _UpperCAmelCase=0.1  ,  _UpperCAmelCase=0.0  ,  _UpperCAmelCase=512  ,  _UpperCAmelCase=3  ,  _UpperCAmelCase=0.0_2  ,  _UpperCAmelCase=3  ,  _UpperCAmelCase=4  ,  _UpperCAmelCase=None  ,  _UpperCAmelCase=False  ,  ):
   __UpperCAmelCase	:  List[str]		=     parent
   __UpperCAmelCase	:  Any		=     batch_size
   __UpperCAmelCase	:  Union[str, Any]		=     seq_length
   __UpperCAmelCase	:  int		=     is_training
   __UpperCAmelCase	:  int		=     use_input_mask
   __UpperCAmelCase	:  Any		=     use_token_type_ids
   __UpperCAmelCase	:  Optional[int]		=     use_labels
   __UpperCAmelCase	:  Union[str, Any]		=     vocab_size
   __UpperCAmelCase	:  List[Any]		=     block_sizes
   __UpperCAmelCase	:  List[str]		=     num_decoder_layers
   __UpperCAmelCase	:  Any		=     d_model
   __UpperCAmelCase	:  Tuple		=     n_head
   __UpperCAmelCase	:  Tuple		=     d_head
   __UpperCAmelCase	:  Optional[int]		=     d_inner
   __UpperCAmelCase	:  Optional[int]		=     hidden_act
   __UpperCAmelCase	:  int		=     hidden_dropout
   __UpperCAmelCase	:  Dict		=     attention_dropout
   __UpperCAmelCase	:  Optional[Any]		=     activation_dropout
   __UpperCAmelCase	:  Any		=     max_position_embeddings
   __UpperCAmelCase	:  str		=     type_vocab_size
   __UpperCAmelCase	:  Optional[Any]		=     2
   __UpperCAmelCase	:  str		=     num_labels
   __UpperCAmelCase	:  Dict		=     num_choices
   __UpperCAmelCase	:  Union[str, Any]		=     scope
   __UpperCAmelCase	:  List[str]		=     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	:  Optional[Any]		=     self.d_model
   # Used in the tests to check the number of output hidden states/attentions
   __UpperCAmelCase	:  List[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	:  List[Any]		=     self.num_hidden_layers + 2




 def     a       (			self							):
   __UpperCAmelCase	:  Tuple		=     ids_tensor([self.batch_size, self.seq_length]  ,  self.vocab_size							)

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

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

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

   __UpperCAmelCase	:  Optional[int]		=     self.get_config()

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




 def     a       (			self							):
   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  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  ):
   __UpperCAmelCase	:  Optional[int]		=     FunnelModel(config=_UpperCAmelCase							)
   model.to(_UpperCAmelCase							)
   model.eval()
   __UpperCAmelCase	:  Optional[int]		=     model(_UpperCAmelCase  ,  attention_mask=_UpperCAmelCase  ,  token_type_ids=_UpperCAmelCase							)
   __UpperCAmelCase	:  int		=     model(_UpperCAmelCase  ,  token_type_ids=_UpperCAmelCase							)
   __UpperCAmelCase	:  int		=     model(_UpperCAmelCase							)
   self.parent.assertEqual(result.last_hidden_state.shape  ,  (self.batch_size, self.seq_length, self.d_model)							)

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

   __UpperCAmelCase	:  Any		=     False
   __UpperCAmelCase	:  List[str]		=     model(_UpperCAmelCase							)
   self.parent.assertEqual(result.last_hidden_state.shape  ,  (self.batch_size, self.seq_length, self.d_model)							)




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

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

   __UpperCAmelCase	:  Any		=     False
   __UpperCAmelCase	:  Tuple		=     model(_UpperCAmelCase							)
   self.parent.assertEqual(result.last_hidden_state.shape  ,  (self.batch_size, 2, self.d_model)							)




 def     a       (			self  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  ):
   __UpperCAmelCase	:  Any		=     self.num_labels
   __UpperCAmelCase	:  Optional[Any]		=     FunnelForPreTraining(config=_UpperCAmelCase							)
   model.to(_UpperCAmelCase							)
   model.eval()
   __UpperCAmelCase	:  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)							)




 def     a       (			self  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  ):
   __UpperCAmelCase	:  Any		=     FunnelForMaskedLM(config=_UpperCAmelCase							)
   model.to(_UpperCAmelCase							)
   model.eval()
   __UpperCAmelCase	:  Union[str, 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  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  ):
   __UpperCAmelCase	:  List[str]		=     self.num_labels
   __UpperCAmelCase	:  Any		=     FunnelForSequenceClassification(_UpperCAmelCase							)
   model.to(_UpperCAmelCase							)
   model.eval()
   __UpperCAmelCase	:  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  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  ):
   __UpperCAmelCase	:  Optional[Any]		=     self.num_choices
   __UpperCAmelCase	:  Optional[Any]		=     FunnelForMultipleChoice(config=_UpperCAmelCase							)
   model.to(_UpperCAmelCase							)
   model.eval()
   __UpperCAmelCase	:  List[str]		=     input_ids.unsqueeze(1							).expand(-1  ,  self.num_choices  ,  -1							).contiguous()
   __UpperCAmelCase	:  Tuple		=     token_type_ids.unsqueeze(1							).expand(-1  ,  self.num_choices  ,  -1							).contiguous()
   __UpperCAmelCase	:  str		=     input_mask.unsqueeze(1							).expand(-1  ,  self.num_choices  ,  -1							).contiguous()
   __UpperCAmelCase	:  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  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  ):
   __UpperCAmelCase	:  str		=     self.num_labels
   __UpperCAmelCase	:  Dict		=     FunnelForTokenClassification(config=_UpperCAmelCase							)
   model.to(_UpperCAmelCase							)
   model.eval()
   __UpperCAmelCase	:  Tuple		=     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  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  ):
   __UpperCAmelCase	:  Optional[int]		=     FunnelForQuestionAnswering(config=_UpperCAmelCase							)
   model.to(_UpperCAmelCase							)
   model.eval()
   __UpperCAmelCase	:  Union[str, Any]		=     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							):
   __UpperCAmelCase	:  Dict		=     self.prepare_config_and_inputs()
   (
       (
       __UpperCAmelCase
   ),			(
       __UpperCAmelCase
   ),			(
       __UpperCAmelCase
   ),			(
       __UpperCAmelCase
   ),			(
       __UpperCAmelCase
   ),			(
       __UpperCAmelCase
   ),			(
       __UpperCAmelCase
   ),			(
       __UpperCAmelCase
   ),			
   )	:  str		=     config_and_inputs
   __UpperCAmelCase	:  str		=     {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
   return config, inputs_dict



@require_torch
class      lowerCamelCase_ (			_lowerCAmelCase	,				_lowerCAmelCase	,				unittest.TestCase):
 _lowerCAmelCase									=	False
 _lowerCAmelCase									=	False
 _lowerCAmelCase									=	(
     (
         FunnelModel,
         FunnelForMaskedLM,
         FunnelForPreTraining,
         FunnelForQuestionAnswering,
         FunnelForTokenClassification,
     )
     if is_torch_available()
     else ()
 )
 _lowerCAmelCase									=	(
     {
         '''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  ,  _UpperCAmelCase  ,  _UpperCAmelCase  ,  _UpperCAmelCase=False							):
   __UpperCAmelCase	:  str		=     super()._prepare_for_class(_UpperCAmelCase  ,  _UpperCAmelCase  ,  return_labels=_UpperCAmelCase							)

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




 def     a       (			self							):
   __UpperCAmelCase	:  List[Any]		=     FunnelModelTester(self							)
   __UpperCAmelCase	:  int		=     ConfigTester(self  ,  config_class=_UpperCAmelCase							)




 def     a       (			self							):
   self.config_tester.run_common_tests()




 def     a       (			self							):
   __UpperCAmelCase	:  List[str]		=     self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_model(*_UpperCAmelCase							)




 def     a       (			self							):
   __UpperCAmelCase	:  Tuple		=     self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_pretraining(*_UpperCAmelCase							)




 def     a       (			self							):
   __UpperCAmelCase	:  Optional[Any]		=     self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_masked_lm(*_UpperCAmelCase							)




 def     a       (			self							):
   __UpperCAmelCase	:  Optional[Any]		=     self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_token_classification(*_UpperCAmelCase							)




 def     a       (			self							):
   __UpperCAmelCase	:  str		=     self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_question_answering(*_UpperCAmelCase							)




 def     a       (			self  ,  _UpperCAmelCase							):
   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:
       __UpperCAmelCase	:  List[Any]		=     getattr(_UpperCAmelCase  ,  _UpperCAmelCase							)
       weight.data.fill_(3							)



@require_torch
class      lowerCamelCase_ (			_lowerCAmelCase	,				unittest.TestCase):
 _lowerCAmelCase									=	False
 _lowerCAmelCase									=	False
 _lowerCAmelCase									=	(
     (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
 )




 def     a       (			self							):
   __UpperCAmelCase	:  int		=     FunnelModelTester(self  ,  base=_UpperCAmelCase							)
   __UpperCAmelCase	:  str		=     ConfigTester(self  ,  config_class=_UpperCAmelCase							)




 def     a       (			self							):
   self.config_tester.run_common_tests()




 def     a       (			self							):
   __UpperCAmelCase	:  Dict		=     self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_base_model(*_UpperCAmelCase							)




 def     a       (			self							):
   __UpperCAmelCase	:  Union[str, Any]		=     self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_sequence_classification(*_UpperCAmelCase							)




 def     a       (			self							):
   __UpperCAmelCase	:  Dict		=     self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_multiple_choice(*_UpperCAmelCase							)




 def     a       (			self							):
   __UpperCAmelCase,			__UpperCAmelCase	:  Dict		=     self.model_tester.prepare_config_and_inputs_for_common()
   __UpperCAmelCase	:  Optional[Any]		=     True

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




 def     a       (			self  ,  _UpperCAmelCase							):
   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:
       __UpperCAmelCase	:  str		=     getattr(_UpperCAmelCase  ,  _UpperCAmelCase							)
       weight.data.fill_(3							)



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




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

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

   __UpperCAmelCase	:  int		=     torch.tensor(2_3_4_4.8_3_5_2							)
   __UpperCAmelCase	:  Any		=     torch.tensor(0.8_0_5_2							)
   self.assertTrue(torch.allclose(output.sum()  ,  _UpperCAmelCase  ,  atol=1E-4							)							)
   self.assertTrue(torch.allclose(output.mean()  ,  _UpperCAmelCase  ,  atol=1E-4							)							)

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

   __UpperCAmelCase	:  Any		=     torch.tensor(2_3_4_3.8_4_2_5							)
   __UpperCAmelCase	:  List[Any]		=     torch.tensor(0.8_0_4_9							)
   self.assertTrue(torch.allclose(output.sum()  ,  _UpperCAmelCase  ,  atol=1E-4							)							)
   self.assertTrue(torch.allclose(output.mean()  ,  _UpperCAmelCase  ,  atol=1E-4							)							)




 @slow
 def     a       (			self							):
   __UpperCAmelCase	:  List[str]		=     FunnelTokenizer.from_pretrained('huggingface/funnel-small'							)
   __UpperCAmelCase	:  Any		=     FunnelModel.from_pretrained('huggingface/funnel-small'							)
   __UpperCAmelCase	:  List[Any]		=     tokenizer('Hello! I am the Funnel Transformer model.'  ,  return_tensors='pt'							)
   __UpperCAmelCase	:  List[str]		=     model(**_UpperCAmelCase							)[0]

   __UpperCAmelCase	:  Optional[int]		=     torch.tensor(2_3_5.7_2_4_6							)
   __UpperCAmelCase	:  List[str]		=     torch.tensor(0.0_2_5_6							)
   self.assertTrue(torch.allclose(output.sum()  ,  _UpperCAmelCase  ,  atol=1E-4							)							)
   self.assertTrue(torch.allclose(output.mean()  ,  _UpperCAmelCase  ,  atol=1E-4							)							)









'''simple docstring'''







from __future__ import annotations

# Define the Gravitational Constant G and the function
a__    :   Optional[int]								=			6.67_43E-11  # unit of G : m^3 * kg^-1 * s^-2







def _UpperCamelCase			(	__A ,     __A ,     __A ,     __A       )				->						dict[str, float]:


      '''simple docstring'''



      UpperCamelCase__      =							mass_a * mass_a

      if (force, mass_a, mass_a, distance).count(0       ) != 1:
            raise ValueError("One and only one argument must be 0"       )
      if force < 0:
            raise ValueError("Gravitational force can not be negative"       )
      if distance < 0:
            raise ValueError("Distance can not be negative"       )
      if mass_a < 0 or mass_a < 0:
            raise ValueError("Mass can not be negative"       )
      if force == 0:
            UpperCamelCase__      =							GRAVITATIONAL_CONSTANT * product_of_mass / (distance**2)
            return {"force": force}
      elif mass_a == 0:
            UpperCamelCase__      =							(force) * (distance**2) / (GRAVITATIONAL_CONSTANT * mass_a)
            return {"mass_1": mass_a}
      elif mass_a == 0:
            UpperCamelCase__      =							(force) * (distance**2) / (GRAVITATIONAL_CONSTANT * mass_a)
            return {"mass_2": mass_a}
      elif distance == 0:
            UpperCamelCase__      =							(GRAVITATIONAL_CONSTANT * product_of_mass / (force)) ** 0.5
            return {"distance": distance}
      raise ValueError("One and only one argument must be 0"       )


# Run doctest
if __name__ == "__main__":
  import doctest

  doctest.testmod()





