



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





							def __init__(   self		:		Any      ,				__lowercase		:		List[str]      ,				__lowercase		:		str=2      ,				__lowercase		:		Dict=56      ,				__lowercase		:		List[Any]=True      ,				__lowercase		:		Union[str, Any]=True      ,				__lowercase		:		int=True      ,				__lowercase		:		List[Any]=True      ,				__lowercase		:		Optional[int]=99      ,				__lowercase		:		int=32      ,				__lowercase		:		Any=2      ,				__lowercase		:		List[str]=2      ,				__lowercase		:		List[Any]=7      ,				__lowercase		:		Optional[int]="gelu_new"      ,				__lowercase		:		Dict=0.1      ,				__lowercase		:		str=0.1      ,				__lowercase		:		Optional[Any]=512      ,				__lowercase		:		int=16      ,				__lowercase		:		int=2      ,				__lowercase		:		List[str]=0.02      ,				__lowercase		:		Any=4      ,				__lowercase		:		Optional[int]="block_sparse"      ,				__lowercase		:		Optional[Any]=True      ,				__lowercase		:		Optional[int]=False      ,				__lowercase		:		Any=2      ,				__lowercase		:		Optional[int]=3      ,				):

											'''simple docstring'''
											__a       =		parent
											__a       =		batch_size
											__a       =		seq_length
											__a       =		is_training
											__a       =		use_attention_mask
											__a       =		use_token_type_ids
											__a       =		use_labels
											__a       =		vocab_size
											__a       =		hidden_size
											__a       =		num_hidden_layers
											__a       =		num_attention_heads
											__a       =		intermediate_size
											__a       =		hidden_act
											__a       =		hidden_dropout_prob
											__a       =		attention_probs_dropout_prob
											__a       =		max_position_embeddings
											__a       =		type_vocab_size
											__a       =		type_sequence_label_size
											__a       =		initializer_range
											__a       =		num_choices

											__a       =		rescale_embeddings
											__a       =		attention_type
											__a       =		use_bias
											__a       =		block_size
											__a       =		num_random_blocks





							def 						UpperCamelCase_					(   self		:		int	):

											'''simple docstring'''
											__a       =		ids_tensor([self.batch_size, self.seq_length]      ,				self.vocab_size	)

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

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

											__a       =		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=__lowercase      ,				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		:		List[Any]	):

											'''simple docstring'''
											__a       =		self.prepare_config_and_inputs()
											__a     ,					__a     ,					__a     ,					__a       =		config_and_inputs
											__a       =		{
											    """input_ids""": input_ids,
											    """token_type_ids""": token_type_ids,
											    """attention_mask""": attention_mask,
											}
											return config, inputs_dict






@require_flax
class    SCREAMING_SNAKE_CASE			(							lowerCamelCase__			,      unittest.TestCase					):
							__lowerCamelCase	:	str    =(
							    (
							        FlaxBigBirdForCausalLM,
							        FlaxBigBirdModel,
							        FlaxBigBirdForPreTraining,
							        FlaxBigBirdForMaskedLM,
							        FlaxBigBirdForMultipleChoice,
							        FlaxBigBirdForQuestionAnswering,
							        FlaxBigBirdForSequenceClassification,
							        FlaxBigBirdForTokenClassification,
							    )
							    if is_flax_available()
							    else ()
							)

							__lowerCamelCase	:	Optional[int]    =False
							__lowerCamelCase	:	Tuple    =False





							def 						UpperCamelCase_					(   self		:		Optional[Any]	):

											'''simple docstring'''
											__a       =		FlaxBigBirdModelTester(self	)





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

											'''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		:		str	):

											'''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		:		Optional[Any]	):

											'''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		:		Union[str, Any]	):

											'''simple docstring'''
											for model_class_name in self.all_model_classes:
															__a       =		model_class_name.from_pretrained("""google/bigbird-roberta-base"""	)
															self.assertIsNotNone(__lowercase	)





							def 						UpperCamelCase_					(   self		:		Tuple	):

											'''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		:		Tuple	):

											'''simple docstring'''
											__a     ,					__a       =		self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
															with self.subTest(model_class.__name__	):
																			__a       =		self._prepare_for_class(__lowercase      ,				__lowercase	)
																			__a       =		model_class(__lowercase	)

																			@jax.jit
																			def model_jitted(__lowercase		:		Optional[int]      ,				__lowercase		:		Union[str, Any]=None      ,				**__lowercase		:		Optional[Any]	):
																							return model(input_ids=__lowercase      ,				attention_mask=__lowercase      ,				**__lowercase	)

																			with self.subTest("""JIT Enabled"""	):
																							__a       =		model_jitted(**__lowercase	).to_tuple()

																			with self.subTest("""JIT Disabled"""	):
																							with jax.disable_jit():
																											__a       =		model_jitted(**__lowercase	).to_tuple()

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







							def 						UpperCamelCase_					(   self		:		Union[str, Any]      ,				__lowercase		:		Tuple      ,				__lowercase		:		Dict      ,				__lowercase		:		Optional[int]      ,				__lowercase		:		List[Any]=1E-5      ,				__lowercase		:		List[Any]="outputs"      ,				__lowercase		:		Optional[Any]=None	):

											'''simple docstring'''
											# `bigbird_block_sparse_attention` in `FlaxBigBird` returns `attention_probs = None`, while in PyTorch version,
											# an effort was done to return `attention_probs` (yet to be verified).
											if name.startswith("""outputs.attentions"""	):
															return
											else:
															super().check_pt_flax_outputs(__lowercase      ,				__lowercase      ,				__lowercase      ,				__lowercase      ,				__lowercase      ,				__lowercase	)





def   lowerCAmelCase__						(							_SCREAMING_SNAKE_CASE       :			int = 3				,     _SCREAMING_SNAKE_CASE       :			int = 7				,     _SCREAMING_SNAKE_CASE       :			int = 100_0000    ):
				"""simple docstring"""







				__a       =		0
				__a       =		1

				for current_denominator in range(1				,     limit + 1    ):
								__a       =		current_denominator * numerator // denominator
								if current_denominator % denominator == 0:
												current_numerator -= 1
								if current_numerator * max_denominator > current_denominator * max_numerator:
												__a       =		current_numerator
												__a       =		current_denominator
				return max_numerator


if __name__ == "__main__":
						print(solution(numerator=3, denominator=7, limit=100_0000))
