mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Remove NO_MULTIPROCESSING_SPAWN checks (#146705)
py 3.9 has spawn. Pull Request resolved: https://github.com/pytorch/pytorch/pull/146705 Approved by: https://github.com/colesbury
This commit is contained in:
committed by
PyTorch MergeBot
parent
2978771c9d
commit
40ad5e01df
@ -28,7 +28,6 @@ from torch.testing._internal.common_utils import (
|
||||
IS_SANDCASTLE,
|
||||
IS_WINDOWS,
|
||||
load_tests,
|
||||
NO_MULTIPROCESSING_SPAWN,
|
||||
parametrize,
|
||||
run_tests,
|
||||
skipIfNoDill,
|
||||
@ -101,21 +100,20 @@ TEST_CUDA_IPC = (
|
||||
|
||||
TEST_MULTIGPU = TEST_CUDA_IPC and torch.cuda.device_count() > 1
|
||||
|
||||
if not NO_MULTIPROCESSING_SPAWN:
|
||||
# We want to use `spawn` if able because some of our tests check that the
|
||||
# data loader terminiates gracefully. To prevent hanging in the testing
|
||||
# process, such data loaders are run in a separate subprocess.
|
||||
#
|
||||
# We also want to test the `pin_memory=True` configuration, thus `spawn` is
|
||||
# required to launch such processes and they initialize the CUDA context.
|
||||
#
|
||||
# Mixing different start method is a recipe for disaster (e.g., using a fork
|
||||
# `mp.Event` with a spawn `mp.Process` segfaults). So we set this globally
|
||||
# to avoid bugs.
|
||||
#
|
||||
# Get a multiprocessing context because some test / third party library will
|
||||
# set start_method when imported, and setting again triggers `RuntimeError`.
|
||||
mp = mp.get_context(method="spawn")
|
||||
# We want to use `spawn` if able because some of our tests check that the
|
||||
# data loader terminates gracefully. To prevent hanging in the testing
|
||||
# process, such data loaders are run in a separate subprocess.
|
||||
#
|
||||
# We also want to test the `pin_memory=True` configuration, thus `spawn` is
|
||||
# required to launch such processes and they initialize the CUDA context.
|
||||
#
|
||||
# Mixing different start method is a recipe for disaster (e.g., using a fork
|
||||
# `mp.Event` with a spawn `mp.Process` segfaults). So we set this globally
|
||||
# to avoid bugs.
|
||||
#
|
||||
# Get a multiprocessing context because some test / third party library will
|
||||
# set start_method when imported, and setting again triggers `RuntimeError`.
|
||||
mp = mp.get_context(method="spawn")
|
||||
|
||||
|
||||
# 60s of timeout?
|
||||
@ -1430,7 +1428,7 @@ except RuntimeError as e:
|
||||
p.terminate()
|
||||
|
||||
def test_timeout(self):
|
||||
if TEST_CUDA and not NO_MULTIPROCESSING_SPAWN:
|
||||
if TEST_CUDA:
|
||||
# This test runs in a subprocess, which can only initialize CUDA with spawn.
|
||||
# _test_timeout_pin_memory with pin_memory=True initializes CUDA when the iterator is
|
||||
# constructed.
|
||||
@ -2313,8 +2311,7 @@ except RuntimeError as e:
|
||||
def test_sampler(self):
|
||||
self._test_sampler()
|
||||
self._test_sampler(num_workers=4)
|
||||
if not NO_MULTIPROCESSING_SPAWN:
|
||||
self._test_batch_sampler(num_workers=4, multiprocessing_context="spawn")
|
||||
self._test_batch_sampler(num_workers=4, multiprocessing_context="spawn")
|
||||
|
||||
def _test_batch_sampler(self, **kwargs):
|
||||
# [(0, 1), (2, 3, 4), (5, 6), (7, 8, 9), ...]
|
||||
@ -2338,8 +2335,7 @@ except RuntimeError as e:
|
||||
def test_batch_sampler(self):
|
||||
self._test_batch_sampler()
|
||||
self._test_batch_sampler(num_workers=4)
|
||||
if not NO_MULTIPROCESSING_SPAWN:
|
||||
self._test_batch_sampler(num_workers=4, multiprocessing_context="spawn")
|
||||
self._test_batch_sampler(num_workers=4, multiprocessing_context="spawn")
|
||||
|
||||
@unittest.skipIf(not TEST_CUDA, "CUDA unavailable")
|
||||
def test_shuffle_pin_memory(self):
|
||||
@ -2496,7 +2492,7 @@ except RuntimeError as e:
|
||||
# not be called before process end. It is important to see that the
|
||||
# processes still exit in both cases.
|
||||
|
||||
if pin_memory and (not TEST_CUDA or NO_MULTIPROCESSING_SPAWN or IS_WINDOWS):
|
||||
if pin_memory and (not TEST_CUDA or IS_WINDOWS):
|
||||
# This test runs in a subprocess, which can only initialize CUDA with spawn.
|
||||
# DataLoader with pin_memory=True initializes CUDA when its iterator is constructed.
|
||||
# For windows, pin_memory sometimes causes CUDA oom.
|
||||
|
Reference in New Issue
Block a user