


"""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    ,				__UpperCAmelCase    ,				__UpperCAmelCase=2    ,				__UpperCAmelCase=56    ,				__UpperCAmelCase=True    ,				__UpperCAmelCase=True    ,				__UpperCAmelCase=True    ,				__UpperCAmelCase=True    ,				__UpperCAmelCase=99    ,				__UpperCAmelCase=32    ,				__UpperCAmelCase=2    ,				__UpperCAmelCase=2    ,				__UpperCAmelCase=7    ,				__UpperCAmelCase="gelu_new"    ,				__UpperCAmelCase=0.1    ,				__UpperCAmelCase=0.1    ,				__UpperCAmelCase=512    ,				__UpperCAmelCase=16    ,				__UpperCAmelCase=2    ,				__UpperCAmelCase=0.02    ,				__UpperCAmelCase=4    ,				__UpperCAmelCase="block_sparse"    ,				__UpperCAmelCase=True    ,				__UpperCAmelCase=False    ,				__UpperCAmelCase=2    ,				__UpperCAmelCase=3    ,				)       ->							str:
          _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							)       ->							Dict:
          _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=__UpperCAmelCase    ,				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]:
          _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     __lowerCamelCase  (					a__  ,					unittest.TestCase				):

     '''simple docstring'''
     A_       :	Any    =		(
         (
             FlaxBigBirdForCausalLM,
             FlaxBigBirdModel,
             FlaxBigBirdForPreTraining,
             FlaxBigBirdForMaskedLM,
             FlaxBigBirdForMultipleChoice,
             FlaxBigBirdForQuestionAnswering,
             FlaxBigBirdForSequenceClassification,
             FlaxBigBirdForTokenClassification,
         )
         if is_flax_available()
         else ()
     )

     A_       :	Tuple    =		False
     A_       :	Optional[Any]    =		False


     def 							_UpperCAmelCase      (      self							)       ->							Tuple:
          _a    	=				FlaxBigBirdModelTester(self							)


     @slow
     # copied from `test_modeling_flax_common` because it takes much longer than other models
     def 							_UpperCAmelCase      (      self							)       ->							Tuple:
          super().test_from_pretrained_save_pretrained()


     @slow
     # copied from `test_modeling_flax_common` because it takes much longer than other models
     def 							_UpperCAmelCase      (      self							)       ->							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 							_UpperCAmelCase      (      self							)       ->							str:
          super().test_no_automatic_init()


     @slow
     # copied from `test_modeling_flax_common` because it takes much longer than other models
     def 							_UpperCAmelCase      (      self							)       ->							Dict:
          super().test_hidden_states_output()


     @slow
     def 							_UpperCAmelCase      (      self							)       ->							Dict:
          for model_class_name in self.all_model_classes:
               _a    	=				model_class_name.from_pretrained('''google/bigbird-roberta-base'''							)
               self.assertIsNotNone(__UpperCAmelCase							)


     def 							_UpperCAmelCase      (      self							)       ->							Optional[Any]:
          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:
          _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(__UpperCAmelCase    ,				__UpperCAmelCase							)
                    _a    	=				model_class(__UpperCAmelCase							)

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

                    with self.subTest('''JIT Enabled'''							):
                         _a    	=				model_jitted(**__UpperCAmelCase							).to_tuple()

                    with self.subTest('''JIT Disabled'''							):
                         with jax.disable_jit():
                              _a    	=				model_jitted(**__UpperCAmelCase							).to_tuple()

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





     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase=1e-5    ,				__UpperCAmelCase="outputs"    ,				__UpperCAmelCase=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(__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase							)



"""simple docstring"""






from . import __version__

# Backward compatibility imports, to make sure all those objects can be found in file_utils
from .utils import (
    CLOUDFRONT_DISTRIB_PREFIX,
    CONFIG_NAME,
    DISABLE_TELEMETRY,
    DUMMY_INPUTS,
    DUMMY_MASK,
    ENV_VARS_TRUE_AND_AUTO_VALUES,
    ENV_VARS_TRUE_VALUES,
    FEATURE_EXTRACTOR_NAME,
    FLAX_WEIGHTS_NAME,
    HF_MODULES_CACHE,
    HUGGINGFACE_CO_PREFIX,
    HUGGINGFACE_CO_RESOLVE_ENDPOINT,
    MODEL_CARD_NAME,
    MULTIPLE_CHOICE_DUMMY_INPUTS,
    PYTORCH_PRETRAINED_BERT_CACHE,
    PYTORCH_TRANSFORMERS_CACHE,
    S3_BUCKET_PREFIX,
    SENTENCEPIECE_UNDERLINE,
    SPIECE_UNDERLINE,
    TF2_WEIGHTS_NAME,
    TF_WEIGHTS_NAME,
    TORCH_FX_REQUIRED_VERSION,
    TRANSFORMERS_CACHE,
    TRANSFORMERS_DYNAMIC_MODULE_NAME,
    USE_JAX,
    USE_TF,
    USE_TORCH,
    WEIGHTS_INDEX_NAME,
    WEIGHTS_NAME,
    ContextManagers,
    DummyObject,
    EntryNotFoundError,
    ExplicitEnum,
    ModelOutput,
    PaddingStrategy,
    PushToHubMixin,
    RepositoryNotFoundError,
    RevisionNotFoundError,
    TensorType,
    _LazyModule,
    add_code_sample_docstrings,
    add_end_docstrings,
    add_start_docstrings,
    add_start_docstrings_to_model_forward,
    cached_property,
    copy_func,
    default_cache_path,
    define_sagemaker_information,
    get_cached_models,
    get_file_from_repo,
    get_full_repo_name,
    get_torch_version,
    has_file,
    http_user_agent,
    is_apex_available,
    is_bsa_available,
    is_coloredlogs_available,
    is_datasets_available,
    is_detectrona_available,
    is_faiss_available,
    is_flax_available,
    is_ftfy_available,
    is_in_notebook,
    is_ipex_available,
    is_librosa_available,
    is_offline_mode,
    is_onnx_available,
    is_pandas_available,
    is_phonemizer_available,
    is_protobuf_available,
    is_psutil_available,
    is_pyanvml_available,
    is_pyctcdecode_available,
    is_pytesseract_available,
    is_pytorch_quantization_available,
    is_rjieba_available,
    is_sagemaker_dp_enabled,
    is_sagemaker_mp_enabled,
    is_scipy_available,
    is_sentencepiece_available,
    is_seqio_available,
    is_sklearn_available,
    is_soundfile_availble,
    is_spacy_available,
    is_speech_available,
    is_tensor,
    is_tensorflow_probability_available,
    is_tfaonnx_available,
    is_tf_available,
    is_timm_available,
    is_tokenizers_available,
    is_torch_available,
    is_torch_bfaa_available,
    is_torch_cuda_available,
    is_torch_fx_available,
    is_torch_fx_proxy,
    is_torch_mps_available,
    is_torch_tfaa_available,
    is_torch_tpu_available,
    is_torchaudio_available,
    is_training_run_on_sagemaker,
    is_vision_available,
    replace_return_docstrings,
    requires_backends,
    to_numpy,
    to_py_obj,
    torch_only_method,
)