


"""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, 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


__a			 =   logging.get_logger(__name__)
class 							lowerCamelCase       (			SCREAMING_SNAKE_CASE__ ):


							"""simple docstring"""
							SCREAMING_SNAKE_CASE										=      ["""pixel_values"""]






							def __init__(						self :     str		, lowerCamelCase_ :     List[str] = True		, lowerCamelCase_ :     Tuple = None		, lowerCamelCase_ :     Dict = True		, lowerCamelCase_ :     Any = None		, lowerCamelCase_ :     str = PILImageResampling.BICUBIC		, lowerCamelCase_ :     int = True		, lowerCamelCase_ :     Union[str, Any] = 1 / 255		, lowerCamelCase_ :     List[Any] = True		, lowerCamelCase_ :     Any = None		, lowerCamelCase_ :     List[str] = None		, **lowerCamelCase_ :     str		, ):
													super().__init__(**lowerCamelCase_				)
													UpperCAmelCase__		=    crop_size if crop_size is not None else {'''height''': 256, '''width''': 256}
													UpperCAmelCase__		=    get_size_dict(lowerCamelCase_		, param_name='''crop_size'''				)
													UpperCAmelCase__		=    size if size is not None else {'''height''': 224, '''width''': 224}
													UpperCAmelCase__		=    get_size_dict(lowerCamelCase_				)

													UpperCAmelCase__		=    do_center_crop
													UpperCAmelCase__		=    crop_size
													UpperCAmelCase__		=    do_resize
													UpperCAmelCase__		=    size
													UpperCAmelCase__		=    resample
													UpperCAmelCase__		=    do_rescale
													UpperCAmelCase__		=    rescale_factor
													UpperCAmelCase__		=    do_normalize
													UpperCAmelCase__		=    image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
													UpperCAmelCase__		=    image_std if image_std is not None else IMAGENET_DEFAULT_STD






							def 					lowerCAmelCase     (						self :     Dict		, lowerCamelCase_ :     int		, lowerCamelCase_ :     List[Any]		, lowerCamelCase_ :     int = None		, lowerCamelCase_ :     int = None		, **lowerCamelCase_ :     Union[str, Any]		, ):
													UpperCAmelCase__		=    self.size if size is None else size
													UpperCAmelCase__		=    get_size_dict(lowerCamelCase_				)
													UpperCAmelCase__		=    get_size_dict(lowerCamelCase_		, param_name='''crop_size'''				)

													UpperCAmelCase__	,				UpperCAmelCase__		=    get_image_size(lowerCamelCase_				)
													UpperCAmelCase__		=    min(lowerCamelCase_		, lowerCamelCase_				)
													UpperCAmelCase__		=    (size['''height'''] / crop_size['''height''']) * min_dim
													UpperCAmelCase__		=    (size['''width'''] / crop_size['''width''']) * min_dim
													return center_crop(lowerCamelCase_		, size=(cropped_height, cropped_width)		, data_format=lowerCamelCase_		, **lowerCamelCase_				)






							def 					lowerCAmelCase     (						self :     int		, lowerCamelCase_ :     Any		, lowerCamelCase_ :     str		, lowerCamelCase_ :     int = PIL.Image.BICUBIC		, lowerCamelCase_ :     List[str] = None		, **lowerCamelCase_ :     int		, ):
													UpperCAmelCase__		=    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 					lowerCAmelCase     (						self :     str		, lowerCamelCase_ :     List[str]		, lowerCamelCase_ :     Optional[Any]		, lowerCamelCase_ :     Tuple = None		, **lowerCamelCase_ :     Union[str, Any]		, ):
													return rescale(lowerCamelCase_		, scale=lowerCamelCase_		, data_format=lowerCamelCase_		, **lowerCamelCase_				)






							def 					lowerCAmelCase     (						self :     Tuple		, lowerCamelCase_ :     List[str]		, lowerCamelCase_ :     Tuple		, lowerCamelCase_ :     int		, lowerCamelCase_ :     List[str] = None		, **lowerCamelCase_ :     int		, ):
													return normalize(lowerCamelCase_		, mean=lowerCamelCase_		, std=lowerCamelCase_		, data_format=lowerCamelCase_		, **lowerCamelCase_				)






							def 					lowerCAmelCase     (						self :     str		, lowerCamelCase_ :     Optional[Any]		, lowerCamelCase_ :     Any = None		, lowerCamelCase_ :     Tuple = None		, lowerCamelCase_ :     Optional[int] = None		, lowerCamelCase_ :     int = None		, lowerCamelCase_ :     Optional[int] = None		, lowerCamelCase_ :     Union[str, Any] = None		, lowerCamelCase_ :     Optional[Any] = None		, lowerCamelCase_ :     Optional[int] = None		, lowerCamelCase_ :     Tuple = None		, lowerCamelCase_ :     List[str] = None		, lowerCamelCase_ :     str = None		, lowerCamelCase_ :     Optional[int] = ChannelDimension.FIRST		, **lowerCamelCase_ :     Union[str, Any]		, ):
													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'''				)
													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_				)
													UpperCAmelCase__		=    resample if resample is not None else self.resample
													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__		=    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.
													UpperCAmelCase__		=    [to_numpy_array(lowerCamelCase_				) for image in images]

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

													if do_resize:
																			UpperCAmelCase__		=    [self.resize(image=lowerCamelCase_		, size=lowerCamelCase_		, resample=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


__a			 =   logging.get_logger(__name__)

__a			 =   {
    "google/pegasus-x-base": "https://huggingface.co/google/pegasus-x-base/resolve/main/config.json",
    "google/pegasus-x-large": "https://huggingface.co/google/pegasus-x-large/resolve/main/config.json",
    # See all PEGASUS-X models at https://huggingface.co/models?filter=pegasus-x
}
class 							lowerCamelCase       (			__SCREAMING_SNAKE_CASE ):


							"""simple docstring"""
							SCREAMING_SNAKE_CASE										=      """pegasus_x"""
							SCREAMING_SNAKE_CASE										=      ["""past_key_values"""]
							SCREAMING_SNAKE_CASE										=      {"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}






							def __init__(						self :     int		, lowerCamelCase_ :     Any=96103		, lowerCamelCase_ :     Union[str, Any]=16384		, lowerCamelCase_ :     Any=16		, lowerCamelCase_ :     str=4096		, lowerCamelCase_ :     Tuple=16		, lowerCamelCase_ :     Optional[int]=16		, lowerCamelCase_ :     Tuple=4096		, lowerCamelCase_ :     Any=16		, lowerCamelCase_ :     List[str]=0.0		, lowerCamelCase_ :     int=0.0		, lowerCamelCase_ :     List[Any]=True		, lowerCamelCase_ :     str=True		, lowerCamelCase_ :     int="gelu"		, lowerCamelCase_ :     Optional[Any]=1024		, lowerCamelCase_ :     Optional[int]=0.1		, lowerCamelCase_ :     str=0.0		, lowerCamelCase_ :     Optional[Any]=0.0		, lowerCamelCase_ :     List[str]=0.02		, lowerCamelCase_ :     Optional[Any]=0		, lowerCamelCase_ :     List[str]=True		, lowerCamelCase_ :     List[Any]=0		, lowerCamelCase_ :     str=1		, lowerCamelCase_ :     Optional[Any]=1		, lowerCamelCase_ :     Tuple=32		, lowerCamelCase_ :     Dict=512		, lowerCamelCase_ :     List[Any]=True		, **lowerCamelCase_ :     int		, ):
													UpperCAmelCase__		=    vocab_size
													UpperCAmelCase__		=    max_position_embeddings
													UpperCAmelCase__		=    d_model
													UpperCAmelCase__		=    encoder_ffn_dim
													UpperCAmelCase__		=    encoder_layers
													UpperCAmelCase__		=    encoder_attention_heads
													UpperCAmelCase__		=    decoder_ffn_dim
													UpperCAmelCase__		=    decoder_layers
													UpperCAmelCase__		=    decoder_attention_heads
													UpperCAmelCase__		=    dropout
													UpperCAmelCase__		=    attention_dropout
													UpperCAmelCase__		=    activation_dropout
													UpperCAmelCase__		=    activation_function
													UpperCAmelCase__		=    init_std
													UpperCAmelCase__		=    encoder_layerdrop
													UpperCAmelCase__		=    decoder_layerdrop
													UpperCAmelCase__		=    use_cache
													UpperCAmelCase__		=    encoder_layers
													UpperCAmelCase__		=    scale_embedding  # scale factor will be sqrt(d_model) if True

													UpperCAmelCase__		=    num_global_tokens
													UpperCAmelCase__		=    block_size
													UpperCAmelCase__		=    stagger_local_blocks

													super().__init__(
													    pad_token_id=lowerCamelCase_		, eos_token_id=lowerCamelCase_		, is_encoder_decoder=lowerCamelCase_		, decoder_start_token_id=lowerCamelCase_		, forced_eos_token_id=lowerCamelCase_		, **lowerCamelCase_		, )






							@property
							def 					lowerCAmelCase     (						self :     Optional[int]				):
													return self.encoder_attention_heads






							@property
							def 					lowerCAmelCase     (						self :     Optional[int]				):
													return self.d_model