






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




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

							SCREAMING_SNAKE_CASE__     :				Optional[int]									=rescale_embeddings
							SCREAMING_SNAKE_CASE__     :				List[Any]									=attention_type
							SCREAMING_SNAKE_CASE__     :				List[str]									=use_bias
							SCREAMING_SNAKE_CASE__     :				Optional[int]									=block_size
							SCREAMING_SNAKE_CASE__     :				Tuple									=num_random_blocks




	def      __magic_name__	(      self	:							List[str]      )	->						List[str]:
							SCREAMING_SNAKE_CASE__     :				str									=ids_tensor([self.batch_size, self.seq_length]					,      self.vocab_size      )

							SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=None
							if self.use_attention_mask:
													SCREAMING_SNAKE_CASE__     :				List[str]									=random_attention_mask([self.batch_size, self.seq_length]      )

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

							SCREAMING_SNAKE_CASE__     :				Optional[Any]									=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      __magic_name__	(      self	:							Optional[int]      )	->						List[str]:
							SCREAMING_SNAKE_CASE__     :				List[Any]									=self.prepare_config_and_inputs()
							SCREAMING_SNAKE_CASE__		,	SCREAMING_SNAKE_CASE__		,	SCREAMING_SNAKE_CASE__		,	SCREAMING_SNAKE_CASE__     :				str									=config_and_inputs
							SCREAMING_SNAKE_CASE__     :				Any									={
							    '''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				):
	snake_case_  							=							(
	    (
	        FlaxBigBirdForCausalLM,
	        FlaxBigBirdModel,
	        FlaxBigBirdForPreTraining,
	        FlaxBigBirdForMaskedLM,
	        FlaxBigBirdForMultipleChoice,
	        FlaxBigBirdForQuestionAnswering,
	        FlaxBigBirdForSequenceClassification,
	        FlaxBigBirdForTokenClassification,
	    )
	    if is_flax_available()
	    else ()
	)

	snake_case_  							=							False
	snake_case_  							=							False




	def      __magic_name__	(      self	:							Any      )	->						Tuple:
							SCREAMING_SNAKE_CASE__     :				Tuple									=FlaxBigBirdModelTester(self      )




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




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




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




	@slow
	def      __magic_name__	(      self	:							List[str]      )	->						int:





							for model_class_name in self.all_model_classes:
													SCREAMING_SNAKE_CASE__     :				int									=model_class_name.from_pretrained('''google/bigbird-roberta-base'''      )
													self.assertIsNotNone(_lowerCamelCase      )




	def      __magic_name__	(      self	:							Optional[Any]      )	->						List[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      __magic_name__	(      self	:							Optional[Any]      )	->						Optional[Any]:
							SCREAMING_SNAKE_CASE__		,	SCREAMING_SNAKE_CASE__     :				Any									=self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
													with self.subTest(model_class.__name__      ):
																			SCREAMING_SNAKE_CASE__     :				Any									=self._prepare_for_class(_lowerCamelCase					,      _lowerCamelCase      )
																			SCREAMING_SNAKE_CASE__     :				int									=model_class(_lowerCamelCase      )

																			@jax.jit
																			def model_jitted(__lowercase	:							int					,      __lowercase	:							Any=None					,      **__lowercase	:							Tuple      ):
																									return model(input_ids=_lowerCamelCase					,      attention_mask=_lowerCamelCase					,      **_lowerCamelCase      )

																			with self.subTest('''JIT Enabled'''      ):
																									SCREAMING_SNAKE_CASE__     :				str									=model_jitted(**_lowerCamelCase      ).to_tuple()

																			with self.subTest('''JIT Disabled'''      ):
																									with jax.disable_jit():
																															SCREAMING_SNAKE_CASE__     :				List[str]									=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      __magic_name__	(      self	:							Dict					,      __lowercase	:							Any					,      __lowercase	:							Dict					,      __lowercase	:							Dict					,      __lowercase	:							List[str]=1e-5					,      __lowercase	:							List[str]="outputs"					,      __lowercase	:							Dict=None      )	->						Optional[int]:





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







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

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


a_					= {
    'configuration_deberta': ['DEBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP', 'DebertaConfig', 'DebertaOnnxConfig'],
    'tokenization_deberta': ['DebertaTokenizer'],
}

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

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a_					= [
      'DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST',
      'DebertaForMaskedLM',
      'DebertaForQuestionAnswering',
      'DebertaForSequenceClassification',
      'DebertaForTokenClassification',
      'DebertaModel',
      'DebertaPreTrainedModel',
  ]

try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a_					= [
      'TF_DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST',
      'TFDebertaForMaskedLM',
      'TFDebertaForQuestionAnswering',
      'TFDebertaForSequenceClassification',
      'TFDebertaForTokenClassification',
      'TFDebertaModel',
      'TFDebertaPreTrainedModel',
  ]


if TYPE_CHECKING:
  from .configuration_deberta import DEBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP, DebertaConfig, DebertaOnnxConfig
  from .tokenization_deberta import DebertaTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_deberta_fast import DebertaTokenizerFast

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_deberta import (
        DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
        DebertaForMaskedLM,
        DebertaForQuestionAnswering,
        DebertaForSequenceClassification,
        DebertaForTokenClassification,
        DebertaModel,
        DebertaPreTrainedModel,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_deberta import (
        TF_DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFDebertaForMaskedLM,
        TFDebertaForQuestionAnswering,
        TFDebertaForSequenceClassification,
        TFDebertaForTokenClassification,
        TFDebertaModel,
        TFDebertaPreTrainedModel,
    )


else:
  import sys

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