
"""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 ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE=13 ,	_SCREAMING_SNAKE_CASE=7 ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=99 ,	_SCREAMING_SNAKE_CASE=16 ,	_SCREAMING_SNAKE_CASE=36 ,	_SCREAMING_SNAKE_CASE=6 ,	_SCREAMING_SNAKE_CASE=6 ,	_SCREAMING_SNAKE_CASE=6 ,	_SCREAMING_SNAKE_CASE=37 ,	_SCREAMING_SNAKE_CASE="gelu" ,	_SCREAMING_SNAKE_CASE=0.1 ,	_SCREAMING_SNAKE_CASE=0.1 ,	_SCREAMING_SNAKE_CASE=5_12 ,	_SCREAMING_SNAKE_CASE=16 ,	_SCREAMING_SNAKE_CASE=2 ,	_SCREAMING_SNAKE_CASE=0.02 ,	_SCREAMING_SNAKE_CASE=3 ,	_SCREAMING_SNAKE_CASE=4 ,	_SCREAMING_SNAKE_CASE=None ,	):
			__lowerCAmelCase    :		int		    =   parent
			__lowerCAmelCase    :		Optional[int]		    =   batch_size
			__lowerCAmelCase    :		str		    =   seq_length
			__lowerCAmelCase    :		Union[str, Any]		    =   is_training
			__lowerCAmelCase    :		Any		    =   use_input_mask
			__lowerCAmelCase    :		List[Any]		    =   use_token_type_ids
			__lowerCAmelCase    :		int		    =   use_labels
			__lowerCAmelCase    :		List[Any]		    =   vocab_size
			__lowerCAmelCase    :		List[str]		    =   embedding_size
			__lowerCAmelCase    :		Optional[int]		    =   hidden_size
			__lowerCAmelCase    :		Optional[Any]		    =   num_hidden_layers
			__lowerCAmelCase    :		str		    =   num_hidden_groups
			__lowerCAmelCase    :		str		    =   num_attention_heads
			__lowerCAmelCase    :		List[str]		    =   intermediate_size
			__lowerCAmelCase    :		int		    =   hidden_act
			__lowerCAmelCase    :		Tuple		    =   hidden_dropout_prob
			__lowerCAmelCase    :		Optional[int]		    =   attention_probs_dropout_prob
			__lowerCAmelCase    :		str		    =   max_position_embeddings
			__lowerCAmelCase    :		Tuple		    =   type_vocab_size
			__lowerCAmelCase    :		Tuple		    =   type_sequence_label_size
			__lowerCAmelCase    :		List[Any]		    =   initializer_range
			__lowerCAmelCase    :		Optional[int]		    =   num_labels
			__lowerCAmelCase    :		Tuple		    =   num_choices
			__lowerCAmelCase    :		Optional[int]		    =   scope

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Dict		    =   ids_tensor([self.batch_size, self.seq_length] ,	self.vocab_size				)

			__lowerCAmelCase    :		Any		    =   None
			if self.use_input_mask:
				__lowerCAmelCase    :		int		    =   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    :		List[Any]		    =   None
			__lowerCAmelCase    :		List[Any]		    =   None
			__lowerCAmelCase    :		Tuple		    =   None
			if self.use_labels:
				__lowerCAmelCase    :		List[Any]		    =   ids_tensor([self.batch_size] ,	self.type_sequence_label_size				)
				__lowerCAmelCase    :		Optional[int]		    =   ids_tensor([self.batch_size, self.seq_length] ,	self.num_labels				)
				__lowerCAmelCase    :		Any		    =   ids_tensor([self.batch_size] ,	self.num_choices				)

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

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

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

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

		def 							__lowerCamelCase							(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE				):
			__lowerCAmelCase    :		Any		    =   self.num_labels
			__lowerCAmelCase    :		List[str]		    =   AlbertForTokenClassification(config=_SCREAMING_SNAKE_CASE				)
			model.to(_SCREAMING_SNAKE_CASE				)
			model.eval()
			__lowerCAmelCase    :		int		    =   model(_SCREAMING_SNAKE_CASE ,	attention_mask=_SCREAMING_SNAKE_CASE ,	token_type_ids=_SCREAMING_SNAKE_CASE ,	labels=_SCREAMING_SNAKE_CASE				)
			self.parent.assertEqual(result.logits.shape ,	(self.batch_size, self.seq_length, self.num_labels)				)

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







		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Union[str, Any]		    =   self.prepare_config_and_inputs()
			(
			    (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     
			)    :		Optional[Any]		    =   config_and_inputs
			__lowerCAmelCase    :		List[str]		    =   {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
			return config, inputs_dict




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

		def 							__lowerCamelCase							(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE=False				):
			__lowerCAmelCase    :		Dict		    =   super()._prepare_for_class(_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	return_labels=_SCREAMING_SNAKE_CASE				)

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

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Union[str, Any]		    =   AlbertModelTester(self				)
			__lowerCAmelCase    :		int		    =   ConfigTester(self ,	config_class=_SCREAMING_SNAKE_CASE ,	hidden_size=37				)

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

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Optional[Any]		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Optional[int]		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_pretraining(*_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Optional[int]		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_masked_lm(*_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Optional[int]		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_multiple_choice(*_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Any		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_question_answering(*_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Tuple		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_sequence_classification(*_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		int		    =   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(*_SCREAMING_SNAKE_CASE				)







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




@require_torch
class 				A__ (			unittest.TestCase):

		@slow
		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Tuple		    =   AlbertModel.from_pretrained('albert-base-v2'				)
			__lowerCAmelCase    :		int		    =   torch.tensor([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]]				)
			__lowerCAmelCase    :		List[Any]		    =   torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]				)
			with torch.no_grad():
				__lowerCAmelCase    :		Optional[int]		    =   model(_SCREAMING_SNAKE_CASE ,	attention_mask=_SCREAMING_SNAKE_CASE				)[0]
			__lowerCAmelCase    :		Optional[int]		    =   torch.Size((1, 11, 7_68)				)
			self.assertEqual(output.shape ,	_SCREAMING_SNAKE_CASE				)
			__lowerCAmelCase    :		List[Any]		    =   torch.tensor(
			    [[[-0.6513, 1.5035, -0.2766], [-0.6515, 1.5046, -0.2780], [-0.6512, 1.5049, -0.2784]]]				)

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

"""simple docstring"""







from transformers import HfArgumentParser, TensorFlowBenchmark, TensorFlowBenchmarkArguments
def 					__lowerCAmelCase       ():
	__lowerCAmelCase    :		Tuple		    =   HfArgumentParser(_UpperCamelCase	)
	__lowerCAmelCase    :		Optional[Any]		    =   parser.parse_args_into_dataclasses()[0]
	__lowerCAmelCase    :		int		    =   TensorFlowBenchmark(args=_UpperCamelCase	)
	try:
		__lowerCAmelCase    :		Dict		    =   parser.parse_args_into_dataclasses()[0]
	except ValueError as e:
		__lowerCAmelCase    :		List[Any]		    =   'Arg --no_{0} is no longer used, please use --no-{0} instead.'
		__lowerCAmelCase    :		Union[str, Any]		    =   ' '.join(str(_UpperCamelCase	).split(' '	)[:-1]	)
		__lowerCAmelCase    :		List[str]		    =   ''
		__lowerCAmelCase    :		Any		    =   eval(str(_UpperCamelCase	).split(' '	)[-1]	)
		__lowerCAmelCase    :		Dict		    =   []
		for arg in depreciated_args:
			# arg[2:] removes '--'
			if arg[2:] in TensorFlowBenchmark.deprecated_args:
				# arg[5:] removes '--no_'
				full_error_msg += arg_error_msg.format(arg[5:]	)
			else:
				wrong_args.append(_UpperCamelCase	)
		if len(_UpperCamelCase	) > 0:
			__lowerCAmelCase    :		Any		    =   full_error_msg + begin_error_msg + str(_UpperCamelCase	)
		raise ValueError(_UpperCamelCase	)
	benchmark.run()


if __name__ == "__main__":
							main()