
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				:






     """simple docstring"""







     def __init__(							self    :    Dict      ,		_A    :    List[Any]      ,		_A    :    int=13      ,		_A    :    Optional[int]=7      ,		_A    :    int=True      ,		_A    :    int=True      ,		_A    :    Union[str, Any]=True      ,		_A    :    int=True      ,		_A    :    List[Any]=99      ,		_A    :    str=[1, 1, 2]      ,		_A    :    Optional[Any]=1      ,		_A    :    Tuple=32      ,		_A    :    Dict=4      ,		_A    :    Union[str, Any]=8      ,		_A    :    Optional[Any]=37      ,		_A    :    Union[str, Any]="gelu_new"      ,		_A    :    Any=0.1      ,		_A    :    str=0.1      ,		_A    :    Dict=0.0      ,		_A    :    List[Any]=512      ,		_A    :    Optional[int]=3      ,		_A    :    Union[str, Any]=0.02      ,		_A    :    Tuple=3      ,		_A    :    List[str]=4      ,		_A    :    Any=None      ,		_A    :    int=False      ,		):







       """simple docstring"""




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

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



     def 				UpperCAmelCase__    (							self    :    Dict				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					Optional[int]			=						ids_tensor([self.batch_size, self.seq_length]      ,		self.vocab_size				)

       __SCREAMING_SNAKE_CASE     :					Tuple			=						None
       if self.use_input_mask:
         __SCREAMING_SNAKE_CASE     :					List[Any]			=						ids_tensor([self.batch_size, self.seq_length]      ,		vocab_size=2				)

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

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

       __SCREAMING_SNAKE_CASE     :					Any			=						self.get_config()

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



     def 				UpperCAmelCase__    (							self    :    Any				):







       """simple docstring"""




       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 				UpperCAmelCase__    (							self    :    Dict      ,		_A    :    str      ,		_A    :    List[Any]      ,		_A    :    Any      ,		_A    :    Optional[int]      ,		_A    :    int      ,		_A    :    Dict      ,		_A    :    Union[str, Any]      ,		_A    :    int      ,		):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					List[Any]			=						FunnelModel(config=_A				)
       model.to(_A				)
       model.eval()
       __SCREAMING_SNAKE_CASE     :					Any			=						model(_A      ,		attention_mask=_A      ,		token_type_ids=_A				)
       __SCREAMING_SNAKE_CASE     :					List[Any]			=						model(_A      ,		token_type_ids=_A				)
       __SCREAMING_SNAKE_CASE     :					Optional[Any]			=						model(_A				)
       self.parent.assertEqual(result.last_hidden_state.shape      ,		(self.batch_size, self.seq_length, self.d_model)				)

       __SCREAMING_SNAKE_CASE     :					Tuple			=						False
       __SCREAMING_SNAKE_CASE     :					Union[str, Any]			=						model(_A				)
       self.parent.assertEqual(result.last_hidden_state.shape      ,		(self.batch_size, self.seq_length, self.d_model)				)

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



     def 				UpperCAmelCase__    (							self    :    Union[str, Any]      ,		_A    :    int      ,		_A    :    str      ,		_A    :    Tuple      ,		_A    :    str      ,		_A    :    List[Any]      ,		_A    :    int      ,		_A    :    str      ,		_A    :    Union[str, Any]      ,		):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					List[str]			=						FunnelBaseModel(config=_A				)
       model.to(_A				)
       model.eval()
       __SCREAMING_SNAKE_CASE     :					Union[str, Any]			=						model(_A      ,		attention_mask=_A      ,		token_type_ids=_A				)
       __SCREAMING_SNAKE_CASE     :					int			=						model(_A      ,		token_type_ids=_A				)
       __SCREAMING_SNAKE_CASE     :					List[Any]			=						model(_A				)
       self.parent.assertEqual(result.last_hidden_state.shape      ,		(self.batch_size, 2, self.d_model)				)

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

       __SCREAMING_SNAKE_CASE     :					Union[str, Any]			=						False
       __SCREAMING_SNAKE_CASE     :					Union[str, Any]			=						model(_A				)
       self.parent.assertEqual(result.last_hidden_state.shape      ,		(self.batch_size, 2, self.d_model)				)



     def 				UpperCAmelCase__    (							self    :    Optional[int]      ,		_A    :    Any      ,		_A    :    Union[str, Any]      ,		_A    :    Dict      ,		_A    :    str      ,		_A    :    int      ,		_A    :    Any      ,		_A    :    List[str]      ,		_A    :    int      ,		):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					Tuple			=						self.num_labels
       __SCREAMING_SNAKE_CASE     :					Dict			=						FunnelForPreTraining(config=_A				)
       model.to(_A				)
       model.eval()
       __SCREAMING_SNAKE_CASE     :					Dict			=						model(_A      ,		attention_mask=_A      ,		token_type_ids=_A      ,		labels=_A				)
       self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.seq_length)				)



     def 				UpperCAmelCase__    (							self    :    List[str]      ,		_A    :    Any      ,		_A    :    Tuple      ,		_A    :    List[Any]      ,		_A    :    Optional[Any]      ,		_A    :    Tuple      ,		_A    :    List[str]      ,		_A    :    Optional[int]      ,		_A    :    Optional[Any]      ,		):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					int			=						FunnelForMaskedLM(config=_A				)
       model.to(_A				)
       model.eval()
       __SCREAMING_SNAKE_CASE     :					Tuple			=						model(_A      ,		attention_mask=_A      ,		token_type_ids=_A      ,		labels=_A				)
       self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.seq_length, self.vocab_size)				)



     def 				UpperCAmelCase__    (							self    :    Optional[Any]      ,		_A    :    Optional[int]      ,		_A    :    Optional[int]      ,		_A    :    Union[str, Any]      ,		_A    :    int      ,		_A    :    Dict      ,		_A    :    Optional[Any]      ,		_A    :    int      ,		_A    :    Any      ,		):







       """simple docstring"""




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



     def 				UpperCAmelCase__    (							self    :    Optional[Any]      ,		_A    :    Optional[Any]      ,		_A    :    List[Any]      ,		_A    :    Any      ,		_A    :    Union[str, Any]      ,		_A    :    List[Any]      ,		_A    :    int      ,		_A    :    List[str]      ,		_A    :    Any      ,		):







       """simple docstring"""




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



     def 				UpperCAmelCase__    (							self    :    List[Any]      ,		_A    :    Dict      ,		_A    :    Dict      ,		_A    :    List[Any]      ,		_A    :    Any      ,		_A    :    Optional[Any]      ,		_A    :    List[Any]      ,		_A    :    Dict      ,		_A    :    List[Any]      ,		):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					Optional[int]			=						self.num_labels
       __SCREAMING_SNAKE_CASE     :					Optional[int]			=						FunnelForTokenClassification(config=_A				)
       model.to(_A				)
       model.eval()
       __SCREAMING_SNAKE_CASE     :					Tuple			=						model(_A      ,		attention_mask=_A      ,		token_type_ids=_A      ,		labels=_A				)
       self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.seq_length, self.num_labels)				)



     def 				UpperCAmelCase__    (							self    :    Optional[int]      ,		_A    :    int      ,		_A    :    List[Any]      ,		_A    :    Optional[int]      ,		_A    :    List[str]      ,		_A    :    Optional[Any]      ,		_A    :    List[Any]      ,		_A    :    List[str]      ,		_A    :    Optional[Any]      ,		):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					Any			=						FunnelForQuestionAnswering(config=_A				)
       model.to(_A				)
       model.eval()
       __SCREAMING_SNAKE_CASE     :					Optional[Any]			=						model(
           _A      ,		attention_mask=_A      ,		token_type_ids=_A      ,		start_positions=_A      ,		end_positions=_A      ,		)
       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 				UpperCAmelCase__    (							self    :    Dict				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					Union[str, Any]			=						self.prepare_config_and_inputs()
       (
           __SCREAMING_SNAKE_CASE						
       )     :					str			=						config_and_inputs
       __SCREAMING_SNAKE_CASE     :					Union[str, Any]			=						{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
       return config, inputs_dict






@require_torch
class   __UpperCamelCase				(    lowerCAmelCase__				,		lowerCAmelCase__				,		unittest.TestCase   ):






     """simple docstring"""







     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 				UpperCAmelCase__    (							self    :    Dict      ,		_A    :    int      ,		_A    :    str      ,		_A    :    Any=False				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					int			=						super()._prepare_for_class(_A      ,		_A      ,		return_labels=_A				)

       if return_labels:
         if model_class in get_values(_A				):
           __SCREAMING_SNAKE_CASE     :					Union[str, Any]			=						torch.zeros(
               (self.model_tester.batch_size, self.model_tester.seq_length)      ,		dtype=torch.long      ,		device=_A				)
       return inputs_dict



     def 				UpperCAmelCase__    (							self    :    int				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					int			=						FunnelModelTester(self				)
       __SCREAMING_SNAKE_CASE     :					Optional[int]			=						ConfigTester(self      ,		config_class=_A				)



     def 				UpperCAmelCase__    (							self    :    Optional[int]				):







       """simple docstring"""




       self.config_tester.run_common_tests()



     def 				UpperCAmelCase__    (							self    :    int				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					Tuple			=						self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*_A				)



     def 				UpperCAmelCase__    (							self    :    List[str]				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					List[Any]			=						self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_pretraining(*_A				)



     def 				UpperCAmelCase__    (							self    :    Any				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					int			=						self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_lm(*_A				)



     def 				UpperCAmelCase__    (							self    :    Union[str, Any]				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					str			=						self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_token_classification(*_A				)



     def 				UpperCAmelCase__    (							self    :    str				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					List[Any]			=						self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_question_answering(*_A				)




     def 				UpperCAmelCase__    (							self    :    Optional[Any]      ,		_A    :    Dict				):







       """simple docstring"""




       if hasattr(_A      ,		'''weight'''				) and module.weight is not None:
         module.weight.data.fill_(3				)
       if hasattr(_A      ,		'''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(_A      ,		_A				) and getattr(_A      ,		_A				) is not None:
           __SCREAMING_SNAKE_CASE     :					Any			=						getattr(_A      ,		_A				)
           weight.data.fill_(3				)






@require_torch
class   __UpperCamelCase				(    lowerCAmelCase__				,		unittest.TestCase   ):






     """simple docstring"""







     lowerCAmelCase_     =	False
     lowerCAmelCase_     =	False
     lowerCAmelCase_     =	(
         (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
     )



     def 				UpperCAmelCase__    (							self    :    int				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					Union[str, Any]			=						FunnelModelTester(self      ,		base=_A				)
       __SCREAMING_SNAKE_CASE     :					Any			=						ConfigTester(self      ,		config_class=_A				)



     def 				UpperCAmelCase__    (							self    :    int				):







       """simple docstring"""




       self.config_tester.run_common_tests()



     def 				UpperCAmelCase__    (							self    :    str				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					int			=						self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_base_model(*_A				)



     def 				UpperCAmelCase__    (							self    :    Union[str, Any]				):







       """simple docstring"""




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



     def 				UpperCAmelCase__    (							self    :    Dict				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					str			=						self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_multiple_choice(*_A				)



     def 				UpperCAmelCase__    (							self    :    Tuple				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					Union[str, Any]			=						self.model_tester.prepare_config_and_inputs_for_common()
       __SCREAMING_SNAKE_CASE     :					Optional[Any]			=						True

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




     def 				UpperCAmelCase__    (							self    :    Dict      ,		_A    :    str				):







       """simple docstring"""




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






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






     """simple docstring"""







     def 				UpperCAmelCase__    (							self    :    Optional[Any]				):







       """simple docstring"""




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

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

       __SCREAMING_SNAKE_CASE     :					Optional[Any]			=						torch.tensor(2344.8352				)
       __SCREAMING_SNAKE_CASE     :					Dict			=						torch.tensor(0.80_52				)
       self.assertTrue(torch.allclose(output.sum()      ,		_A      ,		atol=1e-4				)				)
       self.assertTrue(torch.allclose(output.mean()      ,		_A      ,		atol=1e-4				)				)

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

       __SCREAMING_SNAKE_CASE     :					Optional[int]			=						torch.tensor(2343.8425				)
       __SCREAMING_SNAKE_CASE     :					List[Any]			=						torch.tensor(0.80_49				)
       self.assertTrue(torch.allclose(output.sum()      ,		_A      ,		atol=1e-4				)				)
       self.assertTrue(torch.allclose(output.mean()      ,		_A      ,		atol=1e-4				)				)




     @slow
     def 				UpperCAmelCase__    (							self    :    Union[str, Any]				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					Any			=						FunnelTokenizer.from_pretrained('''huggingface/funnel-small'''				)
       __SCREAMING_SNAKE_CASE     :					str			=						FunnelModel.from_pretrained('''huggingface/funnel-small'''				)
       __SCREAMING_SNAKE_CASE     :					int			=						tokenizer('''Hello! I am the Funnel Transformer model.'''      ,		return_tensors='''pt'''				)
       __SCREAMING_SNAKE_CASE     :					List[str]			=						model(**_A				)[0]

       __SCREAMING_SNAKE_CASE     :					Optional[int]			=						torch.tensor(235.7246				)
       __SCREAMING_SNAKE_CASE     :					Union[str, Any]			=						torch.tensor(0.02_56				)
       self.assertTrue(torch.allclose(output.sum()      ,		_A      ,		atol=1e-4				)				)
       self.assertTrue(torch.allclose(output.mean()      ,		_A      ,		atol=1e-4				)				)


import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


lowercase_											=	"""
Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.

In March 2021, Hugging Face raised $40 million in a Series B funding round.[3]

On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]
"""





class   __UpperCamelCase				(    unittest.TestCase				,		lowerCAmelCase__   ):






     """simple docstring"""







     def 				UpperCAmelCase__    (							self    :    Optional[Any]				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					int			=						load_tool('''summarization'''				)
       self.tool.setup()
       __SCREAMING_SNAKE_CASE     :					Any			=						load_tool('''summarization'''      ,		remote=_A				)



     def 				UpperCAmelCase__    (							self    :    Tuple				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					Dict			=						self.tool(_A				)
       self.assertEqual(
           _A      ,		'''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''      ,		)



     def 				UpperCAmelCase__    (							self    :    List[str]				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					Optional[Any]			=						self.remote_tool(_A				)
       self.assertEqual(
           _A      ,		'''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''      ,		)



     def 				UpperCAmelCase__    (							self    :    List[str]				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					Dict			=						self.tool(text=_A				)
       self.assertEqual(
           _A      ,		'''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''      ,		)




     def 				UpperCAmelCase__    (							self    :    Optional[int]				):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE     :					str			=						self.remote_tool(text=_A				)
       self.assertEqual(
           _A      ,		'''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''      ,		)
