






from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


a		:	List[Any]      					=			logging.get_logger(__name__)

a		:	Union[str, Any]      					=			{
    "facebook/mbart-large-cc25": "https://huggingface.co/facebook/mbart-large-cc25/resolve/main/config.json",
    # See all MBART models at https://huggingface.co/models?filter=mbart
}
class    a   (			lowercase__       ):



      """simple docstring"""


      a  :			int								=     'mbart'
      a  :			Optional[int]								=     ['past_key_values']
      a  :			int								=     {'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}
      def __init__(				self :      Dict		,				__lowercase :      Optional[Any]=50265		,				__lowercase :      str=1024		,				__lowercase :      Tuple=12		,				__lowercase :      int=4096		,				__lowercase :      Any=16		,				__lowercase :      str=12		,				__lowercase :      Dict=4096		,				__lowercase :      Optional[int]=16		,				__lowercase :      List[Any]=0.0		,				__lowercase :      Dict=0.0		,				__lowercase :      Dict=True		,				__lowercase :      Tuple=True		,				__lowercase :      Optional[Any]="gelu"		,				__lowercase :      List[str]=1024		,				__lowercase :      Optional[Any]=0.1		,				__lowercase :      Union[str, Any]=0.0		,				__lowercase :      Any=0.0		,				__lowercase :      Optional[int]=0.02		,				__lowercase :      int=0.0		,				__lowercase :      Union[str, Any]=False		,				__lowercase :      Dict=1		,				__lowercase :      Union[str, Any]=0		,				__lowercase :      str=2		,				__lowercase :      Optional[Any]=2		,				**__lowercase :      List[str]		,				)							->				List[str]:
        __UpperCAmelCase							:     Union[str, Any]									=  vocab_size
        __UpperCAmelCase							:     Tuple									=  max_position_embeddings
        __UpperCAmelCase							:     Dict									=  d_model
        __UpperCAmelCase							:     List[str]									=  encoder_ffn_dim
        __UpperCAmelCase							:     Optional[Any]									=  encoder_layers
        __UpperCAmelCase							:     Optional[int]									=  encoder_attention_heads
        __UpperCAmelCase							:     Tuple									=  decoder_ffn_dim
        __UpperCAmelCase							:     Optional[Any]									=  decoder_layers
        __UpperCAmelCase							:     List[str]									=  decoder_attention_heads
        __UpperCAmelCase							:     List[str]									=  dropout
        __UpperCAmelCase							:     Union[str, Any]									=  attention_dropout
        __UpperCAmelCase							:     int									=  activation_dropout
        __UpperCAmelCase							:     int									=  activation_function
        __UpperCAmelCase							:     int									=  init_std
        __UpperCAmelCase							:     Tuple									=  encoder_layerdrop
        __UpperCAmelCase							:     List[Any]									=  decoder_layerdrop
        __UpperCAmelCase							:     Dict									=  classifier_dropout
        __UpperCAmelCase							:     Tuple									=  use_cache
        __UpperCAmelCase							:     Any									=  encoder_layers
        __UpperCAmelCase							:     int									=  scale_embedding  # scale factor will be sqrt(d_model) if True
        super().__init__(
            pad_token_id=__lowercase		,				bos_token_id=__lowercase		,				eos_token_id=__lowercase		,				is_encoder_decoder=__lowercase		,				forced_eos_token_id=__lowercase		,				**__lowercase		,				)


class    a   (			lowercase__       ):



      """simple docstring"""


      @property
      def      UpperCAmelCase				(				self :      Union[str, Any] )							->				Mapping[str, Mapping[int, str]]:
        if self.task in ["default", "seq2seq-lm"]:
          __UpperCAmelCase							:     Optional[int]									=  OrderedDict(
              [
                  ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
                  ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
              ] )

          if self.use_past:
            __UpperCAmelCase							:     List[Any]									=  {0: """batch"""}
            __UpperCAmelCase							:     Optional[int]									=  {0: """batch""", 1: """past_decoder_sequence + sequence"""}
          else:
            __UpperCAmelCase							:     Optional[Any]									=  {0: """batch""", 1: """decoder_sequence"""}
            __UpperCAmelCase							:     List[Any]									=  {0: """batch""", 1: """decoder_sequence"""}

          if self.use_past:
            self.fill_with_past_key_values_(__lowercase		,				direction="""inputs""" )
        elif self.task == "causal-lm":
          # TODO: figure this case out.
          __UpperCAmelCase							:     Optional[Any]									=  OrderedDict(
              [
                  ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
                  ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
              ] )
          if self.use_past:
            __UpperCAmelCase				,			__UpperCAmelCase							:     Optional[int]									=  self.num_layers
            for i in range(__lowercase ):
              __UpperCAmelCase							:     List[str]									=  {0: """batch""", 2: """past_sequence + sequence"""}
              __UpperCAmelCase							:     Optional[int]									=  {0: """batch""", 2: """past_sequence + sequence"""}
        else:
          __UpperCAmelCase							:     List[Any]									=  OrderedDict(
              [
                  ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
                  ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
                  ("""decoder_input_ids""", {0: """batch""", 1: """decoder_sequence"""}),
                  ("""decoder_attention_mask""", {0: """batch""", 1: """decoder_sequence"""}),
              ] )

        return common_inputs
      @property
      def      UpperCAmelCase				(				self :      Union[str, Any] )							->				Mapping[str, Mapping[int, str]]:
        if self.task in ["default", "seq2seq-lm"]:
          __UpperCAmelCase							:     Optional[Any]									=  super().outputs
        else:
          __UpperCAmelCase							:     Any									=  super(__lowercase		,				self ).outputs
          if self.use_past:
            __UpperCAmelCase				,			__UpperCAmelCase							:     List[Any]									=  self.num_layers
            for i in range(__lowercase ):
              __UpperCAmelCase							:     Tuple									=  {0: """batch""", 2: """past_sequence + sequence"""}
              __UpperCAmelCase							:     Tuple									=  {0: """batch""", 2: """past_sequence + sequence"""}
        return common_outputs
      def      UpperCAmelCase				(				self :      Tuple		,				__lowercase :      PreTrainedTokenizer		,				__lowercase :      int = -1		,				__lowercase :      int = -1		,				__lowercase :      bool = False		,				__lowercase :      Optional[TensorType] = None		,				)							->				Mapping[str, Any]:
        __UpperCAmelCase							:     Any									=  self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
            __lowercase		,				__lowercase		,				__lowercase		,				__lowercase		,				__lowercase )

        # Generate decoder inputs
        __UpperCAmelCase							:     str									=  seq_length if not self.use_past else 1
        __UpperCAmelCase							:     int									=  self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
            __lowercase		,				__lowercase		,				__lowercase		,				__lowercase		,				__lowercase )
        __UpperCAmelCase							:     List[Any]									=  {f"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
        __UpperCAmelCase							:     List[Any]									=  dict(**__lowercase		,				**__lowercase )

        if self.use_past:
          if not is_torch_available():
            raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed.""" )
          else:
            import torch
          __UpperCAmelCase				,			__UpperCAmelCase							:     int									=  common_inputs["""input_ids"""].shape
          __UpperCAmelCase							:     Dict									=  common_inputs["""decoder_input_ids"""].shape[1]
          __UpperCAmelCase				,			__UpperCAmelCase							:     Union[str, Any]									=  self.num_attention_heads
          __UpperCAmelCase							:     List[Any]									=  (
              batch,
              num_encoder_attention_heads,
              encoder_seq_length,
              self._config.hidden_size // num_encoder_attention_heads,
          )
          __UpperCAmelCase							:     Union[str, Any]									=  decoder_seq_length + 3
          __UpperCAmelCase							:     Dict									=  (
              batch,
              num_decoder_attention_heads,
              decoder_past_length,
              self._config.hidden_size // num_decoder_attention_heads,
          )

          __UpperCAmelCase							:     List[Any]									=  torch.cat(
              [common_inputs["""decoder_attention_mask"""], torch.ones(__lowercase		,				__lowercase )]		,				dim=1 )

          __UpperCAmelCase							:     str									=  []
          # If the number of encoder and decoder layers are present in the model configuration, both are considered
          __UpperCAmelCase				,			__UpperCAmelCase							:     Any									=  self.num_layers
          __UpperCAmelCase							:     int									=  min(__lowercase		,				__lowercase )
          __UpperCAmelCase							:     Optional[Any]									=  max(__lowercase		,				__lowercase ) - min_num_layers
          __UpperCAmelCase							:     List[str]									=  """encoder""" if num_encoder_layers > num_decoder_layers else """decoder"""

          for _ in range(__lowercase ):
            common_inputs["past_key_values"].append(
                (
                    torch.zeros(__lowercase ),
                    torch.zeros(__lowercase ),
                    torch.zeros(__lowercase ),
                    torch.zeros(__lowercase ),
                ) )
          # TODO: test this.
          __UpperCAmelCase							:     str									=  encoder_shape if remaining_side_name == """encoder""" else decoder_shape
          for _ in range(__lowercase		,				__lowercase ):
            common_inputs["past_key_values"].append((torch.zeros(__lowercase ), torch.zeros(__lowercase )) )
        return common_inputs
      def      UpperCAmelCase				(				self :      Optional[int]		,				__lowercase :      PreTrainedTokenizer		,				__lowercase :      int = -1		,				__lowercase :      int = -1		,				__lowercase :      bool = False		,				__lowercase :      Optional[TensorType] = None		,				)							->				Mapping[str, Any]:
        __UpperCAmelCase							:     Any									=  self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
            __lowercase		,				__lowercase		,				__lowercase		,				__lowercase		,				__lowercase )

        if self.use_past:
          if not is_torch_available():
            raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed.""" )
          else:
            import torch
          __UpperCAmelCase				,			__UpperCAmelCase							:     List[str]									=  common_inputs["""input_ids"""].shape
          # Not using the same length for past_key_values
          __UpperCAmelCase							:     int									=  seqlen + 2
          __UpperCAmelCase				,			__UpperCAmelCase							:     Optional[int]									=  self.num_layers
          __UpperCAmelCase				,			__UpperCAmelCase							:     Any									=  self.num_attention_heads
          __UpperCAmelCase							:     Tuple									=  (
              batch,
              num_encoder_attention_heads,
              past_key_values_length,
              self._config.hidden_size // num_encoder_attention_heads,
          )

          __UpperCAmelCase							:     str									=  common_inputs["""attention_mask"""].dtype
          __UpperCAmelCase							:     Optional[int]									=  torch.cat(
              [common_inputs["""attention_mask"""], torch.ones(__lowercase		,				__lowercase		,				dtype=__lowercase )]		,				dim=1 )
          __UpperCAmelCase							:     List[Any]									=  [
              (torch.zeros(__lowercase ), torch.zeros(__lowercase )) for _ in range(__lowercase )
          ]
        return common_inputs
      def      UpperCAmelCase				(				self :      int		,				__lowercase :      PreTrainedTokenizer		,				__lowercase :      int = -1		,				__lowercase :      int = -1		,				__lowercase :      bool = False		,				__lowercase :      Optional[TensorType] = None		,				)							->				Mapping[str, Any]:
        # Copied from OnnxConfig.generate_dummy_inputs
        # Did not use super(OnnxConfigWithPast, self).generate_dummy_inputs for code clarity.
        # If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
        __UpperCAmelCase							:     List[Any]									=  compute_effective_axis_dimension(
            __lowercase		,				fixed_dimension=OnnxConfig.default_fixed_batch		,				num_token_to_add=0 )

        # If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
        __UpperCAmelCase							:     Tuple									=  tokenizer.num_special_tokens_to_add(__lowercase )
        __UpperCAmelCase							:     List[Any]									=  compute_effective_axis_dimension(
            __lowercase		,				fixed_dimension=OnnxConfig.default_fixed_sequence		,				num_token_to_add=__lowercase )

        # Generate dummy inputs according to compute batch and sequence
        __UpperCAmelCase							:     int									=  [""" """.join([tokenizer.unk_token] ) * seq_length] * batch_size
        __UpperCAmelCase							:     Tuple									=  dict(tokenizer(__lowercase		,				return_tensors=__lowercase ) )
        return common_inputs
      def      UpperCAmelCase				(				self :      Any		,				__lowercase :      PreTrainedTokenizer		,				__lowercase :      int = -1		,				__lowercase :      int = -1		,				__lowercase :      bool = False		,				__lowercase :      Optional[TensorType] = None		,				)							->				Mapping[str, Any]:
        if self.task in ["default", "seq2seq-lm"]:
          __UpperCAmelCase							:     int									=  self._generate_dummy_inputs_for_default_and_seqaseq_lm(
              __lowercase		,				batch_size=__lowercase		,				seq_length=__lowercase		,				is_pair=__lowercase		,				framework=__lowercase )

        elif self.task == "causal-lm":
          __UpperCAmelCase							:     Optional[Any]									=  self._generate_dummy_inputs_for_causal_lm(
              __lowercase		,				batch_size=__lowercase		,				seq_length=__lowercase		,				is_pair=__lowercase		,				framework=__lowercase )
        else:
          __UpperCAmelCase							:     Union[str, Any]									=  self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
              __lowercase		,				batch_size=__lowercase		,				seq_length=__lowercase		,				is_pair=__lowercase		,				framework=__lowercase )

        return common_inputs




      def      UpperCAmelCase				(				self :      Optional[int]		,				__lowercase :      List[Any]		,				__lowercase :      int		,				__lowercase :      List[str]		,				__lowercase :      int )							->				Optional[Any]:
        if self.task in ["default", "seq2seq-lm"]:
          __UpperCAmelCase							:     Optional[Any]									=  super()._flatten_past_key_values_(__lowercase		,				__lowercase		,				__lowercase		,				__lowercase )
        else:
          __UpperCAmelCase							:     Tuple									=  super(__lowercase		,				self )._flatten_past_key_values_(
              __lowercase		,				__lowercase		,				__lowercase		,				__lowercase )










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 :      List[str]		,				__lowercase :      Tuple=2		,				__lowercase :      Dict=8		,				__lowercase :      int=True		,				__lowercase :      Dict=False		,				__lowercase :      List[Any]=False		,				__lowercase :      List[str]=False		,				__lowercase :      Any=False		,				__lowercase :      List[Any]=99		,				__lowercase :      int=32		,				__lowercase :      Optional[Any]=3		,				__lowercase :      Any=4		,				__lowercase :      List[Any]=37		,				__lowercase :      Dict=32		,				__lowercase :      Any=128		,				__lowercase :      Optional[Any]=8		,				__lowercase :      str=8		,				__lowercase :      str=8		,				__lowercase :      Optional[int]=1.0		,				__lowercase :      int=True		,				)							->				Optional[int]:
        __UpperCAmelCase							:     Optional[Any]									=  parent
        __UpperCAmelCase							:     Optional[int]									=  batch_size
        __UpperCAmelCase							:     List[Any]									=  seq_length
        __UpperCAmelCase							:     Optional[int]									=  is_training
        __UpperCAmelCase							:     Optional[Any]									=  use_token_type_ids
        __UpperCAmelCase							:     Optional[int]									=  use_input_mask
        __UpperCAmelCase							:     Optional[int]									=  use_labels
        __UpperCAmelCase							:     str									=  use_mc_token_ids
        __UpperCAmelCase							:     Any									=  vocab_size
        __UpperCAmelCase							:     str									=  hidden_size
        __UpperCAmelCase							:     str									=  num_hidden_layers
        __UpperCAmelCase							:     Union[str, Any]									=  num_attention_heads
        __UpperCAmelCase							:     Optional[int]									=  intermediate_size
        __UpperCAmelCase							:     Tuple									=  num_buckets
        __UpperCAmelCase							:     Any									=  max_distance
        __UpperCAmelCase							:     Any									=  prompt_length
        __UpperCAmelCase							:     int									=  prompt_types
        __UpperCAmelCase							:     List[Any]									=  segment_types
        __UpperCAmelCase							:     Any									=  init_std
        __UpperCAmelCase							:     int									=  return_dict
      def      UpperCAmelCase				(				self :      Optional[Any] )							->				List[Any]:
        __UpperCAmelCase							:     Optional[Any]									=  {}
        __UpperCAmelCase							:     Dict									=  ids_tensor([self.batch_size, self.seq_length]		,				self.vocab_size ).type(torch.intaa )
        __UpperCAmelCase							:     List[str]									=  False

        __UpperCAmelCase							:     List[str]									=  self.get_config()

        return (config, input_ids)
      def      UpperCAmelCase				(				self :      Union[str, Any] )							->				Optional[int]:
        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      UpperCAmelCase				(				self :      Tuple		,				__lowercase :      Union[str, Any]		,				__lowercase :      List[str]		,				*__lowercase :      Optional[int] )							->				List[Any]:
        __UpperCAmelCase							:     int									=  CpmAntModel(config=__lowercase )
        model.to(__lowercase )
        model.eval()

        __UpperCAmelCase							:     str									=  model(**__lowercase ).last_hidden_state

        self.parent.assertEqual(hidden_states.shape		,				(self.batch_size, self.seq_length, config.hidden_size) )
      def      UpperCAmelCase				(				self :      List[str]		,				__lowercase :      List[str]		,				__lowercase :      Optional[Any]		,				*__lowercase :      Optional[int] )							->				List[str]:
        __UpperCAmelCase							:     List[Any]									=  CpmAntForCausalLM(__lowercase )
        model.to(__lowercase )
        __UpperCAmelCase							:     Optional[Any]									=  input_ids["""input_ids"""].to(__lowercase )
        model.eval()

        __UpperCAmelCase							:     int									=  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      UpperCAmelCase				(				self :      List[Any] )							->				Dict:
        __UpperCAmelCase				,			__UpperCAmelCase							:     Optional[int]									=  self.prepare_config_and_inputs()
        return config, inputs_dict


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



      """simple docstring"""


      a  :			List[Any]								=     (CpmAntModel, CpmAntForCausalLM) if is_torch_available() else ()
      a  :			Optional[int]								=     (
          {'feature-extraction': CpmAntModel, 'text-generation': CpmAntForCausalLM} if is_torch_available() else {}
      )

      a  :			List[Any]								=     False
      a  :			Any								=     False
      a  :			List[Any]								=     False
      a  :			Tuple								=     False
      a  :			Any								=     False
      def      UpperCAmelCase				(				self :      Optional[int] )							->				Optional[Any]:
        __UpperCAmelCase							:     List[Any]									=  CpmAntModelTester(self )
        __UpperCAmelCase							:     Dict									=  ConfigTester(self		,				config_class=__lowercase )
      def      UpperCAmelCase				(				self :      str )							->				Optional[int]:
        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 :      List[str] )							->				List[str]:
        unittest.skip("""CPMAnt doesn't support input_embeds.""" )(self.test_inputs_embeds )
      def      UpperCAmelCase				(				self :      Any )							->				Union[str, 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      UpperCAmelCase				(				self :      str )							->				List[Any]:
        __UpperCAmelCase				,			__UpperCAmelCase							:     Optional[Any]									=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_cpmant_model(__lowercase		,				__lowercase )




      def      UpperCAmelCase				(				self :      Optional[Any] )							->				str:
        __UpperCAmelCase				,			__UpperCAmelCase							:     Dict									=  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      UpperCAmelCase				(				self :      str )							->				Optional[Any]:
        __UpperCAmelCase							:     List[Any]									=  """今天天气真好！"""
        __UpperCAmelCase							:     int									=  """openbmb/cpm-ant-10b"""
        __UpperCAmelCase							:     Tuple									=  CpmAntModel.from_pretrained(__lowercase )
        __UpperCAmelCase							:     Optional[int]									=  CpmAntTokenizer.from_pretrained(__lowercase )
        __UpperCAmelCase							:     Union[str, Any]									=  tokenizer(__lowercase		,				return_tensors="""pt""" )
        __UpperCAmelCase							:     List[Any]									=  model(**__lowercase ).last_hidden_state

        __UpperCAmelCase							:     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]		,				__lowercase		,				atol=1e-2 ) )


@require_torch
class    a   (			unittest.TestCase       ):



      """simple docstring"""


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




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


