8000 Remove NO_MULTIPROCESSING_SPAWN checks (#146705) · pytorch/pytorch@40ad5e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 40ad5e0

Browse files
cyyeverpytorchmergebot
authored andcommitted
Remove NO_MULTIPROCESSING_SPAWN checks (#146705)
py 3.9 has spawn. Pull Request resolved: #146705 Approved by: https://github.com/colesbury
1 parent 2978771 commit 40ad5e0

File tree

11 files changed

+24
-157
lines changed

11 files changed

+24
-157
lines changed

test/distributed/algorithms/quantization/test_quantization.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
skip_if_rocm_multiprocess,
1818
)
1919
from torch.testing._internal.common_utils import (
20-
NO_MULTIPROCESSING_SPAWN,
2120
run_tests,
2221
skip_but_pass_in_sandcastle_if,
2322
TEST_WITH_DEV_DBG_ASAN,
@@ -47,10 +46,6 @@ def _build_tensor(size, value=None, dtype=torch.float, device_id=None):
4746
)
4847
sys.exit(0)
4948

50-
if NO_MULTIPROCESSING_SPAWN:
51-
print("Spawn not available, skipping tests.", file=sys.stderr)
52-
sys.exit(0)
53-
5449
BACKEND = os.environ["BACKEND"]
5550
if BACKEND == "gloo" or BACKEND == "nccl":
5651

test/distributed/elastic/multiprocessing/api_test.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
IS_CI,
3838
IS_MACOS,
3939
IS_WINDOWS,
40-
NO_MULTIPROCESSING_SPAWN,
4140
run_tests,
4241
skip_but_pass_in_sandcastle_if,
4342
skip_if_pytest,
@@ -509,11 +508,6 @@ def test_wait_for_all_child_procs_to_exit(self):
509508
mpc._poll()
510509
self.assertEqual(4, mock_join.call_count)
511510

512-
@skip_but_pass_in_sandcastle_if(
513-
NO_MULTIPROCESSING_SPAWN,
514-
"Disabled for environments that \
515-
don't support multiprocessing with spawn start method",
516-
)
517511
def test_multiprocessing_context_poll_raises_exception(self):
518512
mp_context = MultiprocessContext(
519513
name="test_mp",

test/distributed/test_c10d_spawn.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import torch.distributed as c10d
99
import torch.multiprocessing as mp
1010
from torch.testing._internal.common_distributed import MultiProcessTestCase
11-
from torch.testing._internal.common_utils import load_tests, NO_MULTIPROCESSING_SPAWN
11+
from torch.testing._internal.common_utils import load_tests
1212

1313

1414
# Torch distributed.nn is not available in windows
@@ -27,10 +27,6 @@
2727
print("c10d not available, skipping tests", file=sys.stderr)
2828
sys.exit(0)
2929

30-
if NO_MULTIPROCESSING_SPAWN:
31-
print("spawn not available, skipping tests", file=sys.stderr)
32-
sys.exit(0)
33-
3430

3531
class AbstractProcessGroupShareTensorTest:
3632
world_size = 2

test/distributed/test_distributed_spawn.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313
print("Distributed not available, skipping tests", file=sys.stderr)
1414
sys.exit(0)
1515

16-
from torch.testing._internal.common_utils import (
17-
NO_MULTIPROCESSING_SPAWN,
18-
run_tests,
19-
TEST_WITH_DEV_DBG_ASAN,
20-
)
16+
from torch.testing._internal.common_utils import run_tests, TEST_WITH_DEV_DBG_ASAN
2117
from torch.testing._internal.distributed.distributed_test import (
2218
DistributedTest,
2319
TestDistBackend,
@@ -31,10 +27,6 @@
3127
)
3228
sys.exit(0)
3329

34-
if NO_MULTIPROCESSING_SPAWN:
35-
print("Spawn not available, skipping tests.", file=sys.stderr)
36-
sys.exit(0)
37-
3830
_allowed_backends = ("gloo", "nccl", "ucc")
3931
if (
4032
"BACKEND" not in os.environ

test/test_cuda.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@
5959
IS_LINUX,
6060
IS_SANDCASTLE,
6161
IS_WINDOWS,
62-
load_tests,
63-
NO_MULTIPROCESSING_SPAWN,
62+
load_tests,
6463
parametrize,
6564
run_tests,
6665
serialTest,
@@ -1088,11 +1087,6 @@ def _spawn_test_multinomial_invalid_probs_cuda(self, probs):
10881087

10891088
@slowTest
10901089
@unittest.skipIf(TEST_WITH_ROCM, "ROCm doesn't support device side asserts")
1091-
@unittest.skipIf(
1092-
NO_MULTIPROCESSING_SPAWN,
1093-
"Disabled for environments that \
1094-
don't support multiprocessing with spawn start method",
1095-
)
10961090
def test_multinomial_invalid_probs_cuda(self):
10971091
self._spawn_test_multinomial_invalid_probs_cuda([1.0, -1.0, 1.0])
10981092
self._spawn_test_multinomial_invalid_probs_cuda([1.0, inf, 1.0])
@@ -1121,11 +1115,6 @@ def _test_index_bounds_cuda(idx):
11211115
return err
11221116

11231117
@slowTest
1124-
@unittest.skipIf(
1125-
NO_MULTIPROCESSING_SPAWN,
1126-
"Disabled for environments that \
1127-
don't support multiprocessing with spawn start method",
1128-
)
11291118
@skipIfRocm
11301119
def test_index_out_of_bounds_exception_cuda(self):
11311120
test_method = TestCuda._test_index_bounds_cuda

test/test_dataloader.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
IS_SANDCASTLE,
2929
IS_WINDOWS,
3030
load_tests,
31-
NO_MULTIPROCESSING_SPAWN,
3231
parametrize,
3332
run_tests,
3433
skipIfNoDill,
@@ -101,21 +100,20 @@
101100

102101
TEST_MULTIGPU = TEST_CUDA_IPC and torch.cuda.device_count() > 1
103102

104-
if not NO_MULTIPROCESSING_SPAWN:
105-
# We want to use `spawn` if able because some of our tests check that the
106-
# data loader terminiates gracefully. To prevent hanging in the testing
107-
# process, such data loaders are run in a separate subprocess.
108-
#
109-
# We also want to test the `pin_memory=True` configuration, thus `spawn` is
110-
# required to launch such processes and they initialize the CUDA context.
111-
#
112-
# Mixing different start method is a recipe for disaster (e.g., using a fork
113-
# `mp.Event` with a spawn `mp.Process` segfaults). So we set this globally
114-
# to avoid bugs.
115-
#
116-
# Get a multiprocessing context because some test / third party library will
117-
# set start_method when imported, and setting again triggers `RuntimeError`.
118-
mp = mp.get_context(method="spawn")
103+
# We want to use `spawn` if able because some of our tests check that the
104+
# data loader terminates gracefully. To prevent hanging in the testing
105+
# process, such data loaders are run in a separate subprocess.
106+
#
107+
# We also want to test the `pin_memory=True` configuration, thus `spawn` is
108+
# required to launch such processes and they initialize the CUDA context.
109+
#
110+
# Mixing different start method is a recipe for disaster (e.g., using a fork
111+
# `mp.Event` with a spawn `mp.Process` segfaults). So we set this globally
112+
# to avoid bugs.
113+
#
114+
# Get a multiprocessing context because some test / third party library will
115+
# set start_method when imported, and setting again triggers `RuntimeError`.
116+
mp = mp.get_context(method="spawn")
119117

120118

121119
# 60s of timeout?
@@ -1430,7 +1428,7 @@ def test_no_segfault(self):
14301428
p.terminate()
14311429

14321430
def test_timeout(self):
1433-
if TEST_CUDA and not NO_MULTIPROCESSING_SPAWN:
1431+
if TEST_CUDA:
14341432
# This test runs in a subprocess, which can only initialize CUDA with spawn.
14351433
# _test_timeout_pin_memory with pin_memory=True initializes CUDA when the iterator is
14361434
# constructed.
@@ -2313,8 +2311,7 @@ def _test_sampler(self, **kwargs):
23132311
def test_sampler(self):
23142312
self._test_sampler()
23152313
self._test_sampler(num_workers=4)
2316-
if not NO_MULTIPROCESSING_SPAWN:
2317-
self._test_batch_sampler(num_workers=4, multiprocessing_context="spawn")
2314+
self._test_batch_sampler(num_workers=4, multiprocessing_context="spawn")
23182315

23192316
def _test_batch_sampler(self, **kwargs):
23202317
# [(0, 1), (2, 3, 4), (5, 6), (7, 8, 9), ...]
@@ -2338,8 +2335,7 @@ def _test_batch_sampler(self, **kwargs):
23382335
def test_batch_sampler(self):
23392336
self._test_batch_sampler()
23402337
self._test_batch_sampler(num_workers=4)
2341-
if not NO_MULTIPROCESSING_SPAWN:
2342-
self._test_batch_sampler(num_workers=4, multiprocessing_context="spawn")
2338+
self._test_batch_sampler(num_workers=4, multiprocessing_context="spawn")
23432339

23442340
@unittest.skipIf(not TEST_CUDA, "CUDA unavailable")
23452341
def test_shuffle_pin_memory(self):
@@ -2496,7 +2492,7 @@ def test_proper_exit(self):
24962492
# not be called before process end. It is important to see that the
24972493
# processes still exit in both cases.
24982494

2499-
if pin_memory and (not TEST_CUDA or NO_MULTIPROCESSING_SPAWN or IS_WINDOWS):
2495+
if pin_memory and (not TEST_CUDA or IS_WINDOWS):
25002496
# This test runs in a subprocess, which can only initialize CUDA with spawn.
25012497
# DataLoader with pin_memory=True initializes CUDA when its iterator is constructed.
25022498
# For windows, pin_memory sometimes causes CUDA oom.

test/test_multiprocessing.py

Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
IS_MACOS,
2020
IS_WINDOWS,
2121
load_tests,
22-
NO_MULTIPROCESSING_SPAWN,
2322
run_tests,
2423
slowTest,
2524
TEST_WITH_ASAN,
@@ -471,30 +470,17 @@ def test_autograd_errors(self):
471470
with ctx.Pool(3) as pool:
472471
pool.map(simple_autograd_function, [1, 2, 3])
473472

474-
@unittest.skipIf(
475-
NO_MULTIPROCESSING_SPAWN, "Test needs to use spawn multiprocessing"
476-
)
477473
def test_autograd_fine_with_spawn(self):
478474
ctx = mp.get_context("spawn")
479475
simple_autograd_function()
480476
with ctx.Pool(3) as pool:
481477
pool.map(simple_autograd_function, [1, 2, 3])
482478

483-
@unittest.skipIf(
484-
NO_MULTIPROCESSING_SPAWN,
485-
"Disabled for environments that \
486-
don't support multiprocessing with spawn start method",
487-
)
488479
@unittest.skipIf(not TEST_CUDA_IPC, "CUDA IPC not available")
489480
def test_cuda_simple(self):
490481
torch.cuda.FloatTensor([1]) # initialize CUDA outside of leak checker
491482
self._test_sharing(mp.get_context("spawn"), "cuda", torch.float)
492483

493-
@unittest.skipIf(
494-
NO_MULTIPROCESSING_SPAWN,
495-
"Disabled for environments that \
496-
don't support multiprocessing with spawn start method",
497-
)
498484
@unittest.skipIf(not TEST_CUDA_IPC, "CUDA IPC not available")
499485
def test_cuda_memory_allocation(self):
500486
ctx = mp.get_context("spawn")
@@ -512,11 +498,6 @@ def test_cuda_memory_allocation(self):
512498
e.set()
513499
p.join(1)
514500

515-
@unittest.skipIf(
516-
NO_MULTIPROCESSING_SPAWN,
517-
"Disabled for environments that \
518-
don't support multiprocessing with spawn start method",
519-
)
520501
@unittest.skipIf(not TEST_CUDA_IPC, "CUDA IPC not available")
521502
def test_cuda_ipc_deadlock(self):
522503
ctx = mp.get_context("spawn")
@@ -536,11 +517,6 @@ def test_cuda_ipc_deadlock(self):
536517
self.assertFalse(p.is_alive())
537518

538519
@slowTest
539-
@unittest.skipIf(
540-
NO_MULTIPROCESSING_SPAWN,
541-
"Disabled for environments that \
542-
don't support multiprocessing with spawn start method",
543-
)
544520
@unittest.skipIf(not TEST_CUDA_IPC, "CUDA IPC not available")
545521
def test_cuda_send_many(self, name=None, size=5, count=100000):
546522
ctx = mp.get_context("spawn")
@@ -572,11 +548,6 @@ def test_cuda_send_many(self, name=None, size=5, count=100000):
572548
p2.join(1)
573549
p3.join(1)
574550

575-
@unittest.skipIf(
576-
NO_MULTIPROCESSING_SPAWN,
577-
"Disabled for environments that \
578-
don't support multiprocessing with spawn start method",
579-
)
580551
@unittest.skipIf(not TEST_CUDA_IPC, "CUDA IPC not available")
581552
@unittest.skipIf(not TEST_MULTIGPU, "found only 1 GPU")
582553
def test_cuda_small_tensors(self):
@@ -659,11 +630,6 @@ def run(rank):
659630
)
660631
self.assertRegex(stderr, "Cannot re-initialize CUDA in forked subprocess.")
661632

662-
@unittest.skipIf(
663-
NO_MULTIPROCESSING_SPAWN,
664-
"Disabled for environments that \
665-
don't support multiprocessing with spawn start method",
666-
)
667633
@unittest.skipIf(not TEST_CUDA_IPC, "CUDA IPC not available")
668634
def test_event(self):
669635
ctx = mp.get_context("spawn")
@@ -695,11 +661,6 @@ def _test_event_multiprocess_child(event, p2c, c2p):
695661
event.synchronize()
696662
c2p.put(1) # notify parent synchronization is done
697663

698-
@unittest.skipIf(
699-
NO_MULTIPROCESSING_SPAWN,
700-
"Disabled for environments that \
701-
don't support multiprocessing with spawn start method",
702-
)
703664
@unittest.skipIf(not TEST_CUDA_IPC, "CUDA IPC not available")
704665
def test_event_multiprocess(self):
705666
event = torch.cuda.Event(enable_timing=False, interprocess=True)
@@ -724,11 +685,6 @@ def test_event_multiprocess(self):
724685
self.assertTrue(event.query())
725686
p.join()
726687

727-
@unittest.skipIf(
728-
NO_MULTIPROCESSING_SPAWN,
729-
"Disabled for environments that \
730-
don't support multiprocessing with spawn start method",
731-
)
732688
@unittest.skipIf(not TEST_CUDA_IPC, "CUDA IPC not available")
733689
@unittest.skipIf(not TEST_MULTIGPU, "found only 1 GPU")
734690
def test_event_handle_multi_gpu(self):
@@ -760,11 +716,6 @@ def _test_event_handle_importer_consumer(handle, p2c, c2p):
760716
c2p.put(1) # notify synchronization is done in child
761717
p2c.get() # wait for parent to finish before destructing child event
762718

763-
@unittest.skipIf(
764-
NO_MULTIPROCESSING_SPAWN,
765-
"Disabled for environments that \
766-
don't support multiprocessing with spawn start method",
767-
)
768719
@unittest.skipIf(not TEST_CUDA_IPC, "CUDA IPC not available")
769720
def test_event_handle_importer(self):
770721
e0 = torch.cuda.Event(enable_timing=False, interprocess=True)
@@ -802,11 +753,6 @@ def _test_event_handle_exporter_consumer(handle, p2c, c2p):
802753
# destructing e1
803754
p2c.get()
804755

805-
@unittest.skipIf(
806-
NO_MULTIPROCESSING_SPAWN,
807-
"Disabled for environments that \
808-
don't support multiprocessing with spawn start method",
809-
)
810756
@unittest.skipIf(not TEST_CUDA_IPC, "CUDA IPC not available")
811757
def test_event_handle_exporter(self):
812758
e0 = torch.cuda.Event(enable_timing=False, interprocess=True)
@@ -933,7 +879,7 @@ def test_variable_sharing(self):
933879
@unittest.skipIf(TEST_WITH_ASAN, "non-deterministically hangs with ASAN")
934880
def test_leaf_variable_sharing(self):
935881
devices = ["cpu"]
936-
if torch.cuda.is_available() and not NO_MULTIPROCESSING_SPAWN and TEST_CUDA_IPC:
882+
if torch.cuda.is_available() and TEST_CUDA_IPC:
937883
devices.append("cuda")
938884
for device in devices:
939885
for requires_grad in [True, False]:
@@ -968,11 +914,6 @@ def test_non_leaf_variable_sharing(self):
968914
RuntimeError, r"requires_grad", lambda: queue.put(var)
969915
)
970916

971-
@unittest.skipIf(
972-
NO_MULTIPROCESSING_SPAWN,
973-
"Disabled for environments that \
974-
don't support multiprocessing with spawn start method",
975-
)
976917
@unittest.skipIf(not TEST_CUDA_IPC, "CUDA IPC not available")
977918
def test_cuda_variable_sharing(self):
978919
for requires_grad in [True, False]:
@@ -983,11 +924,6 @@ def test_cuda_variable_sharing(self):
983924
)
984925
self._test_autograd_sharing(var, mp.get_context("spawn"))
985926

986-
@unittest.skipIf(
987-
NO_MULTIPROCESSING_SPAWN,
988-
"Disabled for environments that \
989-
don't support multiprocessing with spawn start method",
990-
)
991927
@unittest.skipIf(not TEST_CUDA_IPC, "CUDA IPC not available")
992928
def test_mixed_types_cuda_sharing(self):
993929
self._test_mixed_types_cuda_sharing(mp.get_context("spawn"))
@@ -996,29 +932,14 @@ def test_parameter_sharing(self):
996932
param = Parameter(torch.arange(1.0, 26).view(5, 5))
997933
self._test_autograd_sharing(param, is_parameter=True)
998934

999-
@unittest.skipIf(
1000-
NO_MULTIPROCESSING_SPAWN,
1001-
"Disabled for environments that \
1002-
don't support multiprocessing with spawn start method",
1003-
)
1004935
@unittest.skipIf(not TEST_CUDA_IPC, "CUDA IPC not available")
1005936
def test_cuda_parameter_sharing(self):
1006937
param = Parameter(torch.arange(1.0, 26, device="cuda").view(5, 5))
1007938
self._test_autograd_sharing(param, mp.get_context("spawn"), is_parameter=True)
1008939

1009-
@unittest.skipIf(
1010-
NO_MULTIPROCESSING_SPAWN,
1011-
"Disabled for environments that \
1012-
don't support multiprocessing with spawn start method",
1013-
)
1014940
def test_integer_parameter_serialization_cpu(self):
1015941
self._test_integer_parameter_serialization(device="cpu")
1016942

1017-
@unittest.skipIf(
1018-
NO_MULTIPROCESSING_SPAWN,
1019-
"Disabled for environments that \
1020-
don't support multiprocessing with spawn start method",
1021-
)
1022943
@unittest.skipIf(not TEST_CUDA_IPC, "CUDA IPC not available")
1023944
def test_integer_parameter_serialization_cuda(self):
1024945
self._test_integer_parameter_serialization(device="cuda")

0 commit comments

Comments
 (0)
0