

'''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				:     Tuple							, _a				:     int							, _a				:     Tuple=13							, _a				:     str=7							, _a				:     Optional[int]=True							, _a				:     List[str]=True							, _a				:     Dict=True							, _a				:     Any=True							, _a				:     Union[str, Any]=99							, _a				:     Tuple=16							, _a				:     Tuple=36							, _a				:     Optional[Any]=6							, _a				:     Dict=6							, _a				:     Optional[Any]=6							, _a				:     List[Any]=37							, _a				:     Any="gelu"							, _a				:     List[str]=0.1							, _a				:     Union[str, Any]=0.1							, _a				:     Dict=512							, _a				:     int=16							, _a				:     List[Any]=2							, _a				:     int=0.02							, _a				:     int=3							, _a				:     Dict=4							, _a				:     Union[str, Any]=None							, )     ->   Tuple:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =parent
							_SCREAMING_SNAKE_CASE							   =batch_size
							_SCREAMING_SNAKE_CASE							   =seq_length
							_SCREAMING_SNAKE_CASE							   =is_training
							_SCREAMING_SNAKE_CASE							   =use_input_mask
							_SCREAMING_SNAKE_CASE							   =use_token_type_ids
							_SCREAMING_SNAKE_CASE							   =use_labels
							_SCREAMING_SNAKE_CASE							   =vocab_size
							_SCREAMING_SNAKE_CASE							   =embedding_size
							_SCREAMING_SNAKE_CASE							   =hidden_size
							_SCREAMING_SNAKE_CASE							   =num_hidden_layers
							_SCREAMING_SNAKE_CASE							   =num_hidden_groups
							_SCREAMING_SNAKE_CASE							   =num_attention_heads
							_SCREAMING_SNAKE_CASE							   =intermediate_size
							_SCREAMING_SNAKE_CASE							   =hidden_act
							_SCREAMING_SNAKE_CASE							   =hidden_dropout_prob
							_SCREAMING_SNAKE_CASE							   =attention_probs_dropout_prob
							_SCREAMING_SNAKE_CASE							   =max_position_embeddings
							_SCREAMING_SNAKE_CASE							   =type_vocab_size
							_SCREAMING_SNAKE_CASE							   =type_sequence_label_size
							_SCREAMING_SNAKE_CASE							   =initializer_range
							_SCREAMING_SNAKE_CASE							   =num_labels
							_SCREAMING_SNAKE_CASE							   =num_choices
							_SCREAMING_SNAKE_CASE							   =scope





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





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =ids_tensor([self.batch_size, self.seq_length]							, self.vocab_size			)

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

							_SCREAMING_SNAKE_CASE							   =None
							if self.use_token_type_ids:
												_SCREAMING_SNAKE_CASE							   =ids_tensor([self.batch_size, self.seq_length]							, self.type_vocab_size			)

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

							_SCREAMING_SNAKE_CASE							   =self.get_config()

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





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





							'''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 						A  (		self				:     List[Any]							, _a				:     List[str]							, _a				:     Any							, _a				:     Dict							, _a				:     List[Any]							, _a				:     Union[str, Any]							, _a				:     Tuple							, _a				:     Dict			)     ->   int:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =AlbertModel(config=_a			)
							model.to(_a			)
							model.eval()
							_SCREAMING_SNAKE_CASE							   =model(_a							, attention_mask=_a							, token_type_ids=_a			)
							_SCREAMING_SNAKE_CASE							   =model(_a							, token_type_ids=_a			)
							_SCREAMING_SNAKE_CASE							   =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				:     int							, _a				:     Any							, _a				:     Dict							, _a				:     Union[str, Any]							, _a				:     Dict							, _a				:     int							, _a				:     Union[str, Any]							, _a				:     Optional[Any]			)     ->   Any:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =AlbertForPreTraining(config=_a			)
							model.to(_a			)
							model.eval()
							_SCREAMING_SNAKE_CASE							   =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				:     Optional[Any]							, _a				:     List[str]							, _a				:     Union[str, Any]							, _a				:     Optional[Any]							, _a				:     Any							, _a				:     int							, _a				:     List[str]							, _a				:     str			)     ->   Tuple:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =AlbertForMaskedLM(config=_a			)
							model.to(_a			)
							model.eval()
							_SCREAMING_SNAKE_CASE							   =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				:     Any							, _a				:     Union[str, Any]							, _a				:     Optional[Any]							, _a				:     Tuple							, _a				:     Any							, _a				:     List[Any]							, _a				:     List[str]							, _a				:     List[str]			)     ->   Dict:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =AlbertForQuestionAnswering(config=_a			)
							model.to(_a			)
							model.eval()
							_SCREAMING_SNAKE_CASE							   =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				:     Union[str, Any]							, _a				:     Dict							, _a				:     str							, _a				:     str							, _a				:     int							, _a				:     int							, _a				:     int							, _a				:     List[Any]			)     ->   Optional[int]:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.num_labels
							_SCREAMING_SNAKE_CASE							   =AlbertForSequenceClassification(_a			)
							model.to(_a			)
							model.eval()
							_SCREAMING_SNAKE_CASE							   =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				:     Union[str, Any]							, _a				:     str							, _a				:     Union[str, Any]							, _a				:     List[str]							, _a				:     List[str]							, _a				:     str							, _a				:     Dict							, _a				:     Tuple			)     ->   Tuple:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.num_labels
							_SCREAMING_SNAKE_CASE							   =AlbertForTokenClassification(config=_a			)
							model.to(_a			)
							model.eval()
							_SCREAMING_SNAKE_CASE							   =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				:     Optional[Any]							, _a				:     Any							, _a				:     Any							, _a				:     Union[str, Any]							, _a				:     Dict							, _a				:     int							, _a				:     List[str]							, _a				:     Optional[int]			)     ->   Optional[Any]:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.num_choices
							_SCREAMING_SNAKE_CASE							   =AlbertForMultipleChoice(config=_a			)
							model.to(_a			)
							model.eval()
							_SCREAMING_SNAKE_CASE							   =input_ids.unsqueeze(1			).expand(-1							, self.num_choices							, -1			).contiguous()
							_SCREAMING_SNAKE_CASE							   =token_type_ids.unsqueeze(1			).expand(-1							, self.num_choices							, -1			).contiguous()
							_SCREAMING_SNAKE_CASE							   =input_mask.unsqueeze(1			).expand(-1							, self.num_choices							, -1			).contiguous()
							_SCREAMING_SNAKE_CASE							   =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				:     Tuple			)     ->   List[Any]:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.prepare_config_and_inputs()
							(
							    (
							    _SCREAMING_SNAKE_CASE						
							)   ,						(
							    _SCREAMING_SNAKE_CASE						
							)   ,						(
							    _SCREAMING_SNAKE_CASE						
							)   ,						(
							    _SCREAMING_SNAKE_CASE						
							)   ,						(
							    _SCREAMING_SNAKE_CASE						
							)   ,						(
							    _SCREAMING_SNAKE_CASE						
							)   ,						(
							    _SCREAMING_SNAKE_CASE						
							)   ,												
							)							   =config_and_inputs
							_SCREAMING_SNAKE_CASE							   ={'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__					=    (
		    (
		        AlbertModel,
		        AlbertForPreTraining,
		        AlbertForMaskedLM,
		        AlbertForMultipleChoice,
		        AlbertForSequenceClassification,
		        AlbertForTokenClassification,
		        AlbertForQuestionAnswering,
		    )
		    if is_torch_available()
		    else ()
		)
		A__					=    (
		    {
		        'feature-extraction': AlbertModel,
		        'fill-mask': AlbertForMaskedLM,
		        'question-answering': AlbertForQuestionAnswering,
		        'text-classification': AlbertForSequenceClassification,
		        'token-classification': AlbertForTokenClassification,
		        'zero-shot': AlbertForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)
		A__					=    True





		def 						A  (		self				:     Tuple							, _a				:     Optional[int]							, _a				:     List[Any]							, _a				:     List[str]=False			)     ->   Dict:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =super()._prepare_for_class(_a							, _a							, return_labels=_a			)

							if return_labels:
												if model_class in get_values(_a			):
																	_SCREAMING_SNAKE_CASE							   =torch.zeros(
																	    (self.model_tester.batch_size, self.model_tester.seq_length)							, dtype=torch.long							, device=_a			)
																	_SCREAMING_SNAKE_CASE							   =torch.zeros(
																	    self.model_tester.batch_size							, dtype=torch.long							, device=_a			)
							return inputs_dict





		def 						A  (		self				:     Tuple			)     ->   Optional[int]:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =AlbertModelTester(self			)
							_SCREAMING_SNAKE_CASE							   =ConfigTester(self							, config_class=_a							, hidden_size=37			)





		def 						A  (		self				:     Optional[Any]			)     ->   Any:





							'''simple docstring'''






							self.config_tester.run_common_tests()





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





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*_a			)





		def 						A  (		self				:     Any			)     ->   Dict:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_pretraining(*_a			)





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





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*_a			)





		def 						A  (		self				:     Dict			)     ->   str:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_multiple_choice(*_a			)





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





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*_a			)





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





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*_a			)





		def 						A  (		self				:     Tuple			)     ->   Optional[int]:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =self.model_tester.prepare_config_and_inputs()
							for type in ["absolute", "relative_key", "relative_key_query"]:
												_SCREAMING_SNAKE_CASE							   =type
												self.model_tester.create_and_check_model(*_a			)





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





							'''simple docstring'''






							for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												_SCREAMING_SNAKE_CASE							   =AlbertModel.from_pretrained(_a			)
												self.assertIsNotNone(_a			)







@require_torch
class 							A__   (	unittest.TestCase  ):





		@slow
		def 						A  (		self				:     Optional[int]			)     ->   Any:





							'''simple docstring'''






							_SCREAMING_SNAKE_CASE							   =AlbertModel.from_pretrained('albert-base-v2'			)
							_SCREAMING_SNAKE_CASE							   =torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]			)
							_SCREAMING_SNAKE_CASE							   =torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]			)
							with torch.no_grad():
												_SCREAMING_SNAKE_CASE							   =model(_a							, attention_mask=_a			)[0]
							_SCREAMING_SNAKE_CASE							   =torch.Size((1, 11, 768)			)
							self.assertEqual(output.shape							, _a			)
							_SCREAMING_SNAKE_CASE							   =torch.tensor(
							    [[[-0.65_13, 1.50_35, -0.27_66], [-0.65_15, 1.50_46, -0.27_80], [-0.65_12, 1.50_49, -0.27_84]]]			)

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



'''simple docstring'''
from ...utils import logging
from ..ta.modeling_tf_ta import TFTaEncoderModel, TFTaForConditionalGeneration, TFTaModel
from .configuration_mta import MTaConfig


lowerCamelCase			:				Optional[Any] 			=					logging.get_logger(__name__)

lowerCamelCase			:				Optional[Any] 			=					"T5Config"







class 							A__   (	A__  ):
  A__					=    'mt5'
  A__					=    MTaConfig







class 							A__   (	A__  ):
  A__					=    'mt5'
  A__					=    MTaConfig







class 							A__   (	A__  ):
  A__					=    'mt5'
  A__					=    MTaConfig
