
'''simple docstring'''




from dataclasses import asdict, dataclass
from typing import Optional

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


lowercase     :							Dict       						=     logging.get_logger(__name__)

# TODO Update this
lowercase     :							Tuple       						=     {
    '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							(				__snake_case		):
     __magic_name__          =						'''esm'''





     def __init__(				self		,     SCREAMING_SNAKE_CASE=None		,     SCREAMING_SNAKE_CASE=None		,     SCREAMING_SNAKE_CASE=None		,     SCREAMING_SNAKE_CASE=768		,     SCREAMING_SNAKE_CASE=12		,     SCREAMING_SNAKE_CASE=12		,     SCREAMING_SNAKE_CASE=3072		,     SCREAMING_SNAKE_CASE=0.1		,     SCREAMING_SNAKE_CASE=0.1		,     SCREAMING_SNAKE_CASE=1026		,     SCREAMING_SNAKE_CASE=0.02		,     SCREAMING_SNAKE_CASE=1e-12		,     SCREAMING_SNAKE_CASE="absolute"		,     SCREAMING_SNAKE_CASE=True		,     SCREAMING_SNAKE_CASE=None		,     SCREAMING_SNAKE_CASE=False		,     SCREAMING_SNAKE_CASE=False		,     SCREAMING_SNAKE_CASE=None		,     SCREAMING_SNAKE_CASE=None		,     **SCREAMING_SNAKE_CASE		,     )					->							Union[str, Any]:






         """simple docstring"""






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

         A			:  Optional[Any]   =		vocab_size
         A			:  int   =		hidden_size
         A			:  Optional[Any]   =		num_hidden_layers
         A			:  Optional[Any]   =		num_attention_heads
         A			:  Dict   =		intermediate_size
         A			:  int   =		hidden_dropout_prob
         A			:  List[str]   =		attention_probs_dropout_prob
         A			:  Dict   =		max_position_embeddings
         A			:  List[str]   =		initializer_range
         A			:  List[str]   =		layer_norm_eps
         A			:  List[str]   =		position_embedding_type
         A			:  Optional[Any]   =		use_cache
         A			:  Dict   =		emb_layer_norm_before
         A			:  List[Any]   =		token_dropout
         A			:  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.'''      )
                 A			:  List[Any]   =		EsmFoldConfig()
             elif isinstance(SCREAMING_SNAKE_CASE		,     SCREAMING_SNAKE_CASE      ):
                 A			:  Optional[Any]   =		EsmFoldConfig(**SCREAMING_SNAKE_CASE      )
             A			:  int   =		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			:  Optional[int]   =		vocab_list
         else:
             A			:  Dict   =		None
             A			:  Tuple   =		None
         if self.esmfold_config is not None and getattr(self.esmfold_config		,     '''use_esm_attn_map'''		,     SCREAMING_SNAKE_CASE      ):
             raise ValueError('''The HuggingFace port of ESMFold does not support use_esm_attn_map at this time!'''      )





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






         """simple docstring"""






         A			:  int   =		super().to_dict()
         if isinstance(self.esmfold_config		,     SCREAMING_SNAKE_CASE      ):
             A			:  List[str]   =		self.esmfold_config.to_dict()
         return output





@dataclass
class 					A							:
     __magic_name__          =						None
     __magic_name__          =						True
     __magic_name__          =						False
     __magic_name__          =						False
     __magic_name__          =						False
     __magic_name__          =						0

     __magic_name__          =						True
     __magic_name__          =						False

     __magic_name__          =						128
     __magic_name__          =						None





     def 							__lowerCAmelCase				(				self      )					->							Dict:






         """simple docstring"""






         if self.trunk is None:
             A			:  Tuple   =		TrunkConfig()
         elif isinstance(self.trunk		,     SCREAMING_SNAKE_CASE      ):
             A			:  int   =		TrunkConfig(**self.trunk      )





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






         """simple docstring"""






         A			:  List[Any]   =		asdict(self      )
         A			:  List[Any]   =		self.trunk.to_dict()
         return output





@dataclass
class 					A							:
     __magic_name__          =						48
     __magic_name__          =						1024
     __magic_name__          =						128
     __magic_name__          =						32
     __magic_name__          =						32
     __magic_name__          =						32
     __magic_name__          =						0
     __magic_name__          =						0
     __magic_name__          =						False
     __magic_name__          =						4
     __magic_name__          =						128
     __magic_name__          =						None





     def 							__lowerCAmelCase				(				self      )					->							str:






         """simple docstring"""






         if self.structure_module is None:
             A			:  Dict   =		StructureModuleConfig()
         elif isinstance(self.structure_module		,     SCREAMING_SNAKE_CASE      ):
             A			:  Optional[int]   =		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			:  Dict   =		self.sequence_state_dim // self.sequence_head_width
         A			:  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 							__lowerCAmelCase				(				self      )					->							List[Any]:






         """simple docstring"""






         A			:  List[Any]   =		asdict(self      )
         A			:  Dict   =		self.structure_module.to_dict()
         return output





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





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






         """simple docstring"""






         return asdict(self      )







def 						lowerCAmelCase_							(  ):




    '''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 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 					A							(				__snake_case       ,     unittest.TestCase		):
     __magic_name__          =						DebertaTokenizer
     __magic_name__          =						True
     __magic_name__          =						DebertaTokenizerFast





     def 							__lowerCAmelCase				(				self      )					->							Tuple:






         """simple docstring"""






         super().setUp()

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

         A			:  Optional[int]   =		os.path.join(self.tmpdirname		,     VOCAB_FILES_NAMES['''vocab_file''']      )
         A			:  str   =		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(SCREAMING_SNAKE_CASE      ) + '''\n'''      )
         with open(self.merges_file		,     '''w'''		,     encoding='''utf-8'''      ) as fp:
             fp.write('''\n'''.join(SCREAMING_SNAKE_CASE      )      )





     def 							__lowerCAmelCase				(				self		,     **SCREAMING_SNAKE_CASE      )					->							Optional[Any]:






         """simple docstring"""






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





     def 							__lowerCAmelCase				(				self		,     SCREAMING_SNAKE_CASE      )					->							str:






         """simple docstring"""






         A			:  Union[str, Any]   =		'''lower newer'''
         A			:  List[Any]   =		'''lower newer'''
         return input_text, output_text





     def 							__lowerCAmelCase				(				self      )					->							str:






         """simple docstring"""






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

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





     def 							__lowerCAmelCase				(				self      )					->							str:






         """simple docstring"""






         A			:  List[Any]   =		self.get_tokenizer()
         A			:  Tuple   =		tokenizer('''Hello'''		,     '''World'''      )
         A			:  str   =		[0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]
         self.assertListEqual(tokd['''token_type_ids''']		,     SCREAMING_SNAKE_CASE      )





     @slow
     def 							__lowerCAmelCase				(				self      )					->							int:






         """simple docstring"""






         A			:  Union[str, Any]   =		self.tokenizer_class.from_pretrained('''microsoft/deberta-base'''      )

         A			:  Union[str, Any]   =		tokenizer.encode('''sequence builders'''		,     add_special_tokens=SCREAMING_SNAKE_CASE      )
         A			:  Any   =		tokenizer.encode('''multi-sequence build'''		,     add_special_tokens=SCREAMING_SNAKE_CASE      )

         A			:  Tuple   =		tokenizer.encode(
             '''sequence builders'''		,     add_special_tokens=SCREAMING_SNAKE_CASE		,     add_prefix_space=SCREAMING_SNAKE_CASE      )
         A			:  Union[str, Any]   =		tokenizer.encode(
             '''sequence builders'''		,     '''multi-sequence build'''		,     add_special_tokens=SCREAMING_SNAKE_CASE		,     add_prefix_space=SCREAMING_SNAKE_CASE      )

         A			:  List[str]   =		tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE      )
         A			:  Union[str, Any]   =		tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE		,     SCREAMING_SNAKE_CASE      )

         assert encoded_sentence == encoded_text_from_decode
         assert encoded_pair == encoded_pair_from_decode





     @slow
     def 							__lowerCAmelCase				(				self      )					->							int:






         """simple docstring"""






         A			:  Any   =		[self.tokenizer_class]
         if self.test_rust_tokenizer:
             tokenizer_classes.append(self.rust_tokenizer_class      )

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

             A			:  Dict   =		[
                 '''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.''',
             ]

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

             # fmt: off
             A			:  List[str]   =		{
                 '''input_ids''': [
                     [1, 2118, 11126, 565, 35, 83, 25191, 163, 18854, 13, 12156, 12, 16101, 25376, 13807, 9, 22205, 27893, 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, 11126, 565, 24536, 80, 43797, 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, 33183, 11303, 43797, 1938, 4, 870, 24165, 29105, 5, 739, 32644, 33183, 11303, 36173, 88, 80, 650, 7821, 45940, 6, 52, 2559, 5, 1836, 9, 5, 7397, 13171, 31, 5, 1836, 9, 32644, 33183, 11303, 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

             A			:  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.''',
             ]

             self.assertDictEqual(encoding.data		,     SCREAMING_SNAKE_CASE      )

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




