

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







						"""simple docstring"""




						def __init__(				self , __UpperCamelCase , __UpperCamelCase=13 , __UpperCamelCase=7 , __UpperCamelCase=True , __UpperCamelCase=True , __UpperCamelCase=True , __UpperCamelCase=True , __UpperCamelCase=99 , __UpperCamelCase=[1, 1, 2] , __UpperCamelCase=1 , __UpperCamelCase=32 , __UpperCamelCase=4 , __UpperCamelCase=8 , __UpperCamelCase=37 , __UpperCamelCase="gelu_new" , __UpperCamelCase=0.1 , __UpperCamelCase=0.1 , __UpperCamelCase=0.0 , __UpperCamelCase=5_12 , __UpperCamelCase=3 , __UpperCamelCase=0.02 , __UpperCamelCase=3 , __UpperCamelCase=4 , __UpperCamelCase=None , __UpperCamelCase=False , )							->	Tuple:




									'''simple docstring'''


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

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

						def __lowerCamelCase					(				self    )							->	List[Any]:




									'''simple docstring'''


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

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

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

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

									__UpperCamelCase    :    Union[str, Any]								=      self.get_config()

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

						def __lowerCamelCase					(				self    )							->	List[str]:




									'''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 __lowerCamelCase					(				self , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , )							->	Union[str, Any]:




									'''simple docstring'''


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

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

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

						def __lowerCamelCase					(				self , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , )							->	Union[str, Any]:




									'''simple docstring'''


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

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

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

						def __lowerCamelCase					(				self , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , )							->	Union[str, Any]:




									'''simple docstring'''


									__UpperCamelCase    :    Any								=      self.num_labels
									__UpperCamelCase    :    Dict								=      FunnelForPreTraining(config=__UpperCamelCase    )
									model.to(__UpperCamelCase    )
									model.eval()
									__UpperCamelCase    :    Dict								=      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 , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , )							->	List[Any]:




									'''simple docstring'''


									__UpperCamelCase    :    Tuple								=      FunnelForMaskedLM(config=__UpperCamelCase    )
									model.to(__UpperCamelCase    )
									model.eval()
									__UpperCamelCase    :    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, self.vocab_size)    )

						def __lowerCamelCase					(				self , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , )							->	Any:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[int]								=      self.num_labels
									__UpperCamelCase    :    Optional[int]								=      FunnelForSequenceClassification(__UpperCamelCase    )
									model.to(__UpperCamelCase    )
									model.eval()
									__UpperCamelCase    :    str								=      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 , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , )							->	Union[str, Any]:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[Any]								=      self.num_choices
									__UpperCamelCase    :    Union[str, Any]								=      FunnelForMultipleChoice(config=__UpperCamelCase    )
									model.to(__UpperCamelCase    )
									model.eval()
									__UpperCamelCase    :    Optional[Any]								=      input_ids.unsqueeze(1    ).expand(-1 , self.num_choices , -1    ).contiguous()
									__UpperCamelCase    :    str								=      token_type_ids.unsqueeze(1    ).expand(-1 , self.num_choices , -1    ).contiguous()
									__UpperCamelCase    :    Optional[Any]								=      input_mask.unsqueeze(1    ).expand(-1 , self.num_choices , -1    ).contiguous()
									__UpperCamelCase    :    List[str]								=      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 , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , )							->	int:




									'''simple docstring'''


									__UpperCamelCase    :    int								=      self.num_labels
									__UpperCamelCase    :    Any								=      FunnelForTokenClassification(config=__UpperCamelCase    )
									model.to(__UpperCamelCase    )
									model.eval()
									__UpperCamelCase    :    Optional[int]								=      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 , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase , )							->	Optional[int]:




									'''simple docstring'''


									__UpperCamelCase    :    str								=      FunnelForQuestionAnswering(config=__UpperCamelCase    )
									model.to(__UpperCamelCase    )
									model.eval()
									__UpperCamelCase    :    Dict								=      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    )							->	int:




									'''simple docstring'''


									__UpperCamelCase    :    List[Any]								=      self.prepare_config_and_inputs()
									(
									    (
									    __UpperCamelCase 
									)							,				(
									    __UpperCamelCase 
									)							,				(
									    __UpperCamelCase 
									)							,				(
									    __UpperCamelCase 
									)							,				(
									    __UpperCamelCase 
									)							,				(
									    __UpperCamelCase 
									)							,				(
									    __UpperCamelCase 
									)							,				(
									    __UpperCamelCase 
									)							,				 
									)    :    List[Any]								=      config_and_inputs
									__UpperCamelCase    :    str								=      {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
									return config, inputs_dict







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







						"""simple docstring"""




						lowercase  :				List[str]											=							False
						lowercase  :				Optional[Any]											=							False
						lowercase  :				Optional[Any]											=							(
						    (
						        FunnelModel,
						        FunnelForMaskedLM,
						        FunnelForPreTraining,
						        FunnelForQuestionAnswering,
						        FunnelForTokenClassification,
						    )
						    if is_torch_available()
						    else ()
						)
						lowercase  :				List[str]											=							(
						    {
						        '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 , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase=False    )							->	int:




									'''simple docstring'''


									__UpperCamelCase    :    Dict								=      super()._prepare_for_class(__UpperCamelCase , __UpperCamelCase , return_labels=__UpperCamelCase    )

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

						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[int]								=      FunnelModelTester(self    )
									__UpperCamelCase    :    Union[str, Any]								=      ConfigTester(self , config_class=__UpperCamelCase    )

						def __lowerCamelCase					(				self    )							->	List[str]:




									'''simple docstring'''


									self.config_tester.run_common_tests()

						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[int]								=      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*__UpperCamelCase    )

						def __lowerCamelCase					(				self    )							->	Dict:




									'''simple docstring'''


									__UpperCamelCase    :    Dict								=      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_pretraining(*__UpperCamelCase    )

						def __lowerCamelCase					(				self    )							->	Dict:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[int]								=      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_lm(*__UpperCamelCase    )

						def __lowerCamelCase					(				self    )							->	Optional[Any]:




									'''simple docstring'''


									__UpperCamelCase    :    Dict								=      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_token_classification(*__UpperCamelCase    )

						def __lowerCamelCase					(				self    )							->	List[str]:




									'''simple docstring'''


									__UpperCamelCase    :    Tuple								=      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*__UpperCamelCase    )




						def __lowerCamelCase					(				self , __UpperCamelCase    )							->	Tuple:




									'''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:
															__UpperCamelCase    :    Optional[Any]								=      getattr(__UpperCamelCase , __UpperCamelCase    )
															weight.data.fill_(3    )







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







						"""simple docstring"""




						lowercase  :				str											=							False
						lowercase  :				List[Any]											=							False
						lowercase  :				Union[str, Any]											=							(
						    (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
						)

						def __lowerCamelCase					(				self    )							->	Optional[Any]:




									'''simple docstring'''


									__UpperCamelCase    :    str								=      FunnelModelTester(self , base=__UpperCamelCase    )
									__UpperCamelCase    :    Any								=      ConfigTester(self , config_class=__UpperCamelCase    )

						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									self.config_tester.run_common_tests()

						def __lowerCamelCase					(				self    )							->	Any:




									'''simple docstring'''


									__UpperCamelCase    :    List[str]								=      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_base_model(*__UpperCamelCase    )

						def __lowerCamelCase					(				self    )							->	int:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[Any]								=      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*__UpperCamelCase    )

						def __lowerCamelCase					(				self    )							->	str:




									'''simple docstring'''


									__UpperCamelCase    :    str								=      self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_multiple_choice(*__UpperCamelCase    )

						def __lowerCamelCase					(				self    )							->	Any:




									'''simple docstring'''


									__UpperCamelCase							,				__UpperCamelCase    :    Optional[Any]								=      self.model_tester.prepare_config_and_inputs_for_common()
									__UpperCamelCase    :    Union[str, Any]								=      True

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




						def __lowerCamelCase					(				self , __UpperCamelCase    )							->	Dict:




									'''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:
															__UpperCamelCase    :    List[Any]								=      getattr(__UpperCamelCase , __UpperCamelCase    )
															weight.data.fill_(3    )







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







						"""simple docstring"""




						def __lowerCamelCase					(				self    )							->	Optional[int]:




									'''simple docstring'''


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

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

									__UpperCamelCase    :    Union[str, Any]								=      torch.tensor(2344.8352    )
									__UpperCamelCase    :    int								=      torch.tensor(0.8052    )
									self.assertTrue(torch.allclose(output.sum() , __UpperCamelCase , atol=1E-4    )    )
									self.assertTrue(torch.allclose(output.mean() , __UpperCamelCase , atol=1E-4    )    )

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

									__UpperCamelCase    :    Union[str, Any]								=      torch.tensor(2343.8425    )
									__UpperCamelCase    :    Tuple								=      torch.tensor(0.8049    )
									self.assertTrue(torch.allclose(output.sum() , __UpperCamelCase , atol=1E-4    )    )
									self.assertTrue(torch.allclose(output.mean() , __UpperCamelCase , atol=1E-4    )    )




						@slow
						def __lowerCamelCase					(				self    )							->	Tuple:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[Any]								=      FunnelTokenizer.from_pretrained("huggingface/funnel-small"    )
									__UpperCamelCase    :    Union[str, Any]								=      FunnelModel.from_pretrained("huggingface/funnel-small"    )
									__UpperCamelCase    :    Any								=      tokenizer("Hello! I am the Funnel Transformer model." , return_tensors="pt"    )
									__UpperCamelCase    :    Optional[Any]								=      model(**__UpperCamelCase    )[0]

									__UpperCamelCase    :    List[str]								=      torch.tensor(235.7246    )
									__UpperCamelCase    :    str								=      torch.tensor(0.0256    )
									self.assertTrue(torch.allclose(output.sum() , __UpperCamelCase , atol=1E-4    )    )
									self.assertTrue(torch.allclose(output.mean() , __UpperCamelCase , atol=1E-4    )    )






lowercase     :       dict[str, float]        =       {
    "kilogram": 1,
    "gram": pow(10, 3),
    "milligram": pow(10, 6),
    "metric-ton": pow(10, -3),
    "long-ton": 0.0009842073,
    "short-ton": 0.0011023122,
    "pound": 2.2046244202,
    "stone": 0.1574731728,
    "ounce": 35.273990723,
    "carrat": 5000,
    "atomic-mass-unit": 6.0_22_13_66_52E26,
}

lowercase     :       dict[str, float]        =       {
    "kilogram": 1,
    "gram": pow(10, -3),
    "milligram": pow(10, -6),
    "metric-ton": pow(10, 3),
    "long-ton": 1016.04608,
    "short-ton": 907.184,
    "pound": 0.453592,
    "stone": 6.35029,
    "ounce": 0.0283495,
    "carrat": 0.0002,
    "atomic-mass-unit": 1.6_60_54_01_99E-27,
}







def  UpperCAmelCase_   (_lowerCAmelCase :		str     ,			_lowerCAmelCase :		str     ,			_lowerCAmelCase :		float		):
			if to_type not in KILOGRAM_CHART or from_type not in WEIGHT_TYPE_CHART:
						__UpperCamelCase    :    Dict								=      (
						    F'''Invalid \'from_type\' or \'to_type\' value: {from_type!r}, {to_type!r}\n'''
						    F'''Supported values are: {", ".join(_lowerCAmelCase		)}'''
						)
						raise ValueError(_lowerCAmelCase		)
			return value * KILOGRAM_CHART[to_type] * WEIGHT_TYPE_CHART[from_type]


if __name__ == "__main__":
					import doctest

					doctest.testmod()