| File: | home/liujun/Analysis/pyrefcon_ws/Paddle/build/paddle/fluid/pybind/../../../../paddle/fluid/pybind/eager_utils.cc | 
| Warning: | line 1914, column 15 PyObject ownership leak with reference count of 1  | 
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. | |||
| 2 | Licensed under the Apache License, Version 2.0 (the "License"); | |||
| 3 | you may not use this file except in compliance with the License. | |||
| 4 | You may obtain a copy of the License at | |||
| 5 | http://www.apache.org/licenses/LICENSE-2.0 | |||
| 6 | Unless required by applicable law or agreed to in writing, software | |||
| 7 | distributed under the License is distributed on an "AS IS" BASIS, | |||
| 8 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| 9 | See the License for the specific language governing permissions and | |||
| 10 | limitations under the License. */ | |||
| 11 | ||||
| 12 | #include "paddle/fluid/pybind/eager_utils.h" | |||
| 13 | #include <Python.h> | |||
| 14 | #include "paddle/ir/core/value.h" | |||
| 15 | // Avoid a problem with copysign defined in pyconfig.h on Windows. | |||
| 16 | #ifdef copysign | |||
| 17 | #undef copysign | |||
| 18 | #endif | |||
| 19 | ||||
| 20 | #include <string> | |||
| 21 | #include <vector> | |||
| 22 | ||||
| 23 | #include "paddle/fluid/eager/api/all.h" | |||
| 24 | #include "paddle/fluid/eager/autograd_meta.h" | |||
| 25 | #include "paddle/fluid/eager/hooks.h" | |||
| 26 | #include "paddle/fluid/framework/convert_utils.h" | |||
| 27 | #include "paddle/fluid/framework/scope.h" | |||
| 28 | #include "paddle/fluid/framework/scope_guard.h" | |||
| 29 | #include "paddle/fluid/jit/function.h" | |||
| 30 | #include "paddle/fluid/memory/allocation/allocator.h" | |||
| 31 | #include "paddle/fluid/operators/py_func_op.h" | |||
| 32 | #include "paddle/fluid/operators/utils.h" | |||
| 33 | #include "paddle/fluid/platform/enforce.h" | |||
| 34 | #include "paddle/fluid/pybind/eager.h" | |||
| 35 | #include "paddle/fluid/pybind/op_function_common.h" | |||
| 36 | #include "paddle/fluid/pybind/tensor_py.h" | |||
| 37 | #include "paddle/phi/api/ext/op_meta_info.h" | |||
| 38 | #include "paddle/phi/common/data_type.h" | |||
| 39 | #include "paddle/phi/core/compat/convert_utils.h" | |||
| 40 | #include "paddle/phi/core/dense_tensor.h" | |||
| 41 | #include "paddle/phi/core/flags.h" | |||
| 42 | ||||
| 43 | PHI_DECLARE_bool(check_nan_inf)namespace paddle_flags { extern bool FLAGS_check_nan_inf; } using paddle_flags::FLAGS_check_nan_inf;  | |||
| 44 | PHI_DECLARE_int32(check_nan_inf_level)namespace paddle_flags { extern int32_t FLAGS_check_nan_inf_level ; } using paddle_flags::FLAGS_check_nan_inf_level;  | |||
| 45 | namespace paddle { | |||
| 46 | namespace pybind { | |||
| 47 | ||||
| 48 | extern PyTypeObject* p_tensor_type; | |||
| 49 | extern PyTypeObject* p_string_tensor_type; | |||
| 50 | ||||
| 51 | extern PyTypeObject* g_framework_scope_pytype; | |||
| 52 | extern PyTypeObject* g_ir_opresult_pytype; | |||
| 53 | extern PyTypeObject* g_vartype_pytype; | |||
| 54 | extern PyTypeObject* g_data_type_pytype; | |||
| 55 | extern PyTypeObject* g_place_pytype; | |||
| 56 | extern PyTypeObject* g_cudaplace_pytype; | |||
| 57 | extern PyTypeObject* g_cpuplace_pytype; | |||
| 58 | extern PyTypeObject* g_xpuplace_pytype; | |||
| 59 | extern PyTypeObject* g_cudapinnedplace_pytype; | |||
| 60 | extern PyTypeObject* g_customplace_pytype; | |||
| 61 | extern PyTypeObject* g_framework_tensor_pytype; | |||
| 62 | extern PyTypeObject* g_framework_lodtensorarray_pytype; | |||
| 63 | extern PyTypeObject* g_jit_function_pytype; | |||
| 64 | extern PyTypeObject* g_tensor_dist_attr_pytype; | |||
| 65 | ||||
| 66 | int TensorDtype2NumpyDtype(phi::DataType dtype) { | |||
| 67 | switch (dtype) { | |||
| 68 | case phi::DataType::BOOL: | |||
| 69 | return pybind11::detail::npy_api::NPY_BOOL_; | |||
| 70 | case phi::DataType::INT8: | |||
| 71 | return pybind11::detail::npy_api::NPY_INT8_; | |||
| 72 | case phi::DataType::UINT8: | |||
| 73 | return pybind11::detail::npy_api::NPY_UINT8_; | |||
| 74 | case phi::DataType::INT16: | |||
| 75 | return pybind11::detail::npy_api::NPY_INT16_; | |||
| 76 | case phi::DataType::INT32: | |||
| 77 | return pybind11::detail::npy_api::NPY_INT32_; | |||
| 78 | case phi::DataType::INT64: | |||
| 79 | return pybind11::detail::npy_api::NPY_INT64_; | |||
| 80 | case phi::DataType::BFLOAT16: | |||
| 81 | return pybind11::detail::NPY_UINT16_; | |||
| 82 | case phi::DataType::FLOAT16: | |||
| 83 | return pybind11::detail::NPY_FLOAT16_; | |||
| 84 | case phi::DataType::FLOAT32: | |||
| 85 | return pybind11::detail::npy_api::NPY_FLOAT_; | |||
| 86 | case phi::DataType::FLOAT64: | |||
| 87 | return pybind11::detail::npy_api::NPY_DOUBLE_; | |||
| 88 | case phi::DataType::COMPLEX64: | |||
| 89 | return pybind11::detail::NPY_COMPLEX64; | |||
| 90 | case phi::DataType::COMPLEX128: | |||
| 91 | return pybind11::detail::NPY_COMPLEX128; | |||
| 92 | case phi::DataType::PSTRING: | |||
| 93 | return pybind11::detail::npy_api::NPY_UNICODE_; | |||
| 94 | default: | |||
| 95 |       PADDLE_THROW(paddle::platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (paddle::platform::errors::InvalidArgument( "Unknow phi::DataType, the int value = %d." , static_cast<int>(dtype))), "../../../../paddle/fluid/pybind/eager_utils.cc" , 97); } while (0)  | |||
| 96 |           "Unknow phi::DataType, the int value = %d.",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (paddle::platform::errors::InvalidArgument( "Unknow phi::DataType, the int value = %d." , static_cast<int>(dtype))), "../../../../paddle/fluid/pybind/eager_utils.cc" , 97); } while (0)  | |||
| 97 |           static_cast<int>(dtype)))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (paddle::platform::errors::InvalidArgument( "Unknow phi::DataType, the int value = %d." , static_cast<int>(dtype))), "../../../../paddle/fluid/pybind/eager_utils.cc" , 97); } while (0);  | |||
| 98 | return 0; | |||
| 99 | } | |||
| 100 | } | |||
| 101 | ||||
| 102 | bool PyObject_CheckLongOrConvertToLong(PyObject** obj) { | |||
| 103 |   if (PyLong_Check(*obj)((((((PyObject*)(*obj))->ob_type))->tp_flags & ((1UL << 24))) != 0) && !PyBool_Check(*obj)((((PyObject*)(*obj))->ob_type) == &PyBool_Type)) {  | |||
| 104 | return true; | |||
| 105 | } | |||
| 106 | ||||
| 107 | if (std::string((reinterpret_cast<PyTypeObject*>((*obj)->ob_type))->tp_name) | |||
| 108 | .find("numpy") != std::string::npos) { | |||
| 109 | auto to = PyNumber_Long(*obj); | |||
| 110 | if (to) { | |||
| 111 | *obj = to; | |||
| 112 | return true; | |||
| 113 | } | |||
| 114 | } | |||
| 115 | ||||
| 116 | return false; | |||
| 117 | } | |||
| 118 | ||||
| 119 | bool PyObject_CheckFloatOrConvertToFloat(PyObject** obj) { | |||
| 120 | // sometimes users provide PyLong or numpy.int64 but attr is float | |||
| 121 |   if (PyFloat_Check(*obj)((((PyObject*)(*obj))->ob_type) == (&PyFloat_Type) || PyType_IsSubtype ((((PyObject*)(*obj))->ob_type), (&PyFloat_Type))) || PyLong_Check(*obj)((((((PyObject*)(*obj))->ob_type))->tp_flags & ((1UL << 24))) != 0)) {  | |||
| 122 | return true; | |||
| 123 | } | |||
| 124 | if (std::string((reinterpret_cast<PyTypeObject*>((*obj)->ob_type))->tp_name) | |||
| 125 | .find("numpy") != std::string::npos) { | |||
| 126 | auto to = PyNumber_Float(*obj); | |||
| 127 | if (to) { | |||
| 128 | *obj = to; | |||
| 129 | return true; | |||
| 130 | } | |||
| 131 | } | |||
| 132 | return false; | |||
| 133 | } | |||
| 134 | ||||
| 135 | bool PyObject_CheckStr(PyObject* obj) { return PyUnicode_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 28))) != 0); }  | |||
| 136 | ||||
| 137 | bool PyObject_CheckIROpResult(PyObject* obj) { | |||
| 138 |   return PyObject_TypeCheck(obj, g_ir_opresult_pytype)((((PyObject*)(obj))->ob_type) == (g_ir_opresult_pytype) || PyType_IsSubtype((((PyObject*)(obj))->ob_type), (g_ir_opresult_pytype )));  | |||
| 139 | } | |||
| 140 | ||||
| 141 | bool CastPyArg2AttrBoolean(PyObject* obj, ssize_t arg_pos) { | |||
| 142 | if (obj == Py_None(&_Py_NoneStruct)) { | |||
| 143 | return false; // To be compatible with QA integration testing. Some | |||
| 144 | // test cases pass in None. | |||
| 145 | } else if (obj == Py_True((PyObject *) &_Py_TrueStruct)) { | |||
| 146 | return true; | |||
| 147 | } else if (obj == Py_False((PyObject *) &_Py_FalseStruct)) { | |||
| 148 | return false; | |||
| 149 | } else { | |||
| 150 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "bool, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 154); } while (0)  | |||
| 151 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "bool, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 154); } while (0)  | |||
| 152 |         "bool, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "bool, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 154); } while (0)  | |||
| 153 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "bool, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 154); } while (0)  | |||
| 154 |         (reinterpret_cast<PyTypeObject*>(obj->ob_type))->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "bool, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 154); } while (0);  | |||
| 155 | } | |||
| 156 | } | |||
| 157 | ||||
| 158 | int CastPyArg2AttrInt(PyObject* obj, ssize_t arg_pos) { | |||
| 159 | if (PyObject_CheckLongOrConvertToLong(&obj)) { | |||
| 160 | return static_cast<int>(PyLong_AsLong(obj)); | |||
| 161 | } else { | |||
| 162 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "int, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 166); } while (0)  | |||
| 163 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "int, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 166); } while (0)  | |||
| 164 |         "int, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "int, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 166); } while (0)  | |||
| 165 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "int, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 166); } while (0)  | |||
| 166 |         (reinterpret_cast<PyTypeObject*>(obj->ob_type))->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "int, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 166); } while (0);  | |||
| 167 | } | |||
| 168 | } | |||
| 169 | ||||
| 170 | int64_t CastPyArg2AttrLong(PyObject* obj, ssize_t arg_pos) { | |||
| 171 | if (PyObject_CheckLongOrConvertToLong(&obj)) { | |||
| 172 | return (int64_t)PyLong_AsLong(obj); // NOLINT | |||
| 173 | } else { | |||
| 174 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "long, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 178); } while (0)  | |||
| 175 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "long, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 178); } while (0)  | |||
| 176 |         "long, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "long, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 178); } while (0)  | |||
| 177 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "long, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 178); } while (0)  | |||
| 178 |         (reinterpret_cast<PyTypeObject*>(obj->ob_type))->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "long, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 178); } while (0);  | |||
| 179 | } | |||
| 180 | } | |||
| 181 | ||||
| 182 | size_t CastPyArg2AttrSize_t(PyObject* obj, ssize_t arg_pos) { | |||
| 183 | if (PyObject_CheckLongOrConvertToLong(&obj)) { | |||
| 184 | return PyLong_AsSize_t(obj); | |||
| 185 | } else { | |||
| 186 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "long, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 190); } while (0)  | |||
| 187 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "long, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 190); } while (0)  | |||
| 188 |         "long, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "long, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 190); } while (0)  | |||
| 189 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "long, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 190); } while (0)  | |||
| 190 |         (reinterpret_cast<PyTypeObject*>(obj->ob_type))->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "long, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 190); } while (0);  | |||
| 191 | } | |||
| 192 | } | |||
| 193 | ||||
| 194 | float CastPyArg2AttrFloat(PyObject* obj, ssize_t arg_pos) { | |||
| 195 | if (PyObject_CheckFloatOrConvertToFloat(&obj)) { | |||
| 196 | return static_cast<float>(PyFloat_AsDouble(obj)); | |||
| 197 | } else { | |||
| 198 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "float, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 202); } while (0)  | |||
| 199 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "float, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 202); } while (0)  | |||
| 200 |         "float, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "float, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 202); } while (0)  | |||
| 201 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "float, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 202); } while (0)  | |||
| 202 |         (reinterpret_cast<PyTypeObject*>(obj->ob_type))->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "float, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 202); } while (0);  | |||
| 203 | } | |||
| 204 | } | |||
| 205 | ||||
| 206 | std::string CastPyArg2AttrString(PyObject* obj, ssize_t arg_pos) { | |||
| 207 | if (PyObject_CheckStr(obj)) { | |||
| 208 | Py_ssize_t size; | |||
| 209 | const char* data; | |||
| 210 | data = PyUnicode_AsUTF8AndSize(obj, &size); | |||
| 211 | return std::string(data, static_cast<size_t>(size)); | |||
| 212 | } else { | |||
| 213 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "str, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 217); } while (0)  | |||
| 214 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "str, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 217); } while (0)  | |||
| 215 |         "str, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "str, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 217); } while (0)  | |||
| 216 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "str, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 217); } while (0)  | |||
| 217 |         (reinterpret_cast<PyTypeObject*>(obj->ob_type))->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "str, but got %s", arg_pos + 1, (reinterpret_cast<PyTypeObject *>(obj->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 217); } while (0);  | |||
| 218 | return ""; | |||
| 219 | } | |||
| 220 | } | |||
| 221 | ||||
| 222 | std::shared_ptr<imperative::VarBase> CastPyArg2VarBase(PyObject* obj, | |||
| 223 | ssize_t arg_pos) { | |||
| 224 | return py::cast<std::shared_ptr<imperative::VarBase>>(obj); | |||
| 225 | } | |||
| 226 | ||||
| 227 | void SetPythonStack() { | |||
| 228 | if (FLAGS_check_nan_inf && FLAGS_check_nan_inf_level == 0) { | |||
| 229 |     VLOG(4)static_cast<void>(0), !(__extension__ ({ static google:: int32* vlocal__ = &google::kLogSiteUninitialized; google:: int32 verbose_level__ = (4); (*vlocal__ >= verbose_level__ ) && ((vlocal__ != &google::kLogSiteUninitialized ) || (google::InitVLOG3__(&vlocal__, &FLAGS_v, "../../../../paddle/fluid/pybind/eager_utils.cc" , verbose_level__))); })) ? (void) 0 : google::LogMessageVoidify () & google::LogMessage( "../../../../paddle/fluid/pybind/eager_utils.cc" , 229).stream() << "this is SetPythonStack";  | |||
| 230 | pybind11::gil_scoped_acquire gil; | |||
| 231 | PyObject* mod = PyImport_ImportModule("traceback"); | |||
| 232 | PyObject* traceback_list = PyObject_CallMethod(mod, "format_stack", ""); | |||
| 233 | std::string str = ""; | |||
| 234 | for (Py_ssize_t i = 0; i < PyList_Size(traceback_list); i++) { | |||
| 235 | PyObject* line = PyList_GetItem(traceback_list, i); | |||
| 236 | str += py::str(PyUnicode_AsUTF8(line)); | |||
| 237 | } | |||
| 238 | std::string last = str + egr::Controller::Instance().GetPythonStack(); | |||
| 239 | egr::Controller::Instance().SetPythonStack(last); | |||
| 240 | } | |||
| 241 | } | |||
| 242 | ||||
| 243 | std::shared_ptr<jit::Function> CastPyArg2JitFunction(PyObject* obj, | |||
| 244 | ssize_t arg_pos) { | |||
| 245 |   if (PyObject_TypeCheck(obj, g_jit_function_pytype)((((PyObject*)(obj))->ob_type) == (g_jit_function_pytype) || PyType_IsSubtype((((PyObject*)(obj))->ob_type), (g_jit_function_pytype )))) {  | |||
| 246 | return ::pybind11::handle(obj).cast<std::shared_ptr<jit::Function>>(); | |||
| 247 | } else { | |||
| 248 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "BaseEngine, but got %s", arg_pos + 1, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 252); } while (0)  | |||
| 249 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "BaseEngine, but got %s", arg_pos + 1, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 252); } while (0)  | |||
| 250 |         "BaseEngine, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "BaseEngine, but got %s", arg_pos + 1, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 252); } while (0)  | |||
| 251 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "BaseEngine, but got %s", arg_pos + 1, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 252); } while (0)  | |||
| 252 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "BaseEngine, but got %s", arg_pos + 1, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 252); } while (0);  | |||
| 253 | } | |||
| 254 | } | |||
| 255 | ||||
| 256 | std::vector<paddle::Tensor> CastPyArg2VectorOfTensor(PyObject* obj, | |||
| 257 | ssize_t arg_pos) { | |||
| 258 | std::vector<paddle::Tensor> result; | |||
| 259 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 260 | Py_ssize_t len = PyList_Size(obj); | |||
| 261 | PyObject* item = nullptr; | |||
| 262 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 263 | item = PyList_GetItem(obj, i); | |||
| 264 |       if (PyObject_TypeCheck(item, p_tensor_type)((((PyObject*)(item))->ob_type) == (p_tensor_type) || PyType_IsSubtype ((((PyObject*)(item))->ob_type), (p_tensor_type)))) {  | |||
| 265 | result.emplace_back(reinterpret_cast<TensorObject*>(item)->tensor); | |||
| 266 | } else if (item == Py_None(&_Py_NoneStruct)) { | |||
| 267 | // emplace empty Tensor for None | |||
| 268 | result.emplace_back(); | |||
| 269 | } else { | |||
| 270 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of Tensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 275); } while (0)  | |||
| 271 |             "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of Tensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 275); } while (0)  | |||
| 272 |             "list of Tensor, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of Tensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 275); } while (0)  | |||
| 273 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of Tensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 275); } while (0)  | |||
| 274 |             reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of Tensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 275); } while (0)  | |||
| 275 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of Tensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 275); } while (0);  | |||
| 276 | } | |||
| 277 | } | |||
| 278 |   } else if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 279 | Py_ssize_t len = PyTuple_Size(obj); | |||
| 280 | PyObject* item = nullptr; | |||
| 281 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 282 | item = PyTuple_GetItem(obj, i); | |||
| 283 |       if (PyObject_TypeCheck(item, p_tensor_type)((((PyObject*)(item))->ob_type) == (p_tensor_type) || PyType_IsSubtype ((((PyObject*)(item))->ob_type), (p_tensor_type)))) {  | |||
| 284 | result.emplace_back(reinterpret_cast<TensorObject*>(item)->tensor); | |||
| 285 | } else if (item == Py_None(&_Py_NoneStruct)) { | |||
| 286 | // emplace empty Tensor for None | |||
| 287 | result.emplace_back(); | |||
| 288 | } else { | |||
| 289 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of Tensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 294); } while (0)  | |||
| 290 |             "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of Tensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 294); } while (0)  | |||
| 291 |             "list of Tensor, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of Tensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 294); } while (0)  | |||
| 292 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of Tensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 294); } while (0)  | |||
| 293 |             reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of Tensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 294); } while (0)  | |||
| 294 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of Tensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 294); } while (0);  | |||
| 295 | } | |||
| 296 | } | |||
| 297 | } else if (obj == Py_None(&_Py_NoneStruct)) { | |||
| 298 | return {}; | |||
| 299 |   } else if (PyObject_TypeCheck(obj, p_tensor_type)((((PyObject*)(obj))->ob_type) == (p_tensor_type) || PyType_IsSubtype ((((PyObject*)(obj))->ob_type), (p_tensor_type)))) {  | |||
| 300 | return {reinterpret_cast<TensorObject*>(obj)->tensor}; | |||
| 301 | } else { | |||
| 302 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 306); } while (0)  | |||
| 303 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 306); } while (0)  | |||
| 304 |         "list or tuple, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 306); } while (0)  | |||
| 305 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 306); } while (0)  | |||
| 306 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 306); } while (0);  | |||
| 307 | } | |||
| 308 | return result; | |||
| 309 | } | |||
| 310 | ||||
| 311 | std::vector<int> CastPyArg2VectorOfInt(PyObject* obj, size_t arg_pos) { | |||
| 312 | std::vector<int> result; | |||
| 313 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 314 | Py_ssize_t len = PyList_Size(obj); | |||
| 315 | PyObject* item = nullptr; | |||
| 316 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 317 | item = PyList_GET_ITEM(obj, i)(((PyListObject *)(obj))->ob_item[i]); | |||
| 318 | if (PyObject_CheckLongOrConvertToLong(&item)) { | |||
| 319 | result.emplace_back(static_cast<int>(PyLong_AsLong(item))); | |||
| 320 | } else { | |||
| 321 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 326); } while (0)  | |||
| 322 |             "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 326); } while (0)  | |||
| 323 |             "list of int, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 326); } while (0)  | |||
| 324 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 326); } while (0)  | |||
| 325 |             reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 326); } while (0)  | |||
| 326 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 326); } while (0);  | |||
| 327 | } | |||
| 328 | } | |||
| 329 |   } else if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 330 | Py_ssize_t len = PyTuple_Size(obj); | |||
| 331 | PyObject* item = nullptr; | |||
| 332 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 333 | item = PyTuple_GET_ITEM(obj, i)(((PyTupleObject *)(obj))->ob_item[i]); | |||
| 334 | if (PyObject_CheckLongOrConvertToLong(&item)) { | |||
| 335 | result.emplace_back(static_cast<int>(PyLong_AsLong(item))); | |||
| 336 | } else { | |||
| 337 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 342); } while (0)  | |||
| 338 |             "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 342); } while (0)  | |||
| 339 |             "list of int, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 342); } while (0)  | |||
| 340 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 342); } while (0)  | |||
| 341 |             reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 342); } while (0)  | |||
| 342 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 342); } while (0);  | |||
| 343 | } | |||
| 344 | } | |||
| 345 | } else if (obj == Py_None(&_Py_NoneStruct)) { | |||
| 346 | return {}; | |||
| 347 | } else if (PyObject_CheckLongOrConvertToLong(&obj)) { | |||
| 348 | return {static_cast<int>(PyLong_AsLong(obj))}; | |||
| 349 | } else { | |||
| 350 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 354); } while (0)  | |||
| 351 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 354); } while (0)  | |||
| 352 |         "list or tuple, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 354); } while (0)  | |||
| 353 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 354); } while (0)  | |||
| 354 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 354); } while (0);  | |||
| 355 | } | |||
| 356 | return result; | |||
| 357 | } | |||
| 358 | ||||
| 359 | std::vector<int64_t> CastPyArg2VectorOfInt64(PyObject* obj, size_t arg_pos) { | |||
| 360 | std::vector<int64_t> result; | |||
| 361 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 362 | Py_ssize_t len = PyList_Size(obj); | |||
| 363 | PyObject* item = nullptr; | |||
| 364 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 365 | item = PyList_GET_ITEM(obj, i)(((PyListObject *)(obj))->ob_item[i]); | |||
| 366 | if (PyObject_CheckLongOrConvertToLong(&item)) { | |||
| 367 | result.emplace_back(static_cast<int64_t>(PyLong_AsLong(item))); | |||
| 368 | } else { | |||
| 369 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 374); } while (0)  | |||
| 370 |             "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 374); } while (0)  | |||
| 371 |             "list of int, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 374); } while (0)  | |||
| 372 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 374); } while (0)  | |||
| 373 |             reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 374); } while (0)  | |||
| 374 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 374); } while (0);  | |||
| 375 | } | |||
| 376 | } | |||
| 377 |   } else if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 378 | Py_ssize_t len = PyTuple_Size(obj); | |||
| 379 | PyObject* item = nullptr; | |||
| 380 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 381 | item = PyTuple_GET_ITEM(obj, i)(((PyTupleObject *)(obj))->ob_item[i]); | |||
| 382 | if (PyObject_CheckLongOrConvertToLong(&item)) { | |||
| 383 | result.emplace_back(static_cast<int64_t>(PyLong_AsLong(item))); | |||
| 384 | } else { | |||
| 385 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 390); } while (0)  | |||
| 386 |             "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 390); } while (0)  | |||
| 387 |             "list of int, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 390); } while (0)  | |||
| 388 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 390); } while (0)  | |||
| 389 |             reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 390); } while (0)  | |||
| 390 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 390); } while (0);  | |||
| 391 | } | |||
| 392 | } | |||
| 393 | } else if (obj == Py_None(&_Py_NoneStruct)) { | |||
| 394 | return {}; | |||
| 395 | } else if (PyObject_CheckLongOrConvertToLong(&obj)) { | |||
| 396 | return {static_cast<int64_t>(PyLong_AsLong(obj))}; | |||
| 397 | } else { | |||
| 398 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 402); } while (0)  | |||
| 399 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 402); } while (0)  | |||
| 400 |         "list or tuple, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 402); } while (0)  | |||
| 401 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 402); } while (0)  | |||
| 402 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 402); } while (0);  | |||
| 403 | } | |||
| 404 | return result; | |||
| 405 | } | |||
| 406 | ||||
| 407 | std::vector<size_t> CastPyArg2VectorOfSize_t(PyObject* obj, size_t arg_pos) { | |||
| 408 | std::vector<size_t> result; | |||
| 409 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 410 | Py_ssize_t len = PyList_Size(obj); | |||
| 411 | PyObject* item = nullptr; | |||
| 412 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 413 | item = PyList_GetItem(obj, i); | |||
| 414 | if (PyObject_CheckLongOrConvertToLong(&item)) { | |||
| 415 | result.emplace_back(PyLong_AsSize_t(item)); | |||
| 416 | } else { | |||
| 417 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 422); } while (0)  | |||
| 418 |             "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 422); } while (0)  | |||
| 419 |             "list of int, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 422); } while (0)  | |||
| 420 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 422); } while (0)  | |||
| 421 |             reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 422); } while (0)  | |||
| 422 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of int, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 422); } while (0);  | |||
| 423 | } | |||
| 424 | } | |||
| 425 |   } else if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 426 | Py_ssize_t len = PyTuple_Size(obj); | |||
| 427 | PyObject* item = nullptr; | |||
| 428 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 429 | item = PyTuple_GET_ITEM(obj, i)(((PyTupleObject *)(obj))->ob_item[i]); | |||
| 430 | if (PyObject_CheckLongOrConvertToLong(&item)) { | |||
| 431 | result.emplace_back(PyLong_AsSize_t(item)); | |||
| 432 | } else { | |||
| 433 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of size_t, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 438); } while (0)  | |||
| 434 |             "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of size_t, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 438); } while (0)  | |||
| 435 |             "list of size_t, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of size_t, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 438); } while (0)  | |||
| 436 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of size_t, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 438); } while (0)  | |||
| 437 |             reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of size_t, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 438); } while (0)  | |||
| 438 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of size_t, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 438); } while (0);  | |||
| 439 | } | |||
| 440 | } | |||
| 441 | } else if (obj == Py_None(&_Py_NoneStruct)) { | |||
| 442 | return {}; | |||
| 443 | } else if (PyObject_CheckLongOrConvertToLong(&obj)) { | |||
| 444 | return {PyLong_AsSize_t(obj)}; | |||
| 445 | } else { | |||
| 446 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of size_t, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 450); } while (0)  | |||
| 447 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of size_t, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 450); } while (0)  | |||
| 448 |         "list of size_t, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of size_t, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 450); } while (0)  | |||
| 449 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of size_t, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 450); } while (0)  | |||
| 450 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of size_t, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 450); } while (0);  | |||
| 451 | } | |||
| 452 | return result; | |||
| 453 | } | |||
| 454 | ||||
| 455 | std::vector<float> CastPyArg2VectorOfFloat(PyObject* obj, size_t arg_pos) { | |||
| 456 | std::vector<float> result; | |||
| 457 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 458 | Py_ssize_t len = PyList_Size(obj); | |||
| 459 | PyObject* item = nullptr; | |||
| 460 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 461 | item = PyList_GetItem(obj, i); | |||
| 462 | if (PyObject_CheckFloatOrConvertToFloat(&item)) { | |||
| 463 | result.emplace_back(static_cast<float>(PyFloat_AsDouble(item))); | |||
| 464 | } else { | |||
| 465 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of float, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 470); } while (0)  | |||
| 466 |             "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of float, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 470); } while (0)  | |||
| 467 |             "list of float, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of float, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 470); } while (0)  | |||
| 468 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of float, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 470); } while (0)  | |||
| 469 |             reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of float, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 470); } while (0)  | |||
| 470 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of float, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 470); } while (0);  | |||
| 471 | } | |||
| 472 | } | |||
| 473 |   } else if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 474 | Py_ssize_t len = PyTuple_Size(obj); | |||
| 475 | PyObject* item = nullptr; | |||
| 476 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 477 | item = PyTuple_GET_ITEM(obj, i)(((PyTupleObject *)(obj))->ob_item[i]); | |||
| 478 | if (PyObject_CheckFloatOrConvertToFloat(&item)) { | |||
| 479 | result.emplace_back(static_cast<float>(PyFloat_AsDouble(item))); | |||
| 480 | } else { | |||
| 481 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of float, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 486); } while (0)  | |||
| 482 |             "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of float, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 486); } while (0)  | |||
| 483 |             "list of float, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of float, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 486); } while (0)  | |||
| 484 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of float, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 486); } while (0)  | |||
| 485 |             reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of float, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 486); } while (0)  | |||
| 486 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of float, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 486); } while (0);  | |||
| 487 | } | |||
| 488 | } | |||
| 489 | } else if (obj == Py_None(&_Py_NoneStruct)) { | |||
| 490 | return {}; | |||
| 491 | } else if (PyObject_CheckFloatOrConvertToFloat(&obj)) { | |||
| 492 | return {static_cast<float>(PyFloat_AsDouble(obj))}; | |||
| 493 | } else { | |||
| 494 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of float, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 498); } while (0)  | |||
| 495 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of float, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 498); } while (0)  | |||
| 496 |         "list of float, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of float, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 498); } while (0)  | |||
| 497 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of float, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 498); } while (0)  | |||
| 498 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of float, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 498); } while (0);  | |||
| 499 | } | |||
| 500 | return result; | |||
| 501 | } | |||
| 502 | ||||
| 503 | std::vector<std::vector<size_t>> CastPyArg2VectorOfVectorOfSize_t( | |||
| 504 | PyObject* obj, size_t arg_pos) { | |||
| 505 | std::vector<std::vector<size_t>> result; | |||
| 506 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 507 | Py_ssize_t len = PyList_Size(obj); | |||
| 508 | PyObject* item = nullptr; | |||
| 509 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 510 | item = PyList_GetItem(obj, i); | |||
| 511 | result.emplace_back(CastPyArg2VectorOfSize_t(item, arg_pos)); | |||
| 512 | } | |||
| 513 | } else { | |||
| 514 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list but got %s", arg_pos + 1, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 518); } while (0)  | |||
| 515 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list but got %s", arg_pos + 1, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 518); } while (0)  | |||
| 516 |         "list but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list but got %s", arg_pos + 1, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 518); } while (0)  | |||
| 517 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list but got %s", arg_pos + 1, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 518); } while (0)  | |||
| 518 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list but got %s", arg_pos + 1, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 518); } while (0);  | |||
| 519 | } | |||
| 520 | return result; | |||
| 521 | } | |||
| 522 | ||||
| 523 | platform::Place CastPyArg2Place(PyObject* obj, ssize_t arg_pos) { | |||
| 524 | platform::Place place; | |||
| 525 |   if (PyObject_TypeCheck(obj, g_place_pytype)((((PyObject*)(obj))->ob_type) == (g_place_pytype) || PyType_IsSubtype ((((PyObject*)(obj))->ob_type), (g_place_pytype)))) {  | |||
| 526 | place = ::pybind11::handle(obj).cast<platform::Place>(); | |||
| 527 |   } else if (PyObject_TypeCheck(obj, g_cudaplace_pytype)((((PyObject*)(obj))->ob_type) == (g_cudaplace_pytype) || PyType_IsSubtype ((((PyObject*)(obj))->ob_type), (g_cudaplace_pytype)))) {  | |||
| 528 | place = ::pybind11::handle(obj).cast<platform::CUDAPlace>(); | |||
| 529 |   } else if (PyObject_TypeCheck(obj, g_cpuplace_pytype)((((PyObject*)(obj))->ob_type) == (g_cpuplace_pytype) || PyType_IsSubtype ((((PyObject*)(obj))->ob_type), (g_cpuplace_pytype)))) {  | |||
| 530 | place = ::pybind11::handle(obj).cast<platform::CPUPlace>(); | |||
| 531 |   } else if (PyObject_TypeCheck(obj, g_xpuplace_pytype)((((PyObject*)(obj))->ob_type) == (g_xpuplace_pytype) || PyType_IsSubtype ((((PyObject*)(obj))->ob_type), (g_xpuplace_pytype)))) {  | |||
| 532 | place = ::pybind11::handle(obj).cast<platform::XPUPlace>(); | |||
| 533 |   } else if (PyObject_TypeCheck(obj, g_cudapinnedplace_pytype)((((PyObject*)(obj))->ob_type) == (g_cudapinnedplace_pytype ) || PyType_IsSubtype((((PyObject*)(obj))->ob_type), (g_cudapinnedplace_pytype )))) {  | |||
| 534 | place = ::pybind11::handle(obj).cast<platform::CUDAPinnedPlace>(); | |||
| 535 |   } else if (PyObject_TypeCheck(obj, g_customplace_pytype)((((PyObject*)(obj))->ob_type) == (g_customplace_pytype) || PyType_IsSubtype((((PyObject*)(obj))->ob_type), (g_customplace_pytype )))) {  | |||
| 536 | place = ::pybind11::handle(obj).cast<platform::CustomPlace>(); | |||
| 537 | } else { | |||
| 538 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "one " "of(Place,CUDAPlace,CPUPlace,XPUPlace,CUDAPinnedPlace," "CustomPlace), " "but got %s", arg_pos + 1, reinterpret_cast <PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 545); } while (0)  | |||
| 539 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "one " "of(Place,CUDAPlace,CPUPlace,XPUPlace,CUDAPinnedPlace," "CustomPlace), " "but got %s", arg_pos + 1, reinterpret_cast <PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 545); } while (0)  | |||
| 540 |         "one "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "one " "of(Place,CUDAPlace,CPUPlace,XPUPlace,CUDAPinnedPlace," "CustomPlace), " "but got %s", arg_pos + 1, reinterpret_cast <PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 545); } while (0)  | |||
| 541 |         "of(Place,CUDAPlace,CPUPlace,XPUPlace,CUDAPinnedPlace,"do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "one " "of(Place,CUDAPlace,CPUPlace,XPUPlace,CUDAPinnedPlace," "CustomPlace), " "but got %s", arg_pos + 1, reinterpret_cast <PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 545); } while (0)  | |||
| 542 |         "CustomPlace), "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "one " "of(Place,CUDAPlace,CPUPlace,XPUPlace,CUDAPinnedPlace," "CustomPlace), " "but got %s", arg_pos + 1, reinterpret_cast <PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 545); } while (0)  | |||
| 543 |         "but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "one " "of(Place,CUDAPlace,CPUPlace,XPUPlace,CUDAPinnedPlace," "CustomPlace), " "but got %s", arg_pos + 1, reinterpret_cast <PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 545); } while (0)  | |||
| 544 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "one " "of(Place,CUDAPlace,CPUPlace,XPUPlace,CUDAPinnedPlace," "CustomPlace), " "but got %s", arg_pos + 1, reinterpret_cast <PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 545); } while (0)  | |||
| 545 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "one " "of(Place,CUDAPlace,CPUPlace,XPUPlace,CUDAPinnedPlace," "CustomPlace), " "but got %s", arg_pos + 1, reinterpret_cast <PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 545); } while (0);  | |||
| 546 | } | |||
| 547 | return place; | |||
| 548 | } | |||
| 549 | ||||
| 550 | using phi::distributed::TensorDistAttr; | |||
| 551 | TensorDistAttr CastPyArg2DistAttr(PyObject* obj, ssize_t arg_pos) { | |||
| 552 | #ifdef PADDLE_WITH_DISTRIBUTE | |||
| 553 | if (PyObject_IsInstance( | |||
| 554 | obj, reinterpret_cast<PyObject*>(g_tensor_dist_attr_pytype))) { | |||
| 555 | return ::pybind11::handle(obj).cast<TensorDistAttr>(); | |||
| 556 | } else { | |||
| 557 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "TensorDistAttr, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 561); } while (0)  | |||
| 558 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "TensorDistAttr, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 561); } while (0)  | |||
| 559 |         "TensorDistAttr, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "TensorDistAttr, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 561); } while (0)  | |||
| 560 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "TensorDistAttr, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 561); } while (0)  | |||
| 561 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "TensorDistAttr, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 561); } while (0);  | |||
| 562 | } | |||
| 563 | #else | |||
| 564 |   PADDLE_THROW(platform::errors::Unavailable(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Unavailable( "The parsing of `DistAttr` is not supported in the current " "PaddlePaddle, please recompile and installPaddlePaddle with the option " "of `WITH_DISTRIBUTE=ON`.")), "../../../../paddle/fluid/pybind/eager_utils.cc" , 567); } while (0)  | |||
| 565 |       "The parsing of `DistAttr` is not supported in the current "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Unavailable( "The parsing of `DistAttr` is not supported in the current " "PaddlePaddle, please recompile and installPaddlePaddle with the option " "of `WITH_DISTRIBUTE=ON`.")), "../../../../paddle/fluid/pybind/eager_utils.cc" , 567); } while (0)  | |||
| 566 |       "PaddlePaddle, please recompile and installPaddlePaddle with the option "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Unavailable( "The parsing of `DistAttr` is not supported in the current " "PaddlePaddle, please recompile and installPaddlePaddle with the option " "of `WITH_DISTRIBUTE=ON`.")), "../../../../paddle/fluid/pybind/eager_utils.cc" , 567); } while (0)  | |||
| 567 |       "of `WITH_DISTRIBUTE=ON`."))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Unavailable( "The parsing of `DistAttr` is not supported in the current " "PaddlePaddle, please recompile and installPaddlePaddle with the option " "of `WITH_DISTRIBUTE=ON`.")), "../../../../paddle/fluid/pybind/eager_utils.cc" , 567); } while (0);  | |||
| 568 | #endif | |||
| 569 | } | |||
| 570 | ||||
| 571 | phi::DenseTensor CastPyArg2FrameworkTensor(PyObject* obj, ssize_t arg_pos) { | |||
| 572 |   if (PyObject_TypeCheck(obj, g_framework_tensor_pytype)((((PyObject*)(obj))->ob_type) == (g_framework_tensor_pytype ) || PyType_IsSubtype((((PyObject*)(obj))->ob_type), (g_framework_tensor_pytype )))) {  | |||
| 573 | return ::pybind11::handle(obj).cast<phi::DenseTensor>(); | |||
| 574 | } else { | |||
| 575 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "DenseTensor, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 579); } while (0)  | |||
| 576 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "DenseTensor, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 579); } while (0)  | |||
| 577 |         "DenseTensor, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "DenseTensor, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 579); } while (0)  | |||
| 578 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "DenseTensor, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 579); } while (0)  | |||
| 579 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "DenseTensor, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 579); } while (0);  | |||
| 580 | } | |||
| 581 | } | |||
| 582 | ||||
| 583 | std::vector<phi::DenseTensor> CastPyArg2VectorOfTensorBase(PyObject* obj, | |||
| 584 | ssize_t arg_pos) { | |||
| 585 | std::vector<phi::DenseTensor> result; | |||
| 586 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 587 | Py_ssize_t len = PyList_Size(obj); | |||
| 588 | PyObject* item = nullptr; | |||
| 589 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 590 | item = PyList_GetItem(obj, i); | |||
| 591 |       if (PyObject_TypeCheck(item, g_framework_tensor_pytype)((((PyObject*)(item))->ob_type) == (g_framework_tensor_pytype ) || PyType_IsSubtype((((PyObject*)(item))->ob_type), (g_framework_tensor_pytype )))) {  | |||
| 592 | result.emplace_back(::pybind11::handle(item).cast<phi::DenseTensor>()); | |||
| 593 | } else { | |||
| 594 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of LoDTensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 599); } while (0)  | |||
| 595 |             "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of LoDTensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 599); } while (0)  | |||
| 596 |             "list of LoDTensor, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of LoDTensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 599); } while (0)  | |||
| 597 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of LoDTensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 599); } while (0)  | |||
| 598 |             reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of LoDTensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 599); } while (0)  | |||
| 599 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of LoDTensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 599); } while (0);  | |||
| 600 | } | |||
| 601 | } | |||
| 602 |   } else if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 603 | Py_ssize_t len = PyTuple_Size(obj); | |||
| 604 | PyObject* item = nullptr; | |||
| 605 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 606 | item = PyTuple_GetItem(obj, i); | |||
| 607 |       if (PyObject_TypeCheck(item, g_framework_tensor_pytype)((((PyObject*)(item))->ob_type) == (g_framework_tensor_pytype ) || PyType_IsSubtype((((PyObject*)(item))->ob_type), (g_framework_tensor_pytype )))) {  | |||
| 608 | result.emplace_back(::pybind11::handle(item).cast<phi::DenseTensor>()); | |||
| 609 | } else { | |||
| 610 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of LoDTensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 615); } while (0)  | |||
| 611 |             "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of LoDTensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 615); } while (0)  | |||
| 612 |             "list of LoDTensor, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of LoDTensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 615); } while (0)  | |||
| 613 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of LoDTensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 615); } while (0)  | |||
| 614 |             reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of LoDTensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 615); } while (0)  | |||
| 615 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list of LoDTensor, but got %s at pos %d", arg_pos + 1, reinterpret_cast <PyTypeObject*>(item->ob_type)->tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 615); } while (0);  | |||
| 616 | } | |||
| 617 | } | |||
| 618 |   } else if (PyObject_TypeCheck(obj, g_framework_lodtensorarray_pytype)((((PyObject*)(obj))->ob_type) == (g_framework_lodtensorarray_pytype ) || PyType_IsSubtype((((PyObject*)(obj))->ob_type), (g_framework_lodtensorarray_pytype )))) {  | |||
| 619 | for (auto& tensor : | |||
| 620 | (::pybind11::handle(obj).cast<framework::LoDTensorArray>())) { | |||
| 621 | result.emplace_back(tensor); | |||
| 622 | } | |||
| 623 | } else if (obj == Py_None(&_Py_NoneStruct)) { | |||
| 624 | return {}; | |||
| 625 |   } else if (PyObject_TypeCheck(obj, g_framework_tensor_pytype)((((PyObject*)(obj))->ob_type) == (g_framework_tensor_pytype ) || PyType_IsSubtype((((PyObject*)(obj))->ob_type), (g_framework_tensor_pytype )))) {  | |||
| 626 | return {::pybind11::handle(obj).cast<phi::DenseTensor>()}; | |||
| 627 | } else { | |||
| 628 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 632); } while (0)  | |||
| 629 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 632); } while (0)  | |||
| 630 |         "list or tuple, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 632); } while (0)  | |||
| 631 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 632); } while (0)  | |||
| 632 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "list or tuple, but got %s", arg_pos + 1, reinterpret_cast< PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 632); } while (0);  | |||
| 633 | } | |||
| 634 | return result; | |||
| 635 | } | |||
| 636 | ||||
| 637 | paddle::framework::proto::VarType::Type CastPyArg2ProtoType(PyObject* obj, | |||
| 638 | ssize_t arg_pos) { | |||
| 639 | paddle::framework::proto::VarType::Type dtype; | |||
| 640 |   if (PyObject_TypeCheck(obj, g_vartype_pytype)((((PyObject*)(obj))->ob_type) == (g_vartype_pytype) || PyType_IsSubtype ((((PyObject*)(obj))->ob_type), (g_vartype_pytype)))) {  | |||
| 641 | dtype = | |||
| 642 | ::pybind11::handle(obj).cast<paddle::framework::proto::VarType::Type>(); | |||
| 643 | } else { | |||
| 644 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "one of core.VarDesc.VarType, " "but got %s", arg_pos + 1, reinterpret_cast <PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 649); } while (0)  | |||
| 645 |         "argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "one of core.VarDesc.VarType, " "but got %s", arg_pos + 1, reinterpret_cast <PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 649); } while (0)  | |||
| 646 |         "one of core.VarDesc.VarType, "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "one of core.VarDesc.VarType, " "but got %s", arg_pos + 1, reinterpret_cast <PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 649); } while (0)  | |||
| 647 |         "but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "one of core.VarDesc.VarType, " "but got %s", arg_pos + 1, reinterpret_cast <PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 649); } while (0)  | |||
| 648 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "one of core.VarDesc.VarType, " "but got %s", arg_pos + 1, reinterpret_cast <PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 649); } while (0)  | |||
| 649 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be " "one of core.VarDesc.VarType, " "but got %s", arg_pos + 1, reinterpret_cast <PyTypeObject*>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 649); } while (0);  | |||
| 650 | } | |||
| 651 | return dtype; | |||
| 652 | } | |||
| 653 | ||||
| 654 | paddle::DataType CastPyArg2DataTypeDirectly(PyObject* obj, | |||
| 655 | const std::string& op_type, | |||
| 656 | ssize_t arg_pos) { | |||
| 657 | if (obj == Py_None(&_Py_NoneStruct)) { | |||
| 658 | return phi::DataType::UNDEFINED; | |||
| 659 | } | |||
| 660 | ||||
| 661 | paddle::DataType dtype; | |||
| 662 |   if (PyObject_TypeCheck(obj, g_data_type_pytype)((((PyObject*)(obj))->ob_type) == (g_data_type_pytype) || PyType_IsSubtype ((((PyObject*)(obj))->ob_type), (g_data_type_pytype)))) {  | |||
| 663 | dtype = ::pybind11::handle(obj).cast<paddle::DataType>(); | |||
| 664 | } else { | |||
| 665 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s: argument (position %d) must be " "one of paddle::DataType, " "but got %s", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(obj->ob_type)-> tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc", 671 ); } while (0)  | |||
| 666 |         "%s: argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s: argument (position %d) must be " "one of paddle::DataType, " "but got %s", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(obj->ob_type)-> tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc", 671 ); } while (0)  | |||
| 667 |         "one of paddle::DataType, "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s: argument (position %d) must be " "one of paddle::DataType, " "but got %s", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(obj->ob_type)-> tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc", 671 ); } while (0)  | |||
| 668 |         "but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s: argument (position %d) must be " "one of paddle::DataType, " "but got %s", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(obj->ob_type)-> tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc", 671 ); } while (0)  | |||
| 669 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s: argument (position %d) must be " "one of paddle::DataType, " "but got %s", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(obj->ob_type)-> tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc", 671 ); } while (0)  | |||
| 670 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s: argument (position %d) must be " "one of paddle::DataType, " "but got %s", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(obj->ob_type)-> tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc", 671 ); } while (0)  | |||
| 671 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s: argument (position %d) must be " "one of paddle::DataType, " "but got %s", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(obj->ob_type)-> tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc", 671 ); } while (0);  | |||
| 672 | } | |||
| 673 | return dtype; | |||
| 674 | } | |||
| 675 | ||||
| 676 | paddle::framework::Vocab CastPyArg2Vocab(PyObject* obj, ssize_t arg_pos) { | |||
| 677 |   if (PyDict_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 29))) != 0)) {  | |||
| 678 | paddle::framework::Vocab vocab; | |||
| 679 | vocab = ::pybind11::handle(obj) | |||
| 680 | .cast<std::unordered_map<std::wstring, std::int32_t>>(); | |||
| 681 | return vocab; | |||
| 682 | } else { | |||
| 683 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be dict, but got %s" , arg_pos + 1, reinterpret_cast<PyTypeObject*>(obj-> ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 686); } while (0)  | |||
| 684 |         "argument (position %d) must be dict, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be dict, but got %s" , arg_pos + 1, reinterpret_cast<PyTypeObject*>(obj-> ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 686); } while (0)  | |||
| 685 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be dict, but got %s" , arg_pos + 1, reinterpret_cast<PyTypeObject*>(obj-> ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 686); } while (0)  | |||
| 686 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be dict, but got %s" , arg_pos + 1, reinterpret_cast<PyTypeObject*>(obj-> ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 686); } while (0);  | |||
| 687 | } | |||
| 688 | } | |||
| 689 | ||||
| 690 | std::vector<std::string> CastPyArg2VectorOfString(PyObject* obj, | |||
| 691 | ssize_t arg_pos) { | |||
| 692 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 693 | return ::pybind11::handle(obj).cast<std::vector<std::string>>(); | |||
| 694 | } else { | |||
| 695 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be list, but got %s" , arg_pos + 1, reinterpret_cast<PyTypeObject*>(obj-> ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 698); } while (0)  | |||
| 696 |         "argument (position %d) must be list, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be list, but got %s" , arg_pos + 1, reinterpret_cast<PyTypeObject*>(obj-> ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 698); } while (0)  | |||
| 697 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be list, but got %s" , arg_pos + 1, reinterpret_cast<PyTypeObject*>(obj-> ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 698); } while (0)  | |||
| 698 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument (position %d) must be list, but got %s" , arg_pos + 1, reinterpret_cast<PyTypeObject*>(obj-> ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 698); } while (0);  | |||
| 699 | } | |||
| 700 | } | |||
| 701 | ||||
| 702 | PyObject* ToPyObject(bool value) { | |||
| 703 | if (value) { | |||
| 704 | Py_INCREF(Py_True)_Py_INCREF(((PyObject*)(((PyObject *) &_Py_TrueStruct)))); | |||
| 705 | return Py_True((PyObject *) &_Py_TrueStruct); | |||
| 706 | } else { | |||
| 707 |     Py_INCREF(Py_False)_Py_INCREF(((PyObject*)(((PyObject *) &_Py_FalseStruct))) );  | |||
| 708 | return Py_False((PyObject *) &_Py_FalseStruct); | |||
| 709 | } | |||
| 710 | } | |||
| 711 | ||||
| 712 | PyObject* ToPyObject(int value) { return PyLong_FromLong(value); } | |||
| 713 | ||||
| 714 | PyObject* ToPyObject(uint32_t value) { return PyLong_FromUnsignedLong(value); } | |||
| 715 | ||||
| 716 | PyObject* ToPyObject(int64_t value) { return PyLong_FromLongLong(value); } | |||
| 717 | ||||
| 718 | PyObject* ToPyObject(size_t value) { return PyLong_FromSize_t(value); } | |||
| 719 | ||||
| 720 | PyObject* ToPyObject(float value) { return PyLong_FromDouble(value); } | |||
| 721 | ||||
| 722 | PyObject* ToPyObject(double value) { return PyLong_FromDouble(value); } | |||
| 723 | ||||
| 724 | PyObject* ToPyObject(const char* value) { return PyUnicode_FromString(value); } | |||
| 725 | ||||
| 726 | PyObject* ToPyObject(const std::string& value) { | |||
| 727 | return PyUnicode_FromString(value.c_str()); | |||
| 728 | } | |||
| 729 | ||||
| 730 | PyObject* ToPyObject(const paddle::Tensor& value, | |||
| 731 | PyObject* args, | |||
| 732 | const std::map<ssize_t, ssize_t>& inplace_var_idx_map) { | |||
| 733 | if (!inplace_var_idx_map.empty() && inplace_var_idx_map.count(0)) { | |||
| 734 | return ToPyObject(args, inplace_var_idx_map.at(0)); | |||
| 735 | } else { | |||
| 736 | return ToPyObject(value); | |||
| 737 | } | |||
| 738 | } | |||
| 739 | ||||
| 740 | PyObject* ToPyObject(PyObject* args, ssize_t arg_idx) { | |||
| 741 | // For inplace op, directly return the input PyObject of the inplace tensor. | |||
| 742 | // [Parameter] | |||
| 743 | // args: Input PyObject. | |||
| 744 | // arg_idx: Index of inplace PyObject in input args. Used to find the input | |||
| 745 | // inplace PyObject. | |||
| 746 | PyObject* obj = PyTuple_GET_ITEM(args, arg_idx)(((PyTupleObject *)(args))->ob_item[arg_idx]); | |||
| 747 | Py_INCREF(obj)_Py_INCREF(((PyObject*)(obj))); | |||
| 748 | return obj; | |||
| 749 | } | |||
| 750 | ||||
| 751 | PyObject* ToPyObject(const std::vector<bool>& value) { | |||
| 752 | PyObject* result = PyList_New((Py_ssize_t)value.size()); | |||
| 753 | ||||
| 754 | for (size_t i = 0; i < value.size(); i++) { | |||
| 755 |     PyList_SET_ITEM(result, static_cast<Py_ssize_t>(i), ToPyObject(value[i]))PyList_SetItem(result, static_cast<Py_ssize_t>(i), ToPyObject (value[i]));  | |||
| 756 | } | |||
| 757 | ||||
| 758 | return result; | |||
| 759 | } | |||
| 760 | ||||
| 761 | PyObject* ToPyObject(const std::vector<int>& value) { | |||
| 762 | PyObject* result = PyList_New((Py_ssize_t)value.size()); | |||
| 763 | ||||
| 764 | for (size_t i = 0; i < value.size(); i++) { | |||
| 765 |     PyList_SET_ITEM(result, static_cast<Py_ssize_t>(i), ToPyObject(value[i]))PyList_SetItem(result, static_cast<Py_ssize_t>(i), ToPyObject (value[i]));  | |||
| 766 | } | |||
| 767 | ||||
| 768 | return result; | |||
| 769 | } | |||
| 770 | ||||
| 771 | PyObject* ToPyObject(const std::vector<int64_t>& value) { | |||
| 772 | PyObject* result = PyList_New((Py_ssize_t)value.size()); | |||
| 773 | ||||
| 774 | for (size_t i = 0; i < value.size(); i++) { | |||
| 775 | PyList_SET_ITEM(result, (Py_ssize_t)i, ToPyObject(value[i]))PyList_SetItem(result, (Py_ssize_t)i, ToPyObject(value[i])); | |||
| 776 | } | |||
| 777 | ||||
| 778 | return result; | |||
| 779 | } | |||
| 780 | ||||
| 781 | PyObject* ToPyObject(const std::vector<size_t>& value) { | |||
| 782 | PyObject* result = PyList_New((Py_ssize_t)value.size()); | |||
| 783 | ||||
| 784 | for (size_t i = 0; i < value.size(); i++) { | |||
| 785 | PyList_SET_ITEM(result, (Py_ssize_t)i, ToPyObject(value[i]))PyList_SetItem(result, (Py_ssize_t)i, ToPyObject(value[i])); | |||
| 786 | } | |||
| 787 | ||||
| 788 | return result; | |||
| 789 | } | |||
| 790 | ||||
| 791 | PyObject* ToPyObject(const std::vector<float>& value) { | |||
| 792 | PyObject* result = PyList_New((Py_ssize_t)value.size()); | |||
| 793 | ||||
| 794 | for (size_t i = 0; i < value.size(); i++) { | |||
| 795 |     PyList_SET_ITEM(result, static_cast<Py_ssize_t>(i), ToPyObject(value[i]))PyList_SetItem(result, static_cast<Py_ssize_t>(i), ToPyObject (value[i]));  | |||
| 796 | } | |||
| 797 | ||||
| 798 | return result; | |||
| 799 | } | |||
| 800 | ||||
| 801 | PyObject* ToPyObject(const std::vector<double>& value) { | |||
| 802 | PyObject* result = PyList_New((Py_ssize_t)value.size()); | |||
| 803 | ||||
| 804 | for (size_t i = 0; i < value.size(); i++) { | |||
| 805 |     PyList_SET_ITEM(result, static_cast<Py_ssize_t>(i), ToPyObject(value[i]))PyList_SetItem(result, static_cast<Py_ssize_t>(i), ToPyObject (value[i]));  | |||
| 806 | } | |||
| 807 | ||||
| 808 | return result; | |||
| 809 | } | |||
| 810 | ||||
| 811 | PyObject* ToPyObject(const std::vector<std::vector<size_t>>& value) { | |||
| 812 | PyObject* result = PyList_New((Py_ssize_t)value.size()); | |||
| 813 | ||||
| 814 | for (size_t i = 0; i < value.size(); i++) { | |||
| 815 |     PyList_SET_ITEM(result, static_cast<Py_ssize_t>(i), ToPyObject(value[i]))PyList_SetItem(result, static_cast<Py_ssize_t>(i), ToPyObject (value[i]));  | |||
| 816 | } | |||
| 817 | ||||
| 818 | return result; | |||
| 819 | } | |||
| 820 | ||||
| 821 | PyObject* ToPyObject(const std::vector<paddle::Tensor>& value, | |||
| 822 | bool return_py_none_if_not_initialize) { | |||
| 823 | // NOTE(liuyuanle): I encountered a bug(access violation) in windows. ref to | |||
| 824 | // https://stackoverflow.com/questions/55598839/how-to-fix-access-violation-error-when-returning-pyobject-from-c-function-usin | |||
| 825 | #ifdef _WIN32 | |||
| 826 | PyGILState_STATE gstate = PyGILState_Ensure(); | |||
| 827 | #endif | |||
| 828 | PyObject* result = PyList_New((Py_ssize_t)value.size()); | |||
| 829 | #ifdef _WIN32 | |||
| 830 | PyGILState_Release(gstate); | |||
| 831 | #endif | |||
| 832 | ||||
| 833 | for (size_t i = 0; i < value.size(); i++) { | |||
| 834 | if (!value[i].initialized() && return_py_none_if_not_initialize) { | |||
| 835 | Py_INCREF(Py_None)_Py_INCREF(((PyObject*)((&_Py_NoneStruct)))); | |||
| 836 |       PyList_SET_ITEM(result, static_cast<Py_ssize_t>(i), Py_None)PyList_SetItem(result, static_cast<Py_ssize_t>(i), (& _Py_NoneStruct));  | |||
| 837 | } else { | |||
| 838 | PyObject* obj = p_tensor_type->tp_alloc(p_tensor_type, 0); | |||
| 839 | if (obj) { | |||
| 840 | auto v = reinterpret_cast<TensorObject*>(obj); | |||
| 841 | new (&(v->tensor)) paddle::Tensor(); | |||
| 842 | v->tensor = value[i]; | |||
| 843 | } else { | |||
| 844 |         PADDLE_THROW(platform::errors::Fatal(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal( "tp_alloc return null, can not new a PyObject." )), "../../../../paddle/fluid/pybind/eager_utils.cc", 845); } while (0)  | |||
| 845 |             "tp_alloc return null, can not new a PyObject."))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal( "tp_alloc return null, can not new a PyObject." )), "../../../../paddle/fluid/pybind/eager_utils.cc", 845); } while (0);  | |||
| 846 | } | |||
| 847 | PyList_SET_ITEM(result, static_cast<Py_ssize_t>(i), obj)PyList_SetItem(result, static_cast<Py_ssize_t>(i), obj); | |||
| 848 | } | |||
| 849 | } | |||
| 850 | ||||
| 851 | return result; | |||
| 852 | } | |||
| 853 | ||||
| 854 | PyObject* ToPyObject(const std::vector<std::vector<paddle::Tensor>>& value, | |||
| 855 | bool return_py_none_if_not_initialize) { | |||
| 856 | PyObject* result = PyList_New((Py_ssize_t)value.size()); | |||
| 857 | ||||
| 858 | for (size_t i = 0; i < value.size(); i++) { | |||
| 859 |     PyList_SET_ITEM(result,PyList_SetItem(result, static_cast<Py_ssize_t>(i), ToPyObject (value[i], return_py_none_if_not_initialize))  | |||
| 860 |                     static_cast<Py_ssize_t>(i),PyList_SetItem(result, static_cast<Py_ssize_t>(i), ToPyObject (value[i], return_py_none_if_not_initialize))  | |||
| 861 |                     ToPyObject(value[i], return_py_none_if_not_initialize))PyList_SetItem(result, static_cast<Py_ssize_t>(i), ToPyObject (value[i], return_py_none_if_not_initialize));  | |||
| 862 | } | |||
| 863 | ||||
| 864 | return result; | |||
| 865 | } | |||
| 866 | ||||
| 867 | PyObject* ToPyObject(const platform::Place& value) { | |||
| 868 | auto obj = ::pybind11::cast(value); | |||
| 869 | obj.inc_ref(); | |||
| 870 | return obj.ptr(); | |||
| 871 | } | |||
| 872 | ||||
| 873 | PyObject* ToPyObject(const paddle::framework::proto::VarType::Type& dtype) { | |||
| 874 | auto obj = ::pybind11::cast(dtype); | |||
| 875 | obj.inc_ref(); | |||
| 876 | return obj.ptr(); | |||
| 877 | } | |||
| 878 | ||||
| 879 | PyObject* ToPyObject(const paddle::framework::proto::VarType& type) { | |||
| 880 | auto obj = ::pybind11::cast(type); | |||
| 881 | obj.inc_ref(); | |||
| 882 | return obj.ptr(); | |||
| 883 | } | |||
| 884 | ||||
| 885 | PyObject* ToPyObject(const phi::DenseTensor* value) { | |||
| 886 | auto obj = ::pybind11::cast(value, py::return_value_policy::reference); | |||
| 887 | obj.inc_ref(); | |||
| 888 | return obj.ptr(); | |||
| 889 | } | |||
| 890 | ||||
| 891 | PyObject* ToPyObject(const ir::OpResult& value) { | |||
| 892 | auto obj = ::pybind11::cast(value); | |||
| 893 | obj.inc_ref(); | |||
| 894 | return obj.ptr(); | |||
| 895 | } | |||
| 896 | ||||
| 897 | PyObject* ToPyObject(const std::vector<ir::OpResult>& value) { | |||
| 898 | PyObject* result = PyList_New((Py_ssize_t)value.size()); | |||
| 899 | ||||
| 900 | for (size_t i = 0; i < value.size(); i++) { | |||
| 901 |     PyList_SET_ITEM(result, static_cast<Py_ssize_t>(i), ToPyObject(value[i]))PyList_SetItem(result, static_cast<Py_ssize_t>(i), ToPyObject (value[i]));  | |||
| 902 | } | |||
| 903 | ||||
| 904 | return result; | |||
| 905 | } | |||
| 906 | ||||
| 907 | PyObject* ToPyObject(const phi::distributed::DistTensor* value) { | |||
| 908 | #ifdef PADDLE_WITH_DISTRIBUTE | |||
| 909 | auto obj = ::pybind11::cast(value, py::return_value_policy::reference); | |||
| 910 | obj.inc_ref(); | |||
| 911 | return obj.ptr(); | |||
| 912 | #else | |||
| 913 |   PADDLE_THROW(platform::errors::Unavailable(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Unavailable( "DistTensor to PyObject is not supported in the current " "PaddlePaddle, please recompile and installPaddlePaddle with the option " "of `WITH_DISTRIBUTE=ON`.")), "../../../../paddle/fluid/pybind/eager_utils.cc" , 916); } while (0)  | |||
| 914 |       "DistTensor to PyObject is not supported in the current "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Unavailable( "DistTensor to PyObject is not supported in the current " "PaddlePaddle, please recompile and installPaddlePaddle with the option " "of `WITH_DISTRIBUTE=ON`.")), "../../../../paddle/fluid/pybind/eager_utils.cc" , 916); } while (0)  | |||
| 915 |       "PaddlePaddle, please recompile and installPaddlePaddle with the option "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Unavailable( "DistTensor to PyObject is not supported in the current " "PaddlePaddle, please recompile and installPaddlePaddle with the option " "of `WITH_DISTRIBUTE=ON`.")), "../../../../paddle/fluid/pybind/eager_utils.cc" , 916); } while (0)  | |||
| 916 |       "of `WITH_DISTRIBUTE=ON`."))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Unavailable( "DistTensor to PyObject is not supported in the current " "PaddlePaddle, please recompile and installPaddlePaddle with the option " "of `WITH_DISTRIBUTE=ON`.")), "../../../../paddle/fluid/pybind/eager_utils.cc" , 916); } while (0);  | |||
| 917 | #endif | |||
| 918 | } | |||
| 919 | ||||
| 920 | PyObject* ToPyObject(const phi::distributed::TensorDistAttr* value) { | |||
| 921 | #ifdef PADDLE_WITH_DISTRIBUTE | |||
| 922 | auto obj = ::pybind11::cast(value, py::return_value_policy::reference); | |||
| 923 | obj.inc_ref(); | |||
| 924 | return obj.ptr(); | |||
| 925 | #else | |||
| 926 |   PADDLE_THROW(platform::errors::Unavailable(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Unavailable( "TensorDistAttr to PyObject is not supported in the current " "PaddlePaddle, please recompile and installPaddlePaddle with the option " "of `WITH_DISTRIBUTE=ON`.")), "../../../../paddle/fluid/pybind/eager_utils.cc" , 929); } while (0)  | |||
| 927 |       "TensorDistAttr to PyObject is not supported in the current "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Unavailable( "TensorDistAttr to PyObject is not supported in the current " "PaddlePaddle, please recompile and installPaddlePaddle with the option " "of `WITH_DISTRIBUTE=ON`.")), "../../../../paddle/fluid/pybind/eager_utils.cc" , 929); } while (0)  | |||
| 928 |       "PaddlePaddle, please recompile and installPaddlePaddle with the option "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Unavailable( "TensorDistAttr to PyObject is not supported in the current " "PaddlePaddle, please recompile and installPaddlePaddle with the option " "of `WITH_DISTRIBUTE=ON`.")), "../../../../paddle/fluid/pybind/eager_utils.cc" , 929); } while (0)  | |||
| 929 |       "of `WITH_DISTRIBUTE=ON`."))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Unavailable( "TensorDistAttr to PyObject is not supported in the current " "PaddlePaddle, please recompile and installPaddlePaddle with the option " "of `WITH_DISTRIBUTE=ON`.")), "../../../../paddle/fluid/pybind/eager_utils.cc" , 929); } while (0);  | |||
| 930 | #endif | |||
| 931 | } | |||
| 932 | ||||
| 933 | PyObject* ToPyObject(const phi::SelectedRows* value) { | |||
| 934 | auto obj = ::pybind11::cast(value, py::return_value_policy::reference); | |||
| 935 | obj.inc_ref(); | |||
| 936 | return obj.ptr(); | |||
| 937 | } | |||
| 938 | ||||
| 939 | PyObject* ToPyObject(const void* value) { | |||
| 940 | if (value == nullptr) { | |||
| 941 |     RETURN_PY_NONE_Py_INCREF(((PyObject*)((&_Py_NoneStruct)))); return (& _Py_NoneStruct);  | |||
| 942 | } | |||
| 943 |   PADDLE_THROW(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal("ToPyObject do not support void* with value." )), "../../../../paddle/fluid/pybind/eager_utils.cc", 944); } while (0)  | |||
| 944 |       platform::errors::Fatal("ToPyObject do not support void* with value."))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal("ToPyObject do not support void* with value." )), "../../../../paddle/fluid/pybind/eager_utils.cc", 944); } while (0);  | |||
| 945 | } | |||
| 946 | ||||
| 947 | PyObject* ToPyObject(const std::unordered_map<int, int>& value) { | |||
| 948 | PyObject* dict = PyDict_New(); | |||
| 949 | for (const auto& map_iter : value) { | |||
| 950 | // Convert Key | |||
| 951 | PyObject* key = ToPyObject(map_iter.first); | |||
| 952 | // Convert Value | |||
| 953 | PyObject* value = ToPyObject(map_iter.second); | |||
| 954 | ||||
| 955 | if (!key || !value) { | |||
| 956 |       PADDLE_THROW(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal("Unable to convert int to PyObject") ), "../../../../paddle/fluid/pybind/eager_utils.cc", 957); } while (0)  | |||
| 957 |           platform::errors::Fatal("Unable to convert int to PyObject"))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal("Unable to convert int to PyObject") ), "../../../../paddle/fluid/pybind/eager_utils.cc", 957); } while (0);  | |||
| 958 | } | |||
| 959 | ||||
| 960 | if (PyDict_SetItem(dict, key, value) != 0) { | |||
| 961 |       PADDLE_THROW(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal("Unable to set key:value for py_dict" )), "../../../../paddle/fluid/pybind/eager_utils.cc", 962); } while (0)  | |||
| 962 |           platform::errors::Fatal("Unable to set key:value for py_dict"))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal("Unable to set key:value for py_dict" )), "../../../../paddle/fluid/pybind/eager_utils.cc", 962); } while (0);  | |||
| 963 | } | |||
| 964 | } | |||
| 965 | return dict; | |||
| 966 | } | |||
| 967 | ||||
| 968 | PyObject* ToPyObject( | |||
| 969 | const std::unordered_map<std::string, std::vector<std::string>>& value) { | |||
| 970 | PyObject* dict = PyDict_New(); | |||
| 971 | for (const auto& map_iter : value) { | |||
| 972 | // Convert Key | |||
| 973 | PyObject* key_string = PyUnicode_FromString(map_iter.first.c_str()); | |||
| 974 | if (!key_string) { | |||
| 975 |       PADDLE_THROW(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal("Unable to convert std::string to PyObject" )), "../../../../paddle/fluid/pybind/eager_utils.cc", 976); } while (0)  | |||
| 976 |           platform::errors::Fatal("Unable to convert std::string to PyObject"))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal("Unable to convert std::string to PyObject" )), "../../../../paddle/fluid/pybind/eager_utils.cc", 976); } while (0);  | |||
| 977 | } | |||
| 978 | ||||
| 979 | // Convert Val | |||
| 980 | PyObject* py_list = PyList_New(0); | |||
| 981 | for (const auto& vector_iter : map_iter.second) { | |||
| 982 | PyObject* val_string = PyUnicode_FromString(vector_iter.c_str()); | |||
| 983 | if (!val_string) { | |||
| 984 |         PADDLE_THROW(platform::errors::Fatal(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal( "Unable to convert std::string to PyObject" )), "../../../../paddle/fluid/pybind/eager_utils.cc", 985); } while (0)  | |||
| 985 |             "Unable to convert std::string to PyObject"))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal( "Unable to convert std::string to PyObject" )), "../../../../paddle/fluid/pybind/eager_utils.cc", 985); } while (0);  | |||
| 986 | } | |||
| 987 | ||||
| 988 | if (PyList_Append(py_list, val_string) != 0) { | |||
| 989 |         PADDLE_THROW(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal("Unable to append string to py_list" )), "../../../../paddle/fluid/pybind/eager_utils.cc", 990); } while (0)  | |||
| 990 |             platform::errors::Fatal("Unable to append string to py_list"))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal("Unable to append string to py_list" )), "../../../../paddle/fluid/pybind/eager_utils.cc", 990); } while (0);  | |||
| 991 | } | |||
| 992 | Py_DECREF(val_string)_Py_DECREF(((PyObject*)(val_string))); | |||
| 993 | } | |||
| 994 | ||||
| 995 | if (PyDict_SetItem(dict, key_string, py_list) != 0) { | |||
| 996 |       PADDLE_THROW(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal("Unable to set key:value for py_dict" )), "../../../../paddle/fluid/pybind/eager_utils.cc", 997); } while (0)  | |||
| 997 |           platform::errors::Fatal("Unable to set key:value for py_dict"))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal("Unable to set key:value for py_dict" )), "../../../../paddle/fluid/pybind/eager_utils.cc", 997); } while (0);  | |||
| 998 | } | |||
| 999 | Py_DECREF(py_list)_Py_DECREF(((PyObject*)(py_list))); | |||
| 1000 | Py_DECREF(key_string)_Py_DECREF(((PyObject*)(key_string))); | |||
| 1001 | } | |||
| 1002 | ||||
| 1003 | return dict; | |||
| 1004 | } | |||
| 1005 | ||||
| 1006 | PyObject* ToPyObject(const paddle::framework::Vocab& value) { | |||
| 1007 | PyObject* dict = PyDict_New(); | |||
| 1008 | for (const auto& map_iter : value) { | |||
| 1009 | // Convert Key | |||
| 1010 | PyObject* key_string = | |||
| 1011 | PyUnicode_FromWideChar(map_iter.first.c_str(), map_iter.first.size()); | |||
| 1012 | if (!key_string) { | |||
| 1013 |       PADDLE_THROW(platform::errors::Fatal(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal( "Unable to convert std::wstring to PyObject" )), "../../../../paddle/fluid/pybind/eager_utils.cc", 1014); } while (0)  | |||
| 1014 |           "Unable to convert std::wstring to PyObject"))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal( "Unable to convert std::wstring to PyObject" )), "../../../../paddle/fluid/pybind/eager_utils.cc", 1014); } while (0);  | |||
| 1015 | } | |||
| 1016 | ||||
| 1017 | // Convert Val | |||
| 1018 | PyObject* py_int = PyLong_FromLong(map_iter.second); | |||
| 1019 | ||||
| 1020 | if (PyDict_SetItem(dict, key_string, py_int) != 0) { | |||
| 1021 |       PADDLE_THROW(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal("Unable to set key:value for py_dict" )), "../../../../paddle/fluid/pybind/eager_utils.cc", 1022); } while (0)  | |||
| 1022 |           platform::errors::Fatal("Unable to set key:value for py_dict"))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal("Unable to set key:value for py_dict" )), "../../../../paddle/fluid/pybind/eager_utils.cc", 1022); } while (0);  | |||
| 1023 | } | |||
| 1024 | } | |||
| 1025 | return dict; | |||
| 1026 | } | |||
| 1027 | ||||
| 1028 | // For Final State Dygraph, | |||
| 1029 | // We directly use paddle::optional(Tensor) as dispensable Tensor | |||
| 1030 | paddle::optional<paddle::Tensor> GetOptionalTensorFromArgs( | |||
| 1031 | const std::string& op_type, | |||
| 1032 | const std::string& arg_name, | |||
| 1033 | PyObject* args, | |||
| 1034 | ssize_t arg_idx, | |||
| 1035 | bool dispensable) { | |||
| 1036 | PyObject* obj = PyTuple_GET_ITEM(args, arg_idx)(((PyTupleObject *)(args))->ob_item[arg_idx]); | |||
| 1037 | ||||
| 1038 |   if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 1039 | obj = PyTuple_GET_ITEM(obj, 0)(((PyTupleObject *)(obj))->ob_item[0]); | |||
| 1040 | } | |||
| 1041 | ||||
| 1042 | if (obj == nullptr || obj == Py_None(&_Py_NoneStruct)) { | |||
| 1043 | if (!dispensable) { | |||
| 1044 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1048); } while (0)  | |||
| 1045 |           "%s(): argument '%s' (position %d) must be Tensor, but got None",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1048); } while (0)  | |||
| 1046 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1048); } while (0)  | |||
| 1047 |           arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1048); } while (0)  | |||
| 1048 |           arg_idx))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1048); } while (0);  | |||
| 1049 | } | |||
| 1050 | return paddle::none; | |||
| 1051 | } | |||
| 1052 | ||||
| 1053 |   if (PyObject_TypeCheck(obj, p_tensor_type)((((PyObject*)(obj))->ob_type) == (p_tensor_type) || PyType_IsSubtype ((((PyObject*)(obj))->ob_type), (p_tensor_type)))) {  | |||
| 1054 | return paddle::make_optional<paddle::Tensor>( | |||
| 1055 | reinterpret_cast<TensorObject*>(obj)->tensor); | |||
| 1056 | } else { | |||
| 1057 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1062); } while (0)  | |||
| 1058 |         "%s(): argument '%s' (position %d) must be Tensor, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1062); } while (0)  | |||
| 1059 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1062); } while (0)  | |||
| 1060 |         arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1062); } while (0)  | |||
| 1061 |         arg_idx,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1062); } while (0)  | |||
| 1062 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1062); } while (0);  | |||
| 1063 | } | |||
| 1064 | } | |||
| 1065 | ||||
| 1066 | PyObject* ToPyObject(std::shared_ptr<egr::GradNodeBase> grad_node) { | |||
| 1067 | py::object py_obj = py::cast(grad_node, py::return_value_policy::reference); | |||
| 1068 | PyObject* py_grad_node = py_obj.release().ptr(); | |||
| 1069 | Py_INCREF(py_grad_node)_Py_INCREF(((PyObject*)(py_grad_node))); | |||
| 1070 | return py_grad_node; | |||
| 1071 | } | |||
| 1072 | ||||
| 1073 | static paddle::Tensor& GetTensorFromPyObject(const std::string& op_type, | |||
| 1074 | const std::string& arg_name, | |||
| 1075 | PyObject* obj, | |||
| 1076 | ssize_t arg_idx, | |||
| 1077 | bool dispensable) { | |||
| 1078 |   if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 1079 | obj = PyTuple_GET_ITEM(obj, 0)(((PyTupleObject *)(obj))->ob_item[0]); | |||
| 1080 | } | |||
| 1081 | ||||
| 1082 | if (obj == nullptr || obj == Py_None(&_Py_NoneStruct)) { | |||
| 1083 | if (!dispensable) { | |||
| 1084 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1088); } while (0)  | |||
| 1085 |           "%s(): argument '%s' (position %d) must be Tensor, but got None",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1088); } while (0)  | |||
| 1086 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1088); } while (0)  | |||
| 1087 |           arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1088); } while (0)  | |||
| 1088 |           arg_idx))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1088); } while (0);  | |||
| 1089 | } | |||
| 1090 | static paddle::Tensor emptytensor; | |||
| 1091 | return emptytensor; | |||
| 1092 | } | |||
| 1093 | ||||
| 1094 |   if (PyObject_TypeCheck(obj, p_tensor_type)((((PyObject*)(obj))->ob_type) == (p_tensor_type) || PyType_IsSubtype ((((PyObject*)(obj))->ob_type), (p_tensor_type)))) {  | |||
| 1095 | return reinterpret_cast<TensorObject*>(obj)->tensor; | |||
| 1096 |   } else if (PyObject_TypeCheck(obj, p_string_tensor_type)((((PyObject*)(obj))->ob_type) == (p_string_tensor_type) || PyType_IsSubtype((((PyObject*)(obj))->ob_type), (p_string_tensor_type )))) {  | |||
| 1097 | return reinterpret_cast<TensorObject*>(obj)->tensor; | |||
| 1098 | } else { | |||
| 1099 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1104); } while (0)  | |||
| 1100 |         "%s(): argument '%s' (position %d) must be Tensor, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1104); } while (0)  | |||
| 1101 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1104); } while (0)  | |||
| 1102 |         arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1104); } while (0)  | |||
| 1103 |         arg_idx,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1104); } while (0)  | |||
| 1104 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1104); } while (0);  | |||
| 1105 | } | |||
| 1106 | } | |||
| 1107 | ||||
| 1108 | // For Intermediate State Dygraph, | |||
| 1109 | // we use an uninitialized Tensor to represent dispensable Tensor | |||
| 1110 | paddle::Tensor& GetTensorFromArgs(const std::string& op_type, | |||
| 1111 | const std::string& arg_name, | |||
| 1112 | PyObject* args, | |||
| 1113 | ssize_t arg_idx, | |||
| 1114 | bool dispensable) { | |||
| 1115 | PyObject* obj = PyTuple_GET_ITEM(args, arg_idx)(((PyTupleObject *)(args))->ob_item[arg_idx]); | |||
| 1116 | return GetTensorFromPyObject(op_type, arg_name, obj, arg_idx, dispensable); | |||
| 1117 | } | |||
| 1118 | ||||
| 1119 | std::vector<paddle::Tensor> GetTensorListFromArgs(const std::string& op_type, | |||
| 1120 | const std::string& arg_name, | |||
| 1121 | PyObject* args, | |||
| 1122 | ssize_t arg_idx, | |||
| 1123 | bool dispensable) { | |||
| 1124 | PyObject* list = PyTuple_GET_ITEM(args, arg_idx)(((PyTupleObject *)(args))->ob_item[arg_idx]); | |||
| 1125 | ||||
| 1126 | if (list == nullptr) { | |||
| 1127 | if (!dispensable) { | |||
| 1128 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1133); } while (0)  | |||
| 1129 |           "%s(): argument '%s' (position %d) must be list of Tensor, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1133); } while (0)  | |||
| 1130 |           "None",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1133); } while (0)  | |||
| 1131 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1133); } while (0)  | |||
| 1132 |           arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1133); } while (0)  | |||
| 1133 |           arg_idx))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1133); } while (0);  | |||
| 1134 | } | |||
| 1135 | return {}; | |||
| 1136 | } | |||
| 1137 | ||||
| 1138 | std::vector<paddle::Tensor> result; | |||
| 1139 | ||||
| 1140 |   if (PyList_Check(list)((((((PyObject*)(list))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 1141 | Py_ssize_t len = PyList_Size(list); | |||
| 1142 | result.reserve(static_cast<size_t>(len)); | |||
| 1143 | if (len == 0) { | |||
| 1144 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1149); } while (0)  | |||
| 1145 |           "%s(): argument '%s' (position %d) must be list of Tensors, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1149); } while (0)  | |||
| 1146 |           "empty list",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1149); } while (0)  | |||
| 1147 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1149); } while (0)  | |||
| 1148 |           arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1149); } while (0)  | |||
| 1149 |           arg_idx))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1149); } while (0);  | |||
| 1150 | } | |||
| 1151 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 1152 | result.emplace_back( | |||
| 1153 | reinterpret_cast<TensorObject*>(PyList_GetItem(list, i))->tensor); | |||
| 1154 | } | |||
| 1155 |   } else if (PyTuple_Check(list)((((((PyObject*)(list))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 1156 | Py_ssize_t len = PyTuple_Size(list); | |||
| 1157 | result.reserve(static_cast<size_t>(len)); | |||
| 1158 | if (len == 0) { | |||
| 1159 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1164); } while (0)  | |||
| 1160 |           "%s(): argument '%s' (position %d) must be list of Tensors, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1164); } while (0)  | |||
| 1161 |           "empty list",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1164); } while (0)  | |||
| 1162 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1164); } while (0)  | |||
| 1163 |           arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1164); } while (0)  | |||
| 1164 |           arg_idx))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1164); } while (0);  | |||
| 1165 | } | |||
| 1166 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 1167 | result.emplace_back( | |||
| 1168 | reinterpret_cast<TensorObject*>(PyTuple_GetItem(list, i))->tensor); | |||
| 1169 | } | |||
| 1170 | } else if (list == Py_None(&_Py_NoneStruct)) { | |||
| 1171 | return {}; | |||
| 1172 | } else { | |||
| 1173 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1179); } while (0)  | |||
| 1174 |         "%s(): argument '%s' (position %d) must be list of Tensors, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1179); } while (0)  | |||
| 1175 |         "%s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1179); } while (0)  | |||
| 1176 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1179); } while (0)  | |||
| 1177 |         arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1179); } while (0)  | |||
| 1178 |         arg_idx,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1179); } while (0)  | |||
| 1179 |         (reinterpret_cast<PyTypeObject*>(list->ob_type))->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1179); } while (0);  | |||
| 1180 | } | |||
| 1181 | ||||
| 1182 | return result; | |||
| 1183 | } | |||
| 1184 | ||||
| 1185 | paddle::optional<std::vector<paddle::Tensor>> GetOptionalTensorListFromArgs( | |||
| 1186 | const std::string& op_type, | |||
| 1187 | const std::string& arg_name, | |||
| 1188 | PyObject* args, | |||
| 1189 | ssize_t arg_idx, | |||
| 1190 | bool dispensable) { | |||
| 1191 | PyObject* list = PyTuple_GET_ITEM(args, arg_idx)(((PyTupleObject *)(args))->ob_item[arg_idx]); | |||
| 1192 | ||||
| 1193 | if (list == nullptr || list == Py_None(&_Py_NoneStruct)) { | |||
| 1194 | if (!dispensable) { | |||
| 1195 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1200); } while (0)  | |||
| 1196 |           "%s(): argument '%s' (position %d) must be list of Tensor, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1200); } while (0)  | |||
| 1197 |           "None",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1200); } while (0)  | |||
| 1198 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1200); } while (0)  | |||
| 1199 |           arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1200); } while (0)  | |||
| 1200 |           arg_idx))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1200); } while (0);  | |||
| 1201 | } | |||
| 1202 | return paddle::none; | |||
| 1203 | } | |||
| 1204 | ||||
| 1205 | std::vector<paddle::Tensor> result; | |||
| 1206 | ||||
| 1207 |   if (PyList_Check(list)((((((PyObject*)(list))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 1208 | Py_ssize_t len = PyList_Size(list); | |||
| 1209 | result.reserve(static_cast<size_t>(len)); | |||
| 1210 | if (len == 0) { | |||
| 1211 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1216); } while (0)  | |||
| 1212 |           "%s(): argument '%s' (position %d) must be list of Tensors, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1216); } while (0)  | |||
| 1213 |           "empty list",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1216); } while (0)  | |||
| 1214 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1216); } while (0)  | |||
| 1215 |           arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1216); } while (0)  | |||
| 1216 |           arg_idx))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1216); } while (0);  | |||
| 1217 | } | |||
| 1218 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 1219 | result.emplace_back( | |||
| 1220 | reinterpret_cast<TensorObject*>(PyList_GetItem(list, i))->tensor); | |||
| 1221 | } | |||
| 1222 |   } else if (PyTuple_Check(list)((((((PyObject*)(list))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 1223 | Py_ssize_t len = PyTuple_Size(list); | |||
| 1224 | result.reserve(static_cast<size_t>(len)); | |||
| 1225 | if (len == 0) { | |||
| 1226 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1231); } while (0)  | |||
| 1227 |           "%s(): argument '%s' (position %d) must be list of Tensors, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1231); } while (0)  | |||
| 1228 |           "empty list",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1231); } while (0)  | |||
| 1229 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1231); } while (0)  | |||
| 1230 |           arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1231); } while (0)  | |||
| 1231 |           arg_idx))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1231); } while (0);  | |||
| 1232 | } | |||
| 1233 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 1234 | result.emplace_back( | |||
| 1235 | reinterpret_cast<TensorObject*>(PyTuple_GetItem(list, i))->tensor); | |||
| 1236 | } | |||
| 1237 | } else { | |||
| 1238 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1244); } while (0)  | |||
| 1239 |         "%s(): argument '%s' (position %d) must be list of Tensors, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1244); } while (0)  | |||
| 1240 |         "%s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1244); } while (0)  | |||
| 1241 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1244); } while (0)  | |||
| 1242 |         arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1244); } while (0)  | |||
| 1243 |         arg_idx,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1244); } while (0)  | |||
| 1244 |         (reinterpret_cast<PyTypeObject*>(list->ob_type))->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1244); } while (0);  | |||
| 1245 | } | |||
| 1246 | ||||
| 1247 | return result; | |||
| 1248 | } | |||
| 1249 | ||||
| 1250 | paddle::Tensor* GetTensorPtrFromArgs(const std::string& op_type, | |||
| 1251 | const std::string& arg_name, | |||
| 1252 | PyObject* args, | |||
| 1253 | ssize_t arg_idx, | |||
| 1254 | bool dispensable) { | |||
| 1255 | PyObject* obj = PyTuple_GET_ITEM(args, arg_idx)(((PyTupleObject *)(args))->ob_item[arg_idx]); | |||
| 1256 | ||||
| 1257 |   if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 1258 | obj = PyTuple_GET_ITEM(obj, 0)(((PyTupleObject *)(obj))->ob_item[0]); | |||
| 1259 | } | |||
| 1260 | ||||
| 1261 | if (obj == nullptr || obj == Py_None(&_Py_NoneStruct)) { | |||
| 1262 | if (!dispensable) { | |||
| 1263 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1267); } while (0)  | |||
| 1264 |           "%s(): argument '%s' (position %d) must be Tensor, but got None",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1267); } while (0)  | |||
| 1265 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1267); } while (0)  | |||
| 1266 |           arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1267); } while (0)  | |||
| 1267 |           arg_idx))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got None" , op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1267); } while (0);  | |||
| 1268 | } | |||
| 1269 | static paddle::Tensor emptytensor; | |||
| 1270 | return &emptytensor; | |||
| 1271 | } | |||
| 1272 | ||||
| 1273 |   if (PyObject_TypeCheck(obj, p_tensor_type)((((PyObject*)(obj))->ob_type) == (p_tensor_type) || PyType_IsSubtype ((((PyObject*)(obj))->ob_type), (p_tensor_type)))) {  | |||
| 1274 | return &(reinterpret_cast<TensorObject*>(obj)->tensor); | |||
| 1275 | } else { | |||
| 1276 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1281); } while (0)  | |||
| 1277 |         "%s(): argument '%s' (position %d) must be Tensor, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1281); } while (0)  | |||
| 1278 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1281); } while (0)  | |||
| 1279 |         arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1281); } while (0)  | |||
| 1280 |         arg_idx,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1281); } while (0)  | |||
| 1281 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be Tensor, but got %s" , op_type, arg_name, arg_idx, reinterpret_cast<PyTypeObject *>(obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1281); } while (0);  | |||
| 1282 | } | |||
| 1283 | } | |||
| 1284 | ||||
| 1285 | std::vector<paddle::Tensor*> GetTensorPtrListFromArgs( | |||
| 1286 | const std::string& op_type, | |||
| 1287 | const std::string& arg_name, | |||
| 1288 | PyObject* args, | |||
| 1289 | ssize_t arg_idx, | |||
| 1290 | bool dispensable) { | |||
| 1291 | PyObject* list = PyTuple_GET_ITEM(args, arg_idx)(((PyTupleObject *)(args))->ob_item[arg_idx]); | |||
| 1292 | ||||
| 1293 | if (list == nullptr) { | |||
| 1294 | if (!dispensable) { | |||
| 1295 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1300); } while (0)  | |||
| 1296 |           "%s(): argument '%s' (position %d) must be list of Tensor, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1300); } while (0)  | |||
| 1297 |           "None",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1300); } while (0)  | |||
| 1298 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1300); } while (0)  | |||
| 1299 |           arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1300); } while (0)  | |||
| 1300 |           arg_idx))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensor, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1300); } while (0);  | |||
| 1301 | } | |||
| 1302 | return {}; | |||
| 1303 | } | |||
| 1304 | ||||
| 1305 | std::vector<paddle::Tensor*> result; | |||
| 1306 | ||||
| 1307 |   if (PyList_Check(list)((((((PyObject*)(list))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 1308 | Py_ssize_t len = PyList_Size(list); | |||
| 1309 | if (len == 0) { | |||
| 1310 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1315); } while (0)  | |||
| 1311 |           "%s(): argument '%s' (position %d) must be list of Tensors, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1315); } while (0)  | |||
| 1312 |           "empty list",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1315); } while (0)  | |||
| 1313 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1315); } while (0)  | |||
| 1314 |           arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1315); } while (0)  | |||
| 1315 |           arg_idx))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1315); } while (0);  | |||
| 1316 | } | |||
| 1317 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 1318 | result.emplace_back( | |||
| 1319 | &(reinterpret_cast<TensorObject*>(PyList_GetItem(list, i))->tensor)); | |||
| 1320 | } | |||
| 1321 |   } else if (PyTuple_Check(list)((((((PyObject*)(list))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 1322 | Py_ssize_t len = PyTuple_Size(list); | |||
| 1323 | if (len == 0) { | |||
| 1324 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1329); } while (0)  | |||
| 1325 |           "%s(): argument '%s' (position %d) must be list of Tensors, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1329); } while (0)  | |||
| 1326 |           "empty list",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1329); } while (0)  | |||
| 1327 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1329); } while (0)  | |||
| 1328 |           arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1329); } while (0)  | |||
| 1329 |           arg_idx))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1329); } while (0);  | |||
| 1330 | } | |||
| 1331 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 1332 | result.emplace_back( | |||
| 1333 | &(reinterpret_cast<TensorObject*>(PyTuple_GetItem(list, i))->tensor)); | |||
| 1334 | } | |||
| 1335 | } else if (list == Py_None(&_Py_NoneStruct)) { | |||
| 1336 | return {}; | |||
| 1337 | } else { | |||
| 1338 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1344); } while (0)  | |||
| 1339 |         "%s(): argument '%s' (position %d) must be list of Tensors, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1344); } while (0)  | |||
| 1340 |         "%s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1344); } while (0)  | |||
| 1341 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1344); } while (0)  | |||
| 1342 |         arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1344); } while (0)  | |||
| 1343 |         arg_idx,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1344); } while (0)  | |||
| 1344 |         (reinterpret_cast<PyTypeObject*>(list->ob_type))->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1344); } while (0);  | |||
| 1345 | } | |||
| 1346 | ||||
| 1347 | return result; | |||
| 1348 | } | |||
| 1349 | ||||
| 1350 | std::vector<paddle::Tensor*> GetTensorPtrListFromPyObject(PyObject* obj) { | |||
| 1351 | std::vector<paddle::Tensor*> result; | |||
| 1352 | ||||
| 1353 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 1354 | Py_ssize_t len = PyList_Size(obj); | |||
| 1355 | if (len == 0) { | |||
| 1356 |       PADDLE_THROW(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument("The list of Tensor is empty." )), "../../../../paddle/fluid/pybind/eager_utils.cc", 1357); } while (0)  | |||
| 1357 |           platform::errors::InvalidArgument("The list of Tensor is empty."))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument("The list of Tensor is empty." )), "../../../../paddle/fluid/pybind/eager_utils.cc", 1357); } while (0);  | |||
| 1358 | } | |||
| 1359 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 1360 | result.emplace_back( | |||
| 1361 | &(reinterpret_cast<TensorObject*>(PyList_GetItem(obj, i))->tensor)); | |||
| 1362 | } | |||
| 1363 |   } else if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 1364 | Py_ssize_t len = PyTuple_Size(obj); | |||
| 1365 | if (len == 0) { | |||
| 1366 |       PADDLE_THROW(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument("The tuple of Tensor is empty." )), "../../../../paddle/fluid/pybind/eager_utils.cc", 1367); } while (0)  | |||
| 1367 |           platform::errors::InvalidArgument("The tuple of Tensor is empty."))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument("The tuple of Tensor is empty." )), "../../../../paddle/fluid/pybind/eager_utils.cc", 1367); } while (0);  | |||
| 1368 | } | |||
| 1369 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 1370 | result.emplace_back( | |||
| 1371 | &(reinterpret_cast<TensorObject*>(PyTuple_GetItem(obj, i))->tensor)); | |||
| 1372 | } | |||
| 1373 | } else { | |||
| 1374 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "The PyObject must be list of Tensors, but got " "%s", (reinterpret_cast<PyTypeObject*>(obj->ob_type ))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1377); } while (0)  | |||
| 1375 |         "The PyObject must be list of Tensors, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "The PyObject must be list of Tensors, but got " "%s", (reinterpret_cast<PyTypeObject*>(obj->ob_type ))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1377); } while (0)  | |||
| 1376 |         "%s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "The PyObject must be list of Tensors, but got " "%s", (reinterpret_cast<PyTypeObject*>(obj->ob_type ))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1377); } while (0)  | |||
| 1377 |         (reinterpret_cast<PyTypeObject*>(obj->ob_type))->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "The PyObject must be list of Tensors, but got " "%s", (reinterpret_cast<PyTypeObject*>(obj->ob_type ))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1377); } while (0);  | |||
| 1378 | } | |||
| 1379 | ||||
| 1380 | return result; | |||
| 1381 | } | |||
| 1382 | ||||
| 1383 | std::vector<paddle::Tensor> GetTensorListFromPyObject(PyObject* obj, | |||
| 1384 | bool allow_none) { | |||
| 1385 | std::vector<paddle::Tensor> result; | |||
| 1386 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 1387 | Py_ssize_t len = PyList_Size(obj); | |||
| 1388 | PyObject* item = nullptr; | |||
| 1389 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 1390 | item = PyList_GetItem(obj, i); | |||
| 1391 |       if (PyObject_TypeCheck(item, p_tensor_type)((((PyObject*)(item))->ob_type) == (p_tensor_type) || PyType_IsSubtype ((((PyObject*)(item))->ob_type), (p_tensor_type)))) {  | |||
| 1392 | result.emplace_back(reinterpret_cast<TensorObject*>(item)->tensor); | |||
| 1393 | } else if (allow_none && (item == Py_None(&_Py_NoneStruct))) { | |||
| 1394 |         VLOG(4)static_cast<void>(0), !(__extension__ ({ static google:: int32* vlocal__ = &google::kLogSiteUninitialized; google:: int32 verbose_level__ = (4); (*vlocal__ >= verbose_level__ ) && ((vlocal__ != &google::kLogSiteUninitialized ) || (google::InitVLOG3__(&vlocal__, &FLAGS_v, "../../../../paddle/fluid/pybind/eager_utils.cc" , verbose_level__))); })) ? (void) 0 : google::LogMessageVoidify () & google::LogMessage( "../../../../paddle/fluid/pybind/eager_utils.cc" , 1394).stream() << "Got None in Tensor list: " << i;  | |||
| 1395 | result.emplace_back(); | |||
| 1396 | } else { | |||
| 1397 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument must be " "list of Tensor, but got %s at pos %d" , reinterpret_cast<PyTypeObject*>(item->ob_type)-> tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1401); } while (0)  | |||
| 1398 |             "argument must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument must be " "list of Tensor, but got %s at pos %d" , reinterpret_cast<PyTypeObject*>(item->ob_type)-> tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1401); } while (0)  | |||
| 1399 |             "list of Tensor, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument must be " "list of Tensor, but got %s at pos %d" , reinterpret_cast<PyTypeObject*>(item->ob_type)-> tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1401); } while (0)  | |||
| 1400 |             reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument must be " "list of Tensor, but got %s at pos %d" , reinterpret_cast<PyTypeObject*>(item->ob_type)-> tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1401); } while (0)  | |||
| 1401 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument must be " "list of Tensor, but got %s at pos %d" , reinterpret_cast<PyTypeObject*>(item->ob_type)-> tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1401); } while (0);  | |||
| 1402 | } | |||
| 1403 | } | |||
| 1404 |   } else if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 1405 | Py_ssize_t len = PyTuple_Size(obj); | |||
| 1406 | PyObject* item = nullptr; | |||
| 1407 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 1408 | item = PyTuple_GetItem(obj, i); | |||
| 1409 |       if (PyObject_TypeCheck(item, p_tensor_type)((((PyObject*)(item))->ob_type) == (p_tensor_type) || PyType_IsSubtype ((((PyObject*)(item))->ob_type), (p_tensor_type)))) {  | |||
| 1410 | result.emplace_back(reinterpret_cast<TensorObject*>(item)->tensor); | |||
| 1411 | } else if (allow_none && (item == Py_None(&_Py_NoneStruct))) { | |||
| 1412 |         VLOG(4)static_cast<void>(0), !(__extension__ ({ static google:: int32* vlocal__ = &google::kLogSiteUninitialized; google:: int32 verbose_level__ = (4); (*vlocal__ >= verbose_level__ ) && ((vlocal__ != &google::kLogSiteUninitialized ) || (google::InitVLOG3__(&vlocal__, &FLAGS_v, "../../../../paddle/fluid/pybind/eager_utils.cc" , verbose_level__))); })) ? (void) 0 : google::LogMessageVoidify () & google::LogMessage( "../../../../paddle/fluid/pybind/eager_utils.cc" , 1412).stream() << "Got None in Tensor list: " << i;  | |||
| 1413 | result.emplace_back(); | |||
| 1414 | } else { | |||
| 1415 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument must be " "list of Tensor, but got %s at pos %d" , reinterpret_cast<PyTypeObject*>(item->ob_type)-> tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1419); } while (0)  | |||
| 1416 |             "argument must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument must be " "list of Tensor, but got %s at pos %d" , reinterpret_cast<PyTypeObject*>(item->ob_type)-> tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1419); } while (0)  | |||
| 1417 |             "list of Tensor, but got %s at pos %d",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument must be " "list of Tensor, but got %s at pos %d" , reinterpret_cast<PyTypeObject*>(item->ob_type)-> tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1419); } while (0)  | |||
| 1418 |             reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument must be " "list of Tensor, but got %s at pos %d" , reinterpret_cast<PyTypeObject*>(item->ob_type)-> tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1419); } while (0)  | |||
| 1419 |             i))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument must be " "list of Tensor, but got %s at pos %d" , reinterpret_cast<PyTypeObject*>(item->ob_type)-> tp_name, i)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1419); } while (0);  | |||
| 1420 | } | |||
| 1421 | } | |||
| 1422 | } else { | |||
| 1423 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument must be " "list or tuple, but got %s" , reinterpret_cast<PyTypeObject*>(obj->ob_type)-> tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc", 1426 ); } while (0)  | |||
| 1424 |         "argument must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument must be " "list or tuple, but got %s" , reinterpret_cast<PyTypeObject*>(obj->ob_type)-> tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc", 1426 ); } while (0)  | |||
| 1425 |         "list or tuple, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument must be " "list or tuple, but got %s" , reinterpret_cast<PyTypeObject*>(obj->ob_type)-> tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc", 1426 ); } while (0)  | |||
| 1426 |         reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "argument must be " "list or tuple, but got %s" , reinterpret_cast<PyTypeObject*>(obj->ob_type)-> tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc", 1426 ); } while (0);  | |||
| 1427 | } | |||
| 1428 | return result; | |||
| 1429 | } | |||
| 1430 | ||||
| 1431 | paddle::Tensor& UnSafeGetTensorFromPyObject(PyObject* obj) { | |||
| 1432 | return reinterpret_cast<TensorObject*>(obj)->tensor; | |||
| 1433 | } | |||
| 1434 | paddle::experimental::Scalar CastNumpy2Scalar(PyObject* obj, | |||
| 1435 | const std::string& op_type, | |||
| 1436 | ssize_t arg_pos) { | |||
| 1437 | PyTypeObject* type = obj->ob_type; | |||
| 1438 | auto type_name = std::string(type->tp_name); | |||
| 1439 |   VLOG(4)static_cast<void>(0), !(__extension__ ({ static google:: int32* vlocal__ = &google::kLogSiteUninitialized; google:: int32 verbose_level__ = (4); (*vlocal__ >= verbose_level__ ) && ((vlocal__ != &google::kLogSiteUninitialized ) || (google::InitVLOG3__(&vlocal__, &FLAGS_v, "../../../../paddle/fluid/pybind/eager_utils.cc" , verbose_level__))); })) ? (void) 0 : google::LogMessageVoidify () & google::LogMessage( "../../../../paddle/fluid/pybind/eager_utils.cc" , 1439).stream() << "type_name: " << type_name;  | |||
| 1440 | if (type_name == "numpy.ndarray" && PySequence_Check(obj)) { | |||
| 1441 | PyObject* item = nullptr; | |||
| 1442 | item = PySequence_GetItem(obj, 0); | |||
| 1443 | if (PyObject_CheckFloatOrToFloat(&item)) { | |||
| 1444 | float value = static_cast<float>(PyFloat_AsDouble(item)); | |||
| 1445 | return paddle::experimental::Scalar(value); | |||
| 1446 | } else { | |||
| 1447 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) is numpy.ndarray, the inner elements " "must be " "numpy.float32/float64 now, but got %s", op_type, arg_pos + 1, type_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1453); } while (0)  | |||
| 1448 |           "%s(): argument (position %d) is numpy.ndarray, the inner elements "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) is numpy.ndarray, the inner elements " "must be " "numpy.float32/float64 now, but got %s", op_type, arg_pos + 1, type_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1453); } while (0)  | |||
| 1449 |           "must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) is numpy.ndarray, the inner elements " "must be " "numpy.float32/float64 now, but got %s", op_type, arg_pos + 1, type_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1453); } while (0)  | |||
| 1450 |           "numpy.float32/float64 now, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) is numpy.ndarray, the inner elements " "must be " "numpy.float32/float64 now, but got %s", op_type, arg_pos + 1, type_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1453); } while (0)  | |||
| 1451 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) is numpy.ndarray, the inner elements " "must be " "numpy.float32/float64 now, but got %s", op_type, arg_pos + 1, type_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1453); } while (0)  | |||
| 1452 |           arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) is numpy.ndarray, the inner elements " "must be " "numpy.float32/float64 now, but got %s", op_type, arg_pos + 1, type_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1453); } while (0)  | |||
| 1453 |           type_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) is numpy.ndarray, the inner elements " "must be " "numpy.float32/float64 now, but got %s", op_type, arg_pos + 1, type_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1453); } while (0); // NOLINT  | |||
| 1454 | } | |||
| 1455 | } else if (type_name == "numpy.float64") { | |||
| 1456 | double value = CastPyArg2Double(obj, op_type, arg_pos); | |||
| 1457 | return paddle::experimental::Scalar(value); | |||
| 1458 | } else if (type_name == "numpy.float32") { | |||
| 1459 | float value = CastPyArg2Float(obj, op_type, arg_pos); | |||
| 1460 | return paddle::experimental::Scalar(value); | |||
| 1461 | } else if (type_name == "numpy.float16") { | |||
| 1462 | float16 value = CastPyArg2Float16(obj, op_type, arg_pos); | |||
| 1463 | return paddle::experimental::Scalar(value); | |||
| 1464 | } else if (type_name == "numpy.int64") { | |||
| 1465 | int64_t value = CastPyArg2Long(obj, op_type, arg_pos); | |||
| 1466 | return paddle::experimental::Scalar(value); | |||
| 1467 | } else if (type_name == "numpy.int32" || type_name == "numpy.intc") { | |||
| 1468 | int value = CastPyArg2Int(obj, op_type, arg_pos); | |||
| 1469 | return paddle::experimental::Scalar(value); | |||
| 1470 | } else if (type_name == "numpy.complex64") { | |||
| 1471 | phi::dtype::complex<float> value = CastPyArg2Complex(obj, op_type, arg_pos); | |||
| 1472 | return paddle::experimental::Scalar(value); | |||
| 1473 | } else if (type_name == "numpy.complex128") { | |||
| 1474 | phi::dtype::complex<double> value = | |||
| 1475 | CastPyArg2Complex128(obj, op_type, arg_pos); | |||
| 1476 | return paddle::experimental::Scalar(value); | |||
| 1477 | } else { | |||
| 1478 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "numpy.float32/float64, numpy.int32/int64, numpy.complex64/complex128, " "but got %s", op_type, arg_pos + 1, type_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1484); } while (0)  | |||
| 1479 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "numpy.float32/float64, numpy.int32/int64, numpy.complex64/complex128, " "but got %s", op_type, arg_pos + 1, type_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1484); } while (0)  | |||
| 1480 |         "numpy.float32/float64, numpy.int32/int64, numpy.complex64/complex128, "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "numpy.float32/float64, numpy.int32/int64, numpy.complex64/complex128, " "but got %s", op_type, arg_pos + 1, type_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1484); } while (0)  | |||
| 1481 |         "but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "numpy.float32/float64, numpy.int32/int64, numpy.complex64/complex128, " "but got %s", op_type, arg_pos + 1, type_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1484); } while (0)  | |||
| 1482 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "numpy.float32/float64, numpy.int32/int64, numpy.complex64/complex128, " "but got %s", op_type, arg_pos + 1, type_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1484); } while (0)  | |||
| 1483 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "numpy.float32/float64, numpy.int32/int64, numpy.complex64/complex128, " "but got %s", op_type, arg_pos + 1, type_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1484); } while (0)  | |||
| 1484 |         type_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "numpy.float32/float64, numpy.int32/int64, numpy.complex64/complex128, " "but got %s", op_type, arg_pos + 1, type_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1484); } while (0); // NOLINT  | |||
| 1485 | } | |||
| 1486 | } | |||
| 1487 | ||||
| 1488 | ir::OpResult CastPyArg2OpResult(PyObject* obj, | |||
| 1489 | const std::string& op_type, | |||
| 1490 | size_t arg_pos) { | |||
| 1491 |   if (PyObject_TypeCheck(obj, g_ir_opresult_pytype)((((PyObject*)(obj))->ob_type) == (g_ir_opresult_pytype) || PyType_IsSubtype((((PyObject*)(obj))->ob_type), (g_ir_opresult_pytype )))) {  | |||
| 1492 | return ::pybind11::handle(obj).cast<ir::OpResult>(); | |||
| 1493 | } else if (obj == nullptr || obj == Py_None(&_Py_NoneStruct)) { | |||
| 1494 | return ir::OpResult(); | |||
| 1495 | } else { | |||
| 1496 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "OpResult, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1501); } while (0)  | |||
| 1497 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "OpResult, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1501); } while (0)  | |||
| 1498 |         "OpResult, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "OpResult, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1501); } while (0)  | |||
| 1499 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "OpResult, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1501); } while (0)  | |||
| 1500 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "OpResult, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1501); } while (0)  | |||
| 1501 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "OpResult, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1501); } while (0); // NOLINT  | |||
| 1502 | } | |||
| 1503 | } | |||
| 1504 | ||||
| 1505 | std::vector<ir::OpResult> CastPyArg2VectorOfOpResult(PyObject* obj, | |||
| 1506 | const std::string& op_type, | |||
| 1507 | size_t arg_pos) { | |||
| 1508 | std::vector<ir::OpResult> result_list; | |||
| 1509 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 1510 | Py_ssize_t len = PyList_Size(obj); | |||
| 1511 | PyObject* item = nullptr; | |||
| 1512 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 1513 | item = PyList_GetItem(obj, i); | |||
| 1514 |       if (PyObject_TypeCheck(item, g_ir_opresult_pytype)((((PyObject*)(item))->ob_type) == (g_ir_opresult_pytype) || PyType_IsSubtype((((PyObject*)(item))->ob_type), (g_ir_opresult_pytype )))) {  | |||
| 1515 | result_list.emplace_back(::pybind11::handle(item).cast<ir::OpResult>()); | |||
| 1516 | } else if (item == Py_None(&_Py_NoneStruct)) { | |||
| 1517 | continue; | |||
| 1518 | } else { | |||
| 1519 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "vector<OpResult>, but got vector<%s>", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(item-> ob_type) ->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1525); } while (0)  | |||
| 1520 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "vector<OpResult>, but got vector<%s>", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(item-> ob_type) ->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1525); } while (0)  | |||
| 1521 |             "vector<OpResult>, but got vector<%s>",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "vector<OpResult>, but got vector<%s>", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(item-> ob_type) ->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1525); } while (0)  | |||
| 1522 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "vector<OpResult>, but got vector<%s>", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(item-> ob_type) ->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1525); } while (0)  | |||
| 1523 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "vector<OpResult>, but got vector<%s>", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(item-> ob_type) ->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1525); } while (0)  | |||
| 1524 |             reinterpret_cast<PyTypeObject*>(item->ob_type)do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "vector<OpResult>, but got vector<%s>", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(item-> ob_type) ->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1525); } while (0)  | |||
| 1525 |                 ->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "vector<OpResult>, but got vector<%s>", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(item-> ob_type) ->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1525); } while (0); // NOLINT  | |||
| 1526 | } | |||
| 1527 | } | |||
| 1528 |   } else if (PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 1529 | Py_ssize_t len = PyTuple_Size(obj); | |||
| 1530 | PyObject* item = nullptr; | |||
| 1531 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 1532 | item = PyTuple_GetItem(obj, i); | |||
| 1533 |       if (PyObject_TypeCheck(item, g_ir_opresult_pytype)((((PyObject*)(item))->ob_type) == (g_ir_opresult_pytype) || PyType_IsSubtype((((PyObject*)(item))->ob_type), (g_ir_opresult_pytype )))) {  | |||
| 1534 | result_list.emplace_back(::pybind11::handle(item).cast<ir::OpResult>()); | |||
| 1535 | } else if (item == Py_None(&_Py_NoneStruct)) { | |||
| 1536 | continue; | |||
| 1537 | } else { | |||
| 1538 |         PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "vector<OpResult>, but got vector<%s>", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(item-> ob_type) ->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1544); } while (0)  | |||
| 1539 |             "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "vector<OpResult>, but got vector<%s>", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(item-> ob_type) ->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1544); } while (0)  | |||
| 1540 |             "vector<OpResult>, but got vector<%s>",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "vector<OpResult>, but got vector<%s>", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(item-> ob_type) ->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1544); } while (0)  | |||
| 1541 |             op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "vector<OpResult>, but got vector<%s>", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(item-> ob_type) ->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1544); } while (0)  | |||
| 1542 |             arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "vector<OpResult>, but got vector<%s>", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(item-> ob_type) ->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1544); } while (0)  | |||
| 1543 |             reinterpret_cast<PyTypeObject*>(item->ob_type)do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "vector<OpResult>, but got vector<%s>", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(item-> ob_type) ->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1544); } while (0)  | |||
| 1544 |                 ->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "vector<OpResult>, but got vector<%s>", op_type, arg_pos + 1, reinterpret_cast<PyTypeObject*>(item-> ob_type) ->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1544); } while (0); // NOLINT  | |||
| 1545 | } | |||
| 1546 | } | |||
| 1547 |   } else if (PyObject_TypeCheck(obj, g_ir_opresult_pytype)((((PyObject*)(obj))->ob_type) == (g_ir_opresult_pytype) || PyType_IsSubtype((((PyObject*)(obj))->ob_type), (g_ir_opresult_pytype )))) {  | |||
| 1548 | return {::pybind11::handle(obj).cast<ir::OpResult>()}; | |||
| 1549 | } else if (obj == Py_None(&_Py_NoneStruct)) { | |||
| 1550 | return {}; | |||
| 1551 | } else { | |||
| 1552 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "Vector<>, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1557); } while (0)  | |||
| 1553 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "Vector<>, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1557); } while (0)  | |||
| 1554 |         "Vector<>, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "Vector<>, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1557); } while (0)  | |||
| 1555 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "Vector<>, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1557); } while (0)  | |||
| 1556 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "Vector<>, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1557); } while (0)  | |||
| 1557 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "Vector<>, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1557); } while (0); // NOLINT  | |||
| 1558 | } | |||
| 1559 | return result_list; | |||
| 1560 | } | |||
| 1561 | ||||
| 1562 | paddle::experimental::Scalar CastPyArg2Scalar(PyObject* obj, | |||
| 1563 | const std::string& op_type, | |||
| 1564 | ssize_t arg_pos) { | |||
| 1565 | if (obj == Py_None(&_Py_NoneStruct)) { | |||
| 1566 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, float, bool or Tensor, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1571); } while (0)  | |||
| 1567 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, float, bool or Tensor, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1571); } while (0)  | |||
| 1568 |         "int, float, bool or Tensor, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, float, bool or Tensor, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1571); } while (0)  | |||
| 1569 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, float, bool or Tensor, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1571); } while (0)  | |||
| 1570 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, float, bool or Tensor, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1571); } while (0)  | |||
| 1571 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, float, bool or Tensor, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1571); } while (0); // NOLINT  | |||
| 1572 | } | |||
| 1573 | ||||
| 1574 | // obj could be: int, float, bool, paddle.Tensor | |||
| 1575 | PyTypeObject* type = obj->ob_type; | |||
| 1576 | auto type_name = std::string(type->tp_name); | |||
| 1577 |   VLOG(4)static_cast<void>(0), !(__extension__ ({ static google:: int32* vlocal__ = &google::kLogSiteUninitialized; google:: int32 verbose_level__ = (4); (*vlocal__ >= verbose_level__ ) && ((vlocal__ != &google::kLogSiteUninitialized ) || (google::InitVLOG3__(&vlocal__, &FLAGS_v, "../../../../paddle/fluid/pybind/eager_utils.cc" , verbose_level__))); })) ? (void) 0 : google::LogMessageVoidify () & google::LogMessage( "../../../../paddle/fluid/pybind/eager_utils.cc" , 1577).stream() << "type_name: " << type_name;  | |||
| 1578 | if (PyBool_Check(obj)((((PyObject*)(obj))->ob_type) == &PyBool_Type)) { | |||
| 1579 | bool value = CastPyArg2Boolean(obj, op_type, arg_pos); | |||
| 1580 | return paddle::experimental::Scalar(value); | |||
| 1581 |   } else if (PyLong_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 24))) != 0)) {  | |||
| 1582 | int64_t value = CastPyArg2Long(obj, op_type, arg_pos); | |||
| 1583 | return paddle::experimental::Scalar(value); | |||
| 1584 |   } else if (PyFloat_Check(obj)((((PyObject*)(obj))->ob_type) == (&PyFloat_Type) || PyType_IsSubtype ((((PyObject*)(obj))->ob_type), (&PyFloat_Type)))) {  | |||
| 1585 | double value = CastPyArg2Double(obj, op_type, arg_pos); | |||
| 1586 | return paddle::experimental::Scalar(value); | |||
| 1587 | } else if (PyCheckTensor(obj)) { | |||
| 1588 | paddle::Tensor& value = GetTensorFromPyObject( | |||
| 1589 | op_type, "" /*arg_name*/, obj, arg_pos, false /*dispensable*/); | |||
| 1590 | return paddle::experimental::Scalar(value); | |||
| 1591 | } else if (type_name.find("numpy") != std::string::npos) { | |||
| 1592 | return CastNumpy2Scalar(obj, op_type, arg_pos); | |||
| 1593 |   } else if (PyComplex_Check(obj)((((PyObject*)(obj))->ob_type) == (&PyComplex_Type) || PyType_IsSubtype((((PyObject*)(obj))->ob_type), (&PyComplex_Type )))) {  | |||
| 1594 | auto value = CastPyArg2Complex128(obj, op_type, arg_pos); | |||
| 1595 | return paddle::experimental::Scalar(value); | |||
| 1596 | } else if (PyObject_CheckLongOrToLong(&obj)) { | |||
| 1597 | int value = CastPyArg2Int(obj, op_type, arg_pos); | |||
| 1598 | return paddle::experimental::Scalar(value); | |||
| 1599 | } else if (PyObject_CheckString(obj)) { | |||
| 1600 | std::string value = CastPyArg2String(obj, op_type, arg_pos); | |||
| 1601 | return paddle::experimental::Scalar(value); | |||
| 1602 | } else { | |||
| 1603 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, float, bool or Tensor, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1608); } while (0)  | |||
| 1604 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, float, bool or Tensor, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1608); } while (0)  | |||
| 1605 |         "int, float, bool or Tensor, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, float, bool or Tensor, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1608); } while (0)  | |||
| 1606 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, float, bool or Tensor, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1608); } while (0)  | |||
| 1607 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, float, bool or Tensor, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1608); } while (0)  | |||
| 1608 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "int, float, bool or Tensor, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1608); } while (0); // NOLINT  | |||
| 1609 | } | |||
| 1610 | ||||
| 1611 | // Fake a Scalar | |||
| 1612 | return paddle::experimental::Scalar(1.0); | |||
| 1613 | } | |||
| 1614 | ||||
| 1615 | std::vector<phi::Scalar> CastPyArg2ScalarArray(PyObject* obj, | |||
| 1616 | const std::string& op_type, | |||
| 1617 | ssize_t arg_pos) { | |||
| 1618 | if (obj == Py_None(&_Py_NoneStruct)) { | |||
| 1619 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, or bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1624); } while (0)  | |||
| 1620 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, or bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1624); } while (0)  | |||
| 1621 |         "a list of int, float, or bool, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, or bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1624); } while (0)  | |||
| 1622 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, or bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1624); } while (0)  | |||
| 1623 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, or bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1624); } while (0)  | |||
| 1624 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, or bool, but got %s", op_type, arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1624); } while (0); // NOLINT  | |||
| 1625 | } | |||
| 1626 | ||||
| 1627 | PyTypeObject* type = obj->ob_type; | |||
| 1628 | auto type_name = std::string(type->tp_name); | |||
| 1629 |   VLOG(4)static_cast<void>(0), !(__extension__ ({ static google:: int32* vlocal__ = &google::kLogSiteUninitialized; google:: int32 verbose_level__ = (4); (*vlocal__ >= verbose_level__ ) && ((vlocal__ != &google::kLogSiteUninitialized ) || (google::InitVLOG3__(&vlocal__, &FLAGS_v, "../../../../paddle/fluid/pybind/eager_utils.cc" , verbose_level__))); })) ? (void) 0 : google::LogMessageVoidify () & google::LogMessage( "../../../../paddle/fluid/pybind/eager_utils.cc" , 1629).stream() << "type_name: " << type_name;  | |||
| 1630 |   if (PyList_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 1631 | Py_ssize_t len = PyList_Size(obj); | |||
| 1632 | PyObject* item = nullptr; | |||
| 1633 | item = PyList_GetItem(obj, 0); | |||
| 1634 | if (PyObject_CheckFloatOrToFloat(&item)) { | |||
| 1635 | std::vector<phi::Scalar> value; | |||
| 1636 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 1637 | item = PyList_GetItem(obj, i); | |||
| 1638 | value.emplace_back(phi::Scalar{PyFloat_AsDouble(item)}); | |||
| 1639 | } | |||
| 1640 | return value; | |||
| 1641 | } else if (PyObject_CheckLongOrToLong(&item)) { | |||
| 1642 | std::vector<phi::Scalar> value; | |||
| 1643 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 1644 | item = PyList_GetItem(obj, i); | |||
| 1645 | value.emplace_back( | |||
| 1646 | phi::Scalar{static_cast<int64_t>(PyLong_AsLong(item))}); | |||
| 1647 | } | |||
| 1648 | return value; | |||
| 1649 | } else if (PyObject_CheckComplexOrToComplex(&item)) { | |||
| 1650 | std::vector<phi::Scalar> value; | |||
| 1651 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 1652 | item = PyList_GetItem(obj, i); | |||
| 1653 | Py_complex v = PyComplex_AsCComplex(item); | |||
| 1654 | value.emplace_back(phi::Scalar{std::complex<double>(v.real, v.imag)}); | |||
| 1655 | } | |||
| 1656 | return value; | |||
| 1657 | } | |||
| 1658 | } else { | |||
| 1659 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, complex, or bool, but got %s", op_type , arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)) , "../../../../paddle/fluid/pybind/eager_utils.cc", 1664); } while (0)  | |||
| 1660 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, complex, or bool, but got %s", op_type , arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)) , "../../../../paddle/fluid/pybind/eager_utils.cc", 1664); } while (0)  | |||
| 1661 |         "a list of int, float, complex, or bool, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, complex, or bool, but got %s", op_type , arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)) , "../../../../paddle/fluid/pybind/eager_utils.cc", 1664); } while (0)  | |||
| 1662 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, complex, or bool, but got %s", op_type , arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)) , "../../../../paddle/fluid/pybind/eager_utils.cc", 1664); } while (0)  | |||
| 1663 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, complex, or bool, but got %s", op_type , arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)) , "../../../../paddle/fluid/pybind/eager_utils.cc", 1664); } while (0)  | |||
| 1664 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "a list of int, float, complex, or bool, but got %s", op_type , arg_pos + 1, ((PyTypeObject*)obj->ob_type)->tp_name)) , "../../../../paddle/fluid/pybind/eager_utils.cc", 1664); } while (0); // NOLINT  | |||
| 1665 | } | |||
| 1666 | ||||
| 1667 | // Fake a ScalarArray | |||
| 1668 | return std::vector<phi::Scalar>({phi::Scalar(1.0)}); | |||
| 1669 | } | |||
| 1670 | ||||
| 1671 | paddle::experimental::IntArray CastPyArg2IntArray(PyObject* obj, | |||
| 1672 | const std::string& op_type, | |||
| 1673 | ssize_t arg_pos) { | |||
| 1674 | if (obj == Py_None(&_Py_NoneStruct)) { | |||
| 1675 | return paddle::experimental::IntArray({}); | |||
| 1676 | } | |||
| 1677 | ||||
| 1678 | // obj could be: int, float, bool, paddle.Tensor | |||
| 1679 | PyTypeObject* type = obj->ob_type; | |||
| 1680 | auto type_name = std::string(type->tp_name); | |||
| 1681 | if (type_name == "list" || type_name == "tuple" || | |||
| 1682 | type_name == "numpy.ndarray") { | |||
| 1683 | std::vector<int64_t> value = CastPyArg2Longs(obj, op_type, arg_pos); | |||
| 1684 | return paddle::experimental::IntArray(value); | |||
| 1685 | } else if (type_name == "paddle.Tensor" || type_name == "Tensor") { | |||
| 1686 | paddle::Tensor& value = GetTensorFromPyObject( | |||
| 1687 | op_type, "" /*arg_name*/, obj, arg_pos, false /*dispensable*/); | |||
| 1688 | return paddle::experimental::IntArray(value); | |||
| 1689 | } else if (PyObject_CheckLongOrConvertToLong(&obj)) { | |||
| 1690 | return paddle::experimental::IntArray( | |||
| 1691 | {static_cast<int64_t>(PyLong_AsLong(obj))}); | |||
| 1692 | } else { | |||
| 1693 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or int, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1698); } while (0)  | |||
| 1694 |         "%s(): argument (position %d) must be "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or int, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1698); } while (0)  | |||
| 1695 |         "list or int, but got %s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or int, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1698); } while (0)  | |||
| 1696 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or int, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1698); } while (0)  | |||
| 1697 |         arg_pos + 1,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or int, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1698); } while (0)  | |||
| 1698 |         ((PyTypeObject*)obj->ob_type)->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument (position %d) must be " "list or int, but got %s", op_type, arg_pos + 1, ((PyTypeObject *)obj->ob_type)->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1698); } while (0); // NOLINT  | |||
| 1699 | } | |||
| 1700 | ||||
| 1701 | // Fake a IntArray | |||
| 1702 | return paddle::experimental::IntArray({1}); | |||
| 1703 | } | |||
| 1704 | ||||
| 1705 | paddle::framework::Scope* CastPyArg2ScopePtr(PyObject* obj) { | |||
| 1706 |   if (PyObject_TypeCheck(obj, g_framework_scope_pytype)((((PyObject*)(obj))->ob_type) == (g_framework_scope_pytype ) || PyType_IsSubtype((((PyObject*)(obj))->ob_type), (g_framework_scope_pytype )))) {  | |||
| 1707 | return ::pybind11::handle(obj).cast<paddle::framework::Scope*>(); | |||
| 1708 | } else { | |||
| 1709 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "PyObject can not be cast into framework::Scope" )), "../../../../paddle/fluid/pybind/eager_utils.cc", 1710); } while (0)  | |||
| 1710 |         "PyObject can not be cast into framework::Scope"))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "PyObject can not be cast into framework::Scope" )), "../../../../paddle/fluid/pybind/eager_utils.cc", 1710); } while (0);  | |||
| 1711 | } | |||
| 1712 | } | |||
| 1713 | ||||
| 1714 | std::vector<paddle::framework::Scope*> GetScopePtrListFromArgs( | |||
| 1715 | const std::string& op_type, | |||
| 1716 | const std::string& arg_name, | |||
| 1717 | PyObject* args, | |||
| 1718 | ssize_t arg_idx, | |||
| 1719 | bool dispensable) { | |||
| 1720 | PyObject* list = PyTuple_GET_ITEM(args, arg_idx)(((PyTupleObject *)(args))->ob_item[arg_idx]); | |||
| 1721 | if (list == nullptr) { | |||
| 1722 | if (!dispensable) { | |||
| 1723 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1728); } while (0)  | |||
| 1724 |           "%s(): argument '%s' (position %d) must be list of scope, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1728); } while (0)  | |||
| 1725 |           "None",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1728); } while (0)  | |||
| 1726 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1728); } while (0)  | |||
| 1727 |           arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1728); } while (0)  | |||
| 1728 |           arg_idx))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "None", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1728); } while (0);  | |||
| 1729 | } | |||
| 1730 | } | |||
| 1731 | ||||
| 1732 | std::vector<paddle::framework::Scope*> result; | |||
| 1733 |   if (PyList_Check(list)((((((PyObject*)(list))->ob_type))->tp_flags & ((1UL << 25))) != 0)) {  | |||
| 1734 | Py_ssize_t len = PyList_Size(list); | |||
| 1735 | if (len == 0) { | |||
| 1736 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1741); } while (0)  | |||
| 1737 |           "%s(): argument '%s' (position %d) must be list of scope, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1741); } while (0)  | |||
| 1738 |           "empty list",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1741); } while (0)  | |||
| 1739 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1741); } while (0)  | |||
| 1740 |           arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1741); } while (0)  | |||
| 1741 |           arg_idx))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1741); } while (0);  | |||
| 1742 | } | |||
| 1743 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 1744 | result.emplace_back(CastPyArg2ScopePtr(PyList_GetItem(list, i))); | |||
| 1745 | } | |||
| 1746 |   } else if (PyTuple_Check(list)((((((PyObject*)(list))->ob_type))->tp_flags & ((1UL << 26))) != 0)) {  | |||
| 1747 | Py_ssize_t len = PyTuple_Size(list); | |||
| 1748 | if (len == 0) { | |||
| 1749 |       PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1754); } while (0)  | |||
| 1750 |           "%s(): argument '%s' (position %d) must be list of scope, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1754); } while (0)  | |||
| 1751 |           "empty list",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1754); } while (0)  | |||
| 1752 |           op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1754); } while (0)  | |||
| 1753 |           arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1754); } while (0)  | |||
| 1754 |           arg_idx))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of scope, but got " "empty list", op_type, arg_name, arg_idx)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1754); } while (0);  | |||
| 1755 | } | |||
| 1756 | for (Py_ssize_t i = 0; i < len; i++) { | |||
| 1757 | result.emplace_back(CastPyArg2ScopePtr(PyList_GetItem(list, i))); | |||
| 1758 | } | |||
| 1759 | } else if (list == Py_None(&_Py_NoneStruct)) { | |||
| 1760 | return {}; | |||
| 1761 | } else { | |||
| 1762 |     PADDLE_THROW(platform::errors::InvalidArgument(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1768); } while (0)  | |||
| 1763 |         "%s(): argument '%s' (position %d) must be list of Tensors, but got "do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1768); } while (0)  | |||
| 1764 |         "%s",do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1768); } while (0)  | |||
| 1765 |         op_type,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1768); } while (0)  | |||
| 1766 |         arg_name,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1768); } while (0)  | |||
| 1767 |         arg_idx,do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1768); } while (0)  | |||
| 1768 |         (reinterpret_cast<PyTypeObject*>(list->ob_type))->tp_name))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::InvalidArgument( "%s(): argument '%s' (position %d) must be list of Tensors, but got " "%s", op_type, arg_name, arg_idx, (reinterpret_cast<PyTypeObject *>(list->ob_type))->tp_name)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1768); } while (0);  | |||
| 1769 | } | |||
| 1770 | return result; | |||
| 1771 | } | |||
| 1772 | ||||
| 1773 | paddle::Place CastPyArg2Place(PyObject* obj, | |||
| 1774 | const std::string& op_type, | |||
| 1775 | ssize_t arg_pos) { | |||
| 1776 | return CastPyArg2Place(obj, arg_pos); | |||
| 1777 | } | |||
| 1778 | ||||
| 1779 | paddle::DataType CastPyArg2DataType(PyObject* obj, | |||
| 1780 | const std::string& op_type, | |||
| 1781 | ssize_t arg_pos) { | |||
| 1782 | if (obj == Py_None(&_Py_NoneStruct)) { | |||
| 1783 | return phi::DataType::UNDEFINED; | |||
| 1784 | } | |||
| 1785 | ||||
| 1786 | framework::proto::VarType::Type type = CastPyArg2ProtoType(obj, arg_pos); | |||
| 1787 | return framework::TransToPhiDataType(type); | |||
| 1788 | } | |||
| 1789 | ||||
| 1790 | paddle::Tensor PyTensorHook::operator()(const paddle::Tensor& var) { | |||
| 1791 | py::gil_scoped_acquire gil; | |||
| 1792 |   VLOG(3)static_cast<void>(0), !(__extension__ ({ static google:: int32* vlocal__ = &google::kLogSiteUninitialized; google:: int32 verbose_level__ = (3); (*vlocal__ >= verbose_level__ ) && ((vlocal__ != &google::kLogSiteUninitialized ) || (google::InitVLOG3__(&vlocal__, &FLAGS_v, "../../../../paddle/fluid/pybind/eager_utils.cc" , verbose_level__))); })) ? (void) 0 : google::LogMessageVoidify () & google::LogMessage( "../../../../paddle/fluid/pybind/eager_utils.cc" , 1792).stream() << "Call PyTensorHook for var " << var.name();  | |||
| 1793 | ||||
| 1794 | PyObject* res = nullptr; | |||
| 1795 | try { | |||
| 1796 | PyObject* p_tmp_var = ToPyObject(var); | |||
| 1797 | res = PyObject_CallFunctionObjArgs(py_func_, p_tmp_var, nullptr); | |||
| 1798 | Py_DECREF(p_tmp_var)_Py_DECREF(((PyObject*)(p_tmp_var))); | |||
| 1799 | } catch (platform::EnforceNotMet& e) { | |||
| 1800 | throw std::move(e); | |||
| 1801 | } catch (std::exception& e) { | |||
| 1802 |     PADDLE_THROW(platform::errors::Unavailable(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Unavailable( "Hook function of Tensor raises an exception: %s." , e.what())), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1803); } while (0)  | |||
| 1803 |         "Hook function of Tensor raises an exception: %s.", e.what()))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Unavailable( "Hook function of Tensor raises an exception: %s." , e.what())), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1803); } while (0);  | |||
| 1804 | } catch (...) { | |||
| 1805 |     PADDLE_THROW(platform::errors::Fatal(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal( "Hook function of Tensor raises an unknown exception." )), "../../../../paddle/fluid/pybind/eager_utils.cc", 1806); } while (0)  | |||
| 1806 |         "Hook function of Tensor raises an unknown exception."))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal( "Hook function of Tensor raises an unknown exception." )), "../../../../paddle/fluid/pybind/eager_utils.cc", 1806); } while (0);  | |||
| 1807 | } | |||
| 1808 | ||||
| 1809 |   PADDLE_ENFORCE_NOT_NULL(res,do { if (__builtin_expect(static_cast<bool>(nullptr == ( res)), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform ::errors::External( pybind11::detail::error_string().c_str()) ); auto __message__ = ::paddle::string::Sprintf( "%s\n [Hint: " "res" " should not be null.]", __summary__.error_message()); do { throw ::phi::enforce::EnforceNotMet(phi::ErrorSummary(__summary__ .code(), std::move(__message__)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1811); } while (0); } } while (0)  | |||
| 1810 |                           paddle::platform::errors::External(do { if (__builtin_expect(static_cast<bool>(nullptr == ( res)), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform ::errors::External( pybind11::detail::error_string().c_str()) ); auto __message__ = ::paddle::string::Sprintf( "%s\n [Hint: " "res" " should not be null.]", __summary__.error_message()); do { throw ::phi::enforce::EnforceNotMet(phi::ErrorSummary(__summary__ .code(), std::move(__message__)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1811); } while (0); } } while (0)  | |||
| 1811 |                               pybind11::detail::error_string().c_str()))do { if (__builtin_expect(static_cast<bool>(nullptr == ( res)), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform ::errors::External( pybind11::detail::error_string().c_str()) ); auto __message__ = ::paddle::string::Sprintf( "%s\n [Hint: " "res" " should not be null.]", __summary__.error_message()); do { throw ::phi::enforce::EnforceNotMet(phi::ErrorSummary(__summary__ .code(), std::move(__message__)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1811); } while (0); } } while (0);  | |||
| 1812 | if (res == Py_None(&_Py_NoneStruct)) { | |||
| 1813 | return var; | |||
| 1814 | } | |||
| 1815 | auto res_tensor = reinterpret_cast<TensorObject*>(res)->tensor; | |||
| 1816 | Py_DECREF(res)_Py_DECREF(((PyObject*)(res))); | |||
| 1817 | return res_tensor; | |||
| 1818 | } | |||
| 1819 | ||||
| 1820 | void PyVoidHook::operator()() { | |||
| 1821 | py::gil_scoped_acquire gil; | |||
| 1822 |   VLOG(3)static_cast<void>(0), !(__extension__ ({ static google:: int32* vlocal__ = &google::kLogSiteUninitialized; google:: int32 verbose_level__ = (3); (*vlocal__ >= verbose_level__ ) && ((vlocal__ != &google::kLogSiteUninitialized ) || (google::InitVLOG3__(&vlocal__, &FLAGS_v, "../../../../paddle/fluid/pybind/eager_utils.cc" , verbose_level__))); })) ? (void) 0 : google::LogMessageVoidify () & google::LogMessage( "../../../../paddle/fluid/pybind/eager_utils.cc" , 1822).stream() << "Call PyVoidHook";  | |||
| 1823 | ||||
| 1824 | try { | |||
| 1825 | PyObject_CallFunctionObjArgs(py_func_, nullptr); | |||
| 1826 | } catch (platform::EnforceNotMet& e) { | |||
| 1827 | throw std::move(e); | |||
| 1828 | } catch (std::exception& e) { | |||
| 1829 |     PADDLE_THROW(platform::errors::Unavailable(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Unavailable( "Hook function of Tensor raises an exception: %s." , e.what())), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1830); } while (0)  | |||
| 1830 |         "Hook function of Tensor raises an exception: %s.", e.what()))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Unavailable( "Hook function of Tensor raises an exception: %s." , e.what())), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1830); } while (0);  | |||
| 1831 | } catch (...) { | |||
| 1832 |     PADDLE_THROW(platform::errors::Fatal(do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal( "Hook function of Tensor raises an unknown exception." )), "../../../../paddle/fluid/pybind/eager_utils.cc", 1833); } while (0)  | |||
| 1833 |         "Hook function of Tensor raises an unknown exception."))do { throw ::phi::enforce::EnforceNotMet( ::phi::ErrorSummary (platform::errors::Fatal( "Hook function of Tensor raises an unknown exception." )), "../../../../paddle/fluid/pybind/eager_utils.cc", 1833); } while (0);  | |||
| 1834 | } | |||
| 1835 | } | |||
| 1836 | ||||
| 1837 | PyObjectHolder::PyObjectHolder(PyObject* ptr) { ptr_ = ptr; } | |||
| 1838 | ||||
| 1839 | PyObjectHolder::~PyObjectHolder() { // NOLINT | |||
| 1840 | ::pybind11::gil_scoped_acquire gil; | |||
| 1841 | Py_XDECREF(ptr_)_Py_XDECREF(((PyObject*)(ptr_))); | |||
| 1842 | } | |||
| 1843 | ||||
| 1844 | void* PyObjectHolder::get() { return reinterpret_cast<void*>(ptr_); } | |||
| 1845 | ||||
| 1846 | void PyObjectHolder::reset(void* ptr) { | |||
| 1847 | if (ptr_) { | |||
| 1848 | ::pybind11::gil_scoped_acquire gil; | |||
| 1849 | Py_XDECREF(ptr_)_Py_XDECREF(((PyObject*)(ptr_))); | |||
| 1850 | } | |||
| 1851 | ptr_ = reinterpret_cast<PyObject*>(ptr); | |||
| 1852 | } | |||
| 1853 | ||||
| 1854 | void PyObjectHolder::inc_ref() { | |||
| 1855 | ::pybind11::gil_scoped_acquire gil; | |||
| 1856 | Py_XINCREF(ptr_)_Py_XINCREF(((PyObject*)(ptr_))); | |||
| 1857 | } | |||
| 1858 | void PyObjectHolder::dec_ref() { | |||
| 1859 | ::pybind11::gil_scoped_acquire gil; | |||
| 1860 | Py_XDECREF(ptr_)_Py_XDECREF(((PyObject*)(ptr_))); | |||
| 1861 | } | |||
| 1862 | ||||
| 1863 | PackHook::PackHook(PyObject* hook) : hook_(hook) { Py_INCREF(hook_)_Py_INCREF(((PyObject*)(hook_))); } | |||
| 1864 | ||||
| 1865 | PackHook::~PackHook() { // NOLINT | |||
| 1866 | ::pybind11::gil_scoped_acquire gil; | |||
| 1867 | Py_DECREF(hook_)_Py_DECREF(((PyObject*)(hook_))); | |||
| 1868 | } | |||
| 1869 | ||||
| 1870 | std::shared_ptr<egr::PyObjectHolderBase> PackHook::operator()( | |||
| 1871 | const paddle::Tensor& tensor) { | |||
| 1872 | bool grad_tmp = egr::Controller::Instance().HasGrad(); | |||
| 1873 | egr::Controller::Instance().SetHasGrad(false); | |||
| 1874 | ::pybind11::gil_scoped_acquire gil; | |||
| 1875 | auto args = PyTuple_New(1); | |||
| 1876 | PyTuple_SET_ITEM(args, 0, paddle::pybind::ToPyObject(tensor))PyTuple_SetItem(args, 0, paddle::pybind::ToPyObject(tensor)); | |||
| 1877 | PyObject* ret = PyObject_Call(hook_, args, nullptr); | |||
| 1878 |   PADDLE_ENFORCE_NOT_NULL(ret,do { if (__builtin_expect(static_cast<bool>(nullptr == ( ret)), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform ::errors::External( pybind11::detail::error_string().c_str()) ); auto __message__ = ::paddle::string::Sprintf( "%s\n [Hint: " "ret" " should not be null.]", __summary__.error_message()); do { throw ::phi::enforce::EnforceNotMet(phi::ErrorSummary(__summary__ .code(), std::move(__message__)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1880); } while (0); } } while (0)  | |||
| 1879 |                           paddle::platform::errors::External(do { if (__builtin_expect(static_cast<bool>(nullptr == ( ret)), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform ::errors::External( pybind11::detail::error_string().c_str()) ); auto __message__ = ::paddle::string::Sprintf( "%s\n [Hint: " "ret" " should not be null.]", __summary__.error_message()); do { throw ::phi::enforce::EnforceNotMet(phi::ErrorSummary(__summary__ .code(), std::move(__message__)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1880); } while (0); } } while (0)  | |||
| 1880 |                               pybind11::detail::error_string().c_str()))do { if (__builtin_expect(static_cast<bool>(nullptr == ( ret)), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform ::errors::External( pybind11::detail::error_string().c_str()) ); auto __message__ = ::paddle::string::Sprintf( "%s\n [Hint: " "ret" " should not be null.]", __summary__.error_message()); do { throw ::phi::enforce::EnforceNotMet(phi::ErrorSummary(__summary__ .code(), std::move(__message__)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1880); } while (0); } } while (0);  | |||
| 1881 | Py_XDECREF(args)_Py_XDECREF(((PyObject*)(args))); | |||
| 1882 | egr::Controller::Instance().SetHasGrad(grad_tmp); | |||
| 1883 | return std::make_shared<PyObjectHolder>(ret); | |||
| 1884 | } | |||
| 1885 | ||||
| 1886 | void* PackHook::operator()(void* py_tensor) { | |||
| 1887 | bool grad_tmp = egr::Controller::Instance().HasGrad(); | |||
| 1888 | egr::Controller::Instance().SetHasGrad(false); | |||
| 1889 | ::pybind11::gil_scoped_acquire gil; | |||
| 1890 | auto args = PyTuple_New(1); | |||
| 1891 |   Py_INCREF(reinterpret_cast<PyObject*>(py_tensor))_Py_INCREF(((PyObject*)(reinterpret_cast<PyObject*>(py_tensor ))));  | |||
| 1892 |   PyTuple_SET_ITEM(args, 0, reinterpret_cast<PyObject*>(py_tensor))PyTuple_SetItem(args, 0, reinterpret_cast<PyObject*>(py_tensor ));  | |||
| 1893 | PyObject* ret = PyObject_Call(hook_, args, nullptr); | |||
| 1894 |   PADDLE_ENFORCE_NOT_NULL(ret,do { if (__builtin_expect(static_cast<bool>(nullptr == ( ret)), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform ::errors::External( pybind11::detail::error_string().c_str()) ); auto __message__ = ::paddle::string::Sprintf( "%s\n [Hint: " "ret" " should not be null.]", __summary__.error_message()); do { throw ::phi::enforce::EnforceNotMet(phi::ErrorSummary(__summary__ .code(), std::move(__message__)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1896); } while (0); } } while (0)  | |||
| 1895 |                           paddle::platform::errors::External(do { if (__builtin_expect(static_cast<bool>(nullptr == ( ret)), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform ::errors::External( pybind11::detail::error_string().c_str()) ); auto __message__ = ::paddle::string::Sprintf( "%s\n [Hint: " "ret" " should not be null.]", __summary__.error_message()); do { throw ::phi::enforce::EnforceNotMet(phi::ErrorSummary(__summary__ .code(), std::move(__message__)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1896); } while (0); } } while (0)  | |||
| 1896 |                               pybind11::detail::error_string().c_str()))do { if (__builtin_expect(static_cast<bool>(nullptr == ( ret)), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform ::errors::External( pybind11::detail::error_string().c_str()) ); auto __message__ = ::paddle::string::Sprintf( "%s\n [Hint: " "ret" " should not be null.]", __summary__.error_message()); do { throw ::phi::enforce::EnforceNotMet(phi::ErrorSummary(__summary__ .code(), std::move(__message__)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1896); } while (0); } } while (0);  | |||
| 1897 | Py_XDECREF(args)_Py_XDECREF(((PyObject*)(args))); | |||
| 1898 | egr::Controller::Instance().SetHasGrad(grad_tmp); | |||
| 1899 | return reinterpret_cast<void*>(ret); | |||
| 1900 | } | |||
| 1901 | ||||
| 1902 | UnPackHook::UnPackHook(PyObject* hook) : hook_(hook) { Py_INCREF(hook_)_Py_INCREF(((PyObject*)(hook_))); } | |||
| 1903 | ||||
| 1904 | UnPackHook::~UnPackHook() { // NOLINT | |||
| 1905 | ::pybind11::gil_scoped_acquire gil; | |||
| 1906 | Py_DECREF(hook_)_Py_DECREF(((PyObject*)(hook_))); | |||
| 1907 | } | |||
| 1908 | ||||
| 1909 | paddle::Tensor UnPackHook::operator()( | |||
| 1910 | std::shared_ptr<egr::PyObjectHolderBase> packed_value) { | |||
| 1911 | bool grad_tmp = egr::Controller::Instance().HasGrad(); | |||
| 1912 | egr::Controller::Instance().SetHasGrad(false); | |||
| 1913 | ::pybind11::gil_scoped_acquire gil; | |||
| 1914 | auto args = PyTuple_New(1); | |||
  | ||||
  | ||||
| 1915 |   Py_INCREF(reinterpret_cast<PyObject*>(packed_value->get()))_Py_INCREF(((PyObject*)(reinterpret_cast<PyObject*>(packed_value ->get()))));  | |||
| 1916 |   PyTuple_SET_ITEM(args, 0, reinterpret_cast<PyObject*>(packed_value->get()))PyTuple_SetItem(args, 0, reinterpret_cast<PyObject*>(packed_value ->get()));  | |||
| 1917 | PyObject* ret = PyObject_Call(hook_, args, nullptr); | |||
| 1918 |   PADDLE_ENFORCE_NOT_NULL(ret,do { if (__builtin_expect(static_cast<bool>(nullptr == ( ret)), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform ::errors::External( pybind11::detail::error_string().c_str()) ); auto __message__ = ::paddle::string::Sprintf( "%s\n [Hint: " "ret" " should not be null.]", __summary__.error_message()); do { throw ::phi::enforce::EnforceNotMet(phi::ErrorSummary(__summary__ .code(), std::move(__message__)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1920); } while (0); } } while (0)  | |||
| 1919 |                           paddle::platform::errors::External(do { if (__builtin_expect(static_cast<bool>(nullptr == ( ret)), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform ::errors::External( pybind11::detail::error_string().c_str()) ); auto __message__ = ::paddle::string::Sprintf( "%s\n [Hint: " "ret" " should not be null.]", __summary__.error_message()); do { throw ::phi::enforce::EnforceNotMet(phi::ErrorSummary(__summary__ .code(), std::move(__message__)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1920); } while (0); } } while (0)  | |||
| 1920 |                               pybind11::detail::error_string().c_str()))do { if (__builtin_expect(static_cast<bool>(nullptr == ( ret)), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform ::errors::External( pybind11::detail::error_string().c_str()) ); auto __message__ = ::paddle::string::Sprintf( "%s\n [Hint: " "ret" " should not be null.]", __summary__.error_message()); do { throw ::phi::enforce::EnforceNotMet(phi::ErrorSummary(__summary__ .code(), std::move(__message__)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1920); } while (0); } } while (0);  | |||
| 1921 | Py_XDECREF(args)_Py_XDECREF(((PyObject*)(args))); | |||
| 1922 | egr::Controller::Instance().SetHasGrad(grad_tmp); | |||
| 1923 | ||||
| 1924 |   PADDLE_ENFORCE_EQ(paddle::pybind::PyCheckTensor(ret),do { auto __val1 = (paddle::pybind::PyCheckTensor(ret)); auto __val2 = (true); using __TYPE1__ = decltype(__val1); using __TYPE2__ = decltype(__val2); using __COMMON_TYPE1__ = ::phi::details:: CommonType1<__TYPE1__, __TYPE2__>; using __COMMON_TYPE2__ = ::phi::details::CommonType2<__TYPE1__, __TYPE2__>; bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1 ))==( static_cast<__COMMON_TYPE2__>(__val2)); if (__builtin_expect (static_cast<bool>(!__is_not_error), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform::errors::InvalidArgument ( "paddle.autograd.saved_tensors_hooks only one pair " "of hooks is allowed at a time." )); constexpr bool __kCanToString__ = ::phi::details::CanToString <__TYPE1__>::kValue && ::phi::details::CanToString <__TYPE2__>::kValue; auto __message__ = ::paddle::string ::Sprintf( "%s\n [Hint: Expected %s " "==" " %s, but received %s " "!=" " %s.]", __summary__.error_message(), "paddle::pybind::PyCheckTensor(ret)" , "true", ::phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("paddle::pybind::PyCheckTensor(ret)", __val1), :: phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("true", __val2)); do { throw ::phi::enforce::EnforceNotMet (phi::ErrorSummary(__summary__.code(), std::move(__message__) ), "../../../../paddle/fluid/pybind/eager_utils.cc", 1928); } while (0); } } while (0)  | |||
| 1925 |                     true,do { auto __val1 = (paddle::pybind::PyCheckTensor(ret)); auto __val2 = (true); using __TYPE1__ = decltype(__val1); using __TYPE2__ = decltype(__val2); using __COMMON_TYPE1__ = ::phi::details:: CommonType1<__TYPE1__, __TYPE2__>; using __COMMON_TYPE2__ = ::phi::details::CommonType2<__TYPE1__, __TYPE2__>; bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1 ))==( static_cast<__COMMON_TYPE2__>(__val2)); if (__builtin_expect (static_cast<bool>(!__is_not_error), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform::errors::InvalidArgument ( "paddle.autograd.saved_tensors_hooks only one pair " "of hooks is allowed at a time." )); constexpr bool __kCanToString__ = ::phi::details::CanToString <__TYPE1__>::kValue && ::phi::details::CanToString <__TYPE2__>::kValue; auto __message__ = ::paddle::string ::Sprintf( "%s\n [Hint: Expected %s " "==" " %s, but received %s " "!=" " %s.]", __summary__.error_message(), "paddle::pybind::PyCheckTensor(ret)" , "true", ::phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("paddle::pybind::PyCheckTensor(ret)", __val1), :: phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("true", __val2)); do { throw ::phi::enforce::EnforceNotMet (phi::ErrorSummary(__summary__.code(), std::move(__message__) ), "../../../../paddle/fluid/pybind/eager_utils.cc", 1928); } while (0); } } while (0)  | |||
| 1926 |                     paddle::platform::errors::InvalidArgument(do { auto __val1 = (paddle::pybind::PyCheckTensor(ret)); auto __val2 = (true); using __TYPE1__ = decltype(__val1); using __TYPE2__ = decltype(__val2); using __COMMON_TYPE1__ = ::phi::details:: CommonType1<__TYPE1__, __TYPE2__>; using __COMMON_TYPE2__ = ::phi::details::CommonType2<__TYPE1__, __TYPE2__>; bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1 ))==( static_cast<__COMMON_TYPE2__>(__val2)); if (__builtin_expect (static_cast<bool>(!__is_not_error), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform::errors::InvalidArgument ( "paddle.autograd.saved_tensors_hooks only one pair " "of hooks is allowed at a time." )); constexpr bool __kCanToString__ = ::phi::details::CanToString <__TYPE1__>::kValue && ::phi::details::CanToString <__TYPE2__>::kValue; auto __message__ = ::paddle::string ::Sprintf( "%s\n [Hint: Expected %s " "==" " %s, but received %s " "!=" " %s.]", __summary__.error_message(), "paddle::pybind::PyCheckTensor(ret)" , "true", ::phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("paddle::pybind::PyCheckTensor(ret)", __val1), :: phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("true", __val2)); do { throw ::phi::enforce::EnforceNotMet (phi::ErrorSummary(__summary__.code(), std::move(__message__) ), "../../../../paddle/fluid/pybind/eager_utils.cc", 1928); } while (0); } } while (0)  | |||
| 1927 |                         "paddle.autograd.saved_tensors_hooks only one pair "do { auto __val1 = (paddle::pybind::PyCheckTensor(ret)); auto __val2 = (true); using __TYPE1__ = decltype(__val1); using __TYPE2__ = decltype(__val2); using __COMMON_TYPE1__ = ::phi::details:: CommonType1<__TYPE1__, __TYPE2__>; using __COMMON_TYPE2__ = ::phi::details::CommonType2<__TYPE1__, __TYPE2__>; bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1 ))==( static_cast<__COMMON_TYPE2__>(__val2)); if (__builtin_expect (static_cast<bool>(!__is_not_error), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform::errors::InvalidArgument ( "paddle.autograd.saved_tensors_hooks only one pair " "of hooks is allowed at a time." )); constexpr bool __kCanToString__ = ::phi::details::CanToString <__TYPE1__>::kValue && ::phi::details::CanToString <__TYPE2__>::kValue; auto __message__ = ::paddle::string ::Sprintf( "%s\n [Hint: Expected %s " "==" " %s, but received %s " "!=" " %s.]", __summary__.error_message(), "paddle::pybind::PyCheckTensor(ret)" , "true", ::phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("paddle::pybind::PyCheckTensor(ret)", __val1), :: phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("true", __val2)); do { throw ::phi::enforce::EnforceNotMet (phi::ErrorSummary(__summary__.code(), std::move(__message__) ), "../../../../paddle/fluid/pybind/eager_utils.cc", 1928); } while (0); } } while (0)  | |||
| 1928 |                         "of hooks is allowed at a time."))do { auto __val1 = (paddle::pybind::PyCheckTensor(ret)); auto __val2 = (true); using __TYPE1__ = decltype(__val1); using __TYPE2__ = decltype(__val2); using __COMMON_TYPE1__ = ::phi::details:: CommonType1<__TYPE1__, __TYPE2__>; using __COMMON_TYPE2__ = ::phi::details::CommonType2<__TYPE1__, __TYPE2__>; bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1 ))==( static_cast<__COMMON_TYPE2__>(__val2)); if (__builtin_expect (static_cast<bool>(!__is_not_error), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform::errors::InvalidArgument ( "paddle.autograd.saved_tensors_hooks only one pair " "of hooks is allowed at a time." )); constexpr bool __kCanToString__ = ::phi::details::CanToString <__TYPE1__>::kValue && ::phi::details::CanToString <__TYPE2__>::kValue; auto __message__ = ::paddle::string ::Sprintf( "%s\n [Hint: Expected %s " "==" " %s, but received %s " "!=" " %s.]", __summary__.error_message(), "paddle::pybind::PyCheckTensor(ret)" , "true", ::phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("paddle::pybind::PyCheckTensor(ret)", __val1), :: phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("true", __val2)); do { throw ::phi::enforce::EnforceNotMet (phi::ErrorSummary(__summary__.code(), std::move(__message__) ), "../../../../paddle/fluid/pybind/eager_utils.cc", 1928); } while (0); } } while (0);  | |||
| 1929 | ||||
| 1930 | auto tensor = reinterpret_cast<paddle::pybind::TensorObject*>(ret)->tensor; | |||
| 1931 | Py_XDECREF(ret)_Py_XDECREF(((PyObject*)(ret))); | |||
| 1932 | return tensor; | |||
| 1933 | } | |||
| 1934 | ||||
| 1935 | void* UnPackHook::operator()(void* packed_value, void* other) { | |||
| 1936 | bool grad_tmp = egr::Controller::Instance().HasGrad(); | |||
| 1937 | egr::Controller::Instance().SetHasGrad(false); | |||
| 1938 | ::pybind11::gil_scoped_acquire gil; | |||
| 1939 | auto args = PyTuple_New(1); | |||
| 1940 |   Py_INCREF(reinterpret_cast<PyObject*>(packed_value))_Py_INCREF(((PyObject*)(reinterpret_cast<PyObject*>(packed_value ))));  | |||
| 1941 |   PyTuple_SET_ITEM(args, 0, reinterpret_cast<PyObject*>(packed_value))PyTuple_SetItem(args, 0, reinterpret_cast<PyObject*>(packed_value ));  | |||
| 1942 | PyObject* ret = PyObject_Call(hook_, args, nullptr); | |||
| 1943 |   PADDLE_ENFORCE_NOT_NULL(ret,do { if (__builtin_expect(static_cast<bool>(nullptr == ( ret)), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform ::errors::External( pybind11::detail::error_string().c_str()) ); auto __message__ = ::paddle::string::Sprintf( "%s\n [Hint: " "ret" " should not be null.]", __summary__.error_message()); do { throw ::phi::enforce::EnforceNotMet(phi::ErrorSummary(__summary__ .code(), std::move(__message__)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1945); } while (0); } } while (0)  | |||
| 1944 |                           paddle::platform::errors::External(do { if (__builtin_expect(static_cast<bool>(nullptr == ( ret)), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform ::errors::External( pybind11::detail::error_string().c_str()) ); auto __message__ = ::paddle::string::Sprintf( "%s\n [Hint: " "ret" " should not be null.]", __summary__.error_message()); do { throw ::phi::enforce::EnforceNotMet(phi::ErrorSummary(__summary__ .code(), std::move(__message__)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1945); } while (0); } } while (0)  | |||
| 1945 |                               pybind11::detail::error_string().c_str()))do { if (__builtin_expect(static_cast<bool>(nullptr == ( ret)), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform ::errors::External( pybind11::detail::error_string().c_str()) ); auto __message__ = ::paddle::string::Sprintf( "%s\n [Hint: " "ret" " should not be null.]", __summary__.error_message()); do { throw ::phi::enforce::EnforceNotMet(phi::ErrorSummary(__summary__ .code(), std::move(__message__)), "../../../../paddle/fluid/pybind/eager_utils.cc" , 1945); } while (0); } } while (0);  | |||
| 1946 | Py_XDECREF(args)_Py_XDECREF(((PyObject*)(args))); | |||
| 1947 | egr::Controller::Instance().SetHasGrad(grad_tmp); | |||
| 1948 | ||||
| 1949 |   PADDLE_ENFORCE_EQ(paddle::pybind::PyCheckTensor(ret),do { auto __val1 = (paddle::pybind::PyCheckTensor(ret)); auto __val2 = (true); using __TYPE1__ = decltype(__val1); using __TYPE2__ = decltype(__val2); using __COMMON_TYPE1__ = ::phi::details:: CommonType1<__TYPE1__, __TYPE2__>; using __COMMON_TYPE2__ = ::phi::details::CommonType2<__TYPE1__, __TYPE2__>; bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1 ))==( static_cast<__COMMON_TYPE2__>(__val2)); if (__builtin_expect (static_cast<bool>(!__is_not_error), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform::errors::InvalidArgument ( "paddle.autograd.saved_tensors_hooks only one pair " "of hooks is allowed at a time." )); constexpr bool __kCanToString__ = ::phi::details::CanToString <__TYPE1__>::kValue && ::phi::details::CanToString <__TYPE2__>::kValue; auto __message__ = ::paddle::string ::Sprintf( "%s\n [Hint: Expected %s " "==" " %s, but received %s " "!=" " %s.]", __summary__.error_message(), "paddle::pybind::PyCheckTensor(ret)" , "true", ::phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("paddle::pybind::PyCheckTensor(ret)", __val1), :: phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("true", __val2)); do { throw ::phi::enforce::EnforceNotMet (phi::ErrorSummary(__summary__.code(), std::move(__message__) ), "../../../../paddle/fluid/pybind/eager_utils.cc", 1953); } while (0); } } while (0)  | |||
| 1950 |                     true,do { auto __val1 = (paddle::pybind::PyCheckTensor(ret)); auto __val2 = (true); using __TYPE1__ = decltype(__val1); using __TYPE2__ = decltype(__val2); using __COMMON_TYPE1__ = ::phi::details:: CommonType1<__TYPE1__, __TYPE2__>; using __COMMON_TYPE2__ = ::phi::details::CommonType2<__TYPE1__, __TYPE2__>; bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1 ))==( static_cast<__COMMON_TYPE2__>(__val2)); if (__builtin_expect (static_cast<bool>(!__is_not_error), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform::errors::InvalidArgument ( "paddle.autograd.saved_tensors_hooks only one pair " "of hooks is allowed at a time." )); constexpr bool __kCanToString__ = ::phi::details::CanToString <__TYPE1__>::kValue && ::phi::details::CanToString <__TYPE2__>::kValue; auto __message__ = ::paddle::string ::Sprintf( "%s\n [Hint: Expected %s " "==" " %s, but received %s " "!=" " %s.]", __summary__.error_message(), "paddle::pybind::PyCheckTensor(ret)" , "true", ::phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("paddle::pybind::PyCheckTensor(ret)", __val1), :: phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("true", __val2)); do { throw ::phi::enforce::EnforceNotMet (phi::ErrorSummary(__summary__.code(), std::move(__message__) ), "../../../../paddle/fluid/pybind/eager_utils.cc", 1953); } while (0); } } while (0)  | |||
| 1951 |                     paddle::platform::errors::InvalidArgument(do { auto __val1 = (paddle::pybind::PyCheckTensor(ret)); auto __val2 = (true); using __TYPE1__ = decltype(__val1); using __TYPE2__ = decltype(__val2); using __COMMON_TYPE1__ = ::phi::details:: CommonType1<__TYPE1__, __TYPE2__>; using __COMMON_TYPE2__ = ::phi::details::CommonType2<__TYPE1__, __TYPE2__>; bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1 ))==( static_cast<__COMMON_TYPE2__>(__val2)); if (__builtin_expect (static_cast<bool>(!__is_not_error), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform::errors::InvalidArgument ( "paddle.autograd.saved_tensors_hooks only one pair " "of hooks is allowed at a time." )); constexpr bool __kCanToString__ = ::phi::details::CanToString <__TYPE1__>::kValue && ::phi::details::CanToString <__TYPE2__>::kValue; auto __message__ = ::paddle::string ::Sprintf( "%s\n [Hint: Expected %s " "==" " %s, but received %s " "!=" " %s.]", __summary__.error_message(), "paddle::pybind::PyCheckTensor(ret)" , "true", ::phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("paddle::pybind::PyCheckTensor(ret)", __val1), :: phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("true", __val2)); do { throw ::phi::enforce::EnforceNotMet (phi::ErrorSummary(__summary__.code(), std::move(__message__) ), "../../../../paddle/fluid/pybind/eager_utils.cc", 1953); } while (0); } } while (0)  | |||
| 1952 |                         "paddle.autograd.saved_tensors_hooks only one pair "do { auto __val1 = (paddle::pybind::PyCheckTensor(ret)); auto __val2 = (true); using __TYPE1__ = decltype(__val1); using __TYPE2__ = decltype(__val2); using __COMMON_TYPE1__ = ::phi::details:: CommonType1<__TYPE1__, __TYPE2__>; using __COMMON_TYPE2__ = ::phi::details::CommonType2<__TYPE1__, __TYPE2__>; bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1 ))==( static_cast<__COMMON_TYPE2__>(__val2)); if (__builtin_expect (static_cast<bool>(!__is_not_error), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform::errors::InvalidArgument ( "paddle.autograd.saved_tensors_hooks only one pair " "of hooks is allowed at a time." )); constexpr bool __kCanToString__ = ::phi::details::CanToString <__TYPE1__>::kValue && ::phi::details::CanToString <__TYPE2__>::kValue; auto __message__ = ::paddle::string ::Sprintf( "%s\n [Hint: Expected %s " "==" " %s, but received %s " "!=" " %s.]", __summary__.error_message(), "paddle::pybind::PyCheckTensor(ret)" , "true", ::phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("paddle::pybind::PyCheckTensor(ret)", __val1), :: phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("true", __val2)); do { throw ::phi::enforce::EnforceNotMet (phi::ErrorSummary(__summary__.code(), std::move(__message__) ), "../../../../paddle/fluid/pybind/eager_utils.cc", 1953); } while (0); } } while (0)  | |||
| 1953 |                         "of hooks is allowed at a time."))do { auto __val1 = (paddle::pybind::PyCheckTensor(ret)); auto __val2 = (true); using __TYPE1__ = decltype(__val1); using __TYPE2__ = decltype(__val2); using __COMMON_TYPE1__ = ::phi::details:: CommonType1<__TYPE1__, __TYPE2__>; using __COMMON_TYPE2__ = ::phi::details::CommonType2<__TYPE1__, __TYPE2__>; bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1 ))==( static_cast<__COMMON_TYPE2__>(__val2)); if (__builtin_expect (static_cast<bool>(!__is_not_error), 0)) { auto __summary__ = phi::ErrorSummary(paddle::platform::errors::InvalidArgument ( "paddle.autograd.saved_tensors_hooks only one pair " "of hooks is allowed at a time." )); constexpr bool __kCanToString__ = ::phi::details::CanToString <__TYPE1__>::kValue && ::phi::details::CanToString <__TYPE2__>::kValue; auto __message__ = ::paddle::string ::Sprintf( "%s\n [Hint: Expected %s " "==" " %s, but received %s " "!=" " %s.]", __summary__.error_message(), "paddle::pybind::PyCheckTensor(ret)" , "true", ::phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("paddle::pybind::PyCheckTensor(ret)", __val1), :: phi::details::BinaryCompareMessageConverter< __kCanToString__ >::Convert("true", __val2)); do { throw ::phi::enforce::EnforceNotMet (phi::ErrorSummary(__summary__.code(), std::move(__message__) ), "../../../../paddle/fluid/pybind/eager_utils.cc", 1953); } while (0); } } while (0);  | |||
| 1954 | ||||
| 1955 | return reinterpret_cast<void*>(ret); | |||
| 1956 | } | |||
| 1957 | ||||
| 1958 | } // namespace pybind | |||
| 1959 | } // namespace paddle | 
| 1 | #ifndef PyTuple_New | 
| 2 | struct _object; | 
| 3 | typedef struct _object PyObject; | 
| 4 | PyObject* clang_analyzer_PyObject_New_Reference(); | 
| 5 | PyObject* PyTuple_New(Py_ssize_t len) { | 
| 6 | return clang_analyzer_PyObject_New_Reference(); | 
| 7 | } | 
| 8 | #else | 
| 9 | #warning "API PyTuple_New is defined as a macro." | 
| 10 | #endif |