





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






				def __init__(					self						:       Optional[Any],					lowerCAmelCase__						:       Any,					lowerCAmelCase__						:       Any=1_3,					lowerCAmelCase__						:       Dict=7,					lowerCAmelCase__						:       str=True,					lowerCAmelCase__						:       str=True,					lowerCAmelCase__						:       str=True,					lowerCAmelCase__						:       Union[str, Any]=9_9,					lowerCAmelCase__						:       int=3_2,					lowerCAmelCase__						:       Optional[Any]=5,					lowerCAmelCase__						:       List[Any]=4,					lowerCAmelCase__						:       List[Any]=3_7,					lowerCAmelCase__						:       Dict="gelu",					lowerCAmelCase__						:       Optional[Any]=0.1,					lowerCAmelCase__						:       Dict=0.1,					lowerCAmelCase__						:       List[Any]=5_1_2,					lowerCAmelCase__						:       int=1_6,					lowerCAmelCase__						:       Optional[Any]=2,					lowerCAmelCase__						:       List[Any]=0.02,					lowerCAmelCase__						:       int=3,					lowerCAmelCase__						:       List[Any]=4,					lowerCAmelCase__						:       Any=None,					)      -> Optional[int]:




										'''simple docstring'''



										_UpperCamelCase     :   Tuple      =       parent
										_UpperCamelCase     :   str      =       batch_size
										_UpperCamelCase     :   str      =       seq_length
										_UpperCamelCase     :   List[str]      =       is_training
										_UpperCamelCase     :   List[str]      =       use_input_mask
										_UpperCamelCase     :   Optional[int]      =       use_labels
										_UpperCamelCase     :   Any      =       vocab_size
										_UpperCamelCase     :   int      =       hidden_size
										_UpperCamelCase     :   Any      =       num_hidden_layers
										_UpperCamelCase     :   List[Any]      =       num_attention_heads
										_UpperCamelCase     :   Any      =       intermediate_size
										_UpperCamelCase     :   Any      =       hidden_act
										_UpperCamelCase     :   Any      =       hidden_dropout_prob
										_UpperCamelCase     :   Dict      =       attention_probs_dropout_prob
										_UpperCamelCase     :   Union[str, Any]      =       max_position_embeddings
										_UpperCamelCase     :   int      =       type_vocab_size
										_UpperCamelCase     :   Union[str, Any]      =       type_sequence_label_size
										_UpperCamelCase     :   Dict      =       initializer_range
										_UpperCamelCase     :   List[Any]      =       num_labels
										_UpperCamelCase     :   List[str]      =       num_choices
										_UpperCamelCase     :   Optional[int]      =       scope






				def 							snake_case      (					self						:       Union[str, Any]				)      -> List[Any]:




										'''simple docstring'''



										_UpperCamelCase     :   Optional[int]      =       ids_tensor([self.batch_size, self.seq_length],					self.vocab_size				)

										_UpperCamelCase     :   List[str]      =       None
										if self.use_input_mask:
																_UpperCamelCase     :   Union[str, Any]      =       random_attention_mask([self.batch_size, self.seq_length]				)

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

										_UpperCamelCase     :   Dict      =       self.get_config()

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






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




										'''simple docstring'''



										_UpperCamelCase     :   int      =       ids_tensor([self.batch_size, self.seq_length],					self.vocab_size				)

										_UpperCamelCase     :   Dict      =       None
										if self.use_input_mask:
																_UpperCamelCase     :   Dict      =       random_attention_mask([self.batch_size, self.seq_length]				)
										_UpperCamelCase     :   Tuple      =       self.get_config()

										return config, input_ids, input_mask






				def 							snake_case      (					self						:       Any				)      -> Any:




										'''simple docstring'''



										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 							snake_case      (					self						:       List[str],					lowerCAmelCase__						:       List[Any],					lowerCAmelCase__						:       Dict,					lowerCAmelCase__						:       List[str],					lowerCAmelCase__						:       Dict,					lowerCAmelCase__						:       Dict,					lowerCAmelCase__						:       List[str]				)      -> Any:




										'''simple docstring'''



										_UpperCamelCase     :   Union[str, Any]      =       ErnieMModel(config=lowerCAmelCase__				)
										model.to(lowerCAmelCase__				)
										model.eval()
										_UpperCamelCase     :   Optional[Any]      =       model(lowerCAmelCase__,					return_dict=lowerCAmelCase__				)
										self.parent.assertEqual(result.last_hidden_state.shape,					(self.batch_size, self.seq_length, self.hidden_size)				)






				def 							snake_case      (					self						:       Optional[int],					lowerCAmelCase__						:       str,					lowerCAmelCase__						:       Dict,					lowerCAmelCase__						:       str,					lowerCAmelCase__						:       int,					lowerCAmelCase__						:       Dict,					lowerCAmelCase__						:       Optional[Any]				)      -> List[str]:




										'''simple docstring'''



										_UpperCamelCase     :   Optional[int]      =       ErnieMForQuestionAnswering(config=lowerCAmelCase__				)
										model.to(lowerCAmelCase__				)
										model.eval()
										_UpperCamelCase     :   Union[str, Any]      =       model(
										    lowerCAmelCase__,					attention_mask=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 							snake_case      (					self						:       List[str],					lowerCAmelCase__						:       List[Any],					lowerCAmelCase__						:       int,					lowerCAmelCase__						:       Union[str, Any],					lowerCAmelCase__						:       str,					lowerCAmelCase__						:       int,					lowerCAmelCase__						:       Union[str, Any]				)      -> Any:




										'''simple docstring'''



										_UpperCamelCase     :   str      =       ErnieMForInformationExtraction(config=lowerCAmelCase__				)
										model.to(lowerCAmelCase__				)
										model.eval()
										_UpperCamelCase     :   Dict      =       torch.ones_like(lowerCAmelCase__,					dtype=torch.floataa				)
										_UpperCamelCase     :   str      =       model(
										    lowerCAmelCase__,					attention_mask=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 							snake_case      (					self						:       Optional[int],					lowerCAmelCase__						:       List[Any],					lowerCAmelCase__						:       Union[str, Any],					lowerCAmelCase__						:       int,					lowerCAmelCase__						:       Dict,					lowerCAmelCase__						:       Tuple,					lowerCAmelCase__						:       List[str]				)      -> int:




										'''simple docstring'''



										_UpperCamelCase     :   Union[str, Any]      =       self.num_labels
										_UpperCamelCase     :   int      =       ErnieMForSequenceClassification(lowerCAmelCase__				)
										model.to(lowerCAmelCase__				)
										model.eval()
										_UpperCamelCase     :   Optional[int]      =       model(lowerCAmelCase__,					attention_mask=lowerCAmelCase__,					labels=lowerCAmelCase__				)
										self.parent.assertEqual(result.logits.shape,					(self.batch_size, self.num_labels)				)






				def 							snake_case      (					self						:       List[str],					lowerCAmelCase__						:       Dict,					lowerCAmelCase__						:       Any,					lowerCAmelCase__						:       Tuple,					lowerCAmelCase__						:       Dict,					lowerCAmelCase__						:       Tuple,					lowerCAmelCase__						:       Optional[int]				)      -> Dict:




										'''simple docstring'''



										_UpperCamelCase     :   Optional[Any]      =       self.num_labels
										_UpperCamelCase     :   List[str]      =       ErnieMForTokenClassification(config=lowerCAmelCase__				)
										model.to(lowerCAmelCase__				)
										model.eval()
										input_ids.to(lowerCAmelCase__				)
										input_mask.to(lowerCAmelCase__				)
										token_labels.to(lowerCAmelCase__				)

										_UpperCamelCase     :   Any      =       model(lowerCAmelCase__,					attention_mask=lowerCAmelCase__,					labels=lowerCAmelCase__				)

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






				def 							snake_case      (					self						:       Union[str, Any],					lowerCAmelCase__						:       List[Any],					lowerCAmelCase__						:       str,					lowerCAmelCase__						:       Union[str, Any],					lowerCAmelCase__						:       Any,					lowerCAmelCase__						:       Any,					lowerCAmelCase__						:       Tuple				)      -> Optional[int]:




										'''simple docstring'''



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






				def 							snake_case      (					self						:       Optional[int]				)      -> Dict:




										'''simple docstring'''



										_UpperCamelCase     :   Tuple      =       self.prepare_config_and_inputs()
										(
										    (
										    _UpperCamelCase
										)  ,				(
										    _UpperCamelCase
										)  ,				(
										    _UpperCamelCase
										)  ,				(
										    _UpperCamelCase
										)  ,				(
										    _UpperCamelCase
										)  ,				(
										    _UpperCamelCase
										)  ,				
										)     :   Tuple      =       config_and_inputs
										_UpperCamelCase     :   Tuple      =       {'''input_ids''': input_ids, '''attention_mask''': input_mask}
										return config, inputs_dict




@require_torch
class 					_a		( _lowerCAmelCase      ,							_lowerCAmelCase      ,							unittest.TestCase							):
				UpperCamelCase								=       (
				    (
				        ErnieMModel,
				        ErnieMForMultipleChoice,
				        ErnieMForQuestionAnswering,
				        ErnieMForSequenceClassification,
				        ErnieMForTokenClassification,
				    )
				    if is_torch_available()
				    else ()
				)
				UpperCamelCase								=       ()
				UpperCamelCase								=       (
				    {
				        '''feature-extraction''': ErnieMModel,
				        '''question-answering''': ErnieMForQuestionAnswering,
				        '''text-classification''': ErnieMForSequenceClassification,
				        '''token-classification''': ErnieMForTokenClassification,
				        '''zero-shot''': ErnieMForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)
				UpperCamelCase								=       False






				def 							snake_case      (					self						:       List[Any],					lowerCAmelCase__						:       Optional[Any],					lowerCAmelCase__						:       Tuple,					lowerCAmelCase__						:       Optional[int],					lowerCAmelCase__						:       int,					lowerCAmelCase__						:       Dict				)      -> Any:




										'''simple docstring'''



										if pipeline_test_casse_name == "QAPipelineTests":
																return True

										return False






				def 							snake_case      (					self						:       List[str]				)      -> Tuple:




										'''simple docstring'''



										_UpperCamelCase     :   int      =       ErnieMModelTester(self				)
										_UpperCamelCase     :   Tuple      =       ConfigTester(self,					config_class=lowerCAmelCase__,					hidden_size=3_7				)






				def 							snake_case      (					self						:       Tuple				)      -> Tuple:




										'''simple docstring'''



										self.config_tester.run_common_tests()






				def 							snake_case      (					self						:       Dict				)      -> Tuple:




										'''simple docstring'''



										_UpperCamelCase     :   int      =       self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*lowerCAmelCase__				)






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




										'''simple docstring'''



										_UpperCamelCase     :   Optional[int]      =       self.model_tester.prepare_config_and_inputs()
										for type in ["absolute", "relative_key", "relative_key_query"]:
																_UpperCamelCase     :   Union[str, Any]      =       type
																self.model_tester.create_and_check_model(*lowerCAmelCase__				)






				def 							snake_case      (					self						:       List[str]				)      -> Dict:




										'''simple docstring'''



										_UpperCamelCase     :   Optional[int]      =       self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_multiple_choice(*lowerCAmelCase__				)






				def 							snake_case      (					self						:       List[str]				)      -> Union[str, Any]:




										'''simple docstring'''



										_UpperCamelCase     :   Optional[Any]      =       self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase__				)






				def 							snake_case      (					self						:       List[Any]				)      -> int:




										'''simple docstring'''



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






				def 							snake_case      (					self						:       str				)      -> int:




										'''simple docstring'''



										_UpperCamelCase     :   int      =       self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_information_extraction(*lowerCAmelCase__				)






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




										'''simple docstring'''



										_UpperCamelCase     :   Dict      =       self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase__				)






				@slow
				def 							snake_case      (					self						:       List[Any]				)      -> str:




										'''simple docstring'''



										for model_name in ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																_UpperCamelCase     :   List[str]      =       ErnieMModel.from_pretrained(lowerCAmelCase__				)
																self.assertIsNotNone(lowerCAmelCase__				)




@require_torch
class 					_a		( unittest.TestCase							):






				@slow
				def 							snake_case      (					self						:       Tuple				)      -> Any:




										'''simple docstring'''



										_UpperCamelCase     :   Any      =       ErnieMModel.from_pretrained('''susnato/ernie-m-base_pytorch'''				)
										model.eval()
										_UpperCamelCase     :   Dict      =       torch.tensor([[0, 1, 2, 3, 4, 5]]				)
										_UpperCamelCase     :   List[str]      =       model(lowerCAmelCase__				)[0]

										# TODO Replace vocab size
										_UpperCamelCase     :   List[Any]      =       7_6_8

										_UpperCamelCase     :   List[Any]      =       torch.Size((1, 6, hidden_size)				)
										self.assertEqual(output.shape,					lowerCAmelCase__				)

										_UpperCamelCase     :   Tuple      =       torch.tensor(
										    [[[-0.0_012, 0.1_245, -0.0_214], [-0.0_742, 0.0_244, -0.0_771], [-0.0_333, 0.1_164, -0.1_554]]]				)

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







'''simple docstring'''




from itertools import combinations, product

def       __UpperCamelCase     (     _A     :					int       , _A     :					int       , _A     :					int       , _A     :					int					)     ->   bool:




	"""simple docstring"""





	if xa == ya == 0 or xa == ya == 0:
		return False
	lowerCAmelCase       :     Optional[Any]   				=			xa * xa + ya * ya
	lowerCAmelCase       :     Tuple   				=			xa * xa + ya * ya
	lowerCAmelCase       :     List[str]   				=			(xa - xa) * (xa - xa) + (ya - ya) * (ya - ya)
	return (
	    a_square + b_square == c_square
	    or a_square + c_square == b_square
	    or b_square + c_square == a_square
	)

def       __UpperCamelCase     (     _A     :					int = 50					)     ->   int:




	"""simple docstring"""





	return sum(
	    1
	    for pta, pta in combinations(product(range(limit + 1					)       , repeat=2					)       , 2					)
	    if is_right(*_A       , *_A					)					)


if __name__ == "__main__":
				print(f"""{solution() = }""")
