Skip to content
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

Call sparse op from python #40608

Merged
merged 10 commits into from
Mar 19, 2022
Merged

Call sparse op from python #40608

merged 10 commits into from
Mar 19, 2022

Conversation

zkh2016
Copy link
Contributor

@zkh2016 zkh2016 commented Mar 16, 2022

PR types

Others

PR changes

Others

Describe

  1. 正确访问tuple元素
  2. 正确访问sparse api(全局作用域)
  3. sparse转换API去除backend参数
  4. 注册去除PD_REGISTER_API(Test);
  5. pybind添加SparseTensor相关的基础方法
  6. to_string.py添加对SparseTensor的支持
  7. 添加单测test_sparse_utils_op.py,todo:目前是测试_C_ops下的接口,后面需要改成paddle.sparse.相应API。

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@@ -1038,7 +1041,8 @@ def GenerateNodeCCFile(filepath, node_definition_str):
#include "paddle/fluid/eager/api/generated/eager_generated/backwards/nodes.h"
#include "paddle/fluid/eager/to_static/run_program_op_node.h"

#include "paddle/phi/api/include/sparse_api.h"
//#include "paddle/phi/api/include/sparse_api.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多了行注释

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 33 to 50
Backend kernel_backend = Backend::UNDEFINED;
DataLayout kernel_layout = DataLayout::UNDEFINED;
DataType kernel_data_type = DataType::UNDEFINED;
if (kernel_backend == Backend::UNDEFINED ||
kernel_layout == DataLayout::UNDEFINED ||
kernel_data_type == DataType::UNDEFINED) {
auto kernel_key_set = ParseKernelKeyByInputArgs(x);
auto kernel_key = kernel_key_set.GetHighestPriorityKernelKey();
if (kernel_backend == Backend::UNDEFINED) {
kernel_backend = kernel_key.backend();
}
if (kernel_layout == DataLayout::UNDEFINED) {
kernel_layout = kernel_key.layout();
}
if (kernel_data_type == DataType::UNDEFINED) {
kernel_data_type = kernel_key.dtype();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果自定义实现的话不用写的这么复杂,直接kernel_key拿出来用就行

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -83,32 +102,50 @@ Tensor to_sparse_coo_impl(const Tensor& x,
out.set_impl(coo);

// 6. Call kernel
VLOG(6) << "call kernel ";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种内容比较少的VLOG感觉可以去掉或者把级别调大一些

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已把debug信息去掉。

@@ -201,7 +207,9 @@ void DenseToSparseCooKernel(const Context& dev_ctx,
temp_indexs_ptr,
indices_data,
sparse_data);
VLOG(6) << "set member";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉这像是调试的log,内容不算规范

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

jim19930609
jim19930609 previously approved these changes Mar 16, 2022
@zkh2016 zkh2016 changed the title Call sparse api from python Call sparse op from python Mar 16, 2022
jim19930609
jim19930609 previously approved these changes Mar 17, 2022
zyfncg
zyfncg previously approved these changes Mar 18, 2022
zyfncg
zyfncg previously approved these changes Mar 19, 2022
@zkh2016 zkh2016 merged commit 95fbbc5 into PaddlePaddle:develop Mar 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants