未验证 提交 797b2dfd 编写于 作者: W WeiXin 提交者: GitHub

clear 'BasicEngine' when an exception occurs in the backward. (#32546)

* clear 'BasicEngine' when an exception occurs in the backward.

* deal with conflict.

* deal with conflict.
上级 f285f4c1
......@@ -470,12 +470,20 @@ void BasicEngine::Execute() {
{
VLOG(3) << "Start to execute grad op " << cur_op.Type();
try {
if (tmp_ins_ptr == nullptr) {
OpBase::Run(cur_op.InnerOp(), bwd_ins, tmp_outs, cur_op.Attrs(),
cur_op.place());
} else {
OpBase::Run(cur_op.InnerOp(), *tmp_ins_ptr, tmp_outs, cur_op.Attrs(),
cur_op.place());
OpBase::Run(cur_op.InnerOp(), *tmp_ins_ptr, tmp_outs,
cur_op.Attrs(), cur_op.place());
}
} catch (platform::EnforceNotMet& exception) {
Clear();
throw std::move(exception);
} catch (std::exception& ex) {
Clear();
PADDLE_THROW(platform::errors::External("%s", ex.what()));
}
}
......
......@@ -234,7 +234,6 @@ class TestPyLayer(unittest.TestCase):
z = Layer_bk_none1.apply(input2)
with self.assertRaises(ValueError):
with paddle.fluid.dygraph.guard():
z.sum().backward()
class Layer_bk_none2(PyLayer):
......@@ -249,8 +248,8 @@ class TestPyLayer(unittest.TestCase):
input1 = paddle.randn([2, 3]).astype("float64")
input1.stop_gradient = False
z = Layer_bk_none2.apply(input1, input1)
with self.assertRaises(ValueError):
with paddle.fluid.dygraph.guard():
z.mean().backward()
class Layer_bk_one1(PyLayer):
......@@ -265,8 +264,8 @@ class TestPyLayer(unittest.TestCase):
input1 = paddle.randn([2, 3]).astype("float64")
input1.stop_gradient = False
z = Layer_bk_one1.apply(input1)
with self.assertRaises(ValueError):
with paddle.fluid.dygraph.guard():
z.mean().backward()
class Layer_bk_one2(PyLayer):
......@@ -280,10 +279,10 @@ class TestPyLayer(unittest.TestCase):
input1 = paddle.randn([2, 3]).astype("float64")
input1.stop_gradient = False
y = Layer_bk_one2.apply(input1, input1)
z = y[0] + y[1]
with self.assertRaises(ValueError):
with paddle.fluid.dygraph.guard():
z.mean().backward()
class Layer_no_bk(PyLayer):
......@@ -295,8 +294,7 @@ class TestPyLayer(unittest.TestCase):
input1.stop_gradient = False
z = Layer_no_bk.apply(input1)
with self.assertRaises(NotImplementedError):
with paddle.fluid.dygraph.guard():
with self.assertRaises(OSError):
z = z[0] + z[1]
z.mean().backward()
......@@ -313,7 +311,6 @@ class TestPyLayer(unittest.TestCase):
input1.stop_gradient = False
z = Layer_bk_match.apply(input1)
with self.assertRaises(ValueError):
with paddle.fluid.dygraph.guard():
z = z[0] + z[1]
z.mean().backward()
......@@ -334,7 +331,6 @@ class TestPyLayer(unittest.TestCase):
z = Layer_bk_none1.apply(input1, input2)
with self.assertRaises(ValueError):
with paddle.fluid.dygraph.guard():
z.mean().backward()
class Layer_bk_none2(PyLayer):
......@@ -353,7 +349,6 @@ class TestPyLayer(unittest.TestCase):
z = Layer_bk_none2.apply(input1, input2)
z = z[0] + z[1]
with self.assertRaises(ValueError):
with paddle.fluid.dygraph.guard():
z.mean().backward()
def test_pylayer_inplace(self):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册