



import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
						import torch

if is_vision_available():
						from PIL import Image

						from transformers import MobileViTImageProcessor




class      __UpperCamelCase       (unittest.TestCase			):







	def __init__(    self ,				_lowerCAmelCase ,				_lowerCAmelCase=7 ,				_lowerCAmelCase=3 ,				_lowerCAmelCase=18 ,				_lowerCAmelCase=30 ,				_lowerCAmelCase=400 ,				_lowerCAmelCase=True ,				_lowerCAmelCase=None ,				_lowerCAmelCase=True ,				_lowerCAmelCase=None ,				_lowerCAmelCase=True ,				)    ->    Optional[int]:
							'''simple docstring'''






							lowercase        =							size if size is not None else {"""shortest_edge""": 20}
							lowercase        =							crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
							lowercase        =							parent
							lowercase        =							batch_size
							lowercase        =							num_channels
							lowercase        =							image_size
							lowercase        =							min_resolution
							lowercase        =							max_resolution
							lowercase        =							do_resize
							lowercase        =							size
							lowercase        =							do_center_crop
							lowercase        =							crop_size
							lowercase        =							do_flip_channel_order







	def   _a   (    self						)    ->    Optional[int]:
							'''simple docstring'''






							return {
							    "do_resize": self.do_resize,
							    "size": self.size,
							    "do_center_crop": self.do_center_crop,
							    "crop_size": self.crop_size,
							    "do_flip_channel_order": self.do_flip_channel_order,
							}




@require_torch
@require_vision
class      __UpperCamelCase       (_UpperCAmelCase			,   unittest.TestCase			):
	__A			  =					MobileViTImageProcessor if is_vision_available() else None







	def   _a   (    self						)    ->    Optional[Any]:
							'''simple docstring'''






							lowercase        =							MobileViTImageProcessingTester(self						)







	@property
	def   _a   (    self						)    ->    Any:
							'''simple docstring'''






							return self.image_processor_tester.prepare_image_processor_dict()







	def   _a   (    self						)    ->    Any:
							'''simple docstring'''






							lowercase        =							self.image_processing_class(**self.image_processor_dict						)
							self.assertTrue(hasattr(_lowerCAmelCase ,				"""do_resize"""						)						)
							self.assertTrue(hasattr(_lowerCAmelCase ,				"""size"""						)						)
							self.assertTrue(hasattr(_lowerCAmelCase ,				"""do_center_crop"""						)						)
							self.assertTrue(hasattr(_lowerCAmelCase ,				"""center_crop"""						)						)
							self.assertTrue(hasattr(_lowerCAmelCase ,				"""do_flip_channel_order"""						)						)







	def   _a   (    self						)    ->    Optional[int]:
							'''simple docstring'''






							lowercase        =							self.image_processing_class.from_dict(self.image_processor_dict						)
							self.assertEqual(image_processor.size ,				{"""shortest_edge""": 20}						)
							self.assertEqual(image_processor.crop_size ,				{"""height""": 18, """width""": 18}						)

							lowercase        =							self.image_processing_class.from_dict(self.image_processor_dict ,				size=42 ,				crop_size=84						)
							self.assertEqual(image_processor.size ,				{"""shortest_edge""": 42}						)
							self.assertEqual(image_processor.crop_size ,				{"""height""": 84, """width""": 84}						)







	def   _a   (    self						)    ->    Union[str, Any]:
							'''simple docstring'''






							pass







	def   _a   (    self						)    ->    Union[str, Any]:
							'''simple docstring'''






							lowercase        =							self.image_processing_class(**self.image_processor_dict						)
							# create random PIL images
							lowercase        =							prepare_image_inputs(self.image_processor_tester ,				equal_resolution=_lowerCAmelCase						)
							for image in image_inputs:
													self.assertIsInstance(_lowerCAmelCase ,				Image.Image						)

							# Test not batched input
							lowercase        =							image_processing(image_inputs[0] ,				return_tensors="""pt"""						).pixel_values
							self.assertEqual(
							    encoded_images.shape ,				(
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    ) ,				)

							# Test batched
							lowercase        =							image_processing(_lowerCAmelCase ,				return_tensors="""pt"""						).pixel_values
							self.assertEqual(
							    encoded_images.shape ,				(
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    ) ,				)







	def   _a   (    self						)    ->    List[Any]:
							'''simple docstring'''






							lowercase        =							self.image_processing_class(**self.image_processor_dict						)
							# create random numpy tensors
							lowercase        =							prepare_image_inputs(self.image_processor_tester ,				equal_resolution=_lowerCAmelCase ,				numpify=_lowerCAmelCase						)
							for image in image_inputs:
													self.assertIsInstance(_lowerCAmelCase ,				np.ndarray						)

							# Test not batched input
							lowercase        =							image_processing(image_inputs[0] ,				return_tensors="""pt"""						).pixel_values
							self.assertEqual(
							    encoded_images.shape ,				(
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    ) ,				)

							# Test batched
							lowercase        =							image_processing(_lowerCAmelCase ,				return_tensors="""pt"""						).pixel_values
							self.assertEqual(
							    encoded_images.shape ,				(
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    ) ,				)







	def   _a   (    self						)    ->    Optional[int]:
							'''simple docstring'''






							lowercase        =							self.image_processing_class(**self.image_processor_dict						)
							# create random PyTorch tensors
							lowercase        =							prepare_image_inputs(self.image_processor_tester ,				equal_resolution=_lowerCAmelCase ,				torchify=_lowerCAmelCase						)
							for image in image_inputs:
													self.assertIsInstance(_lowerCAmelCase ,				torch.Tensor						)

							# Test not batched input
							lowercase        =							image_processing(image_inputs[0] ,				return_tensors="""pt"""						).pixel_values
							self.assertEqual(
							    encoded_images.shape ,				(
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    ) ,				)

							# Test batched
							lowercase        =							image_processing(_lowerCAmelCase ,				return_tensors="""pt"""						).pixel_values
							self.assertEqual(
							    encoded_images.shape ,				(
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    ) ,				)







'''simple docstring'''


from ... import PretrainedConfig


lowercase_      :				int   					=    {
    '''sijunhe/nezha-cn-base''': '''https://huggingface.co/sijunhe/nezha-cn-base/resolve/main/config.json''',
}




class      __UpperCamelCase       (_UpperCAmelCase			):
	__A			  =					NEZHA_PRETRAINED_CONFIG_ARCHIVE_MAP
	__A			  =					'''nezha'''







	def __init__(    self ,				_lowerCAmelCase=2_1128 ,				_lowerCAmelCase=768 ,				_lowerCAmelCase=12 ,				_lowerCAmelCase=12 ,				_lowerCAmelCase=3072 ,				_lowerCAmelCase="gelu" ,				_lowerCAmelCase=0.1 ,				_lowerCAmelCase=0.1 ,				_lowerCAmelCase=512 ,				_lowerCAmelCase=64 ,				_lowerCAmelCase=2 ,				_lowerCAmelCase=0.02 ,				_lowerCAmelCase=1E-12 ,				_lowerCAmelCase=0.1 ,				_lowerCAmelCase=0 ,				_lowerCAmelCase=2 ,				_lowerCAmelCase=3 ,				_lowerCAmelCase=True ,				**_lowerCAmelCase ,				)    ->    int:
							'''simple docstring'''






							super().__init__(pad_token_id=_lowerCAmelCase ,				bos_token_id=_lowerCAmelCase ,				eos_token_id=_lowerCAmelCase ,				**_lowerCAmelCase						)

							lowercase        =							vocab_size
							lowercase        =							hidden_size
							lowercase        =							num_hidden_layers
							lowercase        =							num_attention_heads
							lowercase        =							hidden_act
							lowercase        =							intermediate_size
							lowercase        =							hidden_dropout_prob
							lowercase        =							attention_probs_dropout_prob
							lowercase        =							max_position_embeddings
							lowercase        =							max_relative_position
							lowercase        =							type_vocab_size
							lowercase        =							initializer_range
							lowercase        =							layer_norm_eps
							lowercase        =							classifier_dropout
							lowercase        =							use_cache


