


'''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_DEFAULT_MEAN,
    IMAGENET_DEFAULT_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


__snake_case    						=logging.get_logger(__name__)

class 		UpperCAmelCase_      (  __lowercase		):
     lowerCamelCase				:	Tuple		=     ['''pixel_values''']





     def __init__( self       :      str    ,      UpperCAmelCase__       :      bool = True    ,      UpperCAmelCase__       :      Dict[str, int] = None    ,      UpperCAmelCase__       :      int = 0.9    ,      UpperCAmelCase__       :      PILImageResampling = PILImageResampling.BICUBIC    ,      UpperCAmelCase__       :      bool = True    ,      UpperCAmelCase__       :      Dict[str, int] = None    ,      UpperCAmelCase__       :      Union[int, float] = 1 / 2_5_5    ,      UpperCAmelCase__       :      bool = True    ,      UpperCAmelCase__       :      bool = True    ,      UpperCAmelCase__       :      Optional[Union[float, List[float]]] = None    ,      UpperCAmelCase__       :      Optional[Union[float, List[float]]] = None    ,      **UpperCAmelCase__       :      str    ,      )				->  None:
        super().__init__(**__UpperCAmelCase    )
        lowerCAmelCase     =			size if size is not None else {'shortest_edge': 2_2_4}
        lowerCAmelCase     =			get_size_dict(__UpperCAmelCase    ,      default_to_square=__UpperCAmelCase    )
        lowerCAmelCase     =			crop_size if crop_size is not None else {'height': 2_2_4, 'width': 2_2_4}
        lowerCAmelCase     =			get_size_dict(__UpperCAmelCase    ,      param_name='crop_size'    )

        lowerCAmelCase     =			do_resize
        lowerCAmelCase     =			size
        lowerCAmelCase     =			crop_pct
        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 IMAGENET_DEFAULT_MEAN
        lowerCAmelCase     =			image_std if image_std is not None else IMAGENET_DEFAULT_STD





     def 							__UpperCAmelCase      ( self       :      Tuple    ,      UpperCAmelCase__       :      np.ndarray    ,      UpperCAmelCase__       :      Dict[str, int]    ,      UpperCAmelCase__       :      Optional[float] = None    ,      UpperCAmelCase__       :      PILImageResampling = PILImageResampling.BICUBIC    ,      UpperCAmelCase__       :      Optional[Union[str, ChannelDimension]] = None    ,      **UpperCAmelCase__       :      List[Any]    ,      )				->  np.ndarray:
        lowerCAmelCase     =			get_size_dict(__UpperCAmelCase    ,      default_to_square=__UpperCAmelCase    )
        if "shortest_edge" not in size and ("height" not in size or "width" not in size):
           raise ValueError(F'''size must contain \'height\' and \'width\' or \'shortest_edge\' as keys. Got {size.keys()}'''    )
        if crop_pct is not None:
           if "shortest_edge" in size:
              lowerCAmelCase     =			int(size['shortest_edge'] / crop_pct    )
           elif "height" in size and "width" in size:
              if size["height"] == size["width"]:
                 lowerCAmelCase     =			int(size['height'] / crop_pct    )
              else:
                 lowerCAmelCase     =			(int(size['height'] / crop_pct    ), int(size['width'] / crop_pct    ))
           else:
              raise ValueError('Invalid size for resize: {}'.format(__UpperCAmelCase    )    )

           lowerCAmelCase     =			get_resize_output_image_size(__UpperCAmelCase    ,      size=__UpperCAmelCase    ,      default_to_square=__UpperCAmelCase    )
        else:
           if "shortest_edge" in size:
              lowerCAmelCase     =			get_resize_output_image_size(__UpperCAmelCase    ,      size=size['shortest_edge']    ,      default_to_square=__UpperCAmelCase    )
           elif "height" in size and "width" in size:
              lowerCAmelCase     =			(size['height'], size['width'])
           else:
              raise ValueError('Invalid size for resize: {}'.format(__UpperCAmelCase    )    )

        return resize(__UpperCAmelCase    ,      size=__UpperCAmelCase    ,      resample=__UpperCAmelCase    ,      data_format=__UpperCAmelCase    ,      **__UpperCAmelCase    )





     def 							__UpperCAmelCase      ( self       :      List[Any]    ,      UpperCAmelCase__       :      np.ndarray    ,      UpperCAmelCase__       :      Dict[str, int]    ,      UpperCAmelCase__       :      Optional[Union[str, ChannelDimension]] = None    ,      **UpperCAmelCase__       :      Any    ,      )				->  np.ndarray:
        lowerCAmelCase     =			get_size_dict(__UpperCAmelCase    )
        if "height" not in size or "width" not in size:
           raise ValueError(F'''size must contain \'height\' and \'width\' as keys. Got {size.keys()}'''    )
        return center_crop(__UpperCAmelCase    ,      size=(size['height'], size['width'])    ,      data_format=__UpperCAmelCase    ,      **__UpperCAmelCase    )





     def 							__UpperCAmelCase      ( self       :      Union[str, Any]    ,      UpperCAmelCase__       :      np.ndarray    ,      UpperCAmelCase__       :      Union[int, float]    ,      UpperCAmelCase__       :      Optional[Union[str, ChannelDimension]] = None    ,      **UpperCAmelCase__       :      Tuple    ,      )				->  Tuple:
        return rescale(__UpperCAmelCase    ,      scale=__UpperCAmelCase    ,      data_format=__UpperCAmelCase    ,      **__UpperCAmelCase    )





     def 							__UpperCAmelCase      ( self       :      Optional[Any]    ,      UpperCAmelCase__       :      np.ndarray    ,      UpperCAmelCase__       :      Union[float, List[float]]    ,      UpperCAmelCase__       :      Union[float, List[float]]    ,      UpperCAmelCase__       :      Optional[Union[str, ChannelDimension]] = None    ,      **UpperCAmelCase__       :      Optional[int]    ,      )				->  np.ndarray:
        return normalize(__UpperCAmelCase    ,      mean=__UpperCAmelCase    ,      std=__UpperCAmelCase    ,      data_format=__UpperCAmelCase    ,      **__UpperCAmelCase    )





     def 							__UpperCAmelCase      ( self       :      Optional[int]    ,      UpperCAmelCase__       :      ImageInput    ,      UpperCAmelCase__       :      bool = None    ,      UpperCAmelCase__       :      Dict[str, int] = None    ,      UpperCAmelCase__       :      int = None    ,      UpperCAmelCase__       :      PILImageResampling = None    ,      UpperCAmelCase__       :      bool = None    ,      UpperCAmelCase__       :      Dict[str, int] = None    ,      UpperCAmelCase__       :      bool = None    ,      UpperCAmelCase__       :      float = None    ,      UpperCAmelCase__       :      bool = None    ,      UpperCAmelCase__       :      Optional[Union[float, List[float]]] = None    ,      UpperCAmelCase__       :      Optional[Union[float, List[float]]] = None    ,      UpperCAmelCase__       :      Optional[Union[str, TensorType]] = None    ,      UpperCAmelCase__       :      ChannelDimension = ChannelDimension.FIRST    ,      **UpperCAmelCase__       :      Tuple    ,      )				->  PIL.Image.Image:
        lowerCAmelCase     =			do_resize if do_resize is not None else self.do_resize
        lowerCAmelCase     =			crop_pct if crop_pct is not None else self.crop_pct
        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     =			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     =			size if size is not None else self.size
        lowerCAmelCase     =			get_size_dict(__UpperCAmelCase    ,      default_to_square=__UpperCAmelCase    )
        lowerCAmelCase     =			crop_size if crop_size is not None else self.crop_size
        lowerCAmelCase     =			get_size_dict(__UpperCAmelCase    ,      param_name='crop_size'    )

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

        if do_center_crop and crop_pct is None:
           raise ValueError('Crop_pct 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.
        lowerCAmelCase     =			[to_numpy_array(__UpperCAmelCase    ) for image in images]

        if do_resize:
           lowerCAmelCase     =			[self.resize(image=__UpperCAmelCase    ,      size=__UpperCAmelCase    ,      crop_pct=__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 ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCAmelCase__				   =		logging.get_logger(__name__)

UpperCAmelCase__				   =		{}






class 		lowercase_					(	lowercase   ):






      '''simple docstring'''




      __snake_case       =  '''llama'''
      __snake_case       =  ['''past_key_values''']







      def __init__(      self      :						Optional[Any] ,					__UpperCAmelCase      :						Union[str, Any]=32_000 ,					__UpperCAmelCase      :						str=4_096 ,					__UpperCAmelCase      :						int=11_008 ,					__UpperCAmelCase      :						Tuple=32 ,					__UpperCAmelCase      :						Optional[int]=32 ,					__UpperCAmelCase      :						List[str]=None ,					__UpperCAmelCase      :						Union[str, Any]="silu" ,					__UpperCAmelCase      :						Tuple=2_048 ,					__UpperCAmelCase      :						Optional[Any]=0.02 ,					__UpperCAmelCase      :						Any=1e-6 ,					__UpperCAmelCase      :						Union[str, Any]=True ,					__UpperCAmelCase      :						Optional[int]=0 ,					__UpperCAmelCase      :						Optional[int]=1 ,					__UpperCAmelCase      :						Optional[int]=2 ,					__UpperCAmelCase      :						Tuple=1 ,					__UpperCAmelCase      :						List[str]=False ,					__UpperCAmelCase      :						Tuple=None ,					**__UpperCAmelCase      :						Tuple ,					)    ->str:




       """simple docstring"""


       a		  =      vocab_size
       a		  =      max_position_embeddings
       a		  =      hidden_size
       a		  =      intermediate_size
       a		  =      num_hidden_layers
       a		  =      num_attention_heads

       # for backward compatibility
       if num_key_value_heads is None:
        a		  =      num_attention_heads

       a		  =      num_key_value_heads
       a		  =      hidden_act
       a		  =      initializer_range
       a		  =      rms_norm_eps
       a		  =      pretraining_tp
       a		  =      use_cache
       a		  =      rope_scaling
       self._rope_scaling_validation()

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







      def       __lowerCAmelCase					(      self      :						Tuple  )    ->Tuple:




       """simple docstring"""


       if self.rope_scaling is None:
        return

       if not isinstance(self.rope_scaling ,					__UpperCAmelCase  ) or len(self.rope_scaling  ) != 2:
        raise ValueError(
            '''`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, '''
            F"""got {self.rope_scaling}"""  )
       a		  =      self.rope_scaling.get('''type''' ,					__UpperCAmelCase  )
       a		  =      self.rope_scaling.get('''factor''' ,					__UpperCAmelCase  )
       if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
        raise ValueError(
            F"""`rope_scaling`'s name field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"""  )
       if rope_scaling_factor is None or not isinstance(__UpperCAmelCase ,					__UpperCAmelCase  ) or rope_scaling_factor <= 1.0:
        raise ValueError(F"""`rope_scaling`'s factor field must be an float > 1, got {rope_scaling_factor}"""  )


