From fd1c0d7fc5a0d65cfe18aaa92cf1e62183f0f050 Mon Sep 17 00:00:00 2001 From: ShenLiang <1422485404@qq.com> Date: Wed, 30 Nov 2022 15:46:00 +0800 Subject: [PATCH] [BugFix]Fix tuple output bug of pylayer (#48533) * fix bug of pylayer * fix bug --- paddle/fluid/pybind/eager_py_layer.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/pybind/eager_py_layer.cc b/paddle/fluid/pybind/eager_py_layer.cc index 294da6956a..f80a39f9f0 100644 --- a/paddle/fluid/pybind/eager_py_layer.cc +++ b/paddle/fluid/pybind/eager_py_layer.cc @@ -445,11 +445,14 @@ PyObject* pylayer_method_apply(PyObject* cls, } if (outputs_size == 1) { - Py_XDECREF(outputs); - outputs = PyTuple_GetItem(outputs_tuple, 0); - Py_INCREF(outputs); - Py_XDECREF(outputs_tuple); + if (!PyTuple_Check(outputs) && !PyList_Check(outputs)) { + Py_XDECREF(outputs); + outputs = PyTuple_GetItem(outputs_tuple, 0); + Py_INCREF(outputs); + Py_XDECREF(outputs_tuple); + } } + Py_XDECREF(forward_args); Py_XDECREF(kwargs_value_list); Py_XDECREF(backward_function); -- GitLab