
from collections import OrderedDict
from typing import Mapping

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


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

__lowerCAmelCase      :					Optional[int]   	=       {
    'flaubert/flaubert_small_cased': 'https://huggingface.co/flaubert/flaubert_small_cased/resolve/main/config.json',
    'flaubert/flaubert_base_uncased': 'https://huggingface.co/flaubert/flaubert_base_uncased/resolve/main/config.json',
    'flaubert/flaubert_base_cased': 'https://huggingface.co/flaubert/flaubert_base_cased/resolve/main/config.json',
    'flaubert/flaubert_large_cased': 'https://huggingface.co/flaubert/flaubert_large_cased/resolve/main/config.json',
}




class 	UpperCAmelCase_      (			_A					):


  '''simple docstring'''







  a__   	=		"""flaubert"""
  a__   	=		{
      """hidden_size""": """emb_dim""",
      """num_attention_heads""": """n_heads""",
      """num_hidden_layers""": """n_layers""",
      """n_words""": """vocab_size""",  # For backward compatibility
  }
  def __init__(			self      :			str      ,							UpperCamelCase__      :			Tuple=False      ,							UpperCamelCase__      :			int=0.0      ,							UpperCamelCase__      :			str=3_0145      ,							UpperCamelCase__      :			Any=2048      ,							UpperCamelCase__      :			Tuple=12      ,							UpperCamelCase__      :			Any=16      ,							UpperCamelCase__      :			Optional[Any]=0.1      ,							UpperCamelCase__      :			Any=0.1      ,							UpperCamelCase__      :			List[Any]=True      ,							UpperCamelCase__      :			Tuple=False      ,							UpperCamelCase__      :			List[Any]=False      ,							UpperCamelCase__      :			int=False      ,							UpperCamelCase__      :			Optional[int]=1      ,							UpperCamelCase__      :			int=True      ,							UpperCamelCase__      :			int=512      ,							UpperCamelCase__      :			str=2048**-0.5      ,							UpperCamelCase__      :			Dict=1E-12      ,							UpperCamelCase__      :			Tuple=0.02      ,							UpperCamelCase__      :			Tuple=0      ,							UpperCamelCase__      :			Optional[Any]=1      ,							UpperCamelCase__      :			Dict=2      ,							UpperCamelCase__      :			List[Any]=3      ,							UpperCamelCase__      :			Union[str, Any]=5      ,							UpperCamelCase__      :			str=True      ,							UpperCamelCase__      :			Tuple="first"      ,							UpperCamelCase__      :			Optional[int]=True      ,							UpperCamelCase__      :			Optional[Any]=None      ,							UpperCamelCase__      :			Tuple=True      ,							UpperCamelCase__      :			List[str]=0.1      ,							UpperCamelCase__      :			Tuple=5      ,							UpperCamelCase__      :			Any=5      ,							UpperCamelCase__      :			List[Any]=0      ,							UpperCamelCase__      :			Union[str, Any]=0      ,							UpperCamelCase__      :			Optional[int]=2      ,							UpperCamelCase__      :			List[str]=0      ,							**UpperCamelCase__      :			List[str]      ,							)      ->     Dict:







    """simple docstring"""






    __magic_name__    					=	pre_norm
    __magic_name__    					=	layerdrop
    __magic_name__    					=	vocab_size
    __magic_name__    					=	emb_dim
    __magic_name__    					=	n_layers
    __magic_name__    					=	n_heads
    __magic_name__    					=	dropout
    __magic_name__    					=	attention_dropout
    __magic_name__    					=	gelu_activation
    __magic_name__    					=	sinusoidal_embeddings
    __magic_name__    					=	causal
    __magic_name__    					=	asm
    __magic_name__    					=	n_langs
    __magic_name__    					=	use_lang_emb
    __magic_name__    					=	layer_norm_eps
    __magic_name__    					=	bos_index
    __magic_name__    					=	eos_index
    __magic_name__    					=	pad_index
    __magic_name__    					=	unk_index
    __magic_name__    					=	mask_index
    __magic_name__    					=	is_encoder
    __magic_name__    					=	max_position_embeddings
    __magic_name__    					=	embed_init_std
    __magic_name__    					=	init_std
    __magic_name__    					=	summary_type
    __magic_name__    					=	summary_use_proj
    __magic_name__    					=	summary_activation
    __magic_name__    					=	summary_proj_to_labels
    __magic_name__    					=	summary_first_dropout
    __magic_name__    					=	start_n_top
    __magic_name__    					=	end_n_top
    __magic_name__    					=	mask_token_id
    __magic_name__    					=	lang_id

    if "n_words" in kwargs:
      __magic_name__    					=	kwargs["""n_words"""]

    super().__init__(pad_token_id=UpperCamelCase__      ,							bos_token_id=UpperCamelCase__      ,							**UpperCamelCase__   )







class 	UpperCAmelCase_      (			_A					):


  '''simple docstring'''







  @property
  def 							_lowercase							(			self      :			Union[str, Any]   )      ->     Mapping[str, Mapping[int, str]]:







    """simple docstring"""






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



import torch.nn as nn

from .imports import is_fpa_available


if is_fpa_available():
    import transformer_engine.pytorch as te

def a__   (	A_,					A_=True,					A_=True,					A_=True ):






  '''simple docstring'''





  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(A_,					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
      __magic_name__    					=	module.bias is not None
      __magic_name__    					=	te.Linear(
          module.in_features,					module.out_features,					bias=A_,					params_dtype=module.weight.dtype )
      __magic_name__    					=	module.weight.data.clone()
      if has_bias:
        __magic_name__    					=	module.bias.data.clone()

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

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

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

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





def a__   (	A_ ):






  '''simple docstring'''





  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(A_,					(te.LayerNorm, te.Linear) ):
      return True
  return False

