





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


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

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


					def      lowerCamelCase	( self      :Union[str, Any]		):
												A		=  ids_tensor([self.batch_size, self.seq_length]					,	self.vocab_size		)

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

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

												A		=  None
												A		=  None
												A		=  None
												if self.use_labels:
																			A		=  ids_tensor([self.batch_size]					,	self.type_sequence_label_size		)
																			A		=  ids_tensor([self.batch_size, self.seq_length]					,	self.num_labels		)
																			A		=  ids_tensor([self.batch_size]					,	self.num_choices		)
																			A		=  ids_tensor([self.batch_size, self.seq_length]					,	1		)

												A		=  self.get_config()

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


					def      lowerCamelCase	( self      :Tuple		):
												return FunnelConfig(
												    vocab_size=self.vocab_size					,	block_sizes=self.block_sizes					,	num_decoder_layers=self.num_decoder_layers					,	d_model=self.d_model					,	n_head=self.n_head					,	d_head=self.d_head					,	d_inner=self.d_inner					,	hidden_act=self.hidden_act					,	hidden_dropout=self.hidden_dropout					,	attention_dropout=self.attention_dropout					,	activation_dropout=self.activation_dropout					,	max_position_embeddings=self.max_position_embeddings					,	type_vocab_size=self.type_vocab_size					,	initializer_std=self.initializer_std					,	)


					def      lowerCamelCase	( self      :Optional[int]					,	__UpperCamelCase      :Tuple					,	__UpperCamelCase      :str					,	__UpperCamelCase      :Any					,	__UpperCamelCase      :List[str]					,	__UpperCamelCase      :int					,	__UpperCamelCase      :Tuple					,	__UpperCamelCase      :Dict					,	__UpperCamelCase      :Optional[int]					,	):
												A		=  FunnelModel(config=__UpperCamelCase		)
												model.to(__UpperCamelCase		)
												model.eval()
												A		=  model(__UpperCamelCase					,	attention_mask=__UpperCamelCase					,	token_type_ids=__UpperCamelCase		)
												A		=  model(__UpperCamelCase					,	token_type_ids=__UpperCamelCase		)
												A		=  model(__UpperCamelCase		)
												self.parent.assertEqual(result.last_hidden_state.shape					,	(self.batch_size, self.seq_length, self.d_model)		)

												A		=  False
												A		=  model(__UpperCamelCase		)
												self.parent.assertEqual(result.last_hidden_state.shape					,	(self.batch_size, self.seq_length, self.d_model)		)

												A		=  False
												A		=  model(__UpperCamelCase		)
												self.parent.assertEqual(result.last_hidden_state.shape					,	(self.batch_size, self.seq_length, self.d_model)		)


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

												A		=  False
												A		=  model(__UpperCamelCase		)
												self.parent.assertEqual(result.last_hidden_state.shape					,	(self.batch_size, 3, self.d_model)		)

												A		=  False
												A		=  model(__UpperCamelCase		)
												self.parent.assertEqual(result.last_hidden_state.shape					,	(self.batch_size, 2, self.d_model)		)


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


					def      lowerCamelCase	( self      :Optional[int]					,	__UpperCamelCase      :Any					,	__UpperCamelCase      :List[Any]					,	__UpperCamelCase      :List[Any]					,	__UpperCamelCase      :Optional[int]					,	__UpperCamelCase      :str					,	__UpperCamelCase      :Tuple					,	__UpperCamelCase      :str					,	__UpperCamelCase      :Optional[Any]					,	):
												A		=  FunnelForMaskedLM(config=__UpperCamelCase		)
												model.to(__UpperCamelCase		)
												model.eval()
												A		=  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      lowerCamelCase	( self      :Dict					,	__UpperCamelCase      :str					,	__UpperCamelCase      :List[Any]					,	__UpperCamelCase      :str					,	__UpperCamelCase      :int					,	__UpperCamelCase      :Optional[int]					,	__UpperCamelCase      :int					,	__UpperCamelCase      :str					,	__UpperCamelCase      :Any					,	):
												A		=  self.num_labels
												A		=  FunnelForSequenceClassification(__UpperCamelCase		)
												model.to(__UpperCamelCase		)
												model.eval()
												A		=  model(__UpperCamelCase					,	attention_mask=__UpperCamelCase					,	token_type_ids=__UpperCamelCase					,	labels=__UpperCamelCase		)
												self.parent.assertEqual(result.logits.shape					,	(self.batch_size, self.num_labels)		)


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


					def      lowerCamelCase	( self      :Union[str, Any]					,	__UpperCamelCase      :Optional[int]					,	__UpperCamelCase      :Union[str, Any]					,	__UpperCamelCase      :List[Any]					,	__UpperCamelCase      :Union[str, Any]					,	__UpperCamelCase      :List[str]					,	__UpperCamelCase      :List[Any]					,	__UpperCamelCase      :List[Any]					,	__UpperCamelCase      :Union[str, Any]					,	):
												A		=  self.num_labels
												A		=  FunnelForTokenClassification(config=__UpperCamelCase		)
												model.to(__UpperCamelCase		)
												model.eval()
												A		=  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      lowerCamelCase	( self      :Tuple					,	__UpperCamelCase      :Union[str, Any]					,	__UpperCamelCase      :List[Any]					,	__UpperCamelCase      :int					,	__UpperCamelCase      :Tuple					,	__UpperCamelCase      :List[str]					,	__UpperCamelCase      :int					,	__UpperCamelCase      :str					,	__UpperCamelCase      :Tuple					,	):
												A		=  FunnelForQuestionAnswering(config=__UpperCamelCase		)
												model.to(__UpperCamelCase		)
												model.eval()
												A		=  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      lowerCamelCase	( self      :Union[str, Any]		):
												A		=  self.prepare_config_and_inputs()
												(
												    (
												    A
												),     (
												    A
												),     (
												    A
												),     (
												    A
												),     (
												    A
												),     (
												    A
												),     (
												    A
												),     (
												    A
												),     
												)		=  config_and_inputs
												A		=  {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
												return config, inputs_dict







@require_torch
class  _UpperCAmelCase       (     lowercase_					,							lowercase_					,							unittest.TestCase			):
					UpperCamelCase								=							False
					UpperCamelCase								=							False
					UpperCamelCase								=							(
					    (
					        FunnelModel,
					        FunnelForMaskedLM,
					        FunnelForPreTraining,
					        FunnelForQuestionAnswering,
					        FunnelForTokenClassification,
					    )
					    if is_torch_available()
					    else ()
					)
					UpperCamelCase								=							(
					    {
					        '''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      :List[str]					,	__UpperCamelCase      :Tuple					,	__UpperCamelCase      :Any					,	__UpperCamelCase      :str=False		):
												A		=  super()._prepare_for_class(__UpperCamelCase					,	__UpperCamelCase					,	return_labels=__UpperCamelCase		)

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


					def      lowerCamelCase	( self      :List[str]		):
												A		=  FunnelModelTester(self		)
												A		=  ConfigTester(self					,	config_class=__UpperCamelCase		)


					def      lowerCamelCase	( self      :Dict		):
												self.config_tester.run_common_tests()


					def      lowerCamelCase	( self      :int		):
												A		=  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*__UpperCamelCase		)


					def      lowerCamelCase	( self      :Optional[int]		):
												A		=  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_pretraining(*__UpperCamelCase		)


					def      lowerCamelCase	( self      :Optional[Any]		):
												A		=  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_masked_lm(*__UpperCamelCase		)


					def      lowerCamelCase	( self      :Tuple		):
												A		=  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_token_classification(*__UpperCamelCase		)


					def      lowerCamelCase	( self      :List[str]		):
												A		=  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_question_answering(*__UpperCamelCase		)


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







@require_torch
class  _UpperCAmelCase       (     lowercase_					,							unittest.TestCase			):
					UpperCamelCase								=							False
					UpperCamelCase								=							False
					UpperCamelCase								=							(
					    (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
					)


					def      lowerCamelCase	( self      :List[Any]		):
												A		=  FunnelModelTester(self					,	base=__UpperCamelCase		)
												A		=  ConfigTester(self					,	config_class=__UpperCamelCase		)


					def      lowerCamelCase	( self      :Union[str, Any]		):
												self.config_tester.run_common_tests()


					def      lowerCamelCase	( self      :Any		):
												A		=  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_base_model(*__UpperCamelCase		)


					def      lowerCamelCase	( self      :Dict		):
												A		=  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_sequence_classification(*__UpperCamelCase		)


					def      lowerCamelCase	( self      :Optional[int]		):
												A		=  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_multiple_choice(*__UpperCamelCase		)


					def      lowerCamelCase	( self      :Union[str, Any]		):
												A,     A		=  self.model_tester.prepare_config_and_inputs_for_common()
												A		=  True

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


					def      lowerCamelCase	( self      :Dict					,	__UpperCamelCase      :str		):
												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:
																										A		=  getattr(__UpperCamelCase					,	__UpperCamelCase		)
																										weight.data.fill_(3		)







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


					def      lowerCamelCase	( self      :int		):
												A		=  13
												A		=  7
												A		=  torch.arange(0					,	batch_size * sequence_length		).long().reshape(__UpperCamelCase					,	__UpperCamelCase		)
												A		=  [0, 1, 2, 3, 4, 5, 6, 4, 1, 3, 5, 0, 1]
												A		=  torch.tensor([[2] + [0] * a + [1] * (sequence_length - a - 1) for a in lengths]		)

												A		=  FunnelModel.from_pretrained("sgugger/funnel-random-tiny"		)
												A		=  model(__UpperCamelCase					,	token_type_ids=__UpperCamelCase		)[0].abs()

												A		=  torch.tensor(2_344.8_352		)
												A		=  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		)		)

												A		=  torch.tensor([[1] * 7, [1] * 4 + [0] * 3] * 6 + [[0, 1, 1, 0, 0, 1, 1]]		)
												A		=  model(__UpperCamelCase					,	attention_mask=__UpperCamelCase					,	token_type_ids=__UpperCamelCase		)[0].abs()

												A		=  torch.tensor(2_343.8_425		)
												A		=  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      lowerCamelCase	( self      :Optional[Any]		):
												A		=  FunnelTokenizer.from_pretrained("huggingface/funnel-small"		)
												A		=  FunnelModel.from_pretrained("huggingface/funnel-small"		)
												A		=  tokenizer("Hello! I am the Funnel Transformer model."					,	return_tensors="pt"		)
												A		=  model(**__UpperCamelCase		)[0]

												A		=  torch.tensor(235.7_246		)
												A		=  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		)		)









"""simple docstring"""
def  A__    (      UpperCamelCase ,  UpperCamelCase	):
							for index, item in enumerate(UpperCamelCase	):
														if item == target:
																					return index
							return -1






def  A__    (      UpperCamelCase ,  UpperCamelCase ,  UpperCamelCase ,  UpperCamelCase	):
							if not (0 <= high < len(UpperCamelCase	) and 0 <= low < len(UpperCamelCase	)):
														raise Exception("Invalid upper or lower bound!"	)
							if high < low:
														return -1
							if sequence[low] == target:
														return low
							if sequence[high] == target:
														return high
							return rec_linear_search(UpperCamelCase ,  low + 1 ,  high - 1 ,  UpperCamelCase	)


if __name__ == "__main__":
		_snake_case					:		int							=			input('Enter numbers separated by comma:\n').strip()
		_snake_case					:		int							=			[int(item.strip()) for item in user_input.split(',')]

		_snake_case					:		Union[str, Any]							=			int(input('Enter a single number to be found in the list:\n').strip())
		_snake_case					:		List[Any]							=			linear_search(sequence, target)
		if result != -1:
				print(F"""linear_search({sequence}, {target}) = {result}""")
		else:
				print(F"""{target} was not found in {sequence}""")


