Skip to content

Commit 584a4d1

Browse files
authored
update torch.* mapping (#5618)
* torch.* mapping * fix Difference document
1 parent 3987f66 commit 584a4d1

File tree

134 files changed

+4749
-198
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+4749
-198
lines changed

docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md

Lines changed: 219 additions & 198 deletions
Large diffs are not rendered by default.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## torch.abs
2+
### [torch.abs](https://pytorch.org/docs/stable/generated/torch.abs.html?highlight=abs#torch.abs)
3+
4+
```python
5+
torch.abs(input,
6+
*,
7+
out=None)
8+
```
9+
10+
### [paddle.abs](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/abs_cn.html#abs)
11+
12+
```python
13+
paddle.abs(x,
14+
name=None)
15+
```
16+
17+
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
18+
### 参数差异
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------- | ------------ | ------------------------------------------------------ |
21+
| input | x | 输入的 Tensor。 |
22+
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 |
23+
24+
25+
### 转写示例
26+
#### out:指定输出
27+
```python
28+
# Pytorch 写法
29+
torch.abs([-3, -5], out=y)
30+
31+
# Paddle 写法
32+
y = paddle.abs([-3, -5])
33+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## torch.absolute
2+
### [torch.absolute](https://pytorch.org/docs/stable/generated/torch.absolute.html?highlight=absolute#torch.absolute)
3+
4+
```python
5+
torch.absolute(input,
6+
*,
7+
out=None)
8+
```
9+
10+
### [paddle.abs](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/abs_cn.html#abs)
11+
12+
```python
13+
paddle.abs(x,
14+
name=None)
15+
```
16+
17+
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
18+
### 参数差异
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------- | ------------ | ------------------------------------------------------ |
21+
| input | x | 输入的 Tensor。 |
22+
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 |
23+
24+
25+
### 转写示例
26+
#### out:指定输出
27+
```python
28+
# Pytorch 写法
29+
torch.absolute([-3, -5], out=y)
30+
31+
# Paddle 写法
32+
y = paddle.abs([-3, -5])
33+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## torch.acos
2+
### [torch.acos](https://pytorch.org/docs/stable/generated/torch.acos.html?highlight=acos#torch.acos)
3+
4+
```python
5+
torch.acos(input,
6+
*,
7+
out=None)
8+
```
9+
10+
### [paddle.acos](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/acos_cn.html#acos)
11+
12+
```python
13+
paddle.acos(x,
14+
name=None)
15+
```
16+
17+
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
18+
### 参数差异
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------- | ------------ | ------------------------------------------------------ |
21+
| input | x | 输入的 Tensor。 |
22+
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 |
23+
24+
25+
### 转写示例
26+
#### out:指定输出
27+
```python
28+
# Pytorch 写法
29+
torch.acos([3, 5], out=y)
30+
31+
# Paddle 写法
32+
y = paddle.acos([3, 5])
33+
```
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## torch.add
2+
### [torch.add](https)
3+
4+
```python
5+
torch.add(input,
6+
other,
7+
*,
8+
alpha=1,
9+
out=None)
10+
```
11+
12+
### [paddle.add](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/add_cn.html#add)
13+
14+
```python
15+
paddle.add(x,
16+
y,
17+
name=None)
18+
```
19+
20+
其中 Pytorch 相比 Paddle 支持更多其他参数,具体如下:
21+
### 参数差异
22+
| PyTorch | PaddlePaddle | 备注 |
23+
| ------------- | ------------ | ------------------------------------------------------ |
24+
| input | x | 输入的 Tensor。 |
25+
| other | y | 输入的 Tensor。 |
26+
| alpha | - | other 的乘数,PaddlePaddle 无此参数。 |
27+
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 |
28+
29+
30+
### 转写示例
31+
#### alpha:other 的乘数
32+
```python
33+
# Pytorch 写法
34+
torch.add([3, 5], [2, 3], alpha=2)
35+
36+
# Paddle 写法
37+
paddle.add([3, 5], 2 * [2, 3])
38+
```
39+
40+
#### out:指定输出
41+
```python
42+
# Pytorch 写法
43+
torch.add([3, 5], [2, 3], out=y)
44+
45+
# Paddle 写法
46+
y = paddle.add([3, 5], [2, 3])
47+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## torch.addmv
2+
### [torch.addmv](https://pytorch.org/docs/stable/generated/torch.addmv.html?highlight=addmv#torch.addmv)
3+
```python
4+
torch.addmv(input, mat, vec, beta=1, alpha=1, out=None)
5+
```
6+
7+
### 功能介绍
8+
用于实现矩阵(`mat`)与向量(`vec`)相乘,再加上输入(`input`),公式为:
9+
$ out = β * input + α * (mat @ vec) $
10+
PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。
11+
12+
```python
13+
import paddle
14+
15+
def addmv(input, mat, vec, beta=1, alpha=1, out=None):
16+
mv = alpha * paddle.matmul(mat, vec)
17+
input = beta * input
18+
out = mv + input
19+
return out
20+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## torch.addr
2+
### [torch.addr](https://pytorch.org/docs/stable/generated/torch.addr.html?highlight=addr#torch.addr)
3+
```python
4+
torch.addr(input, vec1, vec2, beta=1, alpha=1, out=None)
5+
```
6+
7+
### 功能介绍
8+
用于实现矩阵(`vec`)与向量(`vec`)相乘,再加上输入(`input`),公式为:
9+
$out = β * input + α * (vec1 ⊗ vec2)$
10+
PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。
11+
12+
```python
13+
import paddle
14+
15+
def addr(input, vec1, vec2, beta=1, alpha=1, out=None):
16+
row = vec1.shape[0]
17+
column = vec2.shape[0]
18+
vec1 = paddle.unsqueeze(vec1, 0)
19+
vec1 = paddle.transpose(vec1, [1, 0])
20+
vec1 = paddle.expand(vec1, [row, column])
21+
new_vec2 = paddle.zeros([column, column], dtype=vec2.dtype)
22+
new_vec2[0, :] = vec2
23+
out = alpha * paddle.matmul(vec1, new_vec2)
24+
out = beta * input + out
25+
return out
26+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## torch.all
2+
### [torch.all](https://pytorch.org/docs/stable/generated/torch.all.html?highlight=all#torch.all)
3+
4+
```python
5+
torch.all(input)
6+
```
7+
8+
### [paddle.all](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/all_cn.html#all)
9+
10+
```python
11+
paddle.all(x,
12+
axis=None,
13+
keepdim=False,
14+
name=None)
15+
```
16+
17+
其中 Paddle 相比 Pytorch 支持更多其他参数,具体如下:
18+
### 参数差异
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------- | ------------ | ------------------------------------------------------ |
21+
| input | x | 输入的多维 Tensor。 |
22+
| - | axis | 计算逻辑与运算的维度,Pytorch 无,保持默认即可。 |
23+
| - | keepdim | 是否在输出 Tensor 中保留减小的维度,Pytorch 无,保持默认即可。 |
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## torch.allclose
2+
### [torch.allclose](https://pytorch.org/docs/stable/generated/torch.allclose.html?highlight=allclose#torch.allclose)
3+
4+
```python
5+
torch.allclose(input,
6+
other,
7+
rtol=1e-05,
8+
atol=1e-08,
9+
equal_nan=False)
10+
```
11+
12+
### [paddle.allclose](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/allclose_cn.html#allclose)
13+
14+
```python
15+
paddle.allclose(x,
16+
y,
17+
rtol=1e-05,
18+
atol=1e-08,
19+
equal_nan=False,
20+
name=None)
21+
```
22+
23+
两者功能一致且参数用法一致,仅参数名不同,具体如下:
24+
### 参数差异
25+
| PyTorch | PaddlePaddle | 备注 |
26+
| ------------- | ------------ | ------------------------------------------------------ |
27+
| input | x | 输入的 Tensor。 |
28+
| other | y | 输入的 Tensor。 |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## torch.any
2+
### [torch.any](https://pytorch.org/docs/stable/generated/torch.any.html?highlight=any#torch.any)
3+
4+
```python
5+
torch.any(input)
6+
```
7+
8+
### [paddle.any](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/any_cn.html#any)
9+
10+
```python
11+
paddle.any(x,
12+
axis=None,
13+
keepdim=False,
14+
name=None)
15+
```
16+
17+
两者功能一致且参数用法一致,仅参数名不同,具体如下:
18+
### 参数差异
19+
| PyTorch | PaddlePaddle | 备注 |
20+
| ------------- | ------------ | ------------------------------------------------------ |
21+
| input | x | 输入的多维 Tensor。 |

0 commit comments

Comments
 (0)