Skip to content

Commit

Permalink
Speed up subprocess launch (#15738)
Browse files Browse the repository at this point in the history
  • Loading branch information
awaelchli committed Nov 21, 2022
1 parent 8306797 commit ec7acb5
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 16 deletions.
7 changes: 0 additions & 7 deletions src/lightning_lite/strategies/launchers/subprocess_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
import os
import subprocess
import sys
from time import sleep
from typing import Any, Callable, Sequence

import numpy as np
from lightning_utilities.core.imports import RequirementCache

from lightning_lite.plugins.environments.cluster_environment import ClusterEnvironment
Expand Down Expand Up @@ -126,11 +124,6 @@ def _call_children_scripts(self) -> None:
command = _basic_subprocess_cmd()
subprocess.Popen(command, env=env_copy)

# starting all processes at once can cause issues
# with dataloaders delay between 1-10 seconds
delay = np.random.uniform(1, 5, 1)[0]
sleep(delay)

def _check_can_spawn_children(self) -> None:
if self.cluster_environment.local_rank() != 0:
raise RuntimeError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
# limitations under the License.
import os
import subprocess
from time import sleep
from typing import Any, Callable, Optional

import numpy as np
from lightning_utilities.core.imports import RequirementCache

import pytorch_lightning as pl
Expand Down Expand Up @@ -123,11 +121,6 @@ def _call_children_scripts(self) -> None:

subprocess.Popen(command, env=env_copy)

# starting all processes at once can cause issues
# with dataloaders delay between 1-10 seconds
delay = np.random.uniform(1, 5, 1)[0]
sleep(delay)

def _check_can_spawn_children(self) -> None:
if self.cluster_environment.local_rank() != 0:
raise RuntimeError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ def test_subprocess_script_launcher_external_processes(popen_mock):
popen_mock.assert_not_called()


@mock.patch("lightning_lite.strategies.launchers.subprocess_script.sleep")
@mock.patch("lightning_lite.strategies.launchers.subprocess_script.subprocess.Popen")
def test_subprocess_script_launcher_launch_processes(popen_mock, _):
def test_subprocess_script_launcher_launch_processes(popen_mock):
cluster_env = Mock()
cluster_env.creates_processes_externally = False
cluster_env.local_rank.return_value = 0
Expand Down

0 comments on commit ec7acb5

Please sign in to comment.