




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     snake_case__							(unittest.TestCase   ):
				"""simple docstring"""



				def __init__(      self				:     List[Any]					,      __lowerCamelCase				:     Optional[int]					,      __lowerCamelCase				:     List[str]=2					,      __lowerCamelCase				:     str=56					,      __lowerCamelCase				:     int=True					,      __lowerCamelCase				:     Any=True					,      __lowerCamelCase				:     Dict=True					,      __lowerCamelCase				:     List[str]=True					,      __lowerCamelCase				:     Optional[int]=99					,      __lowerCamelCase				:     List[str]=32					,      __lowerCamelCase				:     Any=2					,      __lowerCamelCase				:     Union[str, Any]=2					,      __lowerCamelCase				:     List[Any]=7					,      __lowerCamelCase				:     Optional[int]="gelu_new"					,      __lowerCamelCase				:     Dict=0.1					,      __lowerCamelCase				:     Dict=0.1					,      __lowerCamelCase				:     Union[str, Any]=5_12					,      __lowerCamelCase				:     Optional[int]=16					,      __lowerCamelCase				:     Union[str, Any]=2					,      __lowerCamelCase				:     Optional[Any]=0.02					,      __lowerCamelCase				:     str=4					,      __lowerCamelCase				:     List[Any]="block_sparse"					,      __lowerCamelCase				:     Optional[Any]=True					,      __lowerCamelCase				:     List[Any]=False					,      __lowerCamelCase				:     List[str]=2					,      __lowerCamelCase				:     Any=3					,      )					->     List[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				:     Any							)					->     List[Any]:
							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=__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				:     Optional[Any]							)					->     List[str]:
							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     snake_case__							(_UpperCamelCase    ,       unittest.TestCase   ):
				"""simple docstring"""



				SCREAMING_SNAKE_CASE_       :							Union[str, Any]							 =					(
				    (
				        FlaxBigBirdForCausalLM,
				        FlaxBigBirdModel,
				        FlaxBigBirdForPreTraining,
				        FlaxBigBirdForMaskedLM,
				        FlaxBigBirdForMultipleChoice,
				        FlaxBigBirdForQuestionAnswering,
				        FlaxBigBirdForSequenceClassification,
				        FlaxBigBirdForTokenClassification,
				    )
				    if is_flax_available()
				    else ()
				)

				SCREAMING_SNAKE_CASE_       :							Optional[int]							 =					False
				SCREAMING_SNAKE_CASE_       :							Union[str, Any]							 =					False





				def 							__UpperCAmelCase							(      self				:     Tuple							)					->     Any:
							a    =			FlaxBigBirdModelTester(self							)





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





				@slow
				# copied from `test_modeling_flax_common` because it takes much longer than other models
				def 							__UpperCAmelCase							(      self				:     Optional[int]							)					->     str:
							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[int]							)					->     Union[str, Any]:
							super().test_no_automatic_init()





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





				@slow
				def 							__UpperCAmelCase							(      self				:     int							)					->     List[str]:
							for model_class_name in self.all_model_classes:
										a    =			model_class_name.from_pretrained("google/bigbird-roberta-base"							)
										self.assertIsNotNone(__lowerCamelCase							)





				def 							__UpperCAmelCase							(      self				:     Union[str, Any]							)					->     List[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							)					->     Optional[Any]:
							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(__lowerCamelCase					,      __lowerCamelCase							)
													a    =			model_class(__lowerCamelCase							)

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

													with self.subTest("JIT Enabled"							):
																a    =			model_jitted(**__lowerCamelCase							).to_tuple()

													with self.subTest("JIT Disabled"							):
																with jax.disable_jit():
																			a    =			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				:     Dict					,      __lowerCamelCase				:     List[Any]					,      __lowerCamelCase				:     Any					,      __lowerCamelCase				:     Dict					,      __lowerCamelCase				:     Union[str, Any]=1e-5					,      __lowerCamelCase				:     List[str]="outputs"					,      __lowerCamelCase				:     Dict=None							)					->     Any:
							# `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(__lowerCamelCase					,      __lowerCamelCase					,      __lowerCamelCase					,      __lowerCamelCase					,      __lowerCamelCase					,      __lowerCamelCase							)












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,
)






