





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

			"""simple docstring"""







			def __init__(      self						,   _A						,   _A=1_3						,   _A=7						,   _A=True						,   _A=True						,   _A=True						,   _A=True						,   _A=9_9						,   _A=1_6						,   _A=3_6						,   _A=6						,   _A=6						,   _A=6						,   _A=3_7						,   _A="gelu"						,   _A=0.1						,   _A=0.1						,   _A=5_1_2						,   _A=1_6						,   _A=2						,   _A=0.02						,   _A=3						,   _A=4						,   _A=None						,   ):






									'''simple docstring'''







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







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		Optional[int]				   =			ids_tensor([self.batch_size, self.seq_length]						,   self.vocab_size    )

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

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

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

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

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







			def   _a      (      self    ):






									'''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						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A    ):






									'''simple docstring'''







									UpperCamelCase				:		List[str]				   =			AlbertModel(config=_UpperCAmelCase    )
									model.to(_UpperCAmelCase    )
									model.eval()
									UpperCamelCase				:		Optional[Any]				   =			model(_UpperCAmelCase						,   attention_mask=_UpperCAmelCase						,   token_type_ids=_UpperCAmelCase    )
									UpperCamelCase				:		Union[str, Any]				   =			model(_UpperCAmelCase						,   token_type_ids=_UpperCAmelCase    )
									UpperCamelCase				:		Optional[Any]				   =			model(_UpperCAmelCase    )
									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    ):






									'''simple docstring'''







									UpperCamelCase				:		Dict				   =			AlbertForPreTraining(config=_UpperCAmelCase    )
									model.to(_UpperCAmelCase    )
									model.eval()
									UpperCamelCase				:		Dict				   =			model(
									    _UpperCAmelCase						,   attention_mask=_UpperCAmelCase						,   token_type_ids=_UpperCAmelCase						,   labels=_UpperCAmelCase						,   sentence_order_label=_UpperCAmelCase						,   )
									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    ):






									'''simple docstring'''







									UpperCamelCase				:		List[str]				   =			AlbertForMaskedLM(config=_UpperCAmelCase    )
									model.to(_UpperCAmelCase    )
									model.eval()
									UpperCamelCase				:		str				   =			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   _a      (      self						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A    ):






									'''simple docstring'''







									UpperCamelCase				:		List[str]				   =			AlbertForQuestionAnswering(config=_UpperCAmelCase    )
									model.to(_UpperCAmelCase    )
									model.eval()
									UpperCamelCase				:		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   _a      (      self						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A    ):






									'''simple docstring'''







									UpperCamelCase				:		Dict				   =			self.num_labels
									UpperCamelCase				:		Any				   =			AlbertForSequenceClassification(_UpperCAmelCase    )
									model.to(_UpperCAmelCase    )
									model.eval()
									UpperCamelCase				:		List[Any]				   =			model(_UpperCAmelCase						,   attention_mask=_UpperCAmelCase						,   token_type_ids=_UpperCAmelCase						,   labels=_UpperCAmelCase    )
									self.parent.assertEqual(result.logits.shape						,   (self.batch_size, self.num_labels)    )







			def   _a      (      self						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A    ):






									'''simple docstring'''







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






									'''simple docstring'''







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






									'''simple docstring'''







									UpperCamelCase				:		List[str]				   =			self.prepare_config_and_inputs()
									(
									    (
									    UpperCamelCase       
									)   ,						(
									    UpperCamelCase       
									)   ,						(
									    UpperCamelCase       
									)   ,						(
									    UpperCamelCase       
									)   ,						(
									    UpperCamelCase       
									)   ,						(
									    UpperCamelCase       
									)   ,						(
									    UpperCamelCase       
									)   ,						       
									)				:		Optional[int]				   =			config_and_inputs
									UpperCamelCase				:		Tuple				   =			{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
									return config, inputs_dict






@require_torch
class 							lowercase__			(   __lowerCAmelCase					,     __lowerCAmelCase					,     unittest.TestCase	):

			"""simple docstring"""
			__lowerCAmelCase     :				Any										=  (
			    (
			        AlbertModel,
			        AlbertForPreTraining,
			        AlbertForMaskedLM,
			        AlbertForMultipleChoice,
			        AlbertForSequenceClassification,
			        AlbertForTokenClassification,
			        AlbertForQuestionAnswering,
			    )
			    if is_torch_available()
			    else ()
			)
			__lowerCAmelCase     :				List[Any]										=  (
			    {
			        '''feature-extraction''': AlbertModel,
			        '''fill-mask''': AlbertForMaskedLM,
			        '''question-answering''': AlbertForQuestionAnswering,
			        '''text-classification''': AlbertForSequenceClassification,
			        '''token-classification''': AlbertForTokenClassification,
			        '''zero-shot''': AlbertForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			__lowerCAmelCase     :				int										=  True







			def   _a      (      self						,   _A						,   _A						,   _A=False    ):






									'''simple docstring'''







									UpperCamelCase				:		Any				   =			super()._prepare_for_class(_UpperCAmelCase						,   _UpperCAmelCase						,   return_labels=_UpperCAmelCase    )

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







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		Any				   =			AlbertModelTester(self    )
									UpperCamelCase				:		int				   =			ConfigTester(self						,   config_class=_UpperCAmelCase						,   hidden_size=3_7    )







			def   _a      (      self    ):






									'''simple docstring'''







									self.config_tester.run_common_tests()







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		List[Any]				   =			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_UpperCAmelCase    )







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		List[str]				   =			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_pretraining(*_UpperCAmelCase    )







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		List[Any]				   =			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_lm(*_UpperCAmelCase    )







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		str				   =			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_multiple_choice(*_UpperCAmelCase    )







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		List[str]				   =			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*_UpperCAmelCase    )







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		int				   =			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*_UpperCAmelCase    )







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		Optional[int]				   =			self.model_tester.prepare_config_and_inputs()
									for type in ["absolute", "relative_key", "relative_key_query"]:
															UpperCamelCase				:		List[Any]				   =			type
															self.model_tester.create_and_check_model(*_UpperCAmelCase    )







			@slow
			def   _a      (      self    ):






									'''simple docstring'''







									for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															UpperCamelCase				:		Tuple				   =			AlbertModel.from_pretrained(_UpperCAmelCase    )
															self.assertIsNotNone(_UpperCAmelCase    )






@require_torch
class 							lowercase__			(   unittest.TestCase	):

			"""simple docstring"""







			@slow
			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		List[Any]				   =			AlbertModel.from_pretrained("""albert-base-v2"""    )
									UpperCamelCase				:		Optional[Any]				   =			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]]    )
									UpperCamelCase				:		Any				   =			torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]    )
									with torch.no_grad():
															UpperCamelCase				:		Optional[Any]				   =			model(_UpperCAmelCase						,   attention_mask=_UpperCAmelCase    )[0]
									UpperCamelCase				:		Union[str, Any]				   =			torch.Size((1, 1_1, 7_6_8)    )
									self.assertEqual(output.shape						,   _UpperCAmelCase    )
									UpperCamelCase				:		str				   =			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]						,   _UpperCAmelCase						,   atol=1e-4    )    )









"""simple docstring"""

import argparse


a							      =     '''docs/source/_static/js/custom.js'''






def 		_snake_case	(   _snake_case				:   Dict				)       ->   Any:






      '''simple docstring'''


      with open(_snake_case							,    encoding='utf-8'							,    newline='\n'				) as f:
            _A     =  f.readlines()
      _A     =  0

      # First let's put the right version
      while not lines[index].startswith('const stableVersion ='				):
            index += 1
      _A     =  F'''const stableVersion = "v{version}"\n'''

      # Then update the dictionary
      while not lines[index].startswith('const versionMapping = {'				):
            index += 1

      # We go until the end
      while not lines[index].startswith('}'				):
            index += 1
      # We add the new version at the end
      lines[index - 1] += F'''    "v{version}": "v{version}",\n'''

      with open(_snake_case							,    'w'							,    encoding='utf-8'							,    newline='\n'				) as f:
            f.writelines(_snake_case				)


if __name__ == "__main__":
       a							      =     argparse.ArgumentParser()
       parser.add_argument('''--version''', help='''Release version.''')
       a							      =     parser.parse_args()
       update_custom_js(args.version)

