CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
【IR】Support Sparsecootensor and Sparsecsrtensor #63015
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
【IR】Support Sparsecootensor and Sparsecsrtensor #63015
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
❌ The PR is not created using PR's template. You can refer to this Demo. |
40a8c0f
to
168b3eb
Compare
168b3eb
to
54b5b51
Compare
op_compat_item = op_compat_parser.get_compat( | ||
op['forward']['name'] | ||
) | ||
for op in op_yaml_items: |
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.
for op in op_yaml_items: | |
for op in ops: |
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.
好的
for yaml_file in op_yaml_files: | ||
op_yaml_items = [] |
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_yaml_items = [] |
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.
好的
@@ -1367,20 +1382,56 @@ def AutoCodeGen( | |||
# =================================== # | |||
# gen interface list str # | |||
# =================================== # | |||
op_class_name_suffix = 'Sp' if op_info.is_sparse_op 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.
这部分逻辑出现了2遍,考虑封装成一个函数
op_info_items[op_info.op_phi_name[0]], | ||
all_op_info_items[op_info.backward_name], | ||
op_info_items[ | ||
op_info.op_phi_name[0] + sparse_op_name_suffix |
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.
这里建议封装成encode/decode形式,并添加注释,便于理解
Sorry to inform you that b2c5d88's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
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
@@ -141,6 +142,14 @@ inline std::string OpNameCompatibleMapping(std::string op_name) { | |||
auto& op_normalizer = OpNameNormalizer::instance(); | |||
return op_normalizer[op_name]; | |||
} | |||
inline bool isSparseString(const std::string& str) { | |||
std::regex pattern("^sparse_[a-zA-Z0-9_]+$"); | |||
if (std::regex_match(str, pattern)) { |
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.
if (std::regex_match(str, pattern)) { | |
return std::regex_match(str, pattern); |
这样会更简洁?
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.
是的
@@ -662,6 +665,8 @@ def _gen_amp_logic(self, op_info, op_name, is_mutable_attr): | |||
return 'VLOG(5) << " No AMP for grad apis. ";' | |||
if op_name.endswith('_') or op_name == 'cast': | |||
return f'VLOG(5) << "No AMP for {op_name} because it is a inplace or cast api.";' | |||
if op_info.is_sparse_op: | |||
op_name += "sp_" if op_name[-1] == "_" else "_sp" |
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.
类似这样的专有后缀,建议在文件头部通过 kSparseOpPrefix 或者 kSparseOpSuffix来定义;
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.
好的
non_zero_elements_(non_zero_elements), | ||
coalesced_(coalesced) {} | ||
|
||
IrSparseCooTensor::IrSparseCooTensor(const IrSparseCooTensor& other) { |
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.
IrSparseCooTensor(const IrSparseCooTensor& other) = default;
是不是就可以?可以复用下C++的一些默认构造的写法(前提是里面不能有指针类型成员)
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.
好的
coalesced_ = other.coalesced(); | ||
} | ||
|
||
IrSparseCooTensor& IrSparseCooTensor::operator=( |
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.
同上,可以了解下C++的编译器默认生成的系列构造
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.
好的
@@ -0,0 +1,209 @@ | |||
// Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. |
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.
Suggest change file name from ir_sparse to ir_sparse_tensor
@@ -383,6 +381,8 @@ def _gen_ret_type(self, op_info): | |||
def _gen_one_declare( | |||
self, op_info, op_name, is_mutable_attr, is_vector_mutable_attr | |||
): | |||
if op_info.is_sparse_op: | |||
op_name += "sp_" if op_name[-1] == "_" else "_sp" |
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.
建议直接将带有_sp 后缀的名字作为OpInfo的一个属性
… support_sparse_op_in_pir
@@ -104,7 +104,18 @@ void InterpreterCoreEventGarbageCollector::Add( | |||
->MoveMemoryHolder(), | |||
event, | |||
ctx); | |||
var->GetMutable<phi::SelectedRows>()->mutable_rows()->clear(); | |||
} else if (var->IsType<phi::SparseCooTensor>()) { |
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.
同目录下no_event_garbage_collector.cc也需要补充SparseCooTensor相关逻辑
return op_info; | ||
} | ||
if (paddle::dialect::HaveOpToMultiKernelsMap( | ||
OpNameCompatibleMapping(op_desc.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.
这部分处理sparse多kernel的逻辑和下面处理其他op多kernel的逻辑有很多重合,最好把重复部分抽出来形成一个函数或者合并一下,否则难以维护
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 for op_compat
@@ -56,14 +56,17 @@ endif() | |||
|
|||
set(EIGEN_INCLUDE_DIR ${SOURCE_DIR}) | |||
include_directories(${EIGEN_INCLUDE_DIR}) | |||
|
|||
if(NOT WIN32) | |||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=maybe-uninitialized") |
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.
为何加了这个?
* test * support_sparse_op_in_pir * support_sparse_op_in_pir * support suparse op in pir * test * fix * fix * support sparse op in pir * fix * fix * fix * fix * support translator of sparse tests * support translator of sparse tests * support translator of sparse tests * support translator of sparse tests * fix * fix * fix * fix
* test * support_sparse_op_in_pir * support_sparse_op_in_pir * support suparse op in pir * test * fix * fix * support sparse op in pir * fix * fix * fix * fix * support translator of sparse tests * support translator of sparse tests * support translator of sparse tests * support translator of sparse tests * fix * fix * fix * fix
* test * support_sparse_op_in_pir * support_sparse_op_in_pir * support suparse op in pir * test * fix * fix * support sparse op in pir * fix * fix * fix * fix * support translator of sparse tests * support translator of sparse tests * support translator of sparse tests * support translator of sparse tests * fix * fix * fix * fix
* test * support_sparse_op_in_pir * support_sparse_op_in_pir * support suparse op in pir * test * fix * fix * support sparse op in pir * fix * fix * fix * fix * support translator of sparse tests * support translator of sparse tests * support translator of sparse tests * support translator of sparse tests * fix * fix * fix * fix
PR Category
Others
PR Types
New features
Description
此PR做了以下两件事情: