From c0e15fe3f4d5622c7a687cf0d503902be9296596 Mon Sep 17 00:00:00 2001 From: Jiewen Tan Date: Wed, 6 Jul 2022 18:07:54 +0000 Subject: [PATCH] [c10d] Change pg/process_group to self (#80978) Summary: Change the naming of pg/process_group to self in ProcessGroup's py class. Essentially pg and process_group all mean self. Therefore, it's confusing to use a different naming convention. Test Plan: Covered by existing unit tests. Fixed #80246. Pull Request resolved: https://github.com/pytorch/pytorch/pull/80978 Approved by: https://github.com/mrshenli --- torch/csrc/distributed/c10d/init.cpp | 48 ++++++++++++++-------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/torch/csrc/distributed/c10d/init.cpp b/torch/csrc/distributed/c10d/init.cpp index 0e5b64d49df89..31b8e2c469776 100644 --- a/torch/csrc/distributed/c10d/init.cpp +++ b/torch/csrc/distributed/c10d/init.cpp @@ -1022,12 +1022,12 @@ that adds a prefix to each key inserted to the store. .def( "allreduce", - [](const c10::intrusive_ptr<::c10d::ProcessGroup>& pg, + [](const c10::intrusive_ptr<::c10d::ProcessGroup>& self, std::vector& xs, ::c10d::ReduceOp op) { ::c10d::AllreduceOptions opts; opts.reduceOp = op; - return ::c10d::ops::allreduce(pg, xs, opts); + return ::c10d::ops::allreduce(self, xs, opts); }, py::arg("tensors"), py::arg("op") = ::c10d::ReduceOp::SUM, @@ -1035,13 +1035,13 @@ that adds a prefix to each key inserted to the store. .def( "allreduce", - [](const c10::intrusive_ptr<::c10d::ProcessGroup>& pg, + [](const c10::intrusive_ptr<::c10d::ProcessGroup>& self, at::Tensor& x, ::c10d::ReduceOp op) { ::c10d::AllreduceOptions opts; opts.reduceOp = op; std::vector xs = {x}; - return ::c10d::ops::allreduce(pg, xs, opts); + return ::c10d::ops::allreduce(self, xs, opts); }, py::arg("tensor"), py::arg("op") = ::c10d::ReduceOp::SUM, @@ -1049,10 +1049,10 @@ that adds a prefix to each key inserted to the store. .def( "allreduce_coalesced", - [](::c10d::ProcessGroup& pg, + [](::c10d::ProcessGroup& self, std::vector& xs, ::c10d::AllreduceCoalescedOptions opts) { - return pg.allreduce_coalesced(xs, opts); + return self.allreduce_coalesced(xs, opts); }, py::arg("tensors"), py::arg("opts") = ::c10d::AllreduceCoalescedOptions(), @@ -1071,7 +1071,7 @@ that adds a prefix to each key inserted to the store. .def( "reduce", - [](const c10::intrusive_ptr<::c10d::ProcessGroup>& pg, + [](const c10::intrusive_ptr<::c10d::ProcessGroup>& self, at::Tensor& x, int rootRank, ::c10d::ReduceOp op) { @@ -1079,7 +1079,7 @@ that adds a prefix to each key inserted to the store. opts.reduceOp = op; opts.rootRank = rootRank; std::vector xs = {x}; - return ::c10d::ops::reduce(pg, xs, opts); + return ::c10d::ops::reduce(self, xs, opts); }, py::arg("tensor"), py::arg("root"), @@ -1110,13 +1110,13 @@ that adds a prefix to each key inserted to the store. .def( "allgather", - [](const c10::intrusive_ptr<::c10d::ProcessGroup>& pg, + [](const c10::intrusive_ptr<::c10d::ProcessGroup>& self, std::vector& output, at::Tensor& input) { std::vector> outputs = {output}; std::vector inputs = {input}; return ::c10d::ops::allgather( - pg, outputs, inputs, ::c10d::AllgatherOptions()); + self, outputs, inputs, ::c10d::AllgatherOptions()); }, py::arg("output_tensors"), py::arg("input_tensor"), @@ -1146,7 +1146,7 @@ that adds a prefix to each key inserted to the store. .def( "gather", - [](const c10::intrusive_ptr<::c10d::ProcessGroup>& pg, + [](const c10::intrusive_ptr<::c10d::ProcessGroup>& self, std::vector& output, at::Tensor& input, int rootRank) { @@ -1154,7 +1154,7 @@ that adds a prefix to each key inserted to the store. opts.rootRank = rootRank; std::vector> outputs = {output}; std::vector inputs = {input}; - return ::c10d::ops::gather(pg, outputs, inputs, opts); + return ::c10d::ops::gather(self, outputs, inputs, opts); }, py::arg("output_tensors"), py::arg("input_tensor"), @@ -1177,7 +1177,7 @@ that adds a prefix to each key inserted to the store. .def( "scatter", - [](const c10::intrusive_ptr<::c10d::ProcessGroup>& pg, + [](const c10::intrusive_ptr<::c10d::ProcessGroup>& self, at::Tensor& output, std::vector& input, int rootRank) { @@ -1185,7 +1185,7 @@ that adds a prefix to each key inserted to the store. opts.rootRank = rootRank; std::vector> inputs = {input}; std::vector outputs = {output}; - return ::c10d::ops::scatter(pg, outputs, inputs, opts); + return ::c10d::ops::scatter(self, outputs, inputs, opts); }, py::arg("output_tensor"), py::arg("input_tensors"), @@ -1208,7 +1208,7 @@ that adds a prefix to each key inserted to the store. .def( "reduce_scatter", - [](const c10::intrusive_ptr<::c10d::ProcessGroup>& pg, + [](const c10::intrusive_ptr<::c10d::ProcessGroup>& self, at::Tensor& output, std::vector& input, ::c10d::ReduceOp op) { @@ -1216,7 +1216,7 @@ that adds a prefix to each key inserted to the store. std::vector> inputs = {input}; ::c10d::ReduceScatterOptions opts; opts.reduceOp = op; - return ::c10d::ops::reduce_scatter(pg, outputs, inputs, opts); + return ::c10d::ops::reduce_scatter(self, outputs, inputs, opts); }, py::arg("output_tensors"), py::arg("input_tensor"), @@ -1243,12 +1243,12 @@ that adds a prefix to each key inserted to the store. .def( "alltoall_base", - [](::c10d::ProcessGroup& pg, + [](::c10d::ProcessGroup& self, at::Tensor& output, at::Tensor& input, std::vector outputSplitSizes, std::vector inputSplitSizes) { - return pg.alltoall_base( + return self.alltoall_base( output, input, outputSplitSizes, @@ -1277,11 +1277,11 @@ that adds a prefix to each key inserted to the store. .def( "alltoall", - [](const c10::intrusive_ptr<::c10d::ProcessGroup>& pg, + [](const c10::intrusive_ptr<::c10d::ProcessGroup>& self, std::vector& output, std::vector& input) { return ::c10d::ops::alltoall( - pg, output, input, ::c10d::AllToAllOptions()); + self, output, input, ::c10d::AllToAllOptions()); }, py::arg("output"), py::arg("input"), @@ -1289,11 +1289,11 @@ that adds a prefix to each key inserted to the store. .def( "send", - [](const c10::intrusive_ptr<::c10d::ProcessGroup>& process_group, + [](const c10::intrusive_ptr<::c10d::ProcessGroup>& self, const std::vector& tensors, int64_t dstRank, int64_t tag) { - return ::c10d::ops::send(process_group, tensors, dstRank, tag); + return ::c10d::ops::send(self, tensors, dstRank, tag); }, py::arg("tensors"), py::arg("dstRank"), @@ -1302,11 +1302,11 @@ that adds a prefix to each key inserted to the store. .def( "recv", - [](const c10::intrusive_ptr<::c10d::ProcessGroup>& process_group, + [](const c10::intrusive_ptr<::c10d::ProcessGroup>& self, const std::vector& tensors, int64_t srcRank, int64_t tag) { - return ::c10d::ops::recv(process_group, tensors, srcRank, tag); + return ::c10d::ops::recv(self, tensors, srcRank, tag); }, py::arg("tensors"), py::arg("srcRank"),