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



							"""simple docstring"""






							def __init__(						self						:List[Any]  ,							lowerCamelCase_						:List[Any]  ,							lowerCamelCase_						:Dict=2  ,							lowerCamelCase_						:Optional[Any]=8  ,							lowerCamelCase_						:str=True  ,							lowerCamelCase_						:Dict=False  ,							lowerCamelCase_						:List[Any]=False  ,							lowerCamelCase_						:str=False  ,							lowerCamelCase_						:Dict=False  ,							lowerCamelCase_						:Dict=99  ,							lowerCamelCase_						:Union[str, Any]=32  ,							lowerCamelCase_						:int=3  ,							lowerCamelCase_						:Dict=4  ,							lowerCamelCase_						:List[Any]=37  ,							lowerCamelCase_						:Optional[Any]=32  ,							lowerCamelCase_						:Optional[int]=128  ,							lowerCamelCase_						:List[Any]=8  ,							lowerCamelCase_						:Optional[int]=8  ,							lowerCamelCase_						:str=8  ,							lowerCamelCase_						:List[Any]=1.0  ,							lowerCamelCase_						:Any=True  ,							):





										"""simple docstring"""

										lowerCamelCase__			:  int  =parent
										lowerCamelCase__			:  Optional[Any]  =batch_size
										lowerCamelCase__			:  str  =seq_length
										lowerCamelCase__			:  Union[str, Any]  =is_training
										lowerCamelCase__			:  Dict  =use_token_type_ids
										lowerCamelCase__			:  Union[str, Any]  =use_input_mask
										lowerCamelCase__			:  Any  =use_labels
										lowerCamelCase__			:  str  =use_mc_token_ids
										lowerCamelCase__			:  List[str]  =vocab_size
										lowerCamelCase__			:  Tuple  =hidden_size
										lowerCamelCase__			:  Optional[int]  =num_hidden_layers
										lowerCamelCase__			:  Any  =num_attention_heads
										lowerCamelCase__			:  int  =intermediate_size
										lowerCamelCase__			:  List[str]  =num_buckets
										lowerCamelCase__			:  Dict  =max_distance
										lowerCamelCase__			:  Tuple  =prompt_length
										lowerCamelCase__			:  List[str]  =prompt_types
										lowerCamelCase__			:  List[Any]  =segment_types
										lowerCamelCase__			:  Optional[Any]  =init_std
										lowerCamelCase__			:  Any  =return_dict





							def    UpperCAmelCase__							(						self						:Optional[int] ):





										"""simple docstring"""

										lowerCamelCase__			:  str  ={}
										lowerCamelCase__			:  List[Any]  =ids_tensor([self.batch_size, self.seq_length]  ,							self.vocab_size ).type(torch.intaa )
										lowerCamelCase__			:  Dict  =False

										lowerCamelCase__			:  Optional[Any]  =self.get_config()

										return (config, input_ids)





							def    UpperCAmelCase__							(						self						:Union[str, Any] ):





										"""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=lowerCamelCase_  ,							init_std=self.init_std  ,							return_dict=self.return_dict  ,							)





							def    UpperCAmelCase__							(						self						:Union[str, Any]  ,							lowerCamelCase_						:int  ,							lowerCamelCase_						:Dict  ,							*lowerCamelCase_						:List[Any] ):





										"""simple docstring"""

										lowerCamelCase__			:  Union[str, Any]  =CpmAntModel(config=lowerCamelCase_ )
										model.to(lowerCamelCase_ )
										model.eval()

										lowerCamelCase__			:  List[str]  =model(**lowerCamelCase_ ).last_hidden_state

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





							def    UpperCAmelCase__							(						self						:Dict  ,							lowerCamelCase_						:int  ,							lowerCamelCase_						:Optional[Any]  ,							*lowerCamelCase_						:Any ):





										"""simple docstring"""

										lowerCamelCase__			:  Any  =CpmAntForCausalLM(lowerCamelCase_ )
										model.to(lowerCamelCase_ )
										lowerCamelCase__			:  Tuple  =input_ids['input_ids'].to(lowerCamelCase_ )
										model.eval()

										lowerCamelCase__			:  Dict  =model(**lowerCamelCase_ )
										self.parent.assertEqual(
										    model_output.logits.shape  ,							(self.batch_size, self.seq_length, config.vocab_size + config.prompt_types * config.prompt_length)  ,							)





							def    UpperCAmelCase__							(						self						:str ):





										"""simple docstring"""

										lowerCamelCase__ ,       lowerCamelCase__			:  Any  =self.prepare_config_and_inputs()
										return config, inputs_dict






@require_torch
class 					A_			(  A__   ,      A__   ,      unittest.TestCase     ):



							"""simple docstring"""






							SCREAMING_SNAKE_CASE_			   =     (CpmAntModel, CpmAntForCausalLM) if is_torch_available() else ()
							SCREAMING_SNAKE_CASE_			   =     (
							    {"""feature-extraction""": CpmAntModel, """text-generation""": CpmAntForCausalLM} if is_torch_available() else {}
							)

							SCREAMING_SNAKE_CASE_			   =     False
							SCREAMING_SNAKE_CASE_			   =     False
							SCREAMING_SNAKE_CASE_			   =     False
							SCREAMING_SNAKE_CASE_			   =     False
							SCREAMING_SNAKE_CASE_			   =     False





							def    UpperCAmelCase__							(						self						:Tuple ):





										"""simple docstring"""

										lowerCamelCase__			:  Tuple  =CpmAntModelTester(self )
										lowerCamelCase__			:  List[str]  =ConfigTester(self  ,							config_class=lowerCamelCase_ )





							def    UpperCAmelCase__							(						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    UpperCAmelCase__							(						self						:Any ):





										"""simple docstring"""

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





							def    UpperCAmelCase__							(						self						:Union[str, 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    UpperCAmelCase__							(						self						:Dict ):





										"""simple docstring"""

										lowerCamelCase__ ,       lowerCamelCase__			:  Any  =self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_cpmant_model(lowerCamelCase_  ,							lowerCamelCase_ )





							def    UpperCAmelCase__							(						self						:List[Any] ):





										"""simple docstring"""

										lowerCamelCase__ ,       lowerCamelCase__			:  Optional[int]  =self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_lm_head_model(lowerCamelCase_  ,							lowerCamelCase_ )






@require_torch
class 					A_			(  unittest.TestCase     ):



							"""simple docstring"""






							@tooslow
							def    UpperCAmelCase__							(						self						:Tuple ):





										"""simple docstring"""

										lowerCamelCase__			:  int  ='今天天气真好！'
										lowerCamelCase__			:  Dict  ='openbmb/cpm-ant-10b'
										lowerCamelCase__			:  Any  =CpmAntModel.from_pretrained(lowerCamelCase_ )
										lowerCamelCase__			:  Dict  =CpmAntTokenizer.from_pretrained(lowerCamelCase_ )
										lowerCamelCase__			:  Optional[Any]  =tokenizer(lowerCamelCase_  ,							return_tensors='pt' )
										lowerCamelCase__			:  int  =model(**lowerCamelCase_ ).last_hidden_state

										lowerCamelCase__			:  Optional[int]  =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]  ,							lowerCamelCase_  ,							atol=1e-2 ) )






@require_torch
class 					A_			(  unittest.TestCase     ):



							"""simple docstring"""






							@tooslow
							def    UpperCAmelCase__							(						self						:str ):





										"""simple docstring"""

										lowerCamelCase__			:  Optional[Any]  ='今天天气真好！'
										lowerCamelCase__			:  List[str]  ='openbmb/cpm-ant-10b'
										lowerCamelCase__			:  Optional[int]  =CpmAntForCausalLM.from_pretrained(lowerCamelCase_ )
										lowerCamelCase__			:  Optional[int]  =CpmAntTokenizer.from_pretrained(lowerCamelCase_ )
										lowerCamelCase__			:  Dict  =tokenizer(lowerCamelCase_  ,							return_tensors='pt' )
										lowerCamelCase__			:  Optional[Any]  =model(**lowerCamelCase_ ).logits

										lowerCamelCase__			:  Union[str, Any]  =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]  ,							lowerCamelCase_  ,							atol=1e-2 ) )





							@tooslow
							def    UpperCAmelCase__							(						self						:Union[str, Any] ):





										"""simple docstring"""

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





							@tooslow
							def    UpperCAmelCase__							(						self						:Union[str, Any] ):





										"""simple docstring"""

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

"""simple docstring"""


from sklearn.neural_network import MLPClassifier

lowerCAmelCase			=		[[0.0, 0.0], [1.0, 1.0], [1.0, 0.0], [0.0, 1.0]]
lowerCAmelCase			=		[0, 1, 0, 0]


lowerCAmelCase			=		MLPClassifier(
    solver="""lbfgs""", alpha=1E-5, hidden_layer_sizes=(5, 2), random_state=1
)

clf.fit(X, y)


lowerCAmelCase			=		[[0.0, 0.0], [0.0, 1.0], [1.0, 1.0]]
lowerCAmelCase			=		clf.predict(test)






def      lowerCAmelCase_     (	snake_case_	:    Tuple    )     ->List[Any]:
			return list(snake_case_    )


if __name__ == "__main__":
							import doctest

							doctest.testmod()