


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 ViTImageProcessor

class 	__a   (       unittest.TestCase    ):
		def __init__(    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE=7    ,					_SCREAMING_SNAKE_CASE=3    ,					_SCREAMING_SNAKE_CASE=18    ,					_SCREAMING_SNAKE_CASE=30    ,					_SCREAMING_SNAKE_CASE=400    ,					_SCREAMING_SNAKE_CASE=True    ,					_SCREAMING_SNAKE_CASE=None    ,					_SCREAMING_SNAKE_CASE=True    ,					_SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5]    ,					_SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5]    ,					)				-> Optional[Any]:




									"""simple docstring"""





									_UpperCAmelCase					=    size if size is not None else {'height': 18, 'width': 18}
									_UpperCAmelCase					=    parent
									_UpperCAmelCase					=    batch_size
									_UpperCAmelCase					=    num_channels
									_UpperCAmelCase					=    image_size
									_UpperCAmelCase					=    min_resolution
									_UpperCAmelCase					=    max_resolution
									_UpperCAmelCase					=    do_resize
									_UpperCAmelCase					=    size
									_UpperCAmelCase					=    do_normalize
									_UpperCAmelCase					=    image_mean
									_UpperCAmelCase					=    image_std






		def 			UpperCAmelCase__       (    self		)				-> str:




									"""simple docstring"""





									return {
									    "image_mean": self.image_mean,
									    "image_std": self.image_std,
									    "do_normalize": self.do_normalize,
									    "do_resize": self.do_resize,
									    "size": self.size,
									}



@require_torch
@require_vision
class 	__a   (       UpperCAmelCase					,   unittest.TestCase    ):
		_a			:						Tuple    			=			ViTImageProcessor if is_vision_available() else None
		def 			UpperCAmelCase__       (    self		)				-> Tuple:




									"""simple docstring"""





									_UpperCAmelCase					=    ViTImageProcessingTester(self		)
		@property
		def 			UpperCAmelCase__       (    self		)				-> List[Any]:




									"""simple docstring"""





									return self.image_processor_tester.prepare_image_processor_dict()
		def 			UpperCAmelCase__       (    self		)				-> Optional[int]:




									"""simple docstring"""





									_UpperCAmelCase					=    self.image_processing_class(**self.image_processor_dict		)
									self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,					'image_mean'		)		)
									self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,					'image_std'		)		)
									self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,					'do_normalize'		)		)
									self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,					'do_resize'		)		)
									self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,					'size'		)		)
		def 			UpperCAmelCase__       (    self		)				-> List[str]:




									"""simple docstring"""





									_UpperCAmelCase					=    self.image_processing_class.from_dict(self.image_processor_dict		)
									self.assertEqual(image_processor.size    ,					{'height': 18, 'width': 18}		)

									_UpperCAmelCase					=    self.image_processing_class.from_dict(self.image_processor_dict    ,					size=42		)
									self.assertEqual(image_processor.size    ,					{'height': 42, 'width': 42}		)
		def 			UpperCAmelCase__       (    self		)				-> Optional[Any]:




									"""simple docstring"""





									pass
		def 			UpperCAmelCase__       (    self		)				-> Optional[Any]:




									"""simple docstring"""





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

									# Test not batched input
									_UpperCAmelCase					=    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.size['height'],
									        self.image_processor_tester.size['width'],
									    )    ,					)

									# Test batched
									_UpperCAmelCase					=    image_processing(_SCREAMING_SNAKE_CASE    ,					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.size['height'],
									        self.image_processor_tester.size['width'],
									    )    ,					)
		def 			UpperCAmelCase__       (    self		)				-> Tuple:




									"""simple docstring"""





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

									# Test not batched input
									_UpperCAmelCase					=    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.size['height'],
									        self.image_processor_tester.size['width'],
									    )    ,					)

									# Test batched
									_UpperCAmelCase					=    image_processing(_SCREAMING_SNAKE_CASE    ,					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.size['height'],
									        self.image_processor_tester.size['width'],
									    )    ,					)






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




									"""simple docstring"""





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

									# Test not batched input
									_UpperCAmelCase					=    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.size['height'],
									        self.image_processor_tester.size['width'],
									    )    ,					)

									# Test batched
									_UpperCAmelCase					=    image_processing(_SCREAMING_SNAKE_CASE    ,					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.size['height'],
									        self.image_processor_tester.size['width'],
									    )    ,					)




import os
from shutil import copyfile
from typing import Optional, Tuple

from ...file_utils import is_sentencepiece_available
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging


if is_sentencepiece_available():
		from .tokenization_deberta_va import DebertaVaTokenizer
else:
		lowerCAmelCase__						:int         =							None

lowerCAmelCase__						:List[str]         =							logging.get_logger(__name__)

lowerCAmelCase__						:List[str]         =							{'''vocab_file''': '''spm.model''', '''tokenizer_file''': '''tokenizer.json'''}

lowerCAmelCase__						:List[str]         =							{
    '''vocab_file''': {
        '''microsoft/deberta-v2-xlarge''': '''https://huggingface.co/microsoft/deberta-v2-xlarge/resolve/main/spm.model''',
        '''microsoft/deberta-v2-xxlarge''': '''https://huggingface.co/microsoft/deberta-v2-xxlarge/resolve/main/spm.model''',
        '''microsoft/deberta-v2-xlarge-mnli''': (
            '''https://huggingface.co/microsoft/deberta-v2-xlarge-mnli/resolve/main/spm.model'''
        ),
        '''microsoft/deberta-v2-xxlarge-mnli''': (
            '''https://huggingface.co/microsoft/deberta-v2-xxlarge-mnli/resolve/main/spm.model'''
        ),
    }
}

lowerCAmelCase__						:List[str]         =							{
    '''microsoft/deberta-v2-xlarge''': 5_1_2,
    '''microsoft/deberta-v2-xxlarge''': 5_1_2,
    '''microsoft/deberta-v2-xlarge-mnli''': 5_1_2,
    '''microsoft/deberta-v2-xxlarge-mnli''': 5_1_2,
}

lowerCAmelCase__						:Any         =							{
    '''microsoft/deberta-v2-xlarge''': {'''do_lower_case''': False},
    '''microsoft/deberta-v2-xxlarge''': {'''do_lower_case''': False},
    '''microsoft/deberta-v2-xlarge-mnli''': {'''do_lower_case''': False},
    '''microsoft/deberta-v2-xxlarge-mnli''': {'''do_lower_case''': False},
}

class 	__a   (       UpperCAmelCase    ):
		_a			:						Tuple    			=			VOCAB_FILES_NAMES
		_a			:						int    			=			PRETRAINED_VOCAB_FILES_MAP
		_a			:						Optional[Any]    			=			PRETRAINED_INIT_CONFIGURATION
		_a			:						str    			=			PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
		_a			:						Optional[int]    			=			DebertaVaTokenizer
		def __init__(    self    ,					_SCREAMING_SNAKE_CASE=None    ,					_SCREAMING_SNAKE_CASE=None    ,					_SCREAMING_SNAKE_CASE=False    ,					_SCREAMING_SNAKE_CASE=False    ,					_SCREAMING_SNAKE_CASE="[CLS]"    ,					_SCREAMING_SNAKE_CASE="[SEP]"    ,					_SCREAMING_SNAKE_CASE="[UNK]"    ,					_SCREAMING_SNAKE_CASE="[SEP]"    ,					_SCREAMING_SNAKE_CASE="[PAD]"    ,					_SCREAMING_SNAKE_CASE="[CLS]"    ,					_SCREAMING_SNAKE_CASE="[MASK]"    ,					**_SCREAMING_SNAKE_CASE    ,					)				-> None:




									"""simple docstring"""





									super().__init__(
									    _SCREAMING_SNAKE_CASE    ,					tokenizer_file=_SCREAMING_SNAKE_CASE    ,					do_lower_case=_SCREAMING_SNAKE_CASE    ,					bos_token=_SCREAMING_SNAKE_CASE    ,					eos_token=_SCREAMING_SNAKE_CASE    ,					unk_token=_SCREAMING_SNAKE_CASE    ,					sep_token=_SCREAMING_SNAKE_CASE    ,					pad_token=_SCREAMING_SNAKE_CASE    ,					cls_token=_SCREAMING_SNAKE_CASE    ,					mask_token=_SCREAMING_SNAKE_CASE    ,					split_by_punct=_SCREAMING_SNAKE_CASE    ,					**_SCREAMING_SNAKE_CASE    ,					)

									_UpperCAmelCase					=    do_lower_case
									_UpperCAmelCase					=    split_by_punct
									_UpperCAmelCase					=    vocab_file
									_UpperCAmelCase					=    False if not self.vocab_file else True
		def 			UpperCAmelCase__       (    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE=None		)				-> str:




									"""simple docstring"""





									if token_ids_a is None:
																return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
									_UpperCAmelCase					=    [self.cls_token_id]
									_UpperCAmelCase					=    [self.sep_token_id]
									return cls + token_ids_a + sep + token_ids_a + sep
		def 			UpperCAmelCase__       (    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE=None    ,					_SCREAMING_SNAKE_CASE=False		)				-> Any:




									"""simple docstring"""





									if already_has_special_tokens:
																return super().get_special_tokens_mask(
																    token_ids_a=_SCREAMING_SNAKE_CASE    ,					token_ids_a=_SCREAMING_SNAKE_CASE    ,					already_has_special_tokens=_SCREAMING_SNAKE_CASE		)

									if token_ids_a is not None:
																return [1] + ([0] * len(_SCREAMING_SNAKE_CASE		)) + [1] + ([0] * len(_SCREAMING_SNAKE_CASE		)) + [1]
									return [1] + ([0] * len(_SCREAMING_SNAKE_CASE		)) + [1]
		def 			UpperCAmelCase__       (    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE=None		)				-> Union[str, Any]:




									"""simple docstring"""





									_UpperCAmelCase					=    [self.sep_token_id]
									_UpperCAmelCase					=    [self.cls_token_id]
									if token_ids_a is None:
																return len(cls + token_ids_a + sep		) * [0]
									return len(cls + token_ids_a + sep		) * [0] + len(token_ids_a + sep		) * [1]






		def 			UpperCAmelCase__       (    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE = None		)				-> Tuple[str]:




									"""simple docstring"""





									if not self.can_save_slow_tokenizer:
																raise ValueError(
																    'Your fast tokenizer does not have the necessary information to save the vocabulary for a slow '
																    'tokenizer.'		)

									if not os.path.isdir(_SCREAMING_SNAKE_CASE		):
																logger.error(f'''Vocabulary path ({save_directory}) should be a directory'''		)
																return
									_UpperCAmelCase					=    os.path.join(
									    _SCREAMING_SNAKE_CASE    ,					(filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']		)

									if os.path.abspath(self.vocab_file		) != os.path.abspath(_SCREAMING_SNAKE_CASE		):
																copyfile(self.vocab_file    ,					_SCREAMING_SNAKE_CASE		)

									return (out_vocab_file,)
