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

from packaging import version


if TYPE_CHECKING:
							from ... import PreTrainedTokenizer, TensorType

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


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

lowercase__		:List[str]   =    {
    "bigscience/bloom": "https://huggingface.co/bigscience/bloom/resolve/main/config.json",
    "bigscience/bloom-560m": "https://huggingface.co/bigscience/bloom-560m/blob/main/config.json",
    "bigscience/bloom-1b1": "https://huggingface.co/bigscience/bloom-1b1/blob/main/config.json",
    "bigscience/bloom-1b7": "https://huggingface.co/bigscience/bloom-1b7/blob/main/config.json",
    "bigscience/bloom-3b": "https://huggingface.co/bigscience/bloom-3b/blob/main/config.json",
    "bigscience/bloom-7b1": "https://huggingface.co/bigscience/bloom-7b1/blob/main/config.json",
}







class 				lowercase		(					SCREAMING_SNAKE_CASE__		):
							lowercase_       :       Optional[Any]       					='''bloom'''
							lowercase_       :       List[str]       					=['''past_key_values''']
							lowercase_       :       Tuple       					={
							    '''num_hidden_layers''': '''n_layer''',
							    '''num_attention_heads''': '''n_head''',
							}




							def __init__(				self   ,A__=2_5_0_8_8_0   ,A__=6_4   ,A__=2   ,A__=8   ,A__=1E-5   ,A__=0.02   ,A__=True   ,A__=1   ,A__=2   ,A__=False   ,A__=0.0   ,A__=0.0   ,A__=1   ,A__=False   ,**A__   ,):
												lowercase							=						vocab_size
												# Backward compatibility with n_embed kwarg
												lowercase							=						kwargs.pop('''n_embed'''   ,A__)
												lowercase							=						hidden_size if n_embed is None else n_embed
												lowercase							=						n_layer
												lowercase							=						n_head
												lowercase							=						layer_norm_epsilon
												lowercase							=						initializer_range
												lowercase							=						use_cache
												lowercase							=						pretraining_tp
												lowercase							=						apply_residual_connection_post_layernorm
												lowercase							=						hidden_dropout
												lowercase							=						attention_dropout

												lowercase							=						bos_token_id
												lowercase							=						eos_token_id
												lowercase							=						slow_but_exact

												super().__init__(bos_token_id=A__   ,eos_token_id=A__   ,**A__)







class 				lowercase		(					SCREAMING_SNAKE_CASE__		):
							lowercase_       :       List[str]       					=version.parse('''1.12'''		)




							def __init__(				self   ,A__   ,A__ = "default"   ,A__ = None   ,A__ = False   ,):
												super().__init__(A__   ,task=A__   ,patching_specs=A__   ,use_past=A__)
												if not getattr(self._config   ,'''pad_token_id'''   ,A__):
																	# TODO: how to do that better?
																	lowercase							=						0




							@property
							def  A__      (				self):
												lowercase							=						OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}})
												if self.use_past:
																	# BLOOM stores values on dynamic axis 2. For more details see: https://github.com/huggingface/transformers/pull/18344
																	self.fill_with_past_key_values_(A__   ,direction='''inputs'''   ,inverted_values_shape=A__)
																	lowercase							=						{0: '''batch''', 1: '''past_sequence + sequence'''}
												else:
																	lowercase							=						{0: '''batch''', 1: '''sequence'''}

												return common_inputs




							@property
							def  A__      (				self):
												return self._config.n_layer




							@property
							def  A__      (				self):
												return self._config.n_head




							@property
							def  A__      (				self):
												return 1E-3




							def  A__      (				self   ,A__   ,A__ = -1   ,A__ = -1   ,A__ = False   ,A__ = None   ,):
												lowercase							=						super(A__   ,self).generate_dummy_inputs(
												    A__   ,batch_size=A__   ,seq_length=A__   ,is_pair=A__   ,framework=A__)

												# We need to order the input in the way they appears in the forward()
												lowercase							=						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

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

												lowercase							=						common_inputs['''attention_mask''']
												if self.use_past:
																	lowercase							=						ordered_inputs['''attention_mask'''].dtype
																	lowercase							=						torch.cat(
																	    [ordered_inputs['''attention_mask'''], torch.ones(A__   ,A__   ,dtype=A__)]   ,dim=1)

												return ordered_inputs





							@property
							def  A__      (				self):
												return 1_3








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     UpperCAmelCase__       (					A_		):



    """simple docstring"""






    UpperCAmelCase__						:		Union[str, Any]      =  ["pixel_values"]






    def __init__(			self					,   A_ = True					,   A_ = None					,   A_ = PILImageResampling.BICUBIC					,   A_ = True					,   A_ = None					,   A_ = True					,   A_ = 1 / 255					,   A_ = True					,   A_ = None					,   A_ = None					,   A_ = True					,   **A_					,   )  ->       None:
         super().__init__(**A_    )
         __UpperCamelCase    							=size if size is not None else {'shortest_edge': 224}
         __UpperCamelCase    							=get_size_dict(A_					,   default_to_square=A_    )
         __UpperCamelCase    							=crop_size if crop_size is not None else {'height': 224, 'width': 224}
         __UpperCamelCase    							=get_size_dict(A_					,   default_to_square=A_					,   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					,   A_					,   A_					,   A_ = PILImageResampling.BICUBIC					,   A_ = None					,   **A_					,   )  ->       np.ndarray:
         __UpperCamelCase    							=get_size_dict(A_					,   default_to_square=A_    )
         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(A_					,   size=size['shortest_edge']					,   default_to_square=A_    )
         return resize(A_					,   size=A_					,   resample=A_					,   data_format=A_					,   **A_    )






    def _a					(			self					,   A_					,   A_					,   A_ = None					,   **A_					,   )  ->       np.ndarray:
         __UpperCamelCase    							=get_size_dict(A_    )
         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(A_					,   size=(size['height'], size['width'])					,   data_format=A_					,   **A_    )






    def _a					(			self					,   A_					,   A_					,   A_ = None					,   **A_					,   )  ->       Union[str, Any]:
         return rescale(A_					,   scale=A_					,   data_format=A_					,   **A_    )






    def _a					(			self					,   A_					,   A_					,   A_					,   A_ = None					,   **A_					,   )  ->       np.ndarray:
         return normalize(A_					,   mean=A_					,   std=A_					,   data_format=A_					,   **A_    )






    def _a					(			self					,   A_					,   A_ = None					,   A_ = None					,   A_ = None					,   A_ = None					,   A_ = None					,   A_ = None					,   A_ = None					,   A_ = None					,   A_ = None					,   A_ = None					,   A_ = None					,   A_ = None					,   A_ = ChannelDimension.FIRST					,   **A_					,   )  ->       PIL.Image.Image:
         __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(A_					,   param_name='size'					,   default_to_square=A_    )
         __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(A_					,   param_name='crop_size'					,   default_to_square=A_    )
         __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(A_    )

         if not valid_images(A_    ):
              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(A_    ) for image in images]

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

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

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

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

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

         __UpperCamelCase    							=[to_channel_dimension_format(A_					,   A_    ) for image in images]

         __UpperCamelCase    							={'pixel_values': images}
         return BatchFeature(data=A_					,   tensor_type=A_    )





