


'''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      lowercase			(							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					,     ):

							'''simple docstring'''


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

							UpperCamelCase__     :List[str]							      =				rescale_embeddings
							UpperCamelCase__     :Union[str, Any]							      =				attention_type
							UpperCamelCase__     :List[Any]							      =				use_bias
							UpperCamelCase__     :Union[str, Any]							      =				block_size
							UpperCamelCase__     :Optional[int]							      =				num_random_blocks




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Any							      =				ids_tensor([self.batch_size, self.seq_length]					,     self.vocab_size							)

							UpperCamelCase__     :Optional[Any]							      =				None
							if self.use_attention_mask:
												UpperCamelCase__     :List[Any]							      =				random_attention_mask([self.batch_size, self.seq_length]							)

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

							UpperCamelCase__     :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=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 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Tuple							      =				self.prepare_config_and_inputs()
							UpperCamelCase__      ,       UpperCamelCase__      ,       UpperCamelCase__      ,       UpperCamelCase__     :List[Any]							      =				config_and_inputs
							UpperCamelCase__     :Dict							      =				{
							    '''input_ids''': input_ids,
							    '''token_type_ids''': token_type_ids,
							    '''attention_mask''': attention_mask,
							}
							return config, inputs_dict



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

		"""simple docstring"""

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

		_a									=       False
		_a									=       False




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :List[Any]							      =				FlaxBigBirdModelTester(self							)




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

							'''simple docstring'''


							super().test_from_pretrained_save_pretrained()




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

							'''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 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							super().test_no_automatic_init()




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

							'''simple docstring'''


							super().test_hidden_states_output()




		@slow
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							for model_class_name in self.all_model_classes:
												UpperCamelCase__     :List[str]							      =				model_class_name.from_pretrained('''google/bigbird-roberta-base'''							)
												self.assertIsNotNone(UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self							):

							'''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 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__      ,       UpperCamelCase__     :str							      =				self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
												with self.subTest(model_class.__name__							):
																	UpperCamelCase__     :Union[str, Any]							      =				self._prepare_for_class(UpperCamelCase_					,     UpperCamelCase_							)
																	UpperCamelCase__     :Optional[Any]							      =				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'''							):
																						UpperCamelCase__     :Tuple							      =				model_jitted(**UpperCamelCase_							).to_tuple()

																	with self.subTest('''JIT Disabled'''							):
																						with jax.disable_jit():
																											UpperCamelCase__     :Optional[int]							      =				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 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_=1e-5					,     UpperCamelCase_="outputs"					,     UpperCamelCase_=None							):

							'''simple docstring'''


							if name.startswith('''outputs.attentions'''							):
												return
							else:
												super().check_pt_flax_outputs(UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_							)



'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


__snake_case							   =  {
    '''configuration_layoutlmv3''': [
        '''LAYOUTLMV3_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''LayoutLMv3Config''',
        '''LayoutLMv3OnnxConfig''',
    ],
    '''processing_layoutlmv3''': ['''LayoutLMv3Processor'''],
    '''tokenization_layoutlmv3''': ['''LayoutLMv3Tokenizer'''],
}

try:
		if not is_tokenizers_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case							   =  ['''LayoutLMv3TokenizerFast''']

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case							   =  [
		    '''LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''LayoutLMv3ForQuestionAnswering''',
		    '''LayoutLMv3ForSequenceClassification''',
		    '''LayoutLMv3ForTokenClassification''',
		    '''LayoutLMv3Model''',
		    '''LayoutLMv3PreTrainedModel''',
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case							   =  [
		    '''TF_LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''TFLayoutLMv3ForQuestionAnswering''',
		    '''TFLayoutLMv3ForSequenceClassification''',
		    '''TFLayoutLMv3ForTokenClassification''',
		    '''TFLayoutLMv3Model''',
		    '''TFLayoutLMv3PreTrainedModel''',
		]

try:
		if not is_vision_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case							   =  ['''LayoutLMv3FeatureExtractor''']
		__snake_case							   =  ['''LayoutLMv3ImageProcessor''']


if TYPE_CHECKING:
		from .configuration_layoutlmva import (
		    LAYOUTLMV3_PRETRAINED_CONFIG_ARCHIVE_MAP,
		    LayoutLMvaConfig,
		    LayoutLMvaOnnxConfig,
		)
		from .processing_layoutlmva import LayoutLMvaProcessor
		from .tokenization_layoutlmva import LayoutLMvaTokenizer

		try:
				if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_layoutlmva_fast import LayoutLMvaTokenizerFast

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_layoutlmva import (
				    LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST,
				    LayoutLMvaForQuestionAnswering,
				    LayoutLMvaForSequenceClassification,
				    LayoutLMvaForTokenClassification,
				    LayoutLMvaModel,
				    LayoutLMvaPreTrainedModel,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_layoutlmva import (
				    TF_LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFLayoutLMvaForQuestionAnswering,
				    TFLayoutLMvaForSequenceClassification,
				    TFLayoutLMvaForTokenClassification,
				    TFLayoutLMvaModel,
				    TFLayoutLMvaPreTrainedModel,
				)

		try:
				if not is_vision_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .feature_extraction_layoutlmva import LayoutLMvaFeatureExtractor
				from .image_processing_layoutlmva import LayoutLMvaImageProcessor

else:
		import sys

		__snake_case							   =  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)