


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







						'''simple docstring'''




						def __init__(					self ,    __lowercase ,    __lowercase=1_3 ,    __lowercase=7 ,    __lowercase=True ,    __lowercase=True ,    __lowercase=True ,    __lowercase=True ,    __lowercase=9_9 ,    __lowercase=2_4 ,    __lowercase=3_2 ,    __lowercase=5 ,    __lowercase=4 ,    __lowercase=3_7 ,    __lowercase="gelu" ,    __lowercase=0.1 ,    __lowercase=0.1 ,    __lowercase=5_1_2 ,    __lowercase=1_6 ,    __lowercase=2 ,    __lowercase=0.02 ,    __lowercase=4 ,    )       ->     Optional[int]:
										lowerCAmelCase_			:   Dict     					=					parent
										lowerCAmelCase_			:   List[str]     					=					batch_size
										lowerCAmelCase_			:   Tuple     					=					seq_length
										lowerCAmelCase_			:   List[str]     					=					is_training
										lowerCAmelCase_			:   Optional[Any]     					=					use_attention_mask
										lowerCAmelCase_			:   Optional[int]     					=					use_token_type_ids
										lowerCAmelCase_			:   Tuple     					=					use_labels
										lowerCAmelCase_			:   Optional[Any]     					=					vocab_size
										lowerCAmelCase_			:   List[Any]     					=					hidden_size
										lowerCAmelCase_			:   int     					=					embedding_size
										lowerCAmelCase_			:   Union[str, Any]     					=					num_hidden_layers
										lowerCAmelCase_			:   str     					=					num_attention_heads
										lowerCAmelCase_			:   Optional[Any]     					=					intermediate_size
										lowerCAmelCase_			:   Any     					=					hidden_act
										lowerCAmelCase_			:   Union[str, Any]     					=					hidden_dropout_prob
										lowerCAmelCase_			:   Dict     					=					attention_probs_dropout_prob
										lowerCAmelCase_			:   int     					=					max_position_embeddings
										lowerCAmelCase_			:   List[str]     					=					type_vocab_size
										lowerCAmelCase_			:   Union[str, Any]     					=					type_sequence_label_size
										lowerCAmelCase_			:   Dict     					=					initializer_range
										lowerCAmelCase_			:   List[str]     					=					num_choices




						def     lowercase_			(					self				)       ->     Union[str, Any]:
										lowerCAmelCase_			:   List[Any]     					=					ids_tensor([self.batch_size, self.seq_length] ,    self.vocab_size				)

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

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

										lowerCAmelCase_			:   Any     					=					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     lowercase_			(					self				)       ->     Dict:
										lowerCAmelCase_			:   Any     					=					self.prepare_config_and_inputs()
										lowerCAmelCase_			:   int     					=					config_and_inputs
										lowerCAmelCase_			:   Optional[Any]     					=					{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': attention_mask}
										return config, inputs_dict







@require_flax
class 					snake_case__(				lowerCamelCase__,    unittest.TestCase				):







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__   :	Union[str, Any]       =				True

						SCREAMING_SNAKE_CASE__   :	Optional[Any]       =				(
						    (
						        FlaxElectraModel,
						        FlaxElectraForCausalLM,
						        FlaxElectraForMaskedLM,
						        FlaxElectraForPreTraining,
						        FlaxElectraForTokenClassification,
						        FlaxElectraForQuestionAnswering,
						        FlaxElectraForMultipleChoice,
						        FlaxElectraForSequenceClassification,
						    )
						    if is_flax_available()
						    else ()
						)




						def     lowercase_			(					self				)       ->     List[Any]:
										lowerCAmelCase_			:   List[Any]     					=					FlaxElectraModelTester(self				)




						@slow
						def     lowercase_			(					self				)       ->     str:





										for model_class_name in self.all_model_classes:
														if model_class_name == FlaxElectraForMaskedLM:
																		lowerCAmelCase_			:   Optional[Any]     					=					model_class_name.from_pretrained('''google/electra-small-generator'''				)
														else:
																		lowerCAmelCase_			:   int     					=					model_class_name.from_pretrained('''google/electra-small-discriminator'''				)
														lowerCAmelCase_			:   Dict     					=					model(np.ones((1, 1)				)				)
														self.assertIsNotNone(__lowercase				)


"""simple docstring"""
from typing import Callable, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


A									=						logging.get_logger(__name__)

A									=						{
    """microsoft/prophetnet-large-uncased""": (
        """https://huggingface.co/microsoft/prophetnet-large-uncased/resolve/main/config.json"""
    ),
}

class        _UpperCamelCase	(						lowerCamelCase__	):


  """simple docstring"""





  snake_case_        =    'prophetnet'
  snake_case_        =    ['past_key_values']
  snake_case_        =    {
      'num_attention_heads': 'num_encoder_attention_heads',
  }



  def __init__( self					: Union[str, Any]       ,       snake_case					: Optional[float] = 0.1       ,       snake_case					: Optional[Union[str, Callable]] = "gelu"       ,       snake_case					: Optional[int] = 3_0522       ,       snake_case					: Optional[int] = 1024       ,       snake_case					: Optional[int] = 4096       ,       snake_case					: Optional[int] = 12       ,       snake_case					: Optional[int] = 16       ,       snake_case					: Optional[int] = 4096       ,       snake_case					: Optional[int] = 12       ,       snake_case					: Optional[int] = 16       ,       snake_case					: Optional[float] = 0.1       ,       snake_case					: Optional[float] = 0.1       ,       snake_case					: Optional[int] = 512       ,       snake_case					: Optional[float] = 0.02       ,       snake_case					: Optional[bool] = True       ,       snake_case					: Optional[bool] = True       ,       snake_case					: Optional[int] = 0       ,       snake_case					: Optional[int] = 2       ,       snake_case					: Optional[int] = 32       ,       snake_case					: Optional[int] = 128       ,       snake_case					: Optional[bool] = False       ,       snake_case					: Optional[float] = 0.0       ,       snake_case					: Optional[bool] = True       ,       snake_case					: Optional[int] = 0       ,       snake_case					: Optional[int] = 1       ,       snake_case					: Optional[int] = 2       ,       **snake_case					: Optional[int]       ,       )	->			List[Any]:


         '''simple docstring'''





         __magic_name__			:		Union[str, Any]        =     vocab_size
         __magic_name__			:		Tuple        =     hidden_size
         __magic_name__			:		str        =     encoder_ffn_dim
         __magic_name__			:		Tuple        =     num_encoder_layers
         __magic_name__			:		int        =     num_encoder_attention_heads
         __magic_name__			:		int        =     decoder_ffn_dim
         __magic_name__			:		Optional[int]        =     num_decoder_layers
         __magic_name__			:		str        =     num_decoder_attention_heads
         __magic_name__			:		Optional[Any]        =     max_position_embeddings
         __magic_name__			:		Union[str, Any]        =     init_std  # Normal(0, this parameter)
         __magic_name__			:		Tuple        =     activation_function

         # parameters for prophetnet
         __magic_name__			:		int        =     ngram
         __magic_name__			:		str        =     num_buckets
         __magic_name__			:		Any        =     relative_max_distance
         __magic_name__			:		Optional[int]        =     disable_ngram_loss
         __magic_name__			:		str        =     eps

         # 3 Types of Dropout
         __magic_name__			:		Dict        =     attention_dropout
         __magic_name__			:		Optional[int]        =     activation_dropout
         __magic_name__			:		List[Any]        =     dropout

         __magic_name__			:		str        =     use_cache

         super().__init__(
             pad_token_id=snake_case       ,       bos_token_id=snake_case       ,       eos_token_id=snake_case       ,       is_encoder_decoder=snake_case       ,       add_cross_attention=snake_case       ,       decoder_start_token_id=snake_case       ,       **snake_case       ,       )



  @property
  def 							_UpperCAmelCase      ( self					: str      )	->			int:


         '''simple docstring'''





         return self.num_encoder_layers + self.num_decoder_layers




  @num_hidden_layers.setter
  def 							_UpperCAmelCase      ( self					: Dict       ,       snake_case					: int      )	->			Optional[int]:


         '''simple docstring'''





         raise NotImplementedError(
             '''This model does not support the setting of `num_hidden_layers`. Please set `num_encoder_layers` and'''
             ''' `num_decoder_layers`.'''      )
