



"""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	,       snake_case	,       snake_case=13	,       snake_case=7	,       snake_case=False	,       snake_case=True	,       snake_case=False	,       snake_case=False	,       snake_case=19	,       snake_case=32	,       snake_case=5	,       snake_case=4	,       snake_case=37	,       snake_case="gelu"	,       snake_case=0.1	,       snake_case=0.1	,       snake_case=512	,       snake_case=16	,       snake_case=2	,       snake_case=0.02	,       snake_case=3	,       snake_case=4	,       snake_case=None	,       )			->							Tuple:
									_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        lowerCamelCase_   (  self						)			->							Optional[int]:
									_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        lowerCamelCase_   (  self						)			->							Union[str, Any]:
									_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=snake_case	,       esmfold_config={'trunk': {'num_blocks': 2}, 'fp16_esm': False}	,       )
									return config






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







@require_torch
class 			lowercase__			(      A,					A,					unittest.TestCase    ):
							'''simple docstring'''







							_UpperCAmelCase      				=					False

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






							def        lowerCamelCase_   (  self						)			->							Any:
									_UpperCAmelCase							 =		EsmFoldModelTester(self						)
									_UpperCAmelCase							 =		ConfigTester(self	,       config_class=snake_case	,       hidden_size=37						)






							def        lowerCamelCase_   (  self						)			->							Dict:
									self.config_tester.run_common_tests()






							def        lowerCamelCase_   (  self						)			->							str:
									_UpperCAmelCase							 =		self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*snake_case						)






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






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






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






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






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






							@unittest.skip('ESMFold does not support head pruning.'						)
							def        lowerCamelCase_   (  self						)			->							str:
									pass






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






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






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






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






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






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






							@unittest.skip('ESMFold only has one output format.'						)
							def        lowerCamelCase_   (  self						)			->							List[str]:
									pass






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






							@unittest.skip('ESMFold does not support input chunking.'						)
							def        lowerCamelCase_   (  self						)			->							Optional[Any]:
									pass






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






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






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






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






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






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







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







							@slow
							def        lowerCamelCase_   (  self						)			->							List[str]:
									_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(snake_case						)['positions']
									_UpperCAmelCase							 =		torch.tensor([2.5828, 0.7993, -10.9334]	,       dtype=torch.floataa						)
									self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]	,       snake_case	,       atol=1E-4						)						)







"""simple docstring"""





import argparse
import logging
import pickle
from collections import Counter


logging.basicConfig(
    format='''%(asctime)s - %(levelname)s - %(name)s - %(message)s''', datefmt='''%m/%d/%Y %H:%M:%S''', level=logging.INFO
)
lowercase  							=					logging.getLogger(__name__)

if __name__ == "__main__":
					lowercase  							=					argparse.ArgumentParser(
					    description='''Token Counts for smoothing the masking probabilities in MLM (cf XLM/word2vec)'''
					)
					parser.add_argument(
					    '''--data_file''', type=str, default='''data/dump.bert-base-uncased.pickle''', help='''The binarized dataset.'''
					)
					parser.add_argument(
					    '''--token_counts_dump''', type=str, default='''data/token_counts.bert-base-uncased.pickle''', help='''The dump file.'''
					)
					parser.add_argument('''--vocab_size''', default=3_05_22, type=int)
					lowercase  							=					parser.parse_args()

					logger.info(F'''Loading data from {args.data_file}''')
					with open(args.data_file, '''rb''') as fp:
										lowercase  							=					pickle.load(fp)

					logger.info('''Counting occurrences for MLM.''')
					lowercase  							=					Counter()
					for tk_ids in data:
										counter.update(tk_ids)
					lowercase  							=					[0] * args.vocab_size
					for k, v in counter.items():
										lowercase  							=					v

					logger.info(F'''Dump to {args.token_counts_dump}''')
					with open(args.token_counts_dump, '''wb''') as handle:
										pickle.dump(counts, handle, protocol=pickle.HIGHEST_PROTOCOL)


