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.79 #5853

Closed
wants to merge 10 commits into from
Closed

映射文档No.79 #5853

wants to merge 10 commits into from

Conversation

zhangtailai
Copy link

@zhangtailai zhangtailai commented May 5, 2023

完成 #5691 中No.79的文档映射工作,其中新增10个api映射文档,有问题请联系

@paddle-bot
Copy link

paddle-bot bot commented May 5, 2023

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

@CLAassistant
Copy link

CLAassistant commented May 5, 2023

CLA assistant check
All committers have signed the CLA.

@zhangtailai
Copy link
Author

@Tomoko-hjf 请检查一下还有没有什么问题

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.

需要保持和已合并PR格式上的统一,可以参考格式文档https://github.com/PaddlePaddle/docs/blob/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/pytorch_api_mapping_format_cn.md 和已经合并的PR
辛苦修改一下格式~

@zhangtailai
Copy link
Author

@Tomoko-hjf 已修改,麻烦在检查一下

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.

有几个共性问题:

  1. api签名和转写示例部分 代码前面的空格可以删去
  2. 参数映射部分前面 需要一句话说明,可以参考格式文档。如果是参数不一致的情况,需要说明哪个参数用法不一致,并用 强调
  3. 文档里有很多无用的注释,可以检查后删去
  4. 参数映射部分的备注部分可以精简一下,不必把官网内容全都拿过来
    辛苦修改一下~

### [torch.Tensor.permute](https://pytorch.org/docs/1.13/generated/torch.Tensor.permute.html)

```python
torch.Tensor.permute(*dims)
Copy link
Collaborator

Choose a reason for hiding this comment

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

可以删去前面多余的空格

### 转写示例
#### *dim: Tensor 的维度序列,可变参数用法
```python
# pytorch
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
Collaborator

Choose a reason for hiding this comment

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

改为 Pytorch 的 dims 参数与 Paddle 的 perm 参数用法不同,具体如下:

位置放在 ### 参数映射 的上一行

两者部分参数用法不同,具体如下:
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| *dims | perm | dim :torch 可以为 *dim 和 list/tuple 的用法; perm :paddle 仅为 list/tuple 的用法。 torch 的参数为 *dim 时需要转写 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

备注 改为 torch 支持可变参数或list/tuple,paddle仅支持list/tuple,参数用法不一致,需要进行转写。

```

### 参数映射
两者部分参数用法不同,具体如下:
Copy link
Collaborator

Choose a reason for hiding this comment

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

改为 Pytorch 的 sizes 参数与 Paddle 的 repeat_times 参数用法不同,具体如下:

位置放在 ### 参数映射 的上一行

### 转写示例
#### *sizes: 各个维度重复的次数,可变参数用法
```python
# pytorch
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.reshape](https://pytorch.org/docs/1.13/generated/torch.Tensor.reshape.html)

```python
torch.Tensor.reshape(*shape)
Copy link
Collaborator

Choose a reason for hiding this comment

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

可以去掉空格,顺便检查一下其他文件~

| some | full_matrices | 表示是否计算完整的 U 和 V 矩阵。默认时效果一致。 some 为 True 时, full_matrices 需设置为 False ,反之同理。 |
| compute_uv | - | 如果 compute_uv 为 False ,则返回的 U 和 V 将分别为形状为 (m, m) 和 (n ,n) 的零填充矩阵,并且与输入设备相同。当 compute_uv 为 False 时,参数 some 不起作用。一般直接删除即可,无需转写。 |

<!-- ### torch 多的参数
Copy link
Collaborator

Choose a reason for hiding this comment

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

这部分多余的内容可以删去

| ------------- | -------------------------------------------------------------------- |
| compute_uv | 默认参数,默认一致。如果 compute_uv 为 False ,则返回的 U 和 V 将分别为形状为 (m, m) 和 (n ,n) 的零填充矩阵,并且与输入设备相同。当 compute_uv 为 False 时,参数 some 不起作用。 | -->

<!-- ### 转写示例
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 | 备注 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

一致的参数也需要写到参数映射中去,不能注释起来

@zhangtailai
Copy link
Author

@Tomoko-hjf 已修改,麻烦再检查一下还有什么问题。

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.

  • 有几个api名称和链接不一致,辛苦检查修改一下 ~
  • 一句话描述部分的参数用一对 ` ` 强调即可,不需要两对

torch.cuda.get_device_name(device=None)
```

### [paddle.Tensor.transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/device/cuda/get_device_properties_cn.html#get-device-properties)
Copy link
Collaborator

Choose a reason for hiding this comment

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

api名称不正确

paddle.CUDAPlace(id)
```

Pytorch 的 ``device`` 与 Paddle 的 ``id`` 用法不同,具体如下:
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 | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| device | device | torch 的 device 参数类型为 torch.device 或 int 或 str。paddle 的 id 为 paddle.CUDAPlace 或 int 或 str。 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

应该是 paddle 的 device 吧

torch.cuda.device(device)
```

### [paddle.Tensor.transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/CUDAPlace_cn.html#cudaplace)
Copy link
Collaborator

Choose a reason for hiding this comment

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

api 名称不正确

@@ -0,0 +1,31 @@
## [参数不一致]torch.Tensor.transpose

### [torch.Tensor.transpose](https://pytorch.org/docs/1.13/generated/torch.Tensor.swapdims.html)
Copy link
Collaborator

Choose a reason for hiding this comment

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

链接不正确

paddle.linalg.svd(x, full_matrics=False, 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.

说明一下哪个参数用法不一致吧~

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| some | full_matrices | 表示是否计算完整的 U 和 V 矩阵。默认时效果一致。 some 为 True 时, full_matrices 需设置为 False ,反之同理。 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个参数可以写一个转写示例,some 为 True , full_matrices 设置为 False 。

| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| some | full_matrices | 表示是否计算完整的 U 和 V 矩阵。默认时效果一致。 some 为 True 时, full_matrices 需设置为 False ,反之同理。 |
| compute_uv | - | 默认时效果一致。一般直接删除即可,无需转写。 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

如果compute_uv 为 False可以进行转写吗,不可以的话备注写 暂不支持转写就可以

paddle.Tensor.reshape(shape, name=None)
```

Pytorch 的 ``*shape`` 参数与 Paddle 的 ``shape`` 参数用法不同,具体如下:
Copy link
Collaborator

Choose a reason for hiding this comment

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

用一对 ` ` 包含既可~

paddle.Tensor.tile(repeat_times, name=None)
```

Pytorch 的 sizes 参数与 Paddle 的 repeat_times 参数用法不同,具体如下:
Copy link
Collaborator

Choose a reason for hiding this comment

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

sizes 和 repeat_times 用 `` 强调一下吧~

@zhangtailai
Copy link
Author

@Tomoko-hjf 已修改,麻烦再次检查

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.

转写示例部分pytorch和paddle最终的输出变量名统一成y,或者一致的名称吧,现在是不一致的,辛苦修改一下~

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| device | id | torch 的 device 参数类型为 torch.device 或 int 。paddle 的 id 为 int。 torch 参数为 int 时无需转写, 参数为 torch.device 时, paddle 暂无转写方式。|
Copy link
Collaborator

Choose a reason for hiding this comment

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

当参数为torch.device 时也可以进行转写,转写方法为

# PyTorch 写法
torch.cuda.device(torch.device('cuda:0'))

# Paddle 写法
paddle.CUDAPlace(0)


# paddle
x = paddle.randn([2, 3, 5])
x_transposed = x.transpose(perm=[1, 0, 2])
Copy link
Collaborator

Choose a reason for hiding this comment

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

pytorch和paddle转写示例的两个输出变量都统一成y吧,或者名称要一致,现在一个是x_swapdims,一个是x_transposed


# paddle
x = paddle.randn([2, 3, 5])
x_transposed = x.transpose(perm=[1, 0, 2])
Copy link
Collaborator

Choose a reason for hiding this comment

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

两个输出变量名要一致


# paddle
x = paddle.randn([2, 3, 5])
x_tile_tuple = x.tile((6,5))
Copy link
Collaborator

Choose a reason for hiding this comment

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

输出变量名统一成一致的吧~


# paddle
x = paddle.randn([2, 3, 5])
x_tile_tuple = x.tile((4,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.Tensor.transpose(perm, name=None)
```

torch 的 `*dims` 与 paddle 的 `perm` 两者部分参数用法不同,具体如下:
Copy link
Collaborator

Choose a reason for hiding this comment

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

写完整吧,改为 PyTorch 的 dim 与 paddle 的 perm 两者部分参数用法不同,具体如下:

@zhangtailai
Copy link
Author

@Tomoko-hjf 已修改,麻烦再检查一下

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


# paddle
x = paddle.randn([2, 3, 5])
y = x.tile((6,5))
Copy link
Collaborator

@zhwesky2010 zhwesky2010 May 16, 2023

Choose a reason for hiding this comment

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

这个写错了

Copy link
Collaborator

Choose a reason for hiding this comment

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

这个应该是x.reshape

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| *shape | shape | torch 的 *shape 既可以接收 list 也可接收可变参数。需要转写。|
Copy link
Collaborator

Choose a reason for hiding this comment

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

paddle的支持哪些也写下

Copy link
Collaborator

Choose a reason for hiding this comment

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

torch 的 *shape 既可以是可变参数,也可以是 list/tuple

@luotao1 luotao1 added the HappyOpenSource 快乐开源活动issue与PR label May 17, 2023
@huajiao-hjyp
Copy link
Collaborator

@zhangtailai 同学你好,有时间的话可以按照意见再修改一下,这样就能尽快合并了~

@luotao1 luotao1 self-assigned this Jun 26, 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.

5 participants