

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

				def __init__(     self							:    Optional[Any]					,  UpperCamelCase__							:    int					,  UpperCamelCase__							:    List[Any]=1_3					,  UpperCamelCase__							:    List[Any]=7					,  UpperCamelCase__							:    int=True					,  UpperCamelCase__							:    Tuple=True					,  UpperCamelCase__							:    Optional[Any]=True					,  UpperCamelCase__							:    List[str]=True					,  UpperCamelCase__							:    List[str]=9_9					,  UpperCamelCase__							:    List[str]=1_6					,  UpperCamelCase__							:    Dict=3_6					,  UpperCamelCase__							:    Optional[int]=6					,  UpperCamelCase__							:    List[str]=6					,  UpperCamelCase__							:    Dict=6					,  UpperCamelCase__							:    List[Any]=3_7					,  UpperCamelCase__							:    Dict="gelu"					,  UpperCamelCase__							:    Optional[int]=0.1					,  UpperCamelCase__							:    List[Any]=0.1					,  UpperCamelCase__							:    str=5_1_2					,  UpperCamelCase__							:    Union[str, Any]=1_6					,  UpperCamelCase__							:    Optional[Any]=2					,  UpperCamelCase__							:    Union[str, Any]=0.02					,  UpperCamelCase__							:    Tuple=3					,  UpperCamelCase__							:    Dict=4					,  UpperCamelCase__							:    Tuple=None					,  )->       int:



						'''simple docstring'''


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

				def 							lowercase_					(     self							:    Tuple)->       Optional[Any]:



						'''simple docstring'''


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

						__lowerCAmelCase:	List[Any]   				=      None
						if self.use_input_mask:
								__lowerCAmelCase:	Dict   				=      random_attention_mask([self.batch_size, self.seq_length])

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

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

						__lowerCAmelCase:	Optional[int]   				=      self.get_config()

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

				def 							lowercase_					(     self							:    Optional[int])->       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 							lowercase_					(     self							:    Tuple					,  UpperCamelCase__							:    List[str]					,  UpperCamelCase__							:    Any					,  UpperCamelCase__							:    Optional[Any]					,  UpperCamelCase__							:    str					,  UpperCamelCase__							:    Dict					,  UpperCamelCase__							:    Union[str, Any]					,  UpperCamelCase__							:    Optional[int])->       Tuple:



						'''simple docstring'''


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



						'''simple docstring'''


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



						'''simple docstring'''


						__lowerCAmelCase:	List[str]   				=      AlbertForMaskedLM(config=UpperCamelCase__)
						model.to(UpperCamelCase__)
						model.eval()
						__lowerCAmelCase:	Any   				=      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 							lowercase_					(     self							:    List[Any]					,  UpperCamelCase__							:    List[str]					,  UpperCamelCase__							:    Optional[int]					,  UpperCamelCase__							:    List[str]					,  UpperCamelCase__							:    Dict					,  UpperCamelCase__							:    Optional[int]					,  UpperCamelCase__							:    Dict					,  UpperCamelCase__							:    List[Any])->       Tuple:



						'''simple docstring'''


						__lowerCAmelCase:	Dict   				=      AlbertForQuestionAnswering(config=UpperCamelCase__)
						model.to(UpperCamelCase__)
						model.eval()
						__lowerCAmelCase:	List[str]   				=      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 							lowercase_					(     self							:    List[Any]					,  UpperCamelCase__							:    Tuple					,  UpperCamelCase__							:    Tuple					,  UpperCamelCase__							:    str					,  UpperCamelCase__							:    str					,  UpperCamelCase__							:    List[str]					,  UpperCamelCase__							:    Tuple					,  UpperCamelCase__							:    str)->       Union[str, Any]:



						'''simple docstring'''


						__lowerCAmelCase:	Union[str, Any]   				=      self.num_labels
						__lowerCAmelCase:	Optional[int]   				=      AlbertForSequenceClassification(UpperCamelCase__)
						model.to(UpperCamelCase__)
						model.eval()
						__lowerCAmelCase:	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 							lowercase_					(     self							:    Optional[int]					,  UpperCamelCase__							:    Union[str, Any]					,  UpperCamelCase__							:    List[Any]					,  UpperCamelCase__							:    Dict					,  UpperCamelCase__							:    List[str]					,  UpperCamelCase__							:    Dict					,  UpperCamelCase__							:    Dict					,  UpperCamelCase__							:    str)->       int:



						'''simple docstring'''


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



						'''simple docstring'''


						__lowerCAmelCase:	str   				=      self.num_choices
						__lowerCAmelCase:	int   				=      AlbertForMultipleChoice(config=UpperCamelCase__)
						model.to(UpperCamelCase__)
						model.eval()
						__lowerCAmelCase:	Dict   				=      input_ids.unsqueeze(1).expand(-1					,  self.num_choices					,  -1).contiguous()
						__lowerCAmelCase:	Union[str, Any]   				=      token_type_ids.unsqueeze(1).expand(-1					,  self.num_choices					,  -1).contiguous()
						__lowerCAmelCase:	Optional[Any]   				=      input_mask.unsqueeze(1).expand(-1					,  self.num_choices					,  -1).contiguous()
						__lowerCAmelCase:	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 							lowercase_					(     self							:    str)->       Union[str, Any]:



						'''simple docstring'''


						__lowerCAmelCase:	Any   				=      self.prepare_config_and_inputs()
						(
						    (
						    __lowerCAmelCase
						)				,			(
						    __lowerCAmelCase
						)				,			(
						    __lowerCAmelCase
						)				,			(
						    __lowerCAmelCase
						)				,			(
						    __lowerCAmelCase
						)				,			(
						    __lowerCAmelCase
						)				,			(
						    __lowerCAmelCase
						)				,			
						):	Optional[int]   				=      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    snake_case     (    __snake_case,							__snake_case,							unittest.TestCase  ):
				SCREAMING_SNAKE_CASE_       :				List[Any]       				=  (
				    (
				        AlbertModel,
				        AlbertForPreTraining,
				        AlbertForMaskedLM,
				        AlbertForMultipleChoice,
				        AlbertForSequenceClassification,
				        AlbertForTokenClassification,
				        AlbertForQuestionAnswering,
				    )
				    if is_torch_available()
				    else ()
				)
				SCREAMING_SNAKE_CASE_       :				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 {}
				)
				SCREAMING_SNAKE_CASE_       :				Dict       				=  True

				def 							lowercase_					(     self							:    Union[str, Any]					,  UpperCamelCase__							:    str					,  UpperCamelCase__							:    Union[str, Any]					,  UpperCamelCase__							:    List[Any]=False)->       str:



						'''simple docstring'''


						__lowerCAmelCase:	Any   				=      super()._prepare_for_class(UpperCamelCase__					,  UpperCamelCase__					,  return_labels=UpperCamelCase__)

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

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



						'''simple docstring'''


						__lowerCAmelCase:	int   				=      AlbertModelTester(self)
						__lowerCAmelCase:	int   				=      ConfigTester(self					,  config_class=UpperCamelCase__					,  hidden_size=3_7)

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



						'''simple docstring'''


						self.config_tester.run_common_tests()

				def 							lowercase_					(     self							:    Any)->       int:



						'''simple docstring'''


						__lowerCAmelCase:	Tuple   				=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*UpperCamelCase__)

				def 							lowercase_					(     self							:    Any)->       int:



						'''simple docstring'''


						__lowerCAmelCase:	List[str]   				=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_pretraining(*UpperCamelCase__)

				def 							lowercase_					(     self							:    List[Any])->       Dict:



						'''simple docstring'''


						__lowerCAmelCase:	str   				=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase__)

				def 							lowercase_					(     self							:    Tuple)->       Tuple:



						'''simple docstring'''


						__lowerCAmelCase:	Any   				=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_multiple_choice(*UpperCamelCase__)

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



						'''simple docstring'''


						__lowerCAmelCase:	List[str]   				=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*UpperCamelCase__)

				def 							lowercase_					(     self							:    Dict)->       List[Any]:



						'''simple docstring'''


						__lowerCAmelCase:	str   				=      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase__)

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



						'''simple docstring'''


						__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(*UpperCamelCase__)




				@slow
				def 							lowercase_					(     self							:    List[Any])->       List[Any]:



						'''simple docstring'''


						for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								__lowerCAmelCase:	int   				=      AlbertModel.from_pretrained(UpperCamelCase__)
								self.assertIsNotNone(UpperCamelCase__)





@require_torch
class    snake_case     (    unittest.TestCase  ):

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



						'''simple docstring'''


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





"""simple docstring"""


def    a__   (   __SCREAMING_SNAKE_CASE ,			__SCREAMING_SNAKE_CASE			)     ->     int:
		return int((input_a, input_a).count(0			) == 0			)






def    a__   (   )     ->     None:
		assert and_gate(0 ,			0			) == 0
		assert and_gate(0 ,			1			) == 0
		assert and_gate(1 ,			0			) == 0
		assert and_gate(1 ,			1			) == 1


if __name__ == "__main__":
			test_and_gate()
			print(and_gate(1, 0))
			print(and_gate(0, 0))
			print(and_gate(0, 1))
			print(and_gate(1, 1))


