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







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







							def 				snake_case  (				self     :    Optional[int]		):
										lowerCamelCase						:Tuple						  =     ids_tensor([self.batch_size, self.seq_length]	,					self.vocab_size		)

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

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

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

										lowerCamelCase						:Any						  =     self.get_config()

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







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







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







							def 				snake_case  (				self     :    int	,					__snake_case     :    Any	,					__snake_case     :    Union[str, Any]	,					__snake_case     :    Any	,					__snake_case     :    Optional[Any]	,					__snake_case     :    int	,					__snake_case     :    List[str]	,					__snake_case     :    List[str]		):
										lowerCamelCase						:List[Any]						  =     self.num_labels
										lowerCamelCase						:Optional[Any]						  =     AlbertForTokenClassification(config=_lowercase		)
										model.to(_lowercase		)
										model.eval()
										lowerCamelCase						:List[Any]						  =     model(_lowercase	,					attention_mask=_lowercase	,					token_type_ids=_lowercase	,					labels=_lowercase		)
										self.parent.assertEqual(result.logits.shape	,					(self.batch_size, self.seq_length, self.num_labels)		)







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







							def 				snake_case  (				self     :    List[str]		):
										lowerCamelCase						:List[Any]						  =     self.prepare_config_and_inputs()
										(
										    lowerCamelCase      
										)						:int						  =     config_and_inputs
										lowerCamelCase						:Dict						  =     {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
										return config, inputs_dict


@require_torch
class   _lowerCAmelCase		(     UpperCAmelCase_      ,   UpperCAmelCase_      ,   unittest.TestCase				):
							_UpperCAmelCase						    =     (
							    (
							        AlbertModel,
							        AlbertForPreTraining,
							        AlbertForMaskedLM,
							        AlbertForMultipleChoice,
							        AlbertForSequenceClassification,
							        AlbertForTokenClassification,
							        AlbertForQuestionAnswering,
							    )
							    if is_torch_available()
							    else ()
							)
							_UpperCAmelCase						    =     (
							    {
							        'feature-extraction': AlbertModel,
							        'fill-mask': AlbertForMaskedLM,
							        'question-answering': AlbertForQuestionAnswering,
							        'text-classification': AlbertForSequenceClassification,
							        'token-classification': AlbertForTokenClassification,
							        'zero-shot': AlbertForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							_UpperCAmelCase						    =     True







							def 				snake_case  (				self     :    Optional[int]	,					__snake_case     :    List[str]	,					__snake_case     :    Dict	,					__snake_case     :    Dict=False		):
										lowerCamelCase						:List[Any]						  =     super()._prepare_for_class(_lowercase	,					_lowercase	,					return_labels=_lowercase		)

										if return_labels:
													if model_class in get_values(_lowercase		):
																lowerCamelCase						:Optional[Any]						  =     torch.zeros(
																    (self.model_tester.batch_size, self.model_tester.seq_length)	,					dtype=torch.long	,					device=_lowercase		)
																lowerCamelCase						:Dict						  =     torch.zeros(
																    self.model_tester.batch_size	,					dtype=torch.long	,					device=_lowercase		)
										return inputs_dict







							def 				snake_case  (				self     :    List[str]		):
										lowerCamelCase						:List[str]						  =     AlbertModelTester(self		)
										lowerCamelCase						:str						  =     ConfigTester(self	,					config_class=_lowercase	,					hidden_size=37		)







							def 				snake_case  (				self     :    int		):
										self.config_tester.run_common_tests()







							def 				snake_case  (				self     :    Optional[Any]		):
										lowerCamelCase						:Optional[Any]						  =     self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*_lowercase		)







							def 				snake_case  (				self     :    List[Any]		):
										lowerCamelCase						:List[str]						  =     self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_pretraining(*_lowercase		)







							def 				snake_case  (				self     :    Optional[int]		):
										lowerCamelCase						:Union[str, Any]						  =     self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_masked_lm(*_lowercase		)







							def 				snake_case  (				self     :    Dict		):
										lowerCamelCase						:Optional[Any]						  =     self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_multiple_choice(*_lowercase		)







							def 				snake_case  (				self     :    Union[str, Any]		):
										lowerCamelCase						:Tuple						  =     self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_question_answering(*_lowercase		)







							def 				snake_case  (				self     :    Dict		):
										lowerCamelCase						:List[str]						  =     self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_sequence_classification(*_lowercase		)







							def 				snake_case  (				self     :    str		):
										lowerCamelCase						:Any						  =     self.model_tester.prepare_config_and_inputs()
										for type in ["absolute", "relative_key", "relative_key_query"]:
													lowerCamelCase						:Tuple						  =     type
													self.model_tester.create_and_check_model(*_lowercase		)







							@slow
							def 				snake_case  (				self     :    List[Any]		):
										for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													lowerCamelCase						:Tuple						  =     AlbertModel.from_pretrained(_lowercase		)
													self.assertIsNotNone(_lowercase		)


@require_torch
class   _lowerCAmelCase		(     unittest.TestCase				):







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




from maths.prime_factors import prime_factors





def  _lowerCamelCase					(   a_				: int):
			if not isinstance(a_						,			a_):
						lowerCamelCase						:Tuple						  =     F"Input value of [number={number}] must be an integer"
						raise TypeError(a_)
			if number < 1:
						raise ValueError('''Input must be a positive integer''')
			return -1 if len(prime_factors(a_)) % 2 else 1


if __name__ == "__main__":
			import doctest

			doctest.testmod()



