From af89a9433b2a4f328b69590579dd21e72db614a8 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Wed, 19 May 2021 11:07:59 +0800 Subject: [PATCH] add enforce check for set_value (#32972) --- paddle/fluid/pybind/imperative.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/paddle/fluid/pybind/imperative.cc b/paddle/fluid/pybind/imperative.cc index 825b837a732..ac1fab97644 100644 --- a/paddle/fluid/pybind/imperative.cc +++ b/paddle/fluid/pybind/imperative.cc @@ -766,6 +766,13 @@ void BindImperative(py::module *m_ptr) { imperative::NameVarBaseMap ins = {{"Input", {self}}}; imperative::NameVarBaseMap outs = {{"Out", {self}}}; + PADDLE_ENFORCE_EQ( + self->IsLeaf() && !self->OverridedStopGradient(), false, + platform::errors::InvalidArgument( + "Leaf Tensor (%s) that doesn't stop gradient can't use " + "inplace strategy.", + self->Name())); + auto value_tensor = value_obj.cast>(); ins.insert({"ValueTensor", {value_tensor}}); -- GitLab