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

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

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

# paddle
x = paddle.randn([2, 3, 5])
y = 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` 参数用法不同,具体如下:
### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| *sizes | repeat_times | torch 支持可变参数或 list/tuple,paddle 仅支持 list/tuple/Tensor,参数用法不一致,需要进行转写。|

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

# paddle
x = paddle.randn([2, 3, 5])
y = x.tile((4,2,1))
```
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` 参数用法不同,具体如下:
### 参数映射
| 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)
y = x.reshape(6,5)

# 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

```
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)
y = x.split(4)

# paddle
x = paddle.randn([8, 2])
y = x.split(2)
```
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.transpose.html)

```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)
y = x.transpose(0,1)

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

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

```python
torch.cuda.device(device)
```

### [paddle.CUDAPlace](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/CUDAPlace_cn.html#cudaplace)

```python
paddle.CUDAPlace(id)
```

Pytorch 的 `device` 与 Paddle 的 `id` 用法不同,具体如下:
### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| device | id | torch 的 device 参数类型为 torch.device 或 int 。paddle 的 id 为 int。 torch 参数为 int 时无需转写, 参数为 torch.device 时,需要转写。|

### 转写示例
```python
# 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.device.cuda.get_device_properties](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/device/cuda/get_device_properties_cn.html#get-device-properties)

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

两者的返回参数不一致,具体如下:
### 参数映射
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| device | device | torch 的 device 参数类型为 torch.device 或 int 或 str。paddle 的 device 为 paddle.CUDAPlace 或 int 或 str。 |
| Returns | Returns | 两者返回类型不一致。 paddle 的返回数据中 name 属性内容与 torch 的返回内容一致。需要转写。|

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

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