(args=None, check_env=True, should_init_logs=True)
| 62 | |
| 63 | |
| 64 | def init(args=None, check_env=True, should_init_logs=True): |
| 65 | if args is None: |
| 66 | args = load_arguments(fedml._global_training_type, fedml._global_comm_backend) |
| 67 | |
| 68 | """Initialize FedML Engine.""" |
| 69 | # only when the env version is None, we refer to the python configuration arguments. |
| 70 | if get_env_version() is None: |
| 71 | if hasattr(args, "config_version") and args.config_version is not None: |
| 72 | set_env_version(args.config_version) |
| 73 | delattr(args, "config_version") |
| 74 | elif hasattr(args, "env_version") and args.env_version is not None: |
| 75 | set_env_version(args.env_version) |
| 76 | delattr(args, "env_version") |
| 77 | else: |
| 78 | set_env_version("release") |
| 79 | # after environment is set, only fedml.get_env_version() is used to get the environment version |
| 80 | |
| 81 | if check_env: |
| 82 | collect_env() |
| 83 | |
| 84 | if hasattr(args, "training_type"): |
| 85 | fedml._global_training_type = args.training_type |
| 86 | if hasattr(args, "backend"): |
| 87 | fedml._global_comm_backend = args.backend |
| 88 | |
| 89 | """ |
| 90 | # Windows/Linux/MacOS compatability issues on multi-processing |
| 91 | # https://github.com/pytorch/pytorch/issues/3492 |
| 92 | """ |
| 93 | if multiprocessing.get_start_method() != "spawn": |
| 94 | # force all platforms (Windows/Linux/MacOS) to use the same way (spawn) for multiprocessing |
| 95 | multiprocessing.set_start_method("spawn", force=True) |
| 96 | |
| 97 | """ |
| 98 | # https://stackoverflow.com/questions/53014306/error-15-initializing-libiomp5-dylib-but-found-libiomp5-dylib-already-initial |
| 99 | """ |
| 100 | os.environ["KMP_DUPLICATE_LIB_OK"] = "True" |
| 101 | |
| 102 | seed = args.random_seed if hasattr(args, "random_seed") else 0 |
| 103 | random.seed(seed) |
| 104 | np.random.seed(seed) |
| 105 | torch.manual_seed(seed) |
| 106 | torch.cuda.manual_seed_all(seed) |
| 107 | torch.backends.cudnn.deterministic = True |
| 108 | |
| 109 | mlops.pre_setup(args) |
| 110 | |
| 111 | if not hasattr(args, "training_type"): |
| 112 | setattr(args, "training_type", fedml._global_training_type) |
| 113 | |
| 114 | if not hasattr(args, "backend"): |
| 115 | setattr(args, "backend", fedml._global_comm_backend) |
| 116 | |
| 117 | if hasattr(args, "training_type"): |
| 118 | if args.training_type == FEDML_TRAINING_PLATFORM_SIMULATION and hasattr(args, |
| 119 | "backend") and args.backend == "MPI": |
| 120 | args = _init_simulation_mpi(args) |
| 121 |
nothing calls this directly
no test coverage detected