


'''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      lowercase			:

		"""simple docstring"""

		def __init__(	self					,     UpperCamelCase_					,     UpperCamelCase_=13					,     UpperCamelCase_=7					,     UpperCamelCase_=False					,     UpperCamelCase_=True					,     UpperCamelCase_=False					,     UpperCamelCase_=False					,     UpperCamelCase_=19					,     UpperCamelCase_=32					,     UpperCamelCase_=5					,     UpperCamelCase_=4					,     UpperCamelCase_=37					,     UpperCamelCase_="gelu"					,     UpperCamelCase_=0.1					,     UpperCamelCase_=0.1					,     UpperCamelCase_=512					,     UpperCamelCase_=16					,     UpperCamelCase_=2					,     UpperCamelCase_=0.02					,     UpperCamelCase_=3					,     UpperCamelCase_=4					,     UpperCamelCase_=None					,     ):

							'''simple docstring'''


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




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :int							      =				ids_tensor([self.batch_size, self.seq_length]					,     self.vocab_size							)

							UpperCamelCase__     :Tuple							      =				None
							if self.use_input_mask:
												UpperCamelCase__     :Optional[int]							      =				random_attention_mask([self.batch_size, self.seq_length]							)

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

							UpperCamelCase__     :Any							      =				self.get_config()

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




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Any							      =				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 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_					,     UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__     :str							      =				EsmForProteinFolding(config=UpperCamelCase_							).float()
							model.to(UpperCamelCase_							)
							model.eval()
							UpperCamelCase__     :List[str]							      =				model(UpperCamelCase_					,     attention_mask=UpperCamelCase_							)
							UpperCamelCase__     :Tuple							      =				model(UpperCamelCase_							)
							UpperCamelCase__     :Optional[int]							      =				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 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Optional[Any]							      =				self.prepare_config_and_inputs()
							(
							    (
							    UpperCamelCase__
							)      ,       (
							    UpperCamelCase__
							)      ,       (
							    UpperCamelCase__
							)      ,       (
							    UpperCamelCase__
							)      ,       (
							    UpperCamelCase__
							)      ,       (
							    UpperCamelCase__
							)      ,       
							)     :List[str]							      =				config_and_inputs
							UpperCamelCase__     :str							      =				{'''input_ids''': input_ids, '''attention_mask''': input_mask}
							return config, inputs_dict



@require_torch
class      lowercase			(							A__			,	A__			,	unittest.TestCase      ):

		"""simple docstring"""

		_a									=       False

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




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :List[Any]							      =				EsmFoldModelTester(self							)
							UpperCamelCase__     :Optional[int]							      =				ConfigTester(self					,     config_class=UpperCamelCase_					,     hidden_size=37							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							self.config_tester.run_common_tests()




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Union[str, Any]							      =				self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*UpperCamelCase_							)




		@unittest.skip('''Does not support attention outputs'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''Esm does not support embedding resizing'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''Esm does not support embedding resizing'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''ESMFold does not support passing input embeds!'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''ESMFold does not support head pruning.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''ESMFold does not support head pruning.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''ESMFold does not support head pruning.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''ESMFold does not support head pruning.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''ESMFold does not support head pruning.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''ESMFold does not output hidden states in the normal way.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''ESMfold does not output hidden states in the normal way.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''ESMFold only has one output format.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''This test doesn\'t work for ESMFold and doesn\'t test core functionality'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''ESMFold does not support input chunking.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''ESMFold doesn\'t support torchscript compilation.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''ESMFold doesn\'t support torchscript compilation.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''ESMFold doesn\'t support torchscript compilation.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''ESMFold doesn\'t support data parallel.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''							)
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass



@require_torch
class      lowercase			(							A__      ):

		"""simple docstring"""

		@slow
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :List[str]							      =				EsmForProteinFolding.from_pretrained('''facebook/esmfold_v1'''							).float()
							model.eval()
							UpperCamelCase__     :Optional[int]							      =				torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]							)
							UpperCamelCase__     :Tuple							      =				model(UpperCamelCase_							)['''positions''']
							UpperCamelCase__     :Optional[Any]							      =				torch.tensor([2.5828, 0.7993, -10.9334]					,     dtype=torch.floataa							)
							self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]					,     UpperCamelCase_					,     atol=1e-4							)							)



'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


__snake_case							   =  {
    '''configuration_layoutlmv3''': [
        '''LAYOUTLMV3_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''LayoutLMv3Config''',
        '''LayoutLMv3OnnxConfig''',
    ],
    '''processing_layoutlmv3''': ['''LayoutLMv3Processor'''],
    '''tokenization_layoutlmv3''': ['''LayoutLMv3Tokenizer'''],
}

try:
		if not is_tokenizers_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case							   =  ['''LayoutLMv3TokenizerFast''']

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case							   =  [
		    '''LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''LayoutLMv3ForQuestionAnswering''',
		    '''LayoutLMv3ForSequenceClassification''',
		    '''LayoutLMv3ForTokenClassification''',
		    '''LayoutLMv3Model''',
		    '''LayoutLMv3PreTrainedModel''',
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case							   =  [
		    '''TF_LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''TFLayoutLMv3ForQuestionAnswering''',
		    '''TFLayoutLMv3ForSequenceClassification''',
		    '''TFLayoutLMv3ForTokenClassification''',
		    '''TFLayoutLMv3Model''',
		    '''TFLayoutLMv3PreTrainedModel''',
		]

try:
		if not is_vision_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case							   =  ['''LayoutLMv3FeatureExtractor''']
		__snake_case							   =  ['''LayoutLMv3ImageProcessor''']


if TYPE_CHECKING:
		from .configuration_layoutlmva import (
		    LAYOUTLMV3_PRETRAINED_CONFIG_ARCHIVE_MAP,
		    LayoutLMvaConfig,
		    LayoutLMvaOnnxConfig,
		)
		from .processing_layoutlmva import LayoutLMvaProcessor
		from .tokenization_layoutlmva import LayoutLMvaTokenizer

		try:
				if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_layoutlmva_fast import LayoutLMvaTokenizerFast

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_layoutlmva import (
				    LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST,
				    LayoutLMvaForQuestionAnswering,
				    LayoutLMvaForSequenceClassification,
				    LayoutLMvaForTokenClassification,
				    LayoutLMvaModel,
				    LayoutLMvaPreTrainedModel,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_layoutlmva import (
				    TF_LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFLayoutLMvaForQuestionAnswering,
				    TFLayoutLMvaForSequenceClassification,
				    TFLayoutLMvaForTokenClassification,
				    TFLayoutLMvaModel,
				    TFLayoutLMvaPreTrainedModel,
				)

		try:
				if not is_vision_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .feature_extraction_layoutlmva import LayoutLMvaFeatureExtractor
				from .image_processing_layoutlmva import LayoutLMvaImageProcessor

else:
		import sys

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