Skip to content

Commit aadbeb7

Browse files
izaitsevfbmalfet
andauthored
Make TorchElastic timer importable on Windows (#88522) (#90045)
Also, add `torch.distributed` to test imports, so that we would not regress in the future Fixes #85427 Pull Request resolved: #88522 Approved by: https://github.com/d4l3k (cherry picked from commit f98edfc) Co-authored-by: Nikita Shulga <nshulga@meta.com>
1 parent aa94433 commit aadbeb7

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

test/test_testing.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from torch.testing import make_tensor
2020
from torch.testing._internal.common_utils import \
21-
(IS_FBCODE, IS_SANDCASTLE, IS_WINDOWS, TestCase, run_tests, skipIfRocm, slowTest,
21+
(IS_FBCODE, IS_MACOS, IS_SANDCASTLE, IS_WINDOWS, TestCase, run_tests, skipIfRocm, slowTest,
2222
parametrize, subtest, instantiate_parametrized_tests, dtype_name, TEST_WITH_ROCM)
2323
from torch.testing._internal.common_device_type import \
2424
(PYTORCH_TESTING_DEVICE_EXCEPT_FOR_KEY, PYTORCH_TESTING_DEVICE_ONLY_FOR_KEY, dtypes,
@@ -1782,9 +1782,15 @@ def test_circular_dependencies(self) -> None:
17821782
# See https://github.com/pytorch/pytorch/issues/77801
17831783
if not sys.version_info >= (3, 9):
17841784
ignored_modules.append("torch.utils.benchmark")
1785-
if IS_WINDOWS:
1786-
# Distributed does not work on Windows
1787-
ignored_modules.append("torch.distributed.")
1785+
if IS_WINDOWS or IS_MACOS:
1786+
# Distributed should be importable on Windows(except nn.api.), but not on Mac
1787+
if IS_MACOS:
1788+
ignored_modules.append("torch.distributed.")
1789+
else:
1790+
ignored_modules.append("torch.distributed.nn.api.")
1791+
ignored_modules.append("torch.distributed.optim.")
1792+
ignored_modules.append("torch.distributed.pipeline.")
1793+
ignored_modules.append("torch.distributed.rpc.")
17881794
ignored_modules.append("torch.testing._internal.dist_utils")
17891795

17901796
torch_dir = os.path.dirname(torch.__file__)

torch/distributed/elastic/timer/file_based_local_timer.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import os
1111
import select
1212
import signal
13+
import sys
1314
import threading
1415
import time
1516
from typing import Callable, Dict, List, Optional, Set, Tuple
@@ -78,7 +79,8 @@ class FileTimerClient(TimerClient):
7879
signal: singal, the signal to use to kill the process. Using a
7980
negative or zero signal will not kill the process.
8081
"""
81-
def __init__(self, file_path: str, signal=signal.SIGKILL) -> None:
82+
def __init__(self, file_path: str, signal=(signal.SIGKILL if sys.platform != "win32" else
83+
signal.CTRL_C_EVENT)) -> None: # type: ignore[attr-defined]
8284
super().__init__()
8385
self._file_path = file_path
8486
self.signal = signal

0 commit comments

Comments
 (0)