#pragma once
#include <torch/csrc/distributed/rpc/rref_impl.h>
#include <torch/csrc/python_headers.h>
#include <torch/csrc/utils/pybind.h>
namespace torch {
namespace distributed {
namespace rpc {
enum RRefProxyType { RPC_SYNC, RPC_ASYNC, REMOTE };
class PYBIND11_EXPORT PyRRef {
public:
explicit PyRRef(const py::object& value, const py::object& type_hint);
explicit PyRRef(c10::intrusive_ptr<RRef> rref);
~PyRRef();
bool isOwner() const;
bool confirmedByOwner() const;
WorkerInfo owner() const;
std::string ownerName() const;
py::object toHere(
const float timeoutSeconds =
torch::distributed::rpc::kUnsetRpcTimeout) const;
py::object localValue() const;
std::string str() const;
py::tuple pickle() const;
static PyRRef unpickle(const py::tuple& t);
c10::IValue toIValue() const;
c10::intrusive_ptr<JitFuture> getFuture() const;
c10::intrusive_ptr<JitFuture> getProfilingFuture() const;
void setProfilingFuture(c10::intrusive_ptr<JitFuture> profilingFuture);
py::object createRRefProxy(
const RRefProxyType& mode,
float timeoutSeconds = rpc::kUnsetRpcTimeout) const;
py::object getRRefType(
float timeout = rpc::kUnsetRpcTimeout,
bool blocking = true);
void backward(int64_t autogradContextId, bool retainGraph);
static void backward(
int64_t autogradContextId,
bool retainGraph,
const c10::intrusive_ptr<RRef>& rref);
static void backwardOwnerRRef(
int64_t autogradContextId,
bool retainGraph,
IValue value);
private:
c10::intrusive_ptr<RRef> rref_;
c10::optional<c10::intrusive_ptr<JitFuture>> profilingFuture_;
c10::optional<py::object> type_;
};
}
}
}