






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





		'''simple docstring'''



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


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	List[str]													=   ids_tensor([self.batch_size, self.seq_length] ,    self.vocab_size       )

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

						SCREAMING_SNAKE_CASE_   :	List[Any]													=   None
						if self.use_token_type_ids:
										SCREAMING_SNAKE_CASE_   :	Optional[int]													=   ids_tensor([self.batch_size, self.seq_length] ,    self.type_vocab_size       )

						SCREAMING_SNAKE_CASE_   :	Tuple													=   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=UpperCamelCase__ ,    initializer_range=self.initializer_range ,    )

						return config, input_ids, token_type_ids, attention_mask


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Tuple													=   self.prepare_config_and_inputs()
						SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_   :	Dict													=   config_and_inputs
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': attention_mask}
						return config, inputs_dict






		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Tuple													=   self.prepare_config_and_inputs()
						SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_   :	Tuple													=   config_and_inputs

						SCREAMING_SNAKE_CASE_   :	Dict													=   True
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   floats_tensor([self.batch_size, self.seq_length, self.hidden_size]       )
						SCREAMING_SNAKE_CASE_   :	Dict													=   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 							__a							(  __A ,	unittest.TestCase						):





		'''simple docstring'''



		UpperCAmelCase__      :				str				    =						True

		UpperCAmelCase__      :				str				    =						(
		    (
		        FlaxBertModel,
		        FlaxBertForPreTraining,
		        FlaxBertForMaskedLM,
		        FlaxBertForMultipleChoice,
		        FlaxBertForQuestionAnswering,
		        FlaxBertForNextSentencePrediction,
		        FlaxBertForSequenceClassification,
		        FlaxBertForTokenClassification,
		        FlaxBertForQuestionAnswering,
		    )
		    if is_flax_available()
		    else ()
		)


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   FlaxBertModelTester(self       )






		@slow
		def   __snake_case			(						self       ):
						# Only check this for base model, not necessary for all model classes.
						# This will also help speed-up tests.
						SCREAMING_SNAKE_CASE_   :	str													=   FlaxBertModel.from_pretrained('bert-base-cased'       )
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   model(np.ones((1, 1)       )       )
						self.assertIsNotNone(UpperCamelCase__       )







from timeit import timeit



def 					_lowerCamelCase(			lowerCAmelCase__				:		int      ):





				'''simple docstring'''







				if number < 0:
								raise ValueError('the value of input must not be negative'      )
				SCREAMING_SNAKE_CASE_   :	Tuple													=   0
				while number:
								number &= number - 1
								result += 1
				return result



def 					_lowerCamelCase(			lowerCAmelCase__				:		int      ):





				'''simple docstring'''







				if number < 0:
								raise ValueError('the value of input must not be negative'      )
				SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   0
				while number:
								if number % 2 == 1:
												result += 1
								number >>= 1
				return result



def 					_lowerCamelCase(			):





				'''simple docstring'''







				def do_benchmark(lowerCAmelCase__				:		int      ) -> None:
								SCREAMING_SNAKE_CASE_   :	int													=   'import __main__ as z'
								print(F'''Benchmark when {number = }:'''      )
								print(F'''{get_set_bits_count_using_modulo_operator(lowerCAmelCase__      ) = }'''      )
								SCREAMING_SNAKE_CASE_   :	int													=   timeit('z.get_set_bits_count_using_modulo_operator(25)'    ,    setup=lowerCAmelCase__      )
								print(F'''timeit() runs in {timing} seconds'''      )
								print(F'''{get_set_bits_count_using_brian_kernighans_algorithm(lowerCAmelCase__      ) = }'''      )
								SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   timeit(
								    'z.get_set_bits_count_using_brian_kernighans_algorithm(25)'    ,    setup=lowerCAmelCase__    ,    )
								print(F'''timeit() runs in {timing} seconds'''      )

				for number in (25, 37, 58, 0):
								do_benchmark(lowerCAmelCase__      )
								print()


if __name__ == "__main__":
				import doctest

				doctest.testmod()
				benchmark()