



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        lowerCAmelCase__					:


				def __init__(							self      :  List[str]						, __UpperCamelCase      :  Dict						, __UpperCamelCase      :  List[str]=13						, __UpperCamelCase      :  Tuple=7						, __UpperCamelCase      :  int=False						, __UpperCamelCase      :  Union[str, Any]=True						, __UpperCamelCase      :  Dict=False						, __UpperCamelCase      :  List[str]=False						, __UpperCamelCase      :  Optional[int]=19						, __UpperCamelCase      :  Any=32						, __UpperCamelCase      :  Union[str, Any]=5						, __UpperCamelCase      :  str=4						, __UpperCamelCase      :  Tuple=37						, __UpperCamelCase      :  Optional[int]="gelu"						, __UpperCamelCase      :  str=0.1						, __UpperCamelCase      :  Any=0.1						, __UpperCamelCase      :  Tuple=512						, __UpperCamelCase      :  str=16						, __UpperCamelCase      :  Union[str, Any]=2						, __UpperCamelCase      :  List[Any]=0.0_2						, __UpperCamelCase      :  int=3						, __UpperCamelCase      :  Optional[Any]=4						, __UpperCamelCase      :  Optional[int]=None						, )		->     Optional[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 __UpperCamelCase						(							self      :  Any       )		->     str:
											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 __UpperCamelCase						(							self      :  Union[str, Any]       )		->     List[Any]:
											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=__UpperCamelCase						, esmfold_config={'trunk': {'num_blocks': 2}, 'fp16_esm': False}						, )
											return config


				def __UpperCamelCase						(							self      :  Union[str, Any]						, __UpperCamelCase      :  Union[str, Any]						, __UpperCamelCase      :  Any						, __UpperCamelCase      :  Optional[int]						, __UpperCamelCase      :  Optional[Any]						, __UpperCamelCase      :  Union[str, Any]						, __UpperCamelCase      :  Tuple       )		->     Optional[int]:
											A      						=    EsmForProteinFolding(config=__UpperCamelCase       ).float()
											model.to(__UpperCamelCase       )
											model.eval()
											A      						=    model(__UpperCamelCase						, attention_mask=__UpperCamelCase       )
											A      						=    model(__UpperCamelCase       )
											A      						=    model(__UpperCamelCase       )

											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 __UpperCamelCase						(							self      :  Any       )		->     Dict:
											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        lowerCAmelCase__					(  _lowerCamelCase ,				_lowerCamelCase ,				unittest.TestCase       ):
				A_   :     Dict								=     False

				A_   :     List[Any]								=     (EsmForProteinFolding,) if is_torch_available() else ()
				A_   :     Tuple								=     ()
				A_   :     List[Any]								=     {} if is_torch_available() else {}
				A_   :     str								=     False


				def __UpperCamelCase						(							self      :  List[Any]       )		->     str:
											A      						=    EsmFoldModelTester(self       )
											A      						=    ConfigTester(self						, config_class=__UpperCamelCase						, hidden_size=37       )


				def __UpperCamelCase						(							self      :  Union[str, Any]       )		->     Optional[int]:
											self.config_tester.run_common_tests()


				def __UpperCamelCase						(							self      :  List[str]       )		->     Tuple:
											A      						=    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*__UpperCamelCase       )


				@unittest.skip('Does not support attention outputs'       )
				def __UpperCamelCase						(							self      :  Optional[int]       )		->     Optional[int]:
											pass


				@unittest.skip
				def __UpperCamelCase						(							self      :  Dict       )		->     List[str]:
											pass


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


				@unittest.skip('Esm does not support embedding resizing'       )
				def __UpperCamelCase						(							self      :  List[str]       )		->     Optional[int]:
											pass


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


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


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


				@unittest.skip('ESMFold does not support head pruning.'       )
				def __UpperCamelCase						(							self      :  Union[str, Any]       )		->     Optional[Any]:
											pass


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


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


				@unittest.skip('ESMFold does not output hidden states in the normal way.'       )
				def __UpperCamelCase						(							self      :  Tuple       )		->     Union[str, Any]:
											pass


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


				@unittest.skip('ESMFold only has one output format.'       )
				def __UpperCamelCase						(							self      :  Optional[int]       )		->     Any:
											pass


				@unittest.skip('This test doesn\'t work for ESMFold and doesn\'t test core functionality'       )
				def __UpperCamelCase						(							self      :  Tuple       )		->     Tuple:
											pass


				@unittest.skip('ESMFold does not support input chunking.'       )
				def __UpperCamelCase						(							self      :  Any       )		->     Dict:
											pass


				@unittest.skip('ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.'       )
				def __UpperCamelCase						(							self      :  Optional[Any]       )		->     Any:
											pass


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


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


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


				@unittest.skip('ESMFold doesn\'t support data parallel.'       )
				def __UpperCamelCase						(							self      :  List[Any]       )		->     Any:
											pass


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





@require_torch
class        lowerCAmelCase__					(  _lowerCamelCase       ):


				@slow
				def __UpperCamelCase						(							self      :  Union[str, Any]       )		->     Tuple:
											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(__UpperCamelCase       )['positions']
											A      						=    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       )       )




import json
import os
import unittest

from transformers.models.ctrl.tokenization_ctrl import VOCAB_FILES_NAMES, CTRLTokenizer

from ...test_tokenization_common import TokenizerTesterMixin



class        lowerCAmelCase__					(  _lowerCamelCase ,				unittest.TestCase       ):
				A_   :     int								=     CTRLTokenizer
				A_   :     List[str]								=     False
				A_   :     str								=     False


				def __UpperCamelCase						(							self      :  Any       )		->     Tuple:
											super().setUp()

											# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
											A      						=    ['adapt', 're@@', 'a@@', 'apt', 'c@@', 't', '<unk>']
											A      						=    dict(zip(__UpperCamelCase						, range(len(__UpperCamelCase       )       )       )       )
											A      						=    ['#version: 0.2', 'a p', 'ap t</w>', 'r e', 'a d', 'ad apt</w>', '']
											A      						=    {'unk_token': '<unk>'}

											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'						, 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 __UpperCamelCase						(							self      :  Optional[Any]						, **__UpperCamelCase      :  List[str]       )		->     List[Any]:
											kwargs.update(self.special_tokens_map       )
											return CTRLTokenizer.from_pretrained(self.tmpdirname						, **__UpperCamelCase       )


				def __UpperCamelCase						(							self      :  int						, __UpperCamelCase      :  Optional[int]       )		->     Optional[Any]:
											A      						=    'adapt react readapt apt'
											A      						=    'adapt react readapt apt'
											return input_text, output_text


				def __UpperCamelCase						(							self      :  List[Any]       )		->     Optional[int]:
											A      						=    CTRLTokenizer(self.vocab_file						, self.merges_file						, **self.special_tokens_map       )
											A      						=    'adapt react readapt apt'
											A      						=    'adapt re@@ a@@ c@@ t re@@ adapt apt'.split()
											A      						=    tokenizer.tokenize(__UpperCamelCase       )
											self.assertListEqual(__UpperCamelCase						, __UpperCamelCase       )

											A      						=    tokens + [tokenizer.unk_token]

											A      						=    [0, 1, 2, 4, 5, 1, 0, 3, 6]
											self.assertListEqual(tokenizer.convert_tokens_to_ids(__UpperCamelCase       )						, __UpperCamelCase       )