



'''simple docstring'''




import unittest

from transformers import BigBirdConfig, 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

						from transformers.models.big_bird.modeling_flax_big_bird import (
						    FlaxBigBirdForCausalLM,
						    FlaxBigBirdForMaskedLM,
						    FlaxBigBirdForMultipleChoice,
						    FlaxBigBirdForPreTraining,
						    FlaxBigBirdForQuestionAnswering,
						    FlaxBigBirdForSequenceClassification,
						    FlaxBigBirdForTokenClassification,
						    FlaxBigBirdModel,
						)






class 						_UpperCamelCase  (							unittest.TestCase    ):


			'''simple docstring'''

			def __init__(							self     : List[str]							,     lowerCAmelCase__     : Optional[int]							,     lowerCAmelCase__     : Any=2							,     lowerCAmelCase__     : List[str]=5_6							,     lowerCAmelCase__     : Tuple=True							,     lowerCAmelCase__     : Any=True							,     lowerCAmelCase__     : List[str]=True							,     lowerCAmelCase__     : Optional[Any]=True							,     lowerCAmelCase__     : str=9_9							,     lowerCAmelCase__     : Dict=3_2							,     lowerCAmelCase__     : Optional[Any]=2							,     lowerCAmelCase__     : Tuple=2							,     lowerCAmelCase__     : Tuple=7							,     lowerCAmelCase__     : Union[str, Any]="gelu_new"							,     lowerCAmelCase__     : Optional[Any]=0.1							,     lowerCAmelCase__     : List[Any]=0.1							,     lowerCAmelCase__     : List[str]=5_1_2							,     lowerCAmelCase__     : Optional[Any]=1_6							,     lowerCAmelCase__     : Dict=2							,     lowerCAmelCase__     : int=0.02							,     lowerCAmelCase__     : List[str]=4							,     lowerCAmelCase__     : Any="block_sparse"							,     lowerCAmelCase__     : str=True							,     lowerCAmelCase__     : Tuple=False							,     lowerCAmelCase__     : Union[str, Any]=2							,     lowerCAmelCase__     : Dict=3							,     ):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		List[str]           =		parent
					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		batch_size
					__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		seq_length
					__SCREAMING_SNAKE_CASE       :		str           =		is_training
					__SCREAMING_SNAKE_CASE       :		Dict           =		use_attention_mask
					__SCREAMING_SNAKE_CASE       :		Tuple           =		use_token_type_ids
					__SCREAMING_SNAKE_CASE       :		List[Any]           =		use_labels
					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		vocab_size
					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		hidden_size
					__SCREAMING_SNAKE_CASE       :		List[str]           =		num_hidden_layers
					__SCREAMING_SNAKE_CASE       :		List[Any]           =		num_attention_heads
					__SCREAMING_SNAKE_CASE       :		Dict           =		intermediate_size
					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		hidden_act
					__SCREAMING_SNAKE_CASE       :		str           =		hidden_dropout_prob
					__SCREAMING_SNAKE_CASE       :		str           =		attention_probs_dropout_prob
					__SCREAMING_SNAKE_CASE       :		int           =		max_position_embeddings
					__SCREAMING_SNAKE_CASE       :		Any           =		type_vocab_size
					__SCREAMING_SNAKE_CASE       :		Tuple           =		type_sequence_label_size
					__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		initializer_range
					__SCREAMING_SNAKE_CASE       :		List[Any]           =		num_choices

					__SCREAMING_SNAKE_CASE       :		Tuple           =		rescale_embeddings
					__SCREAMING_SNAKE_CASE       :		Dict           =		attention_type
					__SCREAMING_SNAKE_CASE       :		Dict           =		use_bias
					__SCREAMING_SNAKE_CASE       :		List[Any]           =		block_size
					__SCREAMING_SNAKE_CASE       :		Dict           =		num_random_blocks

			def UpperCamelCase__					(							self     : List[str]						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		List[str]           =		ids_tensor([self.batch_size, self.seq_length]							,     self.vocab_size						)

					__SCREAMING_SNAKE_CASE       :		List[Any]           =		None
					if self.use_attention_mask:
							__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		random_attention_mask([self.batch_size, self.seq_length]						)

					__SCREAMING_SNAKE_CASE       :		List[str]           =		None
					if self.use_token_type_ids:
							__SCREAMING_SNAKE_CASE       :		List[Any]           =		ids_tensor([self.batch_size, self.seq_length]							,     self.type_vocab_size						)

					__SCREAMING_SNAKE_CASE       :		int           =		BigBirdConfig(
					    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							,     attention_type=self.attention_type							,     block_size=self.block_size							,     num_random_blocks=self.num_random_blocks							,     use_bias=self.use_bias							,     rescale_embeddings=self.rescale_embeddings							,     )

					return config, input_ids, token_type_ids, attention_mask



			def UpperCamelCase__					(							self     : Dict						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		str           =		self.prepare_config_and_inputs()
					__SCREAMING_SNAKE_CASE       :		List[str]           =		config_and_inputs
					__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		{
					    'input_ids': input_ids,
					    'token_type_ids': token_type_ids,
					    'attention_mask': attention_mask,
					}
					return config, inputs_dict






@require_flax
class 						_UpperCamelCase  (							__UpperCamelCase    ,					unittest.TestCase    ):


			'''simple docstring'''

			_A      :		Optional[Any]			    =		(
			    (
			        FlaxBigBirdForCausalLM,
			        FlaxBigBirdModel,
			        FlaxBigBirdForPreTraining,
			        FlaxBigBirdForMaskedLM,
			        FlaxBigBirdForMultipleChoice,
			        FlaxBigBirdForQuestionAnswering,
			        FlaxBigBirdForSequenceClassification,
			        FlaxBigBirdForTokenClassification,
			    )
			    if is_flax_available()
			    else ()
			)

			_A      :		Any			    =		False
			_A      :		str			    =		False

			def UpperCamelCase__					(							self     : Optional[int]						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		FlaxBigBirdModelTester(self						)

			@slow
			# copied from `test_modeling_flax_common` because it takes much longer than other models
			def UpperCamelCase__					(							self     : int						):





					"""simple docstring"""






					super().test_from_pretrained_save_pretrained()

			@slow
			# copied from `test_modeling_flax_common` because it takes much longer than other models
			def UpperCamelCase__					(							self     : Union[str, Any]						):





					"""simple docstring"""






					super().test_from_pretrained_with_no_automatic_init()

			@slow
			# copied from `test_modeling_flax_common` because it takes much longer than other models
			def UpperCamelCase__					(							self     : Tuple						):





					"""simple docstring"""






					super().test_no_automatic_init()

			@slow
			# copied from `test_modeling_flax_common` because it takes much longer than other models
			def UpperCamelCase__					(							self     : Union[str, Any]						):





					"""simple docstring"""






					super().test_hidden_states_output()

			@slow
			def UpperCamelCase__					(							self     : str						):





					"""simple docstring"""






					for model_class_name in self.all_model_classes:
							__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		model_class_name.from_pretrained("""google/bigbird-roberta-base"""						)
							self.assertIsNotNone(lowerCAmelCase__						)

			def UpperCamelCase__					(							self     : List[str]						):





					"""simple docstring"""






					if self.test_attn_probs:
							super().test_attention_outputs()

			@slow
			# copied from `test_modeling_flax_common` because it takes much longer than other models
			def UpperCamelCase__					(							self     : Union[str, Any]						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		List[str]           =		self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
							with self.subTest(model_class.__name__						):
									__SCREAMING_SNAKE_CASE       :		Optional[int]           =		self._prepare_for_class(lowerCAmelCase__							,     lowerCAmelCase__						)
									__SCREAMING_SNAKE_CASE       :		Any           =		model_class(lowerCAmelCase__						)

									@jax.jit
									def model_jitted(lowerCAmelCase__     : int							,     lowerCAmelCase__     : Tuple=None							,     **lowerCAmelCase__     : Tuple						):
											return model(input_ids=lowerCAmelCase__							,     attention_mask=lowerCAmelCase__							,     **lowerCAmelCase__						)

									with self.subTest("""JIT Enabled"""						):
											__SCREAMING_SNAKE_CASE       :		str           =		model_jitted(**lowerCAmelCase__						).to_tuple()

									with self.subTest("""JIT Disabled"""						):
											with jax.disable_jit():
													__SCREAMING_SNAKE_CASE       :		Dict           =		model_jitted(**lowerCAmelCase__						).to_tuple()

									self.assertEqual(len(lowerCAmelCase__						)							,     len(lowerCAmelCase__						)						)
									for jitted_output, output in zip(lowerCAmelCase__							,     lowerCAmelCase__						):
											self.assertEqual(jitted_output.shape							,     output.shape						)



			def UpperCamelCase__					(							self     : Optional[int]							,     lowerCAmelCase__     : int							,     lowerCAmelCase__     : str							,     lowerCAmelCase__     : List[Any]							,     lowerCAmelCase__     : Optional[int]=1E-5							,     lowerCAmelCase__     : Tuple="outputs"							,     lowerCAmelCase__     : Any=None						):





					"""simple docstring"""






					if name.startswith("""outputs.attentions"""						):
							return
					else:
							super().check_pt_flax_outputs(lowerCAmelCase__							,     lowerCAmelCase__							,     lowerCAmelCase__							,     lowerCAmelCase__							,     lowerCAmelCase__							,     lowerCAmelCase__						)



import math




def    snake_case_     (  snake_case			,							snake_case     )  ->				float:
       return math.pow(snake_case			,							2     ) - a




def    snake_case_     (  snake_case     )  ->				float:
       return 2 * x




def    snake_case_     (  snake_case     )  ->				float:
       lowercase__:   Dict  			=   2.0

       while start <= a:
              lowercase__:   str  			=   math.pow(snake_case			,							2     )

       return start




def    snake_case_     (  snake_case			,							snake_case = 99_99			,							snake_case = 0.0_0_0_0_0_0_0_0_0_0_0_0_0_1     )  ->				float:

       if a < 0:
              raise ValueError('math domain error'     )

       lowercase__:   Tuple  			=   get_initial_point(snake_case     )

       for _ in range(snake_case     ):
              lowercase__:   List[Any]  			=   value
              lowercase__:   Any  			=   value - fx(snake_case			,							snake_case     ) / fx_derivative(snake_case     )
              if abs(prev_value - value     ) < tolerance:
                     return value

       return value


if __name__ == "__main__":
 from doctest import testmod

 testmod()


