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

【Hackathon 6th No.17】为 Paddle 新增 sparse.mask_as API #6663

Merged
merged 5 commits into from
Jun 12, 2024

Conversation

megemini
Copy link
Contributor

PR Category

User Experience

PR Types

Docs

Description

NO.17 为 Paddle 新增 sparse.mask_as API

关联 PR PaddlePaddle/Paddle#64320

Copy link

paddle-bot bot commented May 29, 2024

感谢你贡献飞桨文档,文档预览构建中,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 的形式。
Copy link
Collaborator

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` 相同。
Copy link
Collaborator

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 作为单独的函数调用,两者功能一致,参数用法一致,具体如下:
Copy link
Collaborator

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。 |
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

paddle的哪个参数更多?

@megemini
Copy link
Contributor Author

megemini commented Jun 1, 2024

这个看下其他的 类方法转paddle方法 的描述话术,例如 torch.Tensor.hardshrink
这个看下其他的 类方法转paddle方法 的描述话术
paddle的哪个参数更多?

这几个问题统一回复一下:

torch 与 paddle 的这两个方法其实是一样的,不过,torch 是作为 Tensor 的方法调用,paddle 是单独的函数调用 ~

我找了找,还真没找到类似的函数,不太清楚具体该怎么写,所以写了:仅 paddle 参数更多,paddle 多了个输入 x

所以,到底该咋写呢?🤨

@megemini megemini requested a review from zhwesky2010 June 1, 2024 10:11

```python
# torch 版本可以直接访问方法
# torch.sparse_mask(mask)
Copy link
Collaborator

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 的形式。
Copy link
Collaborator

Choose a reason for hiding this comment

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

是一个 SparseTensor, 这句话多余去掉

@megemini
Copy link
Contributor Author

megemini commented Jun 3, 2024

Update 20240603

  • 修改错误描述

@megemini megemini requested a review from zhwesky2010 June 3, 2024 04:44
paddle.sparse.mask_as(x, mask, name=None)
```

两者功能一致,但使用方式不一致,前者可以直接访问方法,后者需要调用方法,具体如下:
Copy link
Collaborator

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)
Copy link
Collaborator

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)

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 的文档 docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_sparse.md 🫠

Copy link
Collaborator

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@sunzhongkai588 sunzhongkai588 left a comment

Choose a reason for hiding this comment

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

LGTM

@luotao1 luotao1 merged commit f6da494 into PaddlePaddle:develop Jun 12, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor PaddlePaddle Hackathon 飞桨黑客松活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants