






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


a_							=    logging.get_logger(__name__)


if is_vision_available():
					import PIL


class      lowercase__     (			__A	):
	a_         =["""pixel_values"""]

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







							'''simple docstring'''





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

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

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







							'''simple docstring'''





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

	def 		UpperCAmelCase  (							self		,    __UpperCAmelCase		,    __UpperCAmelCase		,    __UpperCAmelCase = None		,    **__UpperCAmelCase		,    )->					np.ndarray:







							'''simple docstring'''





							lowerCAmelCase__       =						get_size_dict(__UpperCAmelCase       )
							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(__UpperCAmelCase		,    size=(size["height"], size["width"])		,    data_format=__UpperCAmelCase		,    **__UpperCAmelCase       )

	def 		UpperCAmelCase  (							self		,    __UpperCAmelCase		,    __UpperCAmelCase		,    __UpperCAmelCase = None		,    **__UpperCAmelCase		,    )->					List[Any]:







							'''simple docstring'''





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

	def 		UpperCAmelCase  (							self		,    __UpperCAmelCase		,    __UpperCAmelCase		,    __UpperCAmelCase		,    __UpperCAmelCase = None		,    **__UpperCAmelCase		,    )->					np.ndarray:







							'''simple docstring'''





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


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







							'''simple docstring'''





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

							lowerCAmelCase__       =						make_list_of_images(__UpperCAmelCase       )

							if not valid_images(__UpperCAmelCase       ):
													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:
													lowerCAmelCase__       =						[convert_to_rgb(__UpperCAmelCase       ) for image in images]

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

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

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

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

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

							lowerCAmelCase__       =						[to_channel_dimension_format(__UpperCAmelCase		,    __UpperCAmelCase       ) for image in images]

							lowerCAmelCase__       =						{'''pixel_values''': images}
							return BatchFeature(data=__UpperCAmelCase		,    tensor_type=__UpperCAmelCase       )














from collections import OrderedDict
from typing import Any, List, Mapping, Optional

from ... import PreTrainedTokenizer, TensorType, is_torch_available
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast, PatchingSpec
from ...utils import logging


a_							=    logging.get_logger(__name__)


a_							=    {
    '''Salesforce/codegen-350M-nl''': '''https://huggingface.co/Salesforce/codegen-350M-nl/resolve/main/config.json''',
    '''Salesforce/codegen-350M-multi''': '''https://huggingface.co/Salesforce/codegen-350M-multi/resolve/main/config.json''',
    '''Salesforce/codegen-350M-mono''': '''https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/config.json''',
    '''Salesforce/codegen-2B-nl''': '''https://huggingface.co/Salesforce/codegen-2B-nl/resolve/main/config.json''',
    '''Salesforce/codegen-2B-multi''': '''https://huggingface.co/Salesforce/codegen-2B-multi/resolve/main/config.json''',
    '''Salesforce/codegen-2B-mono''': '''https://huggingface.co/Salesforce/codegen-2B-mono/resolve/main/config.json''',
    '''Salesforce/codegen-6B-nl''': '''https://huggingface.co/Salesforce/codegen-6B-nl/resolve/main/config.json''',
    '''Salesforce/codegen-6B-multi''': '''https://huggingface.co/Salesforce/codegen-6B-multi/resolve/main/config.json''',
    '''Salesforce/codegen-6B-mono''': '''https://huggingface.co/Salesforce/codegen-6B-mono/resolve/main/config.json''',
    '''Salesforce/codegen-16B-nl''': '''https://huggingface.co/Salesforce/codegen-16B-nl/resolve/main/config.json''',
    '''Salesforce/codegen-16B-multi''': '''https://huggingface.co/Salesforce/codegen-16B-multi/resolve/main/config.json''',
    '''Salesforce/codegen-16B-mono''': '''https://huggingface.co/Salesforce/codegen-16B-mono/resolve/main/config.json''',
}


class      lowercase__     (			_UpperCAmelCase	):
	a_         ="""codegen"""
	a_         ={
	    """max_position_embeddings""": """n_positions""",
	    """hidden_size""": """n_embd""",
	    """num_attention_heads""": """n_head""",
	    """num_hidden_layers""": """n_layer""",
	}

	def __init__(							self		,    __UpperCAmelCase=50400		,    __UpperCAmelCase=2048		,    __UpperCAmelCase=2048		,    __UpperCAmelCase=4096		,    __UpperCAmelCase=28		,    __UpperCAmelCase=16		,    __UpperCAmelCase=64		,    __UpperCAmelCase=None		,    __UpperCAmelCase="gelu_new"		,    __UpperCAmelCase=0.0		,    __UpperCAmelCase=0.0		,    __UpperCAmelCase=0.0		,    __UpperCAmelCase=1E-5		,    __UpperCAmelCase=0.02		,    __UpperCAmelCase=True		,    __UpperCAmelCase=50256		,    __UpperCAmelCase=50256		,    __UpperCAmelCase=False		,    **__UpperCAmelCase		,    )->					Optional[int]:







							'''simple docstring'''





							lowerCAmelCase__       =						vocab_size
							lowerCAmelCase__       =						n_ctx
							lowerCAmelCase__       =						n_positions
							lowerCAmelCase__       =						n_embd
							lowerCAmelCase__       =						n_layer
							lowerCAmelCase__       =						n_head
							lowerCAmelCase__       =						n_inner
							lowerCAmelCase__       =						rotary_dim
							lowerCAmelCase__       =						activation_function
							lowerCAmelCase__       =						resid_pdrop
							lowerCAmelCase__       =						embd_pdrop
							lowerCAmelCase__       =						attn_pdrop
							lowerCAmelCase__       =						layer_norm_epsilon
							lowerCAmelCase__       =						initializer_range
							lowerCAmelCase__       =						use_cache

							lowerCAmelCase__       =						bos_token_id
							lowerCAmelCase__       =						eos_token_id

							super().__init__(
							    bos_token_id=__UpperCAmelCase		,    eos_token_id=__UpperCAmelCase		,    tie_word_embeddings=__UpperCAmelCase		,    **__UpperCAmelCase       )





class      lowercase__     (			_UpperCAmelCase	):

	def __init__(							self		,    __UpperCAmelCase		,    __UpperCAmelCase = "default"		,    __UpperCAmelCase = None		,    __UpperCAmelCase = False		,    )->					Any:







							'''simple docstring'''





							super().__init__(__UpperCAmelCase		,    task=__UpperCAmelCase		,    patching_specs=__UpperCAmelCase		,    use_past=__UpperCAmelCase       )
							if not getattr(self._config		,    "pad_token_id"		,    __UpperCAmelCase       ):
													# TODO: how to do that better?
													lowerCAmelCase__       =						0

	@property
	def 		UpperCAmelCase  (							self       )->					Mapping[str, Mapping[int, str]]:







							'''simple docstring'''





							lowerCAmelCase__       =						OrderedDict({"input_ids": {0: "batch", 1: "sequence"}}       )
							if self.use_past:
													self.fill_with_past_key_values_(__UpperCAmelCase		,    direction="inputs"       )
													lowerCAmelCase__       =						{0: "batch", 1: "past_sequence + sequence"}
							else:
													lowerCAmelCase__       =						{0: "batch", 1: "sequence"}

							return common_inputs

	@property
	def 		UpperCAmelCase  (							self       )->					int:







							'''simple docstring'''





							return self._config.n_layer

	@property
	def 		UpperCAmelCase  (							self       )->					int:







							'''simple docstring'''





							return self._config.n_head

	def 		UpperCAmelCase  (							self		,    __UpperCAmelCase		,    __UpperCAmelCase = -1		,    __UpperCAmelCase = -1		,    __UpperCAmelCase = False		,    __UpperCAmelCase = None		,    )->					Mapping[str, Any]:







							'''simple docstring'''





							lowerCAmelCase__       =						super(__UpperCAmelCase		,    self       ).generate_dummy_inputs(
							    __UpperCAmelCase		,    batch_size=__UpperCAmelCase		,    seq_length=__UpperCAmelCase		,    is_pair=__UpperCAmelCase		,    framework=__UpperCAmelCase       )

							# We need to order the input in the way they appears in the forward()
							lowerCAmelCase__       =						OrderedDict({"input_ids": common_inputs["input_ids"]}       )

							# Need to add the past_keys
							if self.use_past:
													if not is_torch_available():
																			raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."       )
													else:
																			import torch

																			lowerCAmelCase__      ,							lowerCAmelCase__       =						common_inputs["input_ids"].shape
																			# Not using the same length for past_key_values
																			lowerCAmelCase__       =						seqlen + 2
																			lowerCAmelCase__       =						(
																			    batch,
																			    self.num_attention_heads,
																			    past_key_values_length,
																			    self._config.hidden_size // self.num_attention_heads,
																			)
																			lowerCAmelCase__       =						[
																			    (torch.zeros(__UpperCAmelCase       ), torch.zeros(__UpperCAmelCase       )) for _ in range(self.num_layers       )
																			]

							lowerCAmelCase__       =						common_inputs["attention_mask"]
							if self.use_past:
													lowerCAmelCase__       =						ordered_inputs["attention_mask"].dtype
													lowerCAmelCase__       =						torch.cat(
													    [ordered_inputs["attention_mask"], torch.ones(__UpperCAmelCase		,    __UpperCAmelCase		,    dtype=__UpperCAmelCase       )]		,    dim=1       )

							return ordered_inputs


	@property
	def 		UpperCAmelCase  (							self       )->					int:







							'''simple docstring'''





							return 13






