



"""simple docstring"""
import unittest

import numpy as np

from transformers import AlbertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
      import jax.numpy as jnp

      from transformers.models.albert.modeling_flax_albert import (
          FlaxAlbertForMaskedLM,
          FlaxAlbertForMultipleChoice,
          FlaxAlbertForPreTraining,
          FlaxAlbertForQuestionAnswering,
          FlaxAlbertForSequenceClassification,
          FlaxAlbertForTokenClassification,
          FlaxAlbertModel,
      )



class    SCREAMING_SNAKE_CASE__						(				unittest.TestCase				):

   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=32   ,  _SCREAMING_SNAKE_CASE=5   ,  _SCREAMING_SNAKE_CASE=4   ,  _SCREAMING_SNAKE_CASE=37   ,  _SCREAMING_SNAKE_CASE="gelu"   ,  _SCREAMING_SNAKE_CASE=0.1   ,  _SCREAMING_SNAKE_CASE=0.1   ,  _SCREAMING_SNAKE_CASE=512   ,  _SCREAMING_SNAKE_CASE=16   ,  _SCREAMING_SNAKE_CASE=2   ,  _SCREAMING_SNAKE_CASE=0.02   ,  _SCREAMING_SNAKE_CASE=4   ,  )						->   Any:





    '''simple docstring'''




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

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Tuple:





    '''simple docstring'''




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

    UpperCAmelCase			:      Dict			=			None
    if self.use_attention_mask:
     UpperCAmelCase			:      Optional[Any]			=			random_attention_mask([self.batch_size, self.seq_length]		)

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

    UpperCAmelCase			:      List[str]			=			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   ,  is_decoder=_SCREAMING_SNAKE_CASE   ,  initializer_range=self.initializer_range   ,  )

    return config, input_ids, token_type_ids, attention_mask




   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[str]:





    '''simple docstring'''




    UpperCAmelCase			:      str			=			self.prepare_config_and_inputs()
    UpperCAmelCase			:      List[Any]			=			config_and_inputs
    UpperCAmelCase			:      Optional[Any]			=			{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": attention_mask}
    return config, inputs_dict



@require_flax
class    SCREAMING_SNAKE_CASE__						(				UpperCAmelCase__   ,    unittest.TestCase				):
   __lowerCAmelCase						:     Tuple		=		(
       (
           FlaxAlbertModel,
           FlaxAlbertForPreTraining,
           FlaxAlbertForMaskedLM,
           FlaxAlbertForMultipleChoice,
           FlaxAlbertForQuestionAnswering,
           FlaxAlbertForSequenceClassification,
           FlaxAlbertForTokenClassification,
           FlaxAlbertForQuestionAnswering,
       )
       if is_flax_available()
       else ()
   )

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   str:





    '''simple docstring'''




    UpperCAmelCase			:      Optional[int]			=			FlaxAlbertModelTester(self		)




   @slow
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[str]:





    '''simple docstring'''




    for model_class_name in self.all_model_classes:
     UpperCAmelCase			:      str			=			model_class_name.from_pretrained("""albert-base-v2"""		)
     UpperCAmelCase			:      Union[str, Any]			=			model(np.ones((1, 1)		)		)
     self.assertIsNotNone(_SCREAMING_SNAKE_CASE		)



@require_flax
class    SCREAMING_SNAKE_CASE__						(				unittest.TestCase				):

   @slow
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[str]:





    '''simple docstring'''




    UpperCAmelCase			:      Dict			=			FlaxAlbertModel.from_pretrained("""albert-base-v2"""		)
    UpperCAmelCase			:      Optional[Any]			=			np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]		)
    UpperCAmelCase			:      Optional[Any]			=			np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
    UpperCAmelCase			:      str			=			model(_SCREAMING_SNAKE_CASE   ,  attention_mask=_SCREAMING_SNAKE_CASE		)[0]
    UpperCAmelCase			:      List[Any]			=			(1, 11, 768)
    self.assertEqual(output.shape   ,  _SCREAMING_SNAKE_CASE		)
    UpperCAmelCase			:      Dict			=			np.array(
        [[[-0.6513, 1.5035, -0.2766], [-0.6515, 1.5046, -0.2780], [-0.6512, 1.5049, -0.2784]]]		)

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





"""simple docstring"""
def    _snake_case		(		UpperCamelCase		:	int    ,	UpperCamelCase		:	int		):
 return 1 if input_a == input_a else 0

def    _snake_case		(		):
 assert xnor_gate(0    ,	0		) == 1
 assert xnor_gate(0    ,	1		) == 0
 assert xnor_gate(1    ,	0		) == 0
 assert xnor_gate(1    ,	1		) == 1


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