


import unittest

from transformers import FunnelConfig, FunnelTokenizer, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch

 from transformers import (
     MODEL_FOR_PRETRAINING_MAPPING,
     FunnelBaseModel,
     FunnelForMaskedLM,
     FunnelForMultipleChoice,
     FunnelForPreTraining,
     FunnelForQuestionAnswering,
     FunnelForSequenceClassification,
     FunnelForTokenClassification,
     FunnelModel,
 )




class A						:






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




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

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






      def  lowerCamelCase (      self		:  Union[str, Any]				)      ->		str:
             """simple docstring"""




             _lowerCamelCase :	List[Any]						=ids_tensor([self.batch_size, self.seq_length]    ,     self.vocab_size				)

             _lowerCamelCase :	Optional[int]						=None
             if self.use_input_mask:
                    _lowerCamelCase :	Optional[int]						=ids_tensor([self.batch_size, self.seq_length]    ,     vocab_size=2				)

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

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

             _lowerCamelCase :	List[Any]						=self.get_config()

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






      def  lowerCamelCase (      self		:  int				)      ->		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  lowerCamelCase (      self		:  Optional[Any]    ,     lowercase_		:  str    ,     lowercase_		:  int    ,     lowercase_		:  Optional[int]    ,     lowercase_		:  Union[str, Any]    ,     lowercase_		:  int    ,     lowercase_		:  Any    ,     lowercase_		:  str    ,     lowercase_		:  Dict    ,     )      ->		Optional[int]:
             """simple docstring"""




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

             _lowerCamelCase :	List[str]						=False
             _lowerCamelCase :	int						=model(lowercase_				)
             self.parent.assertEqual(result.last_hidden_state.shape    ,     (self.batch_size, self.seq_length, self.d_model)				)

             _lowerCamelCase :	str						=False
             _lowerCamelCase :	Optional[Any]						=model(lowercase_				)
             self.parent.assertEqual(result.last_hidden_state.shape    ,     (self.batch_size, self.seq_length, self.d_model)				)






      def  lowerCamelCase (      self		:  int    ,     lowercase_		:  Union[str, Any]    ,     lowercase_		:  Any    ,     lowercase_		:  List[Any]    ,     lowercase_		:  int    ,     lowercase_		:  List[str]    ,     lowercase_		:  int    ,     lowercase_		:  Any    ,     lowercase_		:  List[str]    ,     )      ->		Dict:
             """simple docstring"""




             _lowerCamelCase :	Dict						=FunnelBaseModel(config=lowercase_				)
             model.to(lowercase_				)
             model.eval()
             _lowerCamelCase :	Dict						=model(lowercase_    ,     attention_mask=lowercase_    ,     token_type_ids=lowercase_				)
             _lowerCamelCase :	str						=model(lowercase_    ,     token_type_ids=lowercase_				)
             _lowerCamelCase :	Optional[int]						=model(lowercase_				)
             self.parent.assertEqual(result.last_hidden_state.shape    ,     (self.batch_size, 2, self.d_model)				)

             _lowerCamelCase :	List[Any]						=False
             _lowerCamelCase :	Union[str, Any]						=model(lowercase_				)
             self.parent.assertEqual(result.last_hidden_state.shape    ,     (self.batch_size, 3, self.d_model)				)

             _lowerCamelCase :	Tuple						=False
             _lowerCamelCase :	Optional[Any]						=model(lowercase_				)
             self.parent.assertEqual(result.last_hidden_state.shape    ,     (self.batch_size, 2, self.d_model)				)






      def  lowerCamelCase (      self		:  Tuple    ,     lowercase_		:  Optional[int]    ,     lowercase_		:  List[str]    ,     lowercase_		:  List[str]    ,     lowercase_		:  Dict    ,     lowercase_		:  Union[str, Any]    ,     lowercase_		:  Union[str, Any]    ,     lowercase_		:  str    ,     lowercase_		:  Union[str, Any]    ,     )      ->		Any:
             """simple docstring"""




             _lowerCamelCase :	List[str]						=self.num_labels
             _lowerCamelCase :	str						=FunnelForPreTraining(config=lowercase_				)
             model.to(lowercase_				)
             model.eval()
             _lowerCamelCase :	Tuple						=model(lowercase_    ,     attention_mask=lowercase_    ,     token_type_ids=lowercase_    ,     labels=lowercase_				)
             self.parent.assertEqual(result.logits.shape    ,     (self.batch_size, self.seq_length)				)






      def  lowerCamelCase (      self		:  Union[str, Any]    ,     lowercase_		:  Any    ,     lowercase_		:  List[str]    ,     lowercase_		:  Tuple    ,     lowercase_		:  int    ,     lowercase_		:  List[str]    ,     lowercase_		:  List[Any]    ,     lowercase_		:  int    ,     lowercase_		:  Union[str, Any]    ,     )      ->		List[Any]:
             """simple docstring"""




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






      def  lowerCamelCase (      self		:  Union[str, Any]    ,     lowercase_		:  str    ,     lowercase_		:  List[str]    ,     lowercase_		:  Optional[Any]    ,     lowercase_		:  Optional[int]    ,     lowercase_		:  str    ,     lowercase_		:  Any    ,     lowercase_		:  Optional[Any]    ,     lowercase_		:  Optional[int]    ,     )      ->		Optional[int]:
             """simple docstring"""




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






      def  lowerCamelCase (      self		:  Tuple    ,     lowercase_		:  Any    ,     lowercase_		:  Optional[Any]    ,     lowercase_		:  Any    ,     lowercase_		:  Optional[int]    ,     lowercase_		:  List[str]    ,     lowercase_		:  int    ,     lowercase_		:  int    ,     lowercase_		:  int    ,     )      ->		Any:
             """simple docstring"""




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






      def  lowerCamelCase (      self		:  int    ,     lowercase_		:  Any    ,     lowercase_		:  Any    ,     lowercase_		:  List[str]    ,     lowercase_		:  List[Any]    ,     lowercase_		:  Any    ,     lowercase_		:  Tuple    ,     lowercase_		:  int    ,     lowercase_		:  str    ,     )      ->		Any:
             """simple docstring"""




             _lowerCamelCase :	Union[str, Any]						=self.num_labels
             _lowerCamelCase :	int						=FunnelForTokenClassification(config=lowercase_				)
             model.to(lowercase_				)
             model.eval()
             _lowerCamelCase :	Optional[Any]						=model(lowercase_    ,     attention_mask=lowercase_    ,     token_type_ids=lowercase_    ,     labels=lowercase_				)
             self.parent.assertEqual(result.logits.shape    ,     (self.batch_size, self.seq_length, self.num_labels)				)






      def  lowerCamelCase (      self		:  Any    ,     lowercase_		:  List[Any]    ,     lowercase_		:  Union[str, Any]    ,     lowercase_		:  Tuple    ,     lowercase_		:  Any    ,     lowercase_		:  int    ,     lowercase_		:  Optional[Any]    ,     lowercase_		:  Any    ,     lowercase_		:  List[Any]    ,     )      ->		str:
             """simple docstring"""




             _lowerCamelCase :	Tuple						=FunnelForQuestionAnswering(config=lowercase_				)
             model.to(lowercase_				)
             model.eval()
             _lowerCamelCase :	List[Any]						=model(
                 lowercase_    ,     attention_mask=lowercase_    ,     token_type_ids=lowercase_    ,     start_positions=lowercase_    ,     end_positions=lowercase_    ,     )
             self.parent.assertEqual(result.start_logits.shape    ,     (self.batch_size, self.seq_length)				)
             self.parent.assertEqual(result.end_logits.shape    ,     (self.batch_size, self.seq_length)				)






      def  lowerCamelCase (      self		:  Dict				)      ->		Union[str, Any]:
             """simple docstring"""




             _lowerCamelCase :	Optional[Any]						=self.prepare_config_and_inputs()
             (
                 _lowerCamelCase  
             ) :	Tuple						=config_and_inputs
             _lowerCamelCase :	List[str]						={'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
             return config, inputs_dict




@require_torch
class A						(     UpperCamelCase_					,							UpperCamelCase_					,							unittest.TestCase  ):
      UpperCamelCase__							:						Dict   =False
      UpperCamelCase__							:						List[str]   =False
      UpperCamelCase__							:						Dict   =(
          (
              FunnelModel,
              FunnelForMaskedLM,
              FunnelForPreTraining,
              FunnelForQuestionAnswering,
              FunnelForTokenClassification,
          )
          if is_torch_available()
          else ()
      )
      UpperCamelCase__							:						Any   =(
          {
              'feature-extraction': (FunnelBaseModel, FunnelModel),
              'fill-mask': FunnelForMaskedLM,
              'question-answering': FunnelForQuestionAnswering,
              'text-classification': FunnelForSequenceClassification,
              'token-classification': FunnelForTokenClassification,
              'zero-shot': FunnelForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )






      def  lowerCamelCase (      self		:  Any    ,     lowercase_		:  str    ,     lowercase_		:  int    ,     lowercase_		:  List[str]=False				)      ->		Optional[int]:
             """simple docstring"""




             _lowerCamelCase :	str						=super()._prepare_for_class(lowercase_    ,     lowercase_    ,     return_labels=lowercase_				)

             if return_labels:
                    if model_class in get_values(lowercase_				):
                           _lowerCamelCase :	Tuple						=torch.zeros(
                               (self.model_tester.batch_size, self.model_tester.seq_length)    ,     dtype=torch.long    ,     device=lowercase_				)
             return inputs_dict






      def  lowerCamelCase (      self		:  Tuple				)      ->		int:
             """simple docstring"""




             _lowerCamelCase :	Tuple						=FunnelModelTester(self				)
             _lowerCamelCase :	Tuple						=ConfigTester(self    ,     config_class=lowercase_				)






      def  lowerCamelCase (      self		:  Any				)      ->		Optional[Any]:
             """simple docstring"""




             self.config_tester.run_common_tests()






      def  lowerCamelCase (      self		:  int				)      ->		Optional[Any]:
             """simple docstring"""




             _lowerCamelCase :	Any						=self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*lowercase_				)






      def  lowerCamelCase (      self		:  Tuple				)      ->		Optional[Any]:
             """simple docstring"""




             _lowerCamelCase :	Optional[Any]						=self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_pretraining(*lowercase_				)






      def  lowerCamelCase (      self		:  Tuple				)      ->		Optional[Any]:
             """simple docstring"""




             _lowerCamelCase :	List[str]						=self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_masked_lm(*lowercase_				)






      def  lowerCamelCase (      self		:  Optional[int]				)      ->		List[Any]:
             """simple docstring"""




             _lowerCamelCase :	Tuple						=self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_token_classification(*lowercase_				)






      def  lowerCamelCase (      self		:  Tuple				)      ->		List[Any]:
             """simple docstring"""




             _lowerCamelCase :	Any						=self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_question_answering(*lowercase_				)






      def  lowerCamelCase (      self		:  Optional[Any]    ,     lowercase_		:  Dict				)      ->		List[str]:
             """simple docstring"""




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




@require_torch
class A						(     UpperCamelCase_					,							unittest.TestCase  ):
      UpperCamelCase__							:						Union[str, Any]   =False
      UpperCamelCase__							:						str   =False
      UpperCamelCase__							:						Optional[int]   =(
          (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
      )






      def  lowerCamelCase (      self		:  Union[str, Any]				)      ->		Optional[int]:
             """simple docstring"""




             _lowerCamelCase :	Optional[Any]						=FunnelModelTester(self    ,     base=lowercase_				)
             _lowerCamelCase :	str						=ConfigTester(self    ,     config_class=lowercase_				)






      def  lowerCamelCase (      self		:  Any				)      ->		Optional[Any]:
             """simple docstring"""




             self.config_tester.run_common_tests()






      def  lowerCamelCase (      self		:  str				)      ->		Any:
             """simple docstring"""




             _lowerCamelCase :	str						=self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_base_model(*lowercase_				)






      def  lowerCamelCase (      self		:  Optional[Any]				)      ->		Optional[int]:
             """simple docstring"""




             _lowerCamelCase :	str						=self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_sequence_classification(*lowercase_				)






      def  lowerCamelCase (      self		:  int				)      ->		int:
             """simple docstring"""




             _lowerCamelCase :	Optional[Any]						=self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_multiple_choice(*lowercase_				)






      def  lowerCamelCase (      self		:  Tuple				)      ->		str:
             """simple docstring"""




             _lowerCamelCase :	Dict						=self.model_tester.prepare_config_and_inputs_for_common()
             _lowerCamelCase :	List[str]						=True

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






      def  lowerCamelCase (      self		:  List[Any]    ,     lowercase_		:  str				)      ->		Optional[Any]:
             """simple docstring"""




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




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






      def  lowerCamelCase (      self		:  List[Any]				)      ->		List[str]:
             """simple docstring"""




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

             _lowerCamelCase :	List[Any]						=FunnelModel.from_pretrained('sgugger/funnel-random-tiny'				)
             _lowerCamelCase :	Any						=model(lowercase_    ,     token_type_ids=lowercase_				)[0].abs()

             _lowerCamelCase :	Tuple						=torch.tensor(2344.8352				)
             _lowerCamelCase :	Tuple						=torch.tensor(0.8052				)
             self.assertTrue(torch.allclose(output.sum()    ,     lowercase_    ,     atol=1E-4				)				)
             self.assertTrue(torch.allclose(output.mean()    ,     lowercase_    ,     atol=1E-4				)				)

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

             _lowerCamelCase :	Optional[int]						=torch.tensor(2343.8425				)
             _lowerCamelCase :	str						=torch.tensor(0.8049				)
             self.assertTrue(torch.allclose(output.sum()    ,     lowercase_    ,     atol=1E-4				)				)
             self.assertTrue(torch.allclose(output.mean()    ,     lowercase_    ,     atol=1E-4				)				)






      @slow
      def  lowerCamelCase (      self		:  List[str]				)      ->		Union[str, Any]:
             """simple docstring"""




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

             _lowerCamelCase :	Optional[Any]						=torch.tensor(235.7246				)
             _lowerCamelCase :	int						=torch.tensor(0.0256				)
             self.assertTrue(torch.allclose(output.sum()    ,     lowercase_    ,     atol=1E-4				)				)
             self.assertTrue(torch.allclose(output.mean()    ,     lowercase_    ,     atol=1E-4				)				)






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowerCamelCase		      = {
    'configuration_deberta_v2': ['DEBERTA_V2_PRETRAINED_CONFIG_ARCHIVE_MAP', 'DebertaV2Config', 'DebertaV2OnnxConfig'],
    'tokenization_deberta_v2': ['DebertaV2Tokenizer'],
}

try:
 if not is_tokenizers_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCamelCase		      = ['DebertaV2TokenizerFast']

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCamelCase		      = [
     'TF_DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST',
     'TFDebertaV2ForMaskedLM',
     'TFDebertaV2ForQuestionAnswering',
     'TFDebertaV2ForSequenceClassification',
     'TFDebertaV2ForTokenClassification',
     'TFDebertaV2Model',
     'TFDebertaV2PreTrainedModel',
 ]

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCamelCase		      = [
     'DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST',
     'DebertaV2ForMaskedLM',
     'DebertaV2ForMultipleChoice',
     'DebertaV2ForQuestionAnswering',
     'DebertaV2ForSequenceClassification',
     'DebertaV2ForTokenClassification',
     'DebertaV2Model',
     'DebertaV2PreTrainedModel',
 ]


if TYPE_CHECKING:
 from .configuration_deberta_va import (
     DEBERTA_V2_PRETRAINED_CONFIG_ARCHIVE_MAP,
     DebertaVaConfig,
     DebertaVaOnnxConfig,
 )
 from .tokenization_deberta_va import DebertaVaTokenizer

 try:
  if not is_tokenizers_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_deberta_va_fast import DebertaVaTokenizerFast

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_deberta_va import (
      TF_DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFDebertaVaForMaskedLM,
      TFDebertaVaForQuestionAnswering,
      TFDebertaVaForSequenceClassification,
      TFDebertaVaForTokenClassification,
      TFDebertaVaModel,
      TFDebertaVaPreTrainedModel,
  )

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_deberta_va import (
      DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST,
      DebertaVaForMaskedLM,
      DebertaVaForMultipleChoice,
      DebertaVaForQuestionAnswering,
      DebertaVaForSequenceClassification,
      DebertaVaForTokenClassification,
      DebertaVaModel,
      DebertaVaPreTrainedModel,
  )

else:
 import sys

 lowerCamelCase		      = _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)


