


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

     def 					lowerCamelCase__					(							self	:						List[str]     )		->				Tuple:
          __UpperCAmelCase      :					Any    				=     {}
          __UpperCAmelCase      :					Dict    				=     ids_tensor([self.batch_size, self.seq_length]				,					self.vocab_size     ).type(torch.intaa     )
          __UpperCAmelCase      :					Optional[int]    				=     False

          __UpperCAmelCase      :					str    				=     self.get_config()

          return (config, input_ids)

     def 					lowerCamelCase__					(							self	:						Any     )		->				List[Any]:
          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=snake_case				,					init_std=self.init_std				,					return_dict=self.return_dict				,					)

     def 					lowerCamelCase__					(							self	:						Dict				,					snake_case	:						List[str]				,					snake_case	:						Any				,					*snake_case	:						Union[str, Any]     )		->				Tuple:
          __UpperCAmelCase      :					List[str]    				=     CpmAntModel(config=snake_case     )
          model.to(snake_case     )
          model.eval()

          __UpperCAmelCase      :					Tuple    				=     model(**snake_case     ).last_hidden_state

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

     def 					lowerCamelCase__					(							self	:						int				,					snake_case	:						Optional[int]				,					snake_case	:						Tuple				,					*snake_case	:						str     )		->				Optional[int]:
          __UpperCAmelCase      :					int    				=     CpmAntForCausalLM(snake_case     )
          model.to(snake_case     )
          __UpperCAmelCase      :					List[Any]    				=     input_ids['''input_ids'''].to(snake_case     )
          model.eval()

          __UpperCAmelCase      :					Tuple    				=     model(**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 					lowerCamelCase__					(							self	:						Tuple     )		->				int:
          __UpperCAmelCase				,  __UpperCAmelCase      :					Any    				=     self.prepare_config_and_inputs()
          return config, inputs_dict



@require_torch
class       a							(						_a      ,    _a      ,    unittest.TestCase			):


     """simple docstring"""






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

     SCREAMING_SNAKE_CASE			:					List[Any]				  =  False
     SCREAMING_SNAKE_CASE			:					Optional[int]				  =  False
     SCREAMING_SNAKE_CASE			:					Tuple				  =  False
     SCREAMING_SNAKE_CASE			:					List[str]				  =  False
     SCREAMING_SNAKE_CASE			:					List[str]				  =  False

     def 					lowerCamelCase__					(							self	:						Optional[Any]     )		->				List[Any]:
          __UpperCAmelCase      :					Tuple    				=     CpmAntModelTester(self     )
          __UpperCAmelCase      :					List[Any]    				=     ConfigTester(self				,					config_class=snake_case     )

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

     def 					lowerCamelCase__					(							self	:						int     )		->				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	:						List[Any]     )		->				int:
          __UpperCAmelCase				,  __UpperCAmelCase      :					Optional[Any]    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_cpmant_model(snake_case				,					snake_case     )






     def 					lowerCamelCase__					(							self	:						Dict     )		->				Tuple:
          __UpperCAmelCase				,  __UpperCAmelCase      :					Optional[int]    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_lm_head_model(snake_case				,					snake_case     )



@require_torch
class       a							(						unittest.TestCase			):


     """simple docstring"""






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

          __UpperCAmelCase      :					List[str]    				=     torch.tensor(
              [[[6.1_708, 5.9_244, 1.0_835], [6.5_207, 6.2_893, -11.3_324], [-1.0_107, -0.0_576, -5.9_577]]]				,					)
          self.assertTrue(torch.allclose(hidden_states[:, :3, :3]				,					snake_case				,					atol=1E-2     )     )



@require_torch
class       a							(						unittest.TestCase			):


     """simple docstring"""






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

          __UpperCAmelCase      :					Dict    				=     torch.tensor(
              [[[-6.4_267, -6.4_083, -6.3_958], [-5.8_802, -5.9_447, -5.7_811], [-5.3_896, -5.4_820, -5.4_295]]]				,					)
          self.assertTrue(torch.allclose(hidden_states[:, :3, :3]				,					snake_case				,					atol=1E-2     )     )

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






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



'''simple docstring'''



import math
from decimal import Decimal, getcontext




def       _a      (		_lowercase   :      int = 4000000    ):





     '''simple docstring'''






     try:
          __UpperCAmelCase      :					List[str]    				=     int(_lowercase    )
     except (TypeError, ValueError):
          raise TypeError('''Parameter n must be int or castable to int.'''    )
     if n <= 0:
          raise ValueError('''Parameter n must be greater than or equal to one.'''    )
     __UpperCAmelCase      :					Tuple    				=     100
     __UpperCAmelCase      :					Optional[Any]    				=     (Decimal(5    ) ** Decimal(0.5    ) + 1) / Decimal(2    )

     __UpperCAmelCase      :					Tuple    				=     (math.floor(math.log(n * (phi + 2)     ,   _lowercase    ) - 1    ) // 3) * 3 + 2
     __UpperCAmelCase      :					List[Any]    				=     Decimal(round(phi ** Decimal(index + 1    )    )    ) / (phi + 2)
     __UpperCAmelCase      :					List[str]    				=     num // 2
     return int(_lowercase    )


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