diff --git a/test/distributed/test_fake_pg.py b/test/distributed/test_fake_pg.py index e22453112148..ad233bcdba4a 100644 --- a/test/distributed/test_fake_pg.py +++ b/test/distributed/test_fake_pg.py @@ -273,12 +273,7 @@ class TestFakePG(TestCase): kwargs = {} return func(*args, **kwargs) - with self.assertRaisesRegex( - RuntimeError, - r"FakeProcessGroup cannot be constructed directly\. " - r"Use torch\.distributed\.init_process_group\(backend='fake'\) instead to ensure " - r"proper dispatch system integration\.", - ): + with self.assertRaisesRegex(TypeError, r"No constructor defined"): fake_pg = FakeProcessGroup(rank=0, world_size=3) with SimpleTensorMode(): diff --git a/torch/_C/_distributed_c10d.pyi b/torch/_C/_distributed_c10d.pyi index ee0fbb7ccfbe..da59123625e8 100644 --- a/torch/_C/_distributed_c10d.pyi +++ b/torch/_C/_distributed_c10d.pyi @@ -607,7 +607,6 @@ class ProcessGroup: def group_desc(self) -> str: ... class FakeProcessGroup(Backend): - def __init__(self, rank: int, world_size: int) -> None: ... @staticmethod def _create_internal(rank: int, world_size: int) -> FakeProcessGroup: ... diff --git a/torch/csrc/distributed/c10d/FakeProcessGroup.hpp b/torch/csrc/distributed/c10d/FakeProcessGroup.hpp index b4e5a2289987..b0cb420eb6fc 100644 --- a/torch/csrc/distributed/c10d/FakeProcessGroup.hpp +++ b/torch/csrc/distributed/c10d/FakeProcessGroup.hpp @@ -33,9 +33,8 @@ class FakeProcessGroup : public Backend { int rank, int size, c10::intrusive_ptr options = c10::make_intrusive()) { - return c10::intrusive_ptr( - new FakeProcessGroup(rank, size, std::move(options)), - c10::raw::DontIncreaseRefcount{}); + return c10::make_intrusive( + rank, size, std::move(options)); } const std::string getBackendName() const override { @@ -238,12 +237,12 @@ class FakeProcessGroup : public Backend { return c10::make_intrusive(); } - private: // Private constructor used by official APIs FakeProcessGroup(int rank, int size, c10::intrusive_ptr options) : Backend(rank, size), options_(std::move(options)) {} c10::intrusive_ptr options_; + private: void checkCollectiveError() { TORCH_CHECK( !options_ || !options_->error_on_collective, diff --git a/torch/csrc/distributed/c10d/init.cpp b/torch/csrc/distributed/c10d/init.cpp index c819bd900c25..bdf2576efbe7 100644 --- a/torch/csrc/distributed/c10d/init.cpp +++ b/torch/csrc/distributed/c10d/init.cpp @@ -3838,17 +3838,6 @@ such as `dist.all_reduce(tensor, async_op=True)`. py::arg("world_size"), py::arg("options") = c10::make_intrusive<::c10d::FakeProcessGroup::Options>()) - .def( - "__init__", - [](const py::object&, - const py::args& args, - const py::kwargs& kwargs) { - TORCH_CHECK( - false, - "FakeProcessGroup cannot be constructed directly. " - "Use torch.distributed.init_process_group(backend='fake') instead to ensure " - "proper dispatch system integration."); - }) .def_property_readonly( "options", &::c10d::FakeProcessGroup::getBackendOptions); auto fakeWork =