





'''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 rescale, resize, to_channel_dimension_format
from ...image_utils import (
    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


_SCREAMING_SNAKE_CASE   =      logging.get_logger(__name__)




def 				_lowerCAmelCase  (			lowerCamelCase_     :					Union[str, Any]						,    lowerCamelCase_     :					List[str]			):
			__lowercase			  =							b.T
			__lowercase			  =							np.sum(np.square(lowerCamelCase_			)						,    axis=1			)
			__lowercase			  =							np.sum(np.square(lowerCamelCase_			)						,    axis=0			)
			__lowercase			  =							np.matmul(lowerCamelCase_						,    lowerCamelCase_			)
			__lowercase			  =							aa[:, None] - 2 * ab + ba[None, :]
			return d




def 				_lowerCAmelCase  (			lowerCamelCase_     :					str						,    lowerCamelCase_     :					Dict			):
			__lowercase			  =							x.reshape(-1						,    3			)
			__lowercase			  =							squared_euclidean_distance(lowerCamelCase_						,    lowerCamelCase_			)
			return np.argmin(lowerCamelCase_						,    axis=1			)






class 							__lowercase    ( lowerCAmelCase__  ):







	'''simple docstring'''

	a      :			Tuple     =    ["pixel_values"]


	def __init__(self       ,_lowerCamelCase = None       ,_lowerCamelCase = True       ,_lowerCamelCase = None       ,_lowerCamelCase = PILImageResampling.BILINEAR       ,_lowerCamelCase = True       ,_lowerCamelCase = True       ,**_lowerCamelCase       ,)							->							None:







				'''simple docstring'''





				super().__init__(**_lowerCamelCase	)
				__lowercase			  =							size if size is not None else {'''height''': 256, '''width''': 256}
				__lowercase			  =							get_size_dict(_lowerCamelCase	)
				__lowercase			  =							np.array(_lowerCamelCase	) if clusters is not None else None
				__lowercase			  =							do_resize
				__lowercase			  =							size
				__lowercase			  =							resample
				__lowercase			  =							do_normalize
				__lowercase			  =							do_color_quantize


	def   _UpperCAmelCase       (self       ,_lowerCamelCase       ,_lowerCamelCase       ,_lowerCamelCase = PILImageResampling.BILINEAR       ,_lowerCamelCase = None       ,**_lowerCamelCase       ,)							->							np.ndarray:







				'''simple docstring'''





				__lowercase			  =							get_size_dict(_lowerCamelCase	)
				if "height" not in size or "width" not in size:
							raise ValueError(f"Size dictionary must contain both height and width keys. Got {size.keys()}"	)
				return resize(
				    _lowerCamelCase       ,size=(size['''height'''], size['''width'''])       ,resample=_lowerCamelCase       ,data_format=_lowerCamelCase       ,**_lowerCamelCase	)


	def   _UpperCAmelCase       (self       ,_lowerCamelCase       ,_lowerCamelCase = None       ,)							->							np.ndarray:







				'''simple docstring'''





				__lowercase			  =							rescale(image=_lowerCamelCase       ,scale=1 / 1_2_7.5       ,data_format=_lowerCamelCase	)
				__lowercase			  =							image - 1
				return image


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







				'''simple docstring'''





				__lowercase			  =							do_resize if do_resize is not None else self.do_resize
				__lowercase			  =							size if size is not None else self.size
				__lowercase			  =							get_size_dict(_lowerCamelCase	)
				__lowercase			  =							resample if resample is not None else self.resample
				__lowercase			  =							do_normalize if do_normalize is not None else self.do_normalize
				__lowercase			  =							do_color_quantize if do_color_quantize is not None else self.do_color_quantize
				__lowercase			  =							clusters if clusters is not None else self.clusters
				__lowercase			  =							np.array(_lowerCamelCase	)

				__lowercase			  =							make_list_of_images(_lowerCamelCase	)

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

				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_color_quantize and clusters is None:
							raise ValueError('''Clusters must be specified if do_color_quantize is True.'''	)

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

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

				if do_normalize:
							__lowercase			  =							[self.normalize(image=_lowerCamelCase	) for image in images]

				if do_color_quantize:
							__lowercase			  =							[to_channel_dimension_format(_lowerCamelCase       ,ChannelDimension.LAST	) for image in images]
							# color quantize from (batch_size, height, width, 3) to (batch_size, height, width)
							__lowercase			  =							np.array(_lowerCamelCase	)
							__lowercase			  =							color_quantize(_lowerCamelCase       ,_lowerCamelCase	).reshape(images.shape[:-1]	)

							# flatten to (batch_size, height*width)
							__lowercase			  =							images.shape[0]
							__lowercase			  =							images.reshape(_lowerCamelCase       ,-1	)

							# We need to convert back to a list of images to keep consistent behaviour across processors.
							__lowercase			  =							list(_lowerCamelCase	)
				else:
							__lowercase			  =							[to_channel_dimension_format(_lowerCamelCase       ,_lowerCamelCase	) for image in images]

				__lowercase			  =							{'''input_ids''': images}
				return BatchFeature(data=_lowerCamelCase       ,tensor_type=_lowerCamelCase	)












'''simple docstring'''



from ...configuration_utils import PretrainedConfig
from ...utils import logging


_SCREAMING_SNAKE_CASE   =      logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE   =      {
    '''s-JoL/Open-Llama-V1''': '''https://huggingface.co/s-JoL/Open-Llama-V1/blob/main/config.json''',
}






class 							__lowercase    ( lowerCAmelCase__  ):







	'''simple docstring'''

	a      :			Dict     =    "open-llama"


	def __init__(self       ,_lowerCamelCase=100000       ,_lowerCamelCase=4096       ,_lowerCamelCase=11008       ,_lowerCamelCase=32       ,_lowerCamelCase=32       ,_lowerCamelCase="silu"       ,_lowerCamelCase=2048       ,_lowerCamelCase=0.0_2       ,_lowerCamelCase=1E-6       ,_lowerCamelCase=True       ,_lowerCamelCase=0       ,_lowerCamelCase=1       ,_lowerCamelCase=2       ,_lowerCamelCase=False       ,_lowerCamelCase=True       ,_lowerCamelCase=0.1       ,_lowerCamelCase=0.1       ,_lowerCamelCase=True       ,_lowerCamelCase=True       ,_lowerCamelCase=None       ,**_lowerCamelCase       ,)							->							Union[str, Any]:







				'''simple docstring'''





				__lowercase			  =							vocab_size
				__lowercase			  =							max_position_embeddings
				__lowercase			  =							hidden_size
				__lowercase			  =							intermediate_size
				__lowercase			  =							num_hidden_layers
				__lowercase			  =							num_attention_heads
				__lowercase			  =							hidden_act
				__lowercase			  =							initializer_range
				__lowercase			  =							rms_norm_eps
				__lowercase			  =							use_cache
				__lowercase			  =							kwargs.pop(
				    '''use_memorry_efficient_attention'''       ,_lowerCamelCase	)
				__lowercase			  =							hidden_dropout_prob
				__lowercase			  =							attention_dropout_prob
				__lowercase			  =							use_stable_embedding
				__lowercase			  =							shared_input_output_embedding
				__lowercase			  =							rope_scaling
				self._rope_scaling_validation()

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


	def   _UpperCAmelCase       (self	)							->							List[Any]:







				'''simple docstring'''





				if self.rope_scaling is None:
							return

				if not isinstance(self.rope_scaling       ,_lowerCamelCase	) 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}"	)
				__lowercase			  =							self.rope_scaling.get('''type'''       ,_lowerCamelCase	)
				__lowercase			  =							self.rope_scaling.get('''factor'''       ,_lowerCamelCase	)
				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(_lowerCamelCase       ,_lowerCamelCase	) or rope_scaling_factor <= 1.0:
							raise ValueError(f"`rope_scaling`'s factor field must be an float > 1, got {rope_scaling_factor}"	)





