
"""simple docstring"""




import unittest

from transformers.testing_utils import is_torch_available, require_torch, tooslow

from ...generation.test_utils import 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 (
        CpmAntConfig,
        CpmAntForCausalLM,
        CpmAntModel,
        CpmAntTokenizer,
    )







@require_torch
class 						lowercase:



     def __init__(       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE=2    ,							__SCREAMING_SNAKE_CASE=8    ,							__SCREAMING_SNAKE_CASE=True    ,							__SCREAMING_SNAKE_CASE=False    ,							__SCREAMING_SNAKE_CASE=False    ,							__SCREAMING_SNAKE_CASE=False    ,							__SCREAMING_SNAKE_CASE=False    ,							__SCREAMING_SNAKE_CASE=9_9    ,							__SCREAMING_SNAKE_CASE=3_2    ,							__SCREAMING_SNAKE_CASE=3    ,							__SCREAMING_SNAKE_CASE=4    ,							__SCREAMING_SNAKE_CASE=3_7    ,							__SCREAMING_SNAKE_CASE=3_2    ,							__SCREAMING_SNAKE_CASE=1_2_8    ,							__SCREAMING_SNAKE_CASE=8    ,							__SCREAMING_SNAKE_CASE=8    ,							__SCREAMING_SNAKE_CASE=8    ,							__SCREAMING_SNAKE_CASE=1.0    ,							__SCREAMING_SNAKE_CASE=True    ,							)		->    Optional[int]:







         """simple docstring"""



         a__    = parent
         a__    = batch_size
         a__    = seq_length
         a__    = is_training
         a__    = use_token_type_ids
         a__    = use_input_mask
         a__    = use_labels
         a__    = use_mc_token_ids
         a__    = vocab_size
         a__    = hidden_size
         a__    = num_hidden_layers
         a__    = num_attention_heads
         a__    = intermediate_size
         a__    = num_buckets
         a__    = max_distance
         a__    = prompt_length
         a__    = prompt_types
         a__    = segment_types
         a__    = init_std
         a__    = return_dict



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







         """simple docstring"""



         a__    = {}
         a__    = ids_tensor([self.batch_size, self.seq_length]    ,							self.vocab_size      ).type(torch.intaa      )
         a__    = False

         a__    = self.get_config()

         return (config, input_ids)



     def  lowercase__     (       self      )		->    str:







         """simple docstring"""



         return CpmAntConfig(
             vocab_size=self.vocab_size    ,							hidden_size=self.hidden_size    ,							num_hidden_layers=self.num_hidden_layers    ,							num_attention_heads=self.num_attention_heads    ,							dim_ff=self.intermediate_size    ,							position_bias_num_buckets=self.num_buckets    ,							position_bias_max_distance=self.max_distance    ,							prompt_types=self.prompt_types    ,							prompt_length=self.prompt_length    ,							segment_types=self.segment_types    ,							use_cache=__SCREAMING_SNAKE_CASE    ,							init_std=self.init_std    ,							return_dict=self.return_dict    ,							)



     def  lowercase__     (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							*__SCREAMING_SNAKE_CASE      )		->    Any:







         """simple docstring"""



         a__    = CpmAntModel(config=__SCREAMING_SNAKE_CASE      )
         model.to(__SCREAMING_SNAKE_CASE      )
         model.eval()

         a__    = model(**__SCREAMING_SNAKE_CASE      ).last_hidden_state

         self.parent.assertEqual(hidden_states.shape    ,							(self.batch_size, self.seq_length, config.hidden_size)      )



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







         """simple docstring"""



         a__    = CpmAntForCausalLM(__SCREAMING_SNAKE_CASE      )
         model.to(__SCREAMING_SNAKE_CASE      )
         a__    = input_ids['input_ids'].to(__SCREAMING_SNAKE_CASE      )
         model.eval()

         a__    = model(**__SCREAMING_SNAKE_CASE      )
         self.parent.assertEqual(
             model_output.logits.shape    ,							(self.batch_size, self.seq_length, config.vocab_size + config.prompt_types * config.prompt_length)    ,							)




     def  lowercase__     (       self      )		->    str:







         """simple docstring"""



         a__  ,    a__    = self.prepare_config_and_inputs()
         return config, inputs_dict







@require_torch
class 						lowercase(_lowercase						,	_lowercase						,	unittest.TestCase					):
     __snake_case:  Union[str, Any]  				=    (CpmAntModel, CpmAntForCausalLM) if is_torch_available() else ()
     __snake_case:  List[str]  				=    (
         {'feature-extraction': CpmAntModel, 'text-generation': CpmAntForCausalLM} if is_torch_available() else {}
     )

     __snake_case:  List[str]  				=    False
     __snake_case:  Dict  				=    False
     __snake_case:  Optional[Any]  				=    False
     __snake_case:  Union[str, Any]  				=    False
     __snake_case:  List[Any]  				=    False



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







         """simple docstring"""



         a__    = CpmAntModelTester(self      )
         a__    = ConfigTester(self    ,							config_class=__SCREAMING_SNAKE_CASE      )



     def  lowercase__     (       self      )		->    Dict:







         """simple docstring"""



         self.config_tester.create_and_test_config_common_properties()
         self.config_tester.create_and_test_config_to_json_string()
         self.config_tester.create_and_test_config_to_json_file()
         self.config_tester.create_and_test_config_from_and_save_pretrained()
         self.config_tester.check_config_can_be_init_without_params()
         self.config_tester.check_config_arguments_init()



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







         """simple docstring"""



         unittest.skip('CPMAnt doesn\'t support input_embeds.'      )(self.test_inputs_embeds      )



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







         """simple docstring"""



         unittest.skip(
             'CPMAnt doesn\'t support retain grad in hidden_states or attentions, because prompt management will peel off the output.hidden_states from graph.\
                 So is attentions. We strongly recommand you use loss to tune model.'      )(self.test_retain_grad_hidden_states_attentions      )



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







         """simple docstring"""



         a__  ,    a__    = self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_cpmant_model(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )




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







         """simple docstring"""



         a__  ,    a__    = self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_lm_head_model(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )







@require_torch
class 						lowercase(unittest.TestCase					):



     @tooslow
     def  lowercase__     (       self      )		->    Any:







         """simple docstring"""



         a__    = '今天天气真好！'
         a__    = 'openbmb/cpm-ant-10b'
         a__    = CpmAntModel.from_pretrained(__SCREAMING_SNAKE_CASE      )
         a__    = CpmAntTokenizer.from_pretrained(__SCREAMING_SNAKE_CASE      )
         a__    = tokenizer(__SCREAMING_SNAKE_CASE    ,							return_tensors='pt'      )
         a__    = model(**__SCREAMING_SNAKE_CASE      ).last_hidden_state

         a__    = torch.tensor(
             [[[6.17_08, 5.92_44, 1.08_35], [6.52_07, 6.28_93, -11.33_24], [-1.01_07, -0.05_76, -5.95_77]]]    ,							)
         self.assertTrue(torch.allclose(hidden_states[:, :3, :3]    ,							__SCREAMING_SNAKE_CASE    ,							atol=1e-2      )      )







@require_torch
class 						lowercase(unittest.TestCase					):



     @tooslow
     def  lowercase__     (       self      )		->    Any:







         """simple docstring"""



         a__    = '今天天气真好！'
         a__    = 'openbmb/cpm-ant-10b'
         a__    = CpmAntForCausalLM.from_pretrained(__SCREAMING_SNAKE_CASE      )
         a__    = CpmAntTokenizer.from_pretrained(__SCREAMING_SNAKE_CASE      )
         a__    = tokenizer(__SCREAMING_SNAKE_CASE    ,							return_tensors='pt'      )
         a__    = model(**__SCREAMING_SNAKE_CASE      ).logits

         a__    = torch.tensor(
             [[[-6.42_67, -6.40_83, -6.39_58], [-5.88_02, -5.94_47, -5.78_11], [-5.38_96, -5.48_20, -5.42_95]]]    ,							)
         self.assertTrue(torch.allclose(hidden_states[:, :3, :3]    ,							__SCREAMING_SNAKE_CASE    ,							atol=1e-2      )      )



     @tooslow
     def  lowercase__     (       self      )		->    Dict:







         """simple docstring"""



         a__    = 'openbmb/cpm-ant-10b'
         a__    = CpmAntForCausalLM.from_pretrained(__SCREAMING_SNAKE_CASE      )
         a__    = CpmAntTokenizer.from_pretrained(__SCREAMING_SNAKE_CASE      )
         a__    = '今天天气不错，'
         a__    = '今天天气不错，阳光明媚，我和妈妈一起去超市买东西。\n在超市里，我看到了一个很好玩的玩具，它的名字叫“机器人”。它有一个圆圆的脑袋，两只圆圆的眼睛，还有一个圆圆的'
         a__    = tokenizer(__SCREAMING_SNAKE_CASE    ,							return_tensors='pt'      )
         a__    = model.generate(**__SCREAMING_SNAKE_CASE      )
         a__    = tokenizer.batch_decode(__SCREAMING_SNAKE_CASE      )
         self.assertEqual(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )




     @tooslow
     def  lowercase__     (       self      )		->    Any:







         """simple docstring"""



         a__    = 'openbmb/cpm-ant-10b'
         a__    = CpmAntForCausalLM.from_pretrained(__SCREAMING_SNAKE_CASE      )
         a__    = CpmAntTokenizer.from_pretrained(__SCREAMING_SNAKE_CASE      )
         a__    = ['今天天气不错，', '新年快乐，万事如意！']
         a__    = [
             '今天天气不错，阳光明媚，我和妈妈一起去超市买东西。\n在超市里，我看到了一个很好玩的玩具，它的名字叫“机器人”。它有一个圆圆的脑袋，两只圆圆的眼睛，还有一个圆圆的',
             '新年快乐，万事如意！在这辞旧迎新的美好时刻，我谨代表《农村新技术》杂志社全体同仁，向一直以来关心、支持《农村新技术》杂志发展的各级领导、各界朋友和广大读者致以最诚挚的',
         ]
         a__    = tokenizer(__SCREAMING_SNAKE_CASE    ,							return_tensors='pt'    ,							padding=__SCREAMING_SNAKE_CASE      )
         a__    = model.generate(**__SCREAMING_SNAKE_CASE      )
         a__    = tokenizer.batch_decode(__SCREAMING_SNAKE_CASE      )
         self.assertEqual(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE      )




"""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() = }''')


