






"""simple docstring"""



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]							,			snake_case__      :	Tuple							,			snake_case__      :	Optional[int]=1_3							,			snake_case__      :	str=7							,			snake_case__      :	List[Any]=False							,			snake_case__      :	List[Any]=True							,			snake_case__      :	List[Any]=False							,			snake_case__      :	Optional[Any]=False							,			snake_case__      :	List[Any]=1_9							,			snake_case__      :	Any=3_2							,			snake_case__      :	Any=5							,			snake_case__      :	List[Any]=4							,			snake_case__      :	Optional[Any]=3_7							,			snake_case__      :	str="gelu"							,			snake_case__      :	List[Any]=0.1							,			snake_case__      :	Union[str, Any]=0.1							,			snake_case__      :	Any=5_1_2							,			snake_case__      :	Dict=1_6							,			snake_case__      :	str=2							,			snake_case__      :	List[Any]=0.02							,			snake_case__      :	List[str]=3							,			snake_case__      :	Optional[Any]=4							,			snake_case__      :	List[Any]=None							,			):


        '''simple docstring'''
        UpperCAmelCase__						:    Tuple							=							parent
        UpperCAmelCase__						:    Optional[Any]							=							batch_size
        UpperCAmelCase__						:    Optional[Any]							=							seq_length
        UpperCAmelCase__						:    Optional[Any]							=							is_training
        UpperCAmelCase__						:    List[Any]							=							use_input_mask
        UpperCAmelCase__						:    Any							=							use_token_type_ids
        UpperCAmelCase__						:    List[Any]							=							use_labels
        UpperCAmelCase__						:    Tuple							=							vocab_size
        UpperCAmelCase__						:    List[Any]							=							hidden_size
        UpperCAmelCase__						:    List[str]							=							num_hidden_layers
        UpperCAmelCase__						:    Any							=							num_attention_heads
        UpperCAmelCase__						:    Dict							=							intermediate_size
        UpperCAmelCase__						:    Optional[int]							=							hidden_act
        UpperCAmelCase__						:    Tuple							=							hidden_dropout_prob
        UpperCAmelCase__						:    Optional[int]							=							attention_probs_dropout_prob
        UpperCAmelCase__						:    Any							=							max_position_embeddings
        UpperCAmelCase__						:    int							=							type_vocab_size
        UpperCAmelCase__						:    List[Any]							=							type_sequence_label_size
        UpperCAmelCase__						:    Union[str, Any]							=							initializer_range
        UpperCAmelCase__						:    Any							=							num_labels
        UpperCAmelCase__						:    Optional[int]							=							num_choices
        UpperCAmelCase__						:    Tuple							=							scope
   def       __a							(		self      :	Optional[int]							):


        '''simple docstring'''
        UpperCAmelCase__						:    Any							=							ids_tensor([self.batch_size, self.seq_length]							,			self.vocab_size							)

        UpperCAmelCase__						:    Any							=							None
        if self.use_input_mask:
             UpperCAmelCase__						:    int							=							random_attention_mask([self.batch_size, self.seq_length]							)

        UpperCAmelCase__						:    Any							=							None
        UpperCAmelCase__						:    Optional[Any]							=							None
        UpperCAmelCase__						:    List[Any]							=							None
        if self.use_labels:
             UpperCAmelCase__						:    Dict							=							ids_tensor([self.batch_size]							,			self.type_sequence_label_size							)
             UpperCAmelCase__						:    str							=							ids_tensor([self.batch_size, self.seq_length]							,			self.num_labels							)
             UpperCAmelCase__						:    int							=							ids_tensor([self.batch_size]							,			self.num_choices							)

        UpperCAmelCase__						:    str							=							self.get_config()

        return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels
   def       __a							(		self      :	Union[str, Any]							):


        '''simple docstring'''
        UpperCAmelCase__						:    List[str]							=							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=snake_case__							,			esmfold_config={"trunk": {"num_blocks": 2}, "fp16_esm": False}							,			)
        return config
   def       __a							(		self      :	Any							,			snake_case__      :	Union[str, Any]							,			snake_case__      :	Tuple							,			snake_case__      :	Dict							,			snake_case__      :	str							,			snake_case__      :	Union[str, Any]							,			snake_case__      :	List[str]							):


        '''simple docstring'''
        UpperCAmelCase__						:    List[Any]							=							EsmForProteinFolding(config=snake_case__							).float()
        model.to(snake_case__							)
        model.eval()
        UpperCAmelCase__						:    List[Any]							=							model(snake_case__							,			attention_mask=snake_case__							)
        UpperCAmelCase__						:    List[Any]							=							model(snake_case__							)
        UpperCAmelCase__						:    str							=							model(snake_case__							)

        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       __a							(		self      :	Any							):


        '''simple docstring'''
        UpperCAmelCase__						:    Any							=							self.prepare_config_and_inputs()
        (
            (
            UpperCAmelCase__
        )							,				(
            UpperCAmelCase__
        )							,				(
            UpperCAmelCase__
        )							,				(
            UpperCAmelCase__
        )							,				(
            UpperCAmelCase__
        )							,				(
            UpperCAmelCase__
        )							,				
        )						:    Tuple							=							config_and_inputs
        UpperCAmelCase__						:    Optional[Any]							=							{"input_ids": input_ids, "attention_mask": input_mask}
        return config, inputs_dict




@require_torch
class 			lowerCAmelCase__			(    __magic_name__							,						__magic_name__							,						unittest.TestCase   ):
   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       __a							(		self      :	Dict							):


        '''simple docstring'''
        UpperCAmelCase__						:    str							=							EsmFoldModelTester(self							)
        UpperCAmelCase__						:    Optional[int]							=							ConfigTester(self							,			config_class=snake_case__							,			hidden_size=3_7							)
   def       __a							(		self      :	Dict							):


        '''simple docstring'''
        self.config_tester.run_common_tests()
   def       __a							(		self      :	List[Any]							):


        '''simple docstring'''
        UpperCAmelCase__						:    Tuple							=							self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*snake_case__							)
   @unittest.skip("Does not support attention outputs"							)
   def       __a							(		self      :	Tuple							):


        '''simple docstring'''
        pass
   @unittest.skip
   def       __a							(		self      :	Any							):


        '''simple docstring'''
        pass
   @unittest.skip("Esm does not support embedding resizing"							)
   def       __a							(		self      :	int							):


        '''simple docstring'''
        pass
   @unittest.skip("Esm does not support embedding resizing"							)
   def       __a							(		self      :	List[Any]							):


        '''simple docstring'''
        pass
   @unittest.skip("ESMFold does not support passing input embeds!"							)
   def       __a							(		self      :	Tuple							):


        '''simple docstring'''
        pass
   @unittest.skip("ESMFold does not support head pruning."							)
   def       __a							(		self      :	int							):


        '''simple docstring'''
        pass
   @unittest.skip("ESMFold does not support head pruning."							)
   def       __a							(		self      :	Optional[int]							):


        '''simple docstring'''
        pass
   @unittest.skip("ESMFold does not support head pruning."							)
   def       __a							(		self      :	Union[str, Any]							):


        '''simple docstring'''
        pass
   @unittest.skip("ESMFold does not support head pruning."							)
   def       __a							(		self      :	List[str]							):


        '''simple docstring'''
        pass
   @unittest.skip("ESMFold does not support head pruning."							)
   def       __a							(		self      :	Union[str, Any]							):


        '''simple docstring'''
        pass
   @unittest.skip("ESMFold does not output hidden states in the normal way."							)
   def       __a							(		self      :	List[str]							):


        '''simple docstring'''
        pass
   @unittest.skip("ESMfold does not output hidden states in the normal way."							)
   def       __a							(		self      :	str							):


        '''simple docstring'''
        pass
   @unittest.skip("ESMFold only has one output format."							)
   def       __a							(		self      :	Optional[Any]							):


        '''simple docstring'''
        pass
   @unittest.skip("This test doesn't work for ESMFold and doesn't test core functionality"							)
   def       __a							(		self      :	Tuple							):


        '''simple docstring'''
        pass
   @unittest.skip("ESMFold does not support input chunking."							)
   def       __a							(		self      :	Any							):


        '''simple docstring'''
        pass
   @unittest.skip("ESMFold doesn't respect you and it certainly doesn't respect your initialization arguments."							)
   def       __a							(		self      :	Tuple							):


        '''simple docstring'''
        pass
   @unittest.skip("ESMFold doesn't support torchscript compilation."							)
   def       __a							(		self      :	Optional[Any]							):


        '''simple docstring'''
        pass
   @unittest.skip("ESMFold doesn't support torchscript compilation."							)
   def       __a							(		self      :	Any							):


        '''simple docstring'''
        pass
   @unittest.skip("ESMFold doesn't support torchscript compilation."							)
   def       __a							(		self      :	str							):


        '''simple docstring'''
        pass
   @unittest.skip("ESMFold doesn't support data parallel."							)
   def       __a							(		self      :	List[Any]							):


        '''simple docstring'''
        pass




   @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."							)
   def       __a							(		self      :	List[str]							):


        '''simple docstring'''
        pass




@require_torch
class 			lowerCAmelCase__			(    __magic_name__   ):
   @slow
   def       __a							(		self      :	Any							):


        '''simple docstring'''
        UpperCAmelCase__						:    Tuple							=							EsmForProteinFolding.from_pretrained("facebook/esmfold_v1"							).float()
        model.eval()
        UpperCAmelCase__						:    str							=							torch.tensor([[0, 6, 4, 1_3, 5, 4, 1_6, 1_2, 1_1, 7, 2]]							)
        UpperCAmelCase__						:    Optional[int]							=							model(snake_case__							)["positions"]
        UpperCAmelCase__						:    Dict							=							torch.tensor([2.5828, 0.7993, -10.9334]							,			dtype=torch.floataa							)
        self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]							,			snake_case__							,			atol=1e-4							)							)










"""simple docstring"""



import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow


if is_torch_available():
 import torch

 from transformers import XLMRobertaModel




@require_sentencepiece
@require_tokenizers
@require_torch
class 			lowerCAmelCase__			(    unittest.TestCase   ):
   @slow
   def       __a							(		self      :	Tuple							):


        '''simple docstring'''
        UpperCAmelCase__						:    List[str]							=							XLMRobertaModel.from_pretrained("xlm-roberta-base"							)
        UpperCAmelCase__						:    str							=							torch.tensor([[0, 5_8_1, 1_0_2_6_9, 8_3, 9_9_9_4_2, 1_3_6, 6_0_7_4_2, 2_3, 7_0, 8_0_5_8_3, 1_8_2_7_6, 2]]							)
        # The dog is cute and lives in the garden house

        UpperCAmelCase__						:    Tuple							=							torch.Size((1, 1_2, 7_6_8)							)  # batch_size, sequence_length, embedding_vector_dim
        UpperCAmelCase__						:    Optional[int]							=							torch.tensor(
            [[-0.0101, 0.1218, -0.0803, 0.0801, 0.1327, 0.0776, -0.1215, 0.2383, 0.3338, 0.3106, 0.0300, 0.0252]]							)
        #  xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.base')
        #  xlmr.eval()
        #  expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
        with torch.no_grad():
             UpperCAmelCase__						:    int							=							model(snake_case__							)["last_hidden_state"].detach()
        self.assertEqual(output.shape							,			snake_case__							)
        # compare the actual values for a slice of last dim
        self.assertTrue(torch.allclose(output[:, :, -1]							,			snake_case__							,			atol=1e-3							)							)




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


        '''simple docstring'''
        UpperCAmelCase__						:    Any							=							XLMRobertaModel.from_pretrained("xlm-roberta-large"							)
        UpperCAmelCase__						:    Tuple							=							torch.tensor([[0, 5_8_1, 1_0_2_6_9, 8_3, 9_9_9_4_2, 1_3_6, 6_0_7_4_2, 2_3, 7_0, 8_0_5_8_3, 1_8_2_7_6, 2]]							)
        # The dog is cute and lives in the garden house

        UpperCAmelCase__						:    Union[str, Any]							=							torch.Size((1, 1_2, 1_0_2_4)							)  # batch_size, sequence_length, embedding_vector_dim
        UpperCAmelCase__						:    Optional[Any]							=							torch.tensor(
            [[-0.0699, -0.0318, 0.0705, -0.1241, 0.0999, -0.0520, 0.1004, -0.1838, -0.4704, 0.1437, 0.0821, 0.0126]]							)
        #  xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.large')
        #  xlmr.eval()
        #  expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
        with torch.no_grad():
             UpperCAmelCase__						:    Optional[Any]							=							model(snake_case__							)["last_hidden_state"].detach()
        self.assertEqual(output.shape							,			snake_case__							)
        # compare the actual values for a slice of last dim
        self.assertTrue(torch.allclose(output[:, :, -1]							,			snake_case__							,			atol=1e-3							)							)


