



import unittest

from transformers import FunnelConfig, FunnelTokenizer, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

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


if is_torch_available():
		import torch

		from transformers import (
		    MODEL_FOR_PRETRAINING_MAPPING,
		    FunnelBaseModel,
		    FunnelForMaskedLM,
		    FunnelForMultipleChoice,
		    FunnelForPreTraining,
		    FunnelForQuestionAnswering,
		    FunnelForSequenceClassification,
		    FunnelForTokenClassification,
		    FunnelModel,
		)



class 	__lowerCAmelCase       :




	def __init__(  self		,			__UpperCAmelCase		,			__UpperCAmelCase=13		,			__UpperCAmelCase=7		,			__UpperCAmelCase=True		,			__UpperCAmelCase=True		,			__UpperCAmelCase=True		,			__UpperCAmelCase=True		,			__UpperCAmelCase=99		,			__UpperCAmelCase=[1, 1, 2]		,			__UpperCAmelCase=1		,			__UpperCAmelCase=32		,			__UpperCAmelCase=4		,			__UpperCAmelCase=8		,			__UpperCAmelCase=37		,			__UpperCAmelCase="gelu_new"		,			__UpperCAmelCase=0.1		,			__UpperCAmelCase=0.1		,			__UpperCAmelCase=0.0		,			__UpperCAmelCase=512		,			__UpperCAmelCase=3		,			__UpperCAmelCase=0.02		,			__UpperCAmelCase=3		,			__UpperCAmelCase=4		,			__UpperCAmelCase=None		,			__UpperCAmelCase=False		,			):



				'''simple docstring'''
				__lowerCamelCase  							=      parent
				__lowerCamelCase  							=      batch_size
				__lowerCamelCase  							=      seq_length
				__lowerCamelCase  							=      is_training
				__lowerCamelCase  							=      use_input_mask
				__lowerCamelCase  							=      use_token_type_ids
				__lowerCamelCase  							=      use_labels
				__lowerCamelCase  							=      vocab_size
				__lowerCamelCase  							=      block_sizes
				__lowerCamelCase  							=      num_decoder_layers
				__lowerCamelCase  							=      d_model
				__lowerCamelCase  							=      n_head
				__lowerCamelCase  							=      d_head
				__lowerCamelCase  							=      d_inner
				__lowerCamelCase  							=      hidden_act
				__lowerCamelCase  							=      hidden_dropout
				__lowerCamelCase  							=      attention_dropout
				__lowerCamelCase  							=      activation_dropout
				__lowerCamelCase  							=      max_position_embeddings
				__lowerCamelCase  							=      type_vocab_size
				__lowerCamelCase  							=      2
				__lowerCamelCase  							=      num_labels
				__lowerCamelCase  							=      num_choices
				__lowerCamelCase  							=      scope
				__lowerCamelCase  							=      initializer_std

				# Used in the tests to check the size of the first attention layer
				__lowerCamelCase  							=      n_head
				# Used in the tests to check the size of the first hidden state
				__lowerCamelCase  							=      self.d_model
				# Used in the tests to check the number of output hidden states/attentions
				__lowerCamelCase  							=      sum(self.block_sizes			) + (0 if base else self.num_decoder_layers)
				# FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
				# the last hidden state of the first block (which is the first hidden state of the decoder).
				if not base:
							__lowerCamelCase  							=      self.num_hidden_layers + 2




	def     lowerCamelCase (  self			):



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

				__lowerCamelCase  							=      None
				if self.use_input_mask:
							__lowerCamelCase  							=      ids_tensor([self.batch_size, self.seq_length]		,			vocab_size=2			)

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

				__lowerCamelCase  							=      None
				__lowerCamelCase  							=      None
				__lowerCamelCase  							=      None
				if self.use_labels:
							__lowerCamelCase  							=      ids_tensor([self.batch_size]		,			self.type_sequence_label_size			)
							__lowerCamelCase  							=      ids_tensor([self.batch_size, self.seq_length]		,			self.num_labels			)
							__lowerCamelCase  							=      ids_tensor([self.batch_size]		,			self.num_choices			)
							__lowerCamelCase  							=      ids_tensor([self.batch_size, self.seq_length]		,			1			)

				__lowerCamelCase  							=      self.get_config()

				return (
				    config,
				    input_ids,
				    token_type_ids,
				    input_mask,
				    sequence_labels,
				    token_labels,
				    choice_labels,
				    fake_token_labels,
				)




	def     lowerCamelCase (  self			):



				'''simple docstring'''
				return FunnelConfig(
				    vocab_size=self.vocab_size		,			block_sizes=self.block_sizes		,			num_decoder_layers=self.num_decoder_layers		,			d_model=self.d_model		,			n_head=self.n_head		,			d_head=self.d_head		,			d_inner=self.d_inner		,			hidden_act=self.hidden_act		,			hidden_dropout=self.hidden_dropout		,			attention_dropout=self.attention_dropout		,			activation_dropout=self.activation_dropout		,			max_position_embeddings=self.max_position_embeddings		,			type_vocab_size=self.type_vocab_size		,			initializer_std=self.initializer_std		,			)




	def     lowerCamelCase (  self		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			):



				'''simple docstring'''
				__lowerCamelCase  							=      FunnelModel(config=lowercase__			)
				model.to(lowercase__			)
				model.eval()
				__lowerCamelCase  							=      model(lowercase__		,			attention_mask=lowercase__		,			token_type_ids=lowercase__			)
				__lowerCamelCase  							=      model(lowercase__		,			token_type_ids=lowercase__			)
				__lowerCamelCase  							=      model(lowercase__			)
				self.parent.assertEqual(result.last_hidden_state.shape		,			(self.batch_size, self.seq_length, self.d_model)			)

				__lowerCamelCase  							=      False
				__lowerCamelCase  							=      model(lowercase__			)
				self.parent.assertEqual(result.last_hidden_state.shape		,			(self.batch_size, self.seq_length, self.d_model)			)

				__lowerCamelCase  							=      False
				__lowerCamelCase  							=      model(lowercase__			)
				self.parent.assertEqual(result.last_hidden_state.shape		,			(self.batch_size, self.seq_length, self.d_model)			)




	def     lowerCamelCase (  self		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			):



				'''simple docstring'''
				__lowerCamelCase  							=      FunnelBaseModel(config=lowercase__			)
				model.to(lowercase__			)
				model.eval()
				__lowerCamelCase  							=      model(lowercase__		,			attention_mask=lowercase__		,			token_type_ids=lowercase__			)
				__lowerCamelCase  							=      model(lowercase__		,			token_type_ids=lowercase__			)
				__lowerCamelCase  							=      model(lowercase__			)
				self.parent.assertEqual(result.last_hidden_state.shape		,			(self.batch_size, 2, self.d_model)			)

				__lowerCamelCase  							=      False
				__lowerCamelCase  							=      model(lowercase__			)
				self.parent.assertEqual(result.last_hidden_state.shape		,			(self.batch_size, 3, self.d_model)			)

				__lowerCamelCase  							=      False
				__lowerCamelCase  							=      model(lowercase__			)
				self.parent.assertEqual(result.last_hidden_state.shape		,			(self.batch_size, 2, self.d_model)			)




	def     lowerCamelCase (  self		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			):



				'''simple docstring'''
				__lowerCamelCase  							=      self.num_labels
				__lowerCamelCase  							=      FunnelForPreTraining(config=lowercase__			)
				model.to(lowercase__			)
				model.eval()
				__lowerCamelCase  							=      model(lowercase__		,			attention_mask=lowercase__		,			token_type_ids=lowercase__		,			labels=lowercase__			)
				self.parent.assertEqual(result.logits.shape		,			(self.batch_size, self.seq_length)			)




	def     lowerCamelCase (  self		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			):



				'''simple docstring'''
				__lowerCamelCase  							=      FunnelForMaskedLM(config=lowercase__			)
				model.to(lowercase__			)
				model.eval()
				__lowerCamelCase  							=      model(lowercase__		,			attention_mask=lowercase__		,			token_type_ids=lowercase__		,			labels=lowercase__			)
				self.parent.assertEqual(result.logits.shape		,			(self.batch_size, self.seq_length, self.vocab_size)			)




	def     lowerCamelCase (  self		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			):



				'''simple docstring'''
				__lowerCamelCase  							=      self.num_labels
				__lowerCamelCase  							=      FunnelForSequenceClassification(lowercase__			)
				model.to(lowercase__			)
				model.eval()
				__lowerCamelCase  							=      model(lowercase__		,			attention_mask=lowercase__		,			token_type_ids=lowercase__		,			labels=lowercase__			)
				self.parent.assertEqual(result.logits.shape		,			(self.batch_size, self.num_labels)			)




	def     lowerCamelCase (  self		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			):



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




	def     lowerCamelCase (  self		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			):



				'''simple docstring'''
				__lowerCamelCase  							=      self.num_labels
				__lowerCamelCase  							=      FunnelForTokenClassification(config=lowercase__			)
				model.to(lowercase__			)
				model.eval()
				__lowerCamelCase  							=      model(lowercase__		,			attention_mask=lowercase__		,			token_type_ids=lowercase__		,			labels=lowercase__			)
				self.parent.assertEqual(result.logits.shape		,			(self.batch_size, self.seq_length, self.num_labels)			)




	def     lowerCamelCase (  self		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase		,			):



				'''simple docstring'''
				__lowerCamelCase  							=      FunnelForQuestionAnswering(config=lowercase__			)
				model.to(lowercase__			)
				model.eval()
				__lowerCamelCase  							=      model(
				    lowercase__		,			attention_mask=lowercase__		,			token_type_ids=lowercase__		,			start_positions=lowercase__		,			end_positions=lowercase__		,			)
				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     lowerCamelCase (  self			):



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



@require_torch
class 	__lowerCAmelCase       (		lowerCAmelCase__					,		lowerCAmelCase__					,		unittest.TestCase				):
	lowerCAmelCase__       =					False
	lowerCAmelCase__       =					False
	lowerCAmelCase__       =					(
	    (
	        FunnelModel,
	        FunnelForMaskedLM,
	        FunnelForPreTraining,
	        FunnelForQuestionAnswering,
	        FunnelForTokenClassification,
	    )
	    if is_torch_available()
	    else ()
	)
	lowerCAmelCase__       =					(
	    {
	        "feature-extraction": (FunnelBaseModel, FunnelModel),
	        "fill-mask": FunnelForMaskedLM,
	        "question-answering": FunnelForQuestionAnswering,
	        "text-classification": FunnelForSequenceClassification,
	        "token-classification": FunnelForTokenClassification,
	        "zero-shot": FunnelForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)




	def     lowerCamelCase (  self		,			__UpperCAmelCase		,			__UpperCAmelCase		,			__UpperCAmelCase=False			):



				'''simple docstring'''
				__lowerCamelCase  							=      super()._prepare_for_class(lowercase__		,			lowercase__		,			return_labels=lowercase__			)

				if return_labels:
							if model_class in get_values(lowercase__			):
										__lowerCamelCase  							=      torch.zeros(
										    (self.model_tester.batch_size, self.model_tester.seq_length)		,			dtype=torch.long		,			device=lowercase__			)
				return inputs_dict




	def     lowerCamelCase (  self			):



				'''simple docstring'''
				__lowerCamelCase  							=      FunnelModelTester(self			)
				__lowerCamelCase  							=      ConfigTester(self		,			config_class=lowercase__			)




	def     lowerCamelCase (  self			):



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




	def     lowerCamelCase (  self			):



				'''simple docstring'''
				__lowerCamelCase  							=      self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*lowercase__			)




	def     lowerCamelCase (  self			):



				'''simple docstring'''
				__lowerCamelCase  							=      self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_pretraining(*lowercase__			)




	def     lowerCamelCase (  self			):



				'''simple docstring'''
				__lowerCamelCase  							=      self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_masked_lm(*lowercase__			)




	def     lowerCamelCase (  self			):



				'''simple docstring'''
				__lowerCamelCase  							=      self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_token_classification(*lowercase__			)




	def     lowerCamelCase (  self			):



				'''simple docstring'''
				__lowerCamelCase  							=      self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_question_answering(*lowercase__			)




	def     lowerCamelCase (  self		,			__UpperCAmelCase			):



				'''simple docstring'''







				if hasattr(lowercase__		,			'''weight'''			) and module.weight is not None:
							module.weight.data.fill_(3			)
				if hasattr(lowercase__		,			'''bias'''			) and module.bias is not None:
							module.bias.data.fill_(3			)

				for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
							if hasattr(lowercase__		,			lowercase__			) and getattr(lowercase__		,			lowercase__			) is not None:
										__lowerCamelCase  							=      getattr(lowercase__		,			lowercase__			)
										weight.data.fill_(3			)



@require_torch
class 	__lowerCAmelCase       (		lowerCAmelCase__					,		unittest.TestCase				):
	lowerCAmelCase__       =					False
	lowerCAmelCase__       =					False
	lowerCAmelCase__       =					(
	    (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
	)




	def     lowerCamelCase (  self			):



				'''simple docstring'''
				__lowerCamelCase  							=      FunnelModelTester(self		,			base=lowercase__			)
				__lowerCamelCase  							=      ConfigTester(self		,			config_class=lowercase__			)




	def     lowerCamelCase (  self			):



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




	def     lowerCamelCase (  self			):



				'''simple docstring'''
				__lowerCamelCase  							=      self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_base_model(*lowercase__			)




	def     lowerCamelCase (  self			):



				'''simple docstring'''
				__lowerCamelCase  							=      self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_sequence_classification(*lowercase__			)




	def     lowerCamelCase (  self			):



				'''simple docstring'''
				__lowerCamelCase  							=      self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_multiple_choice(*lowercase__			)




	def     lowerCamelCase (  self			):



				'''simple docstring'''
				__lowerCamelCase							,__lowerCamelCase  							=      self.model_tester.prepare_config_and_inputs_for_common()
				__lowerCamelCase  							=      True

				for model_class in self.all_model_classes:
							if model_class.__name__ == "FunnelBaseModel":
										continue
							__lowerCamelCase  							=      model_class(lowercase__			)
							model.to(lowercase__			)
							model.train()
							__lowerCamelCase  							=      self._prepare_for_class(lowercase__		,			lowercase__		,			return_labels=lowercase__			)
							__lowerCamelCase  							=      model(**lowercase__			).loss
							loss.backward()




	def     lowerCamelCase (  self		,			__UpperCAmelCase			):



				'''simple docstring'''







				if hasattr(lowercase__		,			'''weight'''			) and module.weight is not None:
							module.weight.data.fill_(3			)
				if hasattr(lowercase__		,			'''bias'''			) and module.bias is not None:
							module.bias.data.fill_(3			)

				for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
							if hasattr(lowercase__		,			lowercase__			) and getattr(lowercase__		,			lowercase__			) is not None:
										__lowerCamelCase  							=      getattr(lowercase__		,			lowercase__			)
										weight.data.fill_(3			)



@require_torch
@require_sentencepiece
@require_tokenizers
class 	__lowerCAmelCase       (		unittest.TestCase				):




	def     lowerCamelCase (  self			):



				'''simple docstring'''
				__lowerCamelCase  							=      13
				__lowerCamelCase  							=      7
				__lowerCamelCase  							=      torch.arange(0		,			batch_size * sequence_length			).long().reshape(lowercase__		,			lowercase__			)
				__lowerCamelCase  							=      [0, 1, 2, 3, 4, 5, 6, 4, 1, 3, 5, 0, 1]
				__lowerCamelCase  							=      torch.tensor([[2] + [0] * a + [1] * (sequence_length - a - 1) for a in lengths]			)

				__lowerCamelCase  							=      FunnelModel.from_pretrained('''sgugger/funnel-random-tiny'''			)
				__lowerCamelCase  							=      model(lowercase__		,			token_type_ids=lowercase__			)[0].abs()

				__lowerCamelCase  							=      torch.tensor(2344.8352			)
				__lowerCamelCase  							=      torch.tensor(0.8_052			)
				self.assertTrue(torch.allclose(output.sum()		,			lowercase__		,			atol=1E-4			)			)
				self.assertTrue(torch.allclose(output.mean()		,			lowercase__		,			atol=1E-4			)			)

				__lowerCamelCase  							=      torch.tensor([[1] * 7, [1] * 4 + [0] * 3] * 6 + [[0, 1, 1, 0, 0, 1, 1]]			)
				__lowerCamelCase  							=      model(lowercase__		,			attention_mask=lowercase__		,			token_type_ids=lowercase__			)[0].abs()

				__lowerCamelCase  							=      torch.tensor(2343.8425			)
				__lowerCamelCase  							=      torch.tensor(0.8_049			)
				self.assertTrue(torch.allclose(output.sum()		,			lowercase__		,			atol=1E-4			)			)
				self.assertTrue(torch.allclose(output.mean()		,			lowercase__		,			atol=1E-4			)			)




	@slow
	def     lowerCamelCase (  self			):



				'''simple docstring'''
				__lowerCamelCase  							=      FunnelTokenizer.from_pretrained('''huggingface/funnel-small'''			)
				__lowerCamelCase  							=      FunnelModel.from_pretrained('''huggingface/funnel-small'''			)
				__lowerCamelCase  							=      tokenizer('''Hello! I am the Funnel Transformer model.'''		,			return_tensors='''pt'''			)
				__lowerCamelCase  							=      model(**lowercase__			)[0]

				__lowerCamelCase  							=      torch.tensor(235.7_246			)
				__lowerCamelCase  							=      torch.tensor(0.0_256			)
				self.assertTrue(torch.allclose(output.sum()		,			lowercase__		,			atol=1E-4			)			)
				self.assertTrue(torch.allclose(output.mean()		,			lowercase__		,			atol=1E-4			)			)











import unittest

import numpy as np

from transformers import ElectraConfig, 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():
  from transformers.models.electra.modeling_flax_electra import (
      FlaxElectraForCausalLM,
      FlaxElectraForMaskedLM,
      FlaxElectraForMultipleChoice,
      FlaxElectraForPreTraining,
      FlaxElectraForQuestionAnswering,
      FlaxElectraForSequenceClassification,
      FlaxElectraForTokenClassification,
      FlaxElectraModel,
  )



class 	__lowerCAmelCase       (		unittest.TestCase				):




 def __init__(  self		,			__UpperCAmelCase		,			__UpperCAmelCase=13		,			__UpperCAmelCase=7		,			__UpperCAmelCase=True		,			__UpperCAmelCase=True		,			__UpperCAmelCase=True		,			__UpperCAmelCase=True		,			__UpperCAmelCase=99		,			__UpperCAmelCase=24		,			__UpperCAmelCase=32		,			__UpperCAmelCase=5		,			__UpperCAmelCase=4		,			__UpperCAmelCase=37		,			__UpperCAmelCase="gelu"		,			__UpperCAmelCase=0.1		,			__UpperCAmelCase=0.1		,			__UpperCAmelCase=512		,			__UpperCAmelCase=16		,			__UpperCAmelCase=2		,			__UpperCAmelCase=0.02		,			__UpperCAmelCase=4		,			):



    '''simple docstring'''
    __lowerCamelCase  							=      parent
    __lowerCamelCase  							=      batch_size
    __lowerCamelCase  							=      seq_length
    __lowerCamelCase  							=      is_training
    __lowerCamelCase  							=      use_attention_mask
    __lowerCamelCase  							=      use_token_type_ids
    __lowerCamelCase  							=      use_labels
    __lowerCamelCase  							=      vocab_size
    __lowerCamelCase  							=      hidden_size
    __lowerCamelCase  							=      embedding_size
    __lowerCamelCase  							=      num_hidden_layers
    __lowerCamelCase  							=      num_attention_heads
    __lowerCamelCase  							=      intermediate_size
    __lowerCamelCase  							=      hidden_act
    __lowerCamelCase  							=      hidden_dropout_prob
    __lowerCamelCase  							=      attention_probs_dropout_prob
    __lowerCamelCase  							=      max_position_embeddings
    __lowerCamelCase  							=      type_vocab_size
    __lowerCamelCase  							=      type_sequence_label_size
    __lowerCamelCase  							=      initializer_range
    __lowerCamelCase  							=      num_choices




 def     lowerCamelCase (  self			):



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

    __lowerCamelCase  							=      None
    if self.use_attention_mask:
       __lowerCamelCase  							=      random_attention_mask([self.batch_size, self.seq_length]			)

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

    __lowerCamelCase  							=      ElectraConfig(
        vocab_size=self.vocab_size		,			hidden_size=self.hidden_size		,			embedding_size=self.embedding_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		,			initializer_range=self.initializer_range		,			)

    return config, input_ids, token_type_ids, attention_mask




 def     lowerCamelCase (  self			):



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



@require_flax
class 	__lowerCAmelCase       (		lowerCAmelCase__					,		unittest.TestCase				):
 lowerCAmelCase__       =					True

 lowerCAmelCase__       =					(
     (
         FlaxElectraModel,
         FlaxElectraForCausalLM,
         FlaxElectraForMaskedLM,
         FlaxElectraForPreTraining,
         FlaxElectraForTokenClassification,
         FlaxElectraForQuestionAnswering,
         FlaxElectraForMultipleChoice,
         FlaxElectraForSequenceClassification,
     )
     if is_flax_available()
     else ()
 )




 def     lowerCamelCase (  self			):



    '''simple docstring'''
    __lowerCamelCase  							=      FlaxElectraModelTester(self			)




 @slow
 def     lowerCamelCase (  self			):



    '''simple docstring'''
    for model_class_name in self.all_model_classes:
       if model_class_name == FlaxElectraForMaskedLM:
          __lowerCamelCase  							=      model_class_name.from_pretrained('''google/electra-small-generator'''			)
       else:
          __lowerCamelCase  							=      model_class_name.from_pretrained('''google/electra-small-discriminator'''			)
       __lowerCamelCase  							=      model(np.ones((1, 1)			)			)
       self.assertIsNotNone(__UpperCAmelCase			)






