


'''simple docstring'''



from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    convert_to_rgb,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


_lowercase      :      Tuple            =					logging.get_logger(__name__)


if is_vision_available():
	import PIL






class 	UpperCamelCase__(       lowerCAmelCase	):
				__magic_name__    :				Tuple  		=	["pixel_values"]




				def __init__(		self      :			int				,   lowerCAmelCase      :			bool = True				,   lowerCAmelCase      :			Dict[str, int] = None				,   lowerCAmelCase      :			PILImageResampling = PILImageResampling.BICUBIC				,   lowerCAmelCase      :			bool = True				,   lowerCAmelCase      :			Dict[str, int] = None				,   lowerCAmelCase      :			bool = True				,   lowerCAmelCase      :			Union[int, float] = 1 / 255				,   lowerCAmelCase      :			bool = True				,   lowerCAmelCase      :			Optional[Union[float, List[float]]] = None				,   lowerCAmelCase      :			Optional[Union[float, List[float]]] = None				,   lowerCAmelCase      :			bool = True				,   **lowerCAmelCase      :			Union[str, Any]				,   )->					None:

										"""simple docstring"""




										super().__init__(**lowerCAmelCase				)
										UpperCAmelCase					    =     size if size is not None else {'''shortest_edge''': 224}
										UpperCAmelCase					    =     get_size_dict(lowerCAmelCase				,   default_to_square=lowerCAmelCase				)
										UpperCAmelCase					    =     crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
										UpperCAmelCase					    =     get_size_dict(lowerCAmelCase				,   default_to_square=lowerCAmelCase				,   param_name='''crop_size'''				)

										UpperCAmelCase					    =     do_resize
										UpperCAmelCase					    =     size
										UpperCAmelCase					    =     resample
										UpperCAmelCase					    =     do_center_crop
										UpperCAmelCase					    =     crop_size
										UpperCAmelCase					    =     do_rescale
										UpperCAmelCase					    =     rescale_factor
										UpperCAmelCase					    =     do_normalize
										UpperCAmelCase					    =     image_mean if image_mean is not None else OPENAI_CLIP_MEAN
										UpperCAmelCase					    =     image_std if image_std is not None else OPENAI_CLIP_STD
										UpperCAmelCase					    =     do_convert_rgb




				def 					a__(		self      :			Dict				,   lowerCAmelCase      :			np.ndarray				,   lowerCAmelCase      :			Dict[str, int]				,   lowerCAmelCase      :			PILImageResampling = PILImageResampling.BICUBIC				,   lowerCAmelCase      :			Optional[Union[str, ChannelDimension]] = None				,   **lowerCAmelCase      :			int				,   )->					np.ndarray:

										"""simple docstring"""




										UpperCAmelCase					    =     get_size_dict(lowerCAmelCase				,   default_to_square=lowerCAmelCase				)
										if "shortest_edge" not in size:
																raise ValueError(F"""The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}"""				)
										UpperCAmelCase					    =     get_resize_output_image_size(lowerCAmelCase				,   size=size['''shortest_edge''']				,   default_to_square=lowerCAmelCase				)
										return resize(lowerCAmelCase				,   size=lowerCAmelCase				,   resample=lowerCAmelCase				,   data_format=lowerCAmelCase				,   **lowerCAmelCase				)




				def 					a__(		self      :			str				,   lowerCAmelCase      :			np.ndarray				,   lowerCAmelCase      :			Dict[str, int]				,   lowerCAmelCase      :			Optional[Union[str, ChannelDimension]] = None				,   **lowerCAmelCase      :			List[str]				,   )->					np.ndarray:

										"""simple docstring"""




										UpperCAmelCase					    =     get_size_dict(lowerCAmelCase				)
										if "height" not in size or "width" not in size:
																raise ValueError(F"""The `size` parameter must contain the keys (height, width). Got {size.keys()}"""				)
										return center_crop(lowerCAmelCase				,   size=(size['''height'''], size['''width'''])				,   data_format=lowerCAmelCase				,   **lowerCAmelCase				)




				def 					a__(		self      :			List[str]				,   lowerCAmelCase      :			np.ndarray				,   lowerCAmelCase      :			Union[int, float]				,   lowerCAmelCase      :			Optional[Union[str, ChannelDimension]] = None				,   **lowerCAmelCase      :			Tuple				,   )->					Dict:

										"""simple docstring"""




										return rescale(lowerCAmelCase				,   scale=lowerCAmelCase				,   data_format=lowerCAmelCase				,   **lowerCAmelCase				)




				def 					a__(		self      :			Union[str, Any]				,   lowerCAmelCase      :			np.ndarray				,   lowerCAmelCase      :			Union[float, List[float]]				,   lowerCAmelCase      :			Union[float, List[float]]				,   lowerCAmelCase      :			Optional[Union[str, ChannelDimension]] = None				,   **lowerCAmelCase      :			Optional[Any]				,   )->					np.ndarray:

										"""simple docstring"""




										return normalize(lowerCAmelCase				,   mean=lowerCAmelCase				,   std=lowerCAmelCase				,   data_format=lowerCAmelCase				,   **lowerCAmelCase				)





				def 					a__(		self      :			Union[str, Any]				,   lowerCAmelCase      :			ImageInput				,   lowerCAmelCase      :			bool = None				,   lowerCAmelCase      :			Dict[str, int] = None				,   lowerCAmelCase      :			PILImageResampling = None				,   lowerCAmelCase      :			bool = None				,   lowerCAmelCase      :			int = None				,   lowerCAmelCase      :			bool = None				,   lowerCAmelCase      :			float = None				,   lowerCAmelCase      :			bool = None				,   lowerCAmelCase      :			Optional[Union[float, List[float]]] = None				,   lowerCAmelCase      :			Optional[Union[float, List[float]]] = None				,   lowerCAmelCase      :			bool = None				,   lowerCAmelCase      :			Optional[Union[str, TensorType]] = None				,   lowerCAmelCase      :			Optional[ChannelDimension] = ChannelDimension.FIRST				,   **lowerCAmelCase      :			List[str]				,   )->					PIL.Image.Image:

										"""simple docstring"""




										UpperCAmelCase					    =     do_resize if do_resize is not None else self.do_resize
										UpperCAmelCase					    =     size if size is not None else self.size
										UpperCAmelCase					    =     get_size_dict(lowerCAmelCase				,   param_name='''size'''				,   default_to_square=lowerCAmelCase				)
										UpperCAmelCase					    =     resample if resample is not None else self.resample
										UpperCAmelCase					    =     do_center_crop if do_center_crop is not None else self.do_center_crop
										UpperCAmelCase					    =     crop_size if crop_size is not None else self.crop_size
										UpperCAmelCase					    =     get_size_dict(lowerCAmelCase				,   param_name='''crop_size'''				,   default_to_square=lowerCAmelCase				)
										UpperCAmelCase					    =     do_rescale if do_rescale is not None else self.do_rescale
										UpperCAmelCase					    =     rescale_factor if rescale_factor is not None else self.rescale_factor
										UpperCAmelCase					    =     do_normalize if do_normalize is not None else self.do_normalize
										UpperCAmelCase					    =     image_mean if image_mean is not None else self.image_mean
										UpperCAmelCase					    =     image_std if image_std is not None else self.image_std
										UpperCAmelCase					    =     do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

										UpperCAmelCase					    =     make_list_of_images(lowerCAmelCase				)

										if not valid_images(lowerCAmelCase				):
																raise ValueError(
																    '''Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '''
																    '''torch.Tensor, tf.Tensor or jax.ndarray.'''				)

										if do_resize and size is None:
																raise ValueError('''Size must be specified if do_resize is True.'''				)

										if do_center_crop and crop_size is None:
																raise ValueError('''Crop size must be specified if do_center_crop is True.'''				)

										if do_rescale and rescale_factor is None:
																raise ValueError('''Rescale factor must be specified if do_rescale is True.'''				)

										if do_normalize and (image_mean is None or image_std is None):
																raise ValueError('''Image mean and std must be specified if do_normalize is True.'''				)

										# PIL RGBA images are converted to RGB
										if do_convert_rgb:
																UpperCAmelCase					    =     [convert_to_rgb(lowerCAmelCase				) for image in images]

										# All transformations expect numpy arrays.
										UpperCAmelCase					    =     [to_numpy_array(lowerCAmelCase				) for image in images]

										if do_resize:
																UpperCAmelCase					    =     [self.resize(image=lowerCAmelCase				,   size=lowerCAmelCase				,   resample=lowerCAmelCase				) for image in images]

										if do_center_crop:
																UpperCAmelCase					    =     [self.center_crop(image=lowerCAmelCase				,   size=lowerCAmelCase				) for image in images]

										if do_rescale:
																UpperCAmelCase					    =     [self.rescale(image=lowerCAmelCase				,   scale=lowerCAmelCase				) for image in images]

										if do_normalize:
																UpperCAmelCase					    =     [self.normalize(image=lowerCAmelCase				,   mean=lowerCAmelCase				,   std=lowerCAmelCase				) for image in images]

										UpperCAmelCase					    =     [to_channel_dimension_format(lowerCAmelCase				,   lowerCAmelCase				) for image in images]

										UpperCAmelCase					    =     {'''pixel_values''': images}
										return BatchFeature(data=lowerCAmelCase				,   tensor_type=lowerCAmelCase				)









'''simple docstring'''



from ...configuration_utils import PretrainedConfig
from ...utils import logging


_lowercase      :      int            =					logging.get_logger(__name__)

_lowercase      :      Optional[Any]            =					{"""openai-gpt""": """https://huggingface.co/openai-gpt/resolve/main/config.json"""}






class 	UpperCamelCase__(       lowerCAmelCase	):
				__magic_name__    :				Union[str, Any]  		=	"openai-gpt"
				__magic_name__    :				Optional[int]  		=	{
				    "max_position_embeddings": "n_positions",
				    "hidden_size": "n_embd",
				    "num_attention_heads": "n_head",
				    "num_hidden_layers": "n_layer",
				}




				def __init__(		self      :			Optional[int]				,   lowerCAmelCase      :			Optional[Any]=40478				,   lowerCAmelCase      :			str=512				,   lowerCAmelCase      :			List[Any]=768				,   lowerCAmelCase      :			Tuple=12				,   lowerCAmelCase      :			int=12				,   lowerCAmelCase      :			List[str]="gelu"				,   lowerCAmelCase      :			List[str]=0.1				,   lowerCAmelCase      :			List[Any]=0.1				,   lowerCAmelCase      :			Dict=0.1				,   lowerCAmelCase      :			Tuple=1E-5				,   lowerCAmelCase      :			Tuple=0.02				,   lowerCAmelCase      :			Optional[int]="cls_index"				,   lowerCAmelCase      :			Dict=True				,   lowerCAmelCase      :			Optional[int]=None				,   lowerCAmelCase      :			Dict=True				,   lowerCAmelCase      :			int=0.1				,   **lowerCAmelCase      :			Optional[int]				,   )->					str:

										"""simple docstring"""




										UpperCAmelCase					    =     vocab_size
										UpperCAmelCase					    =     n_positions
										UpperCAmelCase					    =     n_embd
										UpperCAmelCase					    =     n_layer
										UpperCAmelCase					    =     n_head
										UpperCAmelCase					    =     afn
										UpperCAmelCase					    =     resid_pdrop
										UpperCAmelCase					    =     embd_pdrop
										UpperCAmelCase					    =     attn_pdrop
										UpperCAmelCase					    =     layer_norm_epsilon
										UpperCAmelCase					    =     initializer_range
										UpperCAmelCase					    =     summary_type
										UpperCAmelCase					    =     summary_use_proj
										UpperCAmelCase					    =     summary_activation
										UpperCAmelCase					    =     summary_first_dropout
										UpperCAmelCase					    =     summary_proj_to_labels
										super().__init__(**lowerCAmelCase				)





