

"""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[str]    ,	lowercase_  :       Union[str, Any]    ,	lowercase_  :       List[Any]=2    ,	lowercase_  :       str=8    ,	lowercase_  :       Dict=True    ,	lowercase_  :       Optional[Any]=False    ,	lowercase_  :       int=False    ,	lowercase_  :       Optional[int]=False    ,	lowercase_  :       List[Any]=False    ,	lowercase_  :       Optional[int]=99    ,	lowercase_  :       Optional[int]=32    ,	lowercase_  :       str=3    ,	lowercase_  :       Optional[int]=4    ,	lowercase_  :       Tuple=37    ,	lowercase_  :       Optional[int]=32    ,	lowercase_  :       List[Any]=128    ,	lowercase_  :       List[Any]=8    ,	lowercase_  :       Optional[Any]=8    ,	lowercase_  :       List[Any]=8    ,	lowercase_  :       Any=1.0    ,	lowercase_  :       Optional[Any]=True    ,	):
								UpperCamelCase__		:     int								=parent
								UpperCamelCase__		:     Union[str, Any]								=batch_size
								UpperCamelCase__		:     List[Any]								=seq_length
								UpperCamelCase__		:     Union[str, Any]								=is_training
								UpperCamelCase__		:     int								=use_token_type_ids
								UpperCamelCase__		:     Optional[Any]								=use_input_mask
								UpperCamelCase__		:     Tuple								=use_labels
								UpperCamelCase__		:     str								=use_mc_token_ids
								UpperCamelCase__		:     Dict								=vocab_size
								UpperCamelCase__		:     Any								=hidden_size
								UpperCamelCase__		:     Optional[int]								=num_hidden_layers
								UpperCamelCase__		:     Union[str, Any]								=num_attention_heads
								UpperCamelCase__		:     Dict								=intermediate_size
								UpperCamelCase__		:     str								=num_buckets
								UpperCamelCase__		:     Any								=max_distance
								UpperCamelCase__		:     Optional[Any]								=prompt_length
								UpperCamelCase__		:     int								=prompt_types
								UpperCamelCase__		:     Optional[int]								=segment_types
								UpperCamelCase__		:     Any								=init_std
								UpperCamelCase__		:     Dict								=return_dict






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

								UpperCamelCase__		:     Tuple								=self.get_config()

								return (config, input_ids)






			def  _lowerCAmelCase      (				self  :       List[str]    ):
								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=lowercase_    ,	init_std=self.init_std    ,	return_dict=self.return_dict    ,	)






			def  _lowerCAmelCase      (				self  :       Tuple    ,	lowercase_  :       Optional[Any]    ,	lowercase_  :       Any    ,	*lowercase_  :       List[Any]    ):
								UpperCamelCase__		:     Tuple								=CpmAntModel(config=lowercase_    )
								model.to(lowercase_    )
								model.eval()

								UpperCamelCase__		:     Dict								=model(**lowercase_    ).last_hidden_state

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






			def  _lowerCAmelCase      (				self  :       int    ,	lowercase_  :       int    ,	lowercase_  :       int    ,	*lowercase_  :       Dict    ):
								UpperCamelCase__		:     Union[str, Any]								=CpmAntForCausalLM(lowercase_    )
								model.to(lowercase_    )
								UpperCamelCase__		:     int								=input_ids['''input_ids'''].to(lowercase_    )
								model.eval()

								UpperCamelCase__		:     Tuple								=model(**lowercase_    )
								self.parent.assertEqual(
								    model_output.logits.shape    ,	(self.batch_size, self.seq_length, config.vocab_size + config.prompt_types * config.prompt_length)    ,	)






			def  _lowerCAmelCase      (				self  :       Tuple    ):
								UpperCamelCase__	,      UpperCamelCase__		:     Tuple								=self.prepare_config_and_inputs()
								return config, inputs_dict



@require_torch
class      __a (   snake_case__,     snake_case__,     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  _lowerCAmelCase      (				self  :       str    ):
								UpperCamelCase__		:     Any								=CpmAntModelTester(self    )
								UpperCamelCase__		:     Optional[Any]								=ConfigTester(self    ,	config_class=lowercase_    )






			def  _lowerCAmelCase      (				self  :       List[Any]    ):
								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  _lowerCAmelCase      (				self  :       List[str]    ):
								unittest.skip('''CPMAnt doesn\'t support input_embeds.'''    )(self.test_inputs_embeds    )






			def  _lowerCAmelCase      (				self  :       List[Any]    ):
								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  _lowerCAmelCase      (				self  :       Any    ):
								UpperCamelCase__	,      UpperCamelCase__		:     List[Any]								=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_cpmant_model(lowercase_    ,	lowercase_    )






			def  _lowerCAmelCase      (				self  :       Optional[Any]    ):
								UpperCamelCase__	,      UpperCamelCase__		:     Union[str, Any]								=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_lm_head_model(lowercase_    ,	lowercase_    )



@require_torch
class      __a (   unittest.TestCase     ):

			"""simple docstring"""

			@tooslow
			def  _lowerCAmelCase      (				self  :       Optional[Any]    ):
								UpperCamelCase__		:     List[Any]								='''今天天气真好！'''
								UpperCamelCase__		:     int								='''openbmb/cpm-ant-10b'''
								UpperCamelCase__		:     int								=CpmAntModel.from_pretrained(lowercase_    )
								UpperCamelCase__		:     List[Any]								=CpmAntTokenizer.from_pretrained(lowercase_    )
								UpperCamelCase__		:     Any								=tokenizer(lowercase_    ,	return_tensors='''pt'''    )
								UpperCamelCase__		:     List[Any]								=model(**lowercase_    ).last_hidden_state

								UpperCamelCase__		:     List[Any]								=torch.tensor(
								    [[[6.1_7_0_8, 5.9_2_4_4, 1.0_8_3_5], [6.5_2_0_7, 6.2_8_9_3, -1_1.3_3_2_4], [-1.0_1_0_7, -0.0_5_7_6, -5.9_5_7_7]]]    ,	)
								self.assertTrue(torch.allclose(hidden_states[:, :3, :3]    ,	lowercase_    ,	atol=1e-2    )    )



@require_torch
class      __a (   unittest.TestCase     ):

			"""simple docstring"""

			@tooslow
			def  _lowerCAmelCase      (				self  :       Union[str, Any]    ):
								UpperCamelCase__		:     int								='''今天天气真好！'''
								UpperCamelCase__		:     Any								='''openbmb/cpm-ant-10b'''
								UpperCamelCase__		:     Any								=CpmAntForCausalLM.from_pretrained(lowercase_    )
								UpperCamelCase__		:     Optional[Any]								=CpmAntTokenizer.from_pretrained(lowercase_    )
								UpperCamelCase__		:     List[str]								=tokenizer(lowercase_    ,	return_tensors='''pt'''    )
								UpperCamelCase__		:     List[str]								=model(**lowercase_    ).logits

								UpperCamelCase__		:     int								=torch.tensor(
								    [[[-6.4_2_6_7, -6.4_0_8_3, -6.3_9_5_8], [-5.8_8_0_2, -5.9_4_4_7, -5.7_8_1_1], [-5.3_8_9_6, -5.4_8_2_0, -5.4_2_9_5]]]    ,	)
								self.assertTrue(torch.allclose(hidden_states[:, :3, :3]    ,	lowercase_    ,	atol=1e-2    )    )






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






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





"""simple docstring"""





from __future__ import annotations



def 							_lowerCAmelCase   (    UpperCAmelCase  :				list[int]   ,				UpperCAmelCase  :				int					):


					'''simple docstring'''






					UpperCamelCase__		:     dict[int, int]								={}
					for index, val in enumerate(UpperCAmelCase					):
										UpperCamelCase__		:     List[Any]								=target - val
										if compl in chk_map:
															return [chk_map[compl], index]
										UpperCamelCase__		:     Any								=index
					return []


if __name__ == "__main__":
				import doctest

				doctest.testmod()
				print(F'''{two_sum([2, 7, 1_1, 1_5], 9) = }''')


