






"""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,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    is_valid_image,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
      import PIL


lowerCamelCase__      = logging.get_logger(__name__)






def     _SCREAMING_SNAKE_CASE				(			UpperCamelCase  :						List[str]     ):







  if isinstance(__UpperCAmelCase		,					(list, tuple)     ) and isinstance(videos[0]		,					(list, tuple)     ) and is_valid_image(videos[0][0]     ):
    return videos

  elif isinstance(__UpperCAmelCase		,					(list, tuple)     ) and is_valid_image(videos[0]     ):
    return [videos]

  elif is_valid_image(__UpperCAmelCase     ):
    return [[videos]]

  raise ValueError(F"""Could not make batched video from {videos}"""     )







class        _UpperCamelCase		(			_snake_case):
    __lowerCamelCase    =	['pixel_values']






    def __init__(self    ,   lowerCamelCase__ = True    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = PILImageResampling.BILINEAR    ,   lowerCamelCase__ = True    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = True    ,   lowerCamelCase__ = 1 / 2_5_5    ,   lowerCamelCase__ = True    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   **lowerCamelCase__    ,   ):


      """simple docstring"""
      super().__init__(**lowerCamelCase__ )
      A__           =				size if size is not None else {"""shortest_edge""": 2_2_4}
      A__           =				get_size_dict(lowerCamelCase__    ,   default_to_square=lowerCamelCase__ )
      A__           =				crop_size if crop_size is not None else {"""height""": 2_2_4, """width""": 2_2_4}
      A__           =				get_size_dict(lowerCamelCase__    ,   param_name="""crop_size""" )

      A__           =				do_resize
      A__           =				size
      A__           =				do_center_crop
      A__           =				crop_size
      A__           =				resample
      A__           =				do_rescale
      A__           =				rescale_factor
      A__           =				do_normalize
      A__           =				image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
      A__           =				image_std if image_std is not None else IMAGENET_STANDARD_STD






    def 			A     (self    ,   lowerCamelCase__    ,   lowerCamelCase__    ,   lowerCamelCase__ = PILImageResampling.BILINEAR    ,   lowerCamelCase__ = None    ,   **lowerCamelCase__    ,   ):


      """simple docstring"""
      A__           =				get_size_dict(lowerCamelCase__    ,   default_to_square=lowerCamelCase__ )
      if "shortest_edge" in size:
        A__           =				get_resize_output_image_size(lowerCamelCase__    ,   size["""shortest_edge"""]    ,   default_to_square=lowerCamelCase__ )
      elif "height" in size and "width" in size:
        A__           =				(size["""height"""], size["""width"""])
      else:
        raise ValueError(F"""Size must have 'height' and 'width' or 'shortest_edge' as keys. Got {size.keys()}""" )
      return resize(lowerCamelCase__    ,   size=lowerCamelCase__    ,   resample=lowerCamelCase__    ,   data_format=lowerCamelCase__    ,   **lowerCamelCase__ )






    def 			A     (self    ,   lowerCamelCase__    ,   lowerCamelCase__    ,   lowerCamelCase__ = None    ,   **lowerCamelCase__    ,   ):


      """simple docstring"""
      A__           =				get_size_dict(lowerCamelCase__ )
      if "height" not in size or "width" not in size:
        raise ValueError(F"""Size must have 'height' and 'width' as keys. Got {size.keys()}""" )
      return center_crop(lowerCamelCase__    ,   size=(size["""height"""], size["""width"""])    ,   data_format=lowerCamelCase__    ,   **lowerCamelCase__ )






    def 			A     (self    ,   lowerCamelCase__    ,   lowerCamelCase__    ,   lowerCamelCase__ = None    ,   **lowerCamelCase__    ,   ):


      """simple docstring"""
      return rescale(lowerCamelCase__    ,   scale=lowerCamelCase__    ,   data_format=lowerCamelCase__    ,   **lowerCamelCase__ )






    def 			A     (self    ,   lowerCamelCase__    ,   lowerCamelCase__    ,   lowerCamelCase__    ,   lowerCamelCase__ = None    ,   **lowerCamelCase__    ,   ):


      """simple docstring"""
      return normalize(lowerCamelCase__    ,   mean=lowerCamelCase__    ,   std=lowerCamelCase__    ,   data_format=lowerCamelCase__    ,   **lowerCamelCase__ )






    def 			A     (self    ,   lowerCamelCase__    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = ChannelDimension.FIRST    ,   ):


      """simple docstring"""

      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_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.""" )

      # All transformations expect numpy arrays.
      A__           =				to_numpy_array(lowerCamelCase__ )

      if do_resize:
        A__           =				self.resize(image=lowerCamelCase__    ,   size=lowerCamelCase__    ,   resample=lowerCamelCase__ )

      if do_center_crop:
        A__           =				self.center_crop(lowerCamelCase__    ,   size=lowerCamelCase__ )

      if do_rescale:
        A__           =				self.rescale(image=lowerCamelCase__    ,   scale=lowerCamelCase__ )

      if do_normalize:
        A__           =				self.normalize(image=lowerCamelCase__    ,   mean=lowerCamelCase__    ,   std=lowerCamelCase__ )

      A__           =				to_channel_dimension_format(lowerCamelCase__    ,   lowerCamelCase__ )
      return image






    def 			A     (self    ,   lowerCamelCase__    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = None    ,   lowerCamelCase__ = ChannelDimension.FIRST    ,   **lowerCamelCase__    ,   ):


      """simple docstring"""
      A__           =				do_resize if do_resize is not None else self.do_resize
      A__           =				resample if resample is not None else self.resample
      A__           =				do_center_crop if do_center_crop is not None else self.do_center_crop
      A__           =				do_rescale if do_rescale is not None else self.do_rescale
      A__           =				rescale_factor if rescale_factor is not None else self.rescale_factor
      A__           =				do_normalize if do_normalize is not None else self.do_normalize
      A__           =				image_mean if image_mean is not None else self.image_mean
      A__           =				image_std if image_std is not None else self.image_std

      A__           =				size if size is not None else self.size
      A__           =				get_size_dict(lowerCamelCase__    ,   default_to_square=lowerCamelCase__ )
      A__           =				crop_size if crop_size is not None else self.crop_size
      A__           =				get_size_dict(lowerCamelCase__    ,   param_name="""crop_size""" )

      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.""" )

      A__           =				make_batched(lowerCamelCase__ )

      A__           =				[
          [
              self._preprocess_image(
                  image=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=lowerCamelCase__    ,   image_std=lowerCamelCase__    ,   data_format=lowerCamelCase__    ,   )
              for img in video
          ]
          for video in videos
      ]

      A__           =				{"""pixel_values""": videos}
      return BatchFeature(data=lowerCamelCase__    ,   tensor_type=lowerCamelCase__ )











'''simple docstring'''

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


a   	=    logging.get_logger(__name__)

a   	=    {
    "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			( _snake_case      ):
   __UpperCamelCase :			List[str]						   =						'bloom'
   __UpperCamelCase :			Optional[Any]						   =						['past_key_values']
   __UpperCamelCase :			Optional[int]						   =						{
       'num_hidden_layers': 'n_layer',
       'num_attention_heads': 'n_head',
   }





   def __init__(       self					:      Union[str, Any]					,lowerCamelCase					:      str=25_0880					,lowerCamelCase					:      List[Any]=64					,lowerCamelCase					:      Optional[Any]=2					,lowerCamelCase					:      Tuple=8					,lowerCamelCase					:      Union[str, Any]=1E-5					,lowerCamelCase					:      Optional[Any]=0.02					,lowerCamelCase					:      str=True					,lowerCamelCase					:      List[Any]=1					,lowerCamelCase					:      Union[str, Any]=2					,lowerCamelCase					:      Optional[int]=False					,lowerCamelCase					:      Optional[int]=0.0					,lowerCamelCase					:      List[Any]=0.0					,lowerCamelCase					:      Optional[Any]=1					,lowerCamelCase					:      Tuple=False					,**lowerCamelCase					:      str					,):

      '''simple docstring'''

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

      __SCREAMING_SNAKE_CASE   				=							bos_token_id
      __SCREAMING_SNAKE_CASE   				=							eos_token_id
      __SCREAMING_SNAKE_CASE   				=							slow_but_exact

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







class __a			( _snake_case      ):
   __UpperCamelCase :			int						   =						version.parse('1.12'      )





   def __init__(       self					:      Optional[int]					,lowerCamelCase					:      PretrainedConfig					,lowerCamelCase					:      str = "default"					,lowerCamelCase					:      List[PatchingSpec] = None					,lowerCamelCase					:      bool = False					,):

      '''simple docstring'''

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





   @property
   def   UpperCAmelCase__  (       self					:      int     ):

      '''simple docstring'''

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

      return common_inputs





   @property
   def   UpperCAmelCase__  (       self					:      Tuple     ):

      '''simple docstring'''

      return self._config.n_layer





   @property
   def   UpperCAmelCase__  (       self					:      Dict     ):

      '''simple docstring'''

      return self._config.n_head





   @property
   def   UpperCAmelCase__  (       self					:      str     ):

      '''simple docstring'''

      return 1E-3





   def   UpperCAmelCase__  (       self					:      str					,lowerCamelCase					:      "PreTrainedTokenizer"					,lowerCamelCase					:      int = -1					,lowerCamelCase					:      int = -1					,lowerCamelCase					:      bool = False					,lowerCamelCase					:      Optional["TensorType"] = None					,):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							super(lowerCamelCase					,self     ).generate_dummy_inputs(
          lowerCamelCase					,batch_size=lowerCamelCase					,seq_length=lowerCamelCase					,is_pair=lowerCamelCase					,framework=lowerCamelCase     )

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

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

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

      return ordered_inputs





   @property
   def   UpperCAmelCase__  (       self					:      str     ):

      '''simple docstring'''

      return 13





