
'''simple docstring'''


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






   '''simple docstring'''







   def __init__(			self ,   lowerCamelCase__ ,   lowerCamelCase__=1_3 ,   lowerCamelCase__=7 ,   lowerCamelCase__=True ,   lowerCamelCase__=True ,   lowerCamelCase__=True ,   lowerCamelCase__=True ,   lowerCamelCase__=9_9 ,   lowerCamelCase__=3_2 ,   lowerCamelCase__=5 ,   lowerCamelCase__=4 ,   lowerCamelCase__=3_7 ,   lowerCamelCase__="gelu" ,   lowerCamelCase__=0.1 ,   lowerCamelCase__=0.1 ,   lowerCamelCase__=5_1_2 ,   lowerCamelCase__=1_6 ,   lowerCamelCase__=2 ,   lowerCamelCase__=0.02 ,   lowerCamelCase__=4 ,   ):

      '''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       UpperCAmelCase				(			self   ):

      '''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       =  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       UpperCAmelCase				(			self   ):

      '''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







   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  self.prepare_config_and_inputs()
      UpperCamelCase     , UpperCamelCase     , UpperCamelCase     , UpperCamelCase       =  config_and_inputs

      UpperCamelCase       =  True
      UpperCamelCase       =  floats_tensor([self.batch_size, self.seq_length, self.hidden_size]   )
      UpperCamelCase       =  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 						lowercase__	(  snake_case_,					unittest.TestCase   ):






   '''simple docstring'''







   _snake_case		   =							True

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







   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  FlaxBertModelTester(self   )







   @slow
   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  FlaxBertModel.from_pretrained('''bert-base-cased'''   )
      UpperCamelCase       =  model(np.ones((1, 1)   )   )
      self.assertIsNotNone(lowerCamelCase__   )







'''simple docstring'''


from __future__ import annotations



def  __snake_case     (    _UpperCAmelCase					:       list[int]):
   UpperCamelCase       =  len(_UpperCAmelCase) // 2

   # choose the middle 3 elements
   UpperCamelCase       =  lst[m - 1 : m + 2]

   # if middle element is peak
   if three[1] > three[0] and three[1] > three[2]:
      return three[1]

   # if increasing, recurse on right
   elif three[0] < three[2]:
      if len(lst[:m]) == 2:
         m -= 1
      return peak(lst[m:])

   # decreasing
   else:
      if len(lst[:m]) == 2:
         m += 1
      return peak(lst[:m])


if __name__ == "__main__":
   import doctest

   doctest.testmod()





