



"""simple docstring"""


import os
import random
import sys

from . import cryptomath_module as cryptoMath  # noqa: N812
from . import rabin_miller as rabinMiller  # noqa: N812

def 			_lowerCAmelCase				(       ):
						print('Making key files...'						)
						make_key_files('rsa'		,     1024						)
						print('Key files generation successful.'						)

def 			_lowerCAmelCase				(       lowercase_						):
						print('Generating prime p...'						)
						UpperCAmelCase					=			rabinMiller.generate_large_prime(_a						)
						print('Generating prime q...'						)
						UpperCAmelCase					=			rabinMiller.generate_large_prime(_a						)
						UpperCAmelCase					=			p * q

						print('Generating e that is relatively prime to (p - 1) * (q - 1)...'						)
						while True:
												UpperCAmelCase					=			random.randrange(2 ** (key_size - 1)		,     2 ** (key_size)						)
												if cryptoMath.gcd(_a		,     (p - 1) * (q - 1)						) == 1:
																		break

						print('Calculating d that is mod inverse of e...'						)
						UpperCAmelCase					=			cryptoMath.find_mod_inverse(_a		,     (p - 1) * (q - 1)						)

						UpperCAmelCase					=			(n, e)
						UpperCAmelCase					=			(n, d)
						return (public_key, private_key)

def 			_lowerCAmelCase				(       lowercase_		,     lowercase_						):






						if os.path.exists(F"""{name}_pubkey.txt"""						) or os.path.exists(F"""{name}_privkey.txt"""						):
												print('\nWARNING:'						)
												print(
												    F"""\"{name}_pubkey.txt\" or \"{name}_privkey.txt\" already exists. \n"""
												    'Use a different name or delete these files and re-run this program.'						)
												sys.exit()

						UpperCAmelCase				,   UpperCAmelCase					=			generate_key(_a						)
						print(F"""\nWriting public key to file {name}_pubkey.txt..."""						)
						with open(F"""{name}_pubkey.txt"""		,     'w'						) as out_file:
												out_file.write(F"""{key_size},{public_key[0]},{public_key[1]}"""						)

						print(F"""Writing private key to file {name}_privkey.txt..."""						)
						with open(F"""{name}_privkey.txt"""		,     'w'						) as out_file:
												out_file.write(F"""{key_size},{private_key[0]},{private_key[1]}"""						)


if __name__ == "__main__":
				main()










"""simple docstring"""


import operator as op


snake_case_    					=	"""scaler.pt"""
snake_case_    					=	"""pytorch_model"""
snake_case_    					=	"""random_states"""
snake_case_    					=	"""optimizer"""
snake_case_    					=	"""scheduler"""
snake_case_    					=	"""pytorch_model.bin"""
snake_case_    					=	"""pytorch_model.bin.index.json"""
snake_case_    					=	"""model.safetensors"""
snake_case_    					=	"""model.safetensors.index.json"""
snake_case_    					=	"""1.10.2"""
snake_case_    					=	"""py38"""
snake_case_    					=	"""4.17.0"""
snake_case_    					=	["""ml.p3.16xlarge""", """ml.p3dn.24xlarge""", """ml.p4dn.24xlarge"""]
snake_case_    					=	["""FULL_SHARD""", """SHARD_GRAD_OP""", """NO_SHARD""", """HYBRID_SHARD""", """HYBRID_SHARD_ZERO2"""]
snake_case_    					=	["""TRANSFORMER_BASED_WRAP""", """SIZE_BASED_WRAP""", """NO_WRAP"""]
snake_case_    					=	["""BACKWARD_PRE""", """BACKWARD_POST""", """NO_PREFETCH"""]
snake_case_    					=	["""FULL_STATE_DICT""", """LOCAL_STATE_DICT""", """SHARDED_STATE_DICT"""]
snake_case_    					=	"""2.0.1"""
snake_case_    					=	["""pdsh""", """standard""", """openmpi""", """mvapich"""]
snake_case_    					=	["""default""", """reduce-overhead""", """max-autotune"""]

snake_case_    					=	{""">""": op.gt, """>=""": op.ge, """==""": op.eq, """!=""": op.ne, """<=""": op.le, """<""": op.lt}

# These are the args for `torch.distributed.launch` for pytorch < 1.9
snake_case_    					=	[
    """nnodes""",
    """nproc_per_node""",
    """rdzv_backend""",
    """rdzv_endpoint""",
    """rdzv_id""",
    """rdzv_conf""",
    """standalone""",
    """max_restarts""",
    """monitor_interval""",
    """start_method""",
    """role""",
    """module""",
    """m""",
    """no_python""",
    """run_path""",
    """log_dir""",
    """r""",
    """redirects""",
    """t""",
    """tee""",
    """node_rank""",
    """master_addr""",
    """master_port""",
]

snake_case_    					=	["""DEEPSPEED""", """MULTI_GPU""", """FSDP""", """MEGATRON_LM"""]
snake_case_    					=	["""DEEPSPEED""", """MULTI_XPU""", """FSDP"""]





