


'''simple docstring'''

import torch.nn as nn

from .imports import is_fpa_available


if is_fpa_available():
					import transformer_engine.pytorch as te





def __snake_case (				UpperCAmelCase_						:						Optional[Any] ,    UpperCAmelCase_						:						Optional[Any]=True ,    UpperCAmelCase_						:						Union[str, Any]=True ,    UpperCAmelCase_						:						str=True		):
	if not is_fpa_available():
		raise ImportError("Using `convert_model` requires transformer_engine to be installed."		)
	for name, module in model.named_children():
		if isinstance(UpperCAmelCase_ ,    nn.Linear		) and to_transformer_engine and _convert_linear:
			# Return early if the linear layer weights are not multiples of 16
			if any(p % 16 != 0 for p in module.weight.shape		):
				return
			lowerCamelCase_								=  module.bias is not None
			lowerCamelCase_								=  te.Linear(
			    module.in_features ,    module.out_features ,    bias=UpperCAmelCase_ ,    params_dtype=module.weight.dtype		)
			lowerCamelCase_								=  module.weight.data.clone()
			if has_bias:
				lowerCamelCase_								=  module.bias.data.clone()

			setattr(UpperCAmelCase_ ,    UpperCAmelCase_ ,    UpperCAmelCase_		)
		elif isinstance(UpperCAmelCase_ ,    nn.LayerNorm		) and to_transformer_engine and _convert_ln:
			lowerCamelCase_								=  te.LayerNorm(module.normalized_shape[0] ,    eps=module.eps ,    params_dtype=module.weight.dtype		)
			lowerCamelCase_								=  module.weight.data.clone()
			lowerCamelCase_								=  module.bias.data.clone()

			setattr(UpperCAmelCase_ ,    UpperCAmelCase_ ,    UpperCAmelCase_		)
		elif isinstance(UpperCAmelCase_ ,    te.Linear		) and not to_transformer_engine and _convert_linear:
			lowerCamelCase_								=  module.bias is not None
			lowerCamelCase_								=  nn.Linear(
			    module.in_features ,    module.out_features ,    bias=UpperCAmelCase_ ,    params_dtype=module.weight.dtype		)
			lowerCamelCase_								=  module.weight.data.clone()
			if has_bias:
				lowerCamelCase_								=  module.bias.data.clone()

			setattr(UpperCAmelCase_ ,    UpperCAmelCase_ ,    UpperCAmelCase_		)
		elif isinstance(UpperCAmelCase_ ,    te.LayerNorm		) and not to_transformer_engine and _convert_ln:
			lowerCamelCase_								=  nn.LayerNorm(module.normalized_shape[0] ,    eps=module.eps ,    params_dtype=module.weight.dtype		)
			lowerCamelCase_								=  module.weight.data.clone()
			lowerCamelCase_								=  module.bias.data.clone()

			setattr(UpperCAmelCase_ ,    UpperCAmelCase_ ,    UpperCAmelCase_		)
		else:
			convert_model(
			    UpperCAmelCase_ ,    to_transformer_engine=UpperCAmelCase_ ,    _convert_linear=_convert_linear ,    _convert_ln=_convert_ln ,    )







def __snake_case (				UpperCAmelCase_						:						List[Any]		):
	if not is_fpa_available():
		raise ImportError("Using `has_transformer_engine_layers` requires transformer_engine to be installed."		)
	for m in model.modules():
		if isinstance(UpperCAmelCase_ ,    (te.LayerNorm, te.Linear)		):
			return True
	return False







'''simple docstring'''

from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


a_  :    Optional[Any]      =			logging.get_logger(__name__)

a_  :    Tuple      =			{
    """google/electra-small-generator""": """https://huggingface.co/google/electra-small-generator/resolve/main/config.json""",
    """google/electra-base-generator""": """https://huggingface.co/google/electra-base-generator/resolve/main/config.json""",
    """google/electra-large-generator""": """https://huggingface.co/google/electra-large-generator/resolve/main/config.json""",
    """google/electra-small-discriminator""": (
        """https://huggingface.co/google/electra-small-discriminator/resolve/main/config.json"""
    ),
    """google/electra-base-discriminator""": (
        """https://huggingface.co/google/electra-base-discriminator/resolve/main/config.json"""
    ),
    """google/electra-large-discriminator""": (
        """https://huggingface.co/google/electra-large-discriminator/resolve/main/config.json"""
    ),
}





class 					snake_case   (   lowercase      ):





  """simple docstring"""




  _lowerCamelCase		   =  "electra"






  def __init__(   self      ,  UpperCamelCase=3_0522      ,  UpperCamelCase=128      ,  UpperCamelCase=256      ,  UpperCamelCase=12      ,  UpperCamelCase=4      ,  UpperCamelCase=1024      ,  UpperCamelCase="gelu"      ,  UpperCamelCase=0.1      ,  UpperCamelCase=0.1      ,  UpperCamelCase=512      ,  UpperCamelCase=2      ,  UpperCamelCase=0.02      ,  UpperCamelCase=1e-12      ,  UpperCamelCase="first"      ,  UpperCamelCase=True      ,  UpperCamelCase="gelu"      ,  UpperCamelCase=0.1      ,  UpperCamelCase=0      ,  UpperCamelCase="absolute"      ,  UpperCamelCase=True      ,  UpperCamelCase=None      ,  **UpperCamelCase      ,  ):







   """simple docstring"""
   super().__init__(pad_token_id=UpperCamelCase      ,  **UpperCamelCase					)

   lowerCamelCase_								=  vocab_size
   lowerCamelCase_								=  embedding_size
   lowerCamelCase_								=  hidden_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_								=  initializer_range
   lowerCamelCase_								=  layer_norm_eps

   lowerCamelCase_								=  summary_type
   lowerCamelCase_								=  summary_use_proj
   lowerCamelCase_								=  summary_activation
   lowerCamelCase_								=  summary_last_dropout
   lowerCamelCase_								=  position_embedding_type
   lowerCamelCase_								=  use_cache
   lowerCamelCase_								=  classifier_dropout





class 					snake_case   (   lowercase      ):





  """simple docstring"""




  @property
  def   snake_case		(   self					):







   """simple docstring"""
   if self.task == "multiple-choice":
    lowerCamelCase_								=  {0: "batch", 1: "choice", 2: "sequence"}
   else:
    lowerCamelCase_								=  {0: "batch", 1: "sequence"}
   return OrderedDict(
       [
           ("input_ids", dynamic_axis),
           ("attention_mask", dynamic_axis),
           ("token_type_ids", dynamic_axis),
       ]					)



