code: 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 :					int      ,_lowerCAmelCase :					Optional[int]      ,_lowerCAmelCase :					Optional[Any]=13      ,_lowerCAmelCase :					Dict=7      ,_lowerCAmelCase :					List[Any]=True      ,_lowerCAmelCase :					Optional[Any]=True      ,_lowerCAmelCase :					Dict=True      ,_lowerCAmelCase :					Tuple=True      ,_lowerCAmelCase :					List[str]=99      ,_lowerCAmelCase :					Optional[Any]=[1, 1, 2]      ,_lowerCAmelCase :					Tuple=1      ,_lowerCAmelCase :					Optional[int]=32      ,_lowerCAmelCase :					List[str]=4      ,_lowerCAmelCase :					Tuple=8      ,_lowerCAmelCase :					List[Any]=37      ,_lowerCAmelCase :					List[str]="gelu_new"      ,_lowerCAmelCase :					int=0.1      ,_lowerCAmelCase :					str=0.1      ,_lowerCAmelCase :					List[str]=0.0      ,_lowerCAmelCase :					int=512      ,_lowerCAmelCase :					Any=3      ,_lowerCAmelCase :					Union[str, Any]=0.0_2      ,_lowerCAmelCase :					Optional[int]=3      ,_lowerCAmelCase :					List[Any]=4      ,_lowerCAmelCase :					List[Any]=None      ,_lowerCAmelCase :					List[str]=False      ,):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     parent
         __snake_case		       =     batch_size
         __snake_case		       =     seq_length
         __snake_case		       =     is_training
         __snake_case		       =     use_input_mask
         __snake_case		       =     use_token_type_ids
         __snake_case		       =     use_labels
         __snake_case		       =     vocab_size
         __snake_case		       =     block_sizes
         __snake_case		       =     num_decoder_layers
         __snake_case		       =     d_model
         __snake_case		       =     n_head
         __snake_case		       =     d_head
         __snake_case		       =     d_inner
         __snake_case		       =     hidden_act
         __snake_case		       =     hidden_dropout
         __snake_case		       =     attention_dropout
         __snake_case		       =     activation_dropout
         __snake_case		       =     max_position_embeddings
         __snake_case		       =     type_vocab_size
         __snake_case		       =     2
         __snake_case		       =     num_labels
         __snake_case		       =     num_choices
         __snake_case		       =     scope
         __snake_case		       =     initializer_std
  
         # Used in the tests to check the size of the first attention layer
         __snake_case		       =     n_head
         # Used in the tests to check the size of the first hidden state
         __snake_case		       =     self.d_model
         # Used in the tests to check the number of output hidden states/attentions
         __snake_case		       =     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:
           __snake_case		       =     self.num_hidden_layers + 2
  
  
  
  
       def 							UpperCamelCase_						( self :					str						):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     ids_tensor([self.batch_size, self.seq_length]      ,self.vocab_size						)
  
         __snake_case		       =     None
         if self.use_input_mask:
           __snake_case		       =     ids_tensor([self.batch_size, self.seq_length]      ,vocab_size=2						)
  
         __snake_case		       =     None
         if self.use_token_type_ids:
           __snake_case		       =     ids_tensor([self.batch_size, self.seq_length]      ,self.type_vocab_size						)
  
         __snake_case		       =     None
         __snake_case		       =     None
         __snake_case		       =     None
         if self.use_labels:
           __snake_case		       =     ids_tensor([self.batch_size]      ,self.type_sequence_label_size						)
           __snake_case		       =     ids_tensor([self.batch_size, self.seq_length]      ,self.num_labels						)
           __snake_case		       =     ids_tensor([self.batch_size]      ,self.num_choices						)
           __snake_case		       =     ids_tensor([self.batch_size, self.seq_length]      ,1						)
  
         __snake_case		       =     self.get_config()
  
         return (
             config,
             input_ids,
             token_type_ids,
             input_mask,
             sequence_labels,
             token_labels,
             choice_labels,
             fake_token_labels,
         )
  
  
  
  
       def 							UpperCamelCase_						( self :					List[str]						):
  
  
         """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 :					str      ,_lowerCAmelCase :					str      ,_lowerCAmelCase :					Tuple      ,_lowerCAmelCase :					int      ,_lowerCAmelCase :					Tuple      ,_lowerCAmelCase :					int      ,_lowerCAmelCase :					Optional[int]      ,_lowerCAmelCase :					Union[str, Any]      ,_lowerCAmelCase :					Tuple      ,):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     FunnelModel(config=_lowerCAmelCase						)
         model.to(_lowerCAmelCase						)
         model.eval()
         __snake_case		       =     model(_lowerCAmelCase      ,attention_mask=_lowerCAmelCase      ,token_type_ids=_lowerCAmelCase						)
         __snake_case		       =     model(_lowerCAmelCase      ,token_type_ids=_lowerCAmelCase						)
         __snake_case		       =     model(_lowerCAmelCase						)
         self.parent.assertEqual(result.last_hidden_state.shape      ,(self.batch_size, self.seq_length, self.d_model)						)
  
         __snake_case		       =     False
         __snake_case		       =     model(_lowerCAmelCase						)
         self.parent.assertEqual(result.last_hidden_state.shape      ,(self.batch_size, self.seq_length, self.d_model)						)
  
         __snake_case		       =     False
         __snake_case		       =     model(_lowerCAmelCase						)
         self.parent.assertEqual(result.last_hidden_state.shape      ,(self.batch_size, self.seq_length, self.d_model)						)
  
  
  
  
       def 							UpperCamelCase_						( self :					List[str]      ,_lowerCAmelCase :					str      ,_lowerCAmelCase :					Optional[int]      ,_lowerCAmelCase :					List[str]      ,_lowerCAmelCase :					Union[str, Any]      ,_lowerCAmelCase :					List[str]      ,_lowerCAmelCase :					Any      ,_lowerCAmelCase :					int      ,_lowerCAmelCase :					List[Any]      ,):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     FunnelBaseModel(config=_lowerCAmelCase						)
         model.to(_lowerCAmelCase						)
         model.eval()
         __snake_case		       =     model(_lowerCAmelCase      ,attention_mask=_lowerCAmelCase      ,token_type_ids=_lowerCAmelCase						)
         __snake_case		       =     model(_lowerCAmelCase      ,token_type_ids=_lowerCAmelCase						)
         __snake_case		       =     model(_lowerCAmelCase						)
         self.parent.assertEqual(result.last_hidden_state.shape      ,(self.batch_size, 2, self.d_model)						)
  
         __snake_case		       =     False
         __snake_case		       =     model(_lowerCAmelCase						)
         self.parent.assertEqual(result.last_hidden_state.shape      ,(self.batch_size, 3, self.d_model)						)
  
         __snake_case		       =     False
         __snake_case		       =     model(_lowerCAmelCase						)
         self.parent.assertEqual(result.last_hidden_state.shape      ,(self.batch_size, 2, self.d_model)						)
  
  
  
  
       def 							UpperCamelCase_						( self :					Dict      ,_lowerCAmelCase :					int      ,_lowerCAmelCase :					Any      ,_lowerCAmelCase :					Union[str, Any]      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					Tuple      ,_lowerCAmelCase :					Any      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					Dict      ,):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     self.num_labels
         __snake_case		       =     FunnelForPreTraining(config=_lowerCAmelCase						)
         model.to(_lowerCAmelCase						)
         model.eval()
         __snake_case		       =     model(_lowerCAmelCase      ,attention_mask=_lowerCAmelCase      ,token_type_ids=_lowerCAmelCase      ,labels=_lowerCAmelCase						)
         self.parent.assertEqual(result.logits.shape      ,(self.batch_size, self.seq_length)						)
  
  
  
  
       def 							UpperCamelCase_						( self :					Any      ,_lowerCAmelCase :					Any      ,_lowerCAmelCase :					int      ,_lowerCAmelCase :					Tuple      ,_lowerCAmelCase :					str      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					Any      ,_lowerCAmelCase :					Dict      ,_lowerCAmelCase :					Tuple      ,):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     FunnelForMaskedLM(config=_lowerCAmelCase						)
         model.to(_lowerCAmelCase						)
         model.eval()
         __snake_case		       =     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 							UpperCamelCase_						( self :					Any      ,_lowerCAmelCase :					str      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					Optional[Any]      ,_lowerCAmelCase :					Tuple      ,_lowerCAmelCase :					Optional[Any]      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					Tuple      ,_lowerCAmelCase :					List[Any]      ,):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     self.num_labels
         __snake_case		       =     FunnelForSequenceClassification(_lowerCAmelCase						)
         model.to(_lowerCAmelCase						)
         model.eval()
         __snake_case		       =     model(_lowerCAmelCase      ,attention_mask=_lowerCAmelCase      ,token_type_ids=_lowerCAmelCase      ,labels=_lowerCAmelCase						)
         self.parent.assertEqual(result.logits.shape      ,(self.batch_size, self.num_labels)						)
  
  
  
  
       def 							UpperCamelCase_						( self :					str      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					Tuple      ,_lowerCAmelCase :					Union[str, Any]      ,_lowerCAmelCase :					List[str]      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					str      ,_lowerCAmelCase :					Union[str, Any]      ,_lowerCAmelCase :					Optional[int]      ,):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     self.num_choices
         __snake_case		       =     FunnelForMultipleChoice(config=_lowerCAmelCase						)
         model.to(_lowerCAmelCase						)
         model.eval()
         __snake_case		       =     input_ids.unsqueeze(1						).expand(-1      ,self.num_choices      ,-1						).contiguous()
         __snake_case		       =     token_type_ids.unsqueeze(1						).expand(-1      ,self.num_choices      ,-1						).contiguous()
         __snake_case		       =     input_mask.unsqueeze(1						).expand(-1      ,self.num_choices      ,-1						).contiguous()
         __snake_case		       =     model(
             _lowerCAmelCase      ,attention_mask=_lowerCAmelCase      ,token_type_ids=_lowerCAmelCase      ,labels=_lowerCAmelCase      ,)
         self.parent.assertEqual(result.logits.shape      ,(self.batch_size, self.num_choices)						)
  
  
  
  
       def 							UpperCamelCase_						( self :					Union[str, Any]      ,_lowerCAmelCase :					int      ,_lowerCAmelCase :					str      ,_lowerCAmelCase :					Dict      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					Optional[Any]      ,_lowerCAmelCase :					Union[str, Any]      ,_lowerCAmelCase :					Dict      ,_lowerCAmelCase :					int      ,):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     self.num_labels
         __snake_case		       =     FunnelForTokenClassification(config=_lowerCAmelCase						)
         model.to(_lowerCAmelCase						)
         model.eval()
         __snake_case		       =     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 							UpperCamelCase_						( self :					int      ,_lowerCAmelCase :					Union[str, Any]      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					Any      ,_lowerCAmelCase :					int      ,_lowerCAmelCase :					Dict      ,_lowerCAmelCase :					List[str]      ,_lowerCAmelCase :					Dict      ,_lowerCAmelCase :					Optional[Any]      ,):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     FunnelForQuestionAnswering(config=_lowerCAmelCase						)
         model.to(_lowerCAmelCase						)
         model.eval()
         __snake_case		       =     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 							UpperCamelCase_						( self :					Any						):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     self.prepare_config_and_inputs()
         (
             (
             __snake_case       
         )       ,       (
             __snake_case       
         )       ,       (
             __snake_case       
         )       ,       (
             __snake_case       
         )       ,       (
             __snake_case       
         )       ,       (
             __snake_case       
         )       ,       (
             __snake_case       
         )       ,       (
             __snake_case       
         )       ,              
         )		       =     config_and_inputs
         __snake_case		       =     {"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 							UpperCamelCase_						( self :					Any      ,_lowerCAmelCase :					List[str]      ,_lowerCAmelCase :					Optional[Any]      ,_lowerCAmelCase :					Any=False						):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     super()._prepare_for_class(_lowerCAmelCase      ,_lowerCAmelCase      ,return_labels=_lowerCAmelCase						)
  
         if return_labels:
           if model_class in get_values(_lowerCAmelCase						):
             __snake_case		       =     torch.zeros(
                 (self.model_tester.batch_size, self.model_tester.seq_length)      ,dtype=torch.long      ,device=_lowerCAmelCase						)
         return inputs_dict
  
  
  
  
       def 							UpperCamelCase_						( self :					Optional[Any]						):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     FunnelModelTester(self						)
         __snake_case		       =     ConfigTester(self      ,config_class=_lowerCAmelCase						)
  
  
  
  
       def 							UpperCamelCase_						( self :					List[str]						):
  
  
         """simple docstring"""
  
  
  
  
         self.config_tester.run_common_tests()
  
  
  
  
       def 							UpperCamelCase_						( self :					Dict						):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*_lowerCAmelCase						)
  
  
  
  
       def 							UpperCamelCase_						( self :					int						):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_pretraining(*_lowerCAmelCase						)
  
  
  
  
       def 							UpperCamelCase_						( self :					Any						):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*_lowerCAmelCase						)
  
  
  
  
       def 							UpperCamelCase_						( self :					Tuple						):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*_lowerCAmelCase						)
  
  
  
  
       def 							UpperCamelCase_						( self :					int						):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*_lowerCAmelCase						)
  
  
  
  
  
  
  
       def 							UpperCamelCase_						( self :					List[str]      ,_lowerCAmelCase :					Tuple						):
  
  
         """simple docstring"""
  
  
  
  
         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:
             __snake_case		       =     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 							UpperCamelCase_						( self :					List[str]						):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     FunnelModelTester(self      ,base=_lowerCAmelCase						)
         __snake_case		       =     ConfigTester(self      ,config_class=_lowerCAmelCase						)
  
  
  
  
       def 							UpperCamelCase_						( self :					List[str]						):
  
  
         """simple docstring"""
  
  
  
  
         self.config_tester.run_common_tests()
  
  
  
  
       def 							UpperCamelCase_						( self :					List[Any]						):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_base_model(*_lowerCAmelCase						)
  
  
  
  
       def 							UpperCamelCase_						( self :					List[Any]						):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*_lowerCAmelCase						)
  
  
  
  
       def 							UpperCamelCase_						( self :					Any						):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_multiple_choice(*_lowerCAmelCase						)
  
  
  
  
       def 							UpperCamelCase_						( self :					Optional[Any]						):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case       ,       __snake_case		       =     self.model_tester.prepare_config_and_inputs_for_common()
         __snake_case		       =     True
  
         for model_class in self.all_model_classes:
           if model_class.__name__ == "FunnelBaseModel":
             continue
           __snake_case		       =     model_class(_lowerCAmelCase						)
           model.to(_lowerCAmelCase						)
           model.train()
           __snake_case		       =     self._prepare_for_class(_lowerCAmelCase      ,_lowerCAmelCase      ,return_labels=_lowerCAmelCase						)
           __snake_case		       =     model(**_lowerCAmelCase						).loss
           loss.backward()
  
  
  
  
  
  
  
       def 							UpperCamelCase_						( self :					Optional[int]      ,_lowerCAmelCase :					Optional[Any]						):
  
  
         """simple docstring"""
  
  
  
  
         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:
             __snake_case		       =     getattr(_lowerCAmelCase      ,_lowerCAmelCase						)
             weight.data.fill_(3						)
  
  
  
  
  @require_torch
  @require_sentencepiece
  @require_tokenizers
  class 					UpperCamelCase	(     unittest.TestCase      ):
  
  
  
  
       def 							UpperCamelCase_						( self :					Union[str, Any]						):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     13
         __snake_case		       =     7
         __snake_case		       =     torch.arange(0      ,batch_size * sequence_length						).long().reshape(_lowerCAmelCase      ,_lowerCAmelCase						)
         __snake_case		       =     [0, 1, 2, 3, 4, 5, 6, 4, 1, 3, 5, 0, 1]
         __snake_case		       =     torch.tensor([[2] + [0] * a + [1] * (sequence_length - a - 1) for a in lengths]						)
  
         __snake_case		       =     FunnelModel.from_pretrained("sgugger/funnel-random-tiny"						)
         __snake_case		       =     model(_lowerCAmelCase      ,token_type_ids=_lowerCAmelCase						)[0].abs()
  
         __snake_case		       =     torch.tensor(2_344.8_352						)
         __snake_case		       =     torch.tensor(0.8_0_5_2						)
         self.assertTrue(torch.allclose(output.sum()      ,_lowerCAmelCase      ,atol=1E-4						)						)
         self.assertTrue(torch.allclose(output.mean()      ,_lowerCAmelCase      ,atol=1E-4						)						)
  
         __snake_case		       =     torch.tensor([[1] * 7, [1] * 4 + [0] * 3] * 6 + [[0, 1, 1, 0, 0, 1, 1]]						)
         __snake_case		       =     model(_lowerCAmelCase      ,attention_mask=_lowerCAmelCase      ,token_type_ids=_lowerCAmelCase						)[0].abs()
  
         __snake_case		       =     torch.tensor(2_343.8_425						)
         __snake_case		       =     torch.tensor(0.8_0_4_9						)
         self.assertTrue(torch.allclose(output.sum()      ,_lowerCAmelCase      ,atol=1E-4						)						)
         self.assertTrue(torch.allclose(output.mean()      ,_lowerCAmelCase      ,atol=1E-4						)						)
  
  
  
  
  
  
  
       @slow
       def 							UpperCamelCase_						( self :					List[str]						):
  
  
         """simple docstring"""
  
  
  
  
         __snake_case		       =     FunnelTokenizer.from_pretrained("huggingface/funnel-small"						)
         __snake_case		       =     FunnelModel.from_pretrained("huggingface/funnel-small"						)
         __snake_case		       =     tokenizer("Hello! I am the Funnel Transformer model."      ,return_tensors="pt"						)
         __snake_case		       =     model(**_lowerCAmelCase						)[0]
  
         __snake_case		       =     torch.tensor(235.7_246						)
         __snake_case		       =     torch.tensor(0.0_2_5_6						)
         self.assertTrue(torch.allclose(output.sum()      ,_lowerCAmelCase      ,atol=1E-4						)						)
         self.assertTrue(torch.allclose(output.mean()      ,_lowerCAmelCase      ,atol=1E-4						)						)
  
  
  
  
  
  
style_context: import posixpath
  from pathlib import Path
  from unittest.mock import patch
  
  import pytest
  from fsspec.implementations.local import AbstractFileSystem, LocalFileSystem, stringify_path
  from fsspec.registry import _registry as _fsspec_registry
  
  
  
  
  class 					UpperCamelCase	(     snake_case__      ):
  					__UpperCamelCase						=   """mock"""
  
  
  
  
  					def __init__( self :					List[Any]      ,*_lowerCAmelCase :					Optional[int]      ,_lowerCAmelCase :					Union[str, Any]      ,**_lowerCAmelCase :					Union[str, Any]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							super().__init__()
  							__snake_case		       =     LocalFileSystem(*_lowerCAmelCase      ,**_lowerCAmelCase						)
  							__snake_case		       =     Path(_lowerCAmelCase						).resolve().as_posix() + "/"
  
  
  
  
  					def 							UpperCamelCase_						( self :					List[Any]      ,_lowerCAmelCase :					Optional[Any]      ,*_lowerCAmelCase :					Union[str, Any]      ,**_lowerCAmelCase :					Dict						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     posixpath.join(self.local_root_dir      ,self._strip_protocol(_lowerCAmelCase						)						)
  							return self._fs.mkdir(_lowerCAmelCase      ,*_lowerCAmelCase      ,**_lowerCAmelCase						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					int      ,_lowerCAmelCase :					Tuple      ,*_lowerCAmelCase :					Optional[Any]      ,**_lowerCAmelCase :					Optional[Any]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     posixpath.join(self.local_root_dir      ,self._strip_protocol(_lowerCAmelCase						)						)
  							return self._fs.makedirs(_lowerCAmelCase      ,*_lowerCAmelCase      ,**_lowerCAmelCase						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					Tuple      ,_lowerCAmelCase :					Any						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     posixpath.join(self.local_root_dir      ,self._strip_protocol(_lowerCAmelCase						)						)
  							return self._fs.rmdir(_lowerCAmelCase						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					List[Any]      ,_lowerCAmelCase :					List[Any]      ,_lowerCAmelCase :					str=True      ,*_lowerCAmelCase :					int      ,**_lowerCAmelCase :					List[str]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     posixpath.join(self.local_root_dir      ,self._strip_protocol(_lowerCAmelCase						)						)
  							__snake_case		       =     self._fs.ls(_lowerCAmelCase      ,detail=_lowerCAmelCase      ,*_lowerCAmelCase      ,**_lowerCAmelCase						)
  							if detail:
  									return [{**info, "name": info["name"][len(self.local_root_dir						) :]} for info in out]
  							else:
  									return [name[len(self.local_root_dir						) :] for name in out]
  
  
  
  
  					def 							UpperCamelCase_						( self :					List[str]      ,_lowerCAmelCase :					Any      ,*_lowerCAmelCase :					Any      ,**_lowerCAmelCase :					str						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     posixpath.join(self.local_root_dir      ,self._strip_protocol(_lowerCAmelCase						)						)
  							__snake_case		       =     dict(self._fs.info(_lowerCAmelCase      ,*_lowerCAmelCase      ,**_lowerCAmelCase						)						)
  							__snake_case		       =     out["name"][len(self.local_root_dir						) :]
  							return out
  
  
  
  
  					def 							UpperCamelCase_						( self :					Tuple      ,_lowerCAmelCase :					Optional[int]      ,_lowerCAmelCase :					Optional[Any]      ,*_lowerCAmelCase :					int      ,**_lowerCAmelCase :					Optional[int]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     posixpath.join(self.local_root_dir      ,self._strip_protocol(_lowerCAmelCase						)						)
  							__snake_case		       =     posixpath.join(self.local_root_dir      ,self._strip_protocol(_lowerCAmelCase						)						)
  							return self._fs.cp_file(_lowerCAmelCase      ,_lowerCAmelCase      ,*_lowerCAmelCase      ,**_lowerCAmelCase						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					Union[str, Any]      ,_lowerCAmelCase :					int      ,*_lowerCAmelCase :					List[Any]      ,**_lowerCAmelCase :					int						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     posixpath.join(self.local_root_dir      ,self._strip_protocol(_lowerCAmelCase						)						)
  							return self._fs.rm_file(_lowerCAmelCase      ,*_lowerCAmelCase      ,**_lowerCAmelCase						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					Optional[Any]      ,_lowerCAmelCase :					str      ,*_lowerCAmelCase :					Optional[int]      ,**_lowerCAmelCase :					int						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     posixpath.join(self.local_root_dir      ,self._strip_protocol(_lowerCAmelCase						)						)
  							return self._fs.rm(_lowerCAmelCase      ,*_lowerCAmelCase      ,**_lowerCAmelCase						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					int      ,_lowerCAmelCase :					Optional[int]      ,*_lowerCAmelCase :					str      ,**_lowerCAmelCase :					Optional[Any]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     posixpath.join(self.local_root_dir      ,self._strip_protocol(_lowerCAmelCase						)						)
  							return self._fs._open(_lowerCAmelCase      ,*_lowerCAmelCase      ,**_lowerCAmelCase						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					Union[str, Any]      ,_lowerCAmelCase :					Tuple						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     posixpath.join(self.local_root_dir      ,self._strip_protocol(_lowerCAmelCase						)						)
  							return self._fs.created(_lowerCAmelCase						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					Union[str, Any]      ,_lowerCAmelCase :					int						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     posixpath.join(self.local_root_dir      ,self._strip_protocol(_lowerCAmelCase						)						)
  							return self._fs.modified(_lowerCAmelCase						)
  
  
  
  
  
  
  
  					@classmethod
  					def 							UpperCamelCase_						( cls :					Dict      ,_lowerCAmelCase :					Dict						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     stringify_path(_lowerCAmelCase						)
  							if path.startswith("mock://"						):
  									__snake_case		       =     path[7:]
  							return path
  
  
  
  
  class 					UpperCamelCase	(     snake_case__      ):
  					__UpperCamelCase						=   """tmp"""
  					__UpperCamelCase						=   None
  
  
  
  
  					def __init__( self :					int      ,*_lowerCAmelCase :					Tuple      ,**_lowerCAmelCase :					Union[str, Any]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							assert self.tmp_dir is not None, "TmpDirFileSystem.tmp_dir is not set"
  							super().__init__(*_lowerCAmelCase      ,**_lowerCAmelCase      ,local_root_dir=self.tmp_dir      ,auto_mkdir=_lowerCAmelCase						)
  
  
  
  
  
  
  
  					@classmethod
  					def 							UpperCamelCase_						( cls :					int      ,_lowerCAmelCase :					str						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     stringify_path(_lowerCAmelCase						)
  							if path.startswith("tmp://"						):
  									__snake_case		       =     path[6:]
  							return path
  
  
  
  
  @pytest.fixture
  def 							_lowerCamelCase(				)  ->   str:
  		__snake_case		       =     MockFileSystem
  		__snake_case		       =     TmpDirFileSystem
  		yield
  		del _fsspec_registry["mock"]
  		del _fsspec_registry["tmp"]
  
  
  
  @pytest.fixture
  def 							_lowerCamelCase(				__snake_case						,						__snake_case	)  ->   Dict:
  		__snake_case		       =     tmp_path_factory.mktemp("mockfs"	)
  		return MockFileSystem(local_root_dir=__snake_case						,						auto_mkdir=__snake_case	)
  
  
  
  
  
  @pytest.fixture
  def 							_lowerCamelCase(				__snake_case						,						__snake_case	)  ->   List[Any]:
  		__snake_case		       =     tmp_path_factory.mktemp("tmpfs"	)
  		with patch.object(__snake_case						,						"tmp_dir"						,						__snake_case	):
  				yield TmpDirFileSystem()
  
  
  
  
  
  