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

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

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