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



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







         """simple docstring"""



         a__    = parent
         a__    = batch_size
         a__    = seq_length
         a__    = is_training
         a__    = use_input_mask
         a__    = use_labels
         a__    = vocab_size
         a__    = hidden_size
         a__    = num_hidden_layers
         a__    = num_attention_heads
         a__    = intermediate_size
         a__    = hidden_act
         a__    = hidden_dropout_prob
         a__    = attention_probs_dropout_prob
         a__    = max_position_embeddings
         a__    = type_vocab_size
         a__    = type_sequence_label_size
         a__    = initializer_range
         a__    = num_labels
         a__    = num_choices
         a__    = scope



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







         """simple docstring"""



         a__    = ids_tensor([self.batch_size, self.seq_length]    ,							self.vocab_size      )

         a__    = None
         if self.use_input_mask:
             a__    = random_attention_mask([self.batch_size, self.seq_length]      )

         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__    = self.get_config()

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



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







         """simple docstring"""



         a__    = ids_tensor([self.batch_size, self.seq_length]    ,							self.vocab_size      )

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

         return config, input_ids, input_mask



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







         """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  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    int:







         """simple docstring"""



         a__    = ErnieMModel(config=__SCREAMING_SNAKE_CASE      )
         model.to(__SCREAMING_SNAKE_CASE      )
         model.eval()
         a__    = model(__SCREAMING_SNAKE_CASE    ,							return_dict=__SCREAMING_SNAKE_CASE      )
         self.parent.assertEqual(result.last_hidden_state.shape    ,							(self.batch_size, self.seq_length, self.hidden_size)      )



     def  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    Optional[Any]:







         """simple docstring"""



         a__    = ErnieMForQuestionAnswering(config=__SCREAMING_SNAKE_CASE      )
         model.to(__SCREAMING_SNAKE_CASE      )
         model.eval()
         a__    = model(
             __SCREAMING_SNAKE_CASE    ,							attention_mask=__SCREAMING_SNAKE_CASE    ,							start_positions=__SCREAMING_SNAKE_CASE    ,							end_positions=__SCREAMING_SNAKE_CASE    ,							)
         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    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    int:







         """simple docstring"""



         a__    = ErnieMForInformationExtraction(config=__SCREAMING_SNAKE_CASE      )
         model.to(__SCREAMING_SNAKE_CASE      )
         model.eval()
         a__    = torch.ones_like(__SCREAMING_SNAKE_CASE    ,							dtype=torch.floataa      )
         a__    = model(
             __SCREAMING_SNAKE_CASE    ,							attention_mask=__SCREAMING_SNAKE_CASE    ,							start_positions=__SCREAMING_SNAKE_CASE    ,							end_positions=__SCREAMING_SNAKE_CASE    ,							)
         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    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    List[Any]:







         """simple docstring"""



         a__    = self.num_labels
         a__    = ErnieMForSequenceClassification(__SCREAMING_SNAKE_CASE      )
         model.to(__SCREAMING_SNAKE_CASE      )
         model.eval()
         a__    = model(__SCREAMING_SNAKE_CASE    ,							attention_mask=__SCREAMING_SNAKE_CASE    ,							labels=__SCREAMING_SNAKE_CASE      )
         self.parent.assertEqual(result.logits.shape    ,							(self.batch_size, self.num_labels)      )



     def  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    Tuple:







         """simple docstring"""



         a__    = self.num_labels
         a__    = ErnieMForTokenClassification(config=__SCREAMING_SNAKE_CASE      )
         model.to(__SCREAMING_SNAKE_CASE      )
         model.eval()
         input_ids.to(__SCREAMING_SNAKE_CASE      )
         input_mask.to(__SCREAMING_SNAKE_CASE      )
         token_labels.to(__SCREAMING_SNAKE_CASE      )

         a__    = model(__SCREAMING_SNAKE_CASE    ,							attention_mask=__SCREAMING_SNAKE_CASE    ,							labels=__SCREAMING_SNAKE_CASE      )

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



     def  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    Optional[int]:







         """simple docstring"""



         a__    = self.num_choices
         a__    = ErnieMForMultipleChoice(config=__SCREAMING_SNAKE_CASE      )
         model.to(__SCREAMING_SNAKE_CASE      )
         model.eval()
         a__    = input_ids.unsqueeze(1      ).expand(-1    ,							self.num_choices    ,							-1      ).contiguous()
         a__    = input_mask.unsqueeze(1      ).expand(-1    ,							self.num_choices    ,							-1      ).contiguous()
         a__    = model(
             __SCREAMING_SNAKE_CASE    ,							attention_mask=__SCREAMING_SNAKE_CASE    ,							labels=__SCREAMING_SNAKE_CASE    ,							)
         self.parent.assertEqual(result.logits.shape    ,							(self.batch_size, self.num_choices)      )




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







         """simple docstring"""



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







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



     def  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )		->    Optional[int]:







         """simple docstring"""



         if pipeline_test_casse_name == "QAPipelineTests":
             return True

         return False



     def  lowercase__     (       self      )		->    Any:







         """simple docstring"""



         a__    = ErnieMModelTester(self      )
         a__    = ConfigTester(self    ,							config_class=__SCREAMING_SNAKE_CASE    ,							hidden_size=3_7      )



     def  lowercase__     (       self      )		->    int:







         """simple docstring"""



         self.config_tester.run_common_tests()



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







         """simple docstring"""



         a__    = self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE      )



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







         """simple docstring"""



         a__    = self.model_tester.prepare_config_and_inputs()
         for type in ["absolute", "relative_key", "relative_key_query"]:
             a__    = type
             self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE      )



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







         """simple docstring"""



         a__    = self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_multiple_choice(*__SCREAMING_SNAKE_CASE      )



     def  lowercase__     (       self      )		->    int:







         """simple docstring"""



         a__    = self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*__SCREAMING_SNAKE_CASE      )



     def  lowercase__     (       self      )		->    Dict:







         """simple docstring"""



         a__    = self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*__SCREAMING_SNAKE_CASE      )



     def  lowercase__     (       self      )		->    int:







         """simple docstring"""



         a__    = self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_information_extraction(*__SCREAMING_SNAKE_CASE      )



     def  lowercase__     (       self      )		->    Dict:







         """simple docstring"""



         a__    = self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*__SCREAMING_SNAKE_CASE      )




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







         """simple docstring"""



         for model_name in ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             a__    = ErnieMModel.from_pretrained(__SCREAMING_SNAKE_CASE      )
             self.assertIsNotNone(__SCREAMING_SNAKE_CASE      )







@require_torch
class 						lowercase(unittest.TestCase					):



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







         """simple docstring"""



         a__    = ErnieMModel.from_pretrained('susnato/ernie-m-base_pytorch'      )
         model.eval()
         a__    = torch.tensor([[0, 1, 2, 3, 4, 5]]      )
         a__    = model(__SCREAMING_SNAKE_CASE      )[0]

         # TODO Replace vocab size
         a__    = 7_6_8

         a__    = torch.Size((1, 6, hidden_size)      )
         self.assertEqual(output.shape    ,							__SCREAMING_SNAKE_CASE      )

         a__    = 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]    ,							__SCREAMING_SNAKE_CASE    ,							atol=1e-3      )      )




"""simple docstring"""




from itertools import combinations, product



def 						__magic_name__		(				UpperCamelCase    :		int       ,		UpperCamelCase    :		int       ,		UpperCamelCase    :		int       ,		UpperCamelCase    :		int    )    ->	bool:
    if xa == ya == 0 or xa == ya == 0:
        return False
    a__    = xa * xa + ya * ya
    a__    = xa * xa + ya * ya
    a__    = (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 						__magic_name__		(				UpperCamelCase    :		int = 50    )    ->	int:
    return sum(
        1
        for pta, pta in combinations(product(range(limit + 1    )       ,		repeat=2    )       ,		2    )
        if is_right(*UpperCamelCase       ,		*UpperCamelCase    )    )


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


