From b4b9438a2b370c9d18f3caebf36cf6ad074e7a71 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Wed, 19 May 2021 15:47:43 +0800 Subject: [PATCH] [Cherry-pick] add enforce check for set_value (#32972) (#32981) cherry-pick of #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 450c992d411..231f7cfb1b5 100644 --- a/paddle/fluid/pybind/imperative.cc +++ b/paddle/fluid/pybind/imperative.cc @@ -710,6 +710,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