-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[PIR][Dy2St] Convert Tensor to Value in PIR bind API #59761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PIR][Dy2St] Convert Tensor to Value in PIR bind API #59761
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
pir::Value CastPyArg2Value(PyObject* obj, | ||
const std::string& op_type, | ||
size_t arg_pos) { | ||
obj = CastPyArg2ValuePreHook(obj); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里obj可能会返回nullptr,此时会走到函数里的else分支,在报错文案里直接使用->会段错误吧,这里有潜在风险
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已 ENFORCE~
paddle/fluid/pybind/eager_utils.cc
Outdated
PyObject* result = PyObject_CallFunction(hook, "O", obj); | ||
if (result == nullptr) { | ||
Py_DECREF(obj); | ||
return nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
或者这里是不是不应该允许返回nullptr,应该ENFORCE下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
Bug fixes
PR changes
Others
Description
PIR API 与老 IR 相比并没有统一的
append_op
入口,因此可能有 EagerTensor 传入到_C_ops
的情况,因此我们会在 C API 处将 Tensor 转为 Value具体实现如下:
添加
set_static_op_arg_pre_cast_hook
接口,用于设置一个 hook,在将 PyObject cast 为 Value 之前调用,该 hook 将会在输入是一个 EagerTensor 的时候转换为 Value(利用 ParameterRecorder)在进入动转静时,会同时设置该 hook,在离开动转静时会恢复(时机同
_to_static_mode_guard_
)Pcard-67164