Skip to content

update torch.* mapping #5618

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

Merged
merged 3 commits into from
Feb 22, 2023
Merged
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
417 changes: 219 additions & 198 deletions docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions docs/guides/model_convert/ops/torch.abs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## torch.abs
### [torch.abs](https://pytorch.org/docs/stable/generated/torch.abs.html?highlight=abs#torch.abs)

```python
torch.abs(input,
*,
out=None)
```

### [paddle.abs](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/abs_cn.html#abs)

```python
paddle.abs(x,
name=None)
```

其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
### 参数差异
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input | x | 输入的 Tensor。 |
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 |


### 转写示例
#### out:指定输出
```python
# Pytorch 写法
torch.abs([-3, -5], out=y)

# Paddle 写法
y = paddle.abs([-3, -5])
```
33 changes: 33 additions & 0 deletions docs/guides/model_convert/ops/torch.absolute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## torch.absolute
### [torch.absolute](https://pytorch.org/docs/stable/generated/torch.absolute.html?highlight=absolute#torch.absolute)

```python
torch.absolute(input,
*,
out=None)
```

### [paddle.abs](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/abs_cn.html#abs)

```python
paddle.abs(x,
name=None)
```

其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
### 参数差异
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input | x | 输入的 Tensor。 |
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 |


### 转写示例
#### out:指定输出
```python
# Pytorch 写法
torch.absolute([-3, -5], out=y)

# Paddle 写法
y = paddle.abs([-3, -5])
```
33 changes: 33 additions & 0 deletions docs/guides/model_convert/ops/torch.acos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## torch.acos
### [torch.acos](https://pytorch.org/docs/stable/generated/torch.acos.html?highlight=acos#torch.acos)

```python
torch.acos(input,
*,
out=None)
```

### [paddle.acos](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/acos_cn.html#acos)

```python
paddle.acos(x,
name=None)
```

其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
### 参数差异
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input | x | 输入的 Tensor。 |
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 |


### 转写示例
#### out:指定输出
```python
# Pytorch 写法
torch.acos([3, 5], out=y)

# Paddle 写法
y = paddle.acos([3, 5])
```
47 changes: 47 additions & 0 deletions docs/guides/model_convert/ops/torch.add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## torch.add
### [torch.add](https)

```python
torch.add(input,
other,
*,
alpha=1,
out=None)
```

### [paddle.add](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/add_cn.html#add)

```python
paddle.add(x,
y,
name=None)
```

其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
### 参数差异
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input | x | 输入的 Tensor。 |
| other | y | 输入的 Tensor。 |
| alpha | - | other 的乘数,PaddlePaddle 无此参数。 |
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 |


### 转写示例
#### alpha:other 的乘数
```python
# Pytorch 写法
torch.add([3, 5], [2, 3], alpha=2)

# Paddle 写法
paddle.add([3, 5], 2 * [2, 3])
```

#### out:指定输出
```python
# Pytorch 写法
torch.add([3, 5], [2, 3], out=y)

# Paddle 写法
y = paddle.add([3, 5], [2, 3])
```
20 changes: 20 additions & 0 deletions docs/guides/model_convert/ops/torch.addmv.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## torch.addmv
### [torch.addmv](https://pytorch.org/docs/stable/generated/torch.addmv.html?highlight=addmv#torch.addmv)
```python
torch.addmv(input, mat, vec, beta=1, alpha=1, out=None)
```

### 功能介绍
用于实现矩阵(`mat`)与向量(`vec`)相乘,再加上输入(`input`),公式为:
$ out = β * input + α * (mat @ vec) $
PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。

```python
import paddle

def addmv(input, mat, vec, beta=1, alpha=1, out=None):
mv = alpha * paddle.matmul(mat, vec)
input = beta * input
out = mv + input
return out
```
26 changes: 26 additions & 0 deletions docs/guides/model_convert/ops/torch.addr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## torch.addr
### [torch.addr](https://pytorch.org/docs/stable/generated/torch.addr.html?highlight=addr#torch.addr)
```python
torch.addr(input, vec1, vec2, beta=1, alpha=1, out=None)
```

### 功能介绍
用于实现矩阵(`vec`)与向量(`vec`)相乘,再加上输入(`input`),公式为:
$out = β * input + α * (vec1 ⊗ vec2)$
PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。

```python
import paddle

def addr(input, vec1, vec2, beta=1, alpha=1, out=None):
row = vec1.shape[0]
column = vec2.shape[0]
vec1 = paddle.unsqueeze(vec1, 0)
vec1 = paddle.transpose(vec1, [1, 0])
vec1 = paddle.expand(vec1, [row, column])
new_vec2 = paddle.zeros([column, column], dtype=vec2.dtype)
new_vec2[0, :] = vec2
out = alpha * paddle.matmul(vec1, new_vec2)
out = beta * input + out
return out
```
23 changes: 23 additions & 0 deletions docs/guides/model_convert/ops/torch.all.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## torch.all
### [torch.all](https://pytorch.org/docs/stable/generated/torch.all.html?highlight=all#torch.all)

```python
torch.all(input)
```

### [paddle.all](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/all_cn.html#all)

```python
paddle.all(x,
axis=None,
keepdim=False,
name=None)
```

其中 Paddle 相比 Pytorch 支持更多其他参数,具体如下:
### 参数差异
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input | x | 输入的多维 Tensor。 |
| - | axis | 计算逻辑与运算的维度,Pytorch 无,保持默认即可。 |
| - | keepdim | 是否在输出 Tensor 中保留减小的维度,Pytorch 无,保持默认即可。 |
28 changes: 28 additions & 0 deletions docs/guides/model_convert/ops/torch.allclose.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## torch.allclose
### [torch.allclose](https://pytorch.org/docs/stable/generated/torch.allclose.html?highlight=allclose#torch.allclose)

```python
torch.allclose(input,
other,
rtol=1e-05,
atol=1e-08,
equal_nan=False)
```

### [paddle.allclose](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/allclose_cn.html#allclose)

```python
paddle.allclose(x,
y,
rtol=1e-05,
atol=1e-08,
equal_nan=False,
name=None)
```

两者功能一致且参数用法一致,仅参数名不同,具体如下:
### 参数差异
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input | x | 输入的 Tensor。 |
| other | y | 输入的 Tensor。 |
21 changes: 21 additions & 0 deletions docs/guides/model_convert/ops/torch.any.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## torch.any
### [torch.any](https://pytorch.org/docs/stable/generated/torch.any.html?highlight=any#torch.any)

```python
torch.any(input)
```

### [paddle.any](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/any_cn.html#any)

```python
paddle.any(x,
axis=None,
keepdim=False,
name=None)
```

两者功能一致且参数用法一致,仅参数名不同,具体如下:
### 参数差异
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input | x | 输入的多维 Tensor。 |
56 changes: 56 additions & 0 deletions docs/guides/model_convert/ops/torch.arange.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## torch.arange

### [torch.arange](https://pytorch.org/docs/stable/generated/torch.arange.html?highlight=arange#torch.arange)

```python
torch.arange(start=0,
end,
step=1,
*,
out=None,
dtype=None,
layout=torch.strided,
device=None,
requires_grad=False)
```

### [paddle.arange](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/arange_cn.html#arange)

```python
paddle.arange(start=0,
end=None,
step=1,
dtype=None,
name=None)
```

其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
### 参数差异
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 |
| layout | - | 表示布局方式,PaddlePaddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| device | - | 表示 Tensor 存放位置,PaddlePaddle 无此参数,一般对网络训练结果影响不大,可直接删除。 |
| requires_grad | - | 表示是否不阻断梯度传导,PaddlePaddle 无此参数。 |


### 转写示例
#### out:指定输出
```python
# Pytorch 写法
torch.arange(5, out=y)

# Paddle 写法
y = paddle.arange(5)
```


#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性
```python
# Pytorch 写法
x = torch.arange(5, requires_grad=True)

# Paddle 写法
x = paddle.arange(5)
x.stop_gradient = False
```
33 changes: 33 additions & 0 deletions docs/guides/model_convert/ops/torch.arccos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## torch.arccos
### [torch.arccos](https://pytorch.org/docs/stable/generated/torch.arccos.html?highlight=arccos#torch.arccos)

```python
torch.arccos(input,
*,
out=None)
```

### [paddle.acos](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/acos_cn.html#acos)

```python
paddle.acos(x,
name=None)
```

其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
### 参数差异
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input | x | 输入的 Tensor。 |
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 |


### 转写示例
#### out:指定输出
```python
# Pytorch 写法
torch.arccos([3, 5], out=y)

# Paddle 写法
y = paddle.acos([3, 5])
```
33 changes: 33 additions & 0 deletions docs/guides/model_convert/ops/torch.arcsin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## torch.arcsin
### [torch.arcsin](https://pytorch.org/docs/stable/generated/torch.arcsin.html?highlight=arcsin#torch.arcsin)

```python
torch.arcsin(input,
*,
out=None)
```

### [paddle.asin](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/asin_cn.html#asin)

```python
paddle.asin(x,
name=None)
```

其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
### 参数差异
| PyTorch | PaddlePaddle | 备注 |
| ------------- | ------------ | ------------------------------------------------------ |
| input | x | 输入的 Tensor。 |
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 |


### 转写示例
#### out:指定输出
```python
# Pytorch 写法
torch.arcsin([-0.5962, 1.4985, -0.4396, 1.4525], out=y)

# Paddle 写法
y = paddle.asin([-0.5962, 1.4985, -0.4396, 1.4525])
```
Loading