

'''simple docstring'''


import unittest

from transformers import AlbertConfig, 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, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import (
					    MODEL_FOR_PRETRAINING_MAPPING,
					    AlbertForMaskedLM,
					    AlbertForMultipleChoice,
					    AlbertForPreTraining,
					    AlbertForQuestionAnswering,
					    AlbertForSequenceClassification,
					    AlbertForTokenClassification,
					    AlbertModel,
					)
					from transformers.models.albert.modeling_albert import ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST




class     a			:






						"""simple docstring"""




						def __init__(							self					:      Union[str, Any]			,			snake_case_					:      Tuple			,			snake_case_					:      Dict=1_3			,			snake_case_					:      Optional[int]=7			,			snake_case_					:      Optional[int]=True			,			snake_case_					:      Tuple=True			,			snake_case_					:      Tuple=True			,			snake_case_					:      int=True			,			snake_case_					:      Optional[int]=9_9			,			snake_case_					:      List[Any]=1_6			,			snake_case_					:      str=3_6			,			snake_case_					:      Dict=6			,			snake_case_					:      Optional[int]=6			,			snake_case_					:      List[Any]=6			,			snake_case_					:      int=3_7			,			snake_case_					:      Tuple="gelu"			,			snake_case_					:      Union[str, Any]=0.1			,			snake_case_					:      Optional[Any]=0.1			,			snake_case_					:      Optional[Any]=5_1_2			,			snake_case_					:      Tuple=1_6			,			snake_case_					:      List[str]=2			,			snake_case_					:      Any=0.0_2			,			snake_case_					:      Dict=3			,			snake_case_					:      int=4			,			snake_case_					:      List[str]=None			,			):



								'''simple docstring'''



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







						def       __magic_name__							(							self					:      Any  ):



								'''simple docstring'''



								snake_case__						:       Optional[Any]       						=  ids_tensor([self.batch_size, self.seq_length]			,			self.vocab_size  )

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

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

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

								snake_case__						:       Union[str, Any]       						=  self.get_config()

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







						def       __magic_name__							(							self					:      List[Any]  ):



								'''simple docstring'''



								return AlbertConfig(
								    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			,			initializer_range=self.initializer_range			,			num_hidden_groups=self.num_hidden_groups			,			)







						def       __magic_name__							(							self					:      Tuple			,			snake_case_					:      Any			,			snake_case_					:      str			,			snake_case_					:      Dict			,			snake_case_					:      int			,			snake_case_					:      str			,			snake_case_					:      str			,			snake_case_					:      Any  ):



								'''simple docstring'''



								snake_case__						:       Optional[int]       						=  AlbertModel(config=snake_case_  )
								model.to(snake_case_  )
								model.eval()
								snake_case__						:       Tuple       						=  model(snake_case_			,			attention_mask=snake_case_			,			token_type_ids=snake_case_  )
								snake_case__						:       Optional[Any]       						=  model(snake_case_			,			token_type_ids=snake_case_  )
								snake_case__						:       List[Any]       						=  model(snake_case_  )
								self.parent.assertEqual(result.last_hidden_state.shape			,			(self.batch_size, self.seq_length, self.hidden_size)  )
								self.parent.assertEqual(result.pooler_output.shape			,			(self.batch_size, self.hidden_size)  )







						def       __magic_name__							(							self					:      Dict			,			snake_case_					:      Tuple			,			snake_case_					:      Dict			,			snake_case_					:      str			,			snake_case_					:      List[str]			,			snake_case_					:      str			,			snake_case_					:      List[Any]			,			snake_case_					:      Any  ):



								'''simple docstring'''



								snake_case__						:       Optional[Any]       						=  AlbertForPreTraining(config=snake_case_  )
								model.to(snake_case_  )
								model.eval()
								snake_case__						:       List[Any]       						=  model(
								    snake_case_			,			attention_mask=snake_case_			,			token_type_ids=snake_case_			,			labels=snake_case_			,			sentence_order_label=snake_case_			,			)
								self.parent.assertEqual(result.prediction_logits.shape			,			(self.batch_size, self.seq_length, self.vocab_size)  )
								self.parent.assertEqual(result.sop_logits.shape			,			(self.batch_size, config.num_labels)  )







						def       __magic_name__							(							self					:      str			,			snake_case_					:      int			,			snake_case_					:      int			,			snake_case_					:      List[Any]			,			snake_case_					:      Optional[Any]			,			snake_case_					:      str			,			snake_case_					:      Optional[int]			,			snake_case_					:      List[Any]  ):



								'''simple docstring'''



								snake_case__						:       int       						=  AlbertForMaskedLM(config=snake_case_  )
								model.to(snake_case_  )
								model.eval()
								snake_case__						:       Optional[int]       						=  model(snake_case_			,			attention_mask=snake_case_			,			token_type_ids=snake_case_			,			labels=snake_case_  )
								self.parent.assertEqual(result.logits.shape			,			(self.batch_size, self.seq_length, self.vocab_size)  )







						def       __magic_name__							(							self					:      str			,			snake_case_					:      Any			,			snake_case_					:      Dict			,			snake_case_					:      Optional[Any]			,			snake_case_					:      List[Any]			,			snake_case_					:      int			,			snake_case_					:      Dict			,			snake_case_					:      Union[str, Any]  ):



								'''simple docstring'''



								snake_case__						:       List[str]       						=  AlbertForQuestionAnswering(config=snake_case_  )
								model.to(snake_case_  )
								model.eval()
								snake_case__						:       Optional[Any]       						=  model(
								    snake_case_			,			attention_mask=snake_case_			,			token_type_ids=snake_case_			,			start_positions=snake_case_			,			end_positions=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       __magic_name__							(							self					:      Optional[int]			,			snake_case_					:      int			,			snake_case_					:      List[Any]			,			snake_case_					:      Optional[int]			,			snake_case_					:      Dict			,			snake_case_					:      List[Any]			,			snake_case_					:      Dict			,			snake_case_					:      Tuple  ):



								'''simple docstring'''



								snake_case__						:       str       						=  self.num_labels
								snake_case__						:       Any       						=  AlbertForSequenceClassification(snake_case_  )
								model.to(snake_case_  )
								model.eval()
								snake_case__						:       Union[str, Any]       						=  model(snake_case_			,			attention_mask=snake_case_			,			token_type_ids=snake_case_			,			labels=snake_case_  )
								self.parent.assertEqual(result.logits.shape			,			(self.batch_size, self.num_labels)  )







						def       __magic_name__							(							self					:      Optional[Any]			,			snake_case_					:      List[str]			,			snake_case_					:      Optional[Any]			,			snake_case_					:      List[str]			,			snake_case_					:      Tuple			,			snake_case_					:      List[Any]			,			snake_case_					:      List[str]			,			snake_case_					:      Optional[Any]  ):



								'''simple docstring'''



								snake_case__						:       List[str]       						=  self.num_labels
								snake_case__						:       Optional[Any]       						=  AlbertForTokenClassification(config=snake_case_  )
								model.to(snake_case_  )
								model.eval()
								snake_case__						:       List[str]       						=  model(snake_case_			,			attention_mask=snake_case_			,			token_type_ids=snake_case_			,			labels=snake_case_  )
								self.parent.assertEqual(result.logits.shape			,			(self.batch_size, self.seq_length, self.num_labels)  )







						def       __magic_name__							(							self					:      str			,			snake_case_					:      Any			,			snake_case_					:      Any			,			snake_case_					:      Any			,			snake_case_					:      Optional[Any]			,			snake_case_					:      str			,			snake_case_					:      Optional[int]			,			snake_case_					:      Tuple  ):



								'''simple docstring'''



								snake_case__						:       List[str]       						=  self.num_choices
								snake_case__						:       int       						=  AlbertForMultipleChoice(config=snake_case_  )
								model.to(snake_case_  )
								model.eval()
								snake_case__						:       Any       						=  input_ids.unsqueeze(1  ).expand(-1			,			self.num_choices			,			-1  ).contiguous()
								snake_case__						:       Optional[int]       						=  token_type_ids.unsqueeze(1  ).expand(-1			,			self.num_choices			,			-1  ).contiguous()
								snake_case__						:       Optional[Any]       						=  input_mask.unsqueeze(1  ).expand(-1			,			self.num_choices			,			-1  ).contiguous()
								snake_case__						:       int       						=  model(
								    snake_case_			,			attention_mask=snake_case_			,			token_type_ids=snake_case_			,			labels=snake_case_			,			)
								self.parent.assertEqual(result.logits.shape			,			(self.batch_size, self.num_choices)  )







						def       __magic_name__							(							self					:      Optional[int]  ):



								'''simple docstring'''



								snake_case__						:       List[str]       						=  self.prepare_config_and_inputs()
								(
								    (
								    snake_case__
								)						,       (
								    snake_case__
								)						,       (
								    snake_case__
								)						,       (
								    snake_case__
								)						,       (
								    snake_case__
								)						,       (
								    snake_case__
								)						,       (
								    snake_case__
								)						,       
								)						:       Dict       						=  config_and_inputs
								snake_case__						:       List[Any]       						=  {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
								return config, inputs_dict





@require_torch
class     a			(				SCREAMING_SNAKE_CASE			,			SCREAMING_SNAKE_CASE			,			unittest.TestCase       ):






						"""simple docstring"""




						__UpperCAmelCase			     =    (
						    (
						        AlbertModel,
						        AlbertForPreTraining,
						        AlbertForMaskedLM,
						        AlbertForMultipleChoice,
						        AlbertForSequenceClassification,
						        AlbertForTokenClassification,
						        AlbertForQuestionAnswering,
						    )
						    if is_torch_available()
						    else ()
						)
						__UpperCAmelCase			     =    (
						    {
						        """feature-extraction""": AlbertModel,
						        """fill-mask""": AlbertForMaskedLM,
						        """question-answering""": AlbertForQuestionAnswering,
						        """text-classification""": AlbertForSequenceClassification,
						        """token-classification""": AlbertForTokenClassification,
						        """zero-shot""": AlbertForSequenceClassification,
						    }
						    if is_torch_available()
						    else {}
						)
						__UpperCAmelCase			     =    True







						def       __magic_name__							(							self					:      Any			,			snake_case_					:      Optional[Any]			,			snake_case_					:      Optional[Any]			,			snake_case_					:      Tuple=False  ):



								'''simple docstring'''



								snake_case__						:       Any       						=  super()._prepare_for_class(snake_case_			,			snake_case_			,			return_labels=snake_case_  )

								if return_labels:
										if model_class in get_values(snake_case_  ):
												snake_case__						:       Optional[Any]       						=  torch.zeros(
												    (self.model_tester.batch_size, self.model_tester.seq_length)			,			dtype=torch.long			,			device=snake_case_  )
												snake_case__						:       Any       						=  torch.zeros(
												    self.model_tester.batch_size			,			dtype=torch.long			,			device=snake_case_  )
								return inputs_dict







						def       __magic_name__							(							self					:      Dict  ):



								'''simple docstring'''



								snake_case__						:       int       						=  AlbertModelTester(self  )
								snake_case__						:       Dict       						=  ConfigTester(self			,			config_class=snake_case_			,			hidden_size=3_7  )







						def       __magic_name__							(							self					:      int  ):



								'''simple docstring'''



								self.config_tester.run_common_tests()







						def       __magic_name__							(							self					:      Tuple  ):



								'''simple docstring'''



								snake_case__						:       Optional[Any]       						=  self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*snake_case_  )







						def       __magic_name__							(							self					:      Optional[int]  ):



								'''simple docstring'''



								snake_case__						:       str       						=  self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_pretraining(*snake_case_  )







						def       __magic_name__							(							self					:      Optional[Any]  ):



								'''simple docstring'''



								snake_case__						:       List[Any]       						=  self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_masked_lm(*snake_case_  )







						def       __magic_name__							(							self					:      Union[str, Any]  ):



								'''simple docstring'''



								snake_case__						:       Optional[Any]       						=  self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_multiple_choice(*snake_case_  )







						def       __magic_name__							(							self					:      Dict  ):



								'''simple docstring'''



								snake_case__						:       Union[str, Any]       						=  self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_question_answering(*snake_case_  )







						def       __magic_name__							(							self					:      Optional[Any]  ):



								'''simple docstring'''



								snake_case__						:       Optional[int]       						=  self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_sequence_classification(*snake_case_  )







						def       __magic_name__							(							self					:      Any  ):



								'''simple docstring'''



								snake_case__						:       Optional[int]       						=  self.model_tester.prepare_config_and_inputs()
								for type in ["absolute", "relative_key", "relative_key_query"]:
										snake_case__						:       Dict       						=  type
										self.model_tester.create_and_check_model(*snake_case_  )







						@slow
						def       __magic_name__							(							self					:      Union[str, Any]  ):



								'''simple docstring'''



								for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										snake_case__						:       str       						=  AlbertModel.from_pretrained(snake_case_  )
										self.assertIsNotNone(snake_case_  )





@require_torch
class     a			(				unittest.TestCase       ):






						"""simple docstring"""




						@slow
						def       __magic_name__							(							self					:      Optional[Any]  ):



								'''simple docstring'''



								snake_case__						:       str       						=  AlbertModel.from_pretrained('''albert-base-v2'''  )
								snake_case__						:       Dict       						=  torch.tensor([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]]  )
								snake_case__						:       Optional[Any]       						=  torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]  )
								with torch.no_grad():
										snake_case__						:       Optional[int]       						=  model(snake_case_			,			attention_mask=snake_case_  )[0]
								snake_case__						:       Optional[int]       						=  torch.Size((1, 1_1, 7_6_8)  )
								self.assertEqual(output.shape			,			snake_case_  )
								snake_case__						:       str       						=  torch.tensor(
								    [[[-0.6_5_1_3, 1.5_0_3_5, -0.2_7_6_6], [-0.6_5_1_5, 1.5_0_4_6, -0.2_7_8_0], [-0.6_5_1_2, 1.5_0_4_9, -0.2_7_8_4]]]  )

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






'''simple docstring'''


import warnings

from diffusers import StableDiffusionImgaImgPipeline  # noqa F401


warnings.warn(
    """The `image_to_image.py` script is outdated. Please use directly `from diffusers import"""
    """ StableDiffusionImg2ImgPipeline` instead."""
)



