'''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       ,	_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=None       ,	_SCREAMING_SNAKE_CASE=True       ,	_SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5]       ,	_SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5]       ,	)						->	Optional[int]:
           A_      =  size if size is not None else {'''height''': 20, '''width''': 20}
           A_      =  crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

           A_      =  parent
           A_      =  batch_size
           A_      =  num_channels
           A_      =  image_size
           A_      =  min_resolution
           A_      =  max_resolution
           A_      =  do_resize
           A_      =  size
           A_      =  do_center_crop
           A_      =  crop_size
           A_      =  do_normalize
           A_      =  image_mean
           A_      =  image_std

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



       __lowercase   :   Optional[int]  					=							DeiTImageProcessor if is_vision_available() else None
       __lowercase   :   Any  					=							True

       def    __A			( self					)						->	List[str]:
           A_      =  DeiTImageProcessingTester(self					)

       @property
       def    __A			( self					)						->	List[Any]:
           return self.image_processor_tester.prepare_image_processor_dict()

       def    __A			( self					)						->	List[Any]:
           A_      =  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					)						->	Optional[Any]:
           A_      =  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_      =  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					)						->	int:
           pass

       def    __A			( self					)						->	Optional[int]:
           # Initialize image_processing
           A_      =  self.image_processing_class(**self.image_processor_dict					)
           # create random PIL images
           A_      =  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_      =  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_      =  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					)						->	Tuple:
           # Initialize image_processing
           A_      =  self.image_processing_class(**self.image_processor_dict					)
           # create random numpy tensors
           A_      =  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_      =  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_      =  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					)						->	List[str]:
           # Initialize image_processing
           A_      =  self.image_processing_class(**self.image_processor_dict					)
           # create random PyTorch tensors
           A_      =  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_      =  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_      =  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					)






