Skip to content

Commit

Permalink
apply lintrunner
Browse files Browse the repository at this point in the history
Signed-off-by: Masaki Kozuki <mkozuki@nvidia.com>
  • Loading branch information
crcrpar committed Nov 8, 2022
1 parent 30ab4bc commit 4986b24
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
5 changes: 2 additions & 3 deletions torch/csrc/distributed/c10d/ProcessGroupNCCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ ncclRedOpRAII unpackPreMulSum(
ncclRedOp_t preMulSum;
bool has_tensor = preMulSupplement->tensor_factor.defined();
auto residence = has_tensor ? ncclScalarDevice : ncclScalarHostImmediate;
T* ptr_factor = has_tensor
? preMulSupplement->tensor_factor.data_ptr<T>()
: nullptr;
T* ptr_factor =
has_tensor ? preMulSupplement->tensor_factor.data_ptr<T>() : nullptr;
T scalar_factor = T(preMulSupplement->double_factor);
ncclRedOpCreatePreMulSum(
&preMulSum,
Expand Down
19 changes: 10 additions & 9 deletions torch/csrc/distributed/c10d/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,15 @@ void _register_builtin_comm_hook(
}

// Customize the metaclass of ::c10d::ReduceOp for the backward compatibility.
// https://github.com/pytorch/pytorch/pull/84243 changed ::c10d::ReduceOp to struct
// from enum, sacrificing some of the Python built-in function supports such as
// `isinstance` (see https://github.com/pytorch/pytorch/issues/87191) and
// `copy` (see https://github.com/pytorch/pytorch/pull/87303#discussion_r1002879700).
// Below, we define a custom `isinstance` in CPython/pybind11 (`reduceopmeta___instancecheck__`)
// and modify the default metaclass of pybind11 (`GetReduceOpMetaclass`)
// so that `isinstance(torch.distributed.ReduceOp.SUM, torch.distributed.ReduceOp)`
// https://github.com/pytorch/pytorch/pull/84243 changed ::c10d::ReduceOp to
// struct from enum, sacrificing some of the Python built-in function supports
// such as `isinstance` (see https://github.com/pytorch/pytorch/issues/87191)
// and `copy` (see
// https://github.com/pytorch/pytorch/pull/87303#discussion_r1002879700). Below,
// we define a custom `isinstance` in CPython/pybind11
// (`reduceopmeta___instancecheck__`) and modify the default metaclass of
// pybind11 (`GetReduceOpMetaclass`) so that
// `isinstance(torch.distributed.ReduceOp.SUM, torch.distributed.ReduceOp)`
// returns :obj:`True` as if `ReduceOp` is enum.
// Ref:
// - https://docs.python.org/3/extending/newtypes_tutorial.html
Expand Down Expand Up @@ -658,8 +660,7 @@ This class does not support ``__members__`` property.)");
if (py::isinstance<py::float_>(preMulSupplement_factor)) {
return ::c10d::makeNCCLPreMulSum(t[1].cast<double>());
} else {
return ::c10d::makeNCCLPreMulSum(
t[1].cast<at::Tensor>());
return ::c10d::makeNCCLPreMulSum(t[1].cast<at::Tensor>());
}
}));

Expand Down

0 comments on commit 4986b24

Please sign in to comment.