




"""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       __lowercase       :


				'''simple docstring'''


				def __init__(   self   :     List[Any]      ,SCREAMING_SNAKE_CASE_   :     str      ,SCREAMING_SNAKE_CASE_   :     Optional[Any]=1_3      ,SCREAMING_SNAKE_CASE_   :     Union[str, Any]=7      ,SCREAMING_SNAKE_CASE_   :     Any=True      ,SCREAMING_SNAKE_CASE_   :     Union[str, Any]=True      ,SCREAMING_SNAKE_CASE_   :     Tuple=True      ,SCREAMING_SNAKE_CASE_   :     List[Any]=True      ,SCREAMING_SNAKE_CASE_   :     int=9_9      ,SCREAMING_SNAKE_CASE_   :     List[Any]=[1, 1, 2]      ,SCREAMING_SNAKE_CASE_   :     int=1      ,SCREAMING_SNAKE_CASE_   :     Tuple=3_2      ,SCREAMING_SNAKE_CASE_   :     int=4      ,SCREAMING_SNAKE_CASE_   :     Tuple=8      ,SCREAMING_SNAKE_CASE_   :     int=3_7      ,SCREAMING_SNAKE_CASE_   :     List[Any]="gelu_new"      ,SCREAMING_SNAKE_CASE_   :     List[Any]=0.1      ,SCREAMING_SNAKE_CASE_   :     Optional[Any]=0.1      ,SCREAMING_SNAKE_CASE_   :     Optional[Any]=0.0      ,SCREAMING_SNAKE_CASE_   :     int=5_1_2      ,SCREAMING_SNAKE_CASE_   :     Optional[int]=3      ,SCREAMING_SNAKE_CASE_   :     Any=0.02      ,SCREAMING_SNAKE_CASE_   :     Optional[int]=3      ,SCREAMING_SNAKE_CASE_   :     Tuple=4      ,SCREAMING_SNAKE_CASE_   :     List[str]=None      ,SCREAMING_SNAKE_CASE_   :     Dict=False      ,):
										snake_case__       :					Optional[int]										=					parent
										snake_case__       :					Tuple										=					batch_size
										snake_case__       :					List[Any]										=					seq_length
										snake_case__       :					Union[str, Any]										=					is_training
										snake_case__       :					Union[str, Any]										=					use_input_mask
										snake_case__       :					Any										=					use_token_type_ids
										snake_case__       :					int										=					use_labels
										snake_case__       :					Union[str, Any]										=					vocab_size
										snake_case__       :					List[str]										=					block_sizes
										snake_case__       :					Union[str, Any]										=					num_decoder_layers
										snake_case__       :					Dict										=					d_model
										snake_case__       :					str										=					n_head
										snake_case__       :					Any										=					d_head
										snake_case__       :					Dict										=					d_inner
										snake_case__       :					Dict										=					hidden_act
										snake_case__       :					List[Any]										=					hidden_dropout
										snake_case__       :					List[Any]										=					attention_dropout
										snake_case__       :					Dict										=					activation_dropout
										snake_case__       :					Optional[Any]										=					max_position_embeddings
										snake_case__       :					Tuple										=					type_vocab_size
										snake_case__       :					Any										=					2
										snake_case__       :					Any										=					num_labels
										snake_case__       :					Union[str, Any]										=					num_choices
										snake_case__       :					str										=					scope
										snake_case__       :					List[Any]										=					initializer_std

										# Used in the tests to check the size of the first attention layer
										snake_case__       :					int										=					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__       :					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:
																snake_case__       :					Optional[Any]										=					self.num_hidden_layers + 2

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

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

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

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

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

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

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

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

										snake_case__       :					Dict										=					False
										snake_case__       :					Union[str, Any]										=					model(SCREAMING_SNAKE_CASE_      )
										self.parent.assertEqual(result.last_hidden_state.shape      ,(self.batch_size, 3, self.d_model)      )

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

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

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

				def       _lowerCamelCase					(   self   :     Optional[Any]      ,SCREAMING_SNAKE_CASE_   :     Tuple      ,SCREAMING_SNAKE_CASE_   :     List[Any]      ,SCREAMING_SNAKE_CASE_   :     Optional[int]      ,SCREAMING_SNAKE_CASE_   :     int      ,SCREAMING_SNAKE_CASE_   :     List[str]      ,SCREAMING_SNAKE_CASE_   :     Optional[Any]      ,SCREAMING_SNAKE_CASE_   :     Dict      ,SCREAMING_SNAKE_CASE_   :     List[Any]      ,):
										snake_case__       :					List[str]										=					self.num_labels
										snake_case__       :					Optional[int]										=					FunnelForSequenceClassification(SCREAMING_SNAKE_CASE_      )
										model.to(SCREAMING_SNAKE_CASE_      )
										model.eval()
										snake_case__       :					Union[str, Any]										=					model(SCREAMING_SNAKE_CASE_      ,attention_mask=SCREAMING_SNAKE_CASE_      ,token_type_ids=SCREAMING_SNAKE_CASE_      ,labels=SCREAMING_SNAKE_CASE_      )
										self.parent.assertEqual(result.logits.shape      ,(self.batch_size, self.num_labels)      )

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

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

				def       _lowerCamelCase					(   self   :     List[str]      ,SCREAMING_SNAKE_CASE_   :     List[Any]      ,SCREAMING_SNAKE_CASE_   :     List[Any]      ,SCREAMING_SNAKE_CASE_   :     List[str]      ,SCREAMING_SNAKE_CASE_   :     List[Any]      ,SCREAMING_SNAKE_CASE_   :     str      ,SCREAMING_SNAKE_CASE_   :     Dict      ,SCREAMING_SNAKE_CASE_   :     Tuple      ,SCREAMING_SNAKE_CASE_   :     Any      ,):
										snake_case__       :					List[Any]										=					FunnelForQuestionAnswering(config=SCREAMING_SNAKE_CASE_      )
										model.to(SCREAMING_SNAKE_CASE_      )
										model.eval()
										snake_case__       :					str										=					model(
										    SCREAMING_SNAKE_CASE_      ,attention_mask=SCREAMING_SNAKE_CASE_      ,token_type_ids=SCREAMING_SNAKE_CASE_      ,start_positions=SCREAMING_SNAKE_CASE_      ,end_positions=SCREAMING_SNAKE_CASE_      ,)
										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   :     Optional[int]      ):
										snake_case__       :					Optional[int]										=					self.prepare_config_and_inputs()
										(
										    snake_case__	
										)       :					Optional[int]										=					config_and_inputs
										snake_case__       :					int										=					{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
										return config, inputs_dict







@require_torch
class       __lowercase       (			snake_case_						,   snake_case_						,   unittest.TestCase	):


				'''simple docstring'''


				_lowerCAmelCase				=False
				_lowerCAmelCase				=False
				_lowerCAmelCase				=(
				    (
				        FunnelModel,
				        FunnelForMaskedLM,
				        FunnelForPreTraining,
				        FunnelForQuestionAnswering,
				        FunnelForTokenClassification,
				    )
				    if is_torch_available()
				    else ()
				)
				_lowerCAmelCase				=(
				    {
				        "feature-extraction": (FunnelBaseModel, FunnelModel),
				        "fill-mask": FunnelForMaskedLM,
				        "question-answering": FunnelForQuestionAnswering,
				        "text-classification": FunnelForSequenceClassification,
				        "token-classification": FunnelForTokenClassification,
				        "zero-shot": FunnelForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)

				def       _lowerCamelCase					(   self   :     str      ,SCREAMING_SNAKE_CASE_   :     Optional[Any]      ,SCREAMING_SNAKE_CASE_   :     Dict      ,SCREAMING_SNAKE_CASE_   :     int=False      ):
										snake_case__       :					List[Any]										=					super()._prepare_for_class(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_      ,return_labels=SCREAMING_SNAKE_CASE_      )

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

				def       _lowerCamelCase					(   self   :     str      ):
										snake_case__       :					Any										=					FunnelModelTester(self      )
										snake_case__       :					Union[str, Any]										=					ConfigTester(self      ,config_class=SCREAMING_SNAKE_CASE_      )

				def       _lowerCamelCase					(   self   :     Optional[Any]      ):
										self.config_tester.run_common_tests()

				def       _lowerCamelCase					(   self   :     Optional[Any]      ):
										snake_case__       :					Optional[Any]										=					self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_      )

				def       _lowerCamelCase					(   self   :     Dict      ):
										snake_case__       :					Dict										=					self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_pretraining(*SCREAMING_SNAKE_CASE_      )

				def       _lowerCamelCase					(   self   :     List[str]      ):
										snake_case__       :					Optional[Any]										=					self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE_      )

				def       _lowerCamelCase					(   self   :     List[Any]      ):
										snake_case__       :					Optional[Any]										=					self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE_      )

				def       _lowerCamelCase					(   self   :     Any      ):
										snake_case__       :					Optional[int]										=					self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE_      )





				def       _lowerCamelCase					(   self   :     List[str]      ,SCREAMING_SNAKE_CASE_   :     int      ):
										if hasattr(SCREAMING_SNAKE_CASE_      ,'''weight'''      ) and module.weight is not None:
																module.weight.data.fill_(3      )
										if hasattr(SCREAMING_SNAKE_CASE_      ,'''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(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_      ) and getattr(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_      ) is not None:
																						snake_case__       :					Dict										=					getattr(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_      )
																						weight.data.fill_(3      )







@require_torch
class       __lowercase       (			snake_case_						,   unittest.TestCase	):


				'''simple docstring'''


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

				def       _lowerCamelCase					(   self   :     Tuple      ):
										snake_case__       :					Optional[int]										=					FunnelModelTester(self      ,base=SCREAMING_SNAKE_CASE_      )
										snake_case__       :					List[Any]										=					ConfigTester(self      ,config_class=SCREAMING_SNAKE_CASE_      )

				def       _lowerCamelCase					(   self   :     List[Any]      ):
										self.config_tester.run_common_tests()

				def       _lowerCamelCase					(   self   :     Dict      ):
										snake_case__       :					List[Any]										=					self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_base_model(*SCREAMING_SNAKE_CASE_      )

				def       _lowerCamelCase					(   self   :     List[Any]      ):
										snake_case__       :					int										=					self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_sequence_classification(*SCREAMING_SNAKE_CASE_      )

				def       _lowerCamelCase					(   self   :     Any      ):
										snake_case__       :					Union[str, Any]										=					self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_multiple_choice(*SCREAMING_SNAKE_CASE_      )

				def       _lowerCamelCase					(   self   :     List[str]      ):
										snake_case__       :					List[str]										=					self.model_tester.prepare_config_and_inputs_for_common()
										snake_case__       :					Union[str, Any]										=					True

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





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







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


				'''simple docstring'''


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

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

										snake_case__       :					List[str]										=					torch.tensor(2344.8352      )
										snake_case__       :					Tuple										=					torch.tensor(0.8052      )
										self.assertTrue(torch.allclose(output.sum()      ,SCREAMING_SNAKE_CASE_      ,atol=1E-4      )      )
										self.assertTrue(torch.allclose(output.mean()      ,SCREAMING_SNAKE_CASE_      ,atol=1E-4      )      )

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

										snake_case__       :					List[Any]										=					torch.tensor(2343.8425      )
										snake_case__       :					Optional[int]										=					torch.tensor(0.8049      )
										self.assertTrue(torch.allclose(output.sum()      ,SCREAMING_SNAKE_CASE_      ,atol=1E-4      )      )
										self.assertTrue(torch.allclose(output.mean()      ,SCREAMING_SNAKE_CASE_      ,atol=1E-4      )      )





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

										snake_case__       :					Any										=					torch.tensor(235.7246      )
										snake_case__       :					int										=					torch.tensor(0.0256      )
										self.assertTrue(torch.allclose(output.sum()      ,SCREAMING_SNAKE_CASE_      ,atol=1E-4      )      )
										self.assertTrue(torch.allclose(output.mean()      ,SCREAMING_SNAKE_CASE_      ,atol=1E-4      )      )








"""simple docstring"""





from __future__ import annotations

def 		lowerCAmelCase							( lowerCamelCase      ,			lowerCamelCase      ,			lowerCamelCase      ,			):
						'''simple docstring'''


						if not all((nth_term, start_term_a, common_ratio_r)		):
												return []
						snake_case__       :					list[float | int]										=					[]
						snake_case__       :					List[str]										=					1
						snake_case__       :					Dict										=					common_ratio_r
						for _ in range(int(lowerCamelCase		)		):
												if not series:
																		series.append(lowerCamelCase		)
												else:
																		power += 1
																		series.append(float(start_term_a * multiple		)		)
																		snake_case__       :					Tuple										=					pow(float(lowerCamelCase		)      ,			lowerCamelCase		)
						return series


if __name__ == "__main__":
							import doctest

							doctest.testmod()

							_lowercase	      =    float(input("""Enter the last number (n term) of the Geometric Series"""))
							_lowercase	      =    float(input("""Enter the starting term (a) of the Geometric Series"""))
							_lowercase	      =    float(
							    input("""Enter the common ratio between two terms (r) of the Geometric Series""")
							)
							print("""Formula of Geometric Series => a + ar + ar^2 ... +ar^n""")
							print(geometric_series(nth_term, start_term_a, common_ratio_r))


