



from typing import Optional, Tuple

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


A__						:						List[Any]          =      logging.get_logger(__name__)

A__						:						int          =      {'''vocab_file''': '''vocab.json''', '''merges_file''': '''merges.txt''', '''tokenizer_file''': '''tokenizer.json'''}

A__						:						Optional[Any]          =      {
    '''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'''},
}

A__						:						str          =      {
    '''openai-gpt''': 512,
}



class        __snake_case		(  UpperCamelCase_		):
							_a       =				VOCAB_FILES_NAMES
							_a       =				PRETRAINED_VOCAB_FILES_MAP
							_a       =				PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							_a       =				['''input_ids''', '''attention_mask''']
							_a       =				OpenAIGPTTokenizer




							def __init__( self  : Optional[Any]       ,       A_  : str=None       ,       A_  : Union[str, Any]=None       ,       A_  : Tuple=None       ,       A_  : int="<unk>"       ,       **A_  : int):
									super().__init__(A_       ,       A_       ,       tokenizer_file=A_       ,       unk_token=A_       ,       **A_)




							@property
							def      UpperCAmelCase__    ( self  : Tuple):
									return True







							def      UpperCAmelCase__    ( self  : Any       ,       A_  : str       ,       A_  : Optional[str] = None):
									lowerCAmelCase_    :  Optional[Any]             =				self._tokenizer.model.save(A_       ,       name=A_)
									return tuple(A_)










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        __snake_case		(  unittest.TestCase		):




							def __init__( self  : Union[str, Any]       ,       A_  : Optional[Any]       ,       A_  : Optional[Any]=7       ,       A_  : str=3       ,       A_  : Optional[Any]=1_8       ,       A_  : Union[str, Any]=3_0       ,       A_  : str=4_0_0       ,       A_  : List[str]=True       ,       A_  : str=None       ,       A_  : str=True       ,       A_  : List[Any]=None       ,       A_  : List[Any]=True       ,       A_  : Optional[Any]=[0.5, 0.5, 0.5]       ,       A_  : Optional[int]=[0.5, 0.5, 0.5]       ,       ):
									lowerCAmelCase_    :  List[str]             =				size if size is not None else {'''height''': 2_0, '''width''': 2_0}
									lowerCAmelCase_    :  List[Any]             =				crop_size if crop_size is not None else {'''height''': 1_8, '''width''': 1_8}

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







							def      UpperCAmelCase__    ( self  : int):
									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        __snake_case		(  UpperCamelCase_		,unittest.TestCase		):
							_a       =				DeiTImageProcessor if is_vision_available() else None
							_a       =				True




							def      UpperCAmelCase__    ( self  : Tuple):
									lowerCAmelCase_    :  int             =				DeiTImageProcessingTester(self)




							@property
							def      UpperCAmelCase__    ( self  : Optional[Any]):
									return self.image_processor_tester.prepare_image_processor_dict()




							def      UpperCAmelCase__    ( self  : str):
									lowerCAmelCase_    :  List[Any]             =				self.image_processing_class(**self.image_processor_dict)
									self.assertTrue(hasattr(A_       ,       '''do_resize'''))
									self.assertTrue(hasattr(A_       ,       '''size'''))
									self.assertTrue(hasattr(A_       ,       '''do_center_crop'''))
									self.assertTrue(hasattr(A_       ,       '''center_crop'''))
									self.assertTrue(hasattr(A_       ,       '''do_normalize'''))
									self.assertTrue(hasattr(A_       ,       '''image_mean'''))
									self.assertTrue(hasattr(A_       ,       '''image_std'''))




							def      UpperCAmelCase__    ( self  : Union[str, Any]):
									lowerCAmelCase_    :  Tuple             =				self.image_processing_class.from_dict(self.image_processor_dict)
									self.assertEqual(image_processor.size       ,       {'''height''': 2_0, '''width''': 2_0})
									self.assertEqual(image_processor.crop_size       ,       {'''height''': 1_8, '''width''': 1_8})

									lowerCAmelCase_    :  Any             =				self.image_processing_class.from_dict(self.image_processor_dict       ,       size=4_2       ,       crop_size=8_4)
									self.assertEqual(image_processor.size       ,       {'''height''': 4_2, '''width''': 4_2})
									self.assertEqual(image_processor.crop_size       ,       {'''height''': 8_4, '''width''': 8_4})




							def      UpperCAmelCase__    ( self  : Union[str, Any]):
									pass




							def      UpperCAmelCase__    ( self  : Any):
									# Initialize image_processing
									lowerCAmelCase_    :  List[str]             =				self.image_processing_class(**self.image_processor_dict)
									# create random PIL images
									lowerCAmelCase_    :  Any             =				prepare_image_inputs(self.image_processor_tester       ,       equal_resolution=A_)
									for image in image_inputs:
											self.assertIsInstance(A_       ,       Image.Image)

									# Test not batched input
									lowerCAmelCase_    :  Union[str, 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
									lowerCAmelCase_    :  Dict             =				image_processing(A_       ,       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      UpperCAmelCase__    ( self  : List[str]):
									# Initialize image_processing
									lowerCAmelCase_    :  Union[str, Any]             =				self.image_processing_class(**self.image_processor_dict)
									# create random numpy tensors
									lowerCAmelCase_    :  Union[str, Any]             =				prepare_image_inputs(self.image_processor_tester       ,       equal_resolution=A_       ,       numpify=A_)
									for image in image_inputs:
											self.assertIsInstance(A_       ,       np.ndarray)

									# Test not batched input
									lowerCAmelCase_    :  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
									lowerCAmelCase_    :  str             =				image_processing(A_       ,       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      UpperCAmelCase__    ( self  : Any):
									# Initialize image_processing
									lowerCAmelCase_    :  str             =				self.image_processing_class(**self.image_processor_dict)
									# create random PyTorch tensors
									lowerCAmelCase_    :  Union[str, Any]             =				prepare_image_inputs(self.image_processor_tester       ,       equal_resolution=A_       ,       torchify=A_)
									for image in image_inputs:
											self.assertIsInstance(A_       ,       torch.Tensor)

									# Test not batched input
									lowerCAmelCase_    :  Dict             =				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
									lowerCAmelCase_    :  Tuple             =				image_processing(A_       ,       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'''],
									    )       ,       )





