



import unittest

from transformers import EsmConfig, is_torch_available
from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch

 from transformers.models.esm.modeling_esmfold import EsmForProteinFolding




class 					snake_case__						:






     """simple docstring"""


     def __init__(       self  :  Dict, _snake_case  :  int, _snake_case  :  Tuple=1_3, _snake_case  :  List[Any]=7, _snake_case  :  List[str]=False, _snake_case  :  Optional[int]=True, _snake_case  :  Dict=False, _snake_case  :  Optional[int]=False, _snake_case  :  str=1_9, _snake_case  :  Optional[int]=3_2, _snake_case  :  Tuple=5, _snake_case  :  int=4, _snake_case  :  Optional[int]=3_7, _snake_case  :  List[str]="gelu", _snake_case  :  str=0.1, _snake_case  :  Union[str, Any]=0.1, _snake_case  :  List[Any]=5_1_2, _snake_case  :  Optional[int]=1_6, _snake_case  :  Tuple=2, _snake_case  :  Dict=0.0_2, _snake_case  :  Tuple=3, _snake_case  :  Optional[int]=4, _snake_case  :  List[str]=None, )   ->Any:
            snake_case__							:	Dict   	=	parent
            snake_case__							:	List[str]   	=	batch_size
            snake_case__							:	str   	=	seq_length
            snake_case__							:	Tuple   	=	is_training
            snake_case__							:	Tuple   	=	use_input_mask
            snake_case__							:	int   	=	use_token_type_ids
            snake_case__							:	str   	=	use_labels
            snake_case__							:	Optional[int]   	=	vocab_size
            snake_case__							:	Union[str, Any]   	=	hidden_size
            snake_case__							:	Optional[int]   	=	num_hidden_layers
            snake_case__							:	int   	=	num_attention_heads
            snake_case__							:	Optional[int]   	=	intermediate_size
            snake_case__							:	Any   	=	hidden_act
            snake_case__							:	Dict   	=	hidden_dropout_prob
            snake_case__							:	Any   	=	attention_probs_dropout_prob
            snake_case__							:	Optional[Any]   	=	max_position_embeddings
            snake_case__							:	List[Any]   	=	type_vocab_size
            snake_case__							:	Dict   	=	type_sequence_label_size
            snake_case__							:	int   	=	initializer_range
            snake_case__							:	int   	=	num_labels
            snake_case__							:	Any   	=	num_choices
            snake_case__							:	Any   	=	scope






     def    lowercase_   (       self  :  Dict					)   ->int:
            snake_case__							:	Tuple   	=	ids_tensor([self.batch_size, self.seq_length], self.vocab_size					)

            snake_case__							:	List[str]   	=	None
            if self.use_input_mask:
                   snake_case__							:	Tuple   	=	random_attention_mask([self.batch_size, self.seq_length]					)

            snake_case__							:	str   	=	None
            snake_case__							:	int   	=	None
            snake_case__							:	Union[str, Any]   	=	None
            if self.use_labels:
                   snake_case__							:	Tuple   	=	ids_tensor([self.batch_size], self.type_sequence_label_size					)
                   snake_case__							:	str   	=	ids_tensor([self.batch_size, self.seq_length], self.num_labels					)
                   snake_case__							:	Optional[Any]   	=	ids_tensor([self.batch_size], self.num_choices					)

            snake_case__							:	Tuple   	=	self.get_config()

            return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels






     def    lowercase_   (       self  :  List[str]					)   ->Optional[int]:
            snake_case__							:	List[Any]   	=	EsmConfig(
                vocab_size=3_3, hidden_size=self.hidden_size, pad_token_id=1, num_hidden_layers=self.num_hidden_layers, num_attention_heads=self.num_attention_heads, intermediate_size=self.intermediate_size, hidden_act=self.hidden_act, hidden_dropout_prob=self.hidden_dropout_prob, attention_probs_dropout_prob=self.attention_probs_dropout_prob, max_position_embeddings=self.max_position_embeddings, type_vocab_size=self.type_vocab_size, initializer_range=self.initializer_range, is_folding_model=UpperCamelCase__, esmfold_config={'trunk': {'num_blocks': 2}, 'fp16_esm': False}, )
            return config






     def    lowercase_   (       self  :  Tuple, _snake_case  :  int, _snake_case  :  Dict, _snake_case  :  Tuple, _snake_case  :  List[Any], _snake_case  :  List[str], _snake_case  :  List[str]					)   ->Union[str, Any]:
            snake_case__							:	Any   	=	EsmForProteinFolding(config=UpperCamelCase__					).float()
            model.to(UpperCamelCase__					)
            model.eval()
            snake_case__							:	List[Any]   	=	model(UpperCamelCase__, attention_mask=UpperCamelCase__					)
            snake_case__							:	List[str]   	=	model(UpperCamelCase__					)
            snake_case__							:	Optional[Any]   	=	model(UpperCamelCase__					)

            self.parent.assertEqual(result.positions.shape, (8, self.batch_size, self.seq_length, 1_4, 3)					)
            self.parent.assertEqual(result.angles.shape, (8, self.batch_size, self.seq_length, 7, 2)					)






     def    lowercase_   (       self  :  Any					)   ->Optional[int]:
            snake_case__							:	Any   	=	self.prepare_config_and_inputs()
            (
                snake_case__
            )							:	Union[str, Any]   	=	config_and_inputs
            snake_case__							:	str   	=	{"input_ids": input_ids, "attention_mask": input_mask}
            return config, inputs_dict




@require_torch
class 					snake_case__						(       snake_case_				,     snake_case_				,     unittest.TestCase     ):






     """simple docstring"""


     _SCREAMING_SNAKE_CASE						=	False

     _SCREAMING_SNAKE_CASE						=	(EsmForProteinFolding,) if is_torch_available() else ()
     _SCREAMING_SNAKE_CASE						=	()
     _SCREAMING_SNAKE_CASE						=	{} if is_torch_available() else {}
     _SCREAMING_SNAKE_CASE						=	False






     def    lowercase_   (       self  :  Any					)   ->Optional[int]:
            snake_case__							:	Dict   	=	EsmFoldModelTester(self					)
            snake_case__							:	str   	=	ConfigTester(self, config_class=UpperCamelCase__, hidden_size=3_7					)






     def    lowercase_   (       self  :  List[str]					)   ->int:
            self.config_tester.run_common_tests()






     def    lowercase_   (       self  :  List[Any]					)   ->Optional[Any]:
            snake_case__							:	Any   	=	self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_model(*UpperCamelCase__					)






     @unittest.skip('Does not support attention outputs'					)
     def    lowercase_   (       self  :  Union[str, Any]					)   ->Tuple:
            pass






     @unittest.skip
     def    lowercase_   (       self  :  int					)   ->Dict:
            pass






     @unittest.skip('Esm does not support embedding resizing'					)
     def    lowercase_   (       self  :  Any					)   ->str:
            pass






     @unittest.skip('Esm does not support embedding resizing'					)
     def    lowercase_   (       self  :  Union[str, Any]					)   ->int:
            pass






     @unittest.skip('ESMFold does not support passing input embeds!'					)
     def    lowercase_   (       self  :  Optional[int]					)   ->List[str]:
            pass






     @unittest.skip('ESMFold does not support head pruning.'					)
     def    lowercase_   (       self  :  List[Any]					)   ->List[str]:
            pass






     @unittest.skip('ESMFold does not support head pruning.'					)
     def    lowercase_   (       self  :  Any					)   ->Optional[int]:
            pass






     @unittest.skip('ESMFold does not support head pruning.'					)
     def    lowercase_   (       self  :  List[Any]					)   ->Tuple:
            pass






     @unittest.skip('ESMFold does not support head pruning.'					)
     def    lowercase_   (       self  :  str					)   ->List[str]:
            pass






     @unittest.skip('ESMFold does not support head pruning.'					)
     def    lowercase_   (       self  :  Tuple					)   ->int:
            pass






     @unittest.skip('ESMFold does not output hidden states in the normal way.'					)
     def    lowercase_   (       self  :  List[str]					)   ->int:
            pass






     @unittest.skip('ESMfold does not output hidden states in the normal way.'					)
     def    lowercase_   (       self  :  List[Any]					)   ->List[Any]:
            pass






     @unittest.skip('ESMFold only has one output format.'					)
     def    lowercase_   (       self  :  int					)   ->str:
            pass






     @unittest.skip('This test doesn\'t work for ESMFold and doesn\'t test core functionality'					)
     def    lowercase_   (       self  :  List[Any]					)   ->Optional[Any]:
            pass






     @unittest.skip('ESMFold does not support input chunking.'					)
     def    lowercase_   (       self  :  List[Any]					)   ->Union[str, Any]:
            pass






     @unittest.skip('ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.'					)
     def    lowercase_   (       self  :  Tuple					)   ->str:
            pass






     @unittest.skip('ESMFold doesn\'t support torchscript compilation.'					)
     def    lowercase_   (       self  :  Any					)   ->Any:
            pass






     @unittest.skip('ESMFold doesn\'t support torchscript compilation.'					)
     def    lowercase_   (       self  :  List[Any]					)   ->Optional[Any]:
            pass






     @unittest.skip('ESMFold doesn\'t support torchscript compilation.'					)
     def    lowercase_   (       self  :  List[Any]					)   ->Any:
            pass






     @unittest.skip('ESMFold doesn\'t support data parallel.'					)
     def    lowercase_   (       self  :  Tuple					)   ->Any:
            pass






     @unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'					)
     def    lowercase_   (       self  :  str					)   ->List[str]:
            pass




@require_torch
class 					snake_case__						(       snake_case_     ):






     """simple docstring"""


     @slow
     def    lowercase_   (       self  :  Any					)   ->Optional[Any]:
            snake_case__							:	Dict   	=	EsmForProteinFolding.from_pretrained('facebook/esmfold_v1'					).float()
            model.eval()
            snake_case__							:	Any   	=	torch.tensor([[0, 6, 4, 1_3, 5, 4, 1_6, 1_2, 1_1, 7, 2]]					)
            snake_case__							:	Union[str, Any]   	=	model(UpperCamelCase__					)["positions"]
            snake_case__							:	Optional[int]   	=	torch.tensor([2.5_8_2_8, 0.7_9_9_3, -1_0.9_3_3_4], dtype=torch.floataa					)
            self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0], UpperCamelCase__, atol=1e-4					)					)










"""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 _lowerCAmelCase				(      snake_case_    ,							unittest.TestCase	):
   __UpperCAmelCase :       str							  =  DebertaTokenizer
   __UpperCAmelCase :       Optional[int]							  =  True
   __UpperCAmelCase :       int							  =  DebertaTokenizerFast







   def  lowerCamelCase		(	self						)	->		int:

       '''simple docstring'''




       super().setUp()

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

       snake_case    :      Union[str, Any]      					=    os.path.join(self.tmpdirname						,	VOCAB_FILES_NAMES["vocab_file"]						)
       snake_case    :      Dict      					=    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  lowerCamelCase		(	self						,	**UpperCamelCase__						)	->		Any:

       '''simple docstring'''




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







   def  lowerCamelCase		(	self						,	UpperCamelCase__						)	->		List[str]:

       '''simple docstring'''




       snake_case    :      Tuple      					=    "lower newer"
       snake_case    :      Any      					=    "lower newer"
       return input_text, output_text







   def  lowerCamelCase		(	self						)	->		int:

       '''simple docstring'''




       snake_case    :      Optional[int]      					=    self.get_tokenizer()
       snake_case    :      str      					=    "lower newer"
       snake_case    :      Dict      					=    ["l", "o", "w", "er", "\u0120", "n", "e", "w", "er"]
       snake_case    :      Optional[Any]      					=    tokenizer.tokenize(UpperCamelCase__						)
       self.assertListEqual(UpperCamelCase__						,	UpperCamelCase__						)

       snake_case    :      List[Any]      					=    tokens + [tokenizer.unk_token]
       snake_case    :      Dict      					=    [0, 1, 2, 15, 10, 9, 3, 2, 15, 19]
       self.assertListEqual(tokenizer.convert_tokens_to_ids(UpperCamelCase__						)						,	UpperCamelCase__						)







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

       '''simple docstring'''




       snake_case    :      Tuple      					=    self.get_tokenizer()
       snake_case    :      Dict      					=    tokenizer("Hello"						,	"World"						)
       snake_case    :      str      					=    [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]
       self.assertListEqual(tokd["token_type_ids"]						,	UpperCamelCase__						)







   @slow
   def  lowerCamelCase		(	self						)	->		str:

       '''simple docstring'''




       snake_case    :      List[Any]      					=    self.tokenizer_class.from_pretrained("microsoft/deberta-base"						)

       snake_case    :      Dict      					=    tokenizer.encode("sequence builders"						,	add_special_tokens=UpperCamelCase__						)
       snake_case    :      Tuple      					=    tokenizer.encode("multi-sequence build"						,	add_special_tokens=UpperCamelCase__						)

       snake_case    :      List[str]      					=    tokenizer.encode(
           "sequence builders"						,	add_special_tokens=UpperCamelCase__						,	add_prefix_space=UpperCamelCase__						)
       snake_case    :      Optional[int]      					=    tokenizer.encode(
           "sequence builders"						,	"multi-sequence build"						,	add_special_tokens=UpperCamelCase__						,	add_prefix_space=UpperCamelCase__						)

       snake_case    :      int      					=    tokenizer.build_inputs_with_special_tokens(UpperCamelCase__						)
       snake_case    :      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  lowerCamelCase		(	self						)	->		List[Any]:

       '''simple docstring'''




       snake_case    :      Union[str, Any]      					=    [self.tokenizer_class]
       if self.test_rust_tokenizer:
           tokenizer_classes.append(self.rust_tokenizer_class						)

       for tokenizer_class in tokenizer_classes:
           snake_case    :      str      					=    tokenizer_class.from_pretrained("microsoft/deberta-base"						)

           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.",
           ]

           snake_case    :      Optional[int]      					=    tokenizer(UpperCamelCase__						,	padding=UpperCamelCase__						)
           snake_case    :      Optional[int]      					=    [tokenizer.decode(UpperCamelCase__						,	skip_special_tokens=UpperCamelCase__						) for seq in encoding["input_ids"]]

           # fmt: off
           snake_case    :      Dict      					=    {
               "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

           snake_case    :      int      					=    [
               "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__						)





