-
Notifications
You must be signed in to change notification settings - Fork 274
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
【Hackathon 4th No.25】为 Paddle 新增 paddle.sparse.any 稀疏 API #502
Conversation
any 算子似乎并没有比较合理的梯度定义,在 Dense 张量上似乎也没有实现反向传播 |
目前paddle缺少相关功能实现。 | ||
|
||
# 三、业内方案调研 | ||
## Pytorch |
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.
pytorch的any操作是否支持sparse tensor?
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.
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.
torch应该只支持coo格式,我测试了一下,csr确实是不支持的
import torch
import torch.nn as nn
x = torch.Tensor([[[1, 0], [1, 0]], [[1, 0], [1, 0]], [[1, 0], [1, 0]]])
coo_x = x.to_sparse_coo()
csr_x = x.to_sparse_csr()
print(torch.any(coo_x))
print(torch.any(csr_x)) # error
同时,any也是不支持求解梯度的
import torch
import torch.nn as nn
x = torch.Tensor([[[1, 0], [1, 0]], [[1, 0], [1, 0]], [[1, 0], [1, 0]]])
coo_x = x.to_sparse_coo()
coo_x.requires_grad = True
y = torch.any(coo_x)
z = torch.sum(coo_x)
z.backward()
y.backward() # error
scipy.sparse库中没有any()函数。但是,可以使用numpy库中的any()函数在稀疏矩阵中执行相同的操作。 | ||
|
||
## paddle DenseTensor | ||
DenseTensor中的sum被定义为paddle.any(x, axis=None, dtype=None, keepdim=False, name=None), |
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.
sum->any,包括后面的sum也应该相应修改下。
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.
好的,已修改
任务说明 https://github.com/PaddlePaddle/community/blob/master/hackthon_4th/%E3%80%90PaddlePaddle%20Hackathon%204%E3%80%91%20%E6%A0%B8%E5%BF%83%E6%A1%86%E6%9E%B6%E5%BC%80%E6%BA%90%E8%B4%A1%E7%8C%AE%20API%20%E5%BC%80%E5%8F%91%E4%BB%BB%E5%8A%A1%E5%90%88%E9%9B%86.md#task25
由于在实现上与sparse.sum相近,因此rfc也主要根据 #411 修改