





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     A     :
			'''simple docstring'''




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







					"""simple docstring"""






					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   a_			(     self  :       Optional[int]  )      ->      Tuple:







					"""simple docstring"""






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







					"""simple docstring"""






					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=__lowerCAmelCase				,      esmfold_config={"""trunk""": {"""num_blocks""": 2}, """fp16_esm""": False}				,      )
					return config






			def   a_			(     self  :       int				,      __lowerCAmelCase  :       Optional[Any]				,      __lowerCAmelCase  :       List[Any]				,      __lowerCAmelCase  :       Dict				,      __lowerCAmelCase  :       List[Any]				,      __lowerCAmelCase  :       str				,      __lowerCAmelCase  :       List[Any]  )      ->      Optional[int]:







					"""simple docstring"""






					A__     =  EsmForProteinFolding(config=__lowerCAmelCase  ).float()
					model.to(__lowerCAmelCase  )
					model.eval()
					A__     =  model(__lowerCAmelCase				,      attention_mask=__lowerCAmelCase  )
					A__     =  model(__lowerCAmelCase  )
					A__     =  model(__lowerCAmelCase  )

					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   a_			(     self  :       Optional[Any]  )      ->      List[str]:







					"""simple docstring"""






					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     A     (SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE  ,	unittest.TestCase       ):
			'''simple docstring'''




			__lowerCamelCase      :			Tuple							     =       False

			__lowerCamelCase      :			int							     =       (EsmForProteinFolding,) if is_torch_available() else ()
			__lowerCamelCase      :			List[str]							     =       ()
			__lowerCamelCase      :			Optional[Any]							     =       {} if is_torch_available() else {}
			__lowerCamelCase      :			Optional[int]							     =       False






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







					"""simple docstring"""






					A__     =  EsmFoldModelTester(self  )
					A__     =  ConfigTester(self				,      config_class=__lowerCAmelCase				,      hidden_size=37  )






			def   a_			(     self  :       str  )      ->      Tuple:







					"""simple docstring"""






					self.config_tester.run_common_tests()






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







					"""simple docstring"""






					A__     =  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*__lowerCAmelCase  )






			@unittest.skip("""Does not support attention outputs"""  )
			def   a_			(     self  :       Union[str, Any]  )      ->      Union[str, Any]:







					"""simple docstring"""






					pass






			@unittest.skip
			def   a_			(     self  :       int  )      ->      Tuple:







					"""simple docstring"""






					pass






			@unittest.skip("""Esm does not support embedding resizing"""  )
			def   a_			(     self  :       Tuple  )      ->      List[Any]:







					"""simple docstring"""






					pass






			@unittest.skip("""Esm does not support embedding resizing"""  )
			def   a_			(     self  :       Tuple  )      ->      List[str]:







					"""simple docstring"""






					pass






			@unittest.skip("""ESMFold does not support passing input embeds!"""  )
			def   a_			(     self  :       int  )      ->      List[str]:







					"""simple docstring"""






					pass






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







					"""simple docstring"""






					pass






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







					"""simple docstring"""






					pass






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







					"""simple docstring"""






					pass






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







					"""simple docstring"""






					pass






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







					"""simple docstring"""






					pass






			@unittest.skip("""ESMFold does not output hidden states in the normal way."""  )
			def   a_			(     self  :       Tuple  )      ->      Tuple:







					"""simple docstring"""






					pass






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







					"""simple docstring"""






					pass






			@unittest.skip("""ESMFold only has one output format."""  )
			def   a_			(     self  :       Dict  )      ->      Optional[int]:







					"""simple docstring"""






					pass






			@unittest.skip("""This test doesn't work for ESMFold and doesn't test core functionality"""  )
			def   a_			(     self  :       Tuple  )      ->      Union[str, Any]:







					"""simple docstring"""






					pass






			@unittest.skip("""ESMFold does not support input chunking."""  )
			def   a_			(     self  :       Dict  )      ->      Dict:







					"""simple docstring"""






					pass






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







					"""simple docstring"""






					pass






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







					"""simple docstring"""






					pass






			@unittest.skip("""ESMFold doesn't support torchscript compilation."""  )
			def   a_			(     self  :       Any  )      ->      Union[str, Any]:







					"""simple docstring"""






					pass






			@unittest.skip("""ESMFold doesn't support torchscript compilation."""  )
			def   a_			(     self  :       Union[str, Any]  )      ->      str:







					"""simple docstring"""






					pass






			@unittest.skip("""ESMFold doesn't support data parallel."""  )
			def   a_			(     self  :       Dict  )      ->      Optional[Any]:







					"""simple docstring"""






					pass







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







					"""simple docstring"""






					pass


@require_torch
class     A     (SCREAMING_SNAKE_CASE       ):
			'''simple docstring'''




			@slow
			def   a_			(     self  :       List[Any]  )      ->      Optional[Any]:







					"""simple docstring"""






					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(__lowerCAmelCase  )["""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]				,      __lowerCAmelCase				,      atol=1e-4  )  )










from typing import TYPE_CHECKING

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


A       :   Dict					= {'''processing_layoutxlm''': ['''LayoutXLMProcessor''']}

try:
					if not is_sentencepiece_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					A       :   Dict					= ['''LayoutXLMTokenizer''']

try:
					if not is_tokenizers_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					A       :   Dict					= ['''LayoutXLMTokenizerFast''']

if TYPE_CHECKING:
					from .processing_layoutxlm import LayoutXLMProcessor

					try:
										if not is_sentencepiece_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_layoutxlm import LayoutXLMTokenizer

					try:
										if not is_tokenizers_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_layoutxlm_fast import LayoutXLMTokenizerFast

else:
					import sys

					A       :   int					= _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



