-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
[PTen]Add alias kernel name #37881
[PTen]Add alias kernel name #37881
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,26 @@ limitations under the License. */ | |
|
||
namespace pten { | ||
|
||
// the map between kernel name in fluid and pten | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里再加些注释,说明一下key,value 是什么含义吧 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
const std::unordered_map<std::string, std::string> kernel_alias_name_map = { | ||
{"reshape2", "reshape"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个会导致咱们让大家迁移的时候,还需要额外关注这个文件的更新和映射,能否在注册时一起声明下这个name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果用这种的话,建议这个map单独放到一个文件中管理 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
{"fill_any_like", "full_like"}, | ||
{"fill_constant", "full"}, | ||
{"matmul_v2", "matmul"}, | ||
{"flatten_contiguous_range", "flatten"}, | ||
{"reduce_mean", "mean"}, | ||
{"reduce_sum", "sum"}, | ||
{"elementwise_add", "add"}, | ||
{"elementwise_sub", "subtract"}, | ||
{"elementwise_mul", "muliply"}, | ||
{"elementwise_div", "divide"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里是不可以按照一个统一的规则排下序,后面迁移的kernel多了找起来也方便 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
// fluid kernel "mean/reshape/matmul/flatten/sum" should be deprecated | ||
{"mean", "deprecated"}, | ||
{"reshape", "deprecated"}, | ||
{"matmul", "deprecated"}, | ||
{"flatten", "deprecated"}, | ||
{"sum", "deprecated"}}; | ||
|
||
// TODO(chenweihang): Add other place trans cases later | ||
Backend TransToPtenBackend(const paddle::platform::Place& place) { | ||
if (paddle::platform::is_cpu_place(place)) { | ||
|
@@ -304,4 +324,12 @@ int TensorDtype2NumpyDtype(pten::DataType dtype) { | |
} | ||
} | ||
|
||
std::string TransToPtenKernelName(const std::string& fluid_op_name) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可以返回 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
if (kernel_alias_name_map.find(fluid_op_name) != | ||
kernel_alias_name_map.end()) { | ||
return kernel_alias_name_map.at(fluid_op_name); | ||
} | ||
return fluid_op_name; | ||
} | ||
|
||
} // namespace pten |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ namespace pten { | |
using DataType = paddle::experimental::DataType; | ||
using DataLayout = paddle::experimental::DataLayout; | ||
|
||
std::string TransToPtenKernelName(const std::string& fluid_op_name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上 |
||
|
||
Backend TransToPtenBackend(const paddle::platform::Place& place); | ||
DataType TransToPtenDataType( | ||
const paddle::framework::proto::VarType::Type& dtype); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ void FillConstant(const CPUContext& dev_ctx, | |
|
||
PT_REGISTER_MODULE(CreationCPU); | ||
|
||
PT_REGISTER_KERNEL("fill_any_like", | ||
PT_REGISTER_KERNEL("full_like", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这样直接改会导致pten kernel在运行时都没有被选到吧,兼容态是根据这个名字来搜索是否执行pten kernel的 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 会选到 |
||
CPU, | ||
ANY, | ||
pten::FillAnyLike, | ||
|
@@ -74,7 +74,7 @@ PT_REGISTER_KERNEL("fill_any_like", | |
bool, | ||
paddle::platform::float16) {} | ||
|
||
PT_REGISTER_KERNEL("fill_constant", | ||
PT_REGISTER_KERNEL("full", | ||
CPU, | ||
ANY, | ||
pten::FillConstant, | ||
|
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.
这里的op_type 是不是也要pten::TransToPtenKernelName(op_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.
不需要