Speed up subprocess launch (#15738)

This commit is contained in:
Adrian Wälchli 2022-11-21 12:19:47 +01:00 committed by GitHub
parent 83067977af
commit ec7acb5ae5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 1 additions and 16 deletions

View File

@ -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
@ -126,11 +124,6 @@ class _SubprocessScriptLauncher(_Launcher):
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(

View File

@ -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
@ -123,11 +121,6 @@ class _SubprocessScriptLauncher(_Launcher):
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(

View File

@ -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