


"""simple docstring"""






import collections
import inspect
import unittest

from transformers import SwinvaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch
					from torch import nn

					from transformers import SwinvaForImageClassification, SwinvaForMaskedImageModeling, SwinvaModel
					from transformers.models.swinva.modeling_swinva import SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
					from PIL import Image

					from transformers import AutoImageProcessor






class      A:

		"""simple docstring"""





		def __init__( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__=13					,				SCREAMING_SNAKE_CASE__=32					,				SCREAMING_SNAKE_CASE__=2					,				SCREAMING_SNAKE_CASE__=3					,				SCREAMING_SNAKE_CASE__=16					,				SCREAMING_SNAKE_CASE__=[1, 2, 1]					,				SCREAMING_SNAKE_CASE__=[2, 2, 4]					,				SCREAMING_SNAKE_CASE__=2					,				SCREAMING_SNAKE_CASE__=2.0					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__=0.0					,				SCREAMING_SNAKE_CASE__=0.0					,				SCREAMING_SNAKE_CASE__=0.1					,				SCREAMING_SNAKE_CASE__="gelu"					,				SCREAMING_SNAKE_CASE__=False					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__=0.0_2					,				SCREAMING_SNAKE_CASE__=1E-5					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__=None					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__=10					,				SCREAMING_SNAKE_CASE__=8					,				)      ->	int:

					"""simple docstring"""



					_UpperCamelCase					:Union[str, Any]					     =	parent
					_UpperCamelCase					:Any					     =	batch_size
					_UpperCamelCase					:List[Any]					     =	image_size
					_UpperCamelCase					:List[str]					     =	patch_size
					_UpperCamelCase					:Optional[Any]					     =	num_channels
					_UpperCamelCase					:Optional[Any]					     =	embed_dim
					_UpperCamelCase					:Tuple					     =	depths
					_UpperCamelCase					:str					     =	num_heads
					_UpperCamelCase					:int					     =	window_size
					_UpperCamelCase					:List[Any]					     =	mlp_ratio
					_UpperCamelCase					:Union[str, Any]					     =	qkv_bias
					_UpperCamelCase					:str					     =	hidden_dropout_prob
					_UpperCamelCase					:Any					     =	attention_probs_dropout_prob
					_UpperCamelCase					:Any					     =	drop_path_rate
					_UpperCamelCase					:Any					     =	hidden_act
					_UpperCamelCase					:Tuple					     =	use_absolute_embeddings
					_UpperCamelCase					:str					     =	patch_norm
					_UpperCamelCase					:Union[str, Any]					     =	layer_norm_eps
					_UpperCamelCase					:int					     =	initializer_range
					_UpperCamelCase					:int					     =	is_training
					_UpperCamelCase					:List[str]					     =	scope
					_UpperCamelCase					:List[Any]					     =	use_labels
					_UpperCamelCase					:List[Any]					     =	type_sequence_label_size
					_UpperCamelCase					:List[str]					     =	encoder_stride
		def   _UpperCamelCase( self   )      ->	str:

					"""simple docstring"""



					_UpperCamelCase					:Optional[int]					     =	floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]   )

					_UpperCamelCase					:Tuple					     =	None
					if self.use_labels:
								_UpperCamelCase					:str					     =	ids_tensor([self.batch_size]					,				self.type_sequence_label_size   )

					_UpperCamelCase					:int					     =	self.get_config()

					return config, pixel_values, labels
		def   _UpperCamelCase( self   )      ->	Optional[Any]:

					"""simple docstring"""



					return SwinvaConfig(
					    image_size=self.image_size					,				patch_size=self.patch_size					,				num_channels=self.num_channels					,				embed_dim=self.embed_dim					,				depths=self.depths					,				num_heads=self.num_heads					,				window_size=self.window_size					,				mlp_ratio=self.mlp_ratio					,				qkv_bias=self.qkv_bias					,				hidden_dropout_prob=self.hidden_dropout_prob					,				attention_probs_dropout_prob=self.attention_probs_dropout_prob					,				drop_path_rate=self.drop_path_rate					,				hidden_act=self.hidden_act					,				use_absolute_embeddings=self.use_absolute_embeddings					,				path_norm=self.patch_norm					,				layer_norm_eps=self.layer_norm_eps					,				initializer_range=self.initializer_range					,				encoder_stride=self.encoder_stride					,				)
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )      ->	List[str]:

					"""simple docstring"""



					_UpperCamelCase					:Any					     =	SwinvaModel(config=SCREAMING_SNAKE_CASE__   )
					model.to(SCREAMING_SNAKE_CASE__   )
					model.eval()
					_UpperCamelCase					:Optional[Any]					     =	model(SCREAMING_SNAKE_CASE__   )

					_UpperCamelCase					:str					     =	((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths   ) - 1))
					_UpperCamelCase					:Optional[Any]					     =	int(config.embed_dim * 2 ** (len(config.depths   ) - 1)   )

					self.parent.assertEqual(result.last_hidden_state.shape					,				(self.batch_size, expected_seq_len, expected_dim)   )
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )      ->	List[Any]:

					"""simple docstring"""



					_UpperCamelCase					:int					     =	SwinvaForMaskedImageModeling(config=SCREAMING_SNAKE_CASE__   )
					model.to(SCREAMING_SNAKE_CASE__   )
					model.eval()
					_UpperCamelCase					:List[str]					     =	model(SCREAMING_SNAKE_CASE__   )
					self.parent.assertEqual(
					    result.logits.shape					,				(self.batch_size, self.num_channels, self.image_size, self.image_size)   )

					# test greyscale images
					_UpperCamelCase					:Any					     =	1
					_UpperCamelCase					:Any					     =	SwinvaForMaskedImageModeling(SCREAMING_SNAKE_CASE__   )
					model.to(SCREAMING_SNAKE_CASE__   )
					model.eval()

					_UpperCamelCase					:Optional[Any]					     =	floats_tensor([self.batch_size, 1, self.image_size, self.image_size]   )
					_UpperCamelCase					:Tuple					     =	model(SCREAMING_SNAKE_CASE__   )
					self.parent.assertEqual(result.logits.shape					,				(self.batch_size, 1, self.image_size, self.image_size)   )
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )      ->	str:

					"""simple docstring"""



					_UpperCamelCase					:Union[str, Any]					     =	self.type_sequence_label_size
					_UpperCamelCase					:Union[str, Any]					     =	SwinvaForImageClassification(SCREAMING_SNAKE_CASE__   )
					model.to(SCREAMING_SNAKE_CASE__   )
					model.eval()
					_UpperCamelCase					:List[Any]					     =	model(SCREAMING_SNAKE_CASE__					,				labels=SCREAMING_SNAKE_CASE__   )
					self.parent.assertEqual(result.logits.shape					,				(self.batch_size, self.type_sequence_label_size)   )





		def   _UpperCamelCase( self   )      ->	List[Any]:

					"""simple docstring"""



					_UpperCamelCase					:Optional[Any]					     =	self.prepare_config_and_inputs()
					_UpperCamelCase     ,      _UpperCamelCase     ,      _UpperCamelCase					:Optional[int]					     =	config_and_inputs
					_UpperCamelCase					:Optional[Any]					     =	{'''pixel_values''': pixel_values}
					return config, inputs_dict






@require_torch
class      A(  lowerCamelCase__				,							lowerCamelCase__				,							unittest.TestCase		):

		"""simple docstring"""





		A    =							(
		    (SwinvaModel, SwinvaForImageClassification, SwinvaForMaskedImageModeling) if is_torch_available() else ()
		)
		A    =							(
		    {"feature-extraction": SwinvaModel, "image-classification": SwinvaForImageClassification}
		    if is_torch_available()
		    else {}
		)

		A    =							False
		A    =							False
		A    =							False
		A    =							False
		def   _UpperCamelCase( self   )      ->	List[Any]:

					"""simple docstring"""



					_UpperCamelCase					:Any					     =	SwinvaModelTester(self   )
					_UpperCamelCase					:Optional[int]					     =	ConfigTester(self					,				config_class=SCREAMING_SNAKE_CASE__					,				embed_dim=37   )
		def   _UpperCamelCase( self   )      ->	Dict:

					"""simple docstring"""



					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.create_and_test_config_with_num_labels()
					self.config_tester.check_config_can_be_init_without_params()
					self.config_tester.check_config_arguments_init()
		def   _UpperCamelCase( self   )      ->	List[str]:

					"""simple docstring"""



					_UpperCamelCase					:List[Any]					     =	self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE__   )
		@unittest.skip(reason='''Got `CUDA error: misaligned address` with PyTorch 2.0.0.'''   )
		def   _UpperCamelCase( self   )      ->	List[Any]:

					"""simple docstring"""



					pass
		@unittest.skip(reason='''Swinv2 does not use inputs_embeds'''   )
		def   _UpperCamelCase( self   )      ->	str:

					"""simple docstring"""



					pass
		def   _UpperCamelCase( self   )      ->	str:

					"""simple docstring"""



					_UpperCamelCase     ,      _UpperCamelCase					:List[Any]					     =	self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
								_UpperCamelCase					:str					     =	model_class(SCREAMING_SNAKE_CASE__   )
								self.assertIsInstance(model.get_input_embeddings()					,				(nn.Module)   )
								_UpperCamelCase					:Dict					     =	model.get_output_embeddings()
								self.assertTrue(x is None or isinstance(SCREAMING_SNAKE_CASE__					,				nn.Linear   )   )
		def   _UpperCamelCase( self   )      ->	str:

					"""simple docstring"""



					_UpperCamelCase     ,      _UpperCamelCase					:int					     =	self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
								_UpperCamelCase					:Dict					     =	model_class(SCREAMING_SNAKE_CASE__   )
								_UpperCamelCase					:Any					     =	inspect.signature(model.forward   )
								# signature.parameters is an OrderedDict => so arg_names order is deterministic
								_UpperCamelCase					:Dict					     =	[*signature.parameters.keys()]

								_UpperCamelCase					:Any					     =	['''pixel_values''']
								self.assertListEqual(arg_names[:1]					,				SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self   )      ->	List[str]:

					"""simple docstring"""



					_UpperCamelCase     ,      _UpperCamelCase					:Union[str, Any]					     =	self.model_tester.prepare_config_and_inputs_for_common()
					_UpperCamelCase					:Optional[Any]					     =	True

					for model_class in self.all_model_classes:
								_UpperCamelCase					:Optional[int]					     =	True
								_UpperCamelCase					:Optional[int]					     =	False
								_UpperCamelCase					:List[Any]					     =	True
								_UpperCamelCase					:int					     =	model_class(SCREAMING_SNAKE_CASE__   )
								model.to(SCREAMING_SNAKE_CASE__   )
								model.eval()
								with torch.no_grad():
											_UpperCamelCase					:List[Any]					     =	model(**self._prepare_for_class(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )   )
								_UpperCamelCase					:int					     =	outputs.attentions
								_UpperCamelCase					:Optional[int]					     =	len(self.model_tester.depths   )
								self.assertEqual(len(SCREAMING_SNAKE_CASE__   )					,				SCREAMING_SNAKE_CASE__   )

								# check that output_attentions also work using config
								del inputs_dict["output_attentions"]
								_UpperCamelCase					:int					     =	True
								_UpperCamelCase					:Any					     =	config.window_size**2
								_UpperCamelCase					:int					     =	model_class(SCREAMING_SNAKE_CASE__   )
								model.to(SCREAMING_SNAKE_CASE__   )
								model.eval()
								with torch.no_grad():
											_UpperCamelCase					:Tuple					     =	model(**self._prepare_for_class(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )   )
								_UpperCamelCase					:Any					     =	outputs.attentions
								self.assertEqual(len(SCREAMING_SNAKE_CASE__   )					,				SCREAMING_SNAKE_CASE__   )

								self.assertListEqual(
								    list(attentions[0].shape[-3:]   )					,				[self.model_tester.num_heads[0], window_size_squared, window_size_squared]					,				)
								_UpperCamelCase					:int					     =	len(SCREAMING_SNAKE_CASE__   )

								# Check attention is always last and order is fine
								_UpperCamelCase					:str					     =	True
								_UpperCamelCase					:int					     =	True
								_UpperCamelCase					:Any					     =	model_class(SCREAMING_SNAKE_CASE__   )
								model.to(SCREAMING_SNAKE_CASE__   )
								model.eval()
								with torch.no_grad():
											_UpperCamelCase					:int					     =	model(**self._prepare_for_class(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )   )

								if hasattr(self.model_tester					,				'''num_hidden_states_types'''   ):
											_UpperCamelCase					:Union[str, Any]					     =	self.model_tester.num_hidden_states_types
								else:
											# also another +1 for reshaped_hidden_states
											_UpperCamelCase					:Union[str, Any]					     =	2
								self.assertEqual(out_len + added_hidden_states					,				len(SCREAMING_SNAKE_CASE__   )   )

								_UpperCamelCase					:List[str]					     =	outputs.attentions

								self.assertEqual(len(SCREAMING_SNAKE_CASE__   )					,				SCREAMING_SNAKE_CASE__   )

								self.assertListEqual(
								    list(self_attentions[0].shape[-3:]   )					,				[self.model_tester.num_heads[0], window_size_squared, window_size_squared]					,				)
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )      ->	str:

					"""simple docstring"""



					_UpperCamelCase					:Tuple					     =	model_class(SCREAMING_SNAKE_CASE__   )
					model.to(SCREAMING_SNAKE_CASE__   )
					model.eval()

					with torch.no_grad():
								_UpperCamelCase					:List[Any]					     =	model(**self._prepare_for_class(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )   )

					_UpperCamelCase					:Optional[int]					     =	outputs.hidden_states

					_UpperCamelCase					:Optional[Any]					     =	getattr(
					    self.model_tester					,				'''expected_num_hidden_layers'''					,				len(self.model_tester.depths   ) + 1   )
					self.assertEqual(len(SCREAMING_SNAKE_CASE__   )					,				SCREAMING_SNAKE_CASE__   )

					# Swinv2 has a different seq_length
					_UpperCamelCase					:Union[str, Any]					     =	(
					    config.patch_size
					    if isinstance(config.patch_size					,				collections.abc.Iterable   )
					    else (config.patch_size, config.patch_size)
					)

					_UpperCamelCase					:Dict					     =	(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

					self.assertListEqual(
					    list(hidden_states[0].shape[-2:]   )					,				[num_patches, self.model_tester.embed_dim]					,				)

					_UpperCamelCase					:Any					     =	outputs.reshaped_hidden_states
					self.assertEqual(len(SCREAMING_SNAKE_CASE__   )					,				SCREAMING_SNAKE_CASE__   )

					_UpperCamelCase     ,      _UpperCamelCase     ,      _UpperCamelCase     ,      _UpperCamelCase					:List[str]					     =	reshaped_hidden_states[0].shape
					_UpperCamelCase					:Any					     =	(
					    reshaped_hidden_states[0].view(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				height * width   ).permute(0					,				2					,				1   )
					)
					self.assertListEqual(
					    list(reshaped_hidden_states.shape[-2:]   )					,				[num_patches, self.model_tester.embed_dim]					,				)
		def   _UpperCamelCase( self   )      ->	Union[str, Any]:

					"""simple docstring"""



					_UpperCamelCase     ,      _UpperCamelCase					:List[Any]					     =	self.model_tester.prepare_config_and_inputs_for_common()

					_UpperCamelCase					:int					     =	(
					    self.model_tester.image_size
					    if isinstance(self.model_tester.image_size					,				collections.abc.Iterable   )
					    else (self.model_tester.image_size, self.model_tester.image_size)
					)

					for model_class in self.all_model_classes:
								_UpperCamelCase					:Tuple					     =	True
								self.check_hidden_states_output(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )

								# check that output_hidden_states also work using config
								del inputs_dict["output_hidden_states"]
								_UpperCamelCase					:Any					     =	True

								self.check_hidden_states_output(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self   )      ->	Any:

					"""simple docstring"""



					_UpperCamelCase     ,      _UpperCamelCase					:Optional[Any]					     =	self.model_tester.prepare_config_and_inputs_for_common()
					_UpperCamelCase					:Optional[Any]					     =	3

					_UpperCamelCase					:int					     =	(
					    self.model_tester.image_size
					    if isinstance(self.model_tester.image_size					,				collections.abc.Iterable   )
					    else (self.model_tester.image_size, self.model_tester.image_size)
					)
					_UpperCamelCase					:List[Any]					     =	(
					    config.patch_size
					    if isinstance(config.patch_size					,				collections.abc.Iterable   )
					    else (config.patch_size, config.patch_size)
					)

					_UpperCamelCase					:List[Any]					     =	image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
					_UpperCamelCase					:Optional[int]					     =	image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

					for model_class in self.all_model_classes:
								_UpperCamelCase					:Optional[int]					     =	True
								self.check_hidden_states_output(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				(padded_height, padded_width)   )

								# check that output_hidden_states also work using config
								del inputs_dict["output_hidden_states"]
								_UpperCamelCase					:Union[str, Any]					     =	True
								self.check_hidden_states_output(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				(padded_height, padded_width)   )
		def   _UpperCamelCase( self   )      ->	str:

					"""simple docstring"""



					_UpperCamelCase					:Optional[Any]					     =	self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_image_modeling(*SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self   )      ->	Tuple:

					"""simple docstring"""



					_UpperCamelCase					:Optional[int]					     =	self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_image_classification(*SCREAMING_SNAKE_CASE__   )
		@slow
		def   _UpperCamelCase( self   )      ->	Optional[Any]:

					"""simple docstring"""



					for model_name in SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								_UpperCamelCase					:Tuple					     =	SwinvaModel.from_pretrained(SCREAMING_SNAKE_CASE__   )
								self.assertIsNotNone(SCREAMING_SNAKE_CASE__   )





		def   _UpperCamelCase( self   )      ->	Dict:

					"""simple docstring"""



					_UpperCamelCase     ,      _UpperCamelCase					:Dict					     =	self.model_tester.prepare_config_and_inputs_for_common()

					_UpperCamelCase					:List[str]					     =	_config_zero_init(SCREAMING_SNAKE_CASE__   )
					for model_class in self.all_model_classes:
								_UpperCamelCase					:Union[str, Any]					     =	model_class(config=SCREAMING_SNAKE_CASE__   )
								for name, param in model.named_parameters():
											if "embeddings" not in name and "logit_scale" not in name and param.requires_grad:
														self.assertIn(
														    ((param.data.mean() * 1E9).round() / 1E9).item()					,				[0.0, 1.0]					,				msg=f"Parameter {name} of model {model_class} seems not properly initialized"					,				)






@require_vision
@require_torch
class      A(  unittest.TestCase		):

		"""simple docstring"""





		@cached_property
		def   _UpperCamelCase( self   )      ->	Tuple:

					"""simple docstring"""



					return (
					    AutoImageProcessor.from_pretrained('''microsoft/swinv2-tiny-patch4-window8-256'''   )
					    if is_vision_available()
					    else None
					)





		@slow
		def   _UpperCamelCase( self   )      ->	List[Any]:

					"""simple docstring"""



					_UpperCamelCase					:Dict					     =	SwinvaForImageClassification.from_pretrained('''microsoft/swinv2-tiny-patch4-window8-256'''   ).to(
					    SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:List[str]					     =	self.default_image_processor

					_UpperCamelCase					:Any					     =	Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''   )
					_UpperCamelCase					:List[str]					     =	image_processor(images=SCREAMING_SNAKE_CASE__					,				return_tensors='''pt'''   ).to(SCREAMING_SNAKE_CASE__   )

					# forward pass
					with torch.no_grad():
								_UpperCamelCase					:Optional[int]					     =	model(**SCREAMING_SNAKE_CASE__   )

					# verify the logits
					_UpperCamelCase					:List[Any]					     =	torch.Size((1, 10_00)   )
					self.assertEqual(outputs.logits.shape					,				SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:List[str]					     =	torch.tensor([-0.3_9_4_7, -0.4_3_0_6, 0.0_0_2_6]   ).to(SCREAMING_SNAKE_CASE__   )
					self.assertTrue(torch.allclose(outputs.logits[0, :3]					,				SCREAMING_SNAKE_CASE__					,				atol=1E-4   )   )





"""simple docstring"""






import os
import unittest

from transformers.models.cpmant.tokenization_cpmant import VOCAB_FILES_NAMES, CpmAntTokenizer
from transformers.testing_utils import require_jieba, tooslow

from ...test_tokenization_common import TokenizerTesterMixin






@require_jieba
class      A(  lowerCamelCase__				,							unittest.TestCase		):

		"""simple docstring"""





		A    =							CpmAntTokenizer
		A    =							False
		def   _UpperCamelCase( self   )      ->	Union[str, Any]:

					"""simple docstring"""



					super().setUp()

					_UpperCamelCase					:str					     =	[
					    '''<d>''',
					    '''</d>''',
					    '''<s>''',
					    '''</s>''',
					    '''</_>''',
					    '''<unk>''',
					    '''<pad>''',
					    '''</n>''',
					    '''我''',
					    '''是''',
					    '''C''',
					    '''P''',
					    '''M''',
					    '''A''',
					    '''n''',
					    '''t''',
					]
					_UpperCamelCase					:List[str]					     =	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]   )   )





		@tooslow
		def   _UpperCamelCase( self   )      ->	Tuple:

					"""simple docstring"""



					_UpperCamelCase					:Any					     =	CpmAntTokenizer.from_pretrained('''openbmb/cpm-ant-10b'''   )
					_UpperCamelCase					:List[str]					     =	'''今天天气真好！'''
					_UpperCamelCase					:Tuple					     =	['''今天''', '''天气''', '''真''', '''好''', '''！''']
					_UpperCamelCase					:Tuple					     =	tokenizer.tokenize(SCREAMING_SNAKE_CASE__   )
					self.assertListEqual(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:Dict					     =	'''今天天气真好！'''
					_UpperCamelCase					:Optional[int]					     =	[tokenizer.bos_token] + tokens

					_UpperCamelCase					:List[str]					     =	[6, 98_02, 1_49_62, 20_82, 8_31, 2_44]
					self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__   )					,				SCREAMING_SNAKE_CASE__   )

					_UpperCamelCase					:str					     =	tokenizer.decode(SCREAMING_SNAKE_CASE__   )
					self.assertEqual(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )

