-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import multiprocess as mp | ||
import torch | ||
from loguru import logger | ||
|
||
|
||
def set_mp_start_method(method=None): | ||
if torch.cuda.is_available(): | ||
desired_method = 'spawn' | ||
else: | ||
desired_method = method or mp.get_start_method( | ||
allow_none=True) or 'fork' | ||
|
||
try: | ||
mp.set_start_method(desired_method, force=True) | ||
logger.info( | ||
f"Setting multiprocess start method to '{desired_method}'.") | ||
except RuntimeError as e: | ||
logger.error(f'Error setting multiprocess start method: {e}') | ||
|
||
|
||
def initialize(**kw_args): | ||
mp_start_method = kw_args.pop('mp_start_method', None) | ||
set_mp_start_method(mp_start_method) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters