|
1 | 1 | import logging |
| 2 | +import platform |
2 | 3 |
|
3 | 4 | import multiprocess as multiprocessing |
4 | 5 | import os |
@@ -92,13 +93,7 @@ def init(args=None, check_env=True, should_init_logs=True): |
92 | 93 | # Windows/Linux/MacOS compatability issues on multi-processing |
93 | 94 | # https://github.com/pytorch/pytorch/issues/3492 |
94 | 95 | """ |
95 | | - if multiprocessing.get_start_method() != "fork": |
96 | | - # force all platforms (Windows/Linux/macOS) to use the same way (fork) for multiprocessing |
97 | | - multiprocessing.set_start_method("fork", force=True) |
98 | | - |
99 | | - # if multiprocessing.get_start_method() != "spawn": |
100 | | - # # force all platforms (Windows/Linux/MacOS) to use the same way (spawn) for multiprocessing |
101 | | - # multiprocessing.set_start_method("spawn", force=True) |
| 96 | + _init_multiprocessing() |
102 | 97 |
|
103 | 98 | """ |
104 | 99 | # https://stackoverflow.com/questions/53014306/error-15-initializing-libiomp5-dylib-but-found-libiomp5-dylib-already-initial |
@@ -450,6 +445,21 @@ def _run_distributed(): |
450 | 445 | pass |
451 | 446 |
|
452 | 447 |
|
| 448 | +def _init_multiprocessing(): |
| 449 | + """ |
| 450 | + # Windows/Linux/MacOS compatability issues on multi-processing |
| 451 | + # https://github.com/pytorch/pytorch/issues/3492 |
| 452 | + """ |
| 453 | + if platform.system() == "Windows": |
| 454 | + if multiprocessing.get_start_method() != "spawn": |
| 455 | + # force all platforms (Windows/Linux/macOS) to use the same way (spawn) for multiprocessing |
| 456 | + multiprocessing.set_start_method("spawn", force=True) |
| 457 | + else: |
| 458 | + if multiprocessing.get_start_method() != "fork": |
| 459 | + # force all platforms (Windows/Linux/macOS) to use the same way (fork) for multiprocessing |
| 460 | + multiprocessing.set_start_method("fork", force=True) |
| 461 | + |
| 462 | + |
453 | 463 | def set_env_version(version): |
454 | 464 | set_env_kv("FEDML_ENV_VERSION", version) |
455 | 465 | load_env() |
|
0 commit comments