code: 
  
  '''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 __UpperCamelCase    :
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					def __init__(							self							,			lowerCamelCase__							,			lowerCamelCase__=2							,			lowerCamelCase__=8							,			lowerCamelCase__=True							,			lowerCamelCase__=False							,			lowerCamelCase__=False							,			lowerCamelCase__=False							,			lowerCamelCase__=False							,			lowerCamelCase__=9_9							,			lowerCamelCase__=3_2							,			lowerCamelCase__=3							,			lowerCamelCase__=4							,			lowerCamelCase__=3_7							,			lowerCamelCase__=3_2							,			lowerCamelCase__=1_2_8							,			lowerCamelCase__=8							,			lowerCamelCase__=8							,			lowerCamelCase__=8							,			lowerCamelCase__=1.0							,			lowerCamelCase__=True							,			):
  						UpperCAmelCase__:  Optional[Any]		       =   parent
  						UpperCAmelCase__:  int		       =   batch_size
  						UpperCAmelCase__:  Optional[Any]		       =   seq_length
  						UpperCAmelCase__:  List[str]		       =   is_training
  						UpperCAmelCase__:  str		       =   use_token_type_ids
  						UpperCAmelCase__:  List[Any]		       =   use_input_mask
  						UpperCAmelCase__:  Dict		       =   use_labels
  						UpperCAmelCase__:  Optional[int]		       =   use_mc_token_ids
  						UpperCAmelCase__:  Union[str, Any]		       =   vocab_size
  						UpperCAmelCase__:  Dict		       =   hidden_size
  						UpperCAmelCase__:  List[str]		       =   num_hidden_layers
  						UpperCAmelCase__:  Tuple		       =   num_attention_heads
  						UpperCAmelCase__:  List[Any]		       =   intermediate_size
  						UpperCAmelCase__:  Union[str, Any]		       =   num_buckets
  						UpperCAmelCase__:  str		       =   max_distance
  						UpperCAmelCase__:  Union[str, Any]		       =   prompt_length
  						UpperCAmelCase__:  Tuple		       =   prompt_types
  						UpperCAmelCase__:  int		       =   segment_types
  						UpperCAmelCase__:  Any		       =   init_std
  						UpperCAmelCase__:  List[str]		       =   return_dict
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  int		       =   {}
  						UpperCAmelCase__:  Optional[int]		       =   ids_tensor([self.batch_size, self.seq_length]							,			self.vocab_size	).type(torch.intaa	)
  						UpperCAmelCase__:  List[Any]		       =   False
  
  						UpperCAmelCase__:  List[str]		       =   self.get_config()
  
  						return (config, input_ids)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						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							,			lowerCamelCase__							,			lowerCamelCase__							,			*lowerCamelCase__	):
  						UpperCAmelCase__:  Optional[Any]		       =   CpmAntModel(config=lowerCamelCase__	)
  						model.to(lowerCamelCase__	)
  						model.eval()
  
  						UpperCAmelCase__:  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							,			lowerCamelCase__							,			lowerCamelCase__							,			*lowerCamelCase__	):
  						UpperCAmelCase__:  Tuple		       =   CpmAntForCausalLM(lowerCamelCase__	)
  						model.to(lowerCamelCase__	)
  						UpperCAmelCase__:  int		       =   input_ids["input_ids"].to(lowerCamelCase__	)
  						model.eval()
  
  						UpperCAmelCase__:  str		       =   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	):
  						UpperCAmelCase__:  Any		       =   self.prepare_config_and_inputs()
  						return config, inputs_dict
  
  @require_torch
  class __UpperCamelCase    (							_a				,_a				,unittest.TestCase		):
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					__magic_name__     			=      (CpmAntModel, CpmAntForCausalLM) if is_torch_available() else ()
  					__magic_name__     			=      (
  					    {"feature-extraction": CpmAntModel, "text-generation": CpmAntForCausalLM} if is_torch_available() else {}
  					)
  
  					__magic_name__     			=      False
  					__magic_name__     			=      False
  					__magic_name__     			=      False
  					__magic_name__     			=      False
  					__magic_name__     			=      False
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Tuple		       =   CpmAntModelTester(self	)
  						UpperCAmelCase__:  Dict		       =   ConfigTester(self							,			config_class=lowerCamelCase__	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						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	):
  						unittest.skip("CPMAnt doesn't support input_embeds."	)(self.test_inputs_embeds	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						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	):
  						UpperCAmelCase__:  Optional[int]		       =   self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_cpmant_model(lowerCamelCase__							,			lowerCamelCase__	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  List[Any]		       =   self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_lm_head_model(lowerCamelCase__							,			lowerCamelCase__	)
  
  @require_torch
  class __UpperCamelCase    (							unittest.TestCase		):
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					@tooslow
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Optional[Any]		       =   "今天天气真好！"
  						UpperCAmelCase__:  Optional[int]		       =   "openbmb/cpm-ant-10b"
  						UpperCAmelCase__:  List[Any]		       =   CpmAntModel.from_pretrained(lowerCamelCase__	)
  						UpperCAmelCase__:  Any		       =   CpmAntTokenizer.from_pretrained(lowerCamelCase__	)
  						UpperCAmelCase__:  Union[str, Any]		       =   tokenizer(lowerCamelCase__							,			return_tensors="pt"	)
  						UpperCAmelCase__:  List[Any]		       =   model(**lowerCamelCase__	).last_hidden_state
  
  						UpperCAmelCase__:  Optional[int]		       =   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]							,			lowerCamelCase__							,			atol=1e-2	)	)
  
  @require_torch
  class __UpperCamelCase    (							unittest.TestCase		):
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					@tooslow
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  List[str]		       =   "今天天气真好！"
  						UpperCAmelCase__:  Any		       =   "openbmb/cpm-ant-10b"
  						UpperCAmelCase__:  List[str]		       =   CpmAntForCausalLM.from_pretrained(lowerCamelCase__	)
  						UpperCAmelCase__:  Tuple		       =   CpmAntTokenizer.from_pretrained(lowerCamelCase__	)
  						UpperCAmelCase__:  int		       =   tokenizer(lowerCamelCase__							,			return_tensors="pt"	)
  						UpperCAmelCase__:  str		       =   model(**lowerCamelCase__	).logits
  
  						UpperCAmelCase__:  int		       =   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]							,			lowerCamelCase__							,			atol=1e-2	)	)
  
  
  
  
  
  					@tooslow
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Any		       =   "openbmb/cpm-ant-10b"
  						UpperCAmelCase__:  Tuple		       =   CpmAntForCausalLM.from_pretrained(lowerCamelCase__	)
  						UpperCAmelCase__:  str		       =   CpmAntTokenizer.from_pretrained(lowerCamelCase__	)
  						UpperCAmelCase__:  int		       =   "今天天气不错，"
  						UpperCAmelCase__:  Tuple		       =   "今天天气不错，阳光明媚，我和妈妈一起去超市买东西。\n在超市里，我看到了一个很好玩的玩具，它的名字叫“机器人”。它有一个圆圆的脑袋，两只圆圆的眼睛，还有一个圆圆的"
  						UpperCAmelCase__:  Dict		       =   tokenizer(lowerCamelCase__							,			return_tensors="pt"	)
  						UpperCAmelCase__:  Tuple		       =   model.generate(**lowerCamelCase__	)
  						UpperCAmelCase__:  Union[str, Any]		       =   tokenizer.batch_decode(lowerCamelCase__	)
  						self.assertEqual(lowerCamelCase__							,			lowerCamelCase__	)
  
  
  
  
  
  					@tooslow
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Any		       =   "openbmb/cpm-ant-10b"
  						UpperCAmelCase__:  Union[str, Any]		       =   CpmAntForCausalLM.from_pretrained(lowerCamelCase__	)
  						UpperCAmelCase__:  List[str]		       =   CpmAntTokenizer.from_pretrained(lowerCamelCase__	)
  						UpperCAmelCase__:  Optional[int]		       =   ["今天天气不错，", "新年快乐，万事如意！"]
  						UpperCAmelCase__:  List[str]		       =   [
  						    "今天天气不错，阳光明媚，我和妈妈一起去超市买东西。\n在超市里，我看到了一个很好玩的玩具，它的名字叫“机器人”。它有一个圆圆的脑袋，两只圆圆的眼睛，还有一个圆圆的",
  						    "新年快乐，万事如意！在这辞旧迎新的美好时刻，我谨代表《农村新技术》杂志社全体同仁，向一直以来关心、支持《农村新技术》杂志发展的各级领导、各界朋友和广大读者致以最诚挚的",
  						]
  						UpperCAmelCase__:  List[Any]		       =   tokenizer(lowerCamelCase__							,			return_tensors="pt"							,			padding=lowerCamelCase__	)
  						UpperCAmelCase__:  List[Any]		       =   model.generate(**lowerCamelCase__	)
  						UpperCAmelCase__:  int		       =   tokenizer.batch_decode(lowerCamelCase__	)
  						self.assertEqual(lowerCamelCase__							,			lowerCamelCase__	)
style_context: 
  
  import numpy as np
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE			):
  	UpperCAmelCase__:  List[Any]		       =   np.exp(SCREAMING_SNAKE_CASE			)
  
  	# Add up the all the exponentials
  	UpperCAmelCase__:  str		       =   np.sum(SCREAMING_SNAKE_CASE			)
  
  	# Divide every exponent by the sum of all exponents
  	UpperCAmelCase__:  Tuple		       =   exponent_vector / sum_of_exponents
  
  	return softmax_vector
  
  
  if __name__ == "__main__":
  					print(softmax((0,)))