





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




 def __init__(	self			,     _lowerCAmelCase			,     _lowerCAmelCase=13			,     _lowerCAmelCase=7			,     _lowerCAmelCase=True			,     _lowerCAmelCase=True			,     _lowerCAmelCase=True			,     _lowerCAmelCase=True			,     _lowerCAmelCase=99			,     _lowerCAmelCase=32			,     _lowerCAmelCase=5			,     _lowerCAmelCase=4			,     _lowerCAmelCase=37			,     _lowerCAmelCase="gelu"			,     _lowerCAmelCase=0.1			,     _lowerCAmelCase=0.1			,     _lowerCAmelCase=512			,     _lowerCAmelCase=16			,     _lowerCAmelCase=2			,     _lowerCAmelCase=0.02			,     _lowerCAmelCase=4			,     )    ->							List[str]:
     _lowerCAmelCase				=      parent
     _lowerCAmelCase				=      batch_size
     _lowerCAmelCase				=      seq_length
     _lowerCAmelCase				=      is_training
     _lowerCAmelCase				=      use_attention_mask
     _lowerCAmelCase				=      use_token_type_ids
     _lowerCAmelCase				=      use_labels
     _lowerCAmelCase				=      vocab_size
     _lowerCAmelCase				=      hidden_size
     _lowerCAmelCase				=      num_hidden_layers
     _lowerCAmelCase				=      num_attention_heads
     _lowerCAmelCase				=      intermediate_size
     _lowerCAmelCase				=      hidden_act
     _lowerCAmelCase				=      hidden_dropout_prob
     _lowerCAmelCase				=      attention_probs_dropout_prob
     _lowerCAmelCase				=      max_position_embeddings
     _lowerCAmelCase				=      type_vocab_size
     _lowerCAmelCase				=      type_sequence_label_size
     _lowerCAmelCase				=      initializer_range
     _lowerCAmelCase				=      num_choices




 def 							_snake_case   (	self		)    ->							Any:
     _lowerCAmelCase				=      ids_tensor([self.batch_size, self.seq_length]			,     self.vocab_size		)

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

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

     _lowerCAmelCase				=      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 							_snake_case   (	self		)    ->							int:
     _lowerCAmelCase				=      self.prepare_config_and_inputs()
     _lowerCAmelCase			,			_lowerCAmelCase			,			_lowerCAmelCase			,			_lowerCAmelCase				=      config_and_inputs
     _lowerCAmelCase				=      {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": attention_mask}
     return config, inputs_dict







@require_flax
class    lowerCAmelCase_		(		__magic_name__						,unittest.TestCase		):
 __lowerCamelCase						:							Dict         =					(
     (
         FlaxAlbertModel,
         FlaxAlbertForPreTraining,
         FlaxAlbertForMaskedLM,
         FlaxAlbertForMultipleChoice,
         FlaxAlbertForQuestionAnswering,
         FlaxAlbertForSequenceClassification,
         FlaxAlbertForTokenClassification,
         FlaxAlbertForQuestionAnswering,
     )
     if is_flax_available()
     else ()
 )




 def 							_snake_case   (	self		)    ->							Tuple:
     _lowerCAmelCase				=      FlaxAlbertModelTester(self		)





 @slow
 def 							_snake_case   (	self		)    ->							Tuple:
     for model_class_name in self.all_model_classes:
         _lowerCAmelCase				=      model_class_name.from_pretrained("albert-base-v2"		)
         _lowerCAmelCase				=      model(np.ones((1, 1)		)		)
         self.assertIsNotNone(_lowerCAmelCase		)







@require_flax
class    lowerCAmelCase_		(		unittest.TestCase		):




 @slow
 def 							_snake_case   (	self		)    ->							Optional[Any]:
     _lowerCAmelCase				=      FlaxAlbertModel.from_pretrained("albert-base-v2"		)
     _lowerCAmelCase				=      np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]		)
     _lowerCAmelCase				=      np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
     _lowerCAmelCase				=      model(_lowerCAmelCase			,     attention_mask=_lowerCAmelCase		)[0]
     _lowerCAmelCase				=      (1, 11, 768)
     self.assertEqual(output.shape			,     _lowerCAmelCase		)
     _lowerCAmelCase				=      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'''


def 	__a(SCREAMING_SNAKE_CASE_  :					int    ):



    '''simple docstring'''





    if not isinstance(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    ):
        raise TypeError("Input value must be an 'int' type"    )

    _lowerCAmelCase				=      0
    while number:
        position += 1
        number >>= 1

    return position


if __name__ == "__main__":
       import doctest

       doctest.testmod()


