




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, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    IMAGENET_DEFAULT_MEAN,
    IMAGENET_DEFAULT_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    get_image_size,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
	import PIL


__lowerCamelCase :    Optional[int]      						=      logging.get_logger(__name__)


class  lowerCamelCase     (		_lowerCamelCase    ):






			'''simple docstring'''





			UpperCamelCase__										=['''pixel_values''']

			def __init__(			self      : str							,    lowerCamelCase_      : bool = True							,    lowerCamelCase_      : Dict[str, int] = None							,    lowerCamelCase_      : bool = True							,    lowerCamelCase_      : Dict[str, int] = None							,    lowerCamelCase_      : PILImageResampling = PILImageResampling.BICUBIC							,    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_      : Optional[Any]							,    )    -> None:
								super().__init__(**lowerCamelCase_	)
								__magic_name__				:						Tuple     				=				crop_size if crop_size is not None else {'''height''': 256, '''width''': 256}
								__magic_name__				:						Dict     				=				get_size_dict(lowerCamelCase_							,    param_name='''crop_size'''	)
								__magic_name__				:						Optional[int]     				=				size if size is not None else {'''height''': 224, '''width''': 224}
								__magic_name__				:						List[str]     				=				get_size_dict(lowerCamelCase_	)

								__magic_name__				:						Any     				=				do_center_crop
								__magic_name__				:						List[str]     				=				crop_size
								__magic_name__				:						List[str]     				=				do_resize
								__magic_name__				:						Tuple     				=				size
								__magic_name__				:						Dict     				=				resample
								__magic_name__				:						int     				=				do_rescale
								__magic_name__				:						Optional[Any]     				=				rescale_factor
								__magic_name__				:						Any     				=				do_normalize
								__magic_name__				:						str     				=				image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
								__magic_name__				:						int     				=				image_std if image_std is not None else IMAGENET_DEFAULT_STD

			def 				UpperCAmelCase__							(			self      : int							,    lowerCamelCase_      : np.ndarray							,    lowerCamelCase_      : Dict[str, int]							,    lowerCamelCase_      : Optional[int] = None							,    lowerCamelCase_      : Optional[Union[str, ChannelDimension]] = None							,    **lowerCamelCase_      : Union[str, Any]							,    )    -> np.ndarray:
								__magic_name__				:						Any     				=				self.size if size is None else size
								__magic_name__				:						List[str]     				=				get_size_dict(lowerCamelCase_	)
								__magic_name__				:						Optional[int]     				=				get_size_dict(lowerCamelCase_							,    param_name='''crop_size'''	)

								__magic_name__				,     __magic_name__				:						Tuple     				=				get_image_size(lowerCamelCase_	)
								__magic_name__				:						List[Any]     				=				min(lowerCamelCase_							,    lowerCamelCase_	)
								__magic_name__				:						Any     				=				(size['''height'''] / crop_size['''height''']) * min_dim
								__magic_name__				:						Union[str, Any]     				=				(size['''width'''] / crop_size['''width''']) * min_dim
								return center_crop(lowerCamelCase_							,    size=(cropped_height, cropped_width)							,    data_format=lowerCamelCase_							,    **lowerCamelCase_	)

			def 				UpperCAmelCase__							(			self      : Optional[Any]							,    lowerCamelCase_      : np.ndarray							,    lowerCamelCase_      : Dict[str, int]							,    lowerCamelCase_      : PILImageResampling = PIL.Image.BICUBIC							,    lowerCamelCase_      : Optional[Union[str, ChannelDimension]] = None							,    **lowerCamelCase_      : Dict							,    )    -> np.ndarray:
								__magic_name__				:						List[str]     				=				get_size_dict(lowerCamelCase_	)
								if "height" not in size or "width" not in size:
													raise ValueError(F'''The size dictionary must contain the keys \'height\' and \'width\'. Got {size.keys()}'''	)
								return resize(
								    lowerCamelCase_							,    size=(size['''height'''], size['''width'''])							,    resample=lowerCamelCase_							,    data_format=lowerCamelCase_							,    **lowerCamelCase_	)

			def 				UpperCAmelCase__							(			self      : Tuple							,    lowerCamelCase_      : np.ndarray							,    lowerCamelCase_      : Union[int, float]							,    lowerCamelCase_      : Optional[Union[str, ChannelDimension]] = None							,    **lowerCamelCase_      : List[Any]							,    )    -> str:
								return rescale(lowerCamelCase_							,    scale=lowerCamelCase_							,    data_format=lowerCamelCase_							,    **lowerCamelCase_	)

			def 				UpperCAmelCase__							(			self      : str							,    lowerCamelCase_      : np.ndarray							,    lowerCamelCase_      : Union[float, List[float]]							,    lowerCamelCase_      : Union[float, List[float]]							,    lowerCamelCase_      : Optional[Union[str, ChannelDimension]] = None							,    **lowerCamelCase_      : Optional[int]							,    )    -> np.ndarray:
								return normalize(lowerCamelCase_							,    mean=lowerCamelCase_							,    std=lowerCamelCase_							,    data_format=lowerCamelCase_							,    **lowerCamelCase_	)


			def 				UpperCAmelCase__							(			self      : List[str]							,    lowerCamelCase_      : ImageInput							,    lowerCamelCase_      : Optional[bool] = None							,    lowerCamelCase_      : Optional[Dict[str, int]] = None							,    lowerCamelCase_      : Optional[bool] = None							,    lowerCamelCase_      : Optional[Dict[str, int]] = None							,    lowerCamelCase_      : PILImageResampling = None							,    lowerCamelCase_      : Optional[bool] = None							,    lowerCamelCase_      : Optional[float] = None							,    lowerCamelCase_      : Optional[bool] = None							,    lowerCamelCase_      : Optional[Union[float, List[float]]] = None							,    lowerCamelCase_      : Optional[Union[float, List[float]]] = None							,    lowerCamelCase_      : Optional[Union[str, TensorType]] = None							,    lowerCamelCase_      : ChannelDimension = ChannelDimension.FIRST							,    **lowerCamelCase_      : Dict							,    )    -> PIL.Image.Image:
								__magic_name__				:						Dict     				=				do_center_crop if do_center_crop is not None else self.do_center_crop
								__magic_name__				:						Optional[Any]     				=				crop_size if crop_size is not None else self.crop_size
								__magic_name__				:						Any     				=				get_size_dict(lowerCamelCase_							,    param_name='''crop_size'''	)
								__magic_name__				:						Union[str, Any]     				=				do_resize if do_resize is not None else self.do_resize
								__magic_name__				:						Tuple     				=				size if size is not None else self.size
								__magic_name__				:						Optional[Any]     				=				get_size_dict(lowerCamelCase_	)
								__magic_name__				:						Optional[Any]     				=				resample if resample is not None else self.resample
								__magic_name__				:						Tuple     				=				do_rescale if do_rescale is not None else self.do_rescale
								__magic_name__				:						int     				=				rescale_factor if rescale_factor is not None else self.rescale_factor
								__magic_name__				:						Optional[Any]     				=				do_normalize if do_normalize is not None else self.do_normalize
								__magic_name__				:						Tuple     				=				image_mean if image_mean is not None else self.image_mean
								__magic_name__				:						List[Any]     				=				image_std if image_std is not None else self.image_std

								__magic_name__				:						int     				=				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_center_crop and crop_size is None:
													raise ValueError('''If `do_center_crop` is set to `True`, `crop_size` must be provided.'''	)

								if do_resize and size is None:
													raise ValueError('''Size must be specified if do_resize 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 image standard deviation must be specified if do_normalize is True.'''	)

								# All transformations expect numpy arrays.
								__magic_name__				:						List[Any]     				=				[to_numpy_array(lowerCamelCase_	) for image in images]

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

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

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

								if do_normalize:
													__magic_name__				:						List[Any]     				=				[self.normalize(image=lowerCamelCase_							,    mean=lowerCamelCase_							,    std=lowerCamelCase_	) for image in images]

								__magic_name__				:						Union[str, Any]     				=				[to_channel_dimension_format(lowerCamelCase_							,    lowerCamelCase_	) for image in images]

								__magic_name__				:						List[Any]     				=				{'''pixel_values''': images}
								return BatchFeature(data=lowerCamelCase_							,    tensor_type=lowerCamelCase_	)









from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__A    :				List[str]    						=	logging.get_logger(__name__)

__A    :				List[Any]    						=	{
    """mnaylor/mega-base-wikitext""": """https://huggingface.co/mnaylor/mega-base-wikitext/resolve/main/config.json""",
}




class       UpperCAmelCase_   ( A							):




							'''simple docstring'''



							a__    	=  '''mega'''





							def __init__(       self							:						Any							,  a							:						List[str]=30_522							,  a							:						Dict=128							,  a							:						Dict=4							,  a							:						Union[str, Any]=256							,  a							:						Tuple=16							,  a							:						Any=True							,  a							:						Dict=64							,  a							:						Union[str, Any]=False							,  a							:						Tuple=-1							,  a							:						str=None							,  a							:						int=True							,  a							:						Optional[int]="scalenorm"							,  a							:						Optional[int]=True							,  a							:						Dict="silu"							,  a							:						Optional[Any]="softmax"							,  a							:						Any=0.1							,  a							:						List[Any]=0.1							,  a							:						Tuple=0.1							,  a							:						Optional[int]=False							,  a							:						List[str]=True							,  a							:						Optional[int]=256							,  a							:						List[str]=True							,  a							:						int=0.1							,  a							:						str=2_048							,  a							:						Tuple=False							,  a							:						Optional[int]=2							,  a							:						Optional[int]=0.02							,  a							:						Optional[int]=0.2							,  a							:						Union[str, Any]=0.02							,  a							:						str=1.0							,  a							:						Dict=1							,  a							:						Union[str, Any]=0							,  a							:						Dict=2							,  a							:						List[str]="rotary"							,  a							:						Union[str, Any]=None							,  a							:						List[Any]=True							,  a							:						Tuple=True							,  **a							:						Optional[int]							,  )      ->       Dict:
										super().__init__(pad_token_id=a							,  bos_token_id=a							,  eos_token_id=a							,  **a      )

										SCREAMING_SNAKE_CASE     =       vocab_size
										SCREAMING_SNAKE_CASE     =       hidden_size
										SCREAMING_SNAKE_CASE     =       num_hidden_layers
										SCREAMING_SNAKE_CASE     =       activation
										SCREAMING_SNAKE_CASE     =       attention_activation
										SCREAMING_SNAKE_CASE     =       intermediate_size
										SCREAMING_SNAKE_CASE     =       ema_projection_size
										SCREAMING_SNAKE_CASE     =       bidirectional
										SCREAMING_SNAKE_CASE     =       shared_representation_size
										SCREAMING_SNAKE_CASE     =       use_chunking
										SCREAMING_SNAKE_CASE     =       chunk_size
										SCREAMING_SNAKE_CASE     =       truncation
										SCREAMING_SNAKE_CASE     =       normalize_before_mega
										SCREAMING_SNAKE_CASE     =       normalization_type
										SCREAMING_SNAKE_CASE     =       norm_affine
										SCREAMING_SNAKE_CASE     =       dropout_prob
										SCREAMING_SNAKE_CASE     =       hidden_dropout_prob
										SCREAMING_SNAKE_CASE     =       attention_probs_dropout_prob
										SCREAMING_SNAKE_CASE     =       use_feature_dropout
										SCREAMING_SNAKE_CASE     =       use_normalized_ffn
										SCREAMING_SNAKE_CASE     =       nffn_hidden_size
										SCREAMING_SNAKE_CASE     =       normalize_before_ffn
										SCREAMING_SNAKE_CASE     =       nffn_activation_dropout_prob
										SCREAMING_SNAKE_CASE     =       max_positions
										SCREAMING_SNAKE_CASE     =       add_token_type_embeddings
										SCREAMING_SNAKE_CASE     =       type_vocab_size
										SCREAMING_SNAKE_CASE     =       initializer_range
										SCREAMING_SNAKE_CASE     =       ema_delta_alpha_range
										SCREAMING_SNAKE_CASE     =       ema_beta_range
										SCREAMING_SNAKE_CASE     =       ema_gamma_omega_range
										SCREAMING_SNAKE_CASE     =       relative_positional_bias
										SCREAMING_SNAKE_CASE     =       use_cache
										SCREAMING_SNAKE_CASE     =       classifier_dropout
										SCREAMING_SNAKE_CASE     =       add_lm_hidden_dense_layer
										SCREAMING_SNAKE_CASE     =       1  # not used but required by Hugging Face





class       UpperCAmelCase_   ( A							):




							'''simple docstring'''



							@property
							def  _UpperCAmelCase  (       self							:						Union[str, Any]      )      ->       Mapping[str, Mapping[int, str]]:
										if self.task == "multiple-choice":
													SCREAMING_SNAKE_CASE     =       {0: """batch""", 1: """choice""", 2: """sequence"""}
										else:
													SCREAMING_SNAKE_CASE     =       {0: """batch""", 1: """sequence"""}
										return OrderedDict(
										    [
										        ("""input_ids""", dynamic_axis),
										        ("""attention_mask""", dynamic_axis),
										    ]      )






