
"""simple docstring"""





import os
import tempfile
import unittest

from transformers import FlaubertConfig, is_torch_available
from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers import (
				    FlaubertForMultipleChoice,
				    FlaubertForQuestionAnswering,
				    FlaubertForQuestionAnsweringSimple,
				    FlaubertForSequenceClassification,
				    FlaubertForTokenClassification,
				    FlaubertModel,
				    FlaubertWithLMHeadModel,
				)
				from transformers.models.flaubert.modeling_flaubert import FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST






class        _UpperCAmelCase(       lowerCamelCase      ):



		def __init__(   self							,						__a							,						__a=13							,						__a=7							,						__a=True							,						__a=True							,						__a=True							,						__a=True							,						__a=True							,						__a=False							,						__a=False							,						__a=False							,						__a=2							,						__a=99							,						__a=0							,						__a=32							,						__a=5							,						__a=4							,						__a=0.1							,						__a=0.1							,						__a=5_12							,						__a=12							,						__a=2							,						__a=0.02							,						__a=3							,						__a=4							,						__a="last"							,						__a=None							,						__a=None							,						)			->			List[str]:






							'''simple docstring'''
							_UpperCamelCase									=    parent
							_UpperCamelCase									=    batch_size
							_UpperCamelCase									=    seq_length
							_UpperCamelCase									=    is_training
							_UpperCamelCase									=    use_input_lengths
							_UpperCamelCase									=    use_token_type_ids
							_UpperCamelCase									=    use_labels
							_UpperCamelCase									=    gelu_activation
							_UpperCamelCase									=    sinusoidal_embeddings
							_UpperCamelCase									=    causal
							_UpperCamelCase									=    asm
							_UpperCamelCase									=    n_langs
							_UpperCamelCase									=    vocab_size
							_UpperCamelCase									=    n_special
							_UpperCamelCase									=    hidden_size
							_UpperCamelCase									=    num_hidden_layers
							_UpperCamelCase									=    num_attention_heads
							_UpperCamelCase									=    hidden_dropout_prob
							_UpperCamelCase									=    attention_probs_dropout_prob
							_UpperCamelCase									=    max_position_embeddings
							_UpperCamelCase									=    type_vocab_size
							_UpperCamelCase									=    type_sequence_label_size
							_UpperCamelCase									=    initializer_range
							_UpperCamelCase									=    num_labels
							_UpperCamelCase									=    num_choices
							_UpperCamelCase									=    summary_type
							_UpperCamelCase									=    use_proj
							_UpperCamelCase									=    scope



		def 		UpperCAmelCase				(   self)			->			Optional[Any]:






							'''simple docstring'''
							_UpperCamelCase									=    ids_tensor([self.batch_size, self.seq_length]							,						self.vocab_size)
							_UpperCamelCase									=    random_attention_mask([self.batch_size, self.seq_length])

							_UpperCamelCase									=    None
							if self.use_input_lengths:
												_UpperCamelCase									=    (
												    ids_tensor([self.batch_size]							,						vocab_size=2) + self.seq_length - 2
												)  # small variation of seq_length

							_UpperCamelCase									=    None
							if self.use_token_type_ids:
												_UpperCamelCase									=    ids_tensor([self.batch_size, self.seq_length]							,						self.n_langs)

							_UpperCamelCase									=    None
							_UpperCamelCase									=    None
							_UpperCamelCase									=    None
							if self.use_labels:
												_UpperCamelCase									=    ids_tensor([self.batch_size]							,						self.type_sequence_label_size)
												_UpperCamelCase									=    ids_tensor([self.batch_size, self.seq_length]							,						self.num_labels)
												_UpperCamelCase									=    ids_tensor([self.batch_size]							,						2).float()
												_UpperCamelCase									=    ids_tensor([self.batch_size]							,						self.num_choices)

							_UpperCamelCase									=    self.get_config()

							return (
							    config,
							    input_ids,
							    token_type_ids,
							    input_lengths,
							    sequence_labels,
							    token_labels,
							    is_impossible_labels,
							    choice_labels,
							    input_mask,
							)



		def 		UpperCAmelCase				(   self)			->			Union[str, Any]:






							'''simple docstring'''
							return FlaubertConfig(
							    vocab_size=self.vocab_size							,						n_special=self.n_special							,						emb_dim=self.hidden_size							,						n_layers=self.num_hidden_layers							,						n_heads=self.num_attention_heads							,						dropout=self.hidden_dropout_prob							,						attention_dropout=self.attention_probs_dropout_prob							,						gelu_activation=self.gelu_activation							,						sinusoidal_embeddings=self.sinusoidal_embeddings							,						asm=self.asm							,						causal=self.causal							,						n_langs=self.n_langs							,						max_position_embeddings=self.max_position_embeddings							,						initializer_range=self.initializer_range							,						summary_type=self.summary_type							,						use_proj=self.use_proj							,						)



		def 		UpperCAmelCase				(   self							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						)			->			Any:






							'''simple docstring'''
							_UpperCamelCase									=    FlaubertModel(config=__a)
							model.to(__a)
							model.eval()
							_UpperCamelCase									=    model(__a							,						lengths=__a							,						langs=__a)
							_UpperCamelCase									=    model(__a							,						langs=__a)
							_UpperCamelCase									=    model(__a)
							self.parent.assertEqual(result.last_hidden_state.shape							,						(self.batch_size, self.seq_length, self.hidden_size))



		def 		UpperCAmelCase				(   self							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						)			->			List[Any]:






							'''simple docstring'''
							_UpperCamelCase									=    FlaubertWithLMHeadModel(__a)
							model.to(__a)
							model.eval()

							_UpperCamelCase									=    model(__a							,						token_type_ids=__a							,						labels=__a)
							self.parent.assertEqual(result.loss.shape							,						())
							self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.seq_length, self.vocab_size))



		def 		UpperCAmelCase				(   self							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						)			->			Dict:






							'''simple docstring'''
							_UpperCamelCase									=    FlaubertForQuestionAnsweringSimple(__a)
							model.to(__a)
							model.eval()

							_UpperCamelCase									=    model(__a)

							_UpperCamelCase									=    model(__a							,						start_positions=__a							,						end_positions=__a)
							self.parent.assertEqual(result.start_logits.shape							,						(self.batch_size, self.seq_length))
							self.parent.assertEqual(result.end_logits.shape							,						(self.batch_size, self.seq_length))



		def 		UpperCAmelCase				(   self							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						)			->			Tuple:






							'''simple docstring'''
							_UpperCamelCase									=    FlaubertForQuestionAnswering(__a)
							model.to(__a)
							model.eval()

							_UpperCamelCase									=    model(__a)

							_UpperCamelCase									=    model(
							    __a							,						start_positions=__a							,						end_positions=__a							,						cls_index=__a							,						is_impossible=__a							,						p_mask=__a							,						)

							_UpperCamelCase									=    model(
							    __a							,						start_positions=__a							,						end_positions=__a							,						cls_index=__a							,						is_impossible=__a							,						)

							((_UpperCamelCase)					,    )									=    result_with_labels.to_tuple()

							_UpperCamelCase									=    model(__a							,						start_positions=__a							,						end_positions=__a)

							((_UpperCamelCase)					,    )									=    result_with_labels.to_tuple()

							self.parent.assertEqual(result_with_labels.loss.shape							,						())
							self.parent.assertEqual(result.start_top_log_probs.shape							,						(self.batch_size, model.config.start_n_top))
							self.parent.assertEqual(result.start_top_index.shape							,						(self.batch_size, model.config.start_n_top))
							self.parent.assertEqual(
							    result.end_top_log_probs.shape							,						(self.batch_size, model.config.start_n_top * model.config.end_n_top))
							self.parent.assertEqual(
							    result.end_top_index.shape							,						(self.batch_size, model.config.start_n_top * model.config.end_n_top))
							self.parent.assertEqual(result.cls_logits.shape							,						(self.batch_size,))



		def 		UpperCAmelCase				(   self							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						)			->			Dict:






							'''simple docstring'''
							_UpperCamelCase									=    FlaubertForSequenceClassification(__a)
							model.to(__a)
							model.eval()

							_UpperCamelCase									=    model(__a)
							_UpperCamelCase									=    model(__a							,						labels=__a)

							self.parent.assertEqual(result.loss.shape							,						())
							self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.type_sequence_label_size))



		def 		UpperCAmelCase				(   self							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						)			->			int:






							'''simple docstring'''
							_UpperCamelCase									=    self.num_labels
							_UpperCamelCase									=    FlaubertForTokenClassification(__a)
							model.to(__a)
							model.eval()

							_UpperCamelCase									=    model(__a							,						attention_mask=__a							,						labels=__a)
							self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.seq_length, self.num_labels))



		def 		UpperCAmelCase				(   self							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						)			->			Optional[Any]:






							'''simple docstring'''
							_UpperCamelCase									=    self.num_choices
							_UpperCamelCase									=    FlaubertForMultipleChoice(config=__a)
							model.to(__a)
							model.eval()
							_UpperCamelCase									=    input_ids.unsqueeze(1).expand(-1							,						self.num_choices							,						-1).contiguous()
							_UpperCamelCase									=    token_type_ids.unsqueeze(1).expand(-1							,						self.num_choices							,						-1).contiguous()
							_UpperCamelCase									=    input_mask.unsqueeze(1).expand(-1							,						self.num_choices							,						-1).contiguous()
							_UpperCamelCase									=    model(
							    __a							,						attention_mask=__a							,						token_type_ids=__a							,						labels=__a							,						)
							self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.num_choices))




		def 		UpperCAmelCase				(   self)			->			Any:






							'''simple docstring'''
							_UpperCamelCase									=    self.prepare_config_and_inputs()
							(
							    (
							    _UpperCamelCase
							)					,    (
							    _UpperCamelCase
							)					,    (
							    _UpperCamelCase
							)					,    (
							    _UpperCamelCase
							)					,    (
							    _UpperCamelCase
							)					,    (
							    _UpperCamelCase
							)					,    (
							    _UpperCamelCase
							)					,    (
							    _UpperCamelCase
							)					,    (
							    _UpperCamelCase
							)					,    
							)									=    config_and_inputs
							_UpperCamelCase									=    {
							    '''input_ids''': input_ids,
							    '''token_type_ids''': token_type_ids,
							    '''lengths''': input_lengths,
							    '''attention_mask''': input_mask,
							}
							return config, inputs_dict






@require_torch
class        _UpperCAmelCase(       lowerCamelCase ,	lowerCamelCase ,	unittest.TestCase      ):
		lowercase__         = (
		    (
		        FlaubertModel,
		        FlaubertWithLMHeadModel,
		        FlaubertForQuestionAnswering,
		        FlaubertForQuestionAnsweringSimple,
		        FlaubertForSequenceClassification,
		        FlaubertForTokenClassification,
		        FlaubertForMultipleChoice,
		    )
		    if is_torch_available()
		    else ()
		)
		lowercase__         = (
		    {
		        'feature-extraction': FlaubertModel,
		        'fill-mask': FlaubertWithLMHeadModel,
		        'question-answering': FlaubertForQuestionAnsweringSimple,
		        'text-classification': FlaubertForSequenceClassification,
		        'token-classification': FlaubertForTokenClassification,
		        'zero-shot': FlaubertForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)



		def 		UpperCAmelCase				(   self							,						__a							,						__a							,						__a							,						__a							,						__a)			->			Optional[Any]:






							'''simple docstring'''
							if (
							    pipeline_test_casse_name == "QAPipelineTests"
							    and tokenizer_name is not None
							    and not tokenizer_name.endswith('''Fast''')
							):
												# `QAPipelineTests` fails for a few models when the slower tokenizer are used.
												# (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
												# TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
												return True

							return False



		def 		UpperCAmelCase				(   self							,						__a							,						__a							,						__a=False)			->			Dict:






							'''simple docstring'''
							_UpperCamelCase									=    super()._prepare_for_class(__a							,						__a							,						return_labels=__a)

							if return_labels:
												if model_class.__name__ == "FlaubertForQuestionAnswering":
																	_UpperCamelCase									=    torch.zeros(
																	    self.model_tester.batch_size							,						dtype=torch.long							,						device=__a)
																	_UpperCamelCase									=    torch.zeros(
																	    self.model_tester.batch_size							,						dtype=torch.long							,						device=__a)

							return inputs_dict



		def 		UpperCAmelCase				(   self)			->			Union[str, Any]:






							'''simple docstring'''
							_UpperCamelCase									=    FlaubertModelTester(self)
							_UpperCamelCase									=    ConfigTester(self							,						config_class=__a							,						emb_dim=37)



		def 		UpperCAmelCase				(   self)			->			List[Any]:






							'''simple docstring'''
							self.config_tester.run_common_tests()



		def 		UpperCAmelCase				(   self)			->			Union[str, Any]:






							'''simple docstring'''
							_UpperCamelCase									=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_flaubert_model(*__a)



		def 		UpperCAmelCase				(   self)			->			Union[str, Any]:






							'''simple docstring'''
							_UpperCamelCase									=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_flaubert_lm_head(*__a)



		def 		UpperCAmelCase				(   self)			->			int:






							'''simple docstring'''
							_UpperCamelCase									=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_flaubert_simple_qa(*__a)



		def 		UpperCAmelCase				(   self)			->			Optional[int]:






							'''simple docstring'''
							_UpperCamelCase									=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_flaubert_qa(*__a)



		def 		UpperCAmelCase				(   self)			->			List[Any]:






							'''simple docstring'''
							_UpperCamelCase									=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_flaubert_sequence_classif(*__a)



		def 		UpperCAmelCase				(   self)			->			Any:






							'''simple docstring'''
							_UpperCamelCase									=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_flaubert_token_classif(*__a)



		def 		UpperCAmelCase				(   self)			->			Any:






							'''simple docstring'''
							_UpperCamelCase									=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_flaubert_multiple_choice(*__a)



		@slow
		def 		UpperCAmelCase				(   self)			->			Union[str, Any]:






							'''simple docstring'''
							for model_name in FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												_UpperCamelCase									=    FlaubertModel.from_pretrained(__a)
												self.assertIsNotNone(__a)




		@slow
		@require_torch_gpu
		def 		UpperCAmelCase				(   self)			->			Union[str, Any]:






							'''simple docstring'''
							_UpperCamelCase					,    _UpperCamelCase									=    self.model_tester.prepare_config_and_inputs_for_common()
							for model_class in self.all_model_classes:
												# FlauBertForMultipleChoice behaves incorrectly in JIT environments.
												if model_class == FlaubertForMultipleChoice:
																	return

												_UpperCamelCase									=    True
												_UpperCamelCase									=    model_class(config=__a)

												_UpperCamelCase									=    self._prepare_for_class(__a							,						__a)
												_UpperCamelCase									=    torch.jit.trace(
												    __a							,						(inputs_dict['''input_ids'''].to('''cpu'''), inputs_dict['''attention_mask'''].to('''cpu''')))

												with tempfile.TemporaryDirectory() as tmp:
																	torch.jit.save(__a							,						os.path.join(__a							,						'''traced_model.pt'''))
																	_UpperCamelCase									=    torch.jit.load(os.path.join(__a							,						'''traced_model.pt''')							,						map_location=__a)
																	loaded(inputs_dict['''input_ids'''].to(__a)							,						inputs_dict['''attention_mask'''].to(__a))






@require_torch
class        _UpperCAmelCase(       unittest.TestCase      ):



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






							'''simple docstring'''
							_UpperCamelCase									=    FlaubertModel.from_pretrained('''flaubert/flaubert_base_cased''')
							_UpperCamelCase									=    torch.tensor([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]])
							with torch.no_grad():
												_UpperCamelCase									=    model(__a)[0]
							_UpperCamelCase									=    torch.Size((1, 11, 7_68))
							self.assertEqual(output.shape							,						__a)
							_UpperCamelCase									=    torch.tensor(
							    [[[-2.6251, -1.4298, -0.0227], [-2.8510, -1.6387, 0.2258], [-2.8114, -1.1832, -0.3066]]])

							self.assertTrue(torch.allclose(output[:, :3, :3]							,						__a							,						atol=1e-4))








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

 '''simple docstring'''







 def __init__(					self		:  Tuple			,				snake_case__		:  List[str]			,				snake_case__		:  Union[str, Any]=2			,				snake_case__		:  int=56			,				snake_case__		:  Any=True			,				snake_case__		:  Union[str, Any]=True			,				snake_case__		:  Optional[int]=True			,				snake_case__		:  Any=True			,				snake_case__		:  Tuple=99			,				snake_case__		:  Any=32			,				snake_case__		:  List[Any]=2			,				snake_case__		:  Optional[Any]=2			,				snake_case__		:  Any=7			,				snake_case__		:  Union[str, Any]="gelu_new"			,				snake_case__		:  List[Any]=0.1			,				snake_case__		:  Optional[Any]=0.1			,				snake_case__		:  Optional[int]=5_12			,				snake_case__		:  Optional[int]=16			,				snake_case__		:  int=2			,				snake_case__		:  List[Any]=0.02			,				snake_case__		:  int=4			,				snake_case__		:  Optional[Any]="block_sparse"			,				snake_case__		:  Union[str, Any]=True			,				snake_case__		:  List[Any]=False			,				snake_case__		:  Optional[Any]=2			,				snake_case__		:  Optional[Any]=3			,				):



   '''simple docstring'''




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

   UpperCAmelCase__      :					List[str]				       =							rescale_embeddings
   UpperCAmelCase__      :					Union[str, Any]				       =							attention_type
   UpperCAmelCase__      :					Union[str, Any]				       =							use_bias
   UpperCAmelCase__      :					Union[str, Any]				       =							block_size
   UpperCAmelCase__      :					Any				       =							num_random_blocks







 def 							UpperCamelCase  (					self		:  Optional[Any] ):



   '''simple docstring'''




   UpperCAmelCase__      :					Optional[int]				       =							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__      :					Union[str, Any]				       =							None
   if self.use_token_type_ids:
     UpperCAmelCase__      :					Any				       =							ids_tensor([self.batch_size, self.seq_length]			,				self.type_vocab_size )

   UpperCAmelCase__      :					Union[str, 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=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 							UpperCamelCase  (					self		:  Tuple ):



   '''simple docstring'''




   UpperCAmelCase__      :					int				       =							self.prepare_config_and_inputs()
   UpperCAmelCase__       ,			UpperCAmelCase__       ,			UpperCAmelCase__       ,			UpperCAmelCase__      :					Tuple				       =							config_and_inputs
   UpperCAmelCase__      :					str				       =							{
       "input_ids": input_ids,
       "token_type_ids": token_type_ids,
       "attention_mask": attention_mask,
   }
   return config, inputs_dict






@require_flax
class 							UpperCAmelCase_							(    A					,				unittest.TestCase				):

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

 lowercase_					:    Optional[Any]				=							False
 lowercase_					:    str				=							False







 def 							UpperCamelCase  (					self		:  Optional[Any] ):



   '''simple docstring'''




   UpperCAmelCase__      :					int				       =							FlaxBigBirdModelTester(self )







 @slow
 # copied from `test_modeling_flax_common` because it takes much longer than other models
 def 							UpperCamelCase  (					self		:  List[Any] ):



   '''simple docstring'''




   super().test_from_pretrained_save_pretrained()







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



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



   '''simple docstring'''




   super().test_no_automatic_init()







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



   '''simple docstring'''




   super().test_hidden_states_output()







 @slow
 def 							UpperCamelCase  (					self		:  List[Any] ):



   '''simple docstring'''




   for model_class_name in self.all_model_classes:
     UpperCAmelCase__      :					List[Any]				       =							model_class_name.from_pretrained("google/bigbird-roberta-base" )
     self.assertIsNotNone(snake_case__ )







 def 							UpperCamelCase  (					self		:  Union[str, Any] ):



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



   '''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(snake_case__			,				snake_case__ )
       UpperCAmelCase__      :					List[Any]				       =							model_class(snake_case__ )

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

       with self.subTest("JIT Enabled" ):
         UpperCAmelCase__      :					List[Any]				       =							model_jitted(**snake_case__ ).to_tuple()

       with self.subTest("JIT Disabled" ):
         with jax.disable_jit():
           UpperCAmelCase__      :					Tuple				       =							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 							UpperCamelCase  (					self		:  List[str]			,				snake_case__		:  int			,				snake_case__		:  Dict			,				snake_case__		:  Any			,				snake_case__		:  Union[str, Any]=1e-5			,				snake_case__		:  Any="outputs"			,				snake_case__		:  Optional[Any]=None ):



   '''simple docstring'''




   if name.startswith("outputs.attentions" ):
     return
   else:
     super().check_pt_flax_outputs(snake_case__			,				snake_case__			,				snake_case__			,				snake_case__			,				snake_case__			,				snake_case__ )



