-
Notifications
You must be signed in to change notification settings - Fork 750
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 6th No.17】为 Paddle 新增 sparse.mask_as API #6663
Conversation
感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-6663.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html |
参数 | ||
::::::::: | ||
- **x** (DenseTensor) - 输入的 DenseTensor。数据类型为 float32,float64,int32,int64,complex64,complex128,int8,int16,float16。 | ||
- **mask** (SparseTensor) - 输入的稀疏张量,是一个 SparseTensor,可以为 Coo 或 Csr 格式。当其为 SparseCsrTensor 时,应该是 2D 或 3D 的形式。 |
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.
这里直接写可为 SparseCooTensor、SparseCsrTensor
吧
|
||
返回 | ||
::::::::: | ||
SparseTensor: 其 Tensor 类型、dtype、shape 均与 `mask` 相同。 |
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.
其 稀疏格式
paddle.sparse.mask_as(x, mask, name=None) | ||
``` | ||
|
||
PyTorch 作为 Tensor 的方法,Paddle 作为单独的函数调用,两者功能一致,参数用法一致,具体如下: |
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.
这个看下其他的 类方法转paddle方法
的描述话术,例如 torch.Tensor.hardshrink
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ---------- | ------------ | ------------------------------------ | | ||
| - | x | 输入的 DenseTensor。 | |
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.
这个看下其他的 类方法转paddle方法
的描述话术
@@ -0,0 +1,22 @@ | |||
## [ 仅 paddle 参数更多 ] torch.Tensor.sparse_mask |
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.
paddle的哪个参数更多?
这几个问题统一回复一下: torch 与 paddle 的这两个方法其实是一样的,不过,torch 是作为 Tensor 的方法调用,paddle 是单独的函数调用 ~ 我找了找,还真没找到类似的函数,不太清楚具体该怎么写,所以写了: 所以,到底该咋写呢?🤨 |
|
||
```python | ||
# torch 版本可以直接访问方法 | ||
# torch.sparse_mask(mask) |
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.
这个要写成类方法:x.sparse_mask(mask)
参数 | ||
::::::::: | ||
- **x** (DenseTensor) - 输入的 DenseTensor。数据类型为 float32,float64,int32,int64,complex64,complex128,int8,int16,float16。 | ||
- **mask** (SparseTensor) - 输入的稀疏张量,是一个 SparseTensor,可以为 SparseCooTensor、SparseCsrTensor。当其为 SparseCsrTensor 时,应该是 2D 或 3D 的形式。 |
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.
是一个 SparseTensor,
这句话多余去掉
Update 20240603
|
paddle.sparse.mask_as(x, mask, 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.
两者功能一致,但调用方式不同,torch通过Tensor类方法调用,而paddle是直接调用函数,具体如下:
|
||
```python | ||
# torch 版本可以直接访问方法 | ||
# x = torch.tensor(123) |
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 调用Tensor类方法
x.sparse_mask(mask)
# paddle 直接调用函数
paddle.sparse.mask_as(x, mask)
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 的文档 docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_sparse.md 🫠
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
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
PR Category
User Experience
PR Types
Docs
Description
NO.17 为 Paddle 新增 sparse.mask_as API
关联 PR PaddlePaddle/Paddle#64320