






def     lowerCamelCase__				(   __lowerCamelCase      :					Optional[Any]  ,		__lowerCamelCase      :					List[str]		):
  if n < 0:
    return 0
  # table[i] represents the number of ways to get to amount i
  __UpperCAmelCase							:     Tuple									=  [0] * (n + 1)

  # There is exactly 1 way to get to zero(You pick no coins).
  __UpperCAmelCase							:     int									=  1

  # Pick all coins one by one and update table[] values
  # after the index greater than or equal to the value of the
  # picked coin
  for coin_val in s:
    for j in range(__lowerCamelCase  ,		n + 1		):
      table[j] += table[j - coin_val]

  return table[n]


if __name__ == "__main__":
       import doctest

       doctest.testmod()










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 )


