
"""simple docstring"""




from dataclasses import asdict, dataclass
from typing import Optional

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


A__      :	Dict          =    logging.get_logger(__name__)

# TODO Update this
A__      :	Optional[int]          =    {
    'facebook/esm-1b': 'https://huggingface.co/facebook/esm-1b/resolve/main/config.json',
    # See all ESM models at https://huggingface.co/models?filter=esm
}







class   _lowercase						(       SCREAMING_SNAKE_CASE_				):


     '''simple docstring'''





     _A								=							'esm'



     def __init__(      self ,			__UpperCamelCase=None ,			__UpperCamelCase=None ,			__UpperCamelCase=None ,			__UpperCamelCase=7_68 ,			__UpperCamelCase=12 ,			__UpperCamelCase=12 ,			__UpperCamelCase=30_72 ,			__UpperCamelCase=0.1 ,			__UpperCamelCase=0.1 ,			__UpperCamelCase=10_26 ,			__UpperCamelCase=0.02 ,			__UpperCamelCase=1E-12 ,			__UpperCamelCase="absolute" ,			__UpperCamelCase=True ,			__UpperCamelCase=None ,			__UpperCamelCase=False ,			__UpperCamelCase=False ,			__UpperCamelCase=None ,			__UpperCamelCase=None ,			**__UpperCamelCase ,			)->					int:

          '''simple docstring'''





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

          UpperCAmelCase__							: Optional[Any] 							=						vocab_size
          UpperCAmelCase__							: int 							=						hidden_size
          UpperCAmelCase__							: List[str] 							=						num_hidden_layers
          UpperCAmelCase__							: Tuple 							=						num_attention_heads
          UpperCAmelCase__							: str 							=						intermediate_size
          UpperCAmelCase__							: List[str] 							=						hidden_dropout_prob
          UpperCAmelCase__							: Optional[Any] 							=						attention_probs_dropout_prob
          UpperCAmelCase__							: int 							=						max_position_embeddings
          UpperCAmelCase__							: List[str] 							=						initializer_range
          UpperCAmelCase__							: List[Any] 							=						layer_norm_eps
          UpperCAmelCase__							: int 							=						position_embedding_type
          UpperCAmelCase__							: Optional[Any] 							=						use_cache
          UpperCAmelCase__							: Optional[int] 							=						emb_layer_norm_before
          UpperCAmelCase__							: List[str] 							=						token_dropout
          UpperCAmelCase__							: Tuple 							=						is_folding_model
          if is_folding_model:
               if esmfold_config is None:
                    logger.info("No esmfold_config supplied for folding model, using default values."  )
                    UpperCAmelCase__							: List[Any] 							=						EsmFoldConfig()
               elif isinstance(UpperCamelCase__ ,			UpperCamelCase__  ):
                    UpperCAmelCase__							: Optional[int] 							=						EsmFoldConfig(**UpperCamelCase__  )
               UpperCAmelCase__							: int 							=						esmfold_config
               if vocab_list is None:
                    logger.warning("No vocab_list supplied for folding model, assuming the ESM-2 vocabulary!"  )
                    UpperCAmelCase__							: Any 							=						get_default_vocab_list()
               else:
                    UpperCAmelCase__							: Dict 							=						vocab_list
          else:
               UpperCAmelCase__							: Optional[Any] 							=						None
               UpperCAmelCase__							: Tuple 							=						None
          if self.esmfold_config is not None and getattr(self.esmfold_config ,			"use_esm_attn_map" ,			UpperCamelCase__  ):
               raise ValueError("The HuggingFace port of ESMFold does not support use_esm_attn_map at this time!"  )



     def  lowerCAmelCase__       (      self  )->					str:

          '''simple docstring'''





          UpperCAmelCase__							: Optional[int] 							=						super().to_dict()
          if isinstance(self.esmfold_config ,			UpperCamelCase__  ):
               UpperCAmelCase__							: Dict 							=						self.esmfold_config.to_dict()
          return output







@dataclass
class   _lowercase						:


     '''simple docstring'''





     _A								=							None
     _A								=							True
     _A								=							False
     _A								=							False
     _A								=							False
     _A								=							0

     _A								=							True
     _A								=							False

     _A								=							128
     _A								=							None



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

          '''simple docstring'''





          if self.trunk is None:
               UpperCAmelCase__							: Tuple 							=						TrunkConfig()
          elif isinstance(self.trunk ,			UpperCamelCase__  ):
               UpperCAmelCase__							: List[Any] 							=						TrunkConfig(**self.trunk  )



     def  lowerCAmelCase__       (      self  )->					int:

          '''simple docstring'''





          UpperCAmelCase__							: Optional[int] 							=						asdict(self  )
          UpperCAmelCase__							: int 							=						self.trunk.to_dict()
          return output







@dataclass
class   _lowercase						:


     '''simple docstring'''





     _A								=							48
     _A								=							1024
     _A								=							128
     _A								=							32
     _A								=							32
     _A								=							32
     _A								=							0
     _A								=							0
     _A								=							False
     _A								=							4
     _A								=							128
     _A								=							None



     def  lowerCAmelCase__       (      self  )->					int:

          '''simple docstring'''





          if self.structure_module is None:
               UpperCAmelCase__							: str 							=						StructureModuleConfig()
          elif isinstance(self.structure_module ,			UpperCamelCase__  ):
               UpperCAmelCase__							: str 							=						StructureModuleConfig(**self.structure_module  )

          if self.max_recycles <= 0:
               raise ValueError(F"`max_recycles` should be positive, got {self.max_recycles}."  )
          if self.sequence_state_dim % self.sequence_state_dim != 0:
               raise ValueError(
                   "`sequence_state_dim` should be a round multiple of `sequence_state_dim`, got"
                   F" {self.sequence_state_dim} and {self.sequence_state_dim}."  )
          if self.pairwise_state_dim % self.pairwise_state_dim != 0:
               raise ValueError(
                   "`pairwise_state_dim` should be a round multiple of `pairwise_state_dim`, got"
                   F" {self.pairwise_state_dim} and {self.pairwise_state_dim}."  )

          UpperCAmelCase__							: Tuple 							=						self.sequence_state_dim // self.sequence_head_width
          UpperCAmelCase__							: int 							=						self.pairwise_state_dim // self.pairwise_head_width

          if self.sequence_state_dim != sequence_num_heads * self.sequence_head_width:
               raise ValueError(
                   "`sequence_state_dim` should be equal to `sequence_num_heads * sequence_head_width, got"
                   F" {self.sequence_state_dim} != {sequence_num_heads} * {self.sequence_head_width}."  )
          if self.pairwise_state_dim != pairwise_num_heads * self.pairwise_head_width:
               raise ValueError(
                   "`pairwise_state_dim` should be equal to `pairwise_num_heads * pairwise_head_width, got"
                   F" {self.pairwise_state_dim} != {pairwise_num_heads} * {self.pairwise_head_width}."  )
          if self.pairwise_state_dim % 2 != 0:
               raise ValueError(F"`pairwise_state_dim` should be even, got {self.pairwise_state_dim}."  )

          if self.dropout >= 0.4:
               raise ValueError(F"`dropout` should not be greater than 0.4, got {self.dropout}."  )



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

          '''simple docstring'''





          UpperCAmelCase__							: List[Any] 							=						asdict(self  )
          UpperCAmelCase__							: Optional[int] 							=						self.structure_module.to_dict()
          return output







@dataclass
class   _lowercase						:


     '''simple docstring'''





     _A								=							384
     _A								=							128
     _A								=							16
     _A								=							128
     _A								=							12
     _A								=							4
     _A								=							8
     _A								=							0.1
     _A								=							8
     _A								=							1
     _A								=							2
     _A								=							7
     _A								=							10
     _A								=							1e-8
     _A								=							1e5



     def  lowerCAmelCase__       (      self  )->					List[str]:

          '''simple docstring'''





          return asdict(self  )





def 							a__ (				):






     '''simple docstring'''
     return (
         "<cls>",
         "<pad>",
         "<eos>",
         "<unk>",
         "L",
         "A",
         "G",
         "V",
         "S",
         "E",
         "R",
         "T",
         "I",
         "D",
         "P",
         "K",
         "Q",
         "N",
         "F",
         "Y",
         "M",
         "H",
         "W",
         "C",
         "X",
         "B",
         "U",
         "Z",
         "O",
         ".",
         "-",
         "<null_1>",
         "<mask>",
     )





"""simple docstring"""




from typing import Optional, Union

import torch
from torch import nn

from ...configuration_utils import ConfigMixin, register_to_config
from ...models.modeling_utils import ModelMixin







class   _lowercase						(       lowerCAmelCase_	,   lowerCAmelCase_				):


     '''simple docstring'''





     @register_to_config
     def __init__(      self ,			__UpperCamelCase = 7_68 ,			)->					Union[str, Any]:
          super().__init__()

          UpperCAmelCase__							: str 							=						nn.Parameter(torch.zeros(1 ,			__UpperCamelCase  )  )
          UpperCAmelCase__							: Optional[int] 							=						nn.Parameter(torch.ones(1 ,			__UpperCamelCase  )  )



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase = None ,			__UpperCamelCase = None ,			)->					Any:
          UpperCAmelCase__							: Dict 							=						nn.Parameter(self.mean.to(__UpperCamelCase  ).to(__UpperCamelCase  )  )
          UpperCAmelCase__							: Any 							=						nn.Parameter(self.std.to(__UpperCamelCase  ).to(__UpperCamelCase  )  )
          return self



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase  )->					Union[str, Any]:
          UpperCAmelCase__							: Dict 							=						(embeds - self.mean) * 1.0 / self.std
          return embeds



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase  )->					List[Any]:
          UpperCAmelCase__							: Any 							=						(embeds * self.std) + self.mean
          return embeds



