





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






     """simple docstring"""






     def __init__(   self							:			str   ,       __snake_case							:			List[Any]   ,       __snake_case							:			List[str]=2   ,       __snake_case							:			Optional[Any]=56   ,       __snake_case							:			List[Any]=True   ,       __snake_case							:			Union[str, Any]=True   ,       __snake_case							:			int=True   ,       __snake_case							:			List[str]=True   ,       __snake_case							:			Union[str, Any]=99   ,       __snake_case							:			Any=32   ,       __snake_case							:			int=2   ,       __snake_case							:			Optional[int]=2   ,       __snake_case							:			List[str]=7   ,       __snake_case							:			Dict="gelu_new"   ,       __snake_case							:			int=0.1   ,       __snake_case							:			Tuple=0.1   ,       __snake_case							:			int=5_12   ,       __snake_case							:			Dict=16   ,       __snake_case							:			Tuple=2   ,       __snake_case							:			Optional[Any]=0.02   ,       __snake_case							:			Any=4   ,       __snake_case							:			Optional[Any]="block_sparse"   ,       __snake_case							:			Union[str, Any]=True   ,       __snake_case							:			Tuple=False   ,       __snake_case							:			Optional[Any]=2   ,       __snake_case							:			List[Any]=3   ,       )->	Optional[int]:
        snake_case 						=   parent
        snake_case 						=   batch_size
        snake_case 						=   seq_length
        snake_case 						=   is_training
        snake_case 						=   use_attention_mask
        snake_case 						=   use_token_type_ids
        snake_case 						=   use_labels
        snake_case 						=   vocab_size
        snake_case 						=   hidden_size
        snake_case 						=   num_hidden_layers
        snake_case 						=   num_attention_heads
        snake_case 						=   intermediate_size
        snake_case 						=   hidden_act
        snake_case 						=   hidden_dropout_prob
        snake_case 						=   attention_probs_dropout_prob
        snake_case 						=   max_position_embeddings
        snake_case 						=   type_vocab_size
        snake_case 						=   type_sequence_label_size
        snake_case 						=   initializer_range
        snake_case 						=   num_choices

        snake_case 						=   rescale_embeddings
        snake_case 						=   attention_type
        snake_case 						=   use_bias
        snake_case 						=   block_size
        snake_case 						=   num_random_blocks



     def      lowerCAmelCase			(   self							:			List[Any]						)->	str:
        snake_case 						=   ids_tensor([self.batch_size, self.seq_length]   ,       self.vocab_size						)

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

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

        snake_case 						=   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=__snake_case   ,       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      lowerCAmelCase			(   self							:			int						)->	int:
        snake_case 						=   self.prepare_config_and_inputs()
        snake_case						,    snake_case						,    snake_case						,    snake_case 						=   config_and_inputs
        snake_case 						=   {
            """input_ids""": input_ids,
            """token_type_ids""": token_type_ids,
            """attention_mask""": attention_mask,
        }
        return config, inputs_dict




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






     """simple docstring"""






     snake_case_						      =   (
         (
             FlaxBigBirdForCausalLM,
             FlaxBigBirdModel,
             FlaxBigBirdForPreTraining,
             FlaxBigBirdForMaskedLM,
             FlaxBigBirdForMultipleChoice,
             FlaxBigBirdForQuestionAnswering,
             FlaxBigBirdForSequenceClassification,
             FlaxBigBirdForTokenClassification,
         )
         if is_flax_available()
         else ()
     )

     snake_case_						      =   False
     snake_case_						      =   False



     def      lowerCAmelCase			(   self							:			Optional[int]						)->	Any:
        snake_case 						=   FlaxBigBirdModelTester(self						)



     @slow
     # copied from `test_modeling_flax_common` because it takes much longer than other models
     def      lowerCAmelCase			(   self							:			Optional[int]						)->	List[Any]:
        super().test_from_pretrained_save_pretrained()



     @slow
     # copied from `test_modeling_flax_common` because it takes much longer than other models
     def      lowerCAmelCase			(   self							:			List[str]						)->	Union[str, Any]:
        super().test_from_pretrained_with_no_automatic_init()



     @slow
     # copied from `test_modeling_flax_common` because it takes much longer than other models
     def      lowerCAmelCase			(   self							:			Optional[int]						)->	int:
        super().test_no_automatic_init()



     @slow
     # copied from `test_modeling_flax_common` because it takes much longer than other models
     def      lowerCAmelCase			(   self							:			Any						)->	List[Any]:
        super().test_hidden_states_output()



     @slow
     def      lowerCAmelCase			(   self							:			Union[str, Any]						)->	Union[str, Any]:
        for model_class_name in self.all_model_classes:
           snake_case 						=   model_class_name.from_pretrained("""google/bigbird-roberta-base"""						)
           self.assertIsNotNone(__snake_case						)



     def      lowerCAmelCase			(   self							:			Any						)->	str:
        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      lowerCAmelCase			(   self							:			Tuple						)->	Dict:
        snake_case						,    snake_case 						=   self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
           with self.subTest(model_class.__name__						):
              snake_case 						=   self._prepare_for_class(__snake_case   ,       __snake_case						)
              snake_case 						=   model_class(__snake_case						)

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

              with self.subTest("""JIT Enabled"""						):
                 snake_case 						=   model_jitted(**__snake_case						).to_tuple()

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

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



     def      lowerCAmelCase			(   self							:			Any   ,       __snake_case							:			int   ,       __snake_case							:			int   ,       __snake_case							:			Any   ,       __snake_case							:			Dict=1e-5   ,       __snake_case							:			Optional[Any]="outputs"   ,       __snake_case							:			List[str]=None						)->	List[str]:
        # `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(__snake_case   ,       __snake_case   ,       __snake_case   ,       __snake_case   ,       __snake_case   ,       __snake_case						)








'''simple docstring'''




def 	__lowerCamelCase			(      __lowerCAmelCase       :							int		)		->  int:
   assert isinstance(__lowerCAmelCase      ,    __lowerCAmelCase		), F'''The input value of [n={number}] is not an integer'''

   if number == 1:
      return 2
   elif number < 1:
      snake_case 						=   F'''The input value of [n={number}] has to be > 0'''
      raise ValueError(__lowerCAmelCase		)
   else:
      snake_case 						=   sylvester(number - 1		)
      snake_case 						=   num - 1
      snake_case 						=   num
      return lower * upper + 1


if __name__ == "__main__":
 print(F"""The 8th number in Sylvester's sequence: {sylvester(8)}""")

