MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / ParsePythonOpAttrs

Function ParsePythonOpAttrs

paddle/fluid/pybind/eager_utils.cc:3657–3684  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3655 return result;
3656}
3657std::unordered_map<std::string, void*> ParsePythonOpAttrs(PyObject* py_dict) {
3658 if (!PyDict_Check(py_dict)) {
3659 PADDLE_THROW(common::errors::InvalidType(
3660 "Unknown python op attributes type, expected dict, but got %s",
3661 reinterpret_cast<PyTypeObject*>(py_dict->ob_type)->tp_name));
3662 }
3663
3664 PyObject* py_infer_meta = PyDict_GetItemString(py_dict, "infer_meta_fn_ptr");
3665 PyObject* py_real_fn = PyDict_GetItemString(py_dict, "fn_ptr");
3666 if (!py_infer_meta || !py_real_fn) {
3667 PADDLE_THROW(common::errors::NotFound(
3668 "Missing required keys 'infer_meta_fn_ptr' or 'fn_ptr' in op attrs."));
3669 }
3670
3671 if (!PyCallable_Check(py_infer_meta) || !PyCallable_Check(py_real_fn)) {
3672 PADDLE_THROW(common::errors::InvalidType(
3673 "Expected callable objects for 'infer_meta_fn_ptr' and 'fn_ptr'."));
3674 }
3675
3676 // Increase reference count to prevent garbage collection in C++
3677 Py_INCREF(py_infer_meta);
3678 Py_INCREF(py_real_fn);
3679 std::unordered_map<std::string, void*> attrs;
3680
3681 attrs["infer_meta_fn_ptr"] = reinterpret_cast<void*>(py_infer_meta);
3682 attrs["fn_ptr"] = reinterpret_cast<void*>(py_real_fn);
3683 return attrs;
3684}
3685
3686} // namespace paddle::pybind

Callers 1

run_python_opFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected