





"""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   ,							__a   ,							__a=13   ,							__a=7   ,							__a=False   ,							__a=True   ,							__a=False   ,							__a=False   ,							__a=19   ,							__a=32   ,							__a=5   ,							__a=4   ,							__a=37   ,							__a="gelu"   ,							__a=0.1   ,							__a=0.1   ,							__a=5_12   ,							__a=16   ,							__a=2   ,							__a=0.02   ,							__a=3   ,							__a=4   ,							__a=None   ,							) ->   str:
								UpperCamelCase   =	parent
								UpperCamelCase   =	batch_size
								UpperCamelCase   =	seq_length
								UpperCamelCase   =	is_training
								UpperCamelCase   =	use_input_mask
								UpperCamelCase   =	use_token_type_ids
								UpperCamelCase   =	use_labels
								UpperCamelCase   =	vocab_size
								UpperCamelCase   =	hidden_size
								UpperCamelCase   =	num_hidden_layers
								UpperCamelCase   =	num_attention_heads
								UpperCamelCase   =	intermediate_size
								UpperCamelCase   =	hidden_act
								UpperCamelCase   =	hidden_dropout_prob
								UpperCamelCase   =	attention_probs_dropout_prob
								UpperCamelCase   =	max_position_embeddings
								UpperCamelCase   =	type_vocab_size
								UpperCamelCase   =	type_sequence_label_size
								UpperCamelCase   =	initializer_range
								UpperCamelCase   =	num_labels
								UpperCamelCase   =	num_choices
								UpperCamelCase   =	scope


						def     snake_case_   (self		) ->   Tuple:
								UpperCamelCase   =	ids_tensor([self.batch_size, self.seq_length]   ,							self.vocab_size		)

								UpperCamelCase   =	None
								if self.use_input_mask:
										UpperCamelCase   =	random_attention_mask([self.batch_size, self.seq_length]		)

								UpperCamelCase   =	None
								UpperCamelCase   =	None
								UpperCamelCase   =	None
								if self.use_labels:
										UpperCamelCase   =	ids_tensor([self.batch_size]   ,							self.type_sequence_label_size		)
										UpperCamelCase   =	ids_tensor([self.batch_size, self.seq_length]   ,							self.num_labels		)
										UpperCamelCase   =	ids_tensor([self.batch_size]   ,							self.num_choices		)

								UpperCamelCase   =	self.get_config()

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


						def     snake_case_   (self		) ->   str:
								UpperCamelCase   =	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=__a   ,							esmfold_config={"trunk": {"num_blocks": 2}, "fp16_esm": False}   ,							)
								return config


						def     snake_case_   (self   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a   ,							__a		) ->   Optional[Any]:
								UpperCamelCase   =	EsmForProteinFolding(config=__a		).float()
								model.to(__a		)
								model.eval()
								UpperCamelCase   =	model(__a   ,							attention_mask=__a		)
								UpperCamelCase   =	model(__a		)
								UpperCamelCase   =	model(__a		)

								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     snake_case_   (self		) ->   Tuple:
								UpperCamelCase   =	self.prepare_config_and_inputs()
								(
								    UpperCamelCase	
								)   =	config_and_inputs
								UpperCamelCase   =	{'''input_ids''': input_ids, '''attention_mask''': input_mask}
								return config, inputs_dict





@require_torch
class        _lowerCamelCase      (       UpperCamelCase_  ,			UpperCamelCase_  ,			unittest.TestCase ):
						UpperCAmelCase_ =			False

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


						def     snake_case_   (self		) ->   Optional[int]:
								UpperCamelCase   =	EsmFoldModelTester(self		)
								UpperCamelCase   =	ConfigTester(self   ,							config_class=__a   ,							hidden_size=37		)


						def     snake_case_   (self		) ->   List[Any]:
								self.config_tester.run_common_tests()


						def     snake_case_   (self		) ->   Optional[Any]:
								UpperCamelCase   =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*__a		)


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


						@unittest.skip
						def     snake_case_   (self		) ->   Dict:
								pass


						@unittest.skip("Esm does not support embedding resizing"		)
						def     snake_case_   (self		) ->   Optional[int]:
								pass


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


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


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


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


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


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


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


						@unittest.skip("ESMFold does not output hidden states in the normal way."		)
						def     snake_case_   (self		) ->   List[Any]:
								pass


						@unittest.skip("ESMfold does not output hidden states in the normal way."		)
						def     snake_case_   (self		) ->   List[str]:
								pass


						@unittest.skip("ESMFold only has one output format."		)
						def     snake_case_   (self		) ->   Tuple:
								pass


						@unittest.skip("This test doesn\'t work for ESMFold and doesn\'t test core functionality"		)
						def     snake_case_   (self		) ->   int:
								pass


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


						@unittest.skip("ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments."		)
						def     snake_case_   (self		) ->   Any:
								pass


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


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


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


						@unittest.skip("ESMFold doesn\'t support data parallel."		)
						def     snake_case_   (self		) ->   Tuple:
								pass




						@unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."		)
						def     snake_case_   (self		) ->   Tuple:
								pass





@require_torch
class        _lowerCamelCase      (       UpperCamelCase_ ):


						@slow
						def     snake_case_   (self		) ->   List[Any]:
								UpperCamelCase   =	EsmForProteinFolding.from_pretrained("facebook/esmfold_v1"		).float()
								model.eval()
								UpperCamelCase   =	torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]		)
								UpperCamelCase   =	model(__a		)['''positions''']
								UpperCamelCase   =	torch.tensor([2.5828, 0.7993, -10.9334]   ,							dtype=torch.floataa		)
								self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]   ,							__a   ,							atol=1e-4		)		)









"""simple docstring"""





import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import CONFIG_MAPPING


lowerCAmelCase__     			=			logging.get_logger(__name__)





class        _lowerCamelCase      (       _lowercase ):
						UpperCAmelCase_ =			"upernet"


						def __init__(self   ,							__a=None   ,							__a=5_12   ,							__a=0.02   ,							__a=[1, 2, 3, 6]   ,							__a=True   ,							__a=0.4   ,							__a=3_84   ,							__a=2_56   ,							__a=1   ,							__a=False   ,							__a=2_55   ,							**__a   ,							) ->   Tuple:
								super().__init__(**__a		)

								if backbone_config is None:
										logger.info("`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."		)
										UpperCamelCase   =	CONFIG_MAPPING["resnet"](out_features=["stage1", "stage2", "stage3", "stage4"]		)
								elif isinstance(__a   ,							__a		):
										UpperCamelCase   =	backbone_config.get("model_type"		)
										UpperCamelCase   =	CONFIG_MAPPING[backbone_model_type]
										UpperCamelCase   =	config_class.from_dict(__a		)

								UpperCamelCase   =	backbone_config
								UpperCamelCase   =	hidden_size
								UpperCamelCase   =	initializer_range
								UpperCamelCase   =	pool_scales
								UpperCamelCase   =	use_auxiliary_head
								UpperCamelCase   =	auxiliary_loss_weight
								UpperCamelCase   =	auxiliary_in_channels
								UpperCamelCase   =	auxiliary_channels
								UpperCamelCase   =	auxiliary_num_convs
								UpperCamelCase   =	auxiliary_concat_input
								UpperCamelCase   =	loss_ignore_index




						def     snake_case_   (self		) ->   Optional[int]:
								UpperCamelCase   =	copy.deepcopy(self.__dict__		)
								UpperCamelCase   =	self.backbone_config.to_dict()
								UpperCamelCase   =	self.__class__.model_type
								return output






