

"""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     :
			def __init__(						self ,						_A ,						_A=2 ,						_A=8 ,						_A=True ,						_A=False ,						_A=False ,						_A=False ,						_A=False ,						_A=99 ,						_A=32 ,						_A=3 ,						_A=4 ,						_A=37 ,						_A=32 ,						_A=1_28 ,						_A=8 ,						_A=8 ,						_A=8 ,						_A=1.0 ,						_A=True ,						)      ->      Dict:






				'''simple docstring'''







				_UpperCAmelCase      :							Union[str, Any]       =   parent
				_UpperCAmelCase      :							Tuple       =   batch_size
				_UpperCAmelCase      :							Dict       =   seq_length
				_UpperCAmelCase      :							Optional[Any]       =   is_training
				_UpperCAmelCase      :							Optional[int]       =   use_token_type_ids
				_UpperCAmelCase      :							List[str]       =   use_input_mask
				_UpperCAmelCase      :							str       =   use_labels
				_UpperCAmelCase      :							Tuple       =   use_mc_token_ids
				_UpperCAmelCase      :							Dict       =   vocab_size
				_UpperCAmelCase      :							Any       =   hidden_size
				_UpperCAmelCase      :							Union[str, Any]       =   num_hidden_layers
				_UpperCAmelCase      :							List[Any]       =   num_attention_heads
				_UpperCAmelCase      :							Union[str, Any]       =   intermediate_size
				_UpperCAmelCase      :							Tuple       =   num_buckets
				_UpperCAmelCase      :							Optional[Any]       =   max_distance
				_UpperCAmelCase      :							List[Any]       =   prompt_length
				_UpperCAmelCase      :							Optional[int]       =   prompt_types
				_UpperCAmelCase      :							List[Any]       =   segment_types
				_UpperCAmelCase      :							List[str]       =   init_std
				_UpperCAmelCase      :							int       =   return_dict
			def 							__snake_case	(						self       )      ->      Union[str, Any]:






				'''simple docstring'''







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

				_UpperCAmelCase      :							Any       =   self.get_config()

				return (config, input_ids)
			def 							__snake_case	(						self       )      ->      Optional[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=_A ,						init_std=self.init_std ,						return_dict=self.return_dict ,						)
			def 							__snake_case	(						self ,						_A ,						_A ,						*_A       )      ->      str:






				'''simple docstring'''







				_UpperCAmelCase      :							Union[str, Any]       =   CpmAntModel(config=_A       )
				model.to(_A       )
				model.eval()

				_UpperCAmelCase      :							Any       =   model(**_A       ).last_hidden_state

				self.parent.assertEqual(hidden_states.shape ,						(self.batch_size, self.seq_length, config.hidden_size)       )
			def 							__snake_case	(						self ,						_A ,						_A ,						*_A       )      ->      int:






				'''simple docstring'''







				_UpperCAmelCase      :							Dict       =   CpmAntForCausalLM(_A       )
				model.to(_A       )
				_UpperCAmelCase      :							List[Any]       =   input_ids['input_ids'].to(_A       )
				model.eval()

				_UpperCAmelCase      :							Any       =   model(**_A       )
				self.parent.assertEqual(
				    model_output.logits.shape ,						(self.batch_size, self.seq_length, config.vocab_size + config.prompt_types * config.prompt_length) ,						)
			def 							__snake_case	(						self       )      ->      Optional[int]:






				'''simple docstring'''







				_UpperCAmelCase      :							Optional[Any]       =   self.prepare_config_and_inputs()
				return config, inputs_dict






@require_torch
class       _UpperCAmelCase     (						snake_case__      ,       snake_case__      ,       unittest.TestCase):
			__a	:    Any			   =							(CpmAntModel, CpmAntForCausalLM) if is_torch_available() else ()
			__a	:    List[Any]			   =							(
			    {'feature-extraction': CpmAntModel, 'text-generation': CpmAntForCausalLM} if is_torch_available() else {}
			)

			__a	:    int			   =							False
			__a	:    Union[str, Any]			   =							False
			__a	:    Optional[Any]			   =							False
			__a	:    Any			   =							False
			__a	:    str			   =							False
			def 							__snake_case	(						self       )      ->      List[str]:






				'''simple docstring'''







				_UpperCAmelCase      :							Dict       =   CpmAntModelTester(self       )
				_UpperCAmelCase      :							List[str]       =   ConfigTester(self ,						config_class=_A       )
			def 							__snake_case	(						self       )      ->      Any:






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






				'''simple docstring'''







				unittest.skip("""CPMAnt doesn\'t support input_embeds."""       )(self.test_inputs_embeds       )
			def 							__snake_case	(						self       )      ->      Optional[Any]:






				'''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 							__snake_case	(						self       )      ->      Dict:






				'''simple docstring'''







				_UpperCAmelCase      :							Union[str, Any]       =   self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_cpmant_model(_A ,						_A       )
			def 							__snake_case	(						self       )      ->      int:






				'''simple docstring'''







				_UpperCAmelCase      :							Any       =   self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_lm_head_model(_A ,						_A       )






@require_torch
class       _UpperCAmelCase     (						unittest.TestCase):
			@tooslow
			def 							__snake_case	(						self       )      ->      List[Any]:






				'''simple docstring'''







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

				_UpperCAmelCase      :							Union[str, Any]       =   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] ,						_A ,						atol=1e-2       )       )






@require_torch
class       _UpperCAmelCase     (						unittest.TestCase):
			@tooslow
			def 							__snake_case	(						self       )      ->      Optional[int]:






				'''simple docstring'''







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

				_UpperCAmelCase      :							List[Any]       =   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] ,						_A ,						atol=1e-2       )       )
			@tooslow
			def 							__snake_case	(						self       )      ->      List[Any]:






				'''simple docstring'''







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






				'''simple docstring'''







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








"""simple docstring"""






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


lowerCamelCase__			:					Union[str, Any]							  =					{
    '''configuration_unispeech_sat''': ['''UNISPEECH_SAT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''UniSpeechSatConfig'''],
}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCamelCase__			:					List[str]							  =					[
						    '''UNISPEECH_SAT_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''UniSpeechSatForAudioFrameClassification''',
						    '''UniSpeechSatForCTC''',
						    '''UniSpeechSatForPreTraining''',
						    '''UniSpeechSatForSequenceClassification''',
						    '''UniSpeechSatForXVector''',
						    '''UniSpeechSatModel''',
						    '''UniSpeechSatPreTrainedModel''',
						]

if TYPE_CHECKING:
						from .configuration_unispeech_sat import UNISPEECH_SAT_PRETRAINED_CONFIG_ARCHIVE_MAP, UniSpeechSatConfig

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_unispeech_sat import (
												    UNISPEECH_SAT_PRETRAINED_MODEL_ARCHIVE_LIST,
												    UniSpeechSatForAudioFrameClassification,
												    UniSpeechSatForCTC,
												    UniSpeechSatForPreTraining,
												    UniSpeechSatForSequenceClassification,
												    UniSpeechSatForXVector,
												    UniSpeechSatModel,
												    UniSpeechSatPreTrainedModel,
												)

else:
						import sys

						lowerCamelCase__			:					Any							  =					_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)





