






import logging
import os
import sys
import threading
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


__magic_name__:  int  	=			threading.Lock()
__magic_name__:  Optional[logging.Handler]  	=			None

__magic_name__:  int  	=			{
    "debug": logging.DEBUG,
    "info": logging.INFO,
    "warning": logging.WARNING,
    "error": logging.ERROR,
    "critical": logging.CRITICAL,
}

__magic_name__:  List[str]  	=			logging.WARNING

__magic_name__:  Union[str, Any]  	=			True

def 					UpperCamelCase		( ):






						"""simple docstring"""







						__magic_name__    :     str     		=      os.getenv("""DIFFUSERS_VERBOSITY""",					_A				)
						if env_level_str:
												if env_level_str in log_levels:
																		return log_levels[env_level_str]
												else:
																		logging.getLogger().warning(
																		    f'Unknown option DIFFUSERS_VERBOSITY={env_level_str}, '
																		    f'has to be one of: { ", ".join(log_levels.keys()				) }'				)
						return _default_log_level

def 					UpperCamelCase		( ):






						"""simple docstring"""







						return __name__.split("""."""				)[0]

def 					UpperCamelCase		( ):






						"""simple docstring"""







						return logging.getLogger(_get_library_name()				)

def 					UpperCamelCase		( ):






						"""simple docstring"""







						global _default_handler

						with _lock:
												if _default_handler:
																		# This library has already configured the library root logger.
																		return
												__magic_name__    :     Any     		=      logging.StreamHandler()  # Set sys.stderr as stream.
												__magic_name__    :     Union[str, Any]     		=      sys.stderr.flush

												# Apply our default configuration to the library root logger.
												__magic_name__    :     List[str]     		=      _get_library_root_logger()
												library_root_logger.addHandler(_default_handler				)
												library_root_logger.setLevel(_get_default_logging_level()				)
												__magic_name__    :     Union[str, Any]     		=      False

def 					UpperCamelCase		( ):






						"""simple docstring"""







						global _default_handler

						with _lock:
												if not _default_handler:
																		return

												__magic_name__    :     str     		=      _get_library_root_logger()
												library_root_logger.removeHandler(_default_handler				)
												library_root_logger.setLevel(logging.NOTSET				)
												__magic_name__    :     Optional[Any]     		=      None

def 					UpperCamelCase		( ):






						"""simple docstring"""







						return log_levels

def 					UpperCamelCase		( _A = None				):






						"""simple docstring"""







						if name is None:
												__magic_name__    :     Tuple     		=      _get_library_name()

						_configure_library_root_logger()
						return logging.getLogger(_A				)

def 					UpperCamelCase		( ):






						"""simple docstring"""







						_configure_library_root_logger()
						return _get_library_root_logger().getEffectiveLevel()

def 					UpperCamelCase		( _A				):






						"""simple docstring"""







						_configure_library_root_logger()
						_get_library_root_logger().setLevel(_A				)

def 					UpperCamelCase		( ):






						"""simple docstring"""







						return set_verbosity(_A				)

def 					UpperCamelCase		( ):






						"""simple docstring"""







						return set_verbosity(_A				)

def 					UpperCamelCase		( ):






						"""simple docstring"""







						return set_verbosity(_A				)

def 					UpperCamelCase		( ):






						"""simple docstring"""







						return set_verbosity(_A				)

def 					UpperCamelCase		( ):






						"""simple docstring"""







						_configure_library_root_logger()

						assert _default_handler is not None
						_get_library_root_logger().removeHandler(_default_handler				)

def 					UpperCamelCase		( ):






						"""simple docstring"""







						_configure_library_root_logger()

						assert _default_handler is not None
						_get_library_root_logger().addHandler(_default_handler				)

def 					UpperCamelCase		( _A				):






						"""simple docstring"""







						_configure_library_root_logger()

						assert handler is not None
						_get_library_root_logger().addHandler(_A				)

def 					UpperCamelCase		( _A				):






						"""simple docstring"""







						_configure_library_root_logger()

						assert handler is not None and handler not in _get_library_root_logger().handlers
						_get_library_root_logger().removeHandler(_A				)

def 					UpperCamelCase		( ):






						"""simple docstring"""







						_configure_library_root_logger()
						__magic_name__    :     Optional[int]     		=      False

def 					UpperCamelCase		( ):






						"""simple docstring"""







						_configure_library_root_logger()
						__magic_name__    :     str     		=      True

def 					UpperCamelCase		( ):






						"""simple docstring"""







						__magic_name__    :     List[Any]     		=      _get_library_root_logger().handlers

						for handler in handlers:
												__magic_name__    :     str     		=      logging.Formatter("""[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s"""				)
												handler.setFormatter(_A				)

def 					UpperCamelCase		( ):






						"""simple docstring"""







						__magic_name__    :     str     		=      _get_library_root_logger().handlers

						for handler in handlers:
												handler.setFormatter(_A				)

def 					UpperCamelCase		( self,					*_A,					**_A				):






						"""simple docstring"""







						__magic_name__    :     Optional[Any]     		=      os.getenv("""DIFFUSERS_NO_ADVISORY_WARNINGS""",					_A				)
						if no_advisory_warnings:
												return
						self.warning(*_A,					**_A				)


__magic_name__:  List[Any]  	=			warning_advice





class  snake_case__      :
	def __init__(       self    ,     *lowerCAmelCase__    ,     **lowerCAmelCase__				)							->   Dict:  # pylint: disable=unused-argument
							__magic_name__    :     List[Any]     		=      args[0] if args else None
	def __iter__(       self				)							->   List[Any]:
							return iter(self._iterator				)
	def __getattr__(       self    ,     lowerCAmelCase__				)							->   List[str]:

							def empty_fn(*lowerCAmelCase__    ,     **lowerCAmelCase__				):  # pylint: disable=unused-argument
													return

							return empty_fn
	def __enter__(       self				)							->   Any:
							return self







	def __exit__(       self    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__				)							->   Optional[Any]:
							return





class  snake_case__      :
	def __call__(       self    ,     *lowerCAmelCase__    ,     **lowerCAmelCase__				)							->   Any:
							if _tqdm_active:
													return tqdm_lib.tqdm(*lowerCAmelCase__    ,     **lowerCAmelCase__				)
							else:
													return EmptyTqdm(*lowerCAmelCase__    ,     **lowerCAmelCase__				)
	def     __magic_name__       (       self    ,     *lowerCAmelCase__    ,     **lowerCAmelCase__				)							->   int:
							__magic_name__    :     Optional[int]     		=      None
							if _tqdm_active:
													return tqdm_lib.tqdm.set_lock(*lowerCAmelCase__    ,     **lowerCAmelCase__				)







	def     __magic_name__       (       self				)							->   Optional[int]:
							if _tqdm_active:
													return tqdm_lib.tqdm.get_lock()



__magic_name__:  str  	=			_tqdm_cls()

def 					UpperCamelCase		( ):






						"""simple docstring"""







						global _tqdm_active
						return bool(_tqdm_active				)

def 					UpperCamelCase		( ):






						"""simple docstring"""







						global _tqdm_active
						__magic_name__    :     Union[str, Any]     		=      True

def 					UpperCamelCase		( ):






						"""simple docstring"""







						global _tqdm_active
						__magic_name__    :     Optional[int]     		=      False








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

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

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

							__magic_name__    :     int     		=      None
							if self.use_token_type_ids:
													__magic_name__    :     Optional[Any]     		=      ids_tensor([self.batch_size, self.seq_length]    ,     self.type_vocab_size				)

							__magic_name__    :     Tuple     		=      None
							__magic_name__    :     Optional[Any]     		=      None
							__magic_name__    :     Optional[int]     		=      None
							if self.use_labels:
													__magic_name__    :     Optional[int]     		=      ids_tensor([self.batch_size]    ,     self.type_sequence_label_size				)
													__magic_name__    :     Optional[int]     		=      ids_tensor([self.batch_size, self.seq_length]    ,     self.num_labels				)
													__magic_name__    :     Dict     		=      ids_tensor([self.batch_size]    ,     self.num_choices				)
													__magic_name__    :     Any     		=      ids_tensor([self.batch_size, self.seq_length]    ,     1				)

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

							return (
							    config,
							    input_ids,
							    token_type_ids,
							    input_mask,
							    sequence_labels,
							    token_labels,
							    choice_labels,
							    fake_token_labels,
							)
	def     __magic_name__       (       self				)							->   Optional[int]:
							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     __magic_name__       (       self    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     )							->   str:
							__magic_name__    :     Optional[int]     		=      FunnelModel(config=lowerCAmelCase__				)
							model.to(lowerCAmelCase__				)
							model.eval()
							__magic_name__    :     Optional[Any]     		=      model(lowerCAmelCase__    ,     attention_mask=lowerCAmelCase__    ,     token_type_ids=lowerCAmelCase__				)
							__magic_name__    :     str     		=      model(lowerCAmelCase__    ,     token_type_ids=lowerCAmelCase__				)
							__magic_name__    :     Dict     		=      model(lowerCAmelCase__				)
							self.parent.assertEqual(result.last_hidden_state.shape    ,     (self.batch_size, self.seq_length, self.d_model)				)

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

							__magic_name__    :     Optional[int]     		=      False
							__magic_name__    :     Dict     		=      model(lowerCAmelCase__				)
							self.parent.assertEqual(result.last_hidden_state.shape    ,     (self.batch_size, self.seq_length, self.d_model)				)
	def     __magic_name__       (       self    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     )							->   List[Any]:
							__magic_name__    :     List[str]     		=      FunnelBaseModel(config=lowerCAmelCase__				)
							model.to(lowerCAmelCase__				)
							model.eval()
							__magic_name__    :     Dict     		=      model(lowerCAmelCase__    ,     attention_mask=lowerCAmelCase__    ,     token_type_ids=lowerCAmelCase__				)
							__magic_name__    :     Optional[Any]     		=      model(lowerCAmelCase__    ,     token_type_ids=lowerCAmelCase__				)
							__magic_name__    :     List[str]     		=      model(lowerCAmelCase__				)
							self.parent.assertEqual(result.last_hidden_state.shape    ,     (self.batch_size, 2, self.d_model)				)

							__magic_name__    :     str     		=      False
							__magic_name__    :     Optional[int]     		=      model(lowerCAmelCase__				)
							self.parent.assertEqual(result.last_hidden_state.shape    ,     (self.batch_size, 3, self.d_model)				)

							__magic_name__    :     List[Any]     		=      False
							__magic_name__    :     Optional[int]     		=      model(lowerCAmelCase__				)
							self.parent.assertEqual(result.last_hidden_state.shape    ,     (self.batch_size, 2, self.d_model)				)
	def     __magic_name__       (       self    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     )							->   int:
							__magic_name__    :     Any     		=      self.num_labels
							__magic_name__    :     Tuple     		=      FunnelForPreTraining(config=lowerCAmelCase__				)
							model.to(lowerCAmelCase__				)
							model.eval()
							__magic_name__    :     Optional[int]     		=      model(lowerCAmelCase__    ,     attention_mask=lowerCAmelCase__    ,     token_type_ids=lowerCAmelCase__    ,     labels=lowerCAmelCase__				)
							self.parent.assertEqual(result.logits.shape    ,     (self.batch_size, self.seq_length)				)
	def     __magic_name__       (       self    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     )							->   List[str]:
							__magic_name__    :     int     		=      FunnelForMaskedLM(config=lowerCAmelCase__				)
							model.to(lowerCAmelCase__				)
							model.eval()
							__magic_name__    :     Dict     		=      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     __magic_name__       (       self    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     )							->   Any:
							__magic_name__    :     Tuple     		=      self.num_labels
							__magic_name__    :     str     		=      FunnelForSequenceClassification(lowerCAmelCase__				)
							model.to(lowerCAmelCase__				)
							model.eval()
							__magic_name__    :     int     		=      model(lowerCAmelCase__    ,     attention_mask=lowerCAmelCase__    ,     token_type_ids=lowerCAmelCase__    ,     labels=lowerCAmelCase__				)
							self.parent.assertEqual(result.logits.shape    ,     (self.batch_size, self.num_labels)				)
	def     __magic_name__       (       self    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     )							->   str:
							__magic_name__    :     str     		=      self.num_choices
							__magic_name__    :     int     		=      FunnelForMultipleChoice(config=lowerCAmelCase__				)
							model.to(lowerCAmelCase__				)
							model.eval()
							__magic_name__    :     Union[str, Any]     		=      input_ids.unsqueeze(1				).expand(-1    ,     self.num_choices    ,     -1				).contiguous()
							__magic_name__    :     List[Any]     		=      token_type_ids.unsqueeze(1				).expand(-1    ,     self.num_choices    ,     -1				).contiguous()
							__magic_name__    :     Optional[Any]     		=      input_mask.unsqueeze(1				).expand(-1    ,     self.num_choices    ,     -1				).contiguous()
							__magic_name__    :     Union[str, Any]     		=      model(
							    lowerCAmelCase__    ,     attention_mask=lowerCAmelCase__    ,     token_type_ids=lowerCAmelCase__    ,     labels=lowerCAmelCase__    ,     )
							self.parent.assertEqual(result.logits.shape    ,     (self.batch_size, self.num_choices)				)
	def     __magic_name__       (       self    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     )							->   Tuple:
							__magic_name__    :     Tuple     		=      self.num_labels
							__magic_name__    :     int     		=      FunnelForTokenClassification(config=lowerCAmelCase__				)
							model.to(lowerCAmelCase__				)
							model.eval()
							__magic_name__    :     Union[str, Any]     		=      model(lowerCAmelCase__    ,     attention_mask=lowerCAmelCase__    ,     token_type_ids=lowerCAmelCase__    ,     labels=lowerCAmelCase__				)
							self.parent.assertEqual(result.logits.shape    ,     (self.batch_size, self.seq_length, self.num_labels)				)
	def     __magic_name__       (       self    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     )							->   Optional[int]:
							__magic_name__    :     Union[str, Any]     		=      FunnelForQuestionAnswering(config=lowerCAmelCase__				)
							model.to(lowerCAmelCase__				)
							model.eval()
							__magic_name__    :     Optional[int]     		=      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     __magic_name__       (       self				)							->   List[Any]:
							__magic_name__    :     Tuple     		=      self.prepare_config_and_inputs()
							(
							    (
							    __magic_name__
							)		,(
							    __magic_name__
							)		,(
							    __magic_name__
							)		,(
							    __magic_name__
							)		,(
							    __magic_name__
							)		,(
							    __magic_name__
							)		,(
							    __magic_name__
							)		,(
							    __magic_name__
							)		,
							)    :     str     		=      config_and_inputs
							__magic_name__    :     Optional[Any]     		=      {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
							return config, inputs_dict





@require_torch
class  snake_case__      (							_lowerCAmelCase		,						_lowerCAmelCase		,						unittest.TestCase   ):
	lowercase__		:  Optional[int]							   =					False
	lowercase__		:  Dict							   =					False
	lowercase__		:  int							   =					(
	    (
	        FunnelModel,
	        FunnelForMaskedLM,
	        FunnelForPreTraining,
	        FunnelForQuestionAnswering,
	        FunnelForTokenClassification,
	    )
	    if is_torch_available()
	    else ()
	)
	lowercase__		:  Optional[int]							   =					(
	    {
	        '''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     __magic_name__       (       self    ,     lowerCAmelCase__    ,     lowerCAmelCase__    ,     lowerCAmelCase__=False				)							->   Any:
							__magic_name__    :     Union[str, Any]     		=      super()._prepare_for_class(lowerCAmelCase__    ,     lowerCAmelCase__    ,     return_labels=lowerCAmelCase__				)

							if return_labels:
													if model_class in get_values(lowerCAmelCase__				):
																			__magic_name__    :     List[Any]     		=      torch.zeros(
																			    (self.model_tester.batch_size, self.model_tester.seq_length)    ,     dtype=torch.long    ,     device=lowerCAmelCase__				)
							return inputs_dict
	def     __magic_name__       (       self				)							->   Optional[Any]:
							__magic_name__    :     Any     		=      FunnelModelTester(self				)
							__magic_name__    :     Union[str, Any]     		=      ConfigTester(self    ,     config_class=lowerCAmelCase__				)
	def     __magic_name__       (       self				)							->   List[Any]:
							self.config_tester.run_common_tests()
	def     __magic_name__       (       self				)							->   Any:
							__magic_name__    :     Optional[Any]     		=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*lowerCAmelCase__				)
	def     __magic_name__       (       self				)							->   Any:
							__magic_name__    :     Optional[Any]     		=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_pretraining(*lowerCAmelCase__				)
	def     __magic_name__       (       self				)							->   Tuple:
							__magic_name__    :     Optional[int]     		=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*lowerCAmelCase__				)
	def     __magic_name__       (       self				)							->   Tuple:
							__magic_name__    :     Tuple     		=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase__				)
	def     __magic_name__       (       self				)							->   Union[str, Any]:
							__magic_name__    :     int     		=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase__				)







	def     __magic_name__       (       self    ,     lowerCAmelCase__				)							->   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:
																			__magic_name__    :     Optional[int]     		=      getattr(lowerCAmelCase__    ,     lowerCAmelCase__				)
																			weight.data.fill_(3				)





@require_torch
class  snake_case__      (							_lowerCAmelCase		,						unittest.TestCase   ):
	lowercase__		:  Tuple							   =					False
	lowercase__		:  int							   =					False
	lowercase__		:  Optional[int]							   =					(
	    (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
	)
	def     __magic_name__       (       self				)							->   Optional[Any]:
							__magic_name__    :     str     		=      FunnelModelTester(self    ,     base=lowerCAmelCase__				)
							__magic_name__    :     Tuple     		=      ConfigTester(self    ,     config_class=lowerCAmelCase__				)
	def     __magic_name__       (       self				)							->   str:
							self.config_tester.run_common_tests()
	def     __magic_name__       (       self				)							->   Optional[int]:
							__magic_name__    :     List[str]     		=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_base_model(*lowerCAmelCase__				)
	def     __magic_name__       (       self				)							->   str:
							__magic_name__    :     Any     		=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase__				)
	def     __magic_name__       (       self				)							->   Tuple:
							__magic_name__    :     Any     		=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_multiple_choice(*lowerCAmelCase__				)
	def     __magic_name__       (       self				)							->   List[str]:
							__magic_name__		,__magic_name__    :     Tuple     		=      self.model_tester.prepare_config_and_inputs_for_common()
							__magic_name__    :     int     		=      True

							for model_class in self.all_model_classes:
													if model_class.__name__ == "FunnelBaseModel":
																			continue
													__magic_name__    :     Tuple     		=      model_class(lowerCAmelCase__				)
													model.to(lowerCAmelCase__				)
													model.train()
													__magic_name__    :     Tuple     		=      self._prepare_for_class(lowerCAmelCase__    ,     lowerCAmelCase__    ,     return_labels=lowerCAmelCase__				)
													__magic_name__    :     Dict     		=      model(**lowerCAmelCase__				).loss
													loss.backward()







	def     __magic_name__       (       self    ,     lowerCAmelCase__				)							->   Optional[int]:
							if hasattr(lowerCAmelCase__    ,     """weight"""				) and module.weight is not None:
													module.weight.data.fill_(3				)
							if hasattr(lowerCAmelCase__    ,     """bias"""				) and module.bias is not None:
													module.bias.data.fill_(3				)

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





@require_torch
@require_sentencepiece
@require_tokenizers
class  snake_case__      (							unittest.TestCase   ):
	def     __magic_name__       (       self				)							->   List[Any]:
							__magic_name__    :     Union[str, Any]     		=      13
							__magic_name__    :     str     		=      7
							__magic_name__    :     Optional[int]     		=      torch.arange(0    ,     batch_size * sequence_length				).long().reshape(lowerCAmelCase__    ,     lowerCAmelCase__				)
							__magic_name__    :     str     		=      [0, 1, 2, 3, 4, 5, 6, 4, 1, 3, 5, 0, 1]
							__magic_name__    :     List[Any]     		=      torch.tensor([[2] + [0] * a + [1] * (sequence_length - a - 1) for a in lengths]				)

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

							__magic_name__    :     Tuple     		=      torch.tensor(2_3_4_4.8_3_5_2				)
							__magic_name__    :     Optional[Any]     		=      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				)				)

							__magic_name__    :     int     		=      torch.tensor([[1] * 7, [1] * 4 + [0] * 3] * 6 + [[0, 1, 1, 0, 0, 1, 1]]				)
							__magic_name__    :     Tuple     		=      model(lowerCAmelCase__    ,     attention_mask=lowerCAmelCase__    ,     token_type_ids=lowerCAmelCase__				)[0].abs()

							__magic_name__    :     List[Any]     		=      torch.tensor(2_3_4_3.8_4_2_5				)
							__magic_name__    :     Dict     		=      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     __magic_name__       (       self				)							->   List[Any]:
							__magic_name__    :     Tuple     		=      FunnelTokenizer.from_pretrained("""huggingface/funnel-small"""				)
							__magic_name__    :     Union[str, Any]     		=      FunnelModel.from_pretrained("""huggingface/funnel-small"""				)
							__magic_name__    :     str     		=      tokenizer("""Hello! I am the Funnel Transformer model."""    ,     return_tensors="""pt"""				)
							__magic_name__    :     Optional[Any]     		=      model(**lowerCAmelCase__				)[0]

							__magic_name__    :     List[Any]     		=      torch.tensor(2_3_5.7_2_4_6				)
							__magic_name__    :     List[Any]     		=      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				)				)
