


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_   :
					def __init__(      self   :Any			,__snake_case   :Optional[int]			,__snake_case   :Any=13			,__snake_case   :List[Any]=7			,__snake_case   :Dict=False			,__snake_case   :Any=True			,__snake_case   :int=False			,__snake_case   :int=False			,__snake_case   :Dict=19			,__snake_case   :Optional[int]=32			,__snake_case   :Union[str, Any]=5			,__snake_case   :Optional[Any]=4			,__snake_case   :int=37			,__snake_case   :Optional[int]="gelu"			,__snake_case   :Tuple=0.1			,__snake_case   :Any=0.1			,__snake_case   :List[Any]=5_12			,__snake_case   :List[str]=16			,__snake_case   :int=2			,__snake_case   :List[str]=0.02			,__snake_case   :List[str]=3			,__snake_case   :str=4			,__snake_case   :Union[str, Any]=None			,)					->    Any:
												a__             =     parent
												a__             =     batch_size
												a__             =     seq_length
												a__             =     is_training
												a__             =     use_input_mask
												a__             =     use_token_type_ids
												a__             =     use_labels
												a__             =     vocab_size
												a__             =     hidden_size
												a__             =     num_hidden_layers
												a__             =     num_attention_heads
												a__             =     intermediate_size
												a__             =     hidden_act
												a__             =     hidden_dropout_prob
												a__             =     attention_probs_dropout_prob
												a__             =     max_position_embeddings
												a__             =     type_vocab_size
												a__             =     type_sequence_label_size
												a__             =     initializer_range
												a__             =     num_labels
												a__             =     num_choices
												a__             =     scope
					def  lowerCamelCase__(      self   :Optional[Any]      )					->    Optional[Any]:
												a__             =     ids_tensor([self.batch_size, self.seq_length]			,self.vocab_size      )

												a__             =     None
												if self.use_input_mask:
																			a__             =     random_attention_mask([self.batch_size, self.seq_length]      )

												a__             =     None
												a__             =     None
												a__             =     None
												if self.use_labels:
																			a__             =     ids_tensor([self.batch_size]			,self.type_sequence_label_size      )
																			a__             =     ids_tensor([self.batch_size, self.seq_length]			,self.num_labels      )
																			a__             =     ids_tensor([self.batch_size]			,self.num_choices      )

												a__             =     self.get_config()

												return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels
					def  lowerCamelCase__(      self   :Dict      )					->    List[str]:
												a__             =     EsmConfig(
												    vocab_size=33			,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=__snake_case			,esmfold_config={'trunk': {'num_blocks': 2}, 'fp16_esm': False}			,)
												return config
					def  lowerCamelCase__(      self   :Dict			,__snake_case   :Optional[int]			,__snake_case   :Dict			,__snake_case   :Tuple			,__snake_case   :List[str]			,__snake_case   :Any			,__snake_case   :Union[str, Any]      )					->    List[Any]:
												a__             =     EsmForProteinFolding(config=__snake_case      ).float()
												model.to(__snake_case      )
												model.eval()
												a__             =     model(__snake_case			,attention_mask=__snake_case      )
												a__             =     model(__snake_case      )
												a__             =     model(__snake_case      )

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



					def  lowerCamelCase__(      self   :Dict      )					->    List[str]:
												a__             =     self.prepare_config_and_inputs()
												(
												    (
												    a__
												)      ,					(
												    a__
												)      ,					(
												    a__
												)      ,					(
												    a__
												)      ,					(
												    a__
												)      ,					(
												    a__
												)      ,					
												)             =     config_and_inputs
												a__             =     {'input_ids': input_ids, 'attention_mask': input_mask}
												return config, inputs_dict







@require_torch
class        snake_case_   (lowerCamelCase_	,						lowerCamelCase_	,						unittest.TestCase      ):
					UpperCAmelCase__					:    Optional[Any]          =			False

					UpperCAmelCase__					:    str          =			(EsmForProteinFolding,) if is_torch_available() else ()
					UpperCAmelCase__					:    int          =			()
					UpperCAmelCase__					:    Tuple          =			{} if is_torch_available() else {}
					UpperCAmelCase__					:    Optional[int]          =			False
					def  lowerCamelCase__(      self   :Dict      )					->    str:
												a__             =     EsmFoldModelTester(self      )
												a__             =     ConfigTester(self			,config_class=__snake_case			,hidden_size=37      )
					def  lowerCamelCase__(      self   :List[str]      )					->    int:
												self.config_tester.run_common_tests()
					def  lowerCamelCase__(      self   :Optional[Any]      )					->    Tuple:
												a__             =     self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*__snake_case      )
					@unittest.skip('Does not support attention outputs'      )
					def  lowerCamelCase__(      self   :Any      )					->    List[Any]:
												pass
					@unittest.skip
					def  lowerCamelCase__(      self   :Optional[int]      )					->    List[Any]:
												pass
					@unittest.skip('Esm does not support embedding resizing'      )
					def  lowerCamelCase__(      self   :Optional[int]      )					->    List[Any]:
												pass
					@unittest.skip('Esm does not support embedding resizing'      )
					def  lowerCamelCase__(      self   :Dict      )					->    Dict:
												pass
					@unittest.skip('ESMFold does not support passing input embeds!'      )
					def  lowerCamelCase__(      self   :Optional[Any]      )					->    Union[str, Any]:
												pass
					@unittest.skip('ESMFold does not support head pruning.'      )
					def  lowerCamelCase__(      self   :Any      )					->    Optional[int]:
												pass
					@unittest.skip('ESMFold does not support head pruning.'      )
					def  lowerCamelCase__(      self   :Any      )					->    Tuple:
												pass
					@unittest.skip('ESMFold does not support head pruning.'      )
					def  lowerCamelCase__(      self   :str      )					->    List[str]:
												pass
					@unittest.skip('ESMFold does not support head pruning.'      )
					def  lowerCamelCase__(      self   :Dict      )					->    int:
												pass
					@unittest.skip('ESMFold does not support head pruning.'      )
					def  lowerCamelCase__(      self   :str      )					->    Optional[Any]:
												pass
					@unittest.skip('ESMFold does not output hidden states in the normal way.'      )
					def  lowerCamelCase__(      self   :str      )					->    Any:
												pass
					@unittest.skip('ESMfold does not output hidden states in the normal way.'      )
					def  lowerCamelCase__(      self   :int      )					->    int:
												pass
					@unittest.skip('ESMFold only has one output format.'      )
					def  lowerCamelCase__(      self   :Dict      )					->    Optional[int]:
												pass
					@unittest.skip('This test doesn\'t work for ESMFold and doesn\'t test core functionality'      )
					def  lowerCamelCase__(      self   :List[Any]      )					->    Optional[int]:
												pass
					@unittest.skip('ESMFold does not support input chunking.'      )
					def  lowerCamelCase__(      self   :Dict      )					->    Tuple:
												pass
					@unittest.skip('ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.'      )
					def  lowerCamelCase__(      self   :Union[str, Any]      )					->    List[str]:
												pass
					@unittest.skip('ESMFold doesn\'t support torchscript compilation.'      )
					def  lowerCamelCase__(      self   :int      )					->    Tuple:
												pass
					@unittest.skip('ESMFold doesn\'t support torchscript compilation.'      )
					def  lowerCamelCase__(      self   :List[Any]      )					->    List[Any]:
												pass
					@unittest.skip('ESMFold doesn\'t support torchscript compilation.'      )
					def  lowerCamelCase__(      self   :int      )					->    int:
												pass
					@unittest.skip('ESMFold doesn\'t support data parallel.'      )
					def  lowerCamelCase__(      self   :Any      )					->    List[str]:
												pass



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







@require_torch
class        snake_case_   (lowerCamelCase_      ):
					@slow
					def  lowerCamelCase__(      self   :str      )					->    Dict:
												a__             =     EsmForProteinFolding.from_pretrained('facebook/esmfold_v1'      ).float()
												model.eval()
												a__             =     torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]      )
												a__             =     model(__snake_case      )['positions']
												a__             =     torch.tensor([2.58_28, 0.79_93, -10.93_34]			,dtype=torch.floataa      )
												self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]			,__snake_case			,atol=1E-4      )      )








import json
import os
import unittest

from transformers.models.xlm.tokenization_xlm import VOCAB_FILES_NAMES, XLMTokenizer
from transformers.testing_utils import slow

from ...test_tokenization_common import TokenizerTesterMixin







class        snake_case_   (lowerCamelCase_	,						unittest.TestCase      ):
					UpperCAmelCase__					:    Tuple          =			XLMTokenizer
					UpperCAmelCase__					:    List[str]          =			False
					def  lowerCamelCase__(      self   :Any      )					->    Optional[Any]:
												super().setUp()

												# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
												a__             =     [
												    'l',
												    'o',
												    'w',
												    'e',
												    'r',
												    's',
												    't',
												    'i',
												    'd',
												    'n',
												    'w</w>',
												    'r</w>',
												    't</w>',
												    'lo',
												    'low',
												    'er</w>',
												    'low</w>',
												    'lowest</w>',
												    'newer</w>',
												    'wider</w>',
												    '<unk>',
												]
												a__             =     dict(zip(__snake_case			,range(len(__snake_case      )      )      )      )
												a__             =     ['l o 123', 'lo w 1456', 'e r</w> 1789', '']

												a__             =     os.path.join(self.tmpdirname			,VOCAB_FILES_NAMES['vocab_file']      )
												a__             =     os.path.join(self.tmpdirname			,VOCAB_FILES_NAMES['merges_file']      )
												with open(self.vocab_file			,'w'      ) as fp:
																			fp.write(json.dumps(__snake_case      )      )
												with open(self.merges_file			,'w'      ) as fp:
																			fp.write('\n'.join(__snake_case      )      )
					def  lowerCamelCase__(      self   :Any			,__snake_case   :int      )					->    Optional[int]:
												a__             =     'lower newer'
												a__             =     'lower newer'
												return input_text, output_text
					def  lowerCamelCase__(      self   :Tuple      )					->    Tuple:
												a__             =     XLMTokenizer(self.vocab_file			,self.merges_file      )

												a__             =     'lower'
												a__             =     ['low', 'er</w>']
												a__             =     tokenizer.tokenize(__snake_case      )
												self.assertListEqual(__snake_case			,__snake_case      )

												a__             =     tokens + ['<unk>']
												a__             =     [14, 15, 20]
												self.assertListEqual(tokenizer.convert_tokens_to_ids(__snake_case      )			,__snake_case      )



					@slow
					def  lowerCamelCase__(      self   :List[str]      )					->    Optional[Any]:
												a__             =     XLMTokenizer.from_pretrained('xlm-mlm-en-2048'      )

												a__             =     tokenizer.encode('sequence builders'			,add_special_tokens=__snake_case      )
												a__             =     tokenizer.encode('multi-sequence build'			,add_special_tokens=__snake_case      )

												a__             =     tokenizer.build_inputs_with_special_tokens(__snake_case      )
												a__             =     tokenizer.build_inputs_with_special_tokens(__snake_case			,__snake_case      )

												assert encoded_sentence == [0] + text + [1]
												assert encoded_pair == [0] + text + [1] + text_a + [1]




