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

映射文档 No.48 #5840

Merged
merged 9 commits into from
May 12, 2023
Merged

映射文档 No.48 #5840

merged 9 commits into from
May 12, 2023

Conversation

YiZoey
Copy link
Contributor

@YiZoey YiZoey commented Apr 25, 2023

分组 ID 48

@paddle-bot
Copy link

paddle-bot bot commented Apr 25, 2023

感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-5840.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html
预览工具的更多说明,请参考:飞桨文档预览工具

@YiZoey YiZoey changed the title 映射文档 No.48 workl in process: 映射文档 No.48 Apr 25, 2023
@YiZoey YiZoey changed the title workl in process: 映射文档 No.48 映射文档 No.48 Apr 25, 2023
@YiZoey
Copy link
Contributor Author

YiZoey commented Apr 25, 2023

映射任务列表48中的torch.matmul已经被其他贡献者提交;
https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/linalg/inv_cn.html 下代码示例的的函数名称与文档函数不对应;

| ------------- | ------------ | ------------------------------------------------------ |
| <font color='red'> A </font> | <font color='red'> x </font> | 输入的 Tensor ,仅参数名不同。 |
| <font color='red'> pivots </font> | <font color='red'> pivot </font> | 输入的 bool ,仅参数名不同。 |
| <font color='red'> get_infos </font> | <font color='red'> get_infos </font> | 输入的 bool ,仅参数名不同。 |
Copy link
Collaborator

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.

已更正

torch.lu(torch.tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]), get_infos=True, out=(A_LU, pivots, info))

# Paddle 写法
lu, p, info = paddle.linalg.lu(paddle.to_tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]).astype('float64'), get_infos=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

可以用paddle.assign实现赋值吗

Copy link
Contributor Author

@YiZoey YiZoey Apr 26, 2023

Choose a reason for hiding this comment

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

paddle.assign(x, output)中output为Tensor,此处assign会报TypeError: Unsupport paddle.assign([Variable, Variable...]) with non-scalar variable;
paddle.linalg.lu返回值为tuple,且tuple内Tensor维度不一致, 因此无法将结果转为list等方式拼接;
尚未找到合适赋值方式,暂未修改

| <font color='red'> LU_data </font> | <font color='red'> x </font> | 输入的 Tensor ,仅参数名不同。 |
| <font color='red'> LU_pivots </font> | <font color='red'> y </font> | 输入的 Tensor ,仅参数名不同。 |
| <font color='red'> unpack_data </font> | <font color='red'> unpack_ludata </font> | 输入的 bool ,仅参数名不同。 |
| <font color='red'> unpack_pivots </font> | <font color='red'> unpack_pivots </font> | 输入的 bool ,仅参数名不同。 |
Copy link
Collaborator

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.

已更正

torch.lu_unpack(*torch.lu(torch.tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])), out=(P, L, U))

# Paddle 写法
P,L,U = paddle.linalg.lu_unpack(*paddle.linalg.lu(paddle.to_tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]).astype('float64')))
Copy link
Collaborator

Choose a reason for hiding this comment

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

试一下可以用paddle.assign实现吗

Copy link
Contributor Author

@YiZoey YiZoey Apr 26, 2023

Choose a reason for hiding this comment

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

同paddle.linalg.lu

torch.matrix_power(torch.tensor([[1., 2., 3.],[1., 4., 9.],[1., 8., 27.]]), 2, out=y)

# Paddle 写法
paddle.assign(paddle.linalg.matrix_power(paddle.to_tensor([[1, 2, 3],[1, 4, 9],[1, 8, 27]], dtype='float64'), 2), y)
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里paddle的写法中,可以将1换成 1. ,这样就不用显式写dtype了

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

@@ -0,0 +1,30 @@
## [torch 参数更多 ]torch.matrix_rank
Copy link
Collaborator

Choose a reason for hiding this comment

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

签名和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.

已更正

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| A | x | 输入的 Tensor ,仅参数名不同。 |
| tol | tol | 输入的 Tensor 或者 float,仅参数名不同。 |
Copy link
Collaborator

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.

已更正

| ------------- | ------------ | ------------------------------------------------------ |
| A | x | 输入的 Tensor ,仅参数名不同。 |
| tol | tol | 输入的 Tensor 或者 float,仅参数名不同。 |
| hermitian | hermitian | 输入的 bool ,仅参数名不同。 |
Copy link
Collaborator

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.

已更正

@@ -0,0 +1,30 @@
## [torch 参数更多 ]torch.matrix_rank
### [torch.matrix_rank](https://pytorch.org/docs/stable/generated/torch.linalg.matrix_rank.html?highlight=matrix_rank#torch.linalg.matrix_rank)
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里少了linalg 吧

Copy link
Contributor Author

Choose a reason for hiding this comment

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

原在线文档中该函数为torch.matrix_rank,pytorch1.13中实际只有torch.linalg.matrix_rank,已修改该api名及其文件名

torch.dot(torch.tensor([2, 3]), torch.tensor([2, 1]), out=y)

# Paddle 写法
y = paddle.dot(paddle.to_tensor([2, 3]), paddle.to_tensor([2, 1]))
Copy link
Collaborator

Choose a reason for hiding this comment

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

赋值可以用paddle.assign

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| A | x | 输入的 Tensor ,仅参数名不同。 |
| tol | tol | 输入的 Tensor 或者 float,仅参数名不同。 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

参数名是一样的

@@ -0,0 +1,34 @@
## [torch 参数更多 ]torch.lu

### [torch.lu](https://pytorch.org/docs/stable/generated/torch.inverse.html?highlight=inverse#torch.inverse)
Copy link
Collaborator

Choose a reason for hiding this comment

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

链接不正确

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input | x | 输入的 Tensor ,仅参数名不同。 |
| n | n | 输入的 int ,仅参数名不同。 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

参数名相同~

@YiZoey
Copy link
Contributor Author

YiZoey commented Apr 27, 2023

均已更正,并重新检查类似问题,确认无误

Copy link
Collaborator

@huajiao-hjyp huajiao-hjyp left a comment

Choose a reason for hiding this comment

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

LGTM

@huajiao-hjyp
Copy link
Collaborator

  1. 可以把缺失的 api 名称补充在 comment 中
  2. torch.inverse torch.lu torch.lu_unpack torch.matrix_power 这几个文件可以放在ops下,因为我们是以torch的标准进行分类的~

@YiZoey
Copy link
Contributor Author

YiZoey commented Apr 29, 2023

  1. 缺失的api为torch.matmul,其已在项目仓库中存在,无需修改或添加。
  2. 文件已经迁移,感谢提醒。

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.

辛苦改一下

#### out:指定输出
```python
# Pytorch 写法
torch.inner(torch.arange(1., 7.).reshape((2, 3)), torch.arange(1., 10.).reshape((3, 3)), out=y)
Copy link
Collaborator

Choose a reason for hiding this comment

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

后面可以尽量把示例写的简单些,直接写list表示Tensor也行,这个本质是伪代码的形式让用户一眼看了就懂转换思路的。写出核心转换思路就可以,辅助运行的代码应省尽省。

torch.lu(torch.tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]), get_infos=True, out=(A_LU, pivots, info))

# Paddle 写法
lu, p, info = paddle.linalg.lu(paddle.to_tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]), get_infos=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

A_LU, pivots, info

#### out:指定输出
```python
# Pytorch 写法
torch.ger(torch.arange(1., 5.), torch.arange(1., 4.), out=y)
Copy link
Collaborator

Choose a reason for hiding this comment

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

写的比较复杂,建议写简略一些

@YiZoey
Copy link
Contributor Author

YiZoey commented May 10, 2023

辛苦改一下

已修改相关样例表示

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

@zhwesky2010 zhwesky2010 merged commit 4b757b3 into PaddlePaddle:develop May 12, 2023
@luotao1
Copy link
Collaborator

luotao1 commented May 16, 2023

hi, @YiZoey

  • 非常感谢你对飞桨框架的贡献,我们正在运营一个PFCC组织,会通过定期分享技术知识与发布开发者主导任务的形式持续为飞桨框架做贡献,详情可见 https://github.com/luotao1 主页说明。
  • 如果你对PFCC有兴趣,请发送邮件至 ext_paddle_oss@baidu.com,我们会邀请你加入~

@luotao1 luotao1 added the HappyOpenSource 快乐开源活动issue与PR label Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants