




'''simple docstring'''




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 DeiTImageProcessor






class      UpperCamelCase_  (unittest.TestCase  ):







						"""simple docstring"""


						def __init__(  self   :							List[Any]				,			_lowerCamelCase   :							Optional[Any]				,			_lowerCamelCase   :							Dict=7				,			_lowerCamelCase   :							Dict=3				,			_lowerCamelCase   :							Dict=18				,			_lowerCamelCase   :							str=30				,			_lowerCamelCase   :							int=400				,			_lowerCamelCase   :							Any=True				,			_lowerCamelCase   :							List[Any]=None				,			_lowerCamelCase   :							str=True				,			_lowerCamelCase   :							int=None				,			_lowerCamelCase   :							int=True				,			_lowerCamelCase   :							List[str]=[0.5, 0.5, 0.5]				,			_lowerCamelCase   :							Dict=[0.5, 0.5, 0.5]				,			):





											"""simple docstring"""







											A_			:  int			=				size if size is not None else {'''height''': 20, '''width''': 20}
											A_			:  List[str]			=				crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

											A_			:  Optional[Any]			=				parent
											A_			:  Tuple			=				batch_size
											A_			:  int			=				num_channels
											A_			:  Union[str, Any]			=				image_size
											A_			:  Any			=				min_resolution
											A_			:  Optional[Any]			=				max_resolution
											A_			:  Optional[int]			=				do_resize
											A_			:  List[Any]			=				size
											A_			:  int			=				do_center_crop
											A_			:  List[str]			=				crop_size
											A_			:  int			=				do_normalize
											A_			:  Union[str, Any]			=				image_mean
											A_			:  Dict			=				image_std







						def    _a     (  self   :							List[str]     ):





											"""simple docstring"""







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






@require_torch
@require_vision
class      UpperCamelCase_  (_UpperCamelCase,   unittest.TestCase  ):







						"""simple docstring"""


						_lowerCAmelCase         =       DeiTImageProcessor if is_vision_available() else None
						_lowerCAmelCase         =       True







						def    _a     (  self   :							int     ):





											"""simple docstring"""







											A_			:  Dict			=				DeiTImageProcessingTester(self     )







						@property
						def    _a     (  self   :							Optional[int]     ):





											"""simple docstring"""







											return self.image_processor_tester.prepare_image_processor_dict()







						def    _a     (  self   :							List[Any]     ):





											"""simple docstring"""







											A_			:  Optional[Any]			=				self.image_processing_class(**self.image_processor_dict     )
											self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE				,			'''do_resize'''     )     )
											self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE				,			'''size'''     )     )
											self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE				,			'''do_center_crop'''     )     )
											self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE				,			'''center_crop'''     )     )
											self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE				,			'''do_normalize'''     )     )
											self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE				,			'''image_mean'''     )     )
											self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE				,			'''image_std'''     )     )







						def    _a     (  self   :							List[Any]     ):





											"""simple docstring"""







											A_			:  str			=				self.image_processing_class.from_dict(self.image_processor_dict     )
											self.assertEqual(image_processor.size				,			{'''height''': 20, '''width''': 20}     )
											self.assertEqual(image_processor.crop_size				,			{'''height''': 18, '''width''': 18}     )

											A_			:  Dict			=				self.image_processing_class.from_dict(self.image_processor_dict				,			size=42				,			crop_size=84     )
											self.assertEqual(image_processor.size				,			{'''height''': 42, '''width''': 42}     )
											self.assertEqual(image_processor.crop_size				,			{'''height''': 84, '''width''': 84}     )







						def    _a     (  self   :							Optional[int]     ):





											"""simple docstring"""







											pass







						def    _a     (  self   :							Any     ):





											"""simple docstring"""







											A_			:  Optional[int]			=				self.image_processing_class(**self.image_processor_dict     )
											# create random PIL images
											A_			:  Dict			=				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
											A_			:  Optional[Any]			=				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
											A_			:  Optional[int]			=				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.crop_size['''height'''],
											        self.image_processor_tester.crop_size['''width'''],
											    )				,			)







						def    _a     (  self   :							str     ):





											"""simple docstring"""







											A_			:  List[str]			=				self.image_processing_class(**self.image_processor_dict     )
											# create random numpy tensors
											A_			:  str			=				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
											A_			:  Tuple			=				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
											A_			:  Any			=				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.crop_size['''height'''],
											        self.image_processor_tester.crop_size['''width'''],
											    )				,			)







						def    _a     (  self   :							Dict     ):





											"""simple docstring"""







											A_			:  Dict			=				self.image_processing_class(**self.image_processor_dict     )
											# create random PyTorch tensors
											A_			:  Any			=				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
											A_			:  str			=				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
											A_			:  Dict			=				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.crop_size['''height'''],
											        self.image_processor_tester.crop_size['''width'''],
											    )				,			)




'''simple docstring'''




from typing import Optional, Tuple

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_openai import OpenAIGPTTokenizer


__snake_case  : Union[str, Any]		       =    logging.get_logger(__name__)

__snake_case  : Union[str, Any]		       =    {'vocab_file': 'vocab.json', 'merges_file': 'merges.txt', 'tokenizer_file': 'tokenizer.json'}

__snake_case  : List[str]		       =    {
    'vocab_file': {'openai-gpt': 'https://huggingface.co/openai-gpt/resolve/main/vocab.json'},
    'merges_file': {'openai-gpt': 'https://huggingface.co/openai-gpt/resolve/main/merges.txt'},
    'tokenizer_file': {'openai-gpt': 'https://huggingface.co/openai-gpt/resolve/main/tokenizer.json'},
}

__snake_case  : Optional[int]		       =    {
    'openai-gpt': 512,
}




class       __UpperCAmelCase							(							_UpperCamelCase	):





       '''simple docstring'''



       __lowercase   :   int  					=							VOCAB_FILES_NAMES
       __lowercase   :   int  					=							PRETRAINED_VOCAB_FILES_MAP
       __lowercase   :   str  					=							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
       __lowercase   :   Optional[Any]  					=							['input_ids', 'attention_mask']
       __lowercase   :   List[Any]  					=							OpenAIGPTTokenizer

       def __init__( self       ,	_SCREAMING_SNAKE_CASE=None       ,	_SCREAMING_SNAKE_CASE=None       ,	_SCREAMING_SNAKE_CASE=None       ,	_SCREAMING_SNAKE_CASE="<unk>"       ,	**_SCREAMING_SNAKE_CASE					)						->	Optional[Any]:
           super().__init__(_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	tokenizer_file=_SCREAMING_SNAKE_CASE       ,	unk_token=_SCREAMING_SNAKE_CASE       ,	**_SCREAMING_SNAKE_CASE					)

       @property
       def    __A			( self					)						->	Optional[Any]:
           return True

       def    __A			( self       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE = None					)						->	Tuple[str]:
           A_      =  self._tokenizer.model.save(_SCREAMING_SNAKE_CASE       ,	name=_SCREAMING_SNAKE_CASE					)
           return tuple(_SCREAMING_SNAKE_CASE					)






