




import os
import unittest

from transformers import ElectraTokenizerFast
from transformers.models.electra.tokenization_electra import (
    VOCAB_FILES_NAMES,
    BasicTokenizer,
    ElectraTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english
@require_tokenizers
class       __a					( __lowerCamelCase							,     unittest.TestCase     ):


     """simple docstring"""


     _A				:    int									=  ElectraTokenizer
     _A				:    Union[str, Any]									=  ElectraTokenizerFast
     _A				:    str									=  True
     _A				:    Optional[Any]									=  True
     _A				:    Optional[Any]									=  filter_non_english




     def   __A				(	self			: Union[str, Any]						)		->   List[str]:


         '''simple docstring'''





         super().setUp()

         SCREAMING_SNAKE_CASE__								=[
             """[UNK]""",
             """[CLS]""",
             """[SEP]""",
             """[PAD]""",
             """[MASK]""",
             """want""",
             """##want""",
             """##ed""",
             """wa""",
             """un""",
             """runn""",
             """##ing""",
             """,""",
             """low""",
             """lowest""",
         ]
         SCREAMING_SNAKE_CASE__								=os.path.join(self.tmpdirname				,VOCAB_FILES_NAMES["""vocab_file"""]						)
         with open(self.vocab_file				,"""w"""				,encoding="""utf-8"""						) as vocab_writer:
             vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens]						)						)




     def   __A				(	self			: List[str]				,_UpperCamelCase			: Optional[Any]						)		->   Tuple:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								="""UNwant\u00E9d,running"""
         SCREAMING_SNAKE_CASE__								="""unwanted, running"""
         return input_text, output_text




     def   __A				(	self			: str						)		->   Any:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=self.tokenizer_class(self.vocab_file						)

         SCREAMING_SNAKE_CASE__								=tokenizer.tokenize("""UNwant\u00E9d,running"""						)
         self.assertListEqual(_UpperCamelCase				,["""un""", """##want""", """##ed""", """,""", """runn""", """##ing"""]						)
         self.assertListEqual(tokenizer.convert_tokens_to_ids(_UpperCamelCase						)				,[9, 6, 7, 1_2, 1_0, 1_1]						)




     def   __A				(	self			: Any						)		->   Optional[int]:


         '''simple docstring'''





         if not self.test_rust_tokenizer:
             return

         SCREAMING_SNAKE_CASE__								=self.get_tokenizer()
         SCREAMING_SNAKE_CASE__								=self.get_rust_tokenizer()

         SCREAMING_SNAKE_CASE__								="""UNwant\u00E9d,running"""

         SCREAMING_SNAKE_CASE__								=tokenizer.tokenize(_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__								=rust_tokenizer.tokenize(_UpperCamelCase						)
         self.assertListEqual(_UpperCamelCase				,_UpperCamelCase						)

         SCREAMING_SNAKE_CASE__								=tokenizer.encode(_UpperCamelCase				,add_special_tokens=_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__								=rust_tokenizer.encode(_UpperCamelCase				,add_special_tokens=_UpperCamelCase						)
         self.assertListEqual(_UpperCamelCase				,_UpperCamelCase						)

         SCREAMING_SNAKE_CASE__								=self.get_rust_tokenizer()
         SCREAMING_SNAKE_CASE__								=tokenizer.encode(_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__								=rust_tokenizer.encode(_UpperCamelCase						)
         self.assertListEqual(_UpperCamelCase				,_UpperCamelCase						)

         # With lower casing
         SCREAMING_SNAKE_CASE__								=self.get_tokenizer(do_lower_case=_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__								=self.get_rust_tokenizer(do_lower_case=_UpperCamelCase						)

         SCREAMING_SNAKE_CASE__								="""UNwant\u00E9d,running"""

         SCREAMING_SNAKE_CASE__								=tokenizer.tokenize(_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__								=rust_tokenizer.tokenize(_UpperCamelCase						)
         self.assertListEqual(_UpperCamelCase				,_UpperCamelCase						)

         SCREAMING_SNAKE_CASE__								=tokenizer.encode(_UpperCamelCase				,add_special_tokens=_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__								=rust_tokenizer.encode(_UpperCamelCase				,add_special_tokens=_UpperCamelCase						)
         self.assertListEqual(_UpperCamelCase				,_UpperCamelCase						)

         SCREAMING_SNAKE_CASE__								=self.get_rust_tokenizer()
         SCREAMING_SNAKE_CASE__								=tokenizer.encode(_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__								=rust_tokenizer.encode(_UpperCamelCase						)
         self.assertListEqual(_UpperCamelCase				,_UpperCamelCase						)




     def   __A				(	self			: Optional[int]						)		->   Any:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=BasicTokenizer()

         self.assertListEqual(tokenizer.tokenize("""ah\u535A\u63A8zz"""						)				,["""ah""", """\u535A""", """\u63A8""", """zz"""]						)




     def   __A				(	self			: Union[str, Any]						)		->   str:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=BasicTokenizer(do_lower_case=_UpperCamelCase						)

         self.assertListEqual(
             tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU?  """						)				,["""hello""", """!""", """how""", """are""", """you""", """?"""]						)
         self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""						)				,["""hello"""]						)




     def   __A				(	self			: str						)		->   List[Any]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=BasicTokenizer(do_lower_case=_UpperCamelCase				,strip_accents=_UpperCamelCase						)

         self.assertListEqual(
             tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """						)				,["""hällo""", """!""", """how""", """are""", """you""", """?"""]						)
         self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""						)				,["""h\u00E9llo"""]						)




     def   __A				(	self			: Dict						)		->   Dict:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=BasicTokenizer(do_lower_case=_UpperCamelCase				,strip_accents=_UpperCamelCase						)

         self.assertListEqual(
             tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """						)				,["""hallo""", """!""", """how""", """are""", """you""", """?"""]						)
         self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""						)				,["""hello"""]						)




     def   __A				(	self			: int						)		->   Optional[int]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=BasicTokenizer(do_lower_case=_UpperCamelCase						)

         self.assertListEqual(
             tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """						)				,["""hallo""", """!""", """how""", """are""", """you""", """?"""]						)
         self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""						)				,["""hello"""]						)




     def   __A				(	self			: Tuple						)		->   Union[str, Any]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=BasicTokenizer(do_lower_case=_UpperCamelCase						)

         self.assertListEqual(
             tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU?  """						)				,["""HeLLo""", """!""", """how""", """Are""", """yoU""", """?"""]						)




     def   __A				(	self			: Any						)		->   Dict:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=BasicTokenizer(do_lower_case=_UpperCamelCase				,strip_accents=_UpperCamelCase						)

         self.assertListEqual(
             tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """						)				,["""HäLLo""", """!""", """how""", """Are""", """yoU""", """?"""]						)




     def   __A				(	self			: Union[str, Any]						)		->   Optional[int]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=BasicTokenizer(do_lower_case=_UpperCamelCase				,strip_accents=_UpperCamelCase						)

         self.assertListEqual(
             tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """						)				,["""HaLLo""", """!""", """how""", """Are""", """yoU""", """?"""]						)




     def   __A				(	self			: Optional[int]						)		->   Tuple:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=BasicTokenizer(do_lower_case=_UpperCamelCase				,never_split=["""[UNK]"""]						)

         self.assertListEqual(
             tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU? [UNK]"""						)				,["""HeLLo""", """!""", """how""", """Are""", """yoU""", """?""", """[UNK]"""]						)




     def   __A				(	self			: Union[str, Any]						)		->   int:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=["""[UNK]""", """[CLS]""", """[SEP]""", """want""", """##want""", """##ed""", """wa""", """un""", """runn""", """##ing"""]

         SCREAMING_SNAKE_CASE__								={}
         for i, token in enumerate(_UpperCamelCase						):
             SCREAMING_SNAKE_CASE__								=i
         SCREAMING_SNAKE_CASE__								=WordpieceTokenizer(vocab=_UpperCamelCase				,unk_token="""[UNK]"""						)

         self.assertListEqual(tokenizer.tokenize(""""""						)				,[]						)

         self.assertListEqual(tokenizer.tokenize("""unwanted running"""						)				,["""un""", """##want""", """##ed""", """runn""", """##ing"""]						)

         self.assertListEqual(tokenizer.tokenize("""unwantedX running"""						)				,["""[UNK]""", """runn""", """##ing"""]						)




     def   __A				(	self			: List[str]						)		->   Optional[int]:


         '''simple docstring'''





         self.assertTrue(_is_whitespace(""" """						)						)
         self.assertTrue(_is_whitespace("""\t"""						)						)
         self.assertTrue(_is_whitespace("""\r"""						)						)
         self.assertTrue(_is_whitespace("""\n"""						)						)
         self.assertTrue(_is_whitespace("""\u00A0"""						)						)

         self.assertFalse(_is_whitespace("""A"""						)						)
         self.assertFalse(_is_whitespace("""-"""						)						)




     def   __A				(	self			: Optional[Any]						)		->   Union[str, Any]:


         '''simple docstring'''





         self.assertTrue(_is_control("""\u0005"""						)						)

         self.assertFalse(_is_control("""A"""						)						)
         self.assertFalse(_is_control(""" """						)						)
         self.assertFalse(_is_control("""\t"""						)						)
         self.assertFalse(_is_control("""\r"""						)						)




     def   __A				(	self			: List[Any]						)		->   int:


         '''simple docstring'''





         self.assertTrue(_is_punctuation("""-"""						)						)
         self.assertTrue(_is_punctuation("""$"""						)						)
         self.assertTrue(_is_punctuation("""`"""						)						)
         self.assertTrue(_is_punctuation("""."""						)						)

         self.assertFalse(_is_punctuation("""A"""						)						)
         self.assertFalse(_is_punctuation(""" """						)						)




     def   __A				(	self			: List[Any]						)		->   str:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=self.get_tokenizer()
         SCREAMING_SNAKE_CASE__								=self.get_rust_tokenizer()

         # Example taken from the issue https://github.com/huggingface/tokenizers/issues/340
         self.assertListEqual([tokenizer.tokenize(_UpperCamelCase						) for t in ["""Test""", """\xad""", """test"""]]				,[["""[UNK]"""], [], ["""[UNK]"""]]						)

         self.assertListEqual(
             [rust_tokenizer.tokenize(_UpperCamelCase						) for t in ["""Test""", """\xad""", """test"""]]				,[["""[UNK]"""], [], ["""[UNK]"""]]						)




     @slow
     def   __A				(	self			: Union[str, Any]						)		->   Tuple:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=self.tokenizer_class.from_pretrained("""google/electra-base-discriminator"""						)

         SCREAMING_SNAKE_CASE__								=tokenizer.encode("""sequence builders"""				,add_special_tokens=_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__								=tokenizer.encode("""multi-sequence build"""				,add_special_tokens=_UpperCamelCase						)

         SCREAMING_SNAKE_CASE__								=tokenizer.build_inputs_with_special_tokens(_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__								=tokenizer.build_inputs_with_special_tokens(_UpperCamelCase				,_UpperCamelCase						)

         assert encoded_sentence == [1_0_1] + text + [1_0_2]
         assert encoded_pair == [1_0_1] + text + [1_0_2] + text_a + [1_0_2]




     def   __A				(	self			: Optional[Any]						)		->   Optional[int]:


         '''simple docstring'''





         for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
             with self.subTest(f"""{tokenizer.__class__.__name__} ({pretrained_name})"""						):
                 SCREAMING_SNAKE_CASE__								=self.rust_tokenizer_class.from_pretrained(_UpperCamelCase				,**_UpperCamelCase						)

                 SCREAMING_SNAKE_CASE__								=f"""A, naïve {tokenizer_r.mask_token} AllenNLP sentence."""
                 SCREAMING_SNAKE_CASE__								=tokenizer_r.encode_plus(
                     _UpperCamelCase				,return_attention_mask=_UpperCamelCase				,return_token_type_ids=_UpperCamelCase				,return_offsets_mapping=_UpperCamelCase				,add_special_tokens=_UpperCamelCase				,)

                 SCREAMING_SNAKE_CASE__								=tokenizer_r.do_lower_case if hasattr(_UpperCamelCase				,"""do_lower_case"""						) else False
                 SCREAMING_SNAKE_CASE__								=(
                     [
                         ((0, 0), tokenizer_r.cls_token),
                         ((0, 1), """A"""),
                         ((1, 2), ""","""),
                         ((3, 5), """na"""),
                         ((5, 6), """##ï"""),
                         ((6, 8), """##ve"""),
                         ((9, 1_5), tokenizer_r.mask_token),
                         ((1_6, 2_1), """Allen"""),
                         ((2_1, 2_3), """##NL"""),
                         ((2_3, 2_4), """##P"""),
                         ((2_5, 3_3), """sentence"""),
                         ((3_3, 3_4), """."""),
                         ((0, 0), tokenizer_r.sep_token),
                     ]
                     if not do_lower_case
                     else [
                         ((0, 0), tokenizer_r.cls_token),
                         ((0, 1), """a"""),
                         ((1, 2), ""","""),
                         ((3, 8), """naive"""),
                         ((9, 1_5), tokenizer_r.mask_token),
                         ((1_6, 2_1), """allen"""),
                         ((2_1, 2_3), """##nl"""),
                         ((2_3, 2_4), """##p"""),
                         ((2_5, 3_3), """sentence"""),
                         ((3_3, 3_4), """."""),
                         ((0, 0), tokenizer_r.sep_token),
                     ]
                 )

                 self.assertEqual(
                     [e[1] for e in expected_results]				,tokenizer_r.convert_ids_to_tokens(tokens["""input_ids"""]						)						)
                 self.assertEqual([e[0] for e in expected_results]				,tokens["""offset_mapping"""]						)




     def   __A				(	self			: List[str]						)		->   Union[str, Any]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=["""的""", """人""", """有"""]
         SCREAMING_SNAKE_CASE__								="""""".join(_UpperCamelCase						)
         for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
             with self.subTest(f"""{tokenizer.__class__.__name__} ({pretrained_name})"""						):
                 SCREAMING_SNAKE_CASE__								=True
                 SCREAMING_SNAKE_CASE__								=self.tokenizer_class.from_pretrained(_UpperCamelCase				,**_UpperCamelCase						)
                 SCREAMING_SNAKE_CASE__								=self.rust_tokenizer_class.from_pretrained(_UpperCamelCase				,**_UpperCamelCase						)

                 SCREAMING_SNAKE_CASE__								=tokenizer_p.encode(_UpperCamelCase				,add_special_tokens=_UpperCamelCase						)
                 SCREAMING_SNAKE_CASE__								=tokenizer_r.encode(_UpperCamelCase				,add_special_tokens=_UpperCamelCase						)

                 SCREAMING_SNAKE_CASE__								=tokenizer_r.convert_ids_to_tokens(_UpperCamelCase						)
                 SCREAMING_SNAKE_CASE__								=tokenizer_p.convert_ids_to_tokens(_UpperCamelCase						)

                 # it is expected that each Chinese character is not preceded by "##"
                 self.assertListEqual(_UpperCamelCase				,_UpperCamelCase						)
                 self.assertListEqual(_UpperCamelCase				,_UpperCamelCase						)

                 SCREAMING_SNAKE_CASE__								=False
                 SCREAMING_SNAKE_CASE__								=self.rust_tokenizer_class.from_pretrained(_UpperCamelCase				,**_UpperCamelCase						)
                 SCREAMING_SNAKE_CASE__								=self.tokenizer_class.from_pretrained(_UpperCamelCase				,**_UpperCamelCase						)

                 SCREAMING_SNAKE_CASE__								=tokenizer_r.encode(_UpperCamelCase				,add_special_tokens=_UpperCamelCase						)
                 SCREAMING_SNAKE_CASE__								=tokenizer_p.encode(_UpperCamelCase				,add_special_tokens=_UpperCamelCase						)

                 SCREAMING_SNAKE_CASE__								=tokenizer_r.convert_ids_to_tokens(_UpperCamelCase						)
                 SCREAMING_SNAKE_CASE__								=tokenizer_p.convert_ids_to_tokens(_UpperCamelCase						)

                 # it is expected that only the first Chinese character is not preceded by "##".
                 SCREAMING_SNAKE_CASE__								=[
                     f"""##{token}""" if idx != 0 else token for idx, token in enumerate(_UpperCamelCase						)
                 ]
                 self.assertListEqual(_UpperCamelCase				,_UpperCamelCase						)
                 self.assertListEqual(_UpperCamelCase				,_UpperCamelCase						)












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			: int				,_UpperCamelCase			: str				,_UpperCamelCase			: Optional[int]=2				,_UpperCamelCase			: Tuple=8				,_UpperCamelCase			: Union[str, Any]=True				,_UpperCamelCase			: Tuple=False				,_UpperCamelCase			: Tuple=False				,_UpperCamelCase			: Optional[Any]=False				,_UpperCamelCase			: Union[str, Any]=False				,_UpperCamelCase			: Dict=9_9				,_UpperCamelCase			: int=3_2				,_UpperCamelCase			: Tuple=3				,_UpperCamelCase			: Dict=4				,_UpperCamelCase			: Optional[int]=3_7				,_UpperCamelCase			: int=3_2				,_UpperCamelCase			: Optional[int]=1_2_8				,_UpperCamelCase			: Optional[Any]=8				,_UpperCamelCase			: Optional[int]=8				,_UpperCamelCase			: Tuple=8				,_UpperCamelCase			: Optional[int]=1.0				,_UpperCamelCase			: List[Any]=True				,)		->   Optional[Any]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=parent
         SCREAMING_SNAKE_CASE__								=batch_size
         SCREAMING_SNAKE_CASE__								=seq_length
         SCREAMING_SNAKE_CASE__								=is_training
         SCREAMING_SNAKE_CASE__								=use_token_type_ids
         SCREAMING_SNAKE_CASE__								=use_input_mask
         SCREAMING_SNAKE_CASE__								=use_labels
         SCREAMING_SNAKE_CASE__								=use_mc_token_ids
         SCREAMING_SNAKE_CASE__								=vocab_size
         SCREAMING_SNAKE_CASE__								=hidden_size
         SCREAMING_SNAKE_CASE__								=num_hidden_layers
         SCREAMING_SNAKE_CASE__								=num_attention_heads
         SCREAMING_SNAKE_CASE__								=intermediate_size
         SCREAMING_SNAKE_CASE__								=num_buckets
         SCREAMING_SNAKE_CASE__								=max_distance
         SCREAMING_SNAKE_CASE__								=prompt_length
         SCREAMING_SNAKE_CASE__								=prompt_types
         SCREAMING_SNAKE_CASE__								=segment_types
         SCREAMING_SNAKE_CASE__								=init_std
         SCREAMING_SNAKE_CASE__								=return_dict




     def   __A				(	self			: List[Any]						)		->   Union[str, Any]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								={}
         SCREAMING_SNAKE_CASE__								=ids_tensor([self.batch_size, self.seq_length]				,self.vocab_size						).type(torch.intaa						)
         SCREAMING_SNAKE_CASE__								=False

         SCREAMING_SNAKE_CASE__								=self.get_config()

         return (config, input_ids)




     def   __A				(	self			: Tuple						)		->   List[Any]:


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




     def   __A				(	self			: Any				,_UpperCamelCase			: Dict				,_UpperCamelCase			: List[Any]				,*_UpperCamelCase			: str						)		->   List[Any]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=CpmAntModel(config=_UpperCamelCase						)
         model.to(_UpperCamelCase						)
         model.eval()

         SCREAMING_SNAKE_CASE__								=model(**_UpperCamelCase						).last_hidden_state

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




     def   __A				(	self			: int				,_UpperCamelCase			: str				,_UpperCamelCase			: Tuple				,*_UpperCamelCase			: Dict						)		->   str:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=CpmAntForCausalLM(_UpperCamelCase						)
         model.to(_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__								=input_ids["""input_ids"""].to(_UpperCamelCase						)
         model.eval()

         SCREAMING_SNAKE_CASE__								=model(**_UpperCamelCase						)
         self.parent.assertEqual(
             model_output.logits.shape				,(self.batch_size, self.seq_length, config.vocab_size + config.prompt_types * config.prompt_length)				,)




     def   __A				(	self			: str						)		->   List[Any]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__			,		SCREAMING_SNAKE_CASE__								=self.prepare_config_and_inputs()
         return config, inputs_dict






@require_torch
class       __a					( __lowerCamelCase							,     __lowerCamelCase							,     unittest.TestCase     ):


     """simple docstring"""


     _A				:    List[Any]									=  (CpmAntModel, CpmAntForCausalLM) if is_torch_available() else ()
     _A				:    Any									=  (
         {"feature-extraction": CpmAntModel, "text-generation": CpmAntForCausalLM} if is_torch_available() else {}
     )

     _A				:    Optional[int]									=  False
     _A				:    Optional[int]									=  False
     _A				:    Optional[Any]									=  False
     _A				:    Any									=  False
     _A				:    int									=  False




     def   __A				(	self			: int						)		->   List[Any]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								=CpmAntModelTester(self						)
         SCREAMING_SNAKE_CASE__								=ConfigTester(self				,config_class=_UpperCamelCase						)




     def   __A				(	self			: Optional[int]						)		->   Dict:


         '''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   __A				(	self			: Tuple						)		->   List[Any]:


         '''simple docstring'''





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




     def   __A				(	self			: str						)		->   Dict:


         '''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   __A				(	self			: Any						)		->   List[str]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__			,		SCREAMING_SNAKE_CASE__								=self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_cpmant_model(_UpperCamelCase				,_UpperCamelCase						)




     def   __A				(	self			: str						)		->   Tuple:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__			,		SCREAMING_SNAKE_CASE__								=self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_lm_head_model(_UpperCamelCase				,_UpperCamelCase						)






@require_torch
class       __a					( unittest.TestCase     ):


     """simple docstring"""


     @tooslow
     def   __A				(	self			: Optional[Any]						)		->   Tuple:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								="""今天天气真好！"""
         SCREAMING_SNAKE_CASE__								="""openbmb/cpm-ant-10b"""
         SCREAMING_SNAKE_CASE__								=CpmAntModel.from_pretrained(_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__								=CpmAntTokenizer.from_pretrained(_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__								=tokenizer(_UpperCamelCase				,return_tensors="""pt"""						)
         SCREAMING_SNAKE_CASE__								=model(**_UpperCamelCase						).last_hidden_state

         SCREAMING_SNAKE_CASE__								=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]				,_UpperCamelCase				,atol=1e-2						)						)






@require_torch
class       __a					( unittest.TestCase     ):


     """simple docstring"""


     @tooslow
     def   __A				(	self			: List[Any]						)		->   Optional[Any]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__								="""今天天气真好！"""
         SCREAMING_SNAKE_CASE__								="""openbmb/cpm-ant-10b"""
         SCREAMING_SNAKE_CASE__								=CpmAntForCausalLM.from_pretrained(_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__								=CpmAntTokenizer.from_pretrained(_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__								=tokenizer(_UpperCamelCase				,return_tensors="""pt"""						)
         SCREAMING_SNAKE_CASE__								=model(**_UpperCamelCase						).logits

         SCREAMING_SNAKE_CASE__								=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]				,_UpperCamelCase				,atol=1e-2						)						)




     @tooslow
     def   __A				(	self			: Any						)		->   Any:


         '''simple docstring'''





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




     @tooslow
     def   __A				(	self			: Optional[Any]						)		->   Union[str, Any]:


         '''simple docstring'''





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






