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
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## [参数不一致]torch.Tensor.permute

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

```python
torch.Tensor.permute(*dims)
```

### [paddle.Tensor.transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#transpose-perm-name-none)

```python
paddle.Tensor.transpose(perm, name=None)
```

torch 的 ``*dims`` 与 paddle 的 ``perm`` 两者部分参数用法不同,具体如下:
### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| *dims | perm | torch 支持可变参数或 list/tuple,paddle 仅支持 list/tuple,参数用法不一致,需要进行转写。 |

### 转写示例
#### *dim: Tensor 的维度序列,可变参数用法
```python
# pytorch
x = torch.randn(2, 3, 5)
x_permuted_dim = x.permute(2,0,1)

# paddle
x = paddle.randn([2, 3, 5])
x_transposed_list = x.transpose([2, 0, 1])
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## [参数不一致]torch.Tensor.repeat

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

```python
torch.Tensor.repeat(*sizes)
```

### [paddle.Tensor.tile](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#tile-repeat-times-name-none)

```python
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 用 `` 强调一下吧~

### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| *sizes | repeat_times | torch 支持可变参数或 list/tuple,paddle 仅支持 list/tuple/Tensor,参数用法不一致,需要进行转写。|

### 转写示例
#### *sizes: 各个维度重复的次数,可变参数用法
```python
# pytorch
x = torch.randn(2, 3, 5)
x_repeat = x.repeat(4,2,1)

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

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

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## [参数不一致]torch.Tensor.reshape

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

```python
torch.Tensor.reshape(*shape)
```

### [paddle.Tensor.reshape](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#reshape-shape-name-none)

```python
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.

用一对 ` ` 包含既可~

### 参数映射
| 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


### 转写示例
#### *shape: 新数组的维度序列,可变参数用法
```python
# pytorch
x = torch.randn(2, 3, 5)
x_reshape = x.reshape(6,5)

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

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

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## [参数不一致]torch.Tensor.split

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

```python
torch.Tensor.split(split_size_or_sections, dim=0)
```

### [paddle.Tensor.split](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#split-num-or-sections-axis-0-name-none)

```python
paddle.Tensor.split(num_or_sections, axis=0, name=None)
```

Pytorch 的 ``split_size_or_sections`` 与 Paddle 的 ``num_or_sections`` 用法不同,具体如下:
### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| dim | axis | 表示需要分割的维度,仅参数名不同。 |
| split_size_or_sections | num_or_sections | torch 的 split_size_or_sections :int 时表示块的大小, list 时表示块的大小; paddle 的 num_or_sections : int 时表示块的个数, list 时表示块的大小。参数类型为 int 时需要转写。|

### 转写示例
#### split_size_or_sections: 参数类型为 int 时表示块的大小
```python
# pytorch
x = torch.randn(8, 2)
x_split_int = x.split(4)

# paddle
x = paddle.randn([8, 2])
x_split_int = x.split(2)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [参数不一致]torch.Tensor.svd

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

```python
torch.Tensor.svd(some=True, compute_uv=True)
```
### [paddle.linalg.svd](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/linalg/svd_cn.html#svd)

```python
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 。

| 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可以进行转写吗,不可以的话备注写 暂不支持转写就可以

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## [参数不一致]torch.Tensor.swapaxes

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

```python
torch.Tensor.swapaxes(axis0, axis1)
```

### [paddle.Tensor.transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#transpose-perm-name-none)

```python
paddle.Tensor.transpose(perm, name=None)
```

Pytorch 的 ``axis0, axis1`` 与 Paddle 的 ``perm`` 用法不同,具体如下:
### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| axis0, axis1 | perm | torch 的 axis0 与 axis1 表示要交换的两个轴,为整数。 paddle 的 perm 表示重排的维度序列,为 list/tuple 。需要转写。|

### 转写示例
#### axis0, axis1: 表示要交换的两个轴
```python
# pytorch
x = torch.randn(2, 3, 5)
x_swapaxes = x.swapaxes(0,1)

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

两个输出变量名要一致

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## [参数不一致]torch.Tensor.swapdims

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

```python
torch.Tensor.swapdims(dim0, dim1)
```

### [paddle.Tensor.transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#transpose-perm-name-none)

```python
paddle.Tensor.transpose(perm, name=None)
```

Pytorch 的 ``dim0, dim1`` 与 Paddle 的 ``perm`` 用法不同,具体如下:
### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| dim0, dim1 | perm | torch 的 dim0 与 dim1 表示要交换的两个维度, 为整数。 paddle 的 perm 表示重排的维度序列,为 list/tuple 。需要转写。|

### 转写示例
#### dim0, dim1: 表示要交换的两个维度
```python
# pytorch
x = torch.randn(2, 3, 5)
x_swapdims = x.swapdims(0,1)

# 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

```
Original file line number Diff line number Diff line change
@@ -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.

链接不正确


```python
torch.Tensor.transpose(dim0, dim1)
```

### [paddle.Tensor.transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#transpose-perm-name-none)

```python
paddle.Tensor.transpose(perm, name=None)
```

Pytorch 的 ``dim0, dim1`` 与 Paddle 的 ``perm`` 用法不同,具体如下:
### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| dim0, dim1 | perm | torch 的 dim0 与 dim1 表示要交换的两个维度, 为整数。 paddle 的 perm 表示重排的维度序列,为 list/tuple 。需要转写。|

### 转写示例
#### dim0, dim1: 表示要交换的两个维度
```python
# pytorch
x = torch.randn(2, 3, 5)
x_transpose = x.transpose(0,1)

# paddle
x = paddle.randn([2, 3, 5])
x_transposed = x.transpose(perm=[1, 0, 2])
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [参数不一致]torch.cuda.device

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

```python
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 名称不正确


```python
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 | 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)

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## [参数不一致]torch.cuda.get_device_name

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

```python
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名称不正确


```python
paddle.device.cuda.get_device_properties(device)
```

两者的返回参数不一致,具体如下:
### 参数映射
| 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 吧

| Returns | Returns | 两者返回类型不一致。 paddle 的返回数据中 name 属性内容与 torch 的返回内容一致。需要转写。|

### 转写示例
```python
# pytorch
torch.cuda.get_device_name()

# paddle
paddle.device.cuda.get_device_properties().name
```