




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


														"""simple docstring"""


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







							def      __lowerCAmelCase    (						self :						List[str]      )    ->							Dict:


														"""simple docstring"""


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

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

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

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

														_a			  =       self.get_config()

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







							def      __lowerCAmelCase    (						self :						Optional[Any]      )    ->							Union[str, 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      __lowerCAmelCase    (						self :						Union[str, Any]							,    lowerCAmelCase_ :						Optional[Any]							,    lowerCAmelCase_ :						List[Any]							,    lowerCAmelCase_ :						Optional[Any]							,    lowerCAmelCase_ :						str							,    lowerCAmelCase_ :						str							,    lowerCAmelCase_ :						Optional[int]							,    lowerCAmelCase_ :						Any      )    ->							List[str]:


														"""simple docstring"""


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


														"""simple docstring"""


														_a			  =       AlbertForPreTraining(config=lowerCAmelCase_      )
														model.to(lowerCAmelCase_      )
														model.eval()
														_a			  =       model(
														    lowerCAmelCase_							,    attention_mask=lowerCAmelCase_							,    token_type_ids=lowerCAmelCase_							,    labels=lowerCAmelCase_							,    sentence_order_label=lowerCAmelCase_							,    )
														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 :						int							,    lowerCAmelCase_ :						int							,    lowerCAmelCase_ :						List[str]							,    lowerCAmelCase_ :						Tuple							,    lowerCAmelCase_ :						Dict							,    lowerCAmelCase_ :						Dict							,    lowerCAmelCase_ :						int							,    lowerCAmelCase_ :						str      )    ->							Union[str, Any]:


														"""simple docstring"""


														_a			  =       AlbertForMaskedLM(config=lowerCAmelCase_      )
														model.to(lowerCAmelCase_      )
														model.eval()
														_a			  =       model(lowerCAmelCase_							,    attention_mask=lowerCAmelCase_							,    token_type_ids=lowerCAmelCase_							,    labels=lowerCAmelCase_      )
														self.parent.assertEqual(result.logits.shape							,    (self.batch_size, self.seq_length, self.vocab_size)      )







							def      __lowerCAmelCase    (						self :						List[str]							,    lowerCAmelCase_ :						Union[str, Any]							,    lowerCAmelCase_ :						Optional[int]							,    lowerCAmelCase_ :						List[str]							,    lowerCAmelCase_ :						List[Any]							,    lowerCAmelCase_ :						Any							,    lowerCAmelCase_ :						int							,    lowerCAmelCase_ :						int      )    ->							Dict:


														"""simple docstring"""


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


														"""simple docstring"""


														_a			  =       self.num_labels
														_a			  =       AlbertForSequenceClassification(lowerCAmelCase_      )
														model.to(lowerCAmelCase_      )
														model.eval()
														_a			  =       model(lowerCAmelCase_							,    attention_mask=lowerCAmelCase_							,    token_type_ids=lowerCAmelCase_							,    labels=lowerCAmelCase_      )
														self.parent.assertEqual(result.logits.shape							,    (self.batch_size, self.num_labels)      )







							def      __lowerCAmelCase    (						self :						Optional[Any]							,    lowerCAmelCase_ :						int							,    lowerCAmelCase_ :						str							,    lowerCAmelCase_ :						Optional[Any]							,    lowerCAmelCase_ :						Tuple							,    lowerCAmelCase_ :						List[Any]							,    lowerCAmelCase_ :						Dict							,    lowerCAmelCase_ :						int      )    ->							str:


														"""simple docstring"""


														_a			  =       self.num_labels
														_a			  =       AlbertForTokenClassification(config=lowerCAmelCase_      )
														model.to(lowerCAmelCase_      )
														model.eval()
														_a			  =       model(lowerCAmelCase_							,    attention_mask=lowerCAmelCase_							,    token_type_ids=lowerCAmelCase_							,    labels=lowerCAmelCase_      )
														self.parent.assertEqual(result.logits.shape							,    (self.batch_size, self.seq_length, self.num_labels)      )







							def      __lowerCAmelCase    (						self :						Optional[Any]							,    lowerCAmelCase_ :						Any							,    lowerCAmelCase_ :						Optional[int]							,    lowerCAmelCase_ :						List[str]							,    lowerCAmelCase_ :						str							,    lowerCAmelCase_ :						Tuple							,    lowerCAmelCase_ :						Tuple							,    lowerCAmelCase_ :						Any      )    ->							Any:


														"""simple docstring"""


														_a			  =       self.num_choices
														_a			  =       AlbertForMultipleChoice(config=lowerCAmelCase_      )
														model.to(lowerCAmelCase_      )
														model.eval()
														_a			  =       input_ids.unsqueeze(1      ).expand(-1							,    self.num_choices							,    -1      ).contiguous()
														_a			  =       token_type_ids.unsqueeze(1      ).expand(-1							,    self.num_choices							,    -1      ).contiguous()
														_a			  =       input_mask.unsqueeze(1      ).expand(-1							,    self.num_choices							,    -1      ).contiguous()
														_a			  =       model(
														    lowerCAmelCase_							,    attention_mask=lowerCAmelCase_							,    token_type_ids=lowerCAmelCase_							,    labels=lowerCAmelCase_							,    )
														self.parent.assertEqual(result.logits.shape							,    (self.batch_size, self.num_choices)      )







							def      __lowerCAmelCase    (						self :						Optional[Any]      )    ->							Union[str, Any]:


														"""simple docstring"""


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







							def      __lowerCAmelCase    (						self :						Tuple							,    lowerCAmelCase_ :						Union[str, Any]							,    lowerCAmelCase_ :						Union[str, Any]							,    lowerCAmelCase_ :						Any=False      )    ->							List[Any]:


														"""simple docstring"""


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

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







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


														"""simple docstring"""


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







							def      __lowerCAmelCase    (						self :						Optional[Any]      )    ->							List[Any]:


														"""simple docstring"""


														self.config_tester.run_common_tests()







							def      __lowerCAmelCase    (						self :						str      )    ->							str:


														"""simple docstring"""


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







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


														"""simple docstring"""


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







							def      __lowerCAmelCase    (						self :						str      )    ->							Any:


														"""simple docstring"""


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







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


														"""simple docstring"""


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







							def      __lowerCAmelCase    (						self :						Dict      )    ->							Dict:


														"""simple docstring"""


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







							def      __lowerCAmelCase    (						self :						Optional[int]      )    ->							Optional[int]:


														"""simple docstring"""


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







							def      __lowerCAmelCase    (						self :						List[Any]      )    ->							List[str]:


														"""simple docstring"""


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







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


														"""simple docstring"""


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



@require_torch
class     A					(	unittest.TestCase					):







							@slow
							def      __lowerCAmelCase    (						self :						Dict      )    ->							str:


														"""simple docstring"""


														_a			  =       AlbertModel.from_pretrained('''albert-base-v2'''      )
														_a			  =       torch.tensor([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]]      )
														_a			  =       torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
														with torch.no_grad():
																					_a			  =       model(lowerCAmelCase_							,    attention_mask=lowerCAmelCase_      )[0]
														_a			  =       torch.Size((1, 11, 7_68)      )
														self.assertEqual(output.shape							,    lowerCAmelCase_      )
														_a			  =       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]							,    lowerCAmelCase_							,    atol=1e-4      )      )







'''simple docstring'''


from ..utils import DummyObject, requires_backends

class     A					(	metaclass=_a					):
							lowercase_           =       ['torch', 'torchsde']







							def __init__(						self :						Optional[Any]							,    *lowerCAmelCase_ :						Any							,    **lowerCAmelCase_ :						Tuple      )    ->							Dict:


														"""simple docstring"""


														requires_backends(self							,    ['''torch''', '''torchsde''']      )







							@classmethod
							def      __lowerCAmelCase    (						cls :						Dict							,    *lowerCAmelCase_ :						Optional[int]							,    **lowerCAmelCase_ :						Optional[Any]      )    ->							int:


														"""simple docstring"""


														requires_backends(cls							,    ['''torch''', '''torchsde''']      )







							@classmethod
							def      __lowerCAmelCase    (						cls :						List[str]							,    *lowerCAmelCase_ :						str							,    **lowerCAmelCase_ :						Optional[Any]      )    ->							Any:


														"""simple docstring"""


														requires_backends(cls							,    ['''torch''', '''torchsde''']      )

