



'''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 	_lowerCAmelCase     :






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







									'''simple docstring'''





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

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







									'''simple docstring'''





									_lowercase							:		Tuple				=   ids_tensor([self.batch_size, self.seq_length]      ,		self.vocab_size		)

									_lowercase							:		List[Any]				=   None
									if self.use_input_mask:
																_lowercase							:		Union[str, Any]				=   ids_tensor([self.batch_size, self.seq_length]      ,		vocab_size=2		)

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

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

									_lowercase							:		Optional[int]				=   self.get_config()

									return (
									    config,
									    input_ids,
									    token_type_ids,
									    input_mask,
									    sequence_labels,
									    token_labels,
									    choice_labels,
									    fake_token_labels,
									)
		def 						__lowercase      (						self							:       int		)      ->			Optional[int]:







									'''simple docstring'''





									return FunnelConfig(
									    vocab_size=self.vocab_size      ,		block_sizes=self.block_sizes      ,		num_decoder_layers=self.num_decoder_layers      ,		d_model=self.d_model      ,		n_head=self.n_head      ,		d_head=self.d_head      ,		d_inner=self.d_inner      ,		hidden_act=self.hidden_act      ,		hidden_dropout=self.hidden_dropout      ,		attention_dropout=self.attention_dropout      ,		activation_dropout=self.activation_dropout      ,		max_position_embeddings=self.max_position_embeddings      ,		type_vocab_size=self.type_vocab_size      ,		initializer_std=self.initializer_std      ,		)
		def 						__lowercase      (						self							:       int      ,		UpperCamelCase_							:       str      ,		UpperCamelCase_							:       Dict      ,		UpperCamelCase_							:       Any      ,		UpperCamelCase_							:       List[str]      ,		UpperCamelCase_							:       Tuple      ,		UpperCamelCase_							:       int      ,		UpperCamelCase_							:       Any      ,		UpperCamelCase_							:       Any      ,		)      ->			int:







									'''simple docstring'''





									_lowercase							:		Optional[int]				=   FunnelModel(config=_UpperCAmelCase		)
									model.to(_UpperCAmelCase		)
									model.eval()
									_lowercase							:		Optional[int]				=   model(_UpperCAmelCase      ,		attention_mask=_UpperCAmelCase      ,		token_type_ids=_UpperCAmelCase		)
									_lowercase							:		int				=   model(_UpperCAmelCase      ,		token_type_ids=_UpperCAmelCase		)
									_lowercase							:		int				=   model(_UpperCAmelCase		)
									self.parent.assertEqual(result.last_hidden_state.shape      ,		(self.batch_size, self.seq_length, self.d_model)		)

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

									_lowercase							:		Any				=   False
									_lowercase							:		List[str]				=   model(_UpperCAmelCase		)
									self.parent.assertEqual(result.last_hidden_state.shape      ,		(self.batch_size, self.seq_length, self.d_model)		)
		def 						__lowercase      (						self							:       int      ,		UpperCamelCase_							:       str      ,		UpperCamelCase_							:       int      ,		UpperCamelCase_							:       List[str]      ,		UpperCamelCase_							:       Union[str, Any]      ,		UpperCamelCase_							:       Any      ,		UpperCamelCase_							:       Optional[int]      ,		UpperCamelCase_							:       Tuple      ,		UpperCamelCase_							:       str      ,		)      ->			Dict:







									'''simple docstring'''





									_lowercase							:		List[str]				=   FunnelBaseModel(config=_UpperCAmelCase		)
									model.to(_UpperCAmelCase		)
									model.eval()
									_lowercase							:		int				=   model(_UpperCAmelCase      ,		attention_mask=_UpperCAmelCase      ,		token_type_ids=_UpperCAmelCase		)
									_lowercase							:		Tuple				=   model(_UpperCAmelCase      ,		token_type_ids=_UpperCAmelCase		)
									_lowercase							:		Optional[Any]				=   model(_UpperCAmelCase		)
									self.parent.assertEqual(result.last_hidden_state.shape      ,		(self.batch_size, 2, self.d_model)		)

									_lowercase							:		Dict				=   False
									_lowercase							:		Optional[Any]				=   model(_UpperCAmelCase		)
									self.parent.assertEqual(result.last_hidden_state.shape      ,		(self.batch_size, 3, self.d_model)		)

									_lowercase							:		Any				=   False
									_lowercase							:		Tuple				=   model(_UpperCAmelCase		)
									self.parent.assertEqual(result.last_hidden_state.shape      ,		(self.batch_size, 2, self.d_model)		)
		def 						__lowercase      (						self							:       int      ,		UpperCamelCase_							:       Tuple      ,		UpperCamelCase_							:       Tuple      ,		UpperCamelCase_							:       Dict      ,		UpperCamelCase_							:       Optional[Any]      ,		UpperCamelCase_							:       Optional[int]      ,		UpperCamelCase_							:       Any      ,		UpperCamelCase_							:       List[str]      ,		UpperCamelCase_							:       int      ,		)      ->			Dict:







									'''simple docstring'''





									_lowercase							:		Any				=   self.num_labels
									_lowercase							:		Optional[Any]				=   FunnelForPreTraining(config=_UpperCAmelCase		)
									model.to(_UpperCAmelCase		)
									model.eval()
									_lowercase							:		List[Any]				=   model(_UpperCAmelCase      ,		attention_mask=_UpperCAmelCase      ,		token_type_ids=_UpperCAmelCase      ,		labels=_UpperCAmelCase		)
									self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.seq_length)		)
		def 						__lowercase      (						self							:       str      ,		UpperCamelCase_							:       int      ,		UpperCamelCase_							:       int      ,		UpperCamelCase_							:       Union[str, Any]      ,		UpperCamelCase_							:       List[str]      ,		UpperCamelCase_							:       int      ,		UpperCamelCase_							:       Tuple      ,		UpperCamelCase_							:       int      ,		UpperCamelCase_							:       Optional[Any]      ,		)      ->			List[Any]:







									'''simple docstring'''





									_lowercase							:		Any				=   FunnelForMaskedLM(config=_UpperCAmelCase		)
									model.to(_UpperCAmelCase		)
									model.eval()
									_lowercase							:		Union[str, Any]				=   model(_UpperCAmelCase      ,		attention_mask=_UpperCAmelCase      ,		token_type_ids=_UpperCAmelCase      ,		labels=_UpperCAmelCase		)
									self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.seq_length, self.vocab_size)		)
		def 						__lowercase      (						self							:       Optional[int]      ,		UpperCamelCase_							:       str      ,		UpperCamelCase_							:       Tuple      ,		UpperCamelCase_							:       Optional[int]      ,		UpperCamelCase_							:       Optional[int]      ,		UpperCamelCase_							:       Tuple      ,		UpperCamelCase_							:       Optional[int]      ,		UpperCamelCase_							:       Any      ,		UpperCamelCase_							:       str      ,		)      ->			Dict:







									'''simple docstring'''





									_lowercase							:		List[str]				=   self.num_labels
									_lowercase							:		Any				=   FunnelForSequenceClassification(_UpperCAmelCase		)
									model.to(_UpperCAmelCase		)
									model.eval()
									_lowercase							:		Optional[Any]				=   model(_UpperCAmelCase      ,		attention_mask=_UpperCAmelCase      ,		token_type_ids=_UpperCAmelCase      ,		labels=_UpperCAmelCase		)
									self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.num_labels)		)
		def 						__lowercase      (						self							:       Dict      ,		UpperCamelCase_							:       Dict      ,		UpperCamelCase_							:       Any      ,		UpperCamelCase_							:       int      ,		UpperCamelCase_							:       Any      ,		UpperCamelCase_							:       List[str]      ,		UpperCamelCase_							:       Any      ,		UpperCamelCase_							:       int      ,		UpperCamelCase_							:       str      ,		)      ->			Any:







									'''simple docstring'''





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







									'''simple docstring'''





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







									'''simple docstring'''





									_lowercase							:		Optional[int]				=   FunnelForQuestionAnswering(config=_UpperCAmelCase		)
									model.to(_UpperCAmelCase		)
									model.eval()
									_lowercase							:		Union[str, Any]				=   model(
									    _UpperCAmelCase      ,		attention_mask=_UpperCAmelCase      ,		token_type_ids=_UpperCAmelCase      ,		start_positions=_UpperCAmelCase      ,		end_positions=_UpperCAmelCase      ,		)
									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 						__lowercase      (						self							:       List[Any]		)      ->			str:







									'''simple docstring'''





									_lowercase							:		Dict				=   self.prepare_config_and_inputs()
									(
									    _lowercase			
									)							:		str				=   config_and_inputs
									_lowercase							:		str				=   {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
									return config, inputs_dict




@require_torch
class 	_lowerCAmelCase     (    _lowerCAmelCase     ,		_lowerCAmelCase     ,		unittest.TestCase       ):






		'''simple docstring'''
		snake_case_							= False
		snake_case_							= False
		snake_case_							= (
		    (
		        FunnelModel,
		        FunnelForMaskedLM,
		        FunnelForPreTraining,
		        FunnelForQuestionAnswering,
		        FunnelForTokenClassification,
		    )
		    if is_torch_available()
		    else ()
		)
		snake_case_							= (
		    {
		        '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 						__lowercase      (						self							:       Union[str, Any]      ,		UpperCamelCase_							:       str      ,		UpperCamelCase_							:       str      ,		UpperCamelCase_							:       Optional[int]=False		)      ->			Optional[int]:







									'''simple docstring'''





									_lowercase							:		str				=   super()._prepare_for_class(_UpperCAmelCase      ,		_UpperCAmelCase      ,		return_labels=_UpperCAmelCase		)

									if return_labels:
																if model_class in get_values(_UpperCAmelCase		):
																							_lowercase							:		List[Any]				=   torch.zeros(
																							    (self.model_tester.batch_size, self.model_tester.seq_length)      ,		dtype=torch.long      ,		device=_UpperCAmelCase		)
									return inputs_dict
		def 						__lowercase      (						self							:       Union[str, Any]		)      ->			Union[str, Any]:







									'''simple docstring'''





									_lowercase							:		List[Any]				=   FunnelModelTester(self		)
									_lowercase							:		int				=   ConfigTester(self      ,		config_class=_UpperCAmelCase		)
		def 						__lowercase      (						self							:       List[str]		)      ->			Dict:







									'''simple docstring'''





									self.config_tester.run_common_tests()
		def 						__lowercase      (						self							:       Optional[Any]		)      ->			Tuple:







									'''simple docstring'''





									_lowercase							:		List[str]				=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_UpperCAmelCase		)
		def 						__lowercase      (						self							:       str		)      ->			Optional[int]:







									'''simple docstring'''





									_lowercase							:		Tuple				=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_pretraining(*_UpperCAmelCase		)
		def 						__lowercase      (						self							:       str		)      ->			Optional[Any]:







									'''simple docstring'''





									_lowercase							:		Optional[Any]				=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_lm(*_UpperCAmelCase		)
		def 						__lowercase      (						self							:       str		)      ->			Optional[int]:







									'''simple docstring'''





									_lowercase							:		Optional[Any]				=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_token_classification(*_UpperCAmelCase		)
		def 						__lowercase      (						self							:       Dict		)      ->			Union[str, Any]:







									'''simple docstring'''





									_lowercase							:		str				=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*_UpperCAmelCase		)





		def 						__lowercase      (						self							:       int      ,		UpperCamelCase_							:       Dict		)      ->			Any:







									'''simple docstring'''





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




@require_torch
class 	_lowerCAmelCase     (    _lowerCAmelCase     ,		unittest.TestCase       ):






		'''simple docstring'''
		snake_case_							= False
		snake_case_							= False
		snake_case_							= (
		    (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
		)
		def 						__lowercase      (						self							:       str		)      ->			Optional[int]:







									'''simple docstring'''





									_lowercase							:		int				=   FunnelModelTester(self      ,		base=_UpperCAmelCase		)
									_lowercase							:		str				=   ConfigTester(self      ,		config_class=_UpperCAmelCase		)
		def 						__lowercase      (						self							:       List[Any]		)      ->			Optional[int]:







									'''simple docstring'''





									self.config_tester.run_common_tests()
		def 						__lowercase      (						self							:       Any		)      ->			Optional[Any]:







									'''simple docstring'''





									_lowercase							:		Dict				=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_base_model(*_UpperCAmelCase		)
		def 						__lowercase      (						self							:       Dict		)      ->			List[str]:







									'''simple docstring'''





									_lowercase							:		Union[str, Any]				=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*_UpperCAmelCase		)
		def 						__lowercase      (						self							:       str		)      ->			Optional[Any]:







									'''simple docstring'''





									_lowercase							:		Dict				=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_multiple_choice(*_UpperCAmelCase		)
		def 						__lowercase      (						self							:       Any		)      ->			Tuple:







									'''simple docstring'''





									_lowercase							:		Dict				=   self.model_tester.prepare_config_and_inputs_for_common()
									_lowercase							:		Optional[Any]				=   True

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





		def 						__lowercase      (						self							:       Union[str, Any]      ,		UpperCamelCase_							:       Optional[int]		)      ->			Optional[int]:







									'''simple docstring'''





									if hasattr(_UpperCAmelCase      ,		'''weight'''		) and module.weight is not None:
																module.weight.data.fill_(3		)
									if hasattr(_UpperCAmelCase      ,		'''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(_UpperCAmelCase      ,		_UpperCAmelCase		) and getattr(_UpperCAmelCase      ,		_UpperCAmelCase		) is not None:
																							_lowercase							:		str				=   getattr(_UpperCAmelCase      ,		_UpperCAmelCase		)
																							weight.data.fill_(3		)




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






		'''simple docstring'''
		def 						__lowercase      (						self							:       Tuple		)      ->			Union[str, Any]:







									'''simple docstring'''





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

									_lowercase							:		Optional[Any]				=   FunnelModel.from_pretrained('''sgugger/funnel-random-tiny'''		)
									_lowercase							:		Optional[Any]				=   model(_UpperCAmelCase      ,		token_type_ids=_UpperCAmelCase		)[0].abs()

									_lowercase							:		int				=   torch.tensor(2_344.8_352		)
									_lowercase							:		Any				=   torch.tensor(0.8_052		)
									self.assertTrue(torch.allclose(output.sum()      ,		_UpperCAmelCase      ,		atol=1e-4		)		)
									self.assertTrue(torch.allclose(output.mean()      ,		_UpperCAmelCase      ,		atol=1e-4		)		)

									_lowercase							:		Optional[Any]				=   torch.tensor([[1] * 7, [1] * 4 + [0] * 3] * 6 + [[0, 1, 1, 0, 0, 1, 1]]		)
									_lowercase							:		str				=   model(_UpperCAmelCase      ,		attention_mask=_UpperCAmelCase      ,		token_type_ids=_UpperCAmelCase		)[0].abs()

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





		@slow
		def 						__lowercase      (						self							:       Optional[int]		)      ->			List[str]:







									'''simple docstring'''





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

									_lowercase							:		Optional[int]				=   torch.tensor(235.7_246		)
									_lowercase							:		List[str]				=   torch.tensor(0.0_256		)
									self.assertTrue(torch.allclose(output.sum()      ,		_UpperCAmelCase      ,		atol=1e-4		)		)
									self.assertTrue(torch.allclose(output.mean()      ,		_UpperCAmelCase      ,		atol=1e-4		)		)






from __future__ import annotations





def  _snake_case		(snake_case_					:     int  )							->		int | None:
  for r in range(1    ,       snake_case_  ):
    __UpperCAmelCase	:  List[str]		=     []
    for x in range(n - 1  ):
      __UpperCAmelCase	:  Union[str, Any]		=     pow(snake_case_    ,       snake_case_    ,       snake_case_  )
      if val in li:
        break
      li.append(snake_case_  )
    else:
      return r
  return None


if __name__ == "__main__":
      _SCREAMING_SNAKE_CASE							 =			int(input('''Enter a prime number q: '''))
      _SCREAMING_SNAKE_CASE							 =			find_primitive(q)
      if a is None:
            print(F'''Cannot find the primitive for the value: {a!r}''')
      else:
            _SCREAMING_SNAKE_CASE							 =			int(input('''Enter private key of A: '''))
            _SCREAMING_SNAKE_CASE							 =			pow(a, a_private, q)
            _SCREAMING_SNAKE_CASE							 =			int(input('''Enter private key of B: '''))
            _SCREAMING_SNAKE_CASE							 =			pow(a, b_private, q)

            _SCREAMING_SNAKE_CASE							 =			pow(b_public, a_private, q)
            _SCREAMING_SNAKE_CASE							 =			pow(a_public, b_private, q)

            print('''The key value generated by A is: ''', a_secret)
            print('''The key value generated by B is: ''', b_secret)





