

from dataclasses import asdict, dataclass
from typing import Optional

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


UpperCAmelCase_							:					Dict		 =   logging.get_logger(__name__)

# TODO Update this
UpperCAmelCase_							:					Union[str, 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      lowerCamelCase_      (	_lowercase	):
	_lowercase		:   int     					=				'''esm'''




	def __init__(     self						:     Dict					,      __A						:     Any=None					,      __A						:     Optional[Any]=None					,      __A						:     Tuple=None					,      __A						:     Any=768					,      __A						:     Optional[Any]=12					,      __A						:     int=12					,      __A						:     Union[str, Any]=3072					,      __A						:     Optional[Any]=0.1					,      __A						:     Dict=0.1					,      __A						:     Union[str, Any]=1026					,      __A						:     Any=0.0_2					,      __A						:     Any=1e-1_2					,      __A						:     str="absolute"					,      __A						:     List[str]=True					,      __A						:     List[Any]=None					,      __A						:     List[str]=False					,      __A						:     Optional[int]=False					,      __A						:     Optional[Any]=None					,      __A						:     str=None					,      **__A						:     Tuple					,      ):
		super().__init__(pad_token_id=__A					,      mask_token_id=__A					,      **__A							)

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




	def        lowerCAmelCase_       (     self						:     Union[str, Any]							):
		__A :			List[str]		    =			super().to_dict()
		if isinstance(self.esmfold_config					,      __A							):
			__A :			str		    =			self.esmfold_config.to_dict()
		return output






@dataclass
class      lowerCamelCase_      :
	_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     					=				128
	_lowercase		:   "TrunkConfig"     					=				None




	def        lowerCAmelCase_       (     self						:     Optional[Any]							):
		if self.trunk is None:
			__A :			str		    =			TrunkConfig()
		elif isinstance(self.trunk					,      __A							):
			__A :			Union[str, Any]		    =			TrunkConfig(**self.trunk							)




	def        lowerCAmelCase_       (     self						:     Any							):
		__A :			Optional[int]		    =			asdict(self							)
		__A :			Optional[Any]		    =			self.trunk.to_dict()
		return output






@dataclass
class      lowerCamelCase_      :
	_lowercase		:   int     					=				48
	_lowercase		:   int     					=				1024
	_lowercase		:   int     					=				128
	_lowercase		:   int     					=				32
	_lowercase		:   int     					=				32
	_lowercase		:   int     					=				32
	_lowercase		:   float     					=				0
	_lowercase		:   float     					=				0
	_lowercase		:   bool     					=				False
	_lowercase		:   int     					=				4
	_lowercase		:   Optional[int]     					=				128
	_lowercase		:   "StructureModuleConfig"     					=				None




	def        lowerCAmelCase_       (     self						:     int							):
		if self.structure_module is None:
			__A :			Any		    =			StructureModuleConfig()
		elif isinstance(self.structure_module					,      __A							):
			__A :			Optional[Any]		    =			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}."""							)

		__A :			int		    =			self.sequence_state_dim // self.sequence_head_width
		__A :			Optional[Any]		    =			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						:     int							):
		__A :			Optional[Any]		    =			asdict(self							)
		__A :			Any		    =			self.structure_module.to_dict()
		return output






@dataclass
class      lowerCamelCase_      :
	_lowercase		:   int     					=				384
	_lowercase		:   int     					=				128
	_lowercase		:   int     					=				16
	_lowercase		:   int     					=				128
	_lowercase		:   int     					=				12
	_lowercase		:   int     					=				4
	_lowercase		:   int     					=				8
	_lowercase		:   float     					=				0.1
	_lowercase		:   int     					=				8
	_lowercase		:   int     					=				1
	_lowercase		:   int     					=				2
	_lowercase		:   int     					=				7
	_lowercase		:   int     					=				10
	_lowercase		:   float     					=				1e-8
	_lowercase		:   float     					=				1e5




	def        lowerCAmelCase_       (     self						:     Tuple							):
		return asdict(self							)






def 							__SCREAMING_SNAKE_CASE     (   )					->				Optional[int]:
	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 json
from typing import List, Optional, Tuple

from tokenizers import pre_tokenizers, processors

from ...tokenization_utils_base import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_roberta import RobertaTokenizer


snake_case							:       List[Any]										=	logging.get_logger(__name__)

snake_case							:       Optional[int]										=	{'''vocab_file''': '''vocab.json''', '''merges_file''': '''merges.txt''', '''tokenizer_file''': '''tokenizer.json'''}

snake_case							:       Union[str, Any]										=	{
    '''vocab_file''': {
        '''roberta-base''': '''https://huggingface.co/roberta-base/resolve/main/vocab.json''',
        '''roberta-large''': '''https://huggingface.co/roberta-large/resolve/main/vocab.json''',
        '''roberta-large-mnli''': '''https://huggingface.co/roberta-large-mnli/resolve/main/vocab.json''',
        '''distilroberta-base''': '''https://huggingface.co/distilroberta-base/resolve/main/vocab.json''',
        '''roberta-base-openai-detector''': '''https://huggingface.co/roberta-base-openai-detector/resolve/main/vocab.json''',
        '''roberta-large-openai-detector''': (
            '''https://huggingface.co/roberta-large-openai-detector/resolve/main/vocab.json'''
        ),
    },
    '''merges_file''': {
        '''roberta-base''': '''https://huggingface.co/roberta-base/resolve/main/merges.txt''',
        '''roberta-large''': '''https://huggingface.co/roberta-large/resolve/main/merges.txt''',
        '''roberta-large-mnli''': '''https://huggingface.co/roberta-large-mnli/resolve/main/merges.txt''',
        '''distilroberta-base''': '''https://huggingface.co/distilroberta-base/resolve/main/merges.txt''',
        '''roberta-base-openai-detector''': '''https://huggingface.co/roberta-base-openai-detector/resolve/main/merges.txt''',
        '''roberta-large-openai-detector''': (
            '''https://huggingface.co/roberta-large-openai-detector/resolve/main/merges.txt'''
        ),
    },
    '''tokenizer_file''': {
        '''roberta-base''': '''https://huggingface.co/roberta-base/resolve/main/tokenizer.json''',
        '''roberta-large''': '''https://huggingface.co/roberta-large/resolve/main/tokenizer.json''',
        '''roberta-large-mnli''': '''https://huggingface.co/roberta-large-mnli/resolve/main/tokenizer.json''',
        '''distilroberta-base''': '''https://huggingface.co/distilroberta-base/resolve/main/tokenizer.json''',
        '''roberta-base-openai-detector''': (
            '''https://huggingface.co/roberta-base-openai-detector/resolve/main/tokenizer.json'''
        ),
        '''roberta-large-openai-detector''': (
            '''https://huggingface.co/roberta-large-openai-detector/resolve/main/tokenizer.json'''
        ),
    },
}

snake_case							:       Optional[int]										=	{
    '''roberta-base''': 5_12,
    '''roberta-large''': 5_12,
    '''roberta-large-mnli''': 5_12,
    '''distilroberta-base''': 5_12,
    '''roberta-base-openai-detector''': 5_12,
    '''roberta-large-openai-detector''': 5_12,
}







class 						_snake_case    ( _snake_case				):
 SCREAMING_SNAKE_CASE__ =			VOCAB_FILES_NAMES
 SCREAMING_SNAKE_CASE__ =			PRETRAINED_VOCAB_FILES_MAP
 SCREAMING_SNAKE_CASE__ =			PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 SCREAMING_SNAKE_CASE__ =			['input_ids', 'attention_mask']
 SCREAMING_SNAKE_CASE__ =			RobertaTokenizer




 def __init__(						self   ,    _lowerCamelCase=None   ,    _lowerCamelCase=None   ,    _lowerCamelCase=None   ,    _lowerCamelCase="replace"   ,    _lowerCamelCase="<s>"   ,    _lowerCamelCase="</s>"   ,    _lowerCamelCase="</s>"   ,    _lowerCamelCase="<s>"   ,    _lowerCamelCase="<unk>"   ,    _lowerCamelCase="<pad>"   ,    _lowerCamelCase="<mask>"   ,    _lowerCamelCase=False   ,    _lowerCamelCase=True   ,    **_lowerCamelCase   ,    ):
       super().__init__(
           _lowerCamelCase   ,    _lowerCamelCase   ,    tokenizer_file=_lowerCamelCase   ,    errors=_lowerCamelCase   ,    bos_token=_lowerCamelCase   ,    eos_token=_lowerCamelCase   ,    sep_token=_lowerCamelCase   ,    cls_token=_lowerCamelCase   ,    unk_token=_lowerCamelCase   ,    pad_token=_lowerCamelCase   ,    mask_token=_lowerCamelCase   ,    add_prefix_space=_lowerCamelCase   ,    trim_offsets=_lowerCamelCase   ,    **_lowerCamelCase   ,    )

       a		:List[Any]									=			json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()       )
       if pre_tok_state.get('''add_prefix_space'''   ,    _lowerCamelCase       ) != add_prefix_space:
             a		:Optional[int]									=			getattr(_lowerCamelCase   ,    pre_tok_state.pop('''type'''       )       )
             a		:Union[str, Any]									=			add_prefix_space
             a		:Dict									=			pre_tok_class(**_lowerCamelCase       )

       a		:Union[str, Any]									=			add_prefix_space

       a		:List[Any]									=			'''post_processor'''
       a		:List[str]									=			getattr(self.backend_tokenizer   ,    _lowerCamelCase   ,    _lowerCamelCase       )
       if tokenizer_component_instance:
             a		:Optional[Any]									=			json.loads(tokenizer_component_instance.__getstate__()       )

             # The lists 'sep' and 'cls' must be cased in tuples for the object `post_processor_class`
             if "sep" in state:
                   a		:Optional[int]									=			tuple(state['''sep''']       )
             if "cls" in state:
                   a		:Union[str, Any]									=			tuple(state['''cls''']       )

             a		:Optional[int]									=			False

             if state.get('''add_prefix_space'''   ,    _lowerCamelCase       ) != add_prefix_space:
                   a		:int									=			add_prefix_space
                   a		:Union[str, Any]									=			True

             if state.get('''trim_offsets'''   ,    _lowerCamelCase       ) != trim_offsets:
                   a		:int									=			trim_offsets
                   a		:List[str]									=			True

             if changes_to_apply:
                   a		:Union[str, Any]									=			getattr(_lowerCamelCase   ,    state.pop('''type'''       )       )
                   a		:str									=			component_class(**_lowerCamelCase       )
                   setattr(self.backend_tokenizer   ,    _lowerCamelCase   ,    _lowerCamelCase       )




 @property
 def 			SCREAMING_SNAKE_CASE__							(						self       ):
       if self._mask_token is None:
             if self.verbose:
                   logger.error('''Using mask_token, but it is not set yet.'''       )
             return None
       return str(self._mask_token       )




 @mask_token.setter
 def 			SCREAMING_SNAKE_CASE__							(						self   ,    _lowerCamelCase       ):
       a		:Union[str, Any]									=			AddedToken(_lowerCamelCase   ,    lstrip=_lowerCamelCase   ,    rstrip=_lowerCamelCase       ) if isinstance(_lowerCamelCase   ,    _lowerCamelCase       ) else value
       a		:int									=			value




 def 			SCREAMING_SNAKE_CASE__							(						self   ,    *_lowerCamelCase   ,    **_lowerCamelCase       ):
       a		:Union[str, Any]									=			kwargs.get('''is_split_into_words'''   ,    _lowerCamelCase       )
       assert self.add_prefix_space or not is_split_into_words, (
           F'''You need to instantiate {self.__class__.__name__} with add_prefix_space=True '''
           "to use it with pretokenized inputs."
       )

       return super()._batch_encode_plus(*_lowerCamelCase   ,    **_lowerCamelCase       )




 def 			SCREAMING_SNAKE_CASE__							(						self   ,    *_lowerCamelCase   ,    **_lowerCamelCase       ):
       a		:Any									=			kwargs.get('''is_split_into_words'''   ,    _lowerCamelCase       )

       assert self.add_prefix_space or not is_split_into_words, (
           F'''You need to instantiate {self.__class__.__name__} with add_prefix_space=True '''
           "to use it with pretokenized inputs."
       )

       return super()._encode_plus(*_lowerCamelCase   ,    **_lowerCamelCase       )




 def 			SCREAMING_SNAKE_CASE__							(						self   ,    _lowerCamelCase   ,    _lowerCamelCase = None       ):
       a		:Any									=			self._tokenizer.model.save(_lowerCamelCase   ,    name=_lowerCamelCase       )
       return tuple(_lowerCamelCase       )




 def 			SCREAMING_SNAKE_CASE__							(						self   ,    _lowerCamelCase   ,    _lowerCamelCase=None       ):
       a		:Union[str, Any]									=			[self.bos_token_id] + token_ids_a + [self.eos_token_id]
       if token_ids_a is None:
             return output

       return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]




 def 			SCREAMING_SNAKE_CASE__							(						self   ,    _lowerCamelCase   ,    _lowerCamelCase = None       ):
       a		:Dict									=			[self.sep_token_id]
       a		:int									=			[self.cls_token_id]

       if token_ids_a is None:
             return len(cls + token_ids_a + sep       ) * [0]
       return len(cls + token_ids_a + sep + sep + token_ids_a + sep       ) * [0]





