





'''simple docstring'''







import unittest

from transformers import ElectraConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import (
					    MODEL_FOR_PRETRAINING_MAPPING,
					    ElectraForCausalLM,
					    ElectraForMaskedLM,
					    ElectraForMultipleChoice,
					    ElectraForPreTraining,
					    ElectraForQuestionAnswering,
					    ElectraForSequenceClassification,
					    ElectraForTokenClassification,
					    ElectraModel,
					)
					from transformers.models.electra.modeling_electra import ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST


class    __a :

							def __init__(							self							:       List[Any]    ,       __magic_name__							:       Tuple    ,       __magic_name__							:       Optional[Any]=13    ,       __magic_name__							:       List[str]=7    ,       __magic_name__							:       int=True    ,       __magic_name__							:       List[str]=True    ,       __magic_name__							:       Tuple=True    ,       __magic_name__							:       Dict=True    ,       __magic_name__							:       int=99    ,       __magic_name__							:       List[str]=32    ,       __magic_name__							:       str=5    ,       __magic_name__							:       Tuple=4    ,       __magic_name__							:       str=37    ,       __magic_name__							:       List[str]="gelu"    ,       __magic_name__							:       Optional[int]=0.1    ,       __magic_name__							:       Optional[int]=0.1    ,       __magic_name__							:       Dict=5_12    ,       __magic_name__							:       Any=16    ,       __magic_name__							:       Tuple=2    ,       __magic_name__							:       List[Any]=0.0_2    ,       __magic_name__							:       Any=3    ,       __magic_name__							:       Optional[Any]=4    ,       __magic_name__							:       List[str]=None    ,       )   ->    List[str]:







													"""simple docstring"""
													UpperCAmelCase_     : str         =					parent
													UpperCAmelCase_     : Optional[Any]         =					batch_size
													UpperCAmelCase_     : List[Any]         =					seq_length
													UpperCAmelCase_     : List[Any]         =					is_training
													UpperCAmelCase_     : List[str]         =					use_input_mask
													UpperCAmelCase_     : List[Any]         =					use_token_type_ids
													UpperCAmelCase_     : Any         =					use_labels
													UpperCAmelCase_     : Tuple         =					vocab_size
													UpperCAmelCase_     : List[str]         =					hidden_size
													UpperCAmelCase_     : List[Any]         =					num_hidden_layers
													UpperCAmelCase_     : List[str]         =					num_attention_heads
													UpperCAmelCase_     : List[str]         =					intermediate_size
													UpperCAmelCase_     : str         =					hidden_act
													UpperCAmelCase_     : List[str]         =					hidden_dropout_prob
													UpperCAmelCase_     : Dict         =					attention_probs_dropout_prob
													UpperCAmelCase_     : Dict         =					max_position_embeddings
													UpperCAmelCase_     : Optional[Any]         =					type_vocab_size
													UpperCAmelCase_     : List[str]         =					type_sequence_label_size
													UpperCAmelCase_     : Union[str, Any]         =					initializer_range
													UpperCAmelCase_     : Optional[Any]         =					num_labels
													UpperCAmelCase_     : Union[str, Any]         =					num_choices
													UpperCAmelCase_     : List[Any]         =					scope

							def       UpperCAmelCase__		(							self							:       Tuple				)   ->    str:







													"""simple docstring"""
													UpperCAmelCase_     : Union[str, Any]         =					ids_tensor([self.batch_size, self.seq_length]    ,       self.vocab_size				)

													UpperCAmelCase_     : Dict         =					None
													if self.use_input_mask:
																			UpperCAmelCase_     : Any         =					random_attention_mask([self.batch_size, self.seq_length]				)

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

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

													UpperCAmelCase_     : List[Any]         =					self.get_config()

													return (
													    config,
													    input_ids,
													    token_type_ids,
													    input_mask,
													    sequence_labels,
													    token_labels,
													    choice_labels,
													    fake_token_labels,
													)

							def       UpperCAmelCase__		(							self							:       List[Any]				)   ->    Tuple:







													"""simple docstring"""
													return ElectraConfig(
													    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    ,       )

							def       UpperCAmelCase__		(							self							:       Optional[int]				)   ->    int:







													"""simple docstring"""
													(
													    (
													    UpperCAmelCase_   
													)  ,    (
													    UpperCAmelCase_   
													)  ,    (
													    UpperCAmelCase_   
													)  ,    (
													    UpperCAmelCase_   
													)  ,    (
													    UpperCAmelCase_   
													)  ,    (
													    UpperCAmelCase_   
													)  ,    (
													    UpperCAmelCase_   
													)  ,    (
													    UpperCAmelCase_   
													)  ,       
													)     : Union[str, Any]         =					self.prepare_config_and_inputs()

													UpperCAmelCase_     : Union[str, Any]         =					True
													UpperCAmelCase_     : List[Any]         =					floats_tensor([self.batch_size, self.seq_length, self.hidden_size]				)
													UpperCAmelCase_     : Optional[int]         =					ids_tensor([self.batch_size, self.seq_length]    ,       vocab_size=2				)

													return (
													    config,
													    input_ids,
													    token_type_ids,
													    input_mask,
													    sequence_labels,
													    token_labels,
													    choice_labels,
													    encoder_hidden_states,
													    encoder_attention_mask,
													)

							def       UpperCAmelCase__		(							self							:       Optional[int]    ,       __magic_name__							:       List[Any]    ,       __magic_name__							:       List[str]    ,       __magic_name__							:       Tuple    ,       __magic_name__							:       Tuple    ,       __magic_name__							:       Tuple    ,       __magic_name__							:       Optional[int]    ,       __magic_name__							:       Optional[Any]    ,       __magic_name__							:       str    ,       )   ->    Tuple:







													"""simple docstring"""
													UpperCAmelCase_     : List[str]         =					ElectraModel(config=UpperCamelCase__				)
													model.to(UpperCamelCase__				)
													model.eval()
													UpperCAmelCase_     : Optional[int]         =					model(UpperCamelCase__    ,       attention_mask=UpperCamelCase__    ,       token_type_ids=UpperCamelCase__				)
													UpperCAmelCase_     : Any         =					model(UpperCamelCase__    ,       token_type_ids=UpperCamelCase__				)
													UpperCAmelCase_     : Any         =					model(UpperCamelCase__				)
													self.parent.assertEqual(result.last_hidden_state.shape    ,       (self.batch_size, self.seq_length, self.hidden_size)				)

							def       UpperCAmelCase__		(							self							:       Dict    ,       __magic_name__							:       Dict    ,       __magic_name__							:       int    ,       __magic_name__							:       Tuple    ,       __magic_name__							:       List[str]    ,       __magic_name__							:       Optional[int]    ,       __magic_name__							:       Tuple    ,       __magic_name__							:       Any    ,       __magic_name__							:       Any    ,       __magic_name__							:       int    ,       )   ->    Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_     : Union[str, Any]         =					True
													UpperCAmelCase_     : List[str]         =					ElectraModel(UpperCamelCase__				)
													model.to(UpperCamelCase__				)
													model.eval()
													UpperCAmelCase_     : Optional[Any]         =					model(
													    UpperCamelCase__    ,       attention_mask=UpperCamelCase__    ,       token_type_ids=UpperCamelCase__    ,       encoder_hidden_states=UpperCamelCase__    ,       encoder_attention_mask=UpperCamelCase__    ,       )
													UpperCAmelCase_     : Optional[int]         =					model(
													    UpperCamelCase__    ,       attention_mask=UpperCamelCase__    ,       token_type_ids=UpperCamelCase__    ,       encoder_hidden_states=UpperCamelCase__    ,       )
													UpperCAmelCase_     : Optional[Any]         =					model(UpperCamelCase__    ,       attention_mask=UpperCamelCase__    ,       token_type_ids=UpperCamelCase__				)
													self.parent.assertEqual(result.last_hidden_state.shape    ,       (self.batch_size, self.seq_length, self.hidden_size)				)

							def       UpperCAmelCase__		(							self							:       Optional[Any]    ,       __magic_name__							:       Union[str, Any]    ,       __magic_name__							:       List[Any]    ,       __magic_name__							:       Optional[Any]    ,       __magic_name__							:       Tuple    ,       __magic_name__							:       Optional[int]    ,       __magic_name__							:       int    ,       __magic_name__							:       Union[str, Any]    ,       __magic_name__							:       Optional[int]    ,       )   ->    str:







													"""simple docstring"""
													UpperCAmelCase_     : Union[str, Any]         =					ElectraForMaskedLM(config=UpperCamelCase__				)
													model.to(UpperCamelCase__				)
													model.eval()
													UpperCAmelCase_     : Dict         =					model(UpperCamelCase__    ,       attention_mask=UpperCamelCase__    ,       token_type_ids=UpperCamelCase__    ,       labels=UpperCamelCase__				)
													self.parent.assertEqual(result.logits.shape    ,       (self.batch_size, self.seq_length, self.vocab_size)				)

							def       UpperCAmelCase__		(							self							:       Any    ,       __magic_name__							:       List[Any]    ,       __magic_name__							:       Tuple    ,       __magic_name__							:       Dict    ,       __magic_name__							:       str    ,       __magic_name__							:       Optional[Any]    ,       __magic_name__							:       Dict    ,       __magic_name__							:       Any    ,       __magic_name__							:       List[str]    ,       __magic_name__							:       List[str]    ,       )   ->    Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_     : Any         =					ElectraForCausalLM(config=UpperCamelCase__				)
													model.to(UpperCamelCase__				)
													model.eval()
													UpperCAmelCase_     : Optional[Any]         =					model(UpperCamelCase__    ,       attention_mask=UpperCamelCase__    ,       token_type_ids=UpperCamelCase__    ,       labels=UpperCamelCase__				)
													self.parent.assertEqual(result.logits.shape    ,       (self.batch_size, self.seq_length, self.vocab_size)				)

							def       UpperCAmelCase__		(							self							:       str    ,       __magic_name__							:       int    ,       __magic_name__							:       List[Any]    ,       __magic_name__							:       List[str]    ,       __magic_name__							:       List[str]    ,       __magic_name__							:       Tuple    ,       __magic_name__							:       Optional[int]    ,       __magic_name__							:       List[Any]    ,       __magic_name__							:       Optional[int]    ,       )   ->    int:







													"""simple docstring"""
													UpperCAmelCase_     : List[str]         =					self.num_labels
													UpperCAmelCase_     : Union[str, Any]         =					ElectraForTokenClassification(config=UpperCamelCase__				)
													model.to(UpperCamelCase__				)
													model.eval()
													UpperCAmelCase_     : Any         =					model(UpperCamelCase__    ,       attention_mask=UpperCamelCase__    ,       token_type_ids=UpperCamelCase__    ,       labels=UpperCamelCase__				)
													self.parent.assertEqual(result.logits.shape    ,       (self.batch_size, self.seq_length, self.num_labels)				)

							def       UpperCAmelCase__		(							self							:       Any    ,       __magic_name__							:       List[str]    ,       __magic_name__							:       Optional[int]    ,       __magic_name__							:       List[Any]    ,       __magic_name__							:       List[str]    ,       __magic_name__							:       Optional[Any]    ,       __magic_name__							:       Optional[Any]    ,       __magic_name__							:       List[Any]    ,       __magic_name__							:       Tuple    ,       )   ->    str:







													"""simple docstring"""
													UpperCAmelCase_     : int         =					self.num_labels
													UpperCAmelCase_     : Optional[Any]         =					ElectraForPreTraining(config=UpperCamelCase__				)
													model.to(UpperCamelCase__				)
													model.eval()
													UpperCAmelCase_     : Any         =					model(UpperCamelCase__    ,       attention_mask=UpperCamelCase__    ,       token_type_ids=UpperCamelCase__    ,       labels=UpperCamelCase__				)
													self.parent.assertEqual(result.logits.shape    ,       (self.batch_size, self.seq_length)				)

							def       UpperCAmelCase__		(							self							:       Optional[int]    ,       __magic_name__							:       Union[str, Any]    ,       __magic_name__							:       List[str]    ,       __magic_name__							:       Any    ,       __magic_name__							:       Union[str, Any]    ,       __magic_name__							:       str    ,       __magic_name__							:       List[str]    ,       __magic_name__							:       int    ,       __magic_name__							:       Optional[int]    ,       )   ->    List[Any]:







													"""simple docstring"""
													UpperCAmelCase_     : str         =					self.num_labels
													UpperCAmelCase_     : Optional[Any]         =					ElectraForSequenceClassification(UpperCamelCase__				)
													model.to(UpperCamelCase__				)
													model.eval()
													UpperCAmelCase_     : List[str]         =					model(UpperCamelCase__    ,       attention_mask=UpperCamelCase__    ,       token_type_ids=UpperCamelCase__    ,       labels=UpperCamelCase__				)
													self.parent.assertEqual(result.logits.shape    ,       (self.batch_size, self.num_labels)				)

							def       UpperCAmelCase__		(							self							:       List[Any]    ,       __magic_name__							:       List[str]    ,       __magic_name__							:       int    ,       __magic_name__							:       Optional[Any]    ,       __magic_name__							:       Tuple    ,       __magic_name__							:       Any    ,       __magic_name__							:       Optional[int]    ,       __magic_name__							:       Union[str, Any]    ,       __magic_name__							:       str    ,       )   ->    Any:







													"""simple docstring"""
													UpperCAmelCase_     : str         =					ElectraForQuestionAnswering(config=UpperCamelCase__				)
													model.to(UpperCamelCase__				)
													model.eval()
													UpperCAmelCase_     : Optional[int]         =					model(
													    UpperCamelCase__    ,       attention_mask=UpperCamelCase__    ,       token_type_ids=UpperCamelCase__    ,       start_positions=UpperCamelCase__    ,       end_positions=UpperCamelCase__    ,       )
													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       UpperCAmelCase__		(							self							:       Tuple    ,       __magic_name__							:       Tuple    ,       __magic_name__							:       List[str]    ,       __magic_name__							:       List[Any]    ,       __magic_name__							:       Optional[Any]    ,       __magic_name__							:       Optional[Any]    ,       __magic_name__							:       Optional[Any]    ,       __magic_name__							:       List[Any]    ,       __magic_name__							:       List[Any]    ,       )   ->    Dict:







													"""simple docstring"""
													UpperCAmelCase_     : Any         =					self.num_choices
													UpperCAmelCase_     : Tuple         =					ElectraForMultipleChoice(config=UpperCamelCase__				)
													model.to(UpperCamelCase__				)
													model.eval()
													UpperCAmelCase_     : Optional[int]         =					input_ids.unsqueeze(1				).expand(-1    ,       self.num_choices    ,       -1				).contiguous()
													UpperCAmelCase_     : Optional[Any]         =					token_type_ids.unsqueeze(1				).expand(-1    ,       self.num_choices    ,       -1				).contiguous()
													UpperCAmelCase_     : Tuple         =					input_mask.unsqueeze(1				).expand(-1    ,       self.num_choices    ,       -1				).contiguous()
													UpperCAmelCase_     : Optional[Any]         =					model(
													    UpperCamelCase__    ,       attention_mask=UpperCamelCase__    ,       token_type_ids=UpperCamelCase__    ,       labels=UpperCamelCase__    ,       )
													self.parent.assertEqual(result.logits.shape    ,       (self.batch_size, self.num_choices)				)



							def       UpperCAmelCase__		(							self							:       List[str]				)   ->    int:







													"""simple docstring"""
													UpperCAmelCase_     : Any         =					self.prepare_config_and_inputs()
													(
													    (
													    UpperCAmelCase_   
													)  ,    (
													    UpperCAmelCase_   
													)  ,    (
													    UpperCAmelCase_   
													)  ,    (
													    UpperCAmelCase_   
													)  ,    (
													    UpperCAmelCase_   
													)  ,    (
													    UpperCAmelCase_   
													)  ,    (
													    UpperCAmelCase_   
													)  ,    (
													    UpperCAmelCase_   
													)  ,       
													)     : str         =					config_and_inputs
													UpperCAmelCase_     : Any         =					{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
													return config, inputs_dict





@require_torch
class    __a (_A    ,						_A    ,						unittest.TestCase       ):
							__a   :				Tuple       =    (
							    (
							        ElectraModel,
							        ElectraForPreTraining,
							        ElectraForMaskedLM,
							        ElectraForCausalLM,
							        ElectraForMultipleChoice,
							        ElectraForTokenClassification,
							        ElectraForSequenceClassification,
							        ElectraForQuestionAnswering,
							    )
							    if is_torch_available()
							    else ()
							)
							__a   :				Optional[Any]       =    (
							    {
							        "feature-extraction": ElectraModel,
							        "fill-mask": ElectraForMaskedLM,
							        "question-answering": ElectraForQuestionAnswering,
							        "text-classification": ElectraForSequenceClassification,
							        "text-generation": ElectraForCausalLM,
							        "token-classification": ElectraForTokenClassification,
							        "zero-shot": ElectraForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							__a   :				Tuple       =    True

							def       UpperCAmelCase__		(							self							:       Dict    ,       __magic_name__							:       Tuple    ,       __magic_name__							:       Optional[int]    ,       __magic_name__							:       List[str]=False				)   ->    List[str]:







													"""simple docstring"""
													UpperCAmelCase_     : Any         =					super()._prepare_for_class(UpperCamelCase__    ,       UpperCamelCase__    ,       return_labels=UpperCamelCase__				)

													if return_labels:
																			if model_class in get_values(UpperCamelCase__				):
																									UpperCAmelCase_     : List[str]         =					torch.zeros(
																									    (self.model_tester.batch_size, self.model_tester.seq_length)    ,       dtype=torch.long    ,       device=UpperCamelCase__				)
													return inputs_dict

							def       UpperCAmelCase__		(							self							:       Optional[Any]				)   ->    Dict:







													"""simple docstring"""
													UpperCAmelCase_     : int         =					ElectraModelTester(self				)
													UpperCAmelCase_     : Optional[Any]         =					ConfigTester(self    ,       config_class=UpperCamelCase__    ,       hidden_size=37				)

							def       UpperCAmelCase__		(							self							:       List[str]				)   ->    List[str]:







													"""simple docstring"""
													self.config_tester.run_common_tests()

							def       UpperCAmelCase__		(							self							:       str				)   ->    List[str]:







													"""simple docstring"""
													UpperCAmelCase_     : Optional[int]         =					self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_electra_model(*UpperCamelCase__				)

							def       UpperCAmelCase__		(							self							:       str				)   ->    Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_     : Tuple         =					self.model_tester.prepare_config_and_inputs_for_decoder()
													self.model_tester.create_and_check_electra_model_as_decoder(*UpperCamelCase__				)

							def       UpperCAmelCase__		(							self							:       Optional[Any]				)   ->    List[Any]:







													"""simple docstring"""
													UpperCAmelCase_     : List[str]         =					self.model_tester.prepare_config_and_inputs()
													for type in ["absolute", "relative_key", "relative_key_query"]:
																			UpperCAmelCase_     : str         =					type
																			self.model_tester.create_and_check_electra_model(*UpperCamelCase__				)

							def       UpperCAmelCase__		(							self							:       int				)   ->    Tuple:







													"""simple docstring"""
													UpperCAmelCase_     : int         =					self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_electra_for_masked_lm(*UpperCamelCase__				)

							def       UpperCAmelCase__		(							self							:       Tuple				)   ->    str:







													"""simple docstring"""
													UpperCAmelCase_     : List[str]         =					self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_electra_for_token_classification(*UpperCamelCase__				)

							def       UpperCAmelCase__		(							self							:       List[str]				)   ->    Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_     : List[Any]         =					self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_electra_for_pretraining(*UpperCamelCase__				)

							def       UpperCAmelCase__		(							self							:       List[Any]				)   ->    int:







													"""simple docstring"""
													UpperCAmelCase_     : Any         =					self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_electra_for_sequence_classification(*UpperCamelCase__				)

							def       UpperCAmelCase__		(							self							:       Any				)   ->    Any:







													"""simple docstring"""
													UpperCAmelCase_     : List[str]         =					self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_electra_for_question_answering(*UpperCamelCase__				)

							def       UpperCAmelCase__		(							self							:       Any				)   ->    Any:







													"""simple docstring"""
													UpperCAmelCase_     : List[str]         =					self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_electra_for_multiple_choice(*UpperCamelCase__				)

							@slow
							def       UpperCAmelCase__		(							self							:       Tuple				)   ->    Optional[int]:







													"""simple docstring"""






													for model_name in ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			UpperCAmelCase_     : Dict         =					ElectraModel.from_pretrained(UpperCamelCase__				)
																			self.assertIsNotNone(UpperCamelCase__				)



							def       UpperCAmelCase__		(							self							:       str				)   ->    Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_     : int         =					self.model_tester.prepare_config_and_inputs_for_decoder()
													self.model_tester.create_and_check_electra_for_causal_lm(*UpperCamelCase__				)





@require_torch
class    __a (unittest.TestCase       ):

							@slow
							def       UpperCAmelCase__		(							self							:       Union[str, Any]				)   ->    List[str]:







													"""simple docstring"""
													UpperCAmelCase_     : Dict         =					ElectraModel.from_pretrained('''google/electra-small-discriminator'''				)
													UpperCAmelCase_     : int         =					torch.tensor([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]]				)
													UpperCAmelCase_     : Any         =					torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]				)
													UpperCAmelCase_     : List[Any]         =					model(UpperCamelCase__    ,       attention_mask=UpperCamelCase__				)[0]
													UpperCAmelCase_     : Any         =					torch.Size((1, 11, 2_56)				)
													self.assertEqual(output.shape    ,       UpperCamelCase__				)
													UpperCAmelCase_     : int         =					torch.tensor(
													    [[[0.4_4_7_1, 0.6_8_2_1, -0.3_2_6_5], [0.4_6_2_7, 0.5_2_5_5, -0.3_6_6_8], [0.4_5_3_2, 0.3_3_1_3, -0.4_3_4_4]]]				)

													self.assertTrue(torch.allclose(output[:, 1:4, 1:4]    ,       UpperCamelCase__    ,       atol=1E-4				)				)







'''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, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    IMAGENET_DEFAULT_MEAN,
    IMAGENET_DEFAULT_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    get_image_size,
    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_       :    int          =					logging.get_logger(__name__)


class    __a (lowerCamelCase       ):
							__a   :				Optional[Any]       =    ["pixel_values"]

							def __init__(							self							:       str    ,       __magic_name__							:       bool = True    ,       __magic_name__							:       Dict[str, int] = None    ,       __magic_name__							:       bool = True    ,       __magic_name__							:       Dict[str, int] = None    ,       __magic_name__							:       PILImageResampling = PILImageResampling.BICUBIC    ,       __magic_name__							:       bool = True    ,       __magic_name__							:       Union[int, float] = 1 / 2_55    ,       __magic_name__							:       bool = True    ,       __magic_name__							:       Optional[Union[float, List[float]]] = None    ,       __magic_name__							:       Optional[Union[float, List[float]]] = None    ,       **__magic_name__							:       List[Any]    ,       )   ->    None:







													"""simple docstring"""
													super().__init__(**__magic_name__				)
													UpperCAmelCase_     : Tuple         =					crop_size if crop_size is not None else {'''height''': 2_56, '''width''': 2_56}
													UpperCAmelCase_     : str         =					get_size_dict(__magic_name__    ,       param_name='''crop_size'''				)
													UpperCAmelCase_     : List[Any]         =					size if size is not None else {'''height''': 2_24, '''width''': 2_24}
													UpperCAmelCase_     : int         =					get_size_dict(__magic_name__				)

													UpperCAmelCase_     : Optional[int]         =					do_center_crop
													UpperCAmelCase_     : List[str]         =					crop_size
													UpperCAmelCase_     : Dict         =					do_resize
													UpperCAmelCase_     : str         =					size
													UpperCAmelCase_     : int         =					resample
													UpperCAmelCase_     : Optional[int]         =					do_rescale
													UpperCAmelCase_     : List[str]         =					rescale_factor
													UpperCAmelCase_     : int         =					do_normalize
													UpperCAmelCase_     : Any         =					image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
													UpperCAmelCase_     : str         =					image_std if image_std is not None else IMAGENET_DEFAULT_STD

							def       UpperCAmelCase__		(							self							:       str    ,       __magic_name__							:       np.ndarray    ,       __magic_name__							:       Dict[str, int]    ,       __magic_name__							:       Optional[int] = None    ,       __magic_name__							:       Optional[Union[str, ChannelDimension]] = None    ,       **__magic_name__							:       Union[str, Any]    ,       )   ->    np.ndarray:







													"""simple docstring"""
													UpperCAmelCase_     : List[Any]         =					self.size if size is None else size
													UpperCAmelCase_     : str         =					get_size_dict(__magic_name__				)
													UpperCAmelCase_     : Union[str, Any]         =					get_size_dict(__magic_name__    ,       param_name='''crop_size'''				)

													UpperCAmelCase_  ,    UpperCAmelCase_     : Any         =					get_image_size(__magic_name__				)
													UpperCAmelCase_     : List[str]         =					min(__magic_name__    ,       __magic_name__				)
													UpperCAmelCase_     : Dict         =					(size['''height'''] / crop_size['''height''']) * min_dim
													UpperCAmelCase_     : List[str]         =					(size['''width'''] / crop_size['''width''']) * min_dim
													return center_crop(__magic_name__    ,       size=(cropped_height, cropped_width)    ,       data_format=__magic_name__    ,       **__magic_name__				)

							def       UpperCAmelCase__		(							self							:       Union[str, Any]    ,       __magic_name__							:       np.ndarray    ,       __magic_name__							:       Dict[str, int]    ,       __magic_name__							:       PILImageResampling = PIL.Image.BICUBIC    ,       __magic_name__							:       Optional[Union[str, ChannelDimension]] = None    ,       **__magic_name__							:       str    ,       )   ->    np.ndarray:







													"""simple docstring"""
													UpperCAmelCase_     : str         =					get_size_dict(__magic_name__				)
													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()}"""				)
													return resize(
													    __magic_name__    ,       size=(size['''height'''], size['''width'''])    ,       resample=__magic_name__    ,       data_format=__magic_name__    ,       **__magic_name__				)

							def       UpperCAmelCase__		(							self							:       Tuple    ,       __magic_name__							:       np.ndarray    ,       __magic_name__							:       Union[int, float]    ,       __magic_name__							:       Optional[Union[str, ChannelDimension]] = None    ,       **__magic_name__							:       Tuple    ,       )   ->    str:







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

							def       UpperCAmelCase__		(							self							:       Optional[int]    ,       __magic_name__							:       np.ndarray    ,       __magic_name__							:       Union[float, List[float]]    ,       __magic_name__							:       Union[float, List[float]]    ,       __magic_name__							:       Optional[Union[str, ChannelDimension]] = None    ,       **__magic_name__							:       Dict    ,       )   ->    np.ndarray:







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



							def       UpperCAmelCase__		(							self							:       str    ,       __magic_name__							:       ImageInput    ,       __magic_name__							:       Optional[bool] = None    ,       __magic_name__							:       Optional[Dict[str, int]] = None    ,       __magic_name__							:       Optional[bool] = None    ,       __magic_name__							:       Optional[Dict[str, int]] = None    ,       __magic_name__							:       PILImageResampling = None    ,       __magic_name__							:       Optional[bool] = None    ,       __magic_name__							:       Optional[float] = None    ,       __magic_name__							:       Optional[bool] = None    ,       __magic_name__							:       Optional[Union[float, List[float]]] = None    ,       __magic_name__							:       Optional[Union[float, List[float]]] = None    ,       __magic_name__							:       Optional[Union[str, TensorType]] = None    ,       __magic_name__							:       ChannelDimension = ChannelDimension.FIRST    ,       **__magic_name__							:       Optional[Any]    ,       )   ->    PIL.Image.Image:







													"""simple docstring"""
													UpperCAmelCase_     : List[str]         =					do_center_crop if do_center_crop is not None else self.do_center_crop
													UpperCAmelCase_     : str         =					crop_size if crop_size is not None else self.crop_size
													UpperCAmelCase_     : int         =					get_size_dict(__magic_name__    ,       param_name='''crop_size'''				)
													UpperCAmelCase_     : Dict         =					do_resize if do_resize is not None else self.do_resize
													UpperCAmelCase_     : Optional[Any]         =					size if size is not None else self.size
													UpperCAmelCase_     : Tuple         =					get_size_dict(__magic_name__				)
													UpperCAmelCase_     : Any         =					resample if resample is not None else self.resample
													UpperCAmelCase_     : int         =					do_rescale if do_rescale is not None else self.do_rescale
													UpperCAmelCase_     : str         =					rescale_factor if rescale_factor is not None else self.rescale_factor
													UpperCAmelCase_     : Optional[Any]         =					do_normalize if do_normalize is not None else self.do_normalize
													UpperCAmelCase_     : Tuple         =					image_mean if image_mean is not None else self.image_mean
													UpperCAmelCase_     : Tuple         =					image_std if image_std is not None else self.image_std

													UpperCAmelCase_     : Optional[Any]         =					make_list_of_images(__magic_name__				)

													if not valid_images(__magic_name__				):
																			raise ValueError(
																			    '''Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '''
																			    '''torch.Tensor, tf.Tensor or jax.ndarray.'''				)

													if do_center_crop and crop_size is None:
																			raise ValueError('''If `do_center_crop` is set to `True`, `crop_size` must be provided.'''				)

													if do_resize and size is None:
																			raise ValueError('''Size 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 image standard deviation must be specified if do_normalize is True.'''				)

													# All transformations expect numpy arrays.
													UpperCAmelCase_     : Tuple         =					[to_numpy_array(__magic_name__				) for image in images]

													if do_center_crop:
																			UpperCAmelCase_     : int         =					[self.center_crop(__magic_name__    ,       __magic_name__    ,       size=__magic_name__				) for image in images]

													if do_resize:
																			UpperCAmelCase_     : Dict         =					[self.resize(image=__magic_name__    ,       size=__magic_name__    ,       resample=__magic_name__				) for image in images]

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

													if do_normalize:
																			UpperCAmelCase_     : Any         =					[self.normalize(image=__magic_name__    ,       mean=__magic_name__    ,       std=__magic_name__				) for image in images]

													UpperCAmelCase_     : Optional[int]         =					[to_channel_dimension_format(__magic_name__    ,       __magic_name__				) for image in images]

													UpperCAmelCase_     : Union[str, Any]         =					{'''pixel_values''': images}
													return BatchFeature(data=__magic_name__    ,       tensor_type=__magic_name__				)





