





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 ,							__magic_name__ ,							__magic_name__=13 ,							__magic_name__=7 ,							__magic_name__=False ,							__magic_name__=True ,							__magic_name__=False ,							__magic_name__=False ,							__magic_name__=19 ,							__magic_name__=32 ,							__magic_name__=5 ,							__magic_name__=4 ,							__magic_name__=37 ,							__magic_name__="gelu" ,							__magic_name__=0.1 ,							__magic_name__=0.1 ,							__magic_name__=512 ,							__magic_name__=16 ,							__magic_name__=2 ,							__magic_name__=0.02 ,							__magic_name__=3 ,							__magic_name__=4 ,							__magic_name__=None ,							)					->       List[Any]:


							'''simple docstring'''



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






			def       lowerCamelCase  (self   )					->       Dict:


							'''simple docstring'''



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

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

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

							snake_case_						:   Tuple           =  self.get_config()

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






			def       lowerCamelCase  (self   )					->       Tuple:


							'''simple docstring'''



							snake_case_						:   List[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=__magic_name__ ,							esmfold_config={'''trunk''': {'''num_blocks''': 2}, '''fp16_esm''': False} ,							)
							return config






			def       lowerCamelCase  (self ,							__magic_name__ ,							__magic_name__ ,							__magic_name__ ,							__magic_name__ ,							__magic_name__ ,							__magic_name__   )					->       Union[str, Any]:


							'''simple docstring'''



							snake_case_						:   Any           =  EsmForProteinFolding(config=__magic_name__   ).float()
							model.to(__magic_name__   )
							model.eval()
							snake_case_						:   Union[str, Any]           =  model(__magic_name__ ,							attention_mask=__magic_name__   )
							snake_case_						:   int           =  model(__magic_name__   )
							snake_case_						:   Dict           =  model(__magic_name__   )

							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   )					->       str:


							'''simple docstring'''



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




@require_torch
class  __lowerCAmelCase	(      _a,					_a,					unittest.TestCase					):
			lowerCamelCase_					:					Optional[int]	      =				False

			lowerCamelCase_					:					Union[str, Any]	      =				(EsmForProteinFolding,) if is_torch_available() else ()
			lowerCamelCase_					:					Optional[Any]	      =				()
			lowerCamelCase_					:					Tuple	      =				{} if is_torch_available() else {}
			lowerCamelCase_					:					Optional[Any]	      =				False






			def       lowerCamelCase  (self   )					->       Dict:


							'''simple docstring'''



							snake_case_						:   Tuple           =  EsmFoldModelTester(self   )
							snake_case_						:   List[str]           =  ConfigTester(self ,							config_class=__magic_name__ ,							hidden_size=37   )






			def       lowerCamelCase  (self   )					->       List[str]:


							'''simple docstring'''



							self.config_tester.run_common_tests()






			def       lowerCamelCase  (self   )					->       int:


							'''simple docstring'''



							snake_case_						:   Dict           =  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*__magic_name__   )






			@unittest.skip('''Does not support attention outputs'''   )
			def       lowerCamelCase  (self   )					->       List[Any]:


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass






			@unittest.skip('''Esm does not support embedding resizing'''   )
			def       lowerCamelCase  (self   )					->       Any:


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass






			@unittest.skip('''ESMFold does not support head pruning.'''   )
			def       lowerCamelCase  (self   )					->       int:


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass






			@unittest.skip('''ESMFold does not support head pruning.'''   )
			def       lowerCamelCase  (self   )					->       Dict:


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass






			@unittest.skip('''ESMFold only has one output format.'''   )
			def       lowerCamelCase  (self   )					->       Tuple:


							'''simple docstring'''



							pass






			@unittest.skip('''This test doesn\'t work for ESMFold and doesn\'t test core functionality'''   )
			def       lowerCamelCase  (self   )					->       List[Any]:


							'''simple docstring'''



							pass






			@unittest.skip('''ESMFold does not support input chunking.'''   )
			def       lowerCamelCase  (self   )					->       List[str]:


							'''simple docstring'''



							pass






			@unittest.skip('''ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.'''   )
			def       lowerCamelCase  (self   )					->       Union[str, Any]:


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass






			@unittest.skip('''ESMFold doesn\'t support torchscript compilation.'''   )
			def       lowerCamelCase  (self   )					->       int:


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass




@require_torch
class  __lowerCAmelCase	(      _a					):






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


							'''simple docstring'''



							snake_case_						:   Optional[Any]           =  EsmForProteinFolding.from_pretrained('''facebook/esmfold_v1'''   ).float()
							model.eval()
							snake_case_						:   int           =  torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]   )
							snake_case_						:   Dict           =  model(__magic_name__   )['''positions''']
							snake_case_						:   Tuple           =  torch.tensor([2.5_828, 0.7_993, -10.9_334] ,							dtype=torch.floataa   )
							self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0] ,							__magic_name__ ,							atol=1e-4   )   )







from typing import TYPE_CHECKING

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


lowerCAmelCase_    =    {'''configuration_xglm''': ['''XGLM_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''XGLMConfig''']}

try:
	if not is_sentencepiece_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	lowerCAmelCase_    =    ['''XGLMTokenizer''']

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

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	lowerCAmelCase_    =    [
	    '''XGLM_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''XGLMForCausalLM''',
	    '''XGLMModel''',
	    '''XGLMPreTrainedModel''',
	]


try:
	if not is_flax_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	lowerCAmelCase_    =    [
	    '''FlaxXGLMForCausalLM''',
	    '''FlaxXGLMModel''',
	    '''FlaxXGLMPreTrainedModel''',
	]


try:
	if not is_tf_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	lowerCAmelCase_    =    [
	    '''TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''TFXGLMForCausalLM''',
	    '''TFXGLMModel''',
	    '''TFXGLMPreTrainedModel''',
	]


if TYPE_CHECKING:
	from .configuration_xglm import XGLM_PRETRAINED_CONFIG_ARCHIVE_MAP, XGLMConfig

	try:
		if not is_sentencepiece_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_xglm import XGLMTokenizer

	try:
		if not is_tokenizers_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_xglm_fast import XGLMTokenizerFast

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_xglm import XGLM_PRETRAINED_MODEL_ARCHIVE_LIST, XGLMForCausalLM, XGLMModel, XGLMPreTrainedModel

	try:
		if not is_flax_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_flax_xglm import FlaxXGLMForCausalLM, FlaxXGLMModel, FlaxXGLMPreTrainedModel

	try:
		if not is_tf_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tf_xglm import (
		    TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFXGLMForCausalLM,
		    TFXGLMModel,
		    TFXGLMPreTrainedModel,
		)


else:
	import sys

	lowerCAmelCase_    =    _LazyModule(__name__, globals()['''__file__'''], _import_structure)
