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  ,					_snake_case  ,					_snake_case=2  ,					_snake_case=8  ,					_snake_case=True  ,					_snake_case=False  ,					_snake_case=False  ,					_snake_case=False  ,					_snake_case=False  ,					_snake_case=99  ,					_snake_case=32  ,					_snake_case=3  ,					_snake_case=4  ,					_snake_case=37  ,					_snake_case=32  ,					_snake_case=128  ,					_snake_case=8  ,					_snake_case=8  ,					_snake_case=8  ,					_snake_case=1.0  ,					_snake_case=True  ,					)				->    Optional[Any]:
  				_UpperCamelCase       : Union[str, Any]    =      parent
  				_UpperCamelCase       : Optional[Any]    =      batch_size
  				_UpperCamelCase       : Optional[Any]    =      seq_length
  				_UpperCamelCase       : int    =      is_training
  				_UpperCamelCase       : Optional[Any]    =      use_token_type_ids
  				_UpperCamelCase       : Any    =      use_input_mask
  				_UpperCamelCase       : Optional[int]    =      use_labels
  				_UpperCamelCase       : Optional[Any]    =      use_mc_token_ids
  				_UpperCamelCase       : Any    =      vocab_size
  				_UpperCamelCase       : Union[str, Any]    =      hidden_size
  				_UpperCamelCase       : Dict    =      num_hidden_layers
  				_UpperCamelCase       : Any    =      num_attention_heads
  				_UpperCamelCase       : List[Any]    =      intermediate_size
  				_UpperCamelCase       : str    =      num_buckets
  				_UpperCamelCase       : Tuple    =      max_distance
  				_UpperCamelCase       : Optional[int]    =      prompt_length
  				_UpperCamelCase       : Tuple    =      prompt_types
  				_UpperCamelCase       : Any    =      segment_types
  				_UpperCamelCase       : Optional[Any]    =      init_std
  				_UpperCamelCase       : List[str]    =      return_dict
  		def _lowercase  (    self     )				->    List[str]:
  				_UpperCamelCase       : Optional[Any]    =      {}
  				_UpperCamelCase       : Any    =      ids_tensor([self.batch_size, self.seq_length]  ,					self.vocab_size     ).type(torch.intaa     )
  				_UpperCamelCase       : Any    =      False
  
  				_UpperCamelCase       : Optional[Any]    =      self.get_config()
  
  				return (config, input_ids)
  		def _lowercase  (    self     )				->    Dict:
  				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 _lowercase  (    self  ,					_snake_case  ,					_snake_case  ,					*_snake_case     )				->    Optional[int]:
  				_UpperCamelCase       : List[str]    =      CpmAntModel(config=_snake_case     )
  				model.to(_snake_case     )
  				model.eval()
  
  				_UpperCamelCase       : int    =      model(**_snake_case     ).last_hidden_state
  
  				self.parent.assertEqual(hidden_states.shape  ,					(self.batch_size, self.seq_length, config.hidden_size)     )
  		def _lowercase  (    self  ,					_snake_case  ,					_snake_case  ,					*_snake_case     )				->    List[str]:
  				_UpperCamelCase       : int    =      CpmAntForCausalLM(_snake_case     )
  				model.to(_snake_case     )
  				_UpperCamelCase       : List[Any]    =      input_ids['''input_ids'''].to(_snake_case     )
  				model.eval()
  
  				_UpperCamelCase       : int    =      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 _lowercase  (    self     )				->    List[str]:
  				_UpperCamelCase,							_UpperCamelCase       : Optional[int]    =      self.prepare_config_and_inputs()
  				return config, inputs_dict
  
  
  
  
  
  
  
  @require_torch
  class 			UpperCAmelCase				(					a_  ,		a_  ,		unittest.TestCase ):
  
  
  
  
  
  		"""simple docstring"""
  
  
  
  
  
  		A__  :   Union[str, Any]          =    (CpmAntModel, CpmAntForCausalLM) if is_torch_available() else ()
  		A__  :   Union[str, Any]          =    (
  		    {'feature-extraction': CpmAntModel, 'text-generation': CpmAntForCausalLM} if is_torch_available() else {}
  		)
  
  		A__  :   Optional[int]          =    False
  		A__  :   Any          =    False
  		A__  :   Dict          =    False
  		A__  :   int          =    False
  		A__  :   Optional[Any]          =    False
  		def _lowercase  (    self     )				->    Tuple:
  				_UpperCamelCase       : Dict    =      CpmAntModelTester(self     )
  				_UpperCamelCase       : Dict    =      ConfigTester(self  ,					config_class=_snake_case     )
  		def _lowercase  (    self     )				->    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 _lowercase  (    self     )				->    List[Any]:
  				unittest.skip('''CPMAnt doesn\'t support input_embeds.'''     )(self.test_inputs_embeds     )
  		def _lowercase  (    self     )				->    Tuple:
  				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 _lowercase  (    self     )				->    Union[str, Any]:
  				_UpperCamelCase,							_UpperCamelCase       : Union[str, Any]    =      self.model_tester.prepare_config_and_inputs()
  				self.model_tester.create_and_check_cpmant_model(_snake_case  ,					_snake_case     )
  
  
  
  
  		def _lowercase  (    self     )				->    int:
  				_UpperCamelCase,							_UpperCamelCase       : Union[str, Any]    =      self.model_tester.prepare_config_and_inputs()
  				self.model_tester.create_and_check_lm_head_model(_snake_case  ,					_snake_case     )
  
  
  
  
  
  
  
  @require_torch
  class 			UpperCAmelCase				(					unittest.TestCase ):
  
  
  
  
  
  		"""simple docstring"""
  
  
  
  
  
  		@tooslow
  		def _lowercase  (    self     )				->    int:
  				_UpperCamelCase       : List[Any]    =      '''今天天气真好！'''
  				_UpperCamelCase       : List[Any]    =      '''openbmb/cpm-ant-10b'''
  				_UpperCamelCase       : int    =      CpmAntModel.from_pretrained(_snake_case     )
  				_UpperCamelCase       : int    =      CpmAntTokenizer.from_pretrained(_snake_case     )
  				_UpperCamelCase       : str    =      tokenizer(_snake_case  ,					return_tensors='''pt'''     )
  				_UpperCamelCase       : str    =      model(**_snake_case     ).last_hidden_state
  
  				_UpperCamelCase       : Tuple    =      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 			UpperCAmelCase				(					unittest.TestCase ):
  
  
  
  
  
  		"""simple docstring"""
  
  
  
  
  
  		@tooslow
  		def _lowercase  (    self     )				->    int:
  				_UpperCamelCase       : str    =      '''今天天气真好！'''
  				_UpperCamelCase       : Tuple    =      '''openbmb/cpm-ant-10b'''
  				_UpperCamelCase       : Union[str, Any]    =      CpmAntForCausalLM.from_pretrained(_snake_case     )
  				_UpperCamelCase       : int    =      CpmAntTokenizer.from_pretrained(_snake_case     )
  				_UpperCamelCase       : Tuple    =      tokenizer(_snake_case  ,					return_tensors='''pt'''     )
  				_UpperCamelCase       : int    =      model(**_snake_case     ).logits
  
  				_UpperCamelCase       : List[Any]    =      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 _lowercase  (    self     )				->    List[Any]:
  				_UpperCamelCase       : Optional[int]    =      '''openbmb/cpm-ant-10b'''
  				_UpperCamelCase       : List[Any]    =      CpmAntForCausalLM.from_pretrained(_snake_case     )
  				_UpperCamelCase       : str    =      CpmAntTokenizer.from_pretrained(_snake_case     )
  				_UpperCamelCase       : int    =      '''今天天气不错，'''
  				_UpperCamelCase       : Any    =      '''今天天气不错，阳光明媚，我和妈妈一起去超市买东西。\n在超市里，我看到了一个很好玩的玩具，它的名字叫“机器人”。它有一个圆圆的脑袋，两只圆圆的眼睛，还有一个圆圆的'''
  				_UpperCamelCase       : Optional[Any]    =      tokenizer(_snake_case  ,					return_tensors='''pt'''     )
  				_UpperCamelCase       : Optional[int]    =      model.generate(**_snake_case     )
  				_UpperCamelCase       : List[str]    =      tokenizer.batch_decode(_snake_case     )
  				self.assertEqual(_snake_case  ,					_snake_case     )
  
  
  
  
  		@tooslow
  		def _lowercase  (    self     )				->    Tuple:
  				_UpperCamelCase       : List[str]    =      '''openbmb/cpm-ant-10b'''
  				_UpperCamelCase       : int    =      CpmAntForCausalLM.from_pretrained(_snake_case     )
  				_UpperCamelCase       : str    =      CpmAntTokenizer.from_pretrained(_snake_case     )
  				_UpperCamelCase       : Optional[Any]    =      ['''今天天气不错，''', '''新年快乐，万事如意！''']
  				_UpperCamelCase       : Optional[Any]    =      [
  				    '''今天天气不错，阳光明媚，我和妈妈一起去超市买东西。\n在超市里，我看到了一个很好玩的玩具，它的名字叫“机器人”。它有一个圆圆的脑袋，两只圆圆的眼睛，还有一个圆圆的''',
  				    '''新年快乐，万事如意！在这辞旧迎新的美好时刻，我谨代表《农村新技术》杂志社全体同仁，向一直以来关心、支持《农村新技术》杂志发展的各级领导、各界朋友和广大读者致以最诚挚的''',
  				]
  				_UpperCamelCase       : List[Any]    =      tokenizer(_snake_case  ,					return_tensors='''pt'''  ,					padding=_snake_case     )
  				_UpperCamelCase       : Any    =      model.generate(**_snake_case     )
  				_UpperCamelCase       : Optional[int]    =      tokenizer.batch_decode(_snake_case     )
  				self.assertEqual(_snake_case  ,					_snake_case     )
  
  
  
  
  
  
style_context: 
  '''simple docstring'''
  
  from collections import OrderedDict
  from typing import Mapping
  
  from ...configuration_utils import PretrainedConfig
  from ...onnx import OnnxConfig
  from ...utils import logging
  
  
  _UpperCAmelCase   :      List[Any] 						=  logging.get_logger(__name__)
  
  _UpperCAmelCase   :      List[Any] 						=  {
      """nghuyong/ernie-1.0-base-zh""": """https://huggingface.co/nghuyong/ernie-1.0-base-zh/resolve/main/config.json""",
      """nghuyong/ernie-2.0-base-en""": """https://huggingface.co/nghuyong/ernie-2.0-base-en/resolve/main/config.json""",
      """nghuyong/ernie-2.0-large-en""": """https://huggingface.co/nghuyong/ernie-2.0-large-en/resolve/main/config.json""",
      """nghuyong/ernie-3.0-base-zh""": """https://huggingface.co/nghuyong/ernie-3.0-base-zh/resolve/main/config.json""",
      """nghuyong/ernie-3.0-medium-zh""": """https://huggingface.co/nghuyong/ernie-3.0-medium-zh/resolve/main/config.json""",
      """nghuyong/ernie-3.0-mini-zh""": """https://huggingface.co/nghuyong/ernie-3.0-mini-zh/resolve/main/config.json""",
      """nghuyong/ernie-3.0-micro-zh""": """https://huggingface.co/nghuyong/ernie-3.0-micro-zh/resolve/main/config.json""",
      """nghuyong/ernie-3.0-nano-zh""": """https://huggingface.co/nghuyong/ernie-3.0-nano-zh/resolve/main/config.json""",
      """nghuyong/ernie-gram-zh""": """https://huggingface.co/nghuyong/ernie-gram-zh/resolve/main/config.json""",
      """nghuyong/ernie-health-zh""": """https://huggingface.co/nghuyong/ernie-health-zh/resolve/main/config.json""",
  }
  
  class 			UpperCAmelCase				(					a_ ):
  
  
  
  
  
  		"""simple docstring"""
  
  
  
  
  
  		A__  :   str          =    'ernie'
  		def __init__(    self  ,					_snake_case=30522  ,					_snake_case=768  ,					_snake_case=12  ,					_snake_case=12  ,					_snake_case=3072  ,					_snake_case="gelu"  ,					_snake_case=0.1  ,					_snake_case=0.1  ,					_snake_case=512  ,					_snake_case=2  ,					_snake_case=3  ,					_snake_case=False  ,					_snake_case=0.02  ,					_snake_case=1E-12  ,					_snake_case=0  ,					_snake_case="absolute"  ,					_snake_case=True  ,					_snake_case=None  ,					**_snake_case  ,					)				->    List[Any]:
  				super().__init__(pad_token_id=_snake_case  ,					**_snake_case     )
  
  				_UpperCamelCase       : Dict    =      vocab_size
  				_UpperCamelCase       : int    =      hidden_size
  				_UpperCamelCase       : List[Any]    =      num_hidden_layers
  				_UpperCamelCase       : Tuple    =      num_attention_heads
  				_UpperCamelCase       : List[str]    =      hidden_act
  				_UpperCamelCase       : Optional[int]    =      intermediate_size
  				_UpperCamelCase       : Tuple    =      hidden_dropout_prob
  				_UpperCamelCase       : Optional[int]    =      attention_probs_dropout_prob
  				_UpperCamelCase       : List[str]    =      max_position_embeddings
  				_UpperCamelCase       : Tuple    =      type_vocab_size
  				_UpperCamelCase       : Union[str, Any]    =      task_type_vocab_size
  				_UpperCamelCase       : Union[str, Any]    =      use_task_id
  				_UpperCamelCase       : Any    =      initializer_range
  				_UpperCamelCase       : Optional[int]    =      layer_norm_eps
  				_UpperCamelCase       : str    =      position_embedding_type
  				_UpperCamelCase       : Any    =      use_cache
  				_UpperCamelCase       : str    =      classifier_dropout
  
  
  
  
  
  
  
  class 			UpperCAmelCase				(					a_ ):
  
  
  
  
  
  		"""simple docstring"""
  
  
  
  
  
  		@property
  		def _lowercase  (    self     )				->    Mapping[str, Mapping[int, str]]:
  				if self.task == "multiple-choice":
  						_UpperCamelCase       : str    =      {0: '''batch''', 1: '''choice''', 2: '''sequence'''}
  				else:
  						_UpperCamelCase       : Dict    =      {0: '''batch''', 1: '''sequence'''}
  				return OrderedDict(
  				    [
  				        ('''input_ids''', dynamic_axis),
  				        ('''attention_mask''', dynamic_axis),
  				        ('''token_type_ids''', dynamic_axis),
  				        ('''task_type_ids''', dynamic_axis),
  				    ]     )
  
  
  
  
  
  