-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[PIR][Dy2St] Set TensorArray dtype after first write if its type is undefined #67981
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] Set TensorArray dtype after first write if its type is undefined #67981
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
…write-if-its-type-is-undefined
paddle/pir/include/core/builder.h
Outdated
@@ -136,6 +137,7 @@ class Builder { | |||
template <typename OpTy, typename... Args> | |||
OpTy Build(Args &&...args); | |||
|
|||
IR_API UndefinedDataType undefined_data_type(); |
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.
是不是可以直接叫UndefinedType, 赶紧"Data"有点冗余,个人觉得在不存在歧义的情况下,名字越短越好。
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.
Great work!
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
13f5d88
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 Category
Execute Infrastructure
PR Types
Bug fixes
Description
对于上述情况,动转静下会对
l
创建一个 float32 的TensorArray
,但后续会往里面添加 int64 的数据,这里我们有两种可以处理的方式:之前是直接报错的,后来加上了 cast,这两种其实都有问题,前者会导致大量存量代码需要修改,后者会导致后续取出的元素永远是 float32
由于这里原来是动态图代码,用户没有显式标注类型,因此从最开始而言其类型就应该是
Array<Unknown>
,在发现后续有append(i64)
时应该自动推导为Array<i64>
,这是符合编译器的类型推导原则的从 Paddle 的框架或者说 PIR 的角度,使用了
UndefinedDataType
来表示最开始尚未确定类型,对应 phi 下的DataType::UNDEFINED
,我们会为动转静转换的元素 dtype 设置为 undefined,而在后面append
时候触发的ArrayWriteInferMeta
设置成第一个元素的 dtype由于动转静只有捕获
append
等相关操作才会转为 TensorArray,因此创建的UndefinedDataType
的 array 一定会在组网期间确定类型,组网完成后不会再有UndefinedDataType
的 TensorArrayPcard-67164