


'''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 		UpperCAmelCase_      :





     def __init__( self       :      Union[str, Any]    ,      UpperCAmelCase__       :      Optional[Any]    ,      UpperCAmelCase__       :      Dict=1_3    ,      UpperCAmelCase__       :      str=7    ,      UpperCAmelCase__       :      Dict=False    ,      UpperCAmelCase__       :      List[Any]=True    ,      UpperCAmelCase__       :      Optional[Any]=False    ,      UpperCAmelCase__       :      Optional[int]=False    ,      UpperCAmelCase__       :      int=1_9    ,      UpperCAmelCase__       :      str=3_2    ,      UpperCAmelCase__       :      Dict=5    ,      UpperCAmelCase__       :      Any=4    ,      UpperCAmelCase__       :      Dict=3_7    ,      UpperCAmelCase__       :      List[Any]="gelu"    ,      UpperCAmelCase__       :      Dict=0.1    ,      UpperCAmelCase__       :      Optional[int]=0.1    ,      UpperCAmelCase__       :      int=5_1_2    ,      UpperCAmelCase__       :      int=1_6    ,      UpperCAmelCase__       :      Any=2    ,      UpperCAmelCase__       :      int=0.02    ,      UpperCAmelCase__       :      Any=3    ,      UpperCAmelCase__       :      List[str]=4    ,      UpperCAmelCase__       :      Optional[int]=None    ,      )				->  Union[str, Any]:
        lowerCAmelCase     =			parent
        lowerCAmelCase     =			batch_size
        lowerCAmelCase     =			seq_length
        lowerCAmelCase     =			is_training
        lowerCAmelCase     =			use_input_mask
        lowerCAmelCase     =			use_token_type_ids
        lowerCAmelCase     =			use_labels
        lowerCAmelCase     =			vocab_size
        lowerCAmelCase     =			hidden_size
        lowerCAmelCase     =			num_hidden_layers
        lowerCAmelCase     =			num_attention_heads
        lowerCAmelCase     =			intermediate_size
        lowerCAmelCase     =			hidden_act
        lowerCAmelCase     =			hidden_dropout_prob
        lowerCAmelCase     =			attention_probs_dropout_prob
        lowerCAmelCase     =			max_position_embeddings
        lowerCAmelCase     =			type_vocab_size
        lowerCAmelCase     =			type_sequence_label_size
        lowerCAmelCase     =			initializer_range
        lowerCAmelCase     =			num_labels
        lowerCAmelCase     =			num_choices
        lowerCAmelCase     =			scope





     def 							__UpperCAmelCase      ( self       :      Optional[int]    )				->  Optional[Any]:
        lowerCAmelCase     =			ids_tensor([self.batch_size, self.seq_length]    ,      self.vocab_size    )

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

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

        lowerCAmelCase     =			self.get_config()

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





     def 							__UpperCAmelCase      ( self       :      List[Any]    )				->  int:
        lowerCAmelCase     =			EsmConfig(
            vocab_size=3_3    ,      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=UpperCAmelCase__    ,      esmfold_config={'trunk': {'num_blocks': 2}, 'fp16_esm': False}    ,      )
        return config





     def 							__UpperCAmelCase      ( self       :      Any    ,      UpperCAmelCase__       :      int    ,      UpperCAmelCase__       :      Union[str, Any]    ,      UpperCAmelCase__       :      List[str]    ,      UpperCAmelCase__       :      Tuple    ,      UpperCAmelCase__       :      Any    ,      UpperCAmelCase__       :      List[Any]    )				->  Tuple:
        lowerCAmelCase     =			EsmForProteinFolding(config=UpperCAmelCase__    ).float()
        model.to(UpperCAmelCase__    )
        model.eval()
        lowerCAmelCase     =			model(UpperCAmelCase__    ,      attention_mask=UpperCAmelCase__    )
        lowerCAmelCase     =			model(UpperCAmelCase__    )
        lowerCAmelCase     =			model(UpperCAmelCase__    )

        self.parent.assertEqual(result.positions.shape    ,      (8, self.batch_size, self.seq_length, 1_4, 3)    )
        self.parent.assertEqual(result.angles.shape    ,      (8, self.batch_size, self.seq_length, 7, 2)    )





     def 							__UpperCAmelCase      ( self       :      Dict    )				->  Any:
        lowerCAmelCase     =			self.prepare_config_and_inputs()
        (
            (
            lowerCAmelCase
        )     ,  (
            lowerCAmelCase
        )     ,  (
            lowerCAmelCase
        )     ,  (
            lowerCAmelCase
        )     ,  (
            lowerCAmelCase
        )     ,  (
            lowerCAmelCase
        )     ,  
        )     =			config_and_inputs
        lowerCAmelCase     =			{'input_ids': input_ids, 'attention_mask': input_mask}
        return config, inputs_dict




@require_torch
class 		UpperCAmelCase_      (  __lowercase       ,	__lowercase       ,	unittest.TestCase		):
     lowerCamelCase				:	str		=     False

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





     def 							__UpperCAmelCase      ( self       :      Optional[Any]    )				->  int:
        lowerCAmelCase     =			EsmFoldModelTester(self    )
        lowerCAmelCase     =			ConfigTester(self    ,      config_class=UpperCAmelCase__    ,      hidden_size=3_7    )





     def 							__UpperCAmelCase      ( self       :      Optional[Any]    )				->  Union[str, Any]:
        self.config_tester.run_common_tests()





     def 							__UpperCAmelCase      ( self       :      Optional[Any]    )				->  Any:
        lowerCAmelCase     =			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*UpperCAmelCase__    )





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





     @unittest.skip
     def 							__UpperCAmelCase      ( self       :      List[Any]    )				->  Tuple:
        pass





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





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





     @unittest.skip('ESMFold does not support passing input embeds!'    )
     def 							__UpperCAmelCase      ( self       :      int    )				->  Union[str, Any]:
        pass





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





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





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





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





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





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





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





     @unittest.skip('ESMFold only has one output format.'    )
     def 							__UpperCAmelCase      ( self       :      Dict    )				->  Union[str, Any]:
        pass





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





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





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





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





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





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





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





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




@require_torch
class 		UpperCAmelCase_      (  __lowercase		):





     @slow
     def 							__UpperCAmelCase      ( self       :      Optional[int]    )				->  Optional[Any]:
        lowerCAmelCase     =			EsmForProteinFolding.from_pretrained('facebook/esmfold_v1'    ).float()
        model.eval()
        lowerCAmelCase     =			torch.tensor([[0, 6, 4, 1_3, 5, 4, 1_6, 1_2, 1_1, 7, 2]]    )
        lowerCAmelCase     =			model(UpperCAmelCase__    )['positions']
        lowerCAmelCase     =			torch.tensor([2.5_828, 0.7_993, -10.9_334]    ,      dtype=torch.floataa    )
        self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]    ,      UpperCAmelCase__    ,      atol=1E-4    )    )









'''simple docstring'''




import multiprocessing
import time

from arguments import PretokenizationArguments
from datasets import load_dataset

from transformers import AutoTokenizer, HfArgumentParser





def 	a_					( lowerCamelCase	:     Dict				):
   lowerCAmelCase     =			{}
   lowerCAmelCase     =			tokenizer(example['content']	, truncation=lowerCamelCase				)['input_ids']
   lowerCAmelCase     =			len(example['content']				) / len(output['input_ids']				)
   return output


__snake_case    						=HfArgumentParser(PretokenizationArguments)
__snake_case    						=parser.parse_args()
if args.num_workers is None:
       __snake_case    						=multiprocessing.cpu_count()
__snake_case    						=AutoTokenizer.from_pretrained(args.tokenizer_dir)

__snake_case    						=time.time()
__snake_case    						=load_dataset(args.dataset_name, split="""train""")
print(F'''Dataset loaded in {time.time()-t_start:.2f}s''')

__snake_case    						=time.time()
__snake_case    						=ds.map(
    tokenize,
    num_proc=args.num_workers,
    remove_columns=[
        """repo_name""",
        """path""",
        """copies""",
        """size""",
        """content""",
        """license""",
        """hash""",
        """line_mean""",
        """line_max""",
        """alpha_frac""",
        """autogenerated""",
    ],
)
print(F'''Dataset tokenized in {time.time()-t_start:.2f}s''')

__snake_case    						=time.time()
ds.push_to_hub(args.tokenized_data_repo)




print(F'''Data pushed to the hub in {time.time()-t_start:.2f}s''')





