Skip to content

Commit

Permalink
[c10d] Change pg/process_group to self (pytorch#80978)
Browse files Browse the repository at this point in the history
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 pytorch#80246.
Pull Request resolved: pytorch#80978
Approved by: https://github.com/mrshenli
  • Loading branch information
Jiewen Tan authored and pytorchmergebot committed Jul 7, 2022
1 parent 7591444 commit c0e15fe
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions torch/csrc/distributed/c10d/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,37 +1022,37 @@ 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<at::Tensor>& 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,
py::call_guard<py::gil_scoped_release>())

.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<at::Tensor> 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,
py::call_guard<py::gil_scoped_release>())

.def(
"allreduce_coalesced",
[](::c10d::ProcessGroup& pg,
[](::c10d::ProcessGroup& self,
std::vector<at::Tensor>& xs,
::c10d::AllreduceCoalescedOptions opts) {
return pg.allreduce_coalesced(xs, opts);
return self.allreduce_coalesced(xs, opts);
},
py::arg("tensors"),
py::arg("opts") = ::c10d::AllreduceCoalescedOptions(),
Expand All @@ -1071,15 +1071,15 @@ 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) {
::c10d::ReduceOptions opts;
opts.reduceOp = op;
opts.rootRank = rootRank;
std::vector<at::Tensor> xs = {x};
return ::c10d::ops::reduce(pg, xs, opts);
return ::c10d::ops::reduce(self, xs, opts);
},
py::arg("tensor"),
py::arg("root"),
Expand Down Expand Up @@ -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<at::Tensor>& output,
at::Tensor& input) {
std::vector<std::vector<at::Tensor>> outputs = {output};
std::vector<at::Tensor> inputs = {input};
return ::c10d::ops::allgather(
pg, outputs, inputs, ::c10d::AllgatherOptions());
self, outputs, inputs, ::c10d::AllgatherOptions());
},
py::arg("output_tensors"),
py::arg("input_tensor"),
Expand Down Expand Up @@ -1146,15 +1146,15 @@ 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<at::Tensor>& output,
at::Tensor& input,
int rootRank) {
::c10d::GatherOptions opts;
opts.rootRank = rootRank;
std::vector<std::vector<at::Tensor>> outputs = {output};
std::vector<at::Tensor> 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"),
Expand All @@ -1177,15 +1177,15 @@ 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<at::Tensor>& input,
int rootRank) {
::c10d::ScatterOptions opts;
opts.rootRank = rootRank;
std::vector<std::vector<at::Tensor>> inputs = {input};
std::vector<at::Tensor> 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"),
Expand All @@ -1208,15 +1208,15 @@ 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<at::Tensor>& input,
::c10d::ReduceOp op) {
std::vector<at::Tensor> outputs = {output};
std::vector<std::vector<at::Tensor>> 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"),
Expand All @@ -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<int64_t> outputSplitSizes,
std::vector<int64_t> inputSplitSizes) {
return pg.alltoall_base(
return self.alltoall_base(
output,
input,
outputSplitSizes,
Expand Down Expand Up @@ -1277,23 +1277,23 @@ 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<at::Tensor>& output,
std::vector<at::Tensor>& input) {
return ::c10d::ops::alltoall(
pg, output, input, ::c10d::AllToAllOptions());
self, output, input, ::c10d::AllToAllOptions());
},
py::arg("output"),
py::arg("input"),
py::call_guard<py::gil_scoped_release>())

.def(
"send",
[](const c10::intrusive_ptr<::c10d::ProcessGroup>& process_group,
[](const c10::intrusive_ptr<::c10d::ProcessGroup>& self,
const std::vector<at::Tensor>& 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"),
Expand All @@ -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<at::Tensor>& 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"),
Expand Down

0 comments on commit c0e15fe

Please sign in to comment.