MCPcopy
hub / github.com/FedML-AI/FedML / init

Function init

python/fedml/__init__.py:64–168  ·  view source on GitHub ↗
(args=None, check_env=True, should_init_logs=True)

Source from the content-addressed store, hash-verified

62
63
64def 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

Callers

nothing calls this directly

Calls 15

collect_envFunction · 0.90
get_env_versionFunction · 0.85
set_env_versionFunction · 0.85
_init_simulation_mpiFunction · 0.85
_init_simulation_spFunction · 0.85
_init_cross_deviceFunction · 0.85
_init_cross_cloudFunction · 0.85
_init_model_servingFunction · 0.85
_manage_profiling_argsFunction · 0.85

Tested by

no test coverage detected