

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			:



			'''simple docstring'''






			def __init__(				self	:						List[str]		,      lowerCAmelCase_	:						Any		,      lowerCAmelCase_	:						List[Any]=13		,      lowerCAmelCase_	:						str=7		,      lowerCAmelCase_	:						List[str]=False		,      lowerCAmelCase_	:						Union[str, Any]=True		,      lowerCAmelCase_	:						int=False		,      lowerCAmelCase_	:						List[Any]=False		,      lowerCAmelCase_	:						Optional[Any]=19		,      lowerCAmelCase_	:						int=32		,      lowerCAmelCase_	:						Union[str, Any]=5		,      lowerCAmelCase_	:						List[str]=4		,      lowerCAmelCase_	:						Optional[Any]=37		,      lowerCAmelCase_	:						List[Any]="gelu"		,      lowerCAmelCase_	:						Any=0.1		,      lowerCAmelCase_	:						Any=0.1		,      lowerCAmelCase_	:						List[Any]=5_12		,      lowerCAmelCase_	:						Dict=16		,      lowerCAmelCase_	:						Union[str, Any]=2		,      lowerCAmelCase_	:						Tuple=0.02		,      lowerCAmelCase_	:						List[str]=3		,      lowerCAmelCase_	:						int=4		,      lowerCAmelCase_	:						Dict=None		,      )      ->		int:





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


			def lowercase__						(				self	:						str			)      ->		Optional[int]:





									'''simple docstring'''
									A__					:       List[str]     =ids_tensor([self.batch_size, self.seq_length]		,      self.vocab_size			)

									A__					:       List[Any]     =None
									if self.use_input_mask:
															A__					:       Union[str, Any]     =random_attention_mask([self.batch_size, self.seq_length]			)

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

									A__					:       Dict     =self.get_config()

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


			def lowercase__						(				self	:						Optional[int]			)      ->		str:





									'''simple docstring'''
									A__					:       int     =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 lowercase__						(				self	:						int		,      lowerCAmelCase_	:						List[Any]		,      lowerCAmelCase_	:						str		,      lowerCAmelCase_	:						Tuple		,      lowerCAmelCase_	:						Any		,      lowerCAmelCase_	:						Optional[int]		,      lowerCAmelCase_	:						List[str]			)      ->		Union[str, Any]:





									'''simple docstring'''
									A__					:       Dict     =EsmForProteinFolding(config=snake_case__			).float()
									model.to(snake_case__			)
									model.eval()
									A__					:       Optional[Any]     =model(snake_case__		,      attention_mask=snake_case__			)
									A__					:       Optional[Any]     =model(snake_case__			)
									A__					:       Dict     =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 lowercase__						(				self	:						Optional[int]			)      ->		int:





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



@require_torch
class lowerCamelCase			(  A_	,						A_	,						unittest.TestCase						):



			'''simple docstring'''






			__snake_case        =	False

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


			def lowercase__						(				self	:						Union[str, Any]			)      ->		int:





									'''simple docstring'''
									A__					:       str     =EsmFoldModelTester(self			)
									A__					:       Any     =ConfigTester(self		,      config_class=snake_case__		,      hidden_size=37			)


			def lowercase__						(				self	:						List[str]			)      ->		Optional[Any]:





									'''simple docstring'''
									self.config_tester.run_common_tests()


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





									'''simple docstring'''
									A__					:       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 lowercase__						(				self	:						Tuple			)      ->		str:





									'''simple docstring'''
									pass


			@unittest.skip
			def lowercase__						(				self	:						str			)      ->		List[str]:





									'''simple docstring'''
									pass


			@unittest.skip("""Esm does not support embedding resizing"""			)
			def lowercase__						(				self	:						str			)      ->		str:





									'''simple docstring'''
									pass


			@unittest.skip("""Esm does not support embedding resizing"""			)
			def lowercase__						(				self	:						Union[str, Any]			)      ->		Dict:





									'''simple docstring'''
									pass


			@unittest.skip("""ESMFold does not support passing input embeds!"""			)
			def lowercase__						(				self	:						Any			)      ->		Tuple:





									'''simple docstring'''
									pass


			@unittest.skip("""ESMFold does not support head pruning."""			)
			def lowercase__						(				self	:						List[str]			)      ->		int:





									'''simple docstring'''
									pass


			@unittest.skip("""ESMFold does not support head pruning."""			)
			def lowercase__						(				self	:						int			)      ->		Tuple:





									'''simple docstring'''
									pass


			@unittest.skip("""ESMFold does not support head pruning."""			)
			def lowercase__						(				self	:						Optional[int]			)      ->		List[str]:





									'''simple docstring'''
									pass


			@unittest.skip("""ESMFold does not support head pruning."""			)
			def lowercase__						(				self	:						Dict			)      ->		Optional[Any]:





									'''simple docstring'''
									pass


			@unittest.skip("""ESMFold does not support head pruning."""			)
			def lowercase__						(				self	:						List[Any]			)      ->		Optional[int]:





									'''simple docstring'''
									pass


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





									'''simple docstring'''
									pass


			@unittest.skip("""ESMfold does not output hidden states in the normal way."""			)
			def lowercase__						(				self	:						Any			)      ->		str:





									'''simple docstring'''
									pass


			@unittest.skip("""ESMFold only has one output format."""			)
			def lowercase__						(				self	:						Optional[Any]			)      ->		List[str]:





									'''simple docstring'''
									pass


			@unittest.skip("""This test doesn't work for ESMFold and doesn't test core functionality"""			)
			def lowercase__						(				self	:						Optional[int]			)      ->		Any:





									'''simple docstring'''
									pass


			@unittest.skip("""ESMFold does not support input chunking."""			)
			def lowercase__						(				self	:						Any			)      ->		Union[str, Any]:





									'''simple docstring'''
									pass


			@unittest.skip("""ESMFold doesn't respect you and it certainly doesn't respect your initialization arguments."""			)
			def lowercase__						(				self	:						Dict			)      ->		List[Any]:





									'''simple docstring'''
									pass


			@unittest.skip("""ESMFold doesn't support torchscript compilation."""			)
			def lowercase__						(				self	:						List[str]			)      ->		Optional[Any]:





									'''simple docstring'''
									pass


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





									'''simple docstring'''
									pass


			@unittest.skip("""ESMFold doesn't support torchscript compilation."""			)
			def lowercase__						(				self	:						Optional[int]			)      ->		Optional[Any]:





									'''simple docstring'''
									pass


			@unittest.skip("""ESMFold doesn't support data parallel."""			)
			def lowercase__						(				self	:						str			)      ->		List[Any]:





									'''simple docstring'''
									pass



			@unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""			)
			def lowercase__						(				self	:						Union[str, Any]			)      ->		int:





									'''simple docstring'''
									pass



@require_torch
class lowerCamelCase			(  A_						):



			'''simple docstring'''






			@slow
			def lowercase__						(				self	:						Any			)      ->		int:





									'''simple docstring'''
									A__					:       List[Any]     =EsmForProteinFolding.from_pretrained("""facebook/esmfold_v1"""			).float()
									model.eval()
									A__					:       List[Any]     =torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]			)
									A__					:       Optional[Any]     =model(snake_case__			)["positions"]
									A__					:       List[str]     =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'''



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_speech_available, is_torch_available


__snake_case			:     Any										=      {
    'configuration_audio_spectrogram_transformer': [
        'AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'ASTConfig',
    ]
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case			:     Optional[int]										=      [
		    'AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'ASTForAudioClassification',
		    'ASTModel',
		    'ASTPreTrainedModel',
		]

try:
		if not is_speech_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case			:     List[Any]										=      ['ASTFeatureExtractor']

if TYPE_CHECKING:
		from .configuration_audio_spectrogram_transformer import (
		    AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
		    ASTConfig,
		)

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_audio_spectrogram_transformer import (
				    AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
				    ASTForAudioClassification,
				    ASTModel,
				    ASTPreTrainedModel,
				)

		try:
				if not is_speech_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .feature_extraction_audio_spectrogram_transformer import ASTFeatureExtractor


else:
		import sys

		__snake_case			:     Optional[Any]										=      _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)

