"""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							:






					def __init__(	self       ,  a__       ,  a__=13       ,  a__=7       ,  a__=True       ,  a__=True       ,  a__=True       ,  a__=True       ,  a__=99       ,  a__=16       ,  a__=36       ,  a__=6       ,  a__=6       ,  a__=6       ,  a__=37       ,  a__="gelu"       ,  a__=0.1       ,  a__=0.1       ,  a__=512       ,  a__=16       ,  a__=2       ,  a__=0.0_2       ,  a__=3       ,  a__=4       ,  a__=None       ,  ):
							_lowerCAmelCase		: int						    =  parent
							_lowerCAmelCase		: str						    =  batch_size
							_lowerCAmelCase		: Optional[Any]						    =  seq_length
							_lowerCAmelCase		: Optional[Any]						    =  is_training
							_lowerCAmelCase		: str						    =  use_input_mask
							_lowerCAmelCase		: List[str]						    =  use_token_type_ids
							_lowerCAmelCase		: str						    =  use_labels
							_lowerCAmelCase		: Tuple						    =  vocab_size
							_lowerCAmelCase		: Optional[int]						    =  embedding_size
							_lowerCAmelCase		: Tuple						    =  hidden_size
							_lowerCAmelCase		: int						    =  num_hidden_layers
							_lowerCAmelCase		: Tuple						    =  num_hidden_groups
							_lowerCAmelCase		: Optional[int]						    =  num_attention_heads
							_lowerCAmelCase		: Optional[Any]						    =  intermediate_size
							_lowerCAmelCase		: int						    =  hidden_act
							_lowerCAmelCase		: Any						    =  hidden_dropout_prob
							_lowerCAmelCase		: List[str]						    =  attention_probs_dropout_prob
							_lowerCAmelCase		: Any						    =  max_position_embeddings
							_lowerCAmelCase		: Dict						    =  type_vocab_size
							_lowerCAmelCase		: Tuple						    =  type_sequence_label_size
							_lowerCAmelCase		: Dict						    =  initializer_range
							_lowerCAmelCase		: List[Any]						    =  num_labels
							_lowerCAmelCase		: Optional[int]						    =  num_choices
							_lowerCAmelCase		: Any						    =  scope






					def 					__A						(	self						):
							_lowerCAmelCase		: List[str]						    =  ids_tensor([self.batch_size, self.seq_length]       ,  self.vocab_size						)

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

							_lowerCAmelCase		: str						    =  None
							if self.use_token_type_ids:
									_lowerCAmelCase		: Optional[int]						    =  ids_tensor([self.batch_size, self.seq_length]       ,  self.type_vocab_size						)

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

							_lowerCAmelCase		: Dict						    =  self.get_config()

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






					def 					__A						(	self						):
							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 					__A						(	self       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__						):
							_lowerCAmelCase		: Optional[int]						    =  AlbertModel(config=__A						)
							model.to(__A						)
							model.eval()
							_lowerCAmelCase		: Tuple						    =  model(__A       ,  attention_mask=__A       ,  token_type_ids=__A						)
							_lowerCAmelCase		: Optional[Any]						    =  model(__A       ,  token_type_ids=__A						)
							_lowerCAmelCase		: List[Any]						    =  model(__A						)
							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 					__A						(	self       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__						):
							_lowerCAmelCase		: int						    =  AlbertForPreTraining(config=__A						)
							model.to(__A						)
							model.eval()
							_lowerCAmelCase		: Optional[Any]						    =  model(
							    __A       ,  attention_mask=__A       ,  token_type_ids=__A       ,  labels=__A       ,  sentence_order_label=__A       ,  )
							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 					__A						(	self       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__						):
							_lowerCAmelCase		: Optional[Any]						    =  AlbertForMaskedLM(config=__A						)
							model.to(__A						)
							model.eval()
							_lowerCAmelCase		: List[Any]						    =  model(__A       ,  attention_mask=__A       ,  token_type_ids=__A       ,  labels=__A						)
							self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.seq_length, self.vocab_size)						)






					def 					__A						(	self       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__						):
							_lowerCAmelCase		: Dict						    =  AlbertForQuestionAnswering(config=__A						)
							model.to(__A						)
							model.eval()
							_lowerCAmelCase		: Optional[int]						    =  model(
							    __A       ,  attention_mask=__A       ,  token_type_ids=__A       ,  start_positions=__A       ,  end_positions=__A       ,  )
							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 					__A						(	self       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__						):
							_lowerCAmelCase		: List[str]						    =  self.num_labels
							_lowerCAmelCase		: Any						    =  AlbertForSequenceClassification(__A						)
							model.to(__A						)
							model.eval()
							_lowerCAmelCase		: str						    =  model(__A       ,  attention_mask=__A       ,  token_type_ids=__A       ,  labels=__A						)
							self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.num_labels)						)






					def 					__A						(	self       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__						):
							_lowerCAmelCase		: Tuple						    =  self.num_labels
							_lowerCAmelCase		: str						    =  AlbertForTokenClassification(config=__A						)
							model.to(__A						)
							model.eval()
							_lowerCAmelCase		: Dict						    =  model(__A       ,  attention_mask=__A       ,  token_type_ids=__A       ,  labels=__A						)
							self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.seq_length, self.num_labels)						)






					def 					__A						(	self       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__						):
							_lowerCAmelCase		: Tuple						    =  self.num_choices
							_lowerCAmelCase		: Optional[Any]						    =  AlbertForMultipleChoice(config=__A						)
							model.to(__A						)
							model.eval()
							_lowerCAmelCase		: List[str]						    =  input_ids.unsqueeze(1						).expand(-1       ,  self.num_choices       ,  -1						).contiguous()
							_lowerCAmelCase		: Any						    =  token_type_ids.unsqueeze(1						).expand(-1       ,  self.num_choices       ,  -1						).contiguous()
							_lowerCAmelCase		: Union[str, Any]						    =  input_mask.unsqueeze(1						).expand(-1       ,  self.num_choices       ,  -1						).contiguous()
							_lowerCAmelCase		: List[Any]						    =  model(
							    __A       ,  attention_mask=__A       ,  token_type_ids=__A       ,  labels=__A       ,  )
							self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.num_choices)						)






					def 					__A						(	self						):
							_lowerCAmelCase		: Optional[Any]						    =  self.prepare_config_and_inputs()
							(
							    (
							    _lowerCAmelCase				
							)    ,			(
							    _lowerCAmelCase				
							)    ,			(
							    _lowerCAmelCase				
							)    ,			(
							    _lowerCAmelCase				
							)    ,			(
							    _lowerCAmelCase				
							)    ,			(
							    _lowerCAmelCase				
							)    ,			(
							    _lowerCAmelCase				
							)    ,							
							)		: Dict						    =  config_and_inputs
							_lowerCAmelCase		: Optional[int]						    =  {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
							return config, inputs_dict







@require_torch
class 		__A							(				__lowercase					,			__lowercase					,			unittest.TestCase	):
					_UpperCamelCase							:    Dict	      =	(
					    (
					        AlbertModel,
					        AlbertForPreTraining,
					        AlbertForMaskedLM,
					        AlbertForMultipleChoice,
					        AlbertForSequenceClassification,
					        AlbertForTokenClassification,
					        AlbertForQuestionAnswering,
					    )
					    if is_torch_available()
					    else ()
					)
					_UpperCamelCase							:    Union[str, Any]	      =	(
					    {
					        'feature-extraction': AlbertModel,
					        'fill-mask': AlbertForMaskedLM,
					        'question-answering': AlbertForQuestionAnswering,
					        'text-classification': AlbertForSequenceClassification,
					        'token-classification': AlbertForTokenClassification,
					        'zero-shot': AlbertForSequenceClassification,
					    }
					    if is_torch_available()
					    else {}
					)
					_UpperCamelCase							:    int	      =	True






					def 					__A						(	self       ,  a__       ,  a__       ,  a__=False						):
							_lowerCAmelCase		: int						    =  super()._prepare_for_class(__A       ,  __A       ,  return_labels=__A						)

							if return_labels:
									if model_class in get_values(__A						):
											_lowerCAmelCase		: Union[str, Any]						    =  torch.zeros(
											    (self.model_tester.batch_size, self.model_tester.seq_length)       ,  dtype=torch.long       ,  device=__A						)
											_lowerCAmelCase		: Dict						    =  torch.zeros(
											    self.model_tester.batch_size       ,  dtype=torch.long       ,  device=__A						)
							return inputs_dict






					def 					__A						(	self						):
							_lowerCAmelCase		: Union[str, Any]						    =  AlbertModelTester(self						)
							_lowerCAmelCase		: List[str]						    =  ConfigTester(self       ,  config_class=__A       ,  hidden_size=37						)






					def 					__A						(	self						):
							self.config_tester.run_common_tests()






					def 					__A						(	self						):
							_lowerCAmelCase		: Tuple						    =  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*__A						)






					def 					__A						(	self						):
							_lowerCAmelCase		: int						    =  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_pretraining(*__A						)






					def 					__A						(	self						):
							_lowerCAmelCase		: List[Any]						    =  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*__A						)






					def 					__A						(	self						):
							_lowerCAmelCase		: int						    =  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_multiple_choice(*__A						)






					def 					__A						(	self						):
							_lowerCAmelCase		: List[Any]						    =  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*__A						)






					def 					__A						(	self						):
							_lowerCAmelCase		: List[str]						    =  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*__A						)






					def 					__A						(	self						):
							_lowerCAmelCase		: Any						    =  self.model_tester.prepare_config_and_inputs()
							for type in ["absolute", "relative_key", "relative_key_query"]:
									_lowerCAmelCase		: int						    =  type
									self.model_tester.create_and_check_model(*__A						)






					@slow
					def 					__A						(	self						):
							for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									_lowerCAmelCase		: Tuple						    =  AlbertModel.from_pretrained(__A						)
									self.assertIsNotNone(__A						)







@require_torch
class 		__A							(				unittest.TestCase	):






					@slow
					def 					__A						(	self						):
							_lowerCAmelCase		: int						    =  AlbertModel.from_pretrained("""albert-base-v2"""						)
							_lowerCAmelCase		: str						    =  torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]						)
							_lowerCAmelCase		: Union[str, Any]						    =  torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
							with torch.no_grad():
									_lowerCAmelCase		: Tuple						    =  model(__A       ,  attention_mask=__A						)[0]
							_lowerCAmelCase		: Tuple						    =  torch.Size((1, 11, 768)						)
							self.assertEqual(output.shape       ,  __A						)
							_lowerCAmelCase		: List[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]       ,  __A       ,  atol=1e-4						)						)





"""simple docstring"""




import warnings

from diffusers import StableDiffusionInpaintPipeline as StableDiffusionInpaintPipeline  # noqa F401


warnings.warn(
    'The `inpainting.py` script is outdated. Please use directly `from diffusers import'
    ' StableDiffusionInpaintPipeline` instead.'
)




