
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 						__magic_name__				:





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

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





		def  _A							(							self      :		List[Any]			):
							lowerCAmelCase						:   Optional[Any]							=       ids_tensor([self.batch_size, self.seq_length]  ,					self.vocab_size			)

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

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

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

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

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





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

							lowerCAmelCase						:   Tuple							=       False
							lowerCAmelCase						:   int							=       model(lowerCamelCase__			)
							self.parent.assertEqual(result.last_hidden_state.shape  ,					(self.batch_size, self.seq_length, self.d_model)			)

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





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

							lowerCAmelCase						:   str							=       False
							lowerCAmelCase						:   Any							=       model(lowerCamelCase__			)
							self.parent.assertEqual(result.last_hidden_state.shape  ,					(self.batch_size, 3, self.d_model)			)

							lowerCAmelCase						:   Any							=       False
							lowerCAmelCase						:   int							=       model(lowerCamelCase__			)
							self.parent.assertEqual(result.last_hidden_state.shape  ,					(self.batch_size, 2, self.d_model)			)





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





		def  _A							(							self      :		Optional[int]  ,					lowerCamelCase__      :		List[str]  ,					lowerCamelCase__      :		List[str]  ,					lowerCamelCase__      :		Tuple  ,					lowerCamelCase__      :		str  ,					lowerCamelCase__      :		str  ,					lowerCamelCase__      :		List[str]  ,					lowerCamelCase__      :		Tuple  ,					lowerCamelCase__      :		int  ,					):
							lowerCAmelCase						:   Tuple							=       FunnelForMaskedLM(config=lowerCamelCase__			)
							model.to(lowerCamelCase__			)
							model.eval()
							lowerCAmelCase						:   List[Any]							=       model(lowerCamelCase__  ,					attention_mask=lowerCamelCase__  ,					token_type_ids=lowerCamelCase__  ,					labels=lowerCamelCase__			)
							self.parent.assertEqual(result.logits.shape  ,					(self.batch_size, self.seq_length, self.vocab_size)			)





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





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





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



@require_torch
class 						__magic_name__				(  snake_case,			snake_case,			unittest.TestCase      ):
		_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  _A							(							self      :		Dict  ,					lowerCamelCase__      :		Optional[int]  ,					lowerCamelCase__      :		List[str]  ,					lowerCamelCase__      :		List[str]=False			):
							lowerCAmelCase						:   Optional[int]							=       super()._prepare_for_class(lowerCamelCase__  ,					lowerCamelCase__  ,					return_labels=lowerCamelCase__			)

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





		def  _A							(							self      :		str			):
							lowerCAmelCase						:   Dict							=       FunnelModelTester(self			)
							lowerCAmelCase						:   int							=       ConfigTester(self  ,					config_class=lowerCamelCase__			)





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





		def  _A							(							self      :		Optional[int]			):
							lowerCAmelCase						:   Tuple							=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*lowerCamelCase__			)





		def  _A							(							self      :		Optional[int]			):
							lowerCAmelCase						:   List[Any]							=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_pretraining(*lowerCamelCase__			)





		def  _A							(							self      :		str			):
							lowerCAmelCase						:   Tuple							=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*lowerCamelCase__			)





		def  _A							(							self      :		Optional[int]			):
							lowerCAmelCase						:   Optional[int]							=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*lowerCamelCase__			)





		def  _A							(							self      :		List[Any]			):
							lowerCAmelCase						:   int							=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*lowerCamelCase__			)





		def  _A							(							self      :		Tuple  ,					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:
																	lowerCAmelCase						:   Optional[Any]							=       getattr(lowerCamelCase__  ,					lowerCamelCase__			)
																	weight.data.fill_(3			)



@require_torch
class 						__magic_name__				(  snake_case,			unittest.TestCase      ):
		_lowerCAmelCase						=		False
		_lowerCAmelCase						=		False
		_lowerCAmelCase						=		(
		    (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
		)





		def  _A							(							self      :		Union[str, Any]			):
							lowerCAmelCase						:   Dict							=       FunnelModelTester(self  ,					base=lowerCamelCase__			)
							lowerCAmelCase						:   List[Any]							=       ConfigTester(self  ,					config_class=lowerCamelCase__			)





		def  _A							(							self      :		int			):
							self.config_tester.run_common_tests()





		def  _A							(							self      :		Any			):
							lowerCAmelCase						:   Any							=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_base_model(*lowerCamelCase__			)





		def  _A							(							self      :		Tuple			):
							lowerCAmelCase						:   Optional[int]							=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*lowerCamelCase__			)





		def  _A							(							self      :		List[str]			):
							lowerCAmelCase						:   Any							=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_multiple_choice(*lowerCamelCase__			)





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

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





		def  _A							(							self      :		Tuple  ,					lowerCamelCase__      :		Dict			):
							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:
																	lowerCAmelCase						:   List[str]							=       getattr(lowerCamelCase__  ,					lowerCamelCase__			)
																	weight.data.fill_(3			)



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





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

							lowerCAmelCase						:   Union[str, Any]							=       FunnelModel.from_pretrained('''sgugger/funnel-random-tiny'''			)
							lowerCAmelCase						:   List[Any]							=       model(lowerCamelCase__  ,					token_type_ids=lowerCamelCase__			)[0].abs()

							lowerCAmelCase						:   List[Any]							=       torch.tensor(2_3_4_4.8_3_5_2			)
							lowerCAmelCase						:   List[str]							=       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			)			)

							lowerCAmelCase						:   Tuple							=       torch.tensor([[1] * 7, [1] * 4 + [0] * 3] * 6 + [[0, 1, 1, 0, 0, 1, 1]]			)
							lowerCAmelCase						:   Dict							=       model(lowerCamelCase__  ,					attention_mask=lowerCamelCase__  ,					token_type_ids=lowerCamelCase__			)[0].abs()

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

							lowerCAmelCase						:   str							=       torch.tensor(2_3_5.7_2_4_6			)
							lowerCAmelCase						:   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			)			)


from math import floor, sqrt
def       UpperCAmelCase__							(    __magic_name__  :       int					):


					'''simple docstring'''

					lowerCAmelCase						:   int							=       0.0
					lowerCAmelCase						:   int							=       1.0
					lowerCAmelCase						:   Any							=       int(sqrt(__magic_name__					)					)
					lowerCAmelCase						:   Optional[int]							=       root
					lowerCAmelCase						:   Dict							=       0
					while integer_part != 2 * root:
										lowerCAmelCase						:   str							=       denominator * integer_part - numerator
										lowerCAmelCase						:   Dict							=       (n - numerator**2) / denominator
										lowerCAmelCase						:   str							=       int((root + numerator) / denominator					)
										period += 1
					return period
def       UpperCAmelCase__							(    __magic_name__  :       int = 1_00_00					):


					'''simple docstring'''

					lowerCAmelCase						:   List[str]							=       0
					for i in range(2							,					n + 1					):
										lowerCAmelCase						:   Any							=       sqrt(__magic_name__					)
										if sr - floor(__magic_name__					) != 0 and continuous_fraction_period(__magic_name__					) % 2 == 1:
															count_odd_periods += 1
					return count_odd_periods


if __name__ == "__main__":
		print(f"""{solution(int(input().strip()))}""")
