Skip to content

Commit be2be27

Browse files
author
Shen Li
committed
Update on "Enforce const on PyRRef functions"
Differential Revision: [D21554722](https://our.internmc.facebook.com/intern/diff/D21554722) [ghstack-poisoned]
2 parents ca32de7 + a7eb6d6 commit be2be27

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

torch/csrc/distributed/rpc/py_rref.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ PyRRef::PyRRef(const py::object& value, const py::object& type_hint)
111111
// jit::toIValue takes a py::handle as the first argument, and it calls
112112
// py::handle.cast<py::object>() to incref of provided value. The
113113
// returned ivalue will keep the reference alive.
114+
// NB: the first argument const py::object& value must be kept alive
115+
// until the following jit::toIValue returns (i.e., incref done). That's
116+
// why this ctor can only be called while holding GIL.
114117
IValue ivalue = jit::toIValue(value, elem_type);
115118
rref->setValue(std::move(ivalue));
116119
return rref;

torch/csrc/distributed/rpc/py_rref.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ enum RRefProxyType { RPC_SYNC, RPC_ASYNC, REMOTE };
1414
// pickle and unpickle.
1515
class PyRRef {
1616
public:
17+
// The first ctor can only be called while holding GIL. See its implementation
18+
// for more explanations.
1719
explicit PyRRef(const py::object& value, const py::object& type_hint);
1820
explicit PyRRef(c10::intrusive_ptr<RRef> rref);
1921

0 commit comments

Comments
 (0)