

from dataclasses import asdict, dataclass
from typing import Optional

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


A__						=							logging.get_logger(__name__)

# TODO Update this
A__						=							{
    """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 				__UpperCamelCase				(					SCREAMING_SNAKE_CASE			):
	_lowercase  :   Tuple       				=  "esm"







	def __init__(   self: Optional[Any]  , __UpperCamelCase: Optional[int]=None  , __UpperCamelCase: Optional[Any]=None  , __UpperCamelCase: Dict=None  , __UpperCamelCase: Any=7_68  , __UpperCamelCase: List[str]=12  , __UpperCamelCase: Dict=12  , __UpperCamelCase: List[Any]=30_72  , __UpperCamelCase: Any=0.1  , __UpperCamelCase: Tuple=0.1  , __UpperCamelCase: Any=10_26  , __UpperCamelCase: Optional[Any]=0.02  , __UpperCamelCase: Optional[int]=1E-12  , __UpperCamelCase: List[str]="absolute"  , __UpperCamelCase: int=True  , __UpperCamelCase: Optional[int]=None  , __UpperCamelCase: List[Any]=False  , __UpperCamelCase: Optional[int]=False  , __UpperCamelCase: Optional[Any]=None  , __UpperCamelCase: Dict=None  , **__UpperCamelCase: Optional[int]  , ):

						'''simple docstring'''





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

						__magic_name__							=    vocab_size
						__magic_name__							=    hidden_size
						__magic_name__							=    num_hidden_layers
						__magic_name__							=    num_attention_heads
						__magic_name__							=    intermediate_size
						__magic_name__							=    hidden_dropout_prob
						__magic_name__							=    attention_probs_dropout_prob
						__magic_name__							=    max_position_embeddings
						__magic_name__							=    initializer_range
						__magic_name__							=    layer_norm_eps
						__magic_name__							=    position_embedding_type
						__magic_name__							=    use_cache
						__magic_name__							=    emb_layer_norm_before
						__magic_name__							=    token_dropout
						__magic_name__							=    is_folding_model
						if is_folding_model:
											if esmfold_config is None:
																logger.info('No esmfold_config supplied for folding model, using default values.'      )
																__magic_name__							=    EsmFoldConfig()
											elif isinstance(__UpperCamelCase  , __UpperCamelCase      ):
																__magic_name__							=    EsmFoldConfig(**__UpperCamelCase      )
											__magic_name__							=    esmfold_config
											if vocab_list is None:
																logger.warning('No vocab_list supplied for folding model, assuming the ESM-2 vocabulary!'      )
																__magic_name__							=    get_default_vocab_list()
											else:
																__magic_name__							=    vocab_list
						else:
											__magic_name__							=    None
											__magic_name__							=    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 	_SCREAMING_SNAKE_CASE							(   self: Any      ):

						'''simple docstring'''





						__magic_name__							=    super().to_dict()
						if isinstance(self.esmfold_config  , __UpperCamelCase      ):
											__magic_name__							=    self.esmfold_config.to_dict()
						return output




@dataclass
class 				__UpperCamelCase				:
	_lowercase  :   str       				=  None
	_lowercase  :   bool       				=  True
	_lowercase  :   bool       				=  False
	_lowercase  :   bool       				=  False
	_lowercase  :   bool       				=  False
	_lowercase  :   float       				=  0

	_lowercase  :   bool       				=  True
	_lowercase  :   bool       				=  False

	_lowercase  :   int       				=  1_2_8
	_lowercase  :   "TrunkConfig"       				=  None







	def 	_SCREAMING_SNAKE_CASE							(   self: Any      ):

						'''simple docstring'''





						if self.trunk is None:
											__magic_name__							=    TrunkConfig()
						elif isinstance(self.trunk  , __UpperCamelCase      ):
											__magic_name__							=    TrunkConfig(**self.trunk      )







	def 	_SCREAMING_SNAKE_CASE							(   self: List[str]      ):

						'''simple docstring'''





						__magic_name__							=    asdict(self      )
						__magic_name__							=    self.trunk.to_dict()
						return output




@dataclass
class 				__UpperCamelCase				:
	_lowercase  :   int       				=  4_8
	_lowercase  :   int       				=  1_0_2_4
	_lowercase  :   int       				=  1_2_8
	_lowercase  :   int       				=  3_2
	_lowercase  :   int       				=  3_2
	_lowercase  :   int       				=  3_2
	_lowercase  :   float       				=  0
	_lowercase  :   float       				=  0
	_lowercase  :   bool       				=  False
	_lowercase  :   int       				=  4
	_lowercase  :   Optional[int]       				=  1_2_8
	_lowercase  :   "StructureModuleConfig"       				=  None







	def 	_SCREAMING_SNAKE_CASE							(   self: Optional[int]      ):

						'''simple docstring'''





						if self.structure_module is None:
											__magic_name__							=    StructureModuleConfig()
						elif isinstance(self.structure_module  , __UpperCamelCase      ):
											__magic_name__							=    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}.'      )

						__magic_name__							=    self.sequence_state_dim // self.sequence_head_width
						__magic_name__							=    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 	_SCREAMING_SNAKE_CASE							(   self: List[Any]      ):

						'''simple docstring'''





						__magic_name__							=    asdict(self      )
						__magic_name__							=    self.structure_module.to_dict()
						return output




@dataclass
class 				__UpperCamelCase				:
	_lowercase  :   int       				=  3_8_4
	_lowercase  :   int       				=  1_2_8
	_lowercase  :   int       				=  1_6
	_lowercase  :   int       				=  1_2_8
	_lowercase  :   int       				=  1_2
	_lowercase  :   int       				=  4
	_lowercase  :   int       				=  8
	_lowercase  :   float       				=  0.1
	_lowercase  :   int       				=  8
	_lowercase  :   int       				=  1
	_lowercase  :   int       				=  2
	_lowercase  :   int       				=  7
	_lowercase  :   int       				=  1_0
	_lowercase  :   float       				=  1E-8
	_lowercase  :   float       				=  1E5







	def 	_SCREAMING_SNAKE_CASE							(   self: Any      ):

						'''simple docstring'''





						return asdict(self      )




def 					_lowercase     (				)				->	List[str]:




					'''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>",
					)







import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device


if is_torch_available():
						from transformers import AutoModelForSeqaSeqLM, AutoTokenizer

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







	@slow
	def 	_SCREAMING_SNAKE_CASE							(   self: Tuple      ):

						'''simple docstring'''





						__magic_name__							=    AutoModelForSeqaSeqLM.from_pretrained('google/mt5-small'  , return_dict=__UpperCamelCase      ).to(__UpperCamelCase      )
						__magic_name__							=    AutoTokenizer.from_pretrained('google/mt5-small'      )

						__magic_name__							=    tokenizer('Hello there'  , return_tensors='pt'      ).input_ids
						__magic_name__							=    tokenizer('Hi I am'  , return_tensors='pt'      ).input_ids

						__magic_name__							=    model(input_ids.to(__UpperCamelCase      )  , labels=labels.to(__UpperCamelCase      )      ).loss
						__magic_name__							=    -(labels.shape[-1] * loss.item())

						__magic_name__							=    -84.9127
						self.assertTrue(abs(mtf_score - EXPECTED_SCORE      ) < 1E-4      )




