未验证 提交 be11648a 编写于 作者: W wanghuancoder 提交者: GitHub

fix pylayer mem leak, test=develop (#41559)

上级 0e048fc6
...@@ -154,6 +154,12 @@ operator()( ...@@ -154,6 +154,12 @@ operator()(
} }
} }
Py_XDECREF(backward_fn);
Py_XDECREF(backward_args);
if (!PyTuple_Check(outputs)) {
Py_XDECREF(outputs_tuple);
}
return grad_out; return grad_out;
} }
} // namespace egr } // namespace egr
...@@ -231,6 +231,10 @@ PyObject* pylayer_method_apply(PyObject* cls, PyObject* args, ...@@ -231,6 +231,10 @@ PyObject* pylayer_method_apply(PyObject* cls, PyObject* args,
auto outputs = PyObject_Call(forward_fn, forward_args, kwargs); auto outputs = PyObject_Call(forward_fn, forward_args, kwargs);
egr::Controller::Instance().SetHasGrad(trace_backward); egr::Controller::Instance().SetHasGrad(trace_backward);
if (!outputs) { if (!outputs) {
Py_XDECREF(forward_args);
Py_XDECREF(kwargs_value_list);
Py_XDECREF(backward_function);
Py_XDECREF(forward_fn);
return nullptr; return nullptr;
} }
...@@ -367,6 +371,14 @@ PyObject* pylayer_method_apply(PyObject* cls, PyObject* args, ...@@ -367,6 +371,14 @@ PyObject* pylayer_method_apply(PyObject* cls, PyObject* args,
VLOG(6) << "PyLayer construct backward node finish..."; VLOG(6) << "PyLayer construct backward node finish...";
} }
if (!PyTuple_Check(outputs)) {
Py_XDECREF(outputs_tuple);
}
Py_XDECREF(forward_args);
Py_XDECREF(kwargs_value_list);
Py_XDECREF(backward_function);
Py_XDECREF(forward_fn);
return outputs; return outputs;
EAGER_CATCH_AND_THROW_RETURN_NULL EAGER_CATCH_AND_THROW_RETURN_NULL
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册