

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						:

  def __init__(			self	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE=2	,   _SCREAMING_SNAKE_CASE=8	,   _SCREAMING_SNAKE_CASE=True	,   _SCREAMING_SNAKE_CASE=False	,   _SCREAMING_SNAKE_CASE=False	,   _SCREAMING_SNAKE_CASE=False	,   _SCREAMING_SNAKE_CASE=False	,   _SCREAMING_SNAKE_CASE=99	,   _SCREAMING_SNAKE_CASE=32	,   _SCREAMING_SNAKE_CASE=3	,   _SCREAMING_SNAKE_CASE=4	,   _SCREAMING_SNAKE_CASE=37	,   _SCREAMING_SNAKE_CASE=32	,   _SCREAMING_SNAKE_CASE=128	,   _SCREAMING_SNAKE_CASE=8	,   _SCREAMING_SNAKE_CASE=8	,   _SCREAMING_SNAKE_CASE=8	,   _SCREAMING_SNAKE_CASE=1.0	,   _SCREAMING_SNAKE_CASE=True	,   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					str          =       parent
        SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       batch_size
        SCREAMING_SNAKE_CASE_			:					Tuple          =       seq_length
        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       is_training
        SCREAMING_SNAKE_CASE_			:					List[str]          =       use_token_type_ids
        SCREAMING_SNAKE_CASE_			:					List[str]          =       use_input_mask
        SCREAMING_SNAKE_CASE_			:					List[str]          =       use_labels
        SCREAMING_SNAKE_CASE_			:					List[str]          =       use_mc_token_ids
        SCREAMING_SNAKE_CASE_			:					Tuple          =       vocab_size
        SCREAMING_SNAKE_CASE_			:					int          =       hidden_size
        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       num_hidden_layers
        SCREAMING_SNAKE_CASE_			:					Any          =       num_attention_heads
        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       intermediate_size
        SCREAMING_SNAKE_CASE_			:					Dict          =       num_buckets
        SCREAMING_SNAKE_CASE_			:					Dict          =       max_distance
        SCREAMING_SNAKE_CASE_			:					int          =       prompt_length
        SCREAMING_SNAKE_CASE_			:					List[Any]          =       prompt_types
        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       segment_types
        SCREAMING_SNAKE_CASE_			:					List[str]          =       init_std
        SCREAMING_SNAKE_CASE_			:					Dict          =       return_dict

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       {}
        SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       ids_tensor([self.batch_size, self.seq_length]	,   self.vocab_size   ).type(torch.intaa   )
        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       False

        SCREAMING_SNAKE_CASE_			:					Dict          =       self.get_config()

        return (config, input_ids)

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        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=_SCREAMING_SNAKE_CASE	,   init_std=self.init_std	,   return_dict=self.return_dict	,   )

  def 	UpperCAmelCase      (			self	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   *_SCREAMING_SNAKE_CASE   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					str          =       CpmAntModel(config=_SCREAMING_SNAKE_CASE   )
        model.to(_SCREAMING_SNAKE_CASE   )
        model.eval()

        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       model(**_SCREAMING_SNAKE_CASE   ).last_hidden_state

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

  def 	UpperCAmelCase      (			self	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   *_SCREAMING_SNAKE_CASE   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					List[Any]          =       CpmAntForCausalLM(_SCREAMING_SNAKE_CASE   )
        model.to(_SCREAMING_SNAKE_CASE   )
        SCREAMING_SNAKE_CASE_			:					List[Any]          =       input_ids['input_ids'].to(_SCREAMING_SNAKE_CASE   )
        model.eval()

        SCREAMING_SNAKE_CASE_			:					List[Any]          =       model(**_SCREAMING_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 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_    ,  SCREAMING_SNAKE_CASE_			:					List[Any]          =       self.prepare_config_and_inputs()
        return config, inputs_dict

@require_torch
class 	_A						(					__magic_name__				,       __magic_name__				,       unittest.TestCase):
  SCREAMING_SNAKE_CASE      : Dict    =					(CpmAntModel, CpmAntForCausalLM) if is_torch_available() else ()
  SCREAMING_SNAKE_CASE      : Optional[Any]    =					(
      {'''feature-extraction''': CpmAntModel, '''text-generation''': CpmAntForCausalLM} if is_torch_available() else {}
  )

  SCREAMING_SNAKE_CASE      : str    =					False
  SCREAMING_SNAKE_CASE      : Union[str, Any]    =					False
  SCREAMING_SNAKE_CASE      : Tuple    =					False
  SCREAMING_SNAKE_CASE      : List[Any]    =					False
  SCREAMING_SNAKE_CASE      : int    =					False

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Dict          =       CpmAntModelTester(self   )
        SCREAMING_SNAKE_CASE_			:					Tuple          =       ConfigTester(self	,   config_class=_SCREAMING_SNAKE_CASE   )

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        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   ):





        """simple docstring"""







        unittest.skip('CPMAnt doesn\'t support input_embeds.'   )(self.test_inputs_embeds   )

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        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   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_    ,  SCREAMING_SNAKE_CASE_			:					List[Any]          =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_cpmant_model(_SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE   )



  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_    ,  SCREAMING_SNAKE_CASE_			:					Optional[int]          =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_lm_head_model(_SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE   )

@require_torch
class 	_A						(					unittest.TestCase):

  @tooslow
  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       '今天天气真好！'
        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       'openbmb/cpm-ant-10b'
        SCREAMING_SNAKE_CASE_			:					List[Any]          =       CpmAntModel.from_pretrained(_SCREAMING_SNAKE_CASE   )
        SCREAMING_SNAKE_CASE_			:					str          =       CpmAntTokenizer.from_pretrained(_SCREAMING_SNAKE_CASE   )
        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       tokenizer(_SCREAMING_SNAKE_CASE	,   return_tensors='pt'   )
        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       model(**_SCREAMING_SNAKE_CASE   ).last_hidden_state

        SCREAMING_SNAKE_CASE_			:					int          =       torch.tensor(
            [[[6.1708, 5.9244, 1.0835], [6.5207, 6.2893, -11.3324], [-1.0107, -0.0576, -5.9577]]]	,   )
        self.assertTrue(torch.allclose(hidden_states[:, :3, :3]	,   _SCREAMING_SNAKE_CASE	,   atol=1e-2   )   )

@require_torch
class 	_A						(					unittest.TestCase):

  @tooslow
  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       '今天天气真好！'
        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       'openbmb/cpm-ant-10b'
        SCREAMING_SNAKE_CASE_			:					List[str]          =       CpmAntForCausalLM.from_pretrained(_SCREAMING_SNAKE_CASE   )
        SCREAMING_SNAKE_CASE_			:					List[str]          =       CpmAntTokenizer.from_pretrained(_SCREAMING_SNAKE_CASE   )
        SCREAMING_SNAKE_CASE_			:					str          =       tokenizer(_SCREAMING_SNAKE_CASE	,   return_tensors='pt'   )
        SCREAMING_SNAKE_CASE_			:					Dict          =       model(**_SCREAMING_SNAKE_CASE   ).logits

        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       torch.tensor(
            [[[-6.4267, -6.4083, -6.3958], [-5.8802, -5.9447, -5.7811], [-5.3896, -5.4820, -5.4295]]]	,   )
        self.assertTrue(torch.allclose(hidden_states[:, :3, :3]	,   _SCREAMING_SNAKE_CASE	,   atol=1e-2   )   )

  @tooslow
  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







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



  @tooslow
  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







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









from collections import defaultdict

def 				A_					(							a					):

      """simple docstring"""



      SCREAMING_SNAKE_CASE_			:					defaultdict[str, int]          =       defaultdict(a					)
      # Creating a dictionary containing count of each word
      for word in sentence.split():
            occurrence[word] += 1
      return occurrence


if __name__ == "__main__":
    for word, count in word_occurrence('INPUT STRING').items():
        print(F'{word}: {count}')






