import unittest

from parameterized import parameterized

from transformers import AutoTokenizer, GPTNeoXConfig, is_torch_available, set_seed
from transformers.testing_utils import require_torch, slow, 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 (
				    GPTNeoXForCausalLM,
				    GPTNeoXForQuestionAnswering,
				    GPTNeoXForSequenceClassification,
				    GPTNeoXForTokenClassification,
				    GPTNeoXModel,
				)





class     lowerCAmelCase__     :


		'''simple docstring'''






		def __init__(       self     :     Optional[Any]     ,  snake_case__     :     Optional[int]     ,  snake_case__     :     int=1_3     ,  snake_case__     :     Dict=7     ,  snake_case__     :     Optional[int]=True     ,  snake_case__     :     int=True     ,  snake_case__     :     int=True     ,  snake_case__     :     Union[str, Any]=True     ,  snake_case__     :     str=9_9     ,  snake_case__     :     Dict=6_4     ,  snake_case__     :     Optional[int]=5     ,  snake_case__     :     Dict=4     ,  snake_case__     :     List[Any]=3_7     ,  snake_case__     :     Dict="gelu"     ,  snake_case__     :     Union[str, Any]=0.1     ,  snake_case__     :     int=0.1     ,  snake_case__     :     List[str]=5_1_2     ,  snake_case__     :     str=1_6     ,  snake_case__     :     int=2     ,  snake_case__     :     Dict=0.02     ,  snake_case__     :     List[str]=3     ,  snake_case__     :     int=4     ,  snake_case__     :     Optional[Any]=None     ,  )      ->	str:
				_lowerCamelCase				   =  parent
				_lowerCamelCase				   =  batch_size
				_lowerCamelCase				   =  seq_length
				_lowerCamelCase				   =  is_training
				_lowerCamelCase				   =  use_input_mask
				_lowerCamelCase				   =  use_token_type_ids
				_lowerCamelCase				   =  use_labels
				_lowerCamelCase				   =  vocab_size
				_lowerCamelCase				   =  hidden_size
				_lowerCamelCase				   =  num_hidden_layers
				_lowerCamelCase				   =  num_attention_heads
				_lowerCamelCase				   =  intermediate_size
				_lowerCamelCase				   =  hidden_act
				_lowerCamelCase				   =  hidden_dropout_prob
				_lowerCamelCase				   =  attention_probs_dropout_prob
				_lowerCamelCase				   =  max_position_embeddings
				_lowerCamelCase				   =  type_vocab_size
				_lowerCamelCase				   =  type_sequence_label_size
				_lowerCamelCase				   =  initializer_range
				_lowerCamelCase				   =  num_labels
				_lowerCamelCase				   =  num_choices
				_lowerCamelCase				   =  scope
				_lowerCamelCase				   =  vocab_size - 1
		def   _snake_case       (       self     :     Optional[int]		)      ->	Any:
				_lowerCamelCase				   =  ids_tensor([self.batch_size, self.seq_length]     ,  self.vocab_size		)

				_lowerCamelCase				   =  None
				if self.use_input_mask:
						_lowerCamelCase				   =  random_attention_mask([self.batch_size, self.seq_length]		)

				_lowerCamelCase				   =  None
				if self.use_labels:
						_lowerCamelCase				   =  ids_tensor([self.batch_size, self.seq_length]     ,  self.num_labels		)

				_lowerCamelCase				   =  self.get_config()

				return config, input_ids, input_mask, token_labels
		def   _snake_case       (       self     :     str		)      ->	Any:
				return GPTNeoXConfig(
				    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=snake_case__     ,  initializer_range=self.initializer_range     ,  pad_token_id=self.pad_token_id     ,  )
		def   _snake_case       (       self     :     List[Any]		)      ->	Tuple:
				_lowerCamelCase   ,							_lowerCamelCase   ,							_lowerCamelCase   ,							_lowerCamelCase				   =  self.prepare_config_and_inputs()

				_lowerCamelCase				   =  True

				return config, input_ids, input_mask, token_labels
		def   _snake_case       (       self     :     List[str]     ,  snake_case__     :     str     ,  snake_case__     :     int     ,  snake_case__     :     Dict		)      ->	List[Any]:
				_lowerCamelCase				   =  GPTNeoXModel(config=snake_case__		)
				model.to(snake_case__		)
				model.eval()
				_lowerCamelCase				   =  model(snake_case__     ,  attention_mask=snake_case__		)
				_lowerCamelCase				   =  model(snake_case__		)
				self.parent.assertEqual(result.last_hidden_state.shape     ,  (self.batch_size, self.seq_length, self.hidden_size)		)
		def   _snake_case       (       self     :     int     ,  snake_case__     :     Optional[Any]     ,  snake_case__     :     Dict     ,  snake_case__     :     Tuple		)      ->	int:
				_lowerCamelCase				   =  True
				_lowerCamelCase				   =  GPTNeoXModel(snake_case__		)
				model.to(snake_case__		)
				model.eval()
				_lowerCamelCase				   =  model(snake_case__     ,  attention_mask=snake_case__		)
				self.parent.assertEqual(result.last_hidden_state.shape     ,  (self.batch_size, self.seq_length, self.hidden_size)		)
		def   _snake_case       (       self     :     Tuple     ,  snake_case__     :     Optional[int]     ,  snake_case__     :     Union[str, Any]     ,  snake_case__     :     Union[str, Any]     ,  snake_case__     :     Tuple		)      ->	int:
				_lowerCamelCase				   =  GPTNeoXForCausalLM(config=snake_case__		)
				model.to(snake_case__		)
				model.eval()
				_lowerCamelCase				   =  model(snake_case__     ,  attention_mask=snake_case__     ,  labels=snake_case__		)
				self.parent.assertEqual(result.logits.shape     ,  (self.batch_size, self.seq_length, self.vocab_size)		)
		def   _snake_case       (       self     :     int     ,  snake_case__     :     Any     ,  snake_case__     :     Optional[Any]     ,  snake_case__     :     Optional[int]     ,  snake_case__     :     List[Any]		)      ->	List[str]:
				_lowerCamelCase				   =  self.num_labels
				_lowerCamelCase				   =  GPTNeoXForQuestionAnswering(snake_case__		)
				model.to(snake_case__		)
				model.eval()
				_lowerCamelCase				   =  model(snake_case__     ,  attention_mask=snake_case__		)
				self.parent.assertEqual(result.start_logits.shape     ,  (self.batch_size, self.seq_length)		)
				self.parent.assertEqual(result.end_logits.shape     ,  (self.batch_size, self.seq_length)		)
		def   _snake_case       (       self     :     Dict     ,  snake_case__     :     int     ,  snake_case__     :     Any     ,  snake_case__     :     Optional[int]     ,  snake_case__     :     Optional[Any]		)      ->	Any:
				_lowerCamelCase				   =  self.num_labels
				_lowerCamelCase				   =  GPTNeoXForSequenceClassification(snake_case__		)
				model.to(snake_case__		)
				model.eval()
				_lowerCamelCase				   =  ids_tensor([self.batch_size]     ,  self.type_sequence_label_size		)
				_lowerCamelCase				   =  model(snake_case__     ,  attention_mask=snake_case__     ,  labels=snake_case__		)
				self.parent.assertEqual(result.logits.shape     ,  (self.batch_size, self.num_labels)		)
		def   _snake_case       (       self     :     List[Any]     ,  snake_case__     :     List[Any]     ,  snake_case__     :     Union[str, Any]     ,  snake_case__     :     Optional[Any]     ,  snake_case__     :     Tuple		)      ->	List[str]:
				_lowerCamelCase				   =  self.num_labels
				_lowerCamelCase				   =  GPTNeoXForTokenClassification(snake_case__		)
				model.to(snake_case__		)
				model.eval()
				_lowerCamelCase				   =  model(snake_case__     ,  attention_mask=snake_case__     ,  labels=snake_case__		)
				self.parent.assertEqual(result.logits.shape     ,  (self.batch_size, self.seq_length, self.num_labels)		)
		def   _snake_case       (       self     :     Union[str, Any]     ,  snake_case__     :     Tuple     ,  snake_case__     :     Union[str, Any]     ,  snake_case__     :     Optional[int]		)      ->	Any:
				_lowerCamelCase				   =  True
				_lowerCamelCase				   =  GPTNeoXForCausalLM(config=snake_case__		)
				model.to(snake_case__		)
				model.eval()

				# first forward pass
				_lowerCamelCase				   =  model(snake_case__     ,  attention_mask=snake_case__     ,  use_cache=snake_case__		)
				_lowerCamelCase				   =  outputs.past_key_values

				# create hypothetical multiple next token and extent to next_input_ids
				_lowerCamelCase				   =  ids_tensor((self.batch_size, 3)     ,  config.vocab_size		)
				_lowerCamelCase				   =  ids_tensor((self.batch_size, 3)     ,  vocab_size=2		)

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

				_lowerCamelCase				   =  model(snake_case__     ,  attention_mask=snake_case__     ,  output_hidden_states=snake_case__		)
				_lowerCamelCase				   =  output_from_no_past['hidden_states'][0]
				_lowerCamelCase				   =  model(
				    snake_case__     ,  attention_mask=snake_case__     ,  past_key_values=snake_case__     ,  output_hidden_states=snake_case__     ,  )['hidden_states'][0]

				# select random slice
				_lowerCamelCase				   =  ids_tensor((1,)     ,  output_from_past.shape[-1]		).item()
				_lowerCamelCase				   =  output_from_no_past[:, -3:, random_slice_idx].detach()
				_lowerCamelCase				   =  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(snake_case__     ,  snake_case__     ,  atol=1e-3		)		)



		def   _snake_case       (       self     :     List[str]		)      ->	Union[str, Any]:
				_lowerCamelCase				   =  self.prepare_config_and_inputs()
				_lowerCamelCase   ,							_lowerCamelCase   ,							_lowerCamelCase   ,							_lowerCamelCase				   =  config_and_inputs
				_lowerCamelCase				   =  {'input_ids': input_ids, 'attention_mask': input_mask}
				return config, inputs_dict





@require_torch
class     lowerCAmelCase__     (				SCREAMING_SNAKE_CASE_     ,SCREAMING_SNAKE_CASE_     ,SCREAMING_SNAKE_CASE_     ,unittest.TestCase			):


		'''simple docstring'''






		lowerCAmelCase_     =   (
		    (
		        GPTNeoXModel,
		        GPTNeoXForCausalLM,
		        GPTNeoXForQuestionAnswering,
		        GPTNeoXForSequenceClassification,
		        GPTNeoXForTokenClassification,
		    )
		    if is_torch_available()
		    else ()
		)
		lowerCAmelCase_     =   (GPTNeoXForCausalLM,) if is_torch_available() else ()
		lowerCAmelCase_     =   (
		    {
		        'feature-extraction': GPTNeoXModel,
		        'question-answering': GPTNeoXForQuestionAnswering,
		        'text-classification': GPTNeoXForSequenceClassification,
		        'text-generation': GPTNeoXForCausalLM,
		        'token-classification': GPTNeoXForTokenClassification,
		        'zero-shot': GPTNeoXForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)
		lowerCAmelCase_     =   False
		lowerCAmelCase_     =   False
		lowerCAmelCase_     =   False
		lowerCAmelCase_     =   False
		def   _snake_case       (       self     :     Optional[Any]		)      ->	str:
				_lowerCamelCase				   =  GPTNeoXModelTester(self		)
				_lowerCamelCase				   =  ConfigTester(self     ,  config_class=snake_case__     ,  hidden_size=6_4     ,  num_attention_heads=8		)
		def   _snake_case       (       self     :     List[str]		)      ->	List[Any]:
				self.config_tester.run_common_tests()
		def   _snake_case       (       self     :     int		)      ->	Optional[Any]:
				_lowerCamelCase   ,							_lowerCamelCase   ,							_lowerCamelCase   ,							_lowerCamelCase				   =  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(snake_case__     ,  snake_case__     ,  snake_case__		)
		def   _snake_case       (       self     :     int		)      ->	Optional[int]:
				_lowerCamelCase   ,							_lowerCamelCase   ,							_lowerCamelCase   ,							_lowerCamelCase				   =  self.model_tester.prepare_config_and_inputs_for_decoder()
				self.model_tester.create_and_check_model_as_decoder(snake_case__     ,  snake_case__     ,  snake_case__		)
		def   _snake_case       (       self     :     str		)      ->	Union[str, Any]:
				# This regression test was failing with PyTorch < 1.3
				_lowerCamelCase   ,							_lowerCamelCase   ,							_lowerCamelCase   ,							_lowerCamelCase				   =  self.model_tester.prepare_config_and_inputs_for_decoder()

				_lowerCamelCase				   =  None

				self.model_tester.create_and_check_model_as_decoder(snake_case__     ,  snake_case__     ,  snake_case__		)
		def   _snake_case       (       self     :     Optional[Any]		)      ->	Any:
				_lowerCamelCase   ,							_lowerCamelCase   ,							_lowerCamelCase   ,							_lowerCamelCase				   =  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_decoder_model_past_large_inputs(snake_case__     ,  snake_case__     ,  snake_case__		)
		def   _snake_case       (       self     :     str		)      ->	int:
				_lowerCamelCase				   =  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_causal_lm(*snake_case__		)
		def   _snake_case       (       self     :     Optional[Any]		)      ->	int:
				_lowerCamelCase				   =  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_question_answering(*snake_case__		)
		def   _snake_case       (       self     :     Optional[Any]		)      ->	List[str]:
				_lowerCamelCase				   =  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_sequence_classification(*snake_case__		)
		def   _snake_case       (       self     :     int		)      ->	Dict:
				_lowerCamelCase				   =  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_token_classification(*snake_case__		)
		@unittest.skip(reason='Feed forward chunking is not implemented'		)
		def   _snake_case       (       self     :     List[str]		)      ->	List[str]:
				pass



		@parameterized.expand([('linear',), ('dynamic',)]		)
		def   _snake_case       (       self     :     List[Any]     ,  snake_case__     :     int		)      ->	Optional[int]:
				_lowerCamelCase   ,							_lowerCamelCase				   =  self.model_tester.prepare_config_and_inputs_for_common()
				_lowerCamelCase				   =  ids_tensor([1, 1_0]     ,  config.vocab_size		)
				_lowerCamelCase				   =  ids_tensor([1, int(config.max_position_embeddings * 1.5		)]     ,  config.vocab_size		)

				set_seed(4_2		)  # Fixed seed at init time so the two models get the same random weights
				_lowerCamelCase				   =  GPTNeoXModel(snake_case__		)
				original_model.to(snake_case__		)
				original_model.eval()
				_lowerCamelCase				   =  original_model(snake_case__		).last_hidden_state
				_lowerCamelCase				   =  original_model(snake_case__		).last_hidden_state

				set_seed(4_2		)  # Fixed seed at init time so the two models get the same random weights
				_lowerCamelCase				   =  {'type': scaling_type, 'factor': 10.0}
				_lowerCamelCase				   =  GPTNeoXModel(snake_case__		)
				scaled_model.to(snake_case__		)
				scaled_model.eval()
				_lowerCamelCase				   =  scaled_model(snake_case__		).last_hidden_state
				_lowerCamelCase				   =  scaled_model(snake_case__		).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(snake_case__     ,  snake_case__     ,  atol=1e-5		)		)
				else:
						self.assertFalse(torch.allclose(snake_case__     ,  snake_case__     ,  atol=1e-5		)		)

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





@require_torch
class     lowerCAmelCase__     (				unittest.TestCase			):


		'''simple docstring'''






		@slow
		def   _snake_case       (       self     :     int		)      ->	Optional[int]:
				_lowerCamelCase				   =  AutoTokenizer.from_pretrained('EleutherAI/pythia-410m-deduped'		)
				for checkpointing in [True, False]:
						_lowerCamelCase				   =  GPTNeoXForCausalLM.from_pretrained('EleutherAI/pythia-410m-deduped'		)

						if checkpointing:
								model.gradient_checkpointing_enable()
						else:
								model.gradient_checkpointing_disable()
						model.to(snake_case__		)

						_lowerCamelCase				   =  tokenizer('My favorite food is'     ,  return_tensors='pt'		).to(snake_case__		)
						# The hub repo. is updated on 2023-04-04, resulting in poor outputs.
						# See: https://github.com/huggingface/transformers/pull/24193
						_lowerCamelCase				   =  'My favorite food is a good old-fashioned, old-fashioned, old-fashioned.\n\nI\'m not sure'

						_lowerCamelCase				   =  model.generate(**snake_case__     ,  do_sample=snake_case__     ,  max_new_tokens=2_0		)
						_lowerCamelCase				   =  tokenizer.batch_decode(snake_case__		)[0]

						self.assertEqual(snake_case__     ,  snake_case__		)
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


A						=			logging.get_logger(__name__)





class     lowerCAmelCase__     (				SCREAMING_SNAKE_CASE_			):


		'''simple docstring'''






		lowerCAmelCase_     =   ['pixel_values']
		def __init__(       self     :     List[str]     ,  snake_case__     :     bool = True     ,  snake_case__     :     Dict[str, int] = None     ,  snake_case__     :     PILImageResampling = PILImageResampling.BICUBIC     ,  snake_case__     :     bool = True     ,  snake_case__     :     Union[int, float] = 1 / 2_5_5     ,  snake_case__     :     bool = True     ,  snake_case__     :     Optional[Union[float, List[float]]] = None     ,  snake_case__     :     Optional[Union[float, List[float]]] = None     ,  snake_case__     :     bool = True     ,  **snake_case__     :     List[Any]     ,  )      ->	None:
				super().__init__(**snake_case__		)
				_lowerCamelCase				   =  size if size is not None else {'height': 3_8_4, 'width': 3_8_4}
				_lowerCamelCase				   =  get_size_dict(snake_case__     ,  default_to_square=snake_case__		)

				_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     :     Union[str, Any]     ,  snake_case__     :     np.ndarray     ,  snake_case__     :     Dict[str, int]     ,  snake_case__     :     PILImageResampling = PILImageResampling.BICUBIC     ,  snake_case__     :     Optional[Union[str, ChannelDimension]] = None     ,  **snake_case__     :     Dict     ,  )      ->	np.ndarray:
				_lowerCamelCase				   =  get_size_dict(snake_case__     ,  default_to_square=snake_case__		)
				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(snake_case__     ,  size=snake_case__     ,  resample=snake_case__     ,  data_format=snake_case__     ,  **snake_case__		)
		def   _snake_case       (       self     :     Dict     ,  snake_case__     :     np.ndarray     ,  snake_case__     :     Union[int, float]     ,  snake_case__     :     Optional[Union[str, ChannelDimension]] = None     ,  **snake_case__     :     Optional[int]     ,  )      ->	int:
				return rescale(snake_case__     ,  scale=snake_case__     ,  data_format=snake_case__     ,  **snake_case__		)
		def   _snake_case       (       self     :     Optional[Any]     ,  snake_case__     :     np.ndarray     ,  snake_case__     :     Union[float, List[float]]     ,  snake_case__     :     Union[float, List[float]]     ,  snake_case__     :     Optional[Union[str, ChannelDimension]] = None     ,  **snake_case__     :     Optional[int]     ,  )      ->	np.ndarray:
				return normalize(snake_case__     ,  mean=snake_case__     ,  std=snake_case__     ,  data_format=snake_case__     ,  **snake_case__		)



		def   _snake_case       (       self     :     List[str]     ,  snake_case__     :     ImageInput     ,  snake_case__     :     Optional[bool] = None     ,  snake_case__     :     Optional[Dict[str, int]] = None     ,  snake_case__     :     PILImageResampling = None     ,  snake_case__     :     Optional[bool] = None     ,  snake_case__     :     Optional[float] = None     ,  snake_case__     :     Optional[bool] = None     ,  snake_case__     :     Optional[Union[float, List[float]]] = None     ,  snake_case__     :     Optional[Union[float, List[float]]] = None     ,  snake_case__     :     Optional[Union[str, TensorType]] = None     ,  snake_case__     :     bool = None     ,  snake_case__     :     ChannelDimension = ChannelDimension.FIRST     ,  **snake_case__     :     str     ,  )      ->	PIL.Image.Image:
				_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(snake_case__     ,  default_to_square=snake_case__		)

				_lowerCamelCase				   =  make_list_of_images(snake_case__		)

				if not valid_images(snake_case__		):
						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(snake_case__		) for image in images]

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

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

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

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

				_lowerCamelCase				   =  [to_channel_dimension_format(snake_case__     ,  snake_case__		) for image in images]

				_lowerCamelCase				   =  BatchFeature(data={'pixel_values': images}     ,  tensor_type=snake_case__		)

				return encoded_outputs