


'''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 							UpperCAmelCase :


 def __init__(			self       :  Optional[Any] ,					__lowerCamelCase       :  Any ,					__lowerCamelCase       :  Optional[Any]=1_3 ,					__lowerCamelCase       :  Tuple=7 ,					__lowerCamelCase       :  Any=True ,					__lowerCamelCase       :  Tuple=True ,					__lowerCamelCase       :  List[Any]=True ,					__lowerCamelCase       :  Tuple=True ,					__lowerCamelCase       :  List[str]=9_9 ,					__lowerCamelCase       :  List[str]=[1, 1, 2] ,					__lowerCamelCase       :  List[Any]=1 ,					__lowerCamelCase       :  Any=3_2 ,					__lowerCamelCase       :  Dict=4 ,					__lowerCamelCase       :  List[str]=8 ,					__lowerCamelCase       :  Dict=3_7 ,					__lowerCamelCase       :  Optional[int]="gelu_new" ,					__lowerCamelCase       :  List[Any]=0.1 ,					__lowerCamelCase       :  int=0.1 ,					__lowerCamelCase       :  List[str]=0.0 ,					__lowerCamelCase       :  str=5_1_2 ,					__lowerCamelCase       :  Optional[int]=3 ,					__lowerCamelCase       :  Tuple=0.02 ,					__lowerCamelCase       :  Optional[Any]=3 ,					__lowerCamelCase       :  Optional[Any]=4 ,					__lowerCamelCase       :  List[Any]=None ,					__lowerCamelCase       :  List[str]=False ,					):
    UpperCAmelCase__  :int            =			parent
    UpperCAmelCase__  :Any            =			batch_size
    UpperCAmelCase__  :str            =			seq_length
    UpperCAmelCase__  :int            =			is_training
    UpperCAmelCase__  :Optional[int]            =			use_input_mask
    UpperCAmelCase__  :Tuple            =			use_token_type_ids
    UpperCAmelCase__  :Dict            =			use_labels
    UpperCAmelCase__  :Dict            =			vocab_size
    UpperCAmelCase__  :Any            =			block_sizes
    UpperCAmelCase__  :Any            =			num_decoder_layers
    UpperCAmelCase__  :Dict            =			d_model
    UpperCAmelCase__  :Dict            =			n_head
    UpperCAmelCase__  :Tuple            =			d_head
    UpperCAmelCase__  :str            =			d_inner
    UpperCAmelCase__  :Optional[Any]            =			hidden_act
    UpperCAmelCase__  :str            =			hidden_dropout
    UpperCAmelCase__  :Optional[Any]            =			attention_dropout
    UpperCAmelCase__  :Dict            =			activation_dropout
    UpperCAmelCase__  :Dict            =			max_position_embeddings
    UpperCAmelCase__  :List[str]            =			type_vocab_size
    UpperCAmelCase__  :Tuple            =			2
    UpperCAmelCase__  :Optional[Any]            =			num_labels
    UpperCAmelCase__  :List[str]            =			num_choices
    UpperCAmelCase__  :Optional[Any]            =			scope
    UpperCAmelCase__  :Optional[int]            =			initializer_std

    # Used in the tests to check the size of the first attention layer
    UpperCAmelCase__  :int            =			n_head
    # Used in the tests to check the size of the first hidden state
    UpperCAmelCase__  :str            =			self.d_model
    # Used in the tests to check the number of output hidden states/attentions
    UpperCAmelCase__  :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 					__SCREAMING_SNAKE_CASE				(			self       :  List[str]   ):
    UpperCAmelCase__  :List[Any]            =			ids_tensor([self.batch_size, self.seq_length] ,					self.vocab_size   )

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

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

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

    UpperCAmelCase__  :Optional[Any]            =			self.get_config()

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


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

    UpperCAmelCase__  :str            =			False
    UpperCAmelCase__  :Dict            =			model(__lowerCamelCase   )
    self.parent.assertEqual(result.last_hidden_state.shape ,					(self.batch_size, self.seq_length, self.d_model)   )

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


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

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

    UpperCAmelCase__  :Optional[int]            =			False
    UpperCAmelCase__  :str            =			model(__lowerCamelCase   )
    self.parent.assertEqual(result.last_hidden_state.shape ,					(self.batch_size, 2, self.d_model)   )


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


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


 def 					__SCREAMING_SNAKE_CASE				(			self       :  int ,					__lowerCamelCase       :  Dict ,					__lowerCamelCase       :  Any ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  Any ,					__lowerCamelCase       :  Any ,					__lowerCamelCase       :  Any ,					__lowerCamelCase       :  List[Any] ,					__lowerCamelCase       :  Union[str, Any] ,					):
    UpperCAmelCase__  :Union[str, Any]            =			self.num_labels
    UpperCAmelCase__  :Any            =			FunnelForSequenceClassification(__lowerCamelCase   )
    model.to(__lowerCamelCase   )
    model.eval()
    UpperCAmelCase__  :Dict            =			model(__lowerCamelCase ,					attention_mask=__lowerCamelCase ,					token_type_ids=__lowerCamelCase ,					labels=__lowerCamelCase   )
    self.parent.assertEqual(result.logits.shape ,					(self.batch_size, self.num_labels)   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Optional[int] ,					__lowerCamelCase       :  Optional[Any] ,					__lowerCamelCase       :  Any ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  Any ,					__lowerCamelCase       :  Any ,					__lowerCamelCase       :  Dict ,					__lowerCamelCase       :  Dict ,					):
    UpperCAmelCase__  :Dict            =			self.num_choices
    UpperCAmelCase__  :Optional[Any]            =			FunnelForMultipleChoice(config=__lowerCamelCase   )
    model.to(__lowerCamelCase   )
    model.eval()
    UpperCAmelCase__  :Optional[Any]            =			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__  :Dict            =			model(
        __lowerCamelCase ,					attention_mask=__lowerCamelCase ,					token_type_ids=__lowerCamelCase ,					labels=__lowerCamelCase ,					)
    self.parent.assertEqual(result.logits.shape ,					(self.batch_size, self.num_choices)   )


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


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




@require_torch
class 							UpperCAmelCase ( _snake_case	,   _snake_case	,   unittest.TestCase	):
 UpperCAmelCase				=				False
 UpperCAmelCase				=				False
 UpperCAmelCase				=				(
     (
         FunnelModel,
         FunnelForMaskedLM,
         FunnelForPreTraining,
         FunnelForQuestionAnswering,
         FunnelForTokenClassification,
     )
     if is_torch_available()
     else ()
 )
 UpperCAmelCase				=				(
     {
         "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 					__SCREAMING_SNAKE_CASE				(			self       :  int ,					__lowerCamelCase       :  Any ,					__lowerCamelCase       :  Dict ,					__lowerCamelCase       :  List[str]=False   ):
    UpperCAmelCase__  :Any            =			super()._prepare_for_class(__lowerCamelCase ,					__lowerCamelCase ,					return_labels=__lowerCamelCase   )

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


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Union[str, Any]   ):
    UpperCAmelCase__  :Dict            =			FunnelModelTester(self   )
    UpperCAmelCase__  :Union[str, Any]            =			ConfigTester(self ,					config_class=__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Union[str, Any]   ):
    self.config_tester.run_common_tests()


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Any   ):
    UpperCAmelCase__  :str            =			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Union[str, Any]   ):
    UpperCAmelCase__  :Optional[Any]            =			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_pretraining(*__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  str   ):
    UpperCAmelCase__  :str            =			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_masked_lm(*__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Dict   ):
    UpperCAmelCase__  :List[Any]            =			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_token_classification(*__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  List[Any]   ):
    UpperCAmelCase__  :Tuple            =			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_question_answering(*__lowerCamelCase   )





 def 					__SCREAMING_SNAKE_CASE				(			self       :  Optional[int] ,					__lowerCamelCase       :  Optional[int]   ):
    if hasattr(__lowerCamelCase ,					'''weight'''   ) and module.weight is not None:
       module.weight.data.fill_(3   )
    if hasattr(__lowerCamelCase ,					'''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(__lowerCamelCase ,					__lowerCamelCase   ) and getattr(__lowerCamelCase ,					__lowerCamelCase   ) is not None:
          UpperCAmelCase__  :Dict            =			getattr(__lowerCamelCase ,					__lowerCamelCase   )
          weight.data.fill_(3   )




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


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Any   ):
    UpperCAmelCase__  :List[str]            =			FunnelModelTester(self ,					base=__lowerCamelCase   )
    UpperCAmelCase__  :int            =			ConfigTester(self ,					config_class=__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Dict   ):
    self.config_tester.run_common_tests()


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Any   ):
    UpperCAmelCase__  :Optional[int]            =			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_base_model(*__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Optional[Any]   ):
    UpperCAmelCase__  :str            =			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_sequence_classification(*__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Optional[int]   ):
    UpperCAmelCase__  :Union[str, Any]            =			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_multiple_choice(*__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  int   ):
    UpperCAmelCase__      ,	UpperCAmelCase__  :List[Any]            =			self.model_tester.prepare_config_and_inputs_for_common()
    UpperCAmelCase__  :Optional[int]            =			True

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





 def 					__SCREAMING_SNAKE_CASE				(			self       :  Optional[Any] ,					__lowerCamelCase       :  Any   ):
    if hasattr(__lowerCamelCase ,					'''weight'''   ) and module.weight is not None:
       module.weight.data.fill_(3   )
    if hasattr(__lowerCamelCase ,					'''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(__lowerCamelCase ,					__lowerCamelCase   ) and getattr(__lowerCamelCase ,					__lowerCamelCase   ) is not None:
          UpperCAmelCase__  :Any            =			getattr(__lowerCamelCase ,					__lowerCamelCase   )
          weight.data.fill_(3   )




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


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Any   ):
    UpperCAmelCase__  :Any            =			1_3
    UpperCAmelCase__  :Optional[Any]            =			7
    UpperCAmelCase__  :Dict            =			torch.arange(0 ,					batch_size * sequence_length   ).long().reshape(__lowerCamelCase ,					__lowerCamelCase   )
    UpperCAmelCase__  :List[str]            =			[0, 1, 2, 3, 4, 5, 6, 4, 1, 3, 5, 0, 1]
    UpperCAmelCase__  :Optional[int]            =			torch.tensor([[2] + [0] * a + [1] * (sequence_length - a - 1) for a in lengths]   )

    UpperCAmelCase__  :Union[str, Any]            =			FunnelModel.from_pretrained('''sgugger/funnel-random-tiny'''   )
    UpperCAmelCase__  :int            =			model(__lowerCamelCase ,					token_type_ids=__lowerCamelCase   )[0].abs()

    UpperCAmelCase__  :str            =			torch.tensor(23_44.83_52   )
    UpperCAmelCase__  :str            =			torch.tensor(0.80_52   )
    self.assertTrue(torch.allclose(output.sum() ,					__lowerCamelCase ,					atol=1e-4   )   )
    self.assertTrue(torch.allclose(output.mean() ,					__lowerCamelCase ,					atol=1e-4   )   )

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

    UpperCAmelCase__  :int            =			torch.tensor(23_43.84_25   )
    UpperCAmelCase__  :Optional[int]            =			torch.tensor(0.80_49   )
    self.assertTrue(torch.allclose(output.sum() ,					__lowerCamelCase ,					atol=1e-4   )   )
    self.assertTrue(torch.allclose(output.mean() ,					__lowerCamelCase ,					atol=1e-4   )   )





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

    UpperCAmelCase__  :int            =			torch.tensor(2_35.72_46   )
    UpperCAmelCase__  :List[str]            =			torch.tensor(0.02_56   )
    self.assertTrue(torch.allclose(output.sum() ,					__lowerCamelCase ,					atol=1e-4   )   )
    self.assertTrue(torch.allclose(output.mean() ,					__lowerCamelCase ,					atol=1e-4   )   )







'''simple docstring'''





from scipy.constants import g


def 					a__    (				UpperCamelCase_	:			float,      UpperCamelCase_	:			float	):
   if mass < 0:
      # handling of negative values of mass
      raise ValueError('''The mass of a body cannot be negative'''	)
   if height < 0:
      # handling of negative values of height
      raise ValueError('''The height above the ground cannot be negative'''	)
   return mass * g * height


if __name__ == "__main__":
    from doctest import testmod

    testmod(name='''potential_energy''')



