

import unittest

import numpy as np

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

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
       from transformers.models.bert.modeling_flax_bert import (
           FlaxBertForMaskedLM,
           FlaxBertForMultipleChoice,
           FlaxBertForNextSentencePrediction,
           FlaxBertForPreTraining,
           FlaxBertForQuestionAnswering,
           FlaxBertForSequenceClassification,
           FlaxBertForTokenClassification,
           FlaxBertModel,
       )






class 	UpperCAmelCase__		(	unittest.TestCase	):






  """simple docstring"""


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






  def 				lowercase_		(							self						:		List[Any] )		->							int:
       SCREAMING_SNAKE_CASE__   =   ids_tensor([self.batch_size, self.seq_length]     ,       self.vocab_size )

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

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

       SCREAMING_SNAKE_CASE__   =   BertConfig(
           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						:		Union[str, Any] )		->							int:
       SCREAMING_SNAKE_CASE__   =   self.prepare_config_and_inputs()
       SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__   =   config_and_inputs
       SCREAMING_SNAKE_CASE__   =   {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': attention_mask}
       return config, inputs_dict







  def 				lowercase_		(							self						:		Dict )		->							str:
       SCREAMING_SNAKE_CASE__   =   self.prepare_config_and_inputs()
       SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__   =   config_and_inputs

       SCREAMING_SNAKE_CASE__   =   True
       SCREAMING_SNAKE_CASE__   =   floats_tensor([self.batch_size, self.seq_length, self.hidden_size] )
       SCREAMING_SNAKE_CASE__   =   ids_tensor([self.batch_size, self.seq_length]     ,       vocab_size=2 )

       return (
           config,
           input_ids,
           attention_mask,
           encoder_hidden_states,
           encoder_attention_mask,
       )






@require_flax
class 	UpperCAmelCase__		(	A__						,					unittest.TestCase	):






  """simple docstring"""


  a									= True

  a									= (
      (
          FlaxBertModel,
          FlaxBertForPreTraining,
          FlaxBertForMaskedLM,
          FlaxBertForMultipleChoice,
          FlaxBertForQuestionAnswering,
          FlaxBertForNextSentencePrediction,
          FlaxBertForSequenceClassification,
          FlaxBertForTokenClassification,
          FlaxBertForQuestionAnswering,
      )
      if is_flax_available()
      else ()
  )






  def 				lowercase_		(							self						:		List[str] )		->							Any:
       SCREAMING_SNAKE_CASE__   =   FlaxBertModelTester(self )







  @slow
  def 				lowercase_		(							self						:		int )		->							Optional[int]:
       # Only check this for base model, not necessary for all model classes.
       # This will also help speed-up tests.
       SCREAMING_SNAKE_CASE__   =   FlaxBertModel.from_pretrained('''bert-base-cased''' )
       SCREAMING_SNAKE_CASE__   =   model(np.ones((1, 1) ) )
       self.assertIsNotNone(__lowerCamelCase )





def     UpperCAmelCase_       (						_A    ):





     '''simple docstring'''




     if not isinstance(_A				,		_A    ):
          raise ValueError('''multiplicative_persistence() only accepts integral values'''    )
     if num < 0:
          raise ValueError('''multiplicative_persistence() does not accept negative values'''    )

     SCREAMING_SNAKE_CASE__   =   0
     SCREAMING_SNAKE_CASE__   =   str(_A    )

     while len(_A    ) != 1:
          SCREAMING_SNAKE_CASE__   =   [int(_A    ) for i in num_string]

          SCREAMING_SNAKE_CASE__   =   1
          for i in range(0				,		len(_A    )    ):
               total *= numbers[i]

          SCREAMING_SNAKE_CASE__   =   str(_A    )

          steps += 1
     return steps
def     UpperCAmelCase_       (						_A    ):





     '''simple docstring'''




     if not isinstance(_A				,		_A    ):
          raise ValueError('''additive_persistence() only accepts integral values'''    )
     if num < 0:
          raise ValueError('''additive_persistence() does not accept negative values'''    )

     SCREAMING_SNAKE_CASE__   =   0
     SCREAMING_SNAKE_CASE__   =   str(_A    )

     while len(_A    ) != 1:
          SCREAMING_SNAKE_CASE__   =   [int(_A    ) for i in num_string]

          SCREAMING_SNAKE_CASE__   =   0
          for i in range(0				,		len(_A    )    ):
               total += numbers[i]

          SCREAMING_SNAKE_CASE__   =   str(_A    )

          steps += 1
     return steps


if __name__ == "__main__":
       import doctest

       doctest.testmod()


