
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


lowerCAmelCase__     						=			logging.get_logger(__name__)

lowerCAmelCase__     						=			{
    '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     a_			(						SCREAMING_SNAKE_CASE						):






 '''simple docstring'''






 UpperCAmelCase_     			= 'bloom'
 UpperCAmelCase_     			= ['past_key_values']
 UpperCAmelCase_     			= {
     'num_hidden_layers': 'n_layer',
     'num_attention_heads': 'n_head',
 }




 def __init__(      self :  Optional[Any]      ,   lowercase__ :  Any=250_880      ,   lowercase__ :  Optional[Any]=64      ,   lowercase__ :  int=2      ,   lowercase__ :  str=8      ,   lowercase__ :  Any=1e-5      ,   lowercase__ :  Any=0.02      ,   lowercase__ :  Tuple=True      ,   lowercase__ :  Optional[Any]=1      ,   lowercase__ :  Optional[int]=2      ,   lowercase__ :  Dict=False      ,   lowercase__ :  Union[str, Any]=0.0      ,   lowercase__ :  Any=0.0      ,   lowercase__ :  Tuple=1      ,   lowercase__ :  Tuple=False      ,   **lowercase__ :  Dict      ,   ):







        '''simple docstring'''



        lowerCAmelCase__					     = vocab_size
        # Backward compatibility with n_embed kwarg
        lowerCAmelCase__					     = kwargs.pop('n_embed'      ,   lowercase__)
        lowerCAmelCase__					     = hidden_size if n_embed is None else n_embed
        lowerCAmelCase__					     = n_layer
        lowerCAmelCase__					     = n_head
        lowerCAmelCase__					     = layer_norm_epsilon
        lowerCAmelCase__					     = initializer_range
        lowerCAmelCase__					     = use_cache
        lowerCAmelCase__					     = pretraining_tp
        lowerCAmelCase__					     = apply_residual_connection_post_layernorm
        lowerCAmelCase__					     = hidden_dropout
        lowerCAmelCase__					     = attention_dropout

        lowerCAmelCase__					     = bos_token_id
        lowerCAmelCase__					     = eos_token_id
        lowerCAmelCase__					     = slow_but_exact

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






class     a_			(						SCREAMING_SNAKE_CASE						):






 '''simple docstring'''






 UpperCAmelCase_     			= version.parse('1.12'						)




 def __init__(      self :  List[Any]      ,   lowercase__ :  PretrainedConfig      ,   lowercase__ :  str = "default"      ,   lowercase__ :  List[PatchingSpec] = None      ,   lowercase__ :  bool = False      ,   ):







        '''simple docstring'''



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




 @property
 def 		__snake_case						(      self :  str):







        '''simple docstring'''



        lowerCAmelCase__					     = 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_(lowercase__      ,   direction='inputs'      ,   inverted_values_shape=lowercase__)
               lowerCAmelCase__					     = {0: 'batch', 1: 'past_sequence + sequence'}
        else:
               lowerCAmelCase__					     = {0: 'batch', 1: 'sequence'}

        return common_inputs




 @property
 def 		__snake_case						(      self :  Optional[int]):







        '''simple docstring'''



        return self._config.n_layer




 @property
 def 		__snake_case						(      self :  Tuple):







        '''simple docstring'''



        return self._config.n_head




 @property
 def 		__snake_case						(      self :  Dict):







        '''simple docstring'''



        return 1e-3




 def 		__snake_case						(      self :  Any      ,   lowercase__ :  "PreTrainedTokenizer"      ,   lowercase__ :  int = -1      ,   lowercase__ :  int = -1      ,   lowercase__ :  bool = False      ,   lowercase__ :  Optional["TensorType"] = None      ,   ):







        '''simple docstring'''



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

        # 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__					     = self._config.hidden_size // self.num_attention_heads
                      lowerCAmelCase__					     = (
                          batch * self.num_attention_heads,
                          head_dim,
                          past_key_values_length,
                      )
                      lowerCAmelCase__					     = (
                          batch * self.num_attention_heads,
                          past_key_values_length,
                          head_dim,
                      )
                      lowerCAmelCase__					     = [
                          (torch.zeros(lowercase__), torch.zeros(lowercase__)) 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(lowercase__      ,   lowercase__      ,   dtype=lowercase__)]      ,   dim=1)

        return ordered_inputs




 @property
 def 		__snake_case						(      self :  Dict):







        '''simple docstring'''



        return 13

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


if is_vision_available():
    import PIL


lowerCAmelCase__     						=			logging.get_logger(__name__)
class     a_			(						SCREAMING_SNAKE_CASE						):






 '''simple docstring'''






 UpperCAmelCase_     			= ['pixel_values']




 def __init__(      self :  Tuple      ,   lowercase__ :  bool = True      ,   lowercase__ :  Dict[str, int] = None      ,   lowercase__ :  PILImageResampling = PILImageResampling.BICUBIC      ,   lowercase__ :  bool = True      ,   lowercase__ :  Union[int, float] = 1 / 255      ,   lowercase__ :  bool = True      ,   lowercase__ :  Optional[Union[float, List[float]]] = None      ,   lowercase__ :  Optional[Union[float, List[float]]] = None      ,   lowercase__ :  bool = True      ,   **lowercase__ :  List[Any]      ,   ):







        '''simple docstring'''



        super().__init__(**lowercase__)
        lowerCAmelCase__					     = size if size is not None else {'height': 384, 'width': 384}
        lowerCAmelCase__					     = get_size_dict(lowercase__      ,   default_to_square=lowercase__)

        lowerCAmelCase__					     = do_resize
        lowerCAmelCase__					     = size
        lowerCAmelCase__					     = resample
        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 		__snake_case						(      self :  List[str]      ,   lowercase__ :  np.ndarray      ,   lowercase__ :  Dict[str, int]      ,   lowercase__ :  PILImageResampling = PILImageResampling.BICUBIC      ,   lowercase__ :  Optional[Union[str, ChannelDimension]] = None      ,   **lowercase__ :  Dict      ,   ):







        '''simple docstring'''



        lowerCAmelCase__					     = get_size_dict(lowercase__      ,   default_to_square=lowercase__)
        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()}""")
        lowerCAmelCase__					     = (size['height'], size['width'])
        return resize(lowercase__      ,   size=lowercase__      ,   resample=lowercase__      ,   data_format=lowercase__      ,   **lowercase__)




 def 		__snake_case						(      self :  List[str]      ,   lowercase__ :  np.ndarray      ,   lowercase__ :  Union[int, float]      ,   lowercase__ :  Optional[Union[str, ChannelDimension]] = None      ,   **lowercase__ :  Union[str, Any]      ,   ):







        '''simple docstring'''



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




 def 		__snake_case						(      self :  Optional[Any]      ,   lowercase__ :  np.ndarray      ,   lowercase__ :  Union[float, List[float]]      ,   lowercase__ :  Union[float, List[float]]      ,   lowercase__ :  Optional[Union[str, ChannelDimension]] = None      ,   **lowercase__ :  Any      ,   ):







        '''simple docstring'''



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




 def 		__snake_case						(      self :  Any      ,   lowercase__ :  ImageInput      ,   lowercase__ :  Optional[bool] = None      ,   lowercase__ :  Optional[Dict[str, int]] = None      ,   lowercase__ :  PILImageResampling = None      ,   lowercase__ :  Optional[bool] = None      ,   lowercase__ :  Optional[float] = None      ,   lowercase__ :  Optional[bool] = None      ,   lowercase__ :  Optional[Union[float, List[float]]] = None      ,   lowercase__ :  Optional[Union[float, List[float]]] = None      ,   lowercase__ :  Optional[Union[str, TensorType]] = None      ,   lowercase__ :  bool = None      ,   lowercase__ :  ChannelDimension = ChannelDimension.FIRST      ,   **lowercase__ :  Dict      ,   ):







        '''simple docstring'''



        lowerCAmelCase__					     = do_resize if do_resize is not None else self.do_resize
        lowerCAmelCase__					     = resample if resample is not None else self.resample
        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__					     = size if size is not None else self.size
        lowerCAmelCase__					     = get_size_dict(lowercase__      ,   default_to_square=lowercase__)

        lowerCAmelCase__					     = make_list_of_images(lowercase__)

        if not valid_images(lowercase__):
               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 or resample is None:
               raise ValueError('Size and resample 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 std must be specified if do_normalize is True.')

        # PIL RGBA images are converted to RGB
        if do_convert_rgb:
               lowerCAmelCase__					     = [convert_to_rgb(lowercase__) for image in images]

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

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

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

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

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

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

        return encoded_outputs
