


'''simple docstring'''
import unittest

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

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


if is_torch_available():
     import torch

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







class 					_A						:



   '''simple docstring'''






   def __init__(	self	:					str					, lowerCamelCase	:					int					, lowerCamelCase	:					List[Any]=13					, lowerCamelCase	:					Dict=7					, lowerCamelCase	:					Optional[int]=True					, lowerCamelCase	:					Dict=True					, lowerCamelCase	:					str=True					, lowerCamelCase	:					Union[str, Any]=True					, lowerCamelCase	:					Union[str, Any]=99					, lowerCamelCase	:					Dict=[1, 1, 2]					, lowerCamelCase	:					List[Any]=1					, lowerCamelCase	:					List[str]=32					, lowerCamelCase	:					Dict=4					, lowerCamelCase	:					Tuple=8					, lowerCamelCase	:					List[Any]=37					, lowerCamelCase	:					Dict="gelu_new"					, lowerCamelCase	:					Dict=0.1					, lowerCamelCase	:					List[Any]=0.1					, lowerCamelCase	:					Optional[int]=0.0					, lowerCamelCase	:					Tuple=512					, lowerCamelCase	:					Tuple=3					, lowerCamelCase	:					List[str]=0.02					, lowerCamelCase	:					str=3					, lowerCamelCase	:					Optional[Any]=4					, lowerCamelCase	:					str=None					, lowerCamelCase	:					Union[str, Any]=False					, )->	int:
          snake_case__					:	int          =					parent
          snake_case__					:	Optional[Any]          =					batch_size
          snake_case__					:	Optional[Any]          =					seq_length
          snake_case__					:	List[Any]          =					is_training
          snake_case__					:	List[str]          =					use_input_mask
          snake_case__					:	Any          =					use_token_type_ids
          snake_case__					:	Union[str, Any]          =					use_labels
          snake_case__					:	Any          =					vocab_size
          snake_case__					:	int          =					block_sizes
          snake_case__					:	Optional[int]          =					num_decoder_layers
          snake_case__					:	Union[str, Any]          =					d_model
          snake_case__					:	List[str]          =					n_head
          snake_case__					:	Optional[Any]          =					d_head
          snake_case__					:	str          =					d_inner
          snake_case__					:	Optional[Any]          =					hidden_act
          snake_case__					:	List[Any]          =					hidden_dropout
          snake_case__					:	List[Any]          =					attention_dropout
          snake_case__					:	Tuple          =					activation_dropout
          snake_case__					:	Optional[int]          =					max_position_embeddings
          snake_case__					:	Optional[int]          =					type_vocab_size
          snake_case__					:	Any          =					2
          snake_case__					:	Dict          =					num_labels
          snake_case__					:	List[Any]          =					num_choices
          snake_case__					:	Any          =					scope
          snake_case__					:	Optional[Any]          =					initializer_std

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




   def   __lowerCAmelCase						(	self	:					Any						)->	Any:
          snake_case__					:	Tuple          =					ids_tensor([self.batch_size, self.seq_length]					, self.vocab_size						)

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

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

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

          snake_case__					:	Dict          =					self.get_config()

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




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

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

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




   def   __lowerCAmelCase						(	self	:					Optional[Any]					, lowerCamelCase	:					Union[str, Any]					, lowerCamelCase	:					str					, lowerCamelCase	:					Any					, lowerCamelCase	:					str					, lowerCamelCase	:					Any					, lowerCamelCase	:					str					, lowerCamelCase	:					List[str]					, lowerCamelCase	:					Dict					, )->	List[Any]:
          snake_case__					:	Dict          =					FunnelBaseModel(config=lowerCamelCase						)
          model.to(lowerCamelCase						)
          model.eval()
          snake_case__					:	List[str]          =					model(lowerCamelCase					, attention_mask=lowerCamelCase					, token_type_ids=lowerCamelCase						)
          snake_case__					:	Union[str, Any]          =					model(lowerCamelCase					, token_type_ids=lowerCamelCase						)
          snake_case__					:	List[Any]          =					model(lowerCamelCase						)
          self.parent.assertEqual(result.last_hidden_state.shape					, (self.batch_size, 2, self.d_model)						)

          snake_case__					:	Optional[Any]          =					False
          snake_case__					:	Tuple          =					model(lowerCamelCase						)
          self.parent.assertEqual(result.last_hidden_state.shape					, (self.batch_size, 3, self.d_model)						)

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




   def   __lowerCAmelCase						(	self	:					Tuple					, lowerCamelCase	:					Union[str, Any]					, lowerCamelCase	:					Optional[int]					, lowerCamelCase	:					Optional[int]					, lowerCamelCase	:					Any					, lowerCamelCase	:					str					, lowerCamelCase	:					Optional[int]					, lowerCamelCase	:					Dict					, lowerCamelCase	:					str					, )->	str:
          snake_case__					:	Optional[int]          =					self.num_labels
          snake_case__					:	Optional[Any]          =					FunnelForPreTraining(config=lowerCamelCase						)
          model.to(lowerCamelCase						)
          model.eval()
          snake_case__					:	Dict          =					model(lowerCamelCase					, attention_mask=lowerCamelCase					, token_type_ids=lowerCamelCase					, labels=lowerCamelCase						)
          self.parent.assertEqual(result.logits.shape					, (self.batch_size, self.seq_length)						)




   def   __lowerCAmelCase						(	self	:					List[str]					, lowerCamelCase	:					Optional[int]					, lowerCamelCase	:					List[str]					, lowerCamelCase	:					Tuple					, lowerCamelCase	:					Any					, lowerCamelCase	:					str					, lowerCamelCase	:					Optional[Any]					, lowerCamelCase	:					Optional[Any]					, lowerCamelCase	:					Union[str, Any]					, )->	str:
          snake_case__					:	List[str]          =					FunnelForMaskedLM(config=lowerCamelCase						)
          model.to(lowerCamelCase						)
          model.eval()
          snake_case__					:	Any          =					model(lowerCamelCase					, attention_mask=lowerCamelCase					, token_type_ids=lowerCamelCase					, labels=lowerCamelCase						)
          self.parent.assertEqual(result.logits.shape					, (self.batch_size, self.seq_length, self.vocab_size)						)




   def   __lowerCAmelCase						(	self	:					Dict					, lowerCamelCase	:					str					, lowerCamelCase	:					Dict					, lowerCamelCase	:					List[str]					, lowerCamelCase	:					Any					, lowerCamelCase	:					Optional[Any]					, lowerCamelCase	:					Optional[Any]					, lowerCamelCase	:					Optional[Any]					, lowerCamelCase	:					Any					, )->	Dict:
          snake_case__					:	Dict          =					self.num_labels
          snake_case__					:	Dict          =					FunnelForSequenceClassification(lowerCamelCase						)
          model.to(lowerCamelCase						)
          model.eval()
          snake_case__					:	str          =					model(lowerCamelCase					, attention_mask=lowerCamelCase					, token_type_ids=lowerCamelCase					, labels=lowerCamelCase						)
          self.parent.assertEqual(result.logits.shape					, (self.batch_size, self.num_labels)						)




   def   __lowerCAmelCase						(	self	:					List[str]					, lowerCamelCase	:					Optional[int]					, lowerCamelCase	:					str					, lowerCamelCase	:					Optional[int]					, lowerCamelCase	:					str					, lowerCamelCase	:					Tuple					, lowerCamelCase	:					int					, lowerCamelCase	:					int					, lowerCamelCase	:					Dict					, )->	Union[str, Any]:
          snake_case__					:	List[Any]          =					self.num_choices
          snake_case__					:	Optional[Any]          =					FunnelForMultipleChoice(config=lowerCamelCase						)
          model.to(lowerCamelCase						)
          model.eval()
          snake_case__					:	int          =					input_ids.unsqueeze(1						).expand(-1					, self.num_choices					, -1						).contiguous()
          snake_case__					:	Tuple          =					token_type_ids.unsqueeze(1						).expand(-1					, self.num_choices					, -1						).contiguous()
          snake_case__					:	List[str]          =					input_mask.unsqueeze(1						).expand(-1					, self.num_choices					, -1						).contiguous()
          snake_case__					:	Tuple          =					model(
              lowerCamelCase					, attention_mask=lowerCamelCase					, token_type_ids=lowerCamelCase					, labels=lowerCamelCase					, )
          self.parent.assertEqual(result.logits.shape					, (self.batch_size, self.num_choices)						)




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




   def   __lowerCAmelCase						(	self	:					Dict					, lowerCamelCase	:					Optional[Any]					, lowerCamelCase	:					int					, lowerCamelCase	:					Dict					, lowerCamelCase	:					Optional[int]					, lowerCamelCase	:					Tuple					, lowerCamelCase	:					str					, lowerCamelCase	:					List[Any]					, lowerCamelCase	:					Optional[Any]					, )->	Optional[int]:
          snake_case__					:	List[str]          =					FunnelForQuestionAnswering(config=lowerCamelCase						)
          model.to(lowerCamelCase						)
          model.eval()
          snake_case__					:	str          =					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   __lowerCAmelCase						(	self	:					str						)->	Optional[Any]:
          snake_case__					:	Optional[int]          =					self.prepare_config_and_inputs()
          (
              snake_case__  
          )					:	Dict          =					config_and_inputs
          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 					_A						(						__lowerCamelCase    ,  __lowerCamelCase    ,  unittest.TestCase							):



   '''simple docstring'''






   _lowercase    						= False
   _lowercase    						= False
   _lowercase    						= (
       (
           FunnelModel,
           FunnelForMaskedLM,
           FunnelForPreTraining,
           FunnelForQuestionAnswering,
           FunnelForTokenClassification,
       )
       if is_torch_available()
       else ()
   )
   _lowercase    						= (
       {
           '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	:					int					, lowerCamelCase	:					Optional[Any]					, lowerCamelCase	:					List[str]					, lowerCamelCase	:					int=False						)->	int:
          snake_case__					:	str          =					super()._prepare_for_class(lowerCamelCase					, lowerCamelCase					, return_labels=lowerCamelCase						)

          if return_labels:
                 if model_class in get_values(lowerCamelCase						):
                        snake_case__					:	str          =					torch.zeros(
                            (self.model_tester.batch_size, self.model_tester.seq_length)					, dtype=torch.long					, device=lowerCamelCase						)
          return inputs_dict




   def   __lowerCAmelCase						(	self	:					List[str]						)->	Union[str, Any]:
          snake_case__					:	Union[str, Any]          =					FunnelModelTester(self						)
          snake_case__					:	List[str]          =					ConfigTester(self					, config_class=lowerCamelCase						)




   def   __lowerCAmelCase						(	self	:					Dict						)->	int:
          self.config_tester.run_common_tests()




   def   __lowerCAmelCase						(	self	:					Optional[Any]						)->	str:
          snake_case__					:	int          =					self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*lowerCamelCase						)




   def   __lowerCAmelCase						(	self	:					Optional[int]						)->	Optional[Any]:
          snake_case__					:	Optional[int]          =					self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_pretraining(*lowerCamelCase						)




   def   __lowerCAmelCase						(	self	:					str						)->	int:
          snake_case__					:	Optional[int]          =					self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_masked_lm(*lowerCamelCase						)




   def   __lowerCAmelCase						(	self	:					Optional[int]						)->	Union[str, Any]:
          snake_case__					:	Any          =					self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_token_classification(*lowerCamelCase						)




   def   __lowerCAmelCase						(	self	:					str						)->	List[str]:
          snake_case__					:	str          =					self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_question_answering(*lowerCamelCase						)




   def   __lowerCAmelCase						(	self	:					Union[str, Any]					, lowerCamelCase	:					List[Any]						)->	int:
          if hasattr(lowerCamelCase					, """weight"""						) and module.weight is not None:
                 module.weight.data.fill_(3						)
          if hasattr(lowerCamelCase					, """bias"""						) and module.bias is not None:
                 module.bias.data.fill_(3						)

          for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
                 if hasattr(lowerCamelCase					, lowerCamelCase						) and getattr(lowerCamelCase					, lowerCamelCase						) is not None:
                        snake_case__					:	str          =					getattr(lowerCamelCase					, lowerCamelCase						)
                        weight.data.fill_(3						)







@require_torch
class 					_A						(						__lowerCamelCase    ,  unittest.TestCase							):



   '''simple docstring'''






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




   def   __lowerCAmelCase						(	self	:					Any						)->	Dict:
          snake_case__					:	Optional[int]          =					FunnelModelTester(self					, base=lowerCamelCase						)
          snake_case__					:	int          =					ConfigTester(self					, config_class=lowerCamelCase						)




   def   __lowerCAmelCase						(	self	:					Dict						)->	List[Any]:
          self.config_tester.run_common_tests()




   def   __lowerCAmelCase						(	self	:					Optional[int]						)->	List[Any]:
          snake_case__					:	List[str]          =					self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_base_model(*lowerCamelCase						)




   def   __lowerCAmelCase						(	self	:					str						)->	Optional[Any]:
          snake_case__					:	Dict          =					self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_sequence_classification(*lowerCamelCase						)




   def   __lowerCAmelCase						(	self	:					Optional[Any]						)->	int:
          snake_case__					:	List[str]          =					self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_multiple_choice(*lowerCamelCase						)




   def   __lowerCAmelCase						(	self	:					Optional[Any]						)->	List[str]:
          snake_case__					:	Optional[Any]          =					self.model_tester.prepare_config_and_inputs_for_common()
          snake_case__					:	List[str]          =					True

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




   def   __lowerCAmelCase						(	self	:					Union[str, Any]					, lowerCamelCase	:					Optional[Any]						)->	Any:
          if hasattr(lowerCamelCase					, """weight"""						) and module.weight is not None:
                 module.weight.data.fill_(3						)
          if hasattr(lowerCamelCase					, """bias"""						) and module.bias is not None:
                 module.bias.data.fill_(3						)

          for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
                 if hasattr(lowerCamelCase					, lowerCamelCase						) and getattr(lowerCamelCase					, lowerCamelCase						) is not None:
                        snake_case__					:	int          =					getattr(lowerCamelCase					, lowerCamelCase						)
                        weight.data.fill_(3						)







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



   '''simple docstring'''






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

          snake_case__					:	Optional[int]          =					FunnelModel.from_pretrained("""sgugger/funnel-random-tiny"""						)
          snake_case__					:	List[Any]          =					model(lowerCamelCase					, token_type_ids=lowerCamelCase						)[0].abs()

          snake_case__					:	str          =					torch.tensor(2_344.8_352						)
          snake_case__					:	Union[str, Any]          =					torch.tensor(0.8_052						)
          self.assertTrue(torch.allclose(output.sum()					, lowerCamelCase					, atol=1e-4						)						)
          self.assertTrue(torch.allclose(output.mean()					, lowerCamelCase					, atol=1e-4						)						)

          snake_case__					:	str          =					torch.tensor([[1] * 7, [1] * 4 + [0] * 3] * 6 + [[0, 1, 1, 0, 0, 1, 1]]						)
          snake_case__					:	Tuple          =					model(lowerCamelCase					, attention_mask=lowerCamelCase					, token_type_ids=lowerCamelCase						)[0].abs()

          snake_case__					:	List[str]          =					torch.tensor(2_343.8_425						)
          snake_case__					:	List[Any]          =					torch.tensor(0.8_049						)
          self.assertTrue(torch.allclose(output.sum()					, lowerCamelCase					, atol=1e-4						)						)
          self.assertTrue(torch.allclose(output.mean()					, lowerCamelCase					, atol=1e-4						)						)




   @slow
   def   __lowerCAmelCase						(	self	:					Optional[Any]						)->	int:
          snake_case__					:	Union[str, Any]          =					FunnelTokenizer.from_pretrained("""huggingface/funnel-small"""						)
          snake_case__					:	Tuple          =					FunnelModel.from_pretrained("""huggingface/funnel-small"""						)
          snake_case__					:	Tuple          =					tokenizer("""Hello! I am the Funnel Transformer model."""					, return_tensors="""pt"""						)
          snake_case__					:	Union[str, Any]          =					model(**lowerCamelCase						)[0]

          snake_case__					:	int          =					torch.tensor(235.7_246						)
          snake_case__					:	Dict          =					torch.tensor(0.0_256						)
          self.assertTrue(torch.allclose(output.sum()					, lowerCamelCase					, atol=1e-4						)						)
          self.assertTrue(torch.allclose(output.mean()					, lowerCamelCase					, atol=1e-4						)						)











from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


__UpperCAmelCase			:  List[str]										=				{"configuration_levit": ["LEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP", "LevitConfig", "LevitOnnxConfig"]}

try:
      if not is_vision_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __UpperCAmelCase			:  Any										=				["LevitFeatureExtractor"]
      __UpperCAmelCase			:  Tuple										=				["LevitImageProcessor"]

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __UpperCAmelCase			:  str										=				[
          "LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST",
          "LevitForImageClassification",
          "LevitForImageClassificationWithTeacher",
          "LevitModel",
          "LevitPreTrainedModel",
      ]


if TYPE_CHECKING:
      from .configuration_levit import LEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP, LevitConfig, LevitOnnxConfig

      try:
            if not is_vision_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .feature_extraction_levit import LevitFeatureExtractor
            from .image_processing_levit import LevitImageProcessor

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_levit import (
                LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
                LevitForImageClassification,
                LevitForImageClassificationWithTeacher,
                LevitModel,
                LevitPreTrainedModel,
            )
else:
      import sys

      __UpperCAmelCase			:  Union[str, Any]										=				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)






