



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



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


     '''simple docstring'''




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



  def 		lowerCamelCase__    (  self	:   str						)       ->   Optional[Any]:


     '''simple docstring'''




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

     SCREAMING_SNAKE_CASE_:	List[Any]            =self.get_config()

     return (config, input_ids)



  def 		lowerCamelCase__    (  self	:   str						)       ->   Optional[int]:


     '''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 		lowerCamelCase__    (  self	:   Any    ,						lowerCAmelCase	:   Tuple    ,						lowerCAmelCase	:   Any    ,						*lowerCAmelCase	:   Any						)       ->   Union[str, Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:	str            =CpmAntModel(config=lowerCAmelCase						)
     model.to(lowerCAmelCase						)
     model.eval()

     SCREAMING_SNAKE_CASE_:	Dict            =model(**lowerCAmelCase						).last_hidden_state

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



  def 		lowerCamelCase__    (  self	:   List[Any]    ,						lowerCAmelCase	:   str    ,						lowerCAmelCase	:   List[Any]    ,						*lowerCAmelCase	:   Tuple						)       ->   Tuple:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:	Optional[int]            =CpmAntForCausalLM(lowerCAmelCase						)
     model.to(lowerCAmelCase						)
     SCREAMING_SNAKE_CASE_:	Any            =input_ids["""input_ids"""].to(lowerCAmelCase						)
     model.eval()

     SCREAMING_SNAKE_CASE_:	List[Any]            =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 		lowerCamelCase__    (  self	:   List[str]						)       ->   Optional[int]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_     ,						SCREAMING_SNAKE_CASE_:	Dict            =self.prepare_config_and_inputs()
     return config, inputs_dict







@require_torch
class    a		(					UpperCAmelCase__		, UpperCAmelCase__		, unittest.TestCase    ):
  UpperCamelCase		:			Dict         =   (CpmAntModel, CpmAntForCausalLM) if is_torch_available() else ()
  UpperCamelCase		:			Union[str, Any]         =   (
      {'feature-extraction': CpmAntModel, 'text-generation': CpmAntForCausalLM} if is_torch_available() else {}
  )

  UpperCamelCase		:			Tuple         =   False
  UpperCamelCase		:			List[Any]         =   False
  UpperCamelCase		:			Optional[int]         =   False
  UpperCamelCase		:			Dict         =   False
  UpperCamelCase		:			Union[str, Any]         =   False



  def 		lowerCamelCase__    (  self	:   List[str]						)       ->   Any:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_:	str            =CpmAntModelTester(self						)
     SCREAMING_SNAKE_CASE_:	List[Any]            =ConfigTester(self    ,						config_class=lowerCAmelCase						)



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


     '''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 		lowerCamelCase__    (  self	:   List[str]						)       ->   Optional[int]:


     '''simple docstring'''




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



  def 		lowerCamelCase__    (  self	:   Any						)       ->   int:


     '''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 		lowerCamelCase__    (  self	:   int						)       ->   List[str]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_     ,						SCREAMING_SNAKE_CASE_:	Union[str, Any]            =self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_cpmant_model(lowerCAmelCase    ,						lowerCAmelCase						)





  def 		lowerCamelCase__    (  self	:   Tuple						)       ->   Optional[int]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_     ,						SCREAMING_SNAKE_CASE_:	List[Any]            =self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_lm_head_model(lowerCAmelCase    ,						lowerCAmelCase						)







@require_torch
class    a		(					unittest.TestCase    ):



  @tooslow
  def 		lowerCamelCase__    (  self	:   List[str]						)       ->   Dict:


     '''simple docstring'''




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

     SCREAMING_SNAKE_CASE_:	Union[str, 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]    ,						lowerCAmelCase    ,						atol=1E-2						)						)







@require_torch
class    a		(					unittest.TestCase    ):



  @tooslow
  def 		lowerCamelCase__    (  self	:   Union[str, Any]						)       ->   Dict:


     '''simple docstring'''




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

     SCREAMING_SNAKE_CASE_:	Optional[Any]            =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]    ,						lowerCAmelCase    ,						atol=1E-2						)						)



  @tooslow
  def 		lowerCamelCase__    (  self	:   str						)       ->   str:


     '''simple docstring'''




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





  @tooslow
  def 		lowerCamelCase__    (  self	:   Tuple						)       ->   List[Any]:


     '''simple docstring'''




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








"""simple docstring"""
def        __magic_name__			(							lowercase = 1000	):
   SCREAMING_SNAKE_CASE_:	Dict            =0
   SCREAMING_SNAKE_CASE_:	Any            =0
   while 1:
      num += 3
      if num >= n:
         break
      total += num
      num += 2
      if num >= n:
         break
      total += num
      num += 1
      if num >= n:
         break
      total += num
      num += 3
      if num >= n:
         break
      total += num
      num += 1
      if num >= n:
         break
      total += num
      num += 2
      if num >= n:
         break
      total += num
      num += 3
      if num >= n:
         break
      total += num
   return total


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



