






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  UpperCamelCase_      :



	'''simple docstring'''




	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       ,			)       ->    Optional[int]:
								snake_case_				=							parent
								snake_case_				=							batch_size
								snake_case_				=							seq_length
								snake_case_				=							is_training
								snake_case_				=							use_input_mask
								snake_case_				=							use_token_type_ids
								snake_case_				=							use_labels
								snake_case_				=							vocab_size
								snake_case_				=							hidden_size
								snake_case_				=							num_hidden_layers
								snake_case_				=							num_attention_heads
								snake_case_				=							intermediate_size
								snake_case_				=							hidden_act
								snake_case_				=							hidden_dropout_prob
								snake_case_				=							attention_probs_dropout_prob
								snake_case_				=							max_position_embeddings
								snake_case_				=							type_vocab_size
								snake_case_				=							type_sequence_label_size
								snake_case_				=							initializer_range
								snake_case_				=							num_labels
								snake_case_				=							num_choices
								snake_case_				=							scope




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

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

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

								snake_case_				=							self.get_config()

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




	def 							_UpperCamelCase			(       self					)       ->    Optional[Any]:
								snake_case_				=							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 							_UpperCamelCase			(       self       ,			a       ,			a       ,			a       ,			a       ,			a       ,			a					)       ->    str:
								snake_case_				=							EsmForProteinFolding(config=_snake_case					).float()
								model.to(_snake_case					)
								model.eval()
								snake_case_				=							model(_snake_case       ,			attention_mask=_snake_case					)
								snake_case_				=							model(_snake_case					)
								snake_case_				=							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 							_UpperCamelCase			(       self					)       ->    Any:
								snake_case_				=							self.prepare_config_and_inputs()
								(
								    snake_case_				
								)				=							config_and_inputs
								snake_case_				=							{'input_ids': input_ids, 'attention_mask': input_mask}
								return config, inputs_dict






@require_torch
class  UpperCamelCase_      (			lowerCAmelCase_       ,					lowerCAmelCase_       ,					unittest.TestCase				):



	'''simple docstring'''




	lowerCAmelCase													= False

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




	def 							_UpperCamelCase			(       self					)       ->    Optional[Any]:
								snake_case_				=							EsmFoldModelTester(self					)
								snake_case_				=							ConfigTester(self       ,			config_class=_snake_case       ,			hidden_size=37					)




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




	def 							_UpperCamelCase			(       self					)       ->    Tuple:
								snake_case_				=							self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*_snake_case					)




	@unittest.skip('Does not support attention outputs'					)
	def 							_UpperCamelCase			(       self					)       ->    Dict:
								pass




	@unittest.skip
	def 							_UpperCamelCase			(       self					)       ->    int:
								pass




	@unittest.skip('Esm does not support embedding resizing'					)
	def 							_UpperCamelCase			(       self					)       ->    Dict:
								pass




	@unittest.skip('Esm does not support embedding resizing'					)
	def 							_UpperCamelCase			(       self					)       ->    List[Any]:
								pass




	@unittest.skip('ESMFold does not support passing input embeds!'					)
	def 							_UpperCamelCase			(       self					)       ->    List[str]:
								pass




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




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




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




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




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




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




	@unittest.skip('ESMfold does not output hidden states in the normal way.'					)
	def 							_UpperCamelCase			(       self					)       ->    Union[str, Any]:
								pass




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




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




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




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




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




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




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




	@unittest.skip('ESMFold doesn\'t support data parallel.'					)
	def 							_UpperCamelCase			(       self					)       ->    List[str]:
								pass






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






@require_torch
class  UpperCamelCase_      (			lowerCAmelCase_				):



	'''simple docstring'''




	@slow
	def 							_UpperCamelCase			(       self					)       ->    Optional[Any]:
								snake_case_				=							EsmForProteinFolding.from_pretrained('facebook/esmfold_v1'					).float()
								model.eval()
								snake_case_				=							torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]					)
								snake_case_				=							model(_snake_case					)['positions']
								snake_case_				=							torch.tensor([2.5_828, 0.7_993, -10.93_34]       ,			dtype=torch.floataa					)
								self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]       ,			_snake_case       ,			atol=1E-4					)					)










import argparse

import torch

from transformers import LxmertConfig, LxmertForPreTraining, load_tf_weights_in_lxmert
from transformers.utils import logging


logging.set_verbosity_info()
def        lowercase_							(A : str		,					A : List[Any]		,					A : Any      ):
       # Initialise PyTorch model
       snake_case__							:	List[Any]   	=	LxmertConfig.from_json_file(A      )
       print(F'''Building PyTorch model from configuration: {config}'''      )
       snake_case__							:	List[str]   	=	LxmertForPreTraining(A      )

       # Load weights from tf checkpoint
       load_tf_weights_in_lxmert(A		,					A		,					A      )

       # Save pytorch-model
       print(F'''Save PyTorch model to {pytorch_dump_path}'''      )
       torch.save(model.state_dict()		,					A      )


if __name__ == "__main__":
 a_   :Union[str, Any]        =      argparse.ArgumentParser()
 # Required parameters
 parser.add_argument(
     "--tf_checkpoint_path", default=None, type=str, required=True, help="Path to the TensorFlow checkpoint path."
 )
 parser.add_argument(
     "--config_file",
     default=None,
     type=str,
     required=True,
     help="The config json file corresponding to the pre-trained model. \nThis specifies the model architecture.",
 )
 parser.add_argument(
     "--pytorch_dump_path", default=None, type=str, required=True, help="Path to the output PyTorch model."
 )
 a_   :Optional[int]        =      parser.parse_args()
 convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path)






