Skip to content

Commit

Permalink
映射文档 add some api (#5982)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhwesky2010 authored Jun 28, 2023
1 parent f0d96a4 commit 7a7411e
Show file tree
Hide file tree
Showing 40 changed files with 1,082 additions and 146 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [ 仅参数名不同 ] torch.Tensor.maximum

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

```python
torch.Tensor.maximum(other)
```

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

```python
paddle.Tensor.maximum(y)
```

两者功能一致且参数用法一致,仅参数名不同,具体如下:

| PyTorch | PaddlePaddle | 备注 |
|----------------------------------|---------------------------------|------------------------------------|
| other | y | 输⼊第二个 Tensor ,仅参数名不同。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## [ 仅参数名不同 ] torch.Tensor.minimum

### [torch.Tnsor.,minimum](https://pytorch.org/docs/stable/generated/torch.Tensor.minimum.html)

```python
torch.Tensor.maximum(other)
```

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

```python
paddle.Tensor.minimum(y)
```

两者功能一致且参数用法一致,仅参数名不同,具体如下:

| PyTorch | PaddlePaddle | 备注 |
|----------------------------------|---------------------------------|------------------------------------|
| other | y | 输⼊第二个 Tensor ,仅参数名不同。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## [ 参数完全一致 ]torch.Tensor.mm

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

```python
torch.Tensor.mm(mat2)
```

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

```python
paddle.Tensor.mm(mat2, name=None)
```

两者功能一致且参数用法一致,具体如下:

### 参数映射

| PyTorch | PaddlePaddle | 备注 |
|---------------------------------|---------------------------------| ----------------------------------------- |
| <font> mat2 </font> | <font> mat2 </font> | 输⼊ Tensor 。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## [ 参数完全一致 ]torch.Tensor.moveaxis

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

```python
torch.Tensor.moveaxis(source, destination)
```

### [paddle.Tensor.moveaxis](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/moveaxis_cn.html)

```python
paddle.Tensor.moveaxis(source, destination,name = None)
```

两者功能一致且参数用法一致,具体如下:

| PyTorch | PaddlePaddle | 备注 |
|------------------------------------|------------------------------------|----------------------------------|
| <font> source </font> | <font> source </font> | 将被移动的轴的位置。 |
| <font> destination </font> | <font> destination </font> | 轴被移动后的目标位置。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## [ 参数完全一致 ]torch.Tensor.movedim

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

```python
torch.Tensor.movedim(source, destination)
```

### [paddle.Tensor.moveaxis](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/moveaxis_cn.html)

```python
paddle.Tensor.moveaxis(source, destination, name = None)
```

两者功能一致且参数用法一致,具体如下:

| PyTorch | PaddlePaddle | 备注 |
|------------------------------------|------------------------------------|----------------------------------|
| <font> source </font> | <font> source </font> | 将被移动的轴的位置。 |
| <font> destination </font> | <font> destination </font> | 轴被移动后的目标位置。 |
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。对于可变参数的用法,需要进行转写。 |

### 转写示例
#### *dims: 可变参数用法
```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。对于可变参数的用法,需要进行转写。 |

### 转写示例
#### *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 支持可变参数或 list/tuple,paddle 仅支持 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.reshape((6, 5))
```
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
## [组合替代实现]torch.Tensor.scatter_add
## [ 仅 paddle 参数更多 ]torch.Tensor.scatter_add

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

```python
torch.Tensor.scatter_add(dim, index, src)
```

Paddle 无此 API,需要组合实现。

### 转写示例
### [paddle.Tensor.put_along_axis](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/put_along_axis_cn.html)

```python
# Pytorch 写法
x.scatter_add(dim, index, src)

# Paddle 写法
x2 = paddle.zeros(x.shape)
y = x + x2.put_along_axis(index, value, axis)
paddle.Tensor.put_along_axis(indices,
values,
axis,
reduce='assign')
```

其中 Paddle 相比 Pytorch 支持更多其他参数,具体如下:

### 参数差异
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| dim | axis | 表示在哪一个维度 scatter ,仅参数名不一致。 |
| index | indices | 表示输入的索引张量,仅参数名不一致。 |
| src | values | 表示需要插入的值,仅参数名不一致。 |
| - | reduce | 表示对输出 Tensor 的计算方式, PyTorch 无此参数, Paddle 应设置为 'add' 。 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## [ 仅 paddle 参数更多 ]torch.Tensor.scatter_add_

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

```python
torch.Tensor.scatter_add_(dim,
index,
src)
```

### [paddle.Tensor.put_along_axis_](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/put_along_axis__cn.html)

```python
paddle.Tensor.put_along_axis_(indices,
values,
axis,
reduce='assign')
```

其中 Paddle 相比 Pytorch 支持更多其他参数,具体如下:

### 参数差异
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| dim | axis | 表示在哪一个维度 scatter ,仅参数名不一致。 |
| index | indices | 表示输入的索引张量,仅参数名不一致。 |
| src | values | 表示需要插入的值,仅参数名不一致。 |
| - | reduce | 表示对输出 Tensor 的计算方式, PyTorch 无此参数, Paddle 应设置为 'add' 。 |
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:int 时表示块的大小, list 时表示块的大小; paddle: int 时表示块的个数, list 时表示块的大小。因此对于 int 时,两者用法不同,需要转写。|

### 转写示例
#### split_size_or_sections: 为 int 时 torch 表示块的大小,paddle 表示块的个数
```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,30 @@
## [ 参数不一致 ]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。 |
| 返回值 | 返回值 | 两者返回类型不一致。torch 返回字符串,paddle 返回包含设备多个属性的数据结构,对其取 name 属性即可。需要转写。|

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

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

0 comments on commit 7a7411e

Please sign in to comment.