Skip to content

Commit 34f03fc

Browse files
authored
fix: set multiprocessing start method to 'fork' in pt env (since python3.14 defaults to forkserver) (#5019)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Enhanced platform-specific multiprocessing initialization with improved logging for better diagnostics. * Streamlined module logging setup to reduce code redundancy. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 1ee33c8 commit 34f03fc

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

deepmd/pt/utils/env.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import multiprocessing
44
import os
5+
import sys
56

67
import numpy as np
78
import torch
@@ -16,6 +17,17 @@
1617
set_default_nthreads,
1718
)
1819

20+
log = logging.getLogger(__name__)
21+
22+
if sys.platform != "win32":
23+
try:
24+
multiprocessing.set_start_method("fork", force=True)
25+
log.debug("Successfully set multiprocessing start method to 'fork'.")
26+
except (RuntimeError, ValueError) as err:
27+
log.warning(f"Could not set multiprocessing start method: {err}")
28+
else:
29+
log.debug("Skipping fork start method on Windows (not supported).")
30+
1931
SAMPLER_RECORD = os.environ.get("SAMPLER_RECORD", False)
2032
DP_DTYPE_PROMOTION_STRICT = os.environ.get("DP_DTYPE_PROMOTION_STRICT", "0") == "1"
2133
try:
@@ -26,7 +38,6 @@
2638
NUM_WORKERS = int(os.environ.get("NUM_WORKERS", min(4, ncpus)))
2739
if multiprocessing.get_start_method() != "fork":
2840
# spawn or forkserver does not support NUM_WORKERS > 0 for DataLoader
29-
log = logging.getLogger(__name__)
3041
log.warning(
3142
"NUM_WORKERS > 0 is not supported with spawn or forkserver start method. "
3243
"Setting NUM_WORKERS to 0."

0 commit comments

Comments
 (0)