



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 				lowercase__       (   unittest.TestCase				):







       '''simple docstring'''


       def __init__(							self      :  Optional[Any]		,    _UpperCAmelCase      :  Any		,    _UpperCAmelCase      :  Optional[int]=13		,    _UpperCAmelCase      :  Dict=7		,    _UpperCAmelCase      :  Optional[Any]=True		,    _UpperCAmelCase      :  Optional[int]=True		,    _UpperCAmelCase      :  Optional[int]=True		,    _UpperCAmelCase      :  Tuple=True		,    _UpperCAmelCase      :  Dict=99		,    _UpperCAmelCase      :  Dict=32		,    _UpperCAmelCase      :  Tuple=5		,    _UpperCAmelCase      :  int=4		,    _UpperCAmelCase      :  List[Any]=37		,    _UpperCAmelCase      :  Dict="gelu"		,    _UpperCAmelCase      :  Any=0.1		,    _UpperCAmelCase      :  List[Any]=0.1		,    _UpperCAmelCase      :  int=512		,    _UpperCAmelCase      :  Dict=16		,    _UpperCAmelCase      :  Tuple=2		,    _UpperCAmelCase      :  List[Any]=0.02		,    _UpperCAmelCase      :  Dict=4		,    )			->						Any:


             '''simple docstring'''




             UpperCAmelCase_      			=							parent
             UpperCAmelCase_      			=							batch_size
             UpperCAmelCase_      			=							seq_length
             UpperCAmelCase_      			=							is_training
             UpperCAmelCase_      			=							use_attention_mask
             UpperCAmelCase_      			=							use_token_type_ids
             UpperCAmelCase_      			=							use_labels
             UpperCAmelCase_      			=							vocab_size
             UpperCAmelCase_      			=							hidden_size
             UpperCAmelCase_      			=							num_hidden_layers
             UpperCAmelCase_      			=							num_attention_heads
             UpperCAmelCase_      			=							intermediate_size
             UpperCAmelCase_      			=							hidden_act
             UpperCAmelCase_      			=							hidden_dropout_prob
             UpperCAmelCase_      			=							attention_probs_dropout_prob
             UpperCAmelCase_      			=							max_position_embeddings
             UpperCAmelCase_      			=							type_vocab_size
             UpperCAmelCase_      			=							type_sequence_label_size
             UpperCAmelCase_      			=							initializer_range
             UpperCAmelCase_      			=							num_choices



       def 					lowercase__    (							self      :  str   )			->						Dict:


             '''simple docstring'''




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

             UpperCAmelCase_      			=							None
             if self.use_attention_mask:
                   UpperCAmelCase_      			=							random_attention_mask([self.batch_size, self.seq_length]   )

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

             UpperCAmelCase_      			=							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=__lowerCAmelCase		,    initializer_range=self.initializer_range		,    )

             return config, input_ids, token_type_ids, attention_mask







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


             '''simple docstring'''




             UpperCAmelCase_      			=							self.prepare_config_and_inputs()
             UpperCAmelCase_			,   UpperCAmelCase_			,   UpperCAmelCase_			,   UpperCAmelCase_      			=							config_and_inputs
             UpperCAmelCase_      			=							{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": attention_mask}
             return config, inputs_dict



@require_flax
class 				lowercase__       (   lowerCAmelCase_    , unittest.TestCase				):







       '''simple docstring'''


       UpperCamelCase						=					(
           (
               FlaxAlbertModel,
               FlaxAlbertForPreTraining,
               FlaxAlbertForMaskedLM,
               FlaxAlbertForMultipleChoice,
               FlaxAlbertForQuestionAnswering,
               FlaxAlbertForSequenceClassification,
               FlaxAlbertForTokenClassification,
               FlaxAlbertForQuestionAnswering,
           )
           if is_flax_available()
           else ()
       )



       def 					lowercase__    (							self      :  Dict   )			->						Any:


             '''simple docstring'''




             UpperCAmelCase_      			=							FlaxAlbertModelTester(self   )







       @slow
       def 					lowercase__    (							self      :  Tuple   )			->						Union[str, Any]:


             '''simple docstring'''




             for model_class_name in self.all_model_classes:
                   UpperCAmelCase_      			=							model_class_name.from_pretrained("albert-base-v2"   )
                   UpperCAmelCase_      			=							model(np.ones((1, 1)   )   )
                   self.assertIsNotNone(__lowerCAmelCase   )



@require_flax
class 				lowercase__       (   unittest.TestCase				):







       '''simple docstring'''


       @slow
       def 					lowercase__    (							self      :  str   )			->						Any:


             '''simple docstring'''




             UpperCAmelCase_      			=							FlaxAlbertModel.from_pretrained("albert-base-v2"   )
             UpperCAmelCase_      			=							np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]   )
             UpperCAmelCase_      			=							np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]   )
             UpperCAmelCase_      			=							model(__lowerCAmelCase		,    attention_mask=__lowerCAmelCase   )[0]
             UpperCAmelCase_      			=							(1, 11, 768)
             self.assertEqual(output.shape		,    __lowerCAmelCase   )
             UpperCAmelCase_      			=							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]		,    __lowerCAmelCase		,    atol=1e-4   )   )









"""simple docstring"""





from ..utils import DummyObject, requires_backends
class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Tuple		,    *_UpperCAmelCase      :  str		,    **_UpperCAmelCase      :  Any   )			->						List[str]:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  List[Any]		,    *_UpperCAmelCase      :  Dict		,    **_UpperCAmelCase      :  Tuple   )			->						List[Any]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  List[Any]		,    *_UpperCAmelCase      :  List[Any]		,    **_UpperCAmelCase      :  str   )			->						int:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Union[str, Any]		,    *_UpperCAmelCase      :  Any		,    **_UpperCAmelCase      :  Tuple   )			->						str:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  str		,    *_UpperCAmelCase      :  Optional[int]		,    **_UpperCAmelCase      :  int   )			->						Any:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  List[str]		,    *_UpperCAmelCase      :  Optional[Any]		,    **_UpperCAmelCase      :  Optional[int]   )			->						Dict:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Union[str, Any]		,    *_UpperCAmelCase      :  Dict		,    **_UpperCAmelCase      :  Dict   )			->						str:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  Optional[int]		,    *_UpperCAmelCase      :  int		,    **_UpperCAmelCase      :  List[Any]   )			->						List[str]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  Dict		,    *_UpperCAmelCase      :  Dict		,    **_UpperCAmelCase      :  Union[str, Any]   )			->						int:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Any		,    *_UpperCAmelCase      :  str		,    **_UpperCAmelCase      :  Tuple   )			->						Optional[int]:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



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


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  int		,    *_UpperCAmelCase      :  Any		,    **_UpperCAmelCase      :  int   )			->						Dict:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  str		,    *_UpperCAmelCase      :  int		,    **_UpperCAmelCase      :  Dict   )			->						Tuple:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



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


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  List[Any]		,    *_UpperCAmelCase      :  int		,    **_UpperCAmelCase      :  int   )			->						Optional[Any]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Dict		,    *_UpperCAmelCase      :  Any		,    **_UpperCAmelCase      :  Optional[Any]   )			->						int:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  List[Any]		,    *_UpperCAmelCase      :  str		,    **_UpperCAmelCase      :  List[str]   )			->						Any:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  List[str]		,    *_UpperCAmelCase      :  str		,    **_UpperCAmelCase      :  Optional[Any]   )			->						Tuple:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Union[str, Any]		,    *_UpperCAmelCase      :  Optional[int]		,    **_UpperCAmelCase      :  Tuple   )			->						str:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  str		,    *_UpperCAmelCase      :  Union[str, Any]		,    **_UpperCAmelCase      :  Union[str, Any]   )			->						List[str]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  List[Any]		,    *_UpperCAmelCase      :  Optional[int]		,    **_UpperCAmelCase      :  Optional[Any]   )			->						str:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Optional[Any]		,    *_UpperCAmelCase      :  str		,    **_UpperCAmelCase      :  int   )			->						Union[str, Any]:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  Union[str, Any]		,    *_UpperCAmelCase      :  Optional[Any]		,    **_UpperCAmelCase      :  List[Any]   )			->						str:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  List[Any]		,    *_UpperCAmelCase      :  Dict		,    **_UpperCAmelCase      :  str   )			->						List[str]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  List[str]		,    *_UpperCAmelCase      :  Optional[int]		,    **_UpperCAmelCase      :  Optional[int]   )			->						Tuple:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  Union[str, Any]		,    *_UpperCAmelCase      :  Optional[int]		,    **_UpperCAmelCase      :  str   )			->						Union[str, Any]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  Optional[int]		,    *_UpperCAmelCase      :  Any		,    **_UpperCAmelCase      :  List[str]   )			->						Optional[int]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Optional[Any]		,    *_UpperCAmelCase      :  Union[str, Any]		,    **_UpperCAmelCase      :  Optional[Any]   )			->						Tuple:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  Optional[int]		,    *_UpperCAmelCase      :  Union[str, Any]		,    **_UpperCAmelCase      :  Dict   )			->						Any:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







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


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Tuple		,    *_UpperCAmelCase      :  List[str]		,    **_UpperCAmelCase      :  Optional[int]   )			->						Tuple:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  Any		,    *_UpperCAmelCase      :  Tuple		,    **_UpperCAmelCase      :  Optional[int]   )			->						Any:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  List[Any]		,    *_UpperCAmelCase      :  int		,    **_UpperCAmelCase      :  int   )			->						int:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Tuple		,    *_UpperCAmelCase      :  int		,    **_UpperCAmelCase      :  Any   )			->						List[Any]:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  str		,    *_UpperCAmelCase      :  int		,    **_UpperCAmelCase      :  str   )			->						Any:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  int		,    *_UpperCAmelCase      :  Dict		,    **_UpperCAmelCase      :  List[Any]   )			->						Dict:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  int		,    *_UpperCAmelCase      :  Any		,    **_UpperCAmelCase      :  int   )			->						Union[str, Any]:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  Optional[int]		,    *_UpperCAmelCase      :  Dict		,    **_UpperCAmelCase      :  Dict   )			->						Dict:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  str		,    *_UpperCAmelCase      :  Dict		,    **_UpperCAmelCase      :  Any   )			->						List[str]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )




