Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/python/torchdistx/_C/deferred_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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

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

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