


'''simple docstring'''






import argparse

from ...utils.dataclasses import (
    ComputeEnvironment,
    DistributedType,
    DynamoBackend,
    PrecisionType,
    SageMakerDistributedType,
)
from ..menu import BulletMenu


a_					:    Union[str, Any]          =    [
    """EAGER""",
    """AOT_EAGER""",
    """INDUCTOR""",
    """NVFUSER""",
    """AOT_NVFUSER""",
    """AOT_CUDAGRAPHS""",
    """OFI""",
    """FX2TRT""",
    """ONNXRT""",
    """IPEX""",
]






def 	_A				(lowerCAmelCase__				,						lowerCAmelCase__=None				,						lowerCAmelCase__=None				,						lowerCAmelCase__=None		)   ->  Any:




     '''simple docstring'''



     _a			      =							True
     while ask_again:
          _a			      =							input(lowerCAmelCase__		)
          try:
               if default is not None and len(lowerCAmelCase__		) == 0:
                    return default
               return convert_value(lowerCAmelCase__		) if convert_value is not None else result
          except Exception:
               if error_message is not None:
                    print(lowerCAmelCase__		)






def 	_A				(lowerCAmelCase__				,						lowerCAmelCase__=[]				,						lowerCAmelCase__=None				,						lowerCAmelCase__=0		)   ->  str:




     '''simple docstring'''



     _a			      =							BulletMenu(lowerCAmelCase__				,						lowerCAmelCase__		)
     _a			      =							menu.run(default_choice=lowerCAmelCase__		)
     return convert_value(lowerCAmelCase__		) if convert_value is not None else result






def 	_A				(lowerCAmelCase__		)   ->  Optional[int]:




     '''simple docstring'''



     _a			      =							int(lowerCAmelCase__		)
     return ComputeEnvironment(['LOCAL_MACHINE', 'AMAZON_SAGEMAKER'][value]		)






def 	_A				(lowerCAmelCase__		)   ->  Optional[Any]:




     '''simple docstring'''



     _a			      =							int(lowerCAmelCase__		)
     return DistributedType(['NO', 'MULTI_CPU', 'MULTI_XPU', 'MULTI_GPU', 'MULTI_NPU', 'TPU'][value]		)






def 	_A				(lowerCAmelCase__		)   ->  Union[str, Any]:




     '''simple docstring'''



     _a			      =							int(lowerCAmelCase__		)
     return DynamoBackend(DYNAMO_BACKENDS[value]		).value






def 	_A				(lowerCAmelCase__		)   ->  List[Any]:




     '''simple docstring'''



     _a			      =							int(lowerCAmelCase__		)
     return PrecisionType(['no', 'fp16', 'bf16', 'fp8'][value]		)






def 	_A				(lowerCAmelCase__		)   ->  Any:




     '''simple docstring'''



     _a			      =							int(lowerCAmelCase__		)
     return SageMakerDistributedType(['NO', 'DATA_PARALLEL', 'MODEL_PARALLEL'][value]		)






def 	_A				(lowerCAmelCase__		)   ->  Optional[int]:




     '''simple docstring'''



     return {"yes": True, "no": False}[value.lower()]






class  a     (     argparse.RawDescriptionHelpFormatter       ):
 def 							__UpperCAmelCase		( self      ,				__magic_name__      ,				__magic_name__      ,				__magic_name__      ,				__magic_name__						)					->							int:
      _a			      =							super()._format_usage(__magic_name__      ,				__magic_name__      ,				__magic_name__      ,				__magic_name__						)
      _a			      =							usage.replace('<command> [<args>] '      ,				''						)
      return usage





'''simple docstring'''






import argparse

import torch

from transformers import BertConfig, BertForPreTraining, load_tf_weights_in_bert
from transformers.utils import logging


logging.set_verbosity_info()






def 	_A				(lowerCAmelCase__  :str				,						lowerCAmelCase__  :int				,						lowerCAmelCase__  :Any		)   ->  str:




     '''simple docstring'''



     _a			      =							BertConfig.from_json_file(lowerCAmelCase__		)
     print(f'Building PyTorch model from configuration: {config}'		)
     _a			      =							BertForPreTraining(lowerCAmelCase__		)

     # Load weights from tf checkpoint
     load_tf_weights_in_bert(lowerCAmelCase__				,						lowerCAmelCase__				,						lowerCAmelCase__		)

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


if __name__ == "__main__":
 a_					:    Optional[int]          =    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(
     "--bert_config_file",
     default=None,
     type=str,
     required=True,
     help=(
         "The config json file corresponding to the pre-trained BERT 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."
 )
 a_					:    Optional[int]          =    parser.parse_args()
 convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.bert_config_file, args.pytorch_dump_path)

