import json
import os
import unittest

from transformers import DebertaTokenizer, DebertaTokenizerFast
from transformers.models.deberta.tokenization_deberta import VOCAB_FILES_NAMES
from transformers.testing_utils import slow

from ...test_tokenization_common import TokenizerTesterMixin





class       lowercase__		(     UpperCamelCase_			,							unittest.TestCase):
						UpperCamelCase_  =	DebertaTokenizer
						UpperCamelCase_  =	True
						UpperCamelCase_  =	DebertaTokenizerFast


						def  __A ( self			:       List[Any]		):





												'''simple docstring'''





												super().setUp()

												# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
												SCREAMING_SNAKE_CASE							:					Any           =							[
												    '''l''',
												    '''o''',
												    '''w''',
												    '''e''',
												    '''r''',
												    '''s''',
												    '''t''',
												    '''i''',
												    '''d''',
												    '''n''',
												    '''\u0120''',
												    '''\u0120l''',
												    '''\u0120n''',
												    '''\u0120lo''',
												    '''\u0120low''',
												    '''er''',
												    '''\u0120lowest''',
												    '''\u0120newer''',
												    '''\u0120wider''',
												    '''[UNK]''',
												]
												SCREAMING_SNAKE_CASE							:					str           =							dict(zip(UpperCamelCase__					,	range(len(UpperCamelCase__		)		)		)		)
												SCREAMING_SNAKE_CASE							:					List[str]           =							['''#version: 0.2''', '''\u0120 l''', '''\u0120l o''', '''\u0120lo w''', '''e r''', '''''']
												SCREAMING_SNAKE_CASE							:					Optional[Any]           =							{'''unk_token''': '''[UNK]'''}

												SCREAMING_SNAKE_CASE							:					Union[str, Any]           =							os.path.join(self.tmpdirname					,	VOCAB_FILES_NAMES['''vocab_file''']		)
												SCREAMING_SNAKE_CASE							:					Union[str, Any]           =							os.path.join(self.tmpdirname					,	VOCAB_FILES_NAMES['''merges_file''']		)
												with open(self.vocab_file					,	'''w'''					,	encoding='''utf-8'''		) as fp:
																		fp.write(json.dumps(UpperCamelCase__		) + '''\n'''		)
												with open(self.merges_file					,	'''w'''					,	encoding='''utf-8'''		) as fp:
																		fp.write('''\n'''.join(UpperCamelCase__		)		)


						def  __A ( self			:       Any					,	**UpperCamelCase__			:       str		):





												'''simple docstring'''





												kwargs.update(self.special_tokens_map		)
												return self.tokenizer_class.from_pretrained(self.tmpdirname					,	**UpperCamelCase__		)


						def  __A ( self			:       Tuple					,	UpperCamelCase__			:       Any		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Tuple           =							'''lower newer'''
												SCREAMING_SNAKE_CASE							:					int           =							'''lower newer'''
												return input_text, output_text


						def  __A ( self			:       Tuple		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					List[str]           =							self.get_tokenizer()
												SCREAMING_SNAKE_CASE							:					Dict           =							'''lower newer'''
												SCREAMING_SNAKE_CASE							:					str           =							['''l''', '''o''', '''w''', '''er''', '''\u0120''', '''n''', '''e''', '''w''', '''er''']
												SCREAMING_SNAKE_CASE							:					List[str]           =							tokenizer.tokenize(UpperCamelCase__		)
												self.assertListEqual(UpperCamelCase__					,	UpperCamelCase__		)

												SCREAMING_SNAKE_CASE							:					Union[str, Any]           =							tokens + [tokenizer.unk_token]
												SCREAMING_SNAKE_CASE							:					Optional[Any]           =							[0, 1, 2, 15, 10, 9, 3, 2, 15, 19]
												self.assertListEqual(tokenizer.convert_tokens_to_ids(UpperCamelCase__		)					,	UpperCamelCase__		)


						def  __A ( self			:       Union[str, Any]		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					List[Any]           =							self.get_tokenizer()
												SCREAMING_SNAKE_CASE							:					Optional[int]           =							tokenizer('''Hello'''					,	'''World'''		)
												SCREAMING_SNAKE_CASE							:					Dict           =							[0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]
												self.assertListEqual(tokd['''token_type_ids''']					,	UpperCamelCase__		)


						@slow
						def  __A ( self			:       int		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Optional[Any]           =							self.tokenizer_class.from_pretrained('''microsoft/deberta-base'''		)

												SCREAMING_SNAKE_CASE							:					List[Any]           =							tokenizer.encode('''sequence builders'''					,	add_special_tokens=UpperCamelCase__		)
												SCREAMING_SNAKE_CASE							:					int           =							tokenizer.encode('''multi-sequence build'''					,	add_special_tokens=UpperCamelCase__		)

												SCREAMING_SNAKE_CASE							:					Dict           =							tokenizer.encode(
												    '''sequence builders'''					,	add_special_tokens=UpperCamelCase__					,	add_prefix_space=UpperCamelCase__		)
												SCREAMING_SNAKE_CASE							:					Dict           =							tokenizer.encode(
												    '''sequence builders'''					,	'''multi-sequence build'''					,	add_special_tokens=UpperCamelCase__					,	add_prefix_space=UpperCamelCase__		)

												SCREAMING_SNAKE_CASE							:					str           =							tokenizer.build_inputs_with_special_tokens(UpperCamelCase__		)
												SCREAMING_SNAKE_CASE							:					Optional[int]           =							tokenizer.build_inputs_with_special_tokens(UpperCamelCase__					,	UpperCamelCase__		)

												assert encoded_sentence == encoded_text_from_decode
												assert encoded_pair == encoded_pair_from_decode



						@slow
						def  __A ( self			:       Optional[Any]		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					str           =							[self.tokenizer_class]
												if self.test_rust_tokenizer:
																		tokenizer_classes.append(self.rust_tokenizer_class		)

												for tokenizer_class in tokenizer_classes:
																		SCREAMING_SNAKE_CASE							:					List[Any]           =							tokenizer_class.from_pretrained('''microsoft/deberta-base'''		)

																		SCREAMING_SNAKE_CASE							:					Union[str, Any]           =							[
																		    '''ALBERT: A Lite BERT for Self-supervised Learning of Language Representations''',
																		    '''ALBERT incorporates two parameter reduction techniques''',
																		    '''The first one is a factorized embedding parameterization. By decomposing the large vocabulary'''
																		    ''' embedding matrix into two small matrices, we separate the size of the hidden layers from the size of'''
																		    ''' vocabulary embedding.''',
																		]

																		SCREAMING_SNAKE_CASE							:					str           =							tokenizer(UpperCamelCase__					,	padding=UpperCamelCase__		)
																		SCREAMING_SNAKE_CASE							:					Optional[Any]           =							[tokenizer.decode(UpperCamelCase__					,	skip_special_tokens=UpperCamelCase__		) for seq in encoding['''input_ids''']]

																		# fmt: off
																		SCREAMING_SNAKE_CASE							:					List[str]           =							{
																		    '''input_ids''': [
																		        [1, 2118, 1_1126, 565, 35, 83, 2_5191, 163, 1_8854, 13, 1_2156, 12, 1_6101, 2_5376, 1_3807, 9, 2_2205, 2_7893, 1635, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
																		        [1, 2118, 1_1126, 565, 2_4536, 80, 4_3797, 4878, 7373, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
																		        [1, 133, 78, 65, 16, 10, 3724, 1538, 3_3183, 1_1303, 4_3797, 1938, 4, 870, 2_4165, 2_9105, 5, 739, 3_2644, 3_3183, 1_1303, 3_6173, 88, 80, 650, 7821, 4_5940, 6, 52, 2559, 5, 1836, 9, 5, 7397, 1_3171, 31, 5, 1836, 9, 3_2644, 3_3183, 1_1303, 4, 2]
																		    ],
																		    '''token_type_ids''': [
																		        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
																		        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
																		        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
																		    ],
																		    '''attention_mask''': [
																		        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
																		        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
																		        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
																		    ]
																		}
																		# fmt: on

																		SCREAMING_SNAKE_CASE							:					str           =							[
																		    '''ALBERT: A Lite BERT for Self-supervised Learning of Language Representations''',
																		    '''ALBERT incorporates two parameter reduction techniques''',
																		    '''The first one is a factorized embedding parameterization. By decomposing the large vocabulary'''
																		    ''' embedding matrix into two small matrices, we separate the size of the hidden layers from the size of'''
																		    ''' vocabulary embedding.''',
																		]

																		self.assertDictEqual(encoding.data					,	UpperCamelCase__		)

																		for expected, decoded in zip(UpperCamelCase__					,	UpperCamelCase__		):
																								self.assertEqual(UpperCamelCase__					,	UpperCamelCase__		)






from dataclasses import asdict, dataclass
from typing import Optional

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


__UpperCamelCase	: Tuple    		=  logging.get_logger(__name__)

# TODO Update this
__UpperCamelCase	: List[str]    		=  {
    '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__		(     UpperCamelCase_):
						UpperCamelCase_  =	"""esm"""


						def __init__( self			:       Tuple					,	UpperCamelCase__			:       Optional[Any]=None					,	UpperCamelCase__			:       int=None					,	UpperCamelCase__			:       List[str]=None					,	UpperCamelCase__			:       Any=768					,	UpperCamelCase__			:       Optional[Any]=12					,	UpperCamelCase__			:       str=12					,	UpperCamelCase__			:       Optional[int]=3072					,	UpperCamelCase__			:       Optional[Any]=0.1					,	UpperCamelCase__			:       Any=0.1					,	UpperCamelCase__			:       Union[str, Any]=1026					,	UpperCamelCase__			:       Dict=0.02					,	UpperCamelCase__			:       Any=1E-12					,	UpperCamelCase__			:       Dict="absolute"					,	UpperCamelCase__			:       Optional[Any]=True					,	UpperCamelCase__			:       int=None					,	UpperCamelCase__			:       Optional[int]=False					,	UpperCamelCase__			:       Tuple=False					,	UpperCamelCase__			:       List[str]=None					,	UpperCamelCase__			:       Optional[Any]=None					,	**UpperCamelCase__			:       Any					,	):





												'''simple docstring'''





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

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





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Optional[Any]           =							super().to_dict()
												if isinstance(self.esmfold_config					,	UpperCamelCase__		):
																		SCREAMING_SNAKE_CASE							:					Optional[Any]           =							self.esmfold_config.to_dict()
												return output






@dataclass
class       lowercase__		:
						UpperCamelCase_  =	None
						UpperCamelCase_  =	True
						UpperCamelCase_  =	False
						UpperCamelCase_  =	False
						UpperCamelCase_  =	False
						UpperCamelCase_  =	0

						UpperCamelCase_  =	True
						UpperCamelCase_  =	False

						UpperCamelCase_  =	128
						UpperCamelCase_  =	None


						def  __A ( self			:       Optional[int]		):





												'''simple docstring'''





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



						def  __A ( self			:       str		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					str           =							asdict(self		)
												SCREAMING_SNAKE_CASE							:					Tuple           =							self.trunk.to_dict()
												return output






@dataclass
class       lowercase__		:
						UpperCamelCase_  =	48
						UpperCamelCase_  =	1_024
						UpperCamelCase_  =	128
						UpperCamelCase_  =	32
						UpperCamelCase_  =	32
						UpperCamelCase_  =	32
						UpperCamelCase_  =	0
						UpperCamelCase_  =	0
						UpperCamelCase_  =	False
						UpperCamelCase_  =	4
						UpperCamelCase_  =	128
						UpperCamelCase_  =	None


						def  __A ( self			:       Any		):





												'''simple docstring'''





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

												SCREAMING_SNAKE_CASE							:					Dict           =							self.sequence_state_dim // self.sequence_head_width
												SCREAMING_SNAKE_CASE							:					Tuple           =							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  __A ( self			:       Union[str, Any]		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Any           =							asdict(self		)
												SCREAMING_SNAKE_CASE							:					Union[str, Any]           =							self.structure_module.to_dict()
												return output






@dataclass
class       lowercase__		:
						UpperCamelCase_  =	384
						UpperCamelCase_  =	128
						UpperCamelCase_  =	16
						UpperCamelCase_  =	128
						UpperCamelCase_  =	12
						UpperCamelCase_  =	4
						UpperCamelCase_  =	8
						UpperCamelCase_  =	0.1
						UpperCamelCase_  =	8
						UpperCamelCase_  =	1
						UpperCamelCase_  =	2
						UpperCamelCase_  =	7
						UpperCamelCase_  =	10
						UpperCamelCase_  =	1E-8
						UpperCamelCase_  =	1E5


						def  __A ( self			:       Dict		):





												'''simple docstring'''





												return asdict(self		)






def    A			(					):
						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>",
						)





