



'''simple docstring'''

import unittest

from transformers import ErnieMConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import (
							    ErnieMForInformationExtraction,
							    ErnieMForMultipleChoice,
							    ErnieMForQuestionAnswering,
							    ErnieMForSequenceClassification,
							    ErnieMForTokenClassification,
							    ErnieMModel,
							)
							from transformers.models.ernie_m.modeling_ernie_m import ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST







class 			__magic_name__		:







							def __init__(							self      : Optional[Any]			,_UpperCAmelCase      : List[Any]			,_UpperCAmelCase      : Dict=13			,_UpperCAmelCase      : int=7			,_UpperCAmelCase      : Optional[int]=True			,_UpperCAmelCase      : str=True			,_UpperCAmelCase      : Optional[int]=True			,_UpperCAmelCase      : Tuple=99			,_UpperCAmelCase      : Tuple=32			,_UpperCAmelCase      : Any=5			,_UpperCAmelCase      : Optional[Any]=4			,_UpperCAmelCase      : int=37			,_UpperCAmelCase      : List[str]="gelu"			,_UpperCAmelCase      : List[Any]=0.1			,_UpperCAmelCase      : Dict=0.1			,_UpperCAmelCase      : Any=512			,_UpperCAmelCase      : Union[str, Any]=16			,_UpperCAmelCase      : Union[str, Any]=2			,_UpperCAmelCase      : str=0.02			,_UpperCAmelCase      : int=3			,_UpperCAmelCase      : List[Any]=4			,_UpperCAmelCase      : Tuple=None			,):
									_a  :   Union[str, Any]				 =							parent
									_a  :   Optional[int]				 =							batch_size
									_a  :   Union[str, Any]				 =							seq_length
									_a  :   Union[str, Any]				 =							is_training
									_a  :   Optional[Any]				 =							use_input_mask
									_a  :   Union[str, Any]				 =							use_labels
									_a  :   int				 =							vocab_size
									_a  :   int				 =							hidden_size
									_a  :   Dict				 =							num_hidden_layers
									_a  :   Union[str, Any]				 =							num_attention_heads
									_a  :   int				 =							intermediate_size
									_a  :   Union[str, Any]				 =							hidden_act
									_a  :   Dict				 =							hidden_dropout_prob
									_a  :   Optional[int]				 =							attention_probs_dropout_prob
									_a  :   Tuple				 =							max_position_embeddings
									_a  :   Dict				 =							type_vocab_size
									_a  :   Dict				 =							type_sequence_label_size
									_a  :   Union[str, Any]				 =							initializer_range
									_a  :   Any				 =							num_labels
									_a  :   List[Any]				 =							num_choices
									_a  :   str				 =							scope







							def 							__lowercase    (							self      : str	):
									_a  :   List[str]				 =							ids_tensor([self.batch_size, self.seq_length]			,self.vocab_size	)

									_a  :   str				 =							None
									if self.use_input_mask:
											_a  :   Tuple				 =							random_attention_mask([self.batch_size, self.seq_length]	)

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

									_a  :   Dict				 =							self.get_config()

									return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels







							def 							__lowercase    (							self      : Union[str, Any]	):
									_a  :   List[Any]				 =							ids_tensor([self.batch_size, self.seq_length]			,self.vocab_size	)

									_a  :   Optional[int]				 =							None
									if self.use_input_mask:
											_a  :   Tuple				 =							random_attention_mask([self.batch_size, self.seq_length]	)
									_a  :   Optional[Any]				 =							self.get_config()

									return config, input_ids, input_mask







							def 							__lowercase    (							self      : Any	):
									return ErnieMConfig(
									    vocab_size=self.vocab_size			,hidden_size=self.hidden_size			,num_hidden_layers=self.num_hidden_layers			,num_attention_heads=self.num_attention_heads			,intermediate_size=self.intermediate_size			,hidden_act=self.hidden_act			,hidden_dropout_prob=self.hidden_dropout_prob			,attention_probs_dropout_prob=self.attention_probs_dropout_prob			,max_position_embeddings=self.max_position_embeddings			,type_vocab_size=self.type_vocab_size			,initializer_range=self.initializer_range			,)







							def 							__lowercase    (							self      : int			,_UpperCAmelCase      : Union[str, Any]			,_UpperCAmelCase      : Optional[int]			,_UpperCAmelCase      : Any			,_UpperCAmelCase      : List[Any]			,_UpperCAmelCase      : int			,_UpperCAmelCase      : Any	):
									_a  :   str				 =							ErnieMModel(config=_A	)
									model.to(_A	)
									model.eval()
									_a  :   List[str]				 =							model(_A			,return_dict=_A	)
									self.parent.assertEqual(result.last_hidden_state.shape			,(self.batch_size, self.seq_length, self.hidden_size)	)







							def 							__lowercase    (							self      : Union[str, Any]			,_UpperCAmelCase      : List[str]			,_UpperCAmelCase      : List[Any]			,_UpperCAmelCase      : Optional[int]			,_UpperCAmelCase      : Tuple			,_UpperCAmelCase      : Dict			,_UpperCAmelCase      : List[Any]	):
									_a  :   Any				 =							ErnieMForQuestionAnswering(config=_A	)
									model.to(_A	)
									model.eval()
									_a  :   List[Any]				 =							model(
									    _A			,attention_mask=_A			,start_positions=_A			,end_positions=_A			,)
									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      : Optional[Any]			,_UpperCAmelCase      : Union[str, Any]			,_UpperCAmelCase      : str			,_UpperCAmelCase      : List[str]			,_UpperCAmelCase      : Any			,_UpperCAmelCase      : Any			,_UpperCAmelCase      : str	):
									_a  :   List[Any]				 =							ErnieMForInformationExtraction(config=_A	)
									model.to(_A	)
									model.eval()
									_a  :   Optional[int]				 =							torch.ones_like(_A			,dtype=torch.floataa	)
									_a  :   Dict				 =							model(
									    _A			,attention_mask=_A			,start_positions=_A			,end_positions=_A			,)
									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      : int			,_UpperCAmelCase      : Union[str, Any]			,_UpperCAmelCase      : str			,_UpperCAmelCase      : Optional[Any]			,_UpperCAmelCase      : Optional[Any]			,_UpperCAmelCase      : List[str]			,_UpperCAmelCase      : List[Any]	):
									_a  :   List[str]				 =							self.num_labels
									_a  :   int				 =							ErnieMForSequenceClassification(_A	)
									model.to(_A	)
									model.eval()
									_a  :   str				 =							model(_A			,attention_mask=_A			,labels=_A	)
									self.parent.assertEqual(result.logits.shape			,(self.batch_size, self.num_labels)	)







							def 							__lowercase    (							self      : Union[str, Any]			,_UpperCAmelCase      : List[str]			,_UpperCAmelCase      : Any			,_UpperCAmelCase      : Tuple			,_UpperCAmelCase      : Dict			,_UpperCAmelCase      : str			,_UpperCAmelCase      : List[str]	):
									_a  :   Optional[Any]				 =							self.num_labels
									_a  :   Optional[int]				 =							ErnieMForTokenClassification(config=_A	)
									model.to(_A	)
									model.eval()
									input_ids.to(_A	)
									input_mask.to(_A	)
									token_labels.to(_A	)

									_a  :   List[Any]				 =							model(_A			,attention_mask=_A			,labels=_A	)

									self.parent.assertEqual(result.logits.shape			,(self.batch_size, self.seq_length, self.num_labels)	)







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







							def 							__lowercase    (							self      : List[Any]	):
									_a  :   Optional[int]				 =							self.prepare_config_and_inputs()
									(
									    _a       
									)  :   int				 =							config_and_inputs
									_a  :   str				 =							{'input_ids': input_ids, 'attention_mask': input_mask}
									return config, inputs_dict







@require_torch
class 			__magic_name__		(					lowercase__    ,		lowercase__    ,		unittest.TestCase     ):
							lowerCAmelCase :					Optional[int]            =      (
							    (
							        ErnieMModel,
							        ErnieMForMultipleChoice,
							        ErnieMForQuestionAnswering,
							        ErnieMForSequenceClassification,
							        ErnieMForTokenClassification,
							    )
							    if is_torch_available()
							    else ()
							)
							lowerCAmelCase :					str            =      ()
							lowerCAmelCase :					Optional[int]            =      (
							    {
							        """feature-extraction""": ErnieMModel,
							        """question-answering""": ErnieMForQuestionAnswering,
							        """text-classification""": ErnieMForSequenceClassification,
							        """token-classification""": ErnieMForTokenClassification,
							        """zero-shot""": ErnieMForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							lowerCAmelCase :					Tuple            =      False







							def 							__lowercase    (							self      : List[str]			,_UpperCAmelCase      : Optional[int]			,_UpperCAmelCase      : Any			,_UpperCAmelCase      : Optional[int]			,_UpperCAmelCase      : str			,_UpperCAmelCase      : List[str]	):
									if pipeline_test_casse_name == "QAPipelineTests":
											return True

									return False







							def 							__lowercase    (							self      : Optional[Any]	):
									_a  :   Any				 =							ErnieMModelTester(self	)
									_a  :   Optional[int]				 =							ConfigTester(self			,config_class=_A			,hidden_size=37	)







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







							def 							__lowercase    (							self      : int	):
									_a  :   Union[str, Any]				 =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_A	)







							def 							__lowercase    (							self      : Optional[Any]	):
									_a  :   Tuple				 =							self.model_tester.prepare_config_and_inputs()
									for type in ["absolute", "relative_key", "relative_key_query"]:
											_a  :   int				 =							type
											self.model_tester.create_and_check_model(*_A	)







							def 							__lowercase    (							self      : int	):
									_a  :   Optional[int]				 =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_multiple_choice(*_A	)







							def 							__lowercase    (							self      : List[Any]	):
									_a  :   str				 =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*_A	)







							def 							__lowercase    (							self      : Optional[Any]	):
									_a  :   List[str]				 =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*_A	)







							def 							__lowercase    (							self      : Dict	):
									_a  :   int				 =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_information_extraction(*_A	)







							def 							__lowercase    (							self      : Dict	):
									_a  :   Dict				 =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_token_classification(*_A	)







							@slow
							def 							__lowercase    (							self      : int	):
									for model_name in ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											_a  :   Dict				 =							ErnieMModel.from_pretrained(_A	)
											self.assertIsNotNone(_A	)







@require_torch
class 			__magic_name__		(					unittest.TestCase     ):







							@slow
							def 							__lowercase    (							self      : int	):
									_a  :   Any				 =							ErnieMModel.from_pretrained('susnato/ernie-m-base_pytorch'	)
									model.eval()
									_a  :   Optional[int]				 =							torch.tensor([[0, 1, 2, 3, 4, 5]]	)
									_a  :   List[str]				 =							model(_A	)[0]

									# TODO Replace vocab size
									_a  :   int				 =							768

									_a  :   Optional[int]				 =							torch.Size((1, 6, hidden_size)	)
									self.assertEqual(output.shape			,_A	)

									_a  :   Tuple				 =							torch.tensor(
									    [[[-0.00_12, 0.12_45, -0.02_14], [-0.07_42, 0.02_44, -0.07_71], [-0.03_33, 0.11_64, -0.15_54]]]	)

									self.assertTrue(torch.allclose(output[:, :3, :3]			,_A			,atol=1E-3	)	)









'''simple docstring'''

from __future__ import annotations

# Define the Gravitational Constant G and the function
__lowerCAmelCase		    =     6.6743e-11  # unit of G : m^3 * kg^-1 * s^-2



def   __lowerCamelCase  (   lowerCAmelCase_		,    lowerCAmelCase_		,    lowerCAmelCase_		,    lowerCAmelCase_						)    ->   dict[str, float]:
		_a  :   str				 =							mass_a * mass_a

		if (force, mass_a, mass_a, distance).count(0						) != 1:
				raise ValueError('One and only one argument must be 0'						)
		if force < 0:
				raise ValueError('Gravitational force can not be negative'						)
		if distance < 0:
				raise ValueError('Distance can not be negative'						)
		if mass_a < 0 or mass_a < 0:
				raise ValueError('Mass can not be negative'						)
		if force == 0:
				_a  :   List[Any]				 =							GRAVITATIONAL_CONSTANT * product_of_mass / (distance**2)
				return {"force": force}
		elif mass_a == 0:
				_a  :   Any				 =							(force) * (distance**2) / (GRAVITATIONAL_CONSTANT * mass_a)
				return {"mass_1": mass_a}
		elif mass_a == 0:
				_a  :   Tuple				 =							(force) * (distance**2) / (GRAVITATIONAL_CONSTANT * mass_a)
				return {"mass_2": mass_a}
		elif distance == 0:
				_a  :   str				 =							(GRAVITATIONAL_CONSTANT * product_of_mass / (force)) ** 0.5
				return {"distance": distance}
		raise ValueError('One and only one argument must be 0'						)


# Run doctest
if __name__ == "__main__":
							import doctest

							doctest.testmod()




