



import argparse

import torch

from transformers import RemBertConfig, RemBertModel, load_tf_weights_in_rembert
from transformers.utils import logging


logging.set_verbosity_info()






def 	_lowerCAmelCase						(				__lowerCamelCase   :     str		,	__lowerCamelCase   :     List[str]		,	__lowerCamelCase   :     List[Any]     ):



 """simple docstring"""





 __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	RemBertConfig.from_json_file(__lowerCamelCase     )
 print("Building PyTorch model from configuration: {}".format(str(__lowerCamelCase     )     )     )
 __SCREAMING_SNAKE_CASE       :    Dict       =	RemBertModel(__lowerCamelCase     )

 # Load weights from tf checkpoint
 load_tf_weights_in_rembert(__lowerCamelCase		,	__lowerCamelCase		,	__lowerCamelCase     )

 # Save pytorch-model
 print("Save PyTorch model to {}".format(__lowerCamelCase     )     )
 torch.save(model.state_dict()		,	__lowerCamelCase     )


if __name__ == "__main__":
      _lowerCamelCase						    =  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(
          """--rembert_config_file""",
          default=None,
          type=str,
          required=True,
          help=(
              """The config json file corresponding to the pre-trained RemBERT model. \n"""
              """This specifies the model architecture."""
          ),
      )
      parser.add_argument(
          """--pytorch_dump_path""", default=None, type=str, required=True, help="""Path to the output PyTorch model."""
      )
      _lowerCamelCase						    =  parser.parse_args()
      convert_rembert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.rembert_config_file, args.pytorch_dump_path)











import inspect
import os
import unittest

import torch

import accelerate
from accelerate import debug_launcher
from accelerate.test_utils import (
    execute_subprocess_async,
    require_cpu,
    require_huggingface_suite,
    require_multi_gpu,
    require_single_gpu,
)
from accelerate.utils import patch_environment

@require_huggingface_suite
class       _SCREAMING_SNAKE_CASE	(unittest.TestCase ):





     def 	__snake_case    (       self :							Optional[Any]				)->Union[str, Any]:
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	inspect.getfile(accelerate.test_utils				)
      __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	os.path.sep.join(
          mod_file.split(os.path.sep				)[:-1] + ["scripts", "external_deps", "test_metrics.py"]				)

      from accelerate.test_utils.scripts.external_deps import test_metrics  # noqa: F401

      __SCREAMING_SNAKE_CASE       :    Tuple       =	test_metrics





     @require_cpu
     def 	__snake_case    (       self :							Union[str, Any]				)->List[Any]:
      debug_launcher(self.test_metrics.main     ,  num_processes=1				)





     @require_cpu
     def 	__snake_case    (       self :							str				)->List[str]:
      debug_launcher(self.test_metrics.main				)





     @require_single_gpu
     def 	__snake_case    (       self :							Union[str, Any]				)->str:
      self.test_metrics.main()






     @require_multi_gpu
     def 	__snake_case    (       self :							List[str]				)->int:
      print(F"""Found {torch.cuda.device_count()} devices."""				)
      __SCREAMING_SNAKE_CASE       :    Any       =	["torchrun", F"""--nproc_per_node={torch.cuda.device_count()}""", self.test_file_path]
      with patch_environment(omp_num_threads=1				):
       execute_subprocess_async(UpperCamelCase     ,  env=os.environ.copy()				)






