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

Add kernel sparse_mask_helper; sparse_coo_tensor_grad #41586

Merged
merged 5 commits into from
Apr 13, 2022

Conversation

zkh2016
Copy link
Contributor

@zkh2016 zkh2016 commented Apr 9, 2022

PR types

New features

PR changes

APIs

Describe

  1. 添加SparseMaskHelperKernel
  • 使用输入的mask_indices对输入x进行过滤
  • 如果mask_indices在x的indices中存在,则把对应的values保留下来,否则为0.
  • 输出mask后的DenseTensor
  1. 为sparse_coo_tensor添加反向逻辑

支持中间构造SparseCooTensor,例子:

import paddle
from paddle.fluid.framework import _test_eager_guard

with _test_eager_guard():
  a = paddle.to_tensor([1,2], stop_gradient=False)
  b = paddle.to_tensor([1, 0], stop_gradient=False)
  values = a + b
  indices = paddle.to_tensor([[0, 1][ 0, 1]], dtype='int32')
  #如果sparse_coo_tensor()是纯前向的,就不能反向传播到a和b
  sparse_x = paddle.sparse.sparse_coo_tensor(indices, values, shape=[2,2], stop_gradient=False)
  relu = paddle.sparse.ReLU()
  sparse_out = relu(sparse_x)
  sparse_out.backward(sparse_out)

@paddle-bot-old
Copy link

paddle-bot-old bot commented Apr 9, 2022

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See [Paddle CI Manual(https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/dev_guides/git_guides/paddle_ci_manual_cn.html) for details.

@zkh2016 zkh2016 changed the title 【WIP】Add kernel sparse_mask_helper; sparse_coo_tensor_grad Add kernel sparse_mask_helper; sparse_coo_tensor_grad Apr 11, 2022
@@ -101,3 +167,16 @@ PD_REGISTER_KERNEL(sparse_mask,
int64_t) {
kernel->InputAt(1).SetDataLayout(phi::DataLayout::SPARSE_COO);
}

PD_REGISTER_KERNEL(sparse_mask_helper,
Copy link
Contributor

Choose a reason for hiding this comment

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

sparse_mask_helper API 命名是什么呢 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个主要是后端使用,辅助求sparse_coo_tensor的反向,不准备暴露给前端。

@zkh2016 zkh2016 merged commit acd08a9 into PaddlePaddle:develop Apr 13, 2022
zkh2016 pushed a commit to zkh2016/Paddle that referenced this pull request Apr 15, 2022
zkh2016 pushed a commit to zkh2016/Paddle that referenced this pull request Apr 18, 2022
lanxianghit pushed a commit that referenced this pull request Apr 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