


import unittest

from parameterized import parameterized

from transformers import OpenLlamaConfig, is_torch_available, set_seed
from transformers.testing_utils import require_torch, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import OpenLlamaForCausalLM, OpenLlamaForSequenceClassification, OpenLlamaModel



class 						_UpperCAmelCase      :






		def __init__(						self				:     List[Any]   ,  UpperCAmelCase				:     Tuple   ,  UpperCAmelCase				:     Union[str, Any]=13   ,  UpperCAmelCase				:     Optional[int]=7   ,  UpperCAmelCase				:     List[Any]=True   ,  UpperCAmelCase				:     List[Any]=True   ,  UpperCAmelCase				:     str=False   ,  UpperCAmelCase				:     int=True   ,  UpperCAmelCase				:     Any=99   ,  UpperCAmelCase				:     List[str]=32   ,  UpperCAmelCase				:     Tuple=5   ,  UpperCAmelCase				:     Optional[Any]=4   ,  UpperCAmelCase				:     List[str]=37   ,  UpperCAmelCase				:     List[Any]="gelu"   ,  UpperCAmelCase				:     Optional[Any]=0.1   ,  UpperCAmelCase				:     Dict=0.1   ,  UpperCAmelCase				:     Tuple=5_12   ,  UpperCAmelCase				:     Any=16   ,  UpperCAmelCase				:     List[Any]=2   ,  UpperCAmelCase				:     Optional[Any]=0.02   ,  UpperCAmelCase				:     Dict=3   ,  UpperCAmelCase				:     int=4   ,  UpperCAmelCase				:     Dict=None   ,  ):
				SCREAMING_SNAKE_CASE_				:Dict				     =						parent
				SCREAMING_SNAKE_CASE_				:Optional[Any]				     =						batch_size
				SCREAMING_SNAKE_CASE_				:Any				     =						seq_length
				SCREAMING_SNAKE_CASE_				:List[str]				     =						is_training
				SCREAMING_SNAKE_CASE_				:List[str]				     =						use_input_mask
				SCREAMING_SNAKE_CASE_				:Union[str, Any]				     =						use_token_type_ids
				SCREAMING_SNAKE_CASE_				:List[Any]				     =						use_labels
				SCREAMING_SNAKE_CASE_				:str				     =						vocab_size
				SCREAMING_SNAKE_CASE_				:Tuple				     =						hidden_size
				SCREAMING_SNAKE_CASE_				:List[str]				     =						num_hidden_layers
				SCREAMING_SNAKE_CASE_				:Dict				     =						num_attention_heads
				SCREAMING_SNAKE_CASE_				:Optional[int]				     =						intermediate_size
				SCREAMING_SNAKE_CASE_				:Any				     =						hidden_act
				SCREAMING_SNAKE_CASE_				:List[Any]				     =						hidden_dropout_prob
				SCREAMING_SNAKE_CASE_				:List[str]				     =						attention_probs_dropout_prob
				SCREAMING_SNAKE_CASE_				:Any				     =						max_position_embeddings
				SCREAMING_SNAKE_CASE_				:Optional[int]				     =						type_vocab_size
				SCREAMING_SNAKE_CASE_				:Dict				     =						type_sequence_label_size
				SCREAMING_SNAKE_CASE_				:Optional[int]				     =						initializer_range
				SCREAMING_SNAKE_CASE_				:Dict				     =						num_labels
				SCREAMING_SNAKE_CASE_				:Optional[int]				     =						num_choices
				SCREAMING_SNAKE_CASE_				:Any				     =						scope






		def _snake_case		(						self				:     str):
				SCREAMING_SNAKE_CASE_				:Optional[Any]				     =						ids_tensor([self.batch_size, self.seq_length]   ,  self.vocab_size)

				SCREAMING_SNAKE_CASE_				:Tuple				     =						None
				if self.use_input_mask:
						SCREAMING_SNAKE_CASE_				:List[str]				     =						random_attention_mask([self.batch_size, self.seq_length])

				SCREAMING_SNAKE_CASE_				:str				     =						None
				if self.use_token_type_ids:
						SCREAMING_SNAKE_CASE_				:Union[str, Any]				     =						ids_tensor([self.batch_size, self.seq_length]   ,  self.type_vocab_size)

				SCREAMING_SNAKE_CASE_				:List[str]				     =						None
				SCREAMING_SNAKE_CASE_				:str				     =						None
				SCREAMING_SNAKE_CASE_				:Any				     =						None
				if self.use_labels:
						SCREAMING_SNAKE_CASE_				:Tuple				     =						ids_tensor([self.batch_size]   ,  self.type_sequence_label_size)
						SCREAMING_SNAKE_CASE_				:int				     =						ids_tensor([self.batch_size, self.seq_length]   ,  self.num_labels)
						SCREAMING_SNAKE_CASE_				:Any				     =						ids_tensor([self.batch_size]   ,  self.num_choices)

				SCREAMING_SNAKE_CASE_				:List[str]				     =						self.get_config()

				return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels






		def _snake_case		(						self				:     Optional[Any]):
				return OpenLlamaConfig(
				    vocab_size=self.vocab_size   ,  hidden_size=self.hidden_size   ,  num_hidden_layers=self.num_hidden_layers   ,  num_attention_heads=self.num_attention_heads   ,  intermediate_size=self.intermediate_size   ,  hidden_act=self.hidden_act   ,  hidden_dropout_prob=self.hidden_dropout_prob   ,  attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,  max_position_embeddings=self.max_position_embeddings   ,  type_vocab_size=self.type_vocab_size   ,  is_decoder=UpperCAmelCase   ,  initializer_range=self.initializer_range   ,  use_stable_embedding=UpperCAmelCase   ,  )






		def _snake_case		(						self				:     Dict   ,  UpperCAmelCase				:     Dict   ,  UpperCAmelCase				:     Dict   ,  UpperCAmelCase				:     str   ,  UpperCAmelCase				:     Optional[int]   ,  UpperCAmelCase				:     str   ,  UpperCAmelCase				:     Tuple   ,  UpperCAmelCase				:     Optional[Any]):
				SCREAMING_SNAKE_CASE_				:str				     =						OpenLlamaModel(config=UpperCAmelCase)
				model.to(UpperCAmelCase)
				model.eval()
				SCREAMING_SNAKE_CASE_				:Any				     =						model(UpperCAmelCase   ,  attention_mask=UpperCAmelCase)
				SCREAMING_SNAKE_CASE_				:List[Any]				     =						model(UpperCAmelCase)
				self.parent.assertEqual(result.last_hidden_state.shape   ,  (self.batch_size, self.seq_length, self.hidden_size))






		def _snake_case		(						self				:     int   ,  UpperCAmelCase				:     Optional[Any]   ,  UpperCAmelCase				:     Dict   ,  UpperCAmelCase				:     List[str]   ,  UpperCAmelCase				:     List[str]   ,  UpperCAmelCase				:     Tuple   ,  UpperCAmelCase				:     Any   ,  UpperCAmelCase				:     Union[str, Any]   ,  UpperCAmelCase				:     str   ,  UpperCAmelCase				:     Union[str, Any]   ,  ):
				SCREAMING_SNAKE_CASE_				:Optional[Any]				     =						True
				SCREAMING_SNAKE_CASE_				:str				     =						OpenLlamaModel(UpperCAmelCase)
				model.to(UpperCAmelCase)
				model.eval()
				SCREAMING_SNAKE_CASE_				:Optional[int]				     =						model(
				    UpperCAmelCase   ,  attention_mask=UpperCAmelCase   ,  encoder_hidden_states=UpperCAmelCase   ,  encoder_attention_mask=UpperCAmelCase   ,  )
				SCREAMING_SNAKE_CASE_				:Optional[int]				     =						model(
				    UpperCAmelCase   ,  attention_mask=UpperCAmelCase   ,  encoder_hidden_states=UpperCAmelCase   ,  )
				SCREAMING_SNAKE_CASE_				:str				     =						model(UpperCAmelCase   ,  attention_mask=UpperCAmelCase)
				self.parent.assertEqual(result.last_hidden_state.shape   ,  (self.batch_size, self.seq_length, self.hidden_size))






		def _snake_case		(						self				:     Tuple   ,  UpperCAmelCase				:     Tuple   ,  UpperCAmelCase				:     Any   ,  UpperCAmelCase				:     Dict   ,  UpperCAmelCase				:     Optional[Any]   ,  UpperCAmelCase				:     List[Any]   ,  UpperCAmelCase				:     Union[str, Any]   ,  UpperCAmelCase				:     Tuple   ,  UpperCAmelCase				:     Union[str, Any]   ,  UpperCAmelCase				:     Union[str, Any]   ,  ):
				SCREAMING_SNAKE_CASE_				:Optional[int]				     =						OpenLlamaForCausalLM(config=UpperCAmelCase)
				model.to(UpperCAmelCase)
				model.eval()
				SCREAMING_SNAKE_CASE_				:Dict				     =						model(UpperCAmelCase   ,  attention_mask=UpperCAmelCase   ,  labels=UpperCAmelCase)
				self.parent.assertEqual(result.logits.shape   ,  (self.batch_size, self.seq_length, self.vocab_size))






		def _snake_case		(						self				:     Optional[int]   ,  UpperCAmelCase				:     int   ,  UpperCAmelCase				:     Any   ,  UpperCAmelCase				:     str   ,  UpperCAmelCase				:     Optional[Any]   ,  UpperCAmelCase				:     Tuple   ,  UpperCAmelCase				:     Optional[int]   ,  UpperCAmelCase				:     int   ,  UpperCAmelCase				:     str   ,  UpperCAmelCase				:     Optional[Any]   ,  ):
				SCREAMING_SNAKE_CASE_				:Any				     =						True
				SCREAMING_SNAKE_CASE_				:Optional[Any]				     =						True
				SCREAMING_SNAKE_CASE_				:Optional[Any]				     =						OpenLlamaForCausalLM(config=UpperCAmelCase)
				model.to(UpperCAmelCase)
				model.eval()

				# first forward pass
				SCREAMING_SNAKE_CASE_				:Any				     =						model(
				    UpperCAmelCase   ,  attention_mask=UpperCAmelCase   ,  encoder_hidden_states=UpperCAmelCase   ,  encoder_attention_mask=UpperCAmelCase   ,  use_cache=UpperCAmelCase   ,  )
				SCREAMING_SNAKE_CASE_				:Any				     =						outputs.past_key_values

				# create hypothetical multiple next token and extent to next_input_ids
				SCREAMING_SNAKE_CASE_				:List[str]				     =						ids_tensor((self.batch_size, 3)   ,  config.vocab_size)
				SCREAMING_SNAKE_CASE_				:Optional[int]				     =						ids_tensor((self.batch_size, 3)   ,  vocab_size=2)

				# append to next input_ids and
				SCREAMING_SNAKE_CASE_				:Dict				     =						torch.cat([input_ids, next_tokens]   ,  dim=-1)
				SCREAMING_SNAKE_CASE_				:int				     =						torch.cat([input_mask, next_mask]   ,  dim=-1)

				SCREAMING_SNAKE_CASE_				:Dict				     =						model(
				    UpperCAmelCase   ,  attention_mask=UpperCAmelCase   ,  encoder_hidden_states=UpperCAmelCase   ,  encoder_attention_mask=UpperCAmelCase   ,  output_hidden_states=UpperCAmelCase   ,  )["hidden_states"][0]
				SCREAMING_SNAKE_CASE_				:Dict				     =						model(
				    UpperCAmelCase   ,  attention_mask=UpperCAmelCase   ,  encoder_hidden_states=UpperCAmelCase   ,  encoder_attention_mask=UpperCAmelCase   ,  past_key_values=UpperCAmelCase   ,  output_hidden_states=UpperCAmelCase   ,  )["hidden_states"][0]

				# select random slice
				SCREAMING_SNAKE_CASE_				:List[str]				     =						ids_tensor((1,)   ,  output_from_past.shape[-1]).item()
				SCREAMING_SNAKE_CASE_				:int				     =						output_from_no_past[:, -3:, random_slice_idx].detach()
				SCREAMING_SNAKE_CASE_				:Dict				     =						output_from_past[:, :, random_slice_idx].detach()

				self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1])

				# test that outputs are equal for slice
				self.parent.assertTrue(torch.allclose(UpperCAmelCase   ,  UpperCAmelCase   ,  atol=1E-3))







		def _snake_case		(						self				:     List[Any]):
				SCREAMING_SNAKE_CASE_				:int				     =						self.prepare_config_and_inputs()
				(
				    (
				    SCREAMING_SNAKE_CASE_
				)     ,				(
				    SCREAMING_SNAKE_CASE_
				)     ,				(
				    SCREAMING_SNAKE_CASE_
				)     ,				(
				    SCREAMING_SNAKE_CASE_
				)     ,				(
				    SCREAMING_SNAKE_CASE_
				)     ,				(
				    SCREAMING_SNAKE_CASE_
				)     ,				(
				    SCREAMING_SNAKE_CASE_
				)     ,				
				)				:List[str]				     =						config_and_inputs
				SCREAMING_SNAKE_CASE_				:Optional[int]				     =						{"input_ids": input_ids, "attention_mask": input_mask}
				return config, inputs_dict




@require_torch
class 						_UpperCAmelCase      (     lowercase		,		lowercase		,		lowercase		,		unittest.TestCase							):
		lowerCamelCase_	:			int       			=  (
		    (OpenLlamaModel, OpenLlamaForCausalLM, OpenLlamaForSequenceClassification) if is_torch_available() else ()
		)
		lowerCamelCase_	:			str       			=  (OpenLlamaForCausalLM,) if is_torch_available() else ()
		lowerCamelCase_	:			int       			=  (
		    {
		        """feature-extraction""": OpenLlamaModel,
		        """text-classification""": OpenLlamaForSequenceClassification,
		        """text-generation""": OpenLlamaForCausalLM,
		        """zero-shot""": OpenLlamaForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)
		lowerCamelCase_	:			Dict       			=  False
		lowerCamelCase_	:			int       			=  False






		def _snake_case		(						self				:     Tuple):
				SCREAMING_SNAKE_CASE_				:Dict				     =						OpenLlamaModelTester(self)
				SCREAMING_SNAKE_CASE_				:int				     =						ConfigTester(self   ,  config_class=UpperCAmelCase   ,  hidden_size=37)






		def _snake_case		(						self				:     List[Any]):
				self.config_tester.run_common_tests()






		def _snake_case		(						self				:     Optional[int]):
				SCREAMING_SNAKE_CASE_				:str				     =						self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*UpperCAmelCase)






		def _snake_case		(						self				:     str):
				SCREAMING_SNAKE_CASE_				:Optional[Any]				     =						self.model_tester.prepare_config_and_inputs()
				for type in ["absolute", "relative_key", "relative_key_query"]:
						SCREAMING_SNAKE_CASE_				:Optional[int]				     =						type
						self.model_tester.create_and_check_model(*UpperCAmelCase)






		def _snake_case		(						self				:     str):
				SCREAMING_SNAKE_CASE_     ,				SCREAMING_SNAKE_CASE_				:Any				     =						self.model_tester.prepare_config_and_inputs_for_common()
				SCREAMING_SNAKE_CASE_				:str				     =						3
				SCREAMING_SNAKE_CASE_				:int				     =						input_dict["input_ids"]
				SCREAMING_SNAKE_CASE_				:List[Any]				     =						input_ids.ne(1).to(UpperCAmelCase)
				SCREAMING_SNAKE_CASE_				:Any				     =						ids_tensor([self.model_tester.batch_size]   ,  self.model_tester.type_sequence_label_size)
				SCREAMING_SNAKE_CASE_				:int				     =						OpenLlamaForSequenceClassification(UpperCAmelCase)
				model.to(UpperCAmelCase)
				model.eval()
				SCREAMING_SNAKE_CASE_				:Tuple				     =						model(UpperCAmelCase   ,  attention_mask=UpperCAmelCase   ,  labels=UpperCAmelCase)
				self.assertEqual(result.logits.shape   ,  (self.model_tester.batch_size, self.model_tester.num_labels))






		def _snake_case		(						self				:     Optional[Any]):
				SCREAMING_SNAKE_CASE_     ,				SCREAMING_SNAKE_CASE_				:Optional[int]				     =						self.model_tester.prepare_config_and_inputs_for_common()
				SCREAMING_SNAKE_CASE_				:Optional[int]				     =						3
				SCREAMING_SNAKE_CASE_				:List[str]				     =						"single_label_classification"
				SCREAMING_SNAKE_CASE_				:Dict				     =						input_dict["input_ids"]
				SCREAMING_SNAKE_CASE_				:Union[str, Any]				     =						input_ids.ne(1).to(UpperCAmelCase)
				SCREAMING_SNAKE_CASE_				:Dict				     =						ids_tensor([self.model_tester.batch_size]   ,  self.model_tester.type_sequence_label_size)
				SCREAMING_SNAKE_CASE_				:Any				     =						OpenLlamaForSequenceClassification(UpperCAmelCase)
				model.to(UpperCAmelCase)
				model.eval()
				SCREAMING_SNAKE_CASE_				:Tuple				     =						model(UpperCAmelCase   ,  attention_mask=UpperCAmelCase   ,  labels=UpperCAmelCase)
				self.assertEqual(result.logits.shape   ,  (self.model_tester.batch_size, self.model_tester.num_labels))






		def _snake_case		(						self				:     Tuple):
				SCREAMING_SNAKE_CASE_     ,				SCREAMING_SNAKE_CASE_				:Optional[int]				     =						self.model_tester.prepare_config_and_inputs_for_common()
				SCREAMING_SNAKE_CASE_				:Optional[Any]				     =						3
				SCREAMING_SNAKE_CASE_				:int				     =						"multi_label_classification"
				SCREAMING_SNAKE_CASE_				:Dict				     =						input_dict["input_ids"]
				SCREAMING_SNAKE_CASE_				:Tuple				     =						input_ids.ne(1).to(UpperCAmelCase)
				SCREAMING_SNAKE_CASE_				:List[Any]				     =						ids_tensor(
				    [self.model_tester.batch_size, config.num_labels]   ,  self.model_tester.type_sequence_label_size).to(torch.float)
				SCREAMING_SNAKE_CASE_				:Union[str, Any]				     =						OpenLlamaForSequenceClassification(UpperCAmelCase)
				model.to(UpperCAmelCase)
				model.eval()
				SCREAMING_SNAKE_CASE_				:str				     =						model(UpperCAmelCase   ,  attention_mask=UpperCAmelCase   ,  labels=UpperCAmelCase)
				self.assertEqual(result.logits.shape   ,  (self.model_tester.batch_size, self.model_tester.num_labels))






		@unittest.skip("Open-Llama buffers include complex numbers, which breaks this test")
		def _snake_case		(						self				:     Dict):
				pass







		@parameterized.expand([("linear",), ("dynamic",)])
		def _snake_case		(						self				:     Tuple   ,  UpperCAmelCase				:     int):
				SCREAMING_SNAKE_CASE_     ,				SCREAMING_SNAKE_CASE_				:int				     =						self.model_tester.prepare_config_and_inputs_for_common()
				SCREAMING_SNAKE_CASE_				:Tuple				     =						ids_tensor([1, 10]   ,  config.vocab_size)
				SCREAMING_SNAKE_CASE_				:Union[str, Any]				     =						ids_tensor([1, int(config.max_position_embeddings * 1.5)]   ,  config.vocab_size)

				set_seed(42)  # Fixed seed at init time so the two models get the same random weights
				SCREAMING_SNAKE_CASE_				:int				     =						OpenLlamaModel(UpperCAmelCase)
				original_model.to(UpperCAmelCase)
				original_model.eval()
				SCREAMING_SNAKE_CASE_				:Dict				     =						original_model(UpperCAmelCase).last_hidden_state
				SCREAMING_SNAKE_CASE_				:List[Any]				     =						original_model(UpperCAmelCase).last_hidden_state

				set_seed(42)  # Fixed seed at init time so the two models get the same random weights
				SCREAMING_SNAKE_CASE_				:Dict				     =						{"type": scaling_type, "factor": 10.0}
				SCREAMING_SNAKE_CASE_				:Optional[int]				     =						OpenLlamaModel(UpperCAmelCase)
				scaled_model.to(UpperCAmelCase)
				scaled_model.eval()
				SCREAMING_SNAKE_CASE_				:str				     =						scaled_model(UpperCAmelCase).last_hidden_state
				SCREAMING_SNAKE_CASE_				:List[str]				     =						scaled_model(UpperCAmelCase).last_hidden_state

				# Dynamic scaling does not change the RoPE embeddings until it receives an input longer than the original
				# maximum sequence length, so the outputs for the short input should match.
				if scaling_type == "dynamic":
						self.assertTrue(torch.allclose(UpperCAmelCase   ,  UpperCAmelCase   ,  atol=1E-5))
				else:
						self.assertFalse(torch.allclose(UpperCAmelCase   ,  UpperCAmelCase   ,  atol=1E-5))

				# The output should be different for long inputs
				self.assertFalse(torch.allclose(UpperCAmelCase   ,  UpperCAmelCase   ,  atol=1E-5))










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


SCREAMING_SNAKE_CASE__     					=			logging.get_logger(__name__)



class 						_UpperCAmelCase      (     lowercase							):
		lowerCamelCase_	:			Dict       			=  ["""pixel_values"""]






		def __init__(						self				:     Tuple   ,  UpperCAmelCase				:     bool = True   ,  UpperCAmelCase				:     Dict[str, int] = None   ,  UpperCAmelCase				:     PILImageResampling = PILImageResampling.BICUBIC   ,  UpperCAmelCase				:     bool = True   ,  UpperCAmelCase				:     Union[int, float] = 1 / 2_55   ,  UpperCAmelCase				:     bool = True   ,  UpperCAmelCase				:     Optional[Union[float, List[float]]] = None   ,  UpperCAmelCase				:     Optional[Union[float, List[float]]] = None   ,  UpperCAmelCase				:     bool = True   ,  **UpperCAmelCase				:     Any   ,  ):
				super().__init__(**UpperCAmelCase)
				SCREAMING_SNAKE_CASE_				:List[Any]				     =						size if size is not None else {"height": 3_84, "width": 3_84}
				SCREAMING_SNAKE_CASE_				:str				     =						get_size_dict(UpperCAmelCase   ,  default_to_square=UpperCAmelCase)

				SCREAMING_SNAKE_CASE_				:Optional[Any]				     =						do_resize
				SCREAMING_SNAKE_CASE_				:int				     =						size
				SCREAMING_SNAKE_CASE_				:int				     =						resample
				SCREAMING_SNAKE_CASE_				:Union[str, Any]				     =						do_rescale
				SCREAMING_SNAKE_CASE_				:Union[str, Any]				     =						rescale_factor
				SCREAMING_SNAKE_CASE_				:Union[str, Any]				     =						do_normalize
				SCREAMING_SNAKE_CASE_				:List[Any]				     =						image_mean if image_mean is not None else OPENAI_CLIP_MEAN
				SCREAMING_SNAKE_CASE_				:Dict				     =						image_std if image_std is not None else OPENAI_CLIP_STD
				SCREAMING_SNAKE_CASE_				:List[Any]				     =						do_convert_rgb






		def _snake_case		(						self				:     int   ,  UpperCAmelCase				:     np.ndarray   ,  UpperCAmelCase				:     Dict[str, int]   ,  UpperCAmelCase				:     PILImageResampling = PILImageResampling.BICUBIC   ,  UpperCAmelCase				:     Optional[Union[str, ChannelDimension]] = None   ,  **UpperCAmelCase				:     Any   ,  ):
				SCREAMING_SNAKE_CASE_				:Optional[int]				     =						get_size_dict(UpperCAmelCase   ,  default_to_square=UpperCAmelCase)
				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()}")
				SCREAMING_SNAKE_CASE_				:List[Any]				     =						(size["height"], size["width"])
				return resize(UpperCAmelCase   ,  size=UpperCAmelCase   ,  resample=UpperCAmelCase   ,  data_format=UpperCAmelCase   ,  **UpperCAmelCase)






		def _snake_case		(						self				:     Optional[Any]   ,  UpperCAmelCase				:     np.ndarray   ,  UpperCAmelCase				:     Union[int, float]   ,  UpperCAmelCase				:     Optional[Union[str, ChannelDimension]] = None   ,  **UpperCAmelCase				:     List[str]   ,  ):
				return rescale(UpperCAmelCase   ,  scale=UpperCAmelCase   ,  data_format=UpperCAmelCase   ,  **UpperCAmelCase)






		def _snake_case		(						self				:     Optional[Any]   ,  UpperCAmelCase				:     np.ndarray   ,  UpperCAmelCase				:     Union[float, List[float]]   ,  UpperCAmelCase				:     Union[float, List[float]]   ,  UpperCAmelCase				:     Optional[Union[str, ChannelDimension]] = None   ,  **UpperCAmelCase				:     Optional[Any]   ,  ):
				return normalize(UpperCAmelCase   ,  mean=UpperCAmelCase   ,  std=UpperCAmelCase   ,  data_format=UpperCAmelCase   ,  **UpperCAmelCase)







		def _snake_case		(						self				:     List[Any]   ,  UpperCAmelCase				:     ImageInput   ,  UpperCAmelCase				:     Optional[bool] = None   ,  UpperCAmelCase				:     Optional[Dict[str, int]] = None   ,  UpperCAmelCase				:     PILImageResampling = None   ,  UpperCAmelCase				:     Optional[bool] = None   ,  UpperCAmelCase				:     Optional[float] = None   ,  UpperCAmelCase				:     Optional[bool] = None   ,  UpperCAmelCase				:     Optional[Union[float, List[float]]] = None   ,  UpperCAmelCase				:     Optional[Union[float, List[float]]] = None   ,  UpperCAmelCase				:     Optional[Union[str, TensorType]] = None   ,  UpperCAmelCase				:     bool = None   ,  UpperCAmelCase				:     ChannelDimension = ChannelDimension.FIRST   ,  **UpperCAmelCase				:     Dict   ,  ):
				SCREAMING_SNAKE_CASE_				:Union[str, Any]				     =						do_resize if do_resize is not None else self.do_resize
				SCREAMING_SNAKE_CASE_				:Tuple				     =						resample if resample is not None else self.resample
				SCREAMING_SNAKE_CASE_				:List[Any]				     =						do_rescale if do_rescale is not None else self.do_rescale
				SCREAMING_SNAKE_CASE_				:Union[str, Any]				     =						rescale_factor if rescale_factor is not None else self.rescale_factor
				SCREAMING_SNAKE_CASE_				:Dict				     =						do_normalize if do_normalize is not None else self.do_normalize
				SCREAMING_SNAKE_CASE_				:List[str]				     =						image_mean if image_mean is not None else self.image_mean
				SCREAMING_SNAKE_CASE_				:Optional[int]				     =						image_std if image_std is not None else self.image_std
				SCREAMING_SNAKE_CASE_				:Tuple				     =						do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

				SCREAMING_SNAKE_CASE_				:Dict				     =						size if size is not None else self.size
				SCREAMING_SNAKE_CASE_				:Tuple				     =						get_size_dict(UpperCAmelCase   ,  default_to_square=UpperCAmelCase)

				SCREAMING_SNAKE_CASE_				:Tuple				     =						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_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:
						SCREAMING_SNAKE_CASE_				:Union[str, Any]				     =						[convert_to_rgb(UpperCAmelCase) for image in images]

				# All transformations expect numpy arrays.
				SCREAMING_SNAKE_CASE_				:List[str]				     =						[to_numpy_array(UpperCAmelCase) for image in images]

				if do_resize:
						SCREAMING_SNAKE_CASE_				:List[str]				     =						[self.resize(image=UpperCAmelCase   ,  size=UpperCAmelCase   ,  resample=UpperCAmelCase) for image in images]

				if do_rescale:
						SCREAMING_SNAKE_CASE_				:Union[str, Any]				     =						[self.rescale(image=UpperCAmelCase   ,  scale=UpperCAmelCase) for image in images]

				if do_normalize:
						SCREAMING_SNAKE_CASE_				:Union[str, Any]				     =						[self.normalize(image=UpperCAmelCase   ,  mean=UpperCAmelCase   ,  std=UpperCAmelCase) for image in images]

				SCREAMING_SNAKE_CASE_				:Optional[Any]				     =						[to_channel_dimension_format(UpperCAmelCase   ,  UpperCAmelCase) for image in images]

				SCREAMING_SNAKE_CASE_				:Optional[int]				     =						BatchFeature(data={"pixel_values": images}   ,  tensor_type=UpperCAmelCase)

				return encoded_outputs






