Skip to content

Commit 47a8eec

Browse files
GuoQuanhaoustiniankw
authored andcommitted
add ViT classification (PaddlePaddle#5528)
* add ViT classification * add new ViT classification * add new ViT classification * modify MSA in ViT * fix cl * Updadte the doc * fix all issuse * update-2023-02-10-19-14 * update at 2023-02-13
1 parent aa4a17d commit 47a8eec

File tree

137 files changed

+6051
-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.

137 files changed

+6051
-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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
### 参数差异
18+
| PyTorch | PaddlePaddle | 备注 |
19+
| ------------- | ------------ | ------------------------------------------------------ |
20+
| input | x | 输入的 Tensor。 |
21+
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 |
22+
23+
24+
### 代码示例
25+
``` python
26+
# PyTorch 示例:
27+
torch.abs(torch.tensor([-1, -2, 3]))
28+
# 输出
29+
# tensor([ 1, 2, 3])
30+
```
31+
32+
``` python
33+
# PaddlePaddle 示例:
34+
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
35+
out = paddle.abs(x)
36+
print(out)
37+
# 输出
38+
# [0.4 0.2 0.1 0.3]
39+
```
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
### 参数差异
18+
| PyTorch | PaddlePaddle | 备注 |
19+
| ------------- | ------------ | ------------------------------------------------------ |
20+
| input | x | 输入的 Tensor。 |
21+
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 |
22+
23+
24+
### 代码示例
25+
``` python
26+
# PyTorch 示例:
27+
torch.absolute(torch.tensor([-1, -2, 3]))
28+
# 输出
29+
# tensor([ 1, 2, 3])
30+
```
31+
32+
``` python
33+
# PaddlePaddle 示例:
34+
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
35+
out = paddle.abs(x)
36+
print(out)
37+
# 输出
38+
# [0.4 0.2 0.1 0.3]
39+
```
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
### 参数差异
18+
| PyTorch | PaddlePaddle | 备注 |
19+
| ------------- | ------------ | ------------------------------------------------------ |
20+
| input | x | 输入的 Tensor。 |
21+
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 |
22+
23+
24+
### 代码示例
25+
``` python
26+
# PyTorch 示例:
27+
a = torch.randn(4)
28+
# 输出
29+
# tensor([ 0.3348, -0.5889, 0.2005, -0.1584])
30+
torch.acos(a)
31+
# 输出
32+
# tensor([ 1.2294, 2.2004, 1.3690, 1.7298])
33+
```
34+
35+
``` python
36+
# PaddlePaddle 示例:
37+
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
38+
out = paddle.acos(x)
39+
print(out)
40+
# 输出
41+
# [1.98231317 1.77215425 1.47062891 1.26610367]
42+
```
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
### 参数差异
21+
| PyTorch | PaddlePaddle | 备注 |
22+
| ------------- | ------------ | ------------------------------------------------------ |
23+
| input | x | 输入的 Tensor。 |
24+
| other | y | 输入的 Tensor。 |
25+
| alpha | - | other 的乘数,PaddlePaddle 无此参数。 |
26+
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 |
27+
28+
29+
### 功能差异
30+
31+
#### 使用方式
32+
***PyTorch***:out = input + alpha * other。
33+
***PaddlePaddle***:out = x + y。
34+
35+
### 代码示例
36+
``` python
37+
# PyTorch 示例:
38+
a = torch.randn(4)
39+
a
40+
# 输出
41+
# tensortensor([ 0.0202, 1.0985, 1.3506, -0.6056])
42+
torch.add(a, 20)
43+
# 输出
44+
# tensortensor([ 20.0202, 21.0985, 21.3506, 19.3944])
45+
46+
b = torch.randn(4)
47+
b
48+
# 输出
49+
# tensortensor([-0.9732, -0.3497, 0.6245, 0.4022])
50+
c = torch.randn(4, 1)
51+
c
52+
# 输出
53+
# tensortensor([[ 0.3743],
54+
[-1.7724],
55+
[-0.5811],
56+
[-0.8017]])
57+
torch.add(b, c, alpha=10)
58+
# 输出
59+
# tensor([[ 2.7695, 3.3930, 4.3672, 4.1450],
60+
[-18.6971, -18.0736, -17.0994, -17.3216],
61+
[ -6.7845, -6.1610, -5.1868, -5.4090],
62+
[ -8.9902, -8.3667, -7.3925, -7.6147]])
63+
```
64+
65+
``` python
66+
# PaddlePaddle 示例:
67+
x = paddle.to_tensor([2, 3, 4], 'float64')
68+
y = paddle.to_tensor([1, 5, 2], 'float64')
69+
z = paddle.add(x, y)
70+
print(z)
71+
# 输出
72+
# [3., 8., 6. ]
73+
```
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
| PyTorch | PaddlePaddle | 备注 |
18+
| ------------- | ------------ | ------------------------------------------------------ |
19+
| input | x | 输入的多维 Tensor。 |
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
| PyTorch | PaddlePaddle | 备注 |
24+
| ------------- | ------------ | ------------------------------------------------------ |
25+
| input | x | 输入的 Tensor。 |
26+
| other | y | 输入的 Tensor。 |
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
| PyTorch | PaddlePaddle | 备注 |
18+
| ------------- | ------------ | ------------------------------------------------------ |
19+
| input | x | 输入的多维 Tensor。 |
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## torch.arange
2+
3+
### [torch.arange](https://pytorch.org/docs/stable/generated/torch.arange.html?highlight=arange#torch.arange)
4+
```python
5+
torch.arange(start=0,
6+
end,
7+
step=1,
8+
*,
9+
out=None,
10+
dtype=None,
11+
layout=torch.strided,
12+
device=None,
13+
requires_grad=False)
14+
```
15+
### [paddle.arange](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/arange_cn.html#arange)
16+
```python
17+
paddle.arange(start=0,
18+
end=None,
19+
step=1,
20+
dtype=None,
21+
name=None)
22+
```
23+
24+
### 参数差异
25+
| PyTorch | PaddlePaddle | 备注 |
26+
| ------------- | ------------ | ------------------------------------------------------ |
27+
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 |
28+
| layout | - | 表示布局方式,PaddlePaddle 无此参数。 |
29+
| device | - | 表示 Tensor 存放位置,PaddlePaddle 无此参数。 |
30+
| requires_grad | - | 表示是否不阻断梯度传导,PaddlePaddle 无此参数。 |
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## torch.arccos
2+
### [torch.arccos](https://pytorch.org/docs/stable/generated/torch.arccos.html?highlight=arccos#torch.arccos)
3+
4+
```python
5+
torch.arccos(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+
### 参数差异
18+
| PyTorch | PaddlePaddle | 备注 |
19+
| ------------- | ------------ | ------------------------------------------------------ |
20+
| input | x | 输入的 Tensor。 |
21+
| out | - | 表示输出的 Tensor,PaddlePaddle 无此参数。 |
22+
23+
24+
### 代码示例
25+
``` python
26+
# PyTorch 示例:
27+
a = torch.randn(4)
28+
# 输出
29+
# tensor([ 0.3348, -0.5889, 0.2005, -0.1584])
30+
torch.arccos(a)
31+
# 输出
32+
# tensor([ 1.2294, 2.2004, 1.3690, 1.7298])
33+
```
34+
35+
``` python
36+
# PaddlePaddle 示例:
37+
x = paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])
38+
out = paddle.acos(x)
39+
print(out)
40+
# 输出
41+
# [1.98231317 1.77215425 1.47062891 1.26610367]
42+
```

0 commit comments

Comments
 (0)