


"""simple docstring"""






from dataclasses import asdict, dataclass
from typing import Optional

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


_lowerCAmelCase							:    Union[str, Any]					   =	logging.get_logger(__name__)

# TODO Update this
_lowerCAmelCase							:    Optional[Any]					   =	{
    '''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 							A_      (       _a ):
  lowerCAmelCase__      			=	'esm'


  def __init__(			self:						str							,__lowerCAmelCase:						Tuple=None							,__lowerCAmelCase:						Tuple=None							,__lowerCAmelCase:						str=None							,__lowerCAmelCase:						Optional[int]=768							,__lowerCAmelCase:						Any=12							,__lowerCAmelCase:						str=12							,__lowerCAmelCase:						List[Any]=3_072							,__lowerCAmelCase:						int=0.1							,__lowerCAmelCase:						int=0.1							,__lowerCAmelCase:						List[Any]=1_026							,__lowerCAmelCase:						Optional[Any]=0.02							,__lowerCAmelCase:						Dict=1e-12							,__lowerCAmelCase:						Dict="absolute"							,__lowerCAmelCase:						List[Any]=True							,__lowerCAmelCase:						Optional[Any]=None							,__lowerCAmelCase:						Union[str, Any]=False							,__lowerCAmelCase:						str=False							,__lowerCAmelCase:						List[Any]=None							,__lowerCAmelCase:						Union[str, Any]=None							,**__lowerCAmelCase:						int							,):







     '''simple docstring'''







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

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






  def 							_lowercase					(			self:						Any    ):







     '''simple docstring'''







     _lowerCamelCase   :				List[Any]							=     super().to_dict()
     if isinstance(self.esmfold_config							,__lowerCAmelCase    ):
        _lowerCamelCase   :				Optional[int]							=     self.esmfold_config.to_dict()
     return output




@dataclass
class 							A_      :
  lowerCAmelCase__      			=	None
  lowerCAmelCase__      			=	True
  lowerCAmelCase__      			=	False
  lowerCAmelCase__      			=	False
  lowerCAmelCase__      			=	False
  lowerCAmelCase__      			=	0

  lowerCAmelCase__      			=	True
  lowerCAmelCase__      			=	False

  lowerCAmelCase__      			=	1_2_8
  lowerCAmelCase__      			=	None


  def 							_lowercase					(			self:						Dict    ):







     '''simple docstring'''







     if self.trunk is None:
        _lowerCamelCase   :				Optional[int]							=     TrunkConfig()
     elif isinstance(self.trunk							,__lowerCAmelCase    ):
        _lowerCamelCase   :				Union[str, Any]							=     TrunkConfig(**self.trunk    )






  def 							_lowercase					(			self:						Optional[Any]    ):







     '''simple docstring'''







     _lowerCamelCase   :				Dict							=     asdict(self    )
     _lowerCamelCase   :				str							=     self.trunk.to_dict()
     return output




@dataclass
class 							A_      :
  lowerCAmelCase__      			=	4_8
  lowerCAmelCase__      			=	1_0_2_4
  lowerCAmelCase__      			=	1_2_8
  lowerCAmelCase__      			=	3_2
  lowerCAmelCase__      			=	3_2
  lowerCAmelCase__      			=	3_2
  lowerCAmelCase__      			=	0
  lowerCAmelCase__      			=	0
  lowerCAmelCase__      			=	False
  lowerCAmelCase__      			=	4
  lowerCAmelCase__      			=	1_2_8
  lowerCAmelCase__      			=	None


  def 							_lowercase					(			self:						Any    ):







     '''simple docstring'''







     if self.structure_module is None:
        _lowerCamelCase   :				Tuple							=     StructureModuleConfig()
     elif isinstance(self.structure_module							,__lowerCAmelCase    ):
        _lowerCamelCase   :				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}."""    )

     _lowerCamelCase   :				Optional[Any]							=     self.sequence_state_dim // self.sequence_head_width
     _lowerCamelCase   :				Optional[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 							_lowercase					(			self:						List[str]    ):







     '''simple docstring'''







     _lowerCamelCase   :				Dict							=     asdict(self    )
     _lowerCamelCase   :				Optional[int]							=     self.structure_module.to_dict()
     return output




@dataclass
class 							A_      :
  lowerCAmelCase__      			=	3_8_4
  lowerCAmelCase__      			=	1_2_8
  lowerCAmelCase__      			=	1_6
  lowerCAmelCase__      			=	1_2_8
  lowerCAmelCase__      			=	1_2
  lowerCAmelCase__      			=	4
  lowerCAmelCase__      			=	8
  lowerCAmelCase__      			=	0.1
  lowerCAmelCase__      			=	8
  lowerCAmelCase__      			=	1
  lowerCAmelCase__      			=	2
  lowerCAmelCase__      			=	7
  lowerCAmelCase__      			=	1_0
  lowerCAmelCase__      			=	1E-8
  lowerCAmelCase__      			=	1E5


  def 							_lowercase					(			self:						Any    ):







     '''simple docstring'''







     return asdict(self    )







def        lowerCamelCase_(		)    ->     int:
   '''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"""







import os
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


a_							=    logging.get_logger(__name__)


a_							=    """▁"""

a_							=    {"""vocab_file""": """spiece.model"""}

a_							=    {
    """vocab_file""": {
        """google/reformer-crime-and-punishment""": (
            """https://huggingface.co/google/reformer-crime-and-punishment/resolve/main/spiece.model"""
        )
    }
}

a_							=    {
    """google/reformer-crime-and-punishment""": 52_42_88,
}







class 					A_(SCREAMING_SNAKE_CASE_      ):







			"""simple docstring"""



			a_       :			Optional[int]												=			VOCAB_FILES_NAMES
			a_       :			int												=			PRETRAINED_VOCAB_FILES_MAP
			a_       :			str												=			PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
			a_       :			Optional[Any]												=			["""input_ids""", """attention_mask"""]
			def __init__(	self				,   A				,   A="</s>"				,   A="<unk>"				,   A=[]				,   A = None				,   **A				,   ):
						_lowerCamelCase					:					Any	       =    {} if sp_model_kwargs is None else sp_model_kwargs

						super().__init__(
						    eos_token=A				,   unk_token=A				,   additional_special_tokens=A				,   sp_model_kwargs=self.sp_model_kwargs				,   **A				,   )

						_lowerCamelCase					:					Dict	       =    vocab_file
						_lowerCamelCase					:					List[Any]	       =    spm.SentencePieceProcessor(**self.sp_model_kwargs							)
						self.sp_model.Load(A							)
			@property
			def    _lowerCAmelCase		(	self							):
						return self.sp_model.get_piece_size()
			def    _lowerCAmelCase		(	self							):
						_lowerCamelCase					:					int	       =    {self.convert_ids_to_tokens(A							): i for i in range(self.vocab_size							)}
						vocab.update(self.added_tokens_encoder							)
						return vocab
			def __getstate__(	self							):
						_lowerCamelCase					:					Optional[int]	       =    self.__dict__.copy()
						_lowerCamelCase					:					Union[str, Any]	       =    None
						return state
			def __setstate__(	self				,   A							):
						_lowerCamelCase					:					int	       =    d

						# for backward compatibility
						if not hasattr(self				,   'sp_model_kwargs'							):
									_lowerCamelCase					:					Union[str, Any]	       =    {}

						_lowerCamelCase					:					Dict	       =    spm.SentencePieceProcessor(**self.sp_model_kwargs							)
						self.sp_model.Load(self.vocab_file							)
			def    _lowerCAmelCase		(	self				,   A							):
						return self.sp_model.encode(A				,   out_type=A							)
			def    _lowerCAmelCase		(	self				,   A							):
						return self.sp_model.piece_to_id(A							)
			def    _lowerCAmelCase		(	self				,   A							):
						if index < self.sp_model.get_piece_size():
									_lowerCamelCase					:					Dict	       =    self.sp_model.IdToPiece(A							)
						return token
			def    _lowerCAmelCase		(	self				,   A							):
						_lowerCamelCase					:					Tuple	       =    []
						_lowerCamelCase					:					Optional[int]	       =    ''
						for token in tokens:
									# make sure that special tokens are not decoded using sentencepiece model
									if token in self.all_special_tokens:
												out_string += self.sp_model.decode(A							) + token
												_lowerCamelCase					:					Dict	       =    []
									else:
												current_sub_tokens.append(A							)
						out_string += self.sp_model.decode(A							)
						return out_string.strip()

			def    _lowerCAmelCase		(	self				,   A				,   A = None							):
						if not os.path.isdir(A							):
									logger.error(F"Vocabulary path ({save_directory}) should be a directory"							)
									return
						_lowerCamelCase					:					Any	       =    os.path.join(
						    A				,   (filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']							)

						if os.path.abspath(self.vocab_file							) != os.path.abspath(A							) and os.path.isfile(self.vocab_file							):
									copyfile(self.vocab_file				,   A							)
						elif not os.path.isfile(self.vocab_file							):
									with open(A				,   'wb'							) as fi:
												_lowerCamelCase					:					List[str]	       =    self.sp_model.serialized_model_proto()
												fi.write(A							)

						return (out_vocab_file,)





