Skip to content

Commit

Permalink
Correct CWD for ddp subprocesses when using Hydra (#2719)
Browse files Browse the repository at this point in the history
* when hydra is enabled, set the cwd of subprocesses to the original cwd for ddp

* move imports up

* clean up imports
  • Loading branch information
yukw777 committed Jul 28, 2020
1 parent db9f11d commit b7f613b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pytorch_lightning/trainer/distrib_data_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ def train_fx(trial_hparams, cluster_manager, _):


try:
from hydra.utils import to_absolute_path
from hydra.utils import to_absolute_path, get_original_cwd
from hydra.core.hydra_config import HydraConfig
except ImportError:
HYDRA_AVAILABLE = False
else:
Expand Down Expand Up @@ -464,7 +465,12 @@ def spawn_ddp_children(self, model):
env_copy['LOCAL_RANK'] = f'{local_rank}'

# start process
proc = subprocess.Popen(command, env=env_copy)
# if hydra is available and initialized, make sure to set the cwd correctly
cwd: Optional[str] = None
if HYDRA_AVAILABLE:
if HydraConfig.initialized():
cwd = get_original_cwd()
proc = subprocess.Popen(command, env=env_copy, cwd=cwd)
self.interactive_ddp_procs.append(proc)

# starting all processes at once can cause issues
Expand Down

0 comments on commit b7f613b

Please sign in to comment.