Skip to content

Commit

Permalink
[TCPStore] Throw value error if passing world_size=0 to TCPStore (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
awgu authored and pytorchmergebot committed Oct 11, 2024
1 parent 25ac565 commit e269a5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/distributed/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@ def test_store_timeout_on_missing_clients(self):
use_libuv=self._use_libuv,
)

@skip_if_win32()
def test_world_size_0_raises(self):
with self.assertRaisesRegex(ValueError, "TCPStore world size cannot be 0"):
dist.TCPStore("localhost", 0, world_size=0, is_master=False)


class LibUvTCPStoreTest(TCPStoreTest):
_use_libuv = True
Expand Down
3 changes: 3 additions & 0 deletions torch/csrc/distributed/c10d/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,9 @@ Example::
bool useLibUV) {
std::optional<std::size_t> numWorkers = std::nullopt;
if (worldSize.has_value() && worldSize.value() > -1) {
if (worldSize.value() == 0) {
throw py::value_error("TCPStore world size cannot be 0");
}
numWorkers = static_cast<std::size_t>(worldSize.value());
}

Expand Down

0 comments on commit e269a5c

Please sign in to comment.