Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

Commit eb86016

Browse files
committed
Use new PyObjectSlot API
1 parent 21a5c8e commit eb86016

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pip==22.0.3
22
setuptools==60.9.3
3-
torch
3+
# torch
44
types-setuptools==57.4.9
55
wheel==0.37.1

src/python/torchdistx/_C/deferred_init.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <ATen/Tensor.h>
1010
#include <c10/core/TensorImpl.h>
11+
#include <torch/csrc/PyInterpreter.h>
1112
#include <torch/csrc/autograd/python_variable.h>
1213
#include <torch/csrc/utils/pybind.h>
1314
#include <torchdistx/deferred_init.h>
@@ -40,7 +41,7 @@ py::object makeVariable(PyTypeObject* type, Tensor data) {
4041
constexpr auto s = PyInterpreterStatus::DEFINITELY_UNINITIALIZED;
4142

4243
// Associate ATen and Python tensor instances.
43-
data.unsafeGetTensorImpl()->init_pyobj(getPyInterpreter(), naked_obj, s);
44+
data.unsafeGetTensorImpl()->pyobj_slot()->init_pyobj(getPyInterpreter(), naked_obj, s);
4445

4546
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
4647
auto* var = reinterpret_cast<THPVariable*>(naked_obj);
@@ -83,7 +84,7 @@ py::object materializeVariable(const py::object& var) {
8384
// We might have already materialized `data`. Make sure that we preserve its
8485
// identity on the Python side and avoid creating a new Python tensor.
8586
c10::optional<PyObject*> opt_materialized_var =
86-
materialized_data.unsafeGetTensorImpl()->check_pyobj(getPyInterpreter());
87+
materialized_data.unsafeGetTensorImpl()->pyobj_slot()->check_pyobj(getPyInterpreter());
8788
if (opt_materialized_var.has_value()) {
8889
return py::reinterpret_borrow<py::object>(*opt_materialized_var);
8990
}

0 commit comments

Comments
 (0)