





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


lowerCAmelCase_    =				logging.get_logger(__name__)


if is_vision_available():
	import PIL



class 					__lowerCAmelCase       (			_a     ):
			lowerCamelCase_     :     List[str]       			=      ['''pixel_values''']






			def __init__(self					,							__magic_name__ = True					,							__magic_name__ = None					,							__magic_name__ = PILImageResampling.BICUBIC					,							__magic_name__ = True					,							__magic_name__ = None					,							__magic_name__ = True					,							__magic_name__ = 1 / 255					,							__magic_name__ = True					,							__magic_name__ = None					,							__magic_name__ = None					,							__magic_name__ = True					,							**__magic_name__					,							)     ->   None:


							'''simple docstring'''



							super().__init__(**__magic_name__    )
							snake_case_						:    List[str]				=  size if size is not None else {'''shortest_edge''': 224}
							snake_case_						:    int				=  get_size_dict(__magic_name__					,							default_to_square=__magic_name__    )
							snake_case_						:    Dict				=  crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
							snake_case_						:    Union[str, Any]				=  get_size_dict(__magic_name__					,							default_to_square=__magic_name__					,							param_name='''crop_size'''    )

							snake_case_						:    List[str]				=  do_resize
							snake_case_						:    int				=  size
							snake_case_						:    str				=  resample
							snake_case_						:    List[Any]				=  do_center_crop
							snake_case_						:    Union[str, Any]				=  crop_size
							snake_case_						:    Tuple				=  do_rescale
							snake_case_						:    List[Any]				=  rescale_factor
							snake_case_						:    Union[str, Any]				=  do_normalize
							snake_case_						:    Optional[int]				=  image_mean if image_mean is not None else OPENAI_CLIP_MEAN
							snake_case_						:    Dict				=  image_std if image_std is not None else OPENAI_CLIP_STD
							snake_case_						:    Tuple				=  do_convert_rgb






			def 			lowerCamelCase  (self					,							__magic_name__					,							__magic_name__					,							__magic_name__ = PILImageResampling.BICUBIC					,							__magic_name__ = None					,							**__magic_name__					,							)     ->   np.ndarray:


							'''simple docstring'''



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






			def 			lowerCamelCase  (self					,							__magic_name__					,							__magic_name__					,							__magic_name__ = None					,							**__magic_name__					,							)     ->   np.ndarray:


							'''simple docstring'''



							snake_case_						:    int				=  get_size_dict(__magic_name__    )
							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(__magic_name__					,							size=(size['''height'''], size['''width'''])					,							data_format=__magic_name__					,							**__magic_name__    )






			def 			lowerCamelCase  (self					,							__magic_name__					,							__magic_name__					,							__magic_name__ = None					,							**__magic_name__					,							)     ->   Dict:


							'''simple docstring'''



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






			def 			lowerCamelCase  (self					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__ = None					,							**__magic_name__					,							)     ->   np.ndarray:


							'''simple docstring'''



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






			def 			lowerCamelCase  (self					,							__magic_name__					,							__magic_name__ = None					,							__magic_name__ = None					,							__magic_name__ = None					,							__magic_name__ = None					,							__magic_name__ = None					,							__magic_name__ = None					,							__magic_name__ = None					,							__magic_name__ = None					,							__magic_name__ = None					,							__magic_name__ = None					,							__magic_name__ = None					,							__magic_name__ = None					,							__magic_name__ = ChannelDimension.FIRST					,							**__magic_name__					,							)     ->   PIL.Image.Image:


							'''simple docstring'''



							snake_case_						:    Any				=  do_resize if do_resize is not None else self.do_resize
							snake_case_						:    Optional[Any]				=  size if size is not None else self.size
							snake_case_						:    Tuple				=  get_size_dict(__magic_name__					,							param_name='''size'''					,							default_to_square=__magic_name__    )
							snake_case_						:    int				=  resample if resample is not None else self.resample
							snake_case_						:    Union[str, Any]				=  do_center_crop if do_center_crop is not None else self.do_center_crop
							snake_case_						:    str				=  crop_size if crop_size is not None else self.crop_size
							snake_case_						:    Optional[int]				=  get_size_dict(__magic_name__					,							param_name='''crop_size'''					,							default_to_square=__magic_name__    )
							snake_case_						:    Tuple				=  do_rescale if do_rescale is not None else self.do_rescale
							snake_case_						:    str				=  rescale_factor if rescale_factor is not None else self.rescale_factor
							snake_case_						:    Optional[Any]				=  do_normalize if do_normalize is not None else self.do_normalize
							snake_case_						:    List[Any]				=  image_mean if image_mean is not None else self.image_mean
							snake_case_						:    Optional[int]				=  image_std if image_std is not None else self.image_std
							snake_case_						:    Dict				=  do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

							snake_case_						:    List[str]				=  make_list_of_images(__magic_name__    )

							if not valid_images(__magic_name__    ):
											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:
											snake_case_						:    Optional[Any]				=  [convert_to_rgb(__magic_name__    ) for image in images]

							# All transformations expect numpy arrays.
							snake_case_						:    Union[str, Any]				=  [to_numpy_array(__magic_name__    ) for image in images]

							if do_resize:
											snake_case_						:    List[str]				=  [self.resize(image=__magic_name__					,							size=__magic_name__					,							resample=__magic_name__    ) for image in images]

							if do_center_crop:
											snake_case_						:    List[Any]				=  [self.center_crop(image=__magic_name__					,							size=__magic_name__    ) for image in images]

							if do_rescale:
											snake_case_						:    Union[str, Any]				=  [self.rescale(image=__magic_name__					,							scale=__magic_name__    ) for image in images]

							if do_normalize:
											snake_case_						:    int				=  [self.normalize(image=__magic_name__					,							mean=__magic_name__					,							std=__magic_name__    ) for image in images]

							snake_case_						:    Optional[Any]				=  [to_channel_dimension_format(__magic_name__					,							__magic_name__    ) for image in images]

							snake_case_						:    int				=  {'''pixel_values''': images}
							return BatchFeature(data=__magic_name__					,							tensor_type=__magic_name__    )







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


lowerCAmelCase_    =				logging.get_logger(__name__)

lowerCAmelCase_    =				{
    # See all MEGATRON_BERT models at https://huggingface.co/models?filter=bert
}



class 					__lowerCAmelCase       (			_a     ):
			lowerCamelCase_     :     Any       			=      '''megatron-bert'''






			def __init__(self					,							__magic_name__=2_9056					,							__magic_name__=1024					,							__magic_name__=24					,							__magic_name__=16					,							__magic_name__=4096					,							__magic_name__="gelu"					,							__magic_name__=0.1					,							__magic_name__=0.1					,							__magic_name__=512					,							__magic_name__=2					,							__magic_name__=0.02					,							__magic_name__=1e-12					,							__magic_name__=0					,							__magic_name__="absolute"					,							__magic_name__=True					,							**__magic_name__					,							)     ->   Any:


							'''simple docstring'''



							super().__init__(pad_token_id=__magic_name__					,							**__magic_name__    )

							snake_case_						:    Union[str, Any]				=  vocab_size
							snake_case_						:    Dict				=  hidden_size
							snake_case_						:    Dict				=  num_hidden_layers
							snake_case_						:    Optional[int]				=  num_attention_heads
							snake_case_						:    int				=  hidden_act
							snake_case_						:    List[str]				=  intermediate_size
							snake_case_						:    Dict				=  hidden_dropout_prob
							snake_case_						:    str				=  attention_probs_dropout_prob
							snake_case_						:    str				=  max_position_embeddings
							snake_case_						:    Any				=  type_vocab_size
							snake_case_						:    int				=  initializer_range
							snake_case_						:    int				=  layer_norm_eps
							snake_case_						:    List[str]				=  position_embedding_type
							snake_case_						:    Dict				=  use_cache
