File tree Expand file tree Collapse file tree 4 files changed +123
-1
lines changed
docs/guides/model_convert/convert_from_pytorch Expand file tree Collapse file tree 4 files changed +123
-1
lines changed Original file line number Diff line number Diff line change
1
+ ## [ 返回参数类型不一致 ] torch.Tensor.max
2
+
3
+ 该 api 有两组参数列表重载,因此有两组差异分析。
4
+
5
+ -----------------------------------------------
6
+
7
+ ### [ torch.Tensor.max] ( https://pytorch.org/docs/stable/generated/torch.Tensor.max.html )
8
+
9
+ ``` python
10
+ torch.Tensor.max(dim = None , keepdim = False )
11
+ ```
12
+
13
+ ### [ paddle.Tensor.max] ( https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#max-axis-none-keepdim-false-name-none )
14
+
15
+ ``` python
16
+ paddle.Tensor.max(axis = None , keepdim = False , name = None )
17
+ ```
18
+
19
+ 其中 PyTorch 与 Paddle 指定 ` dim ` 后返回值不一致,具体如下:
20
+
21
+ ### 参数映射
22
+
23
+ | PyTorch | PaddlePaddle | 备注 |
24
+ | ------------- | ------------ | ------------------------------------------------------ |
25
+ | dim | axis | 求最大值运算的维度, 仅参数名不一致。 |
26
+ | keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 |
27
+ | 返回值 | 返回值 | 表示返回结果,当指定 dim 后,PyTorch 会返回比较结果和元素索引, Paddle 不会返回元素索引,需要转写。 |
28
+
29
+ ### 转写示例
30
+
31
+ #### 指定 dim 后的返回值
32
+ ``` python
33
+ # PyTorch 写法
34
+ result = x.max(dim = 1 )
35
+
36
+ # Paddle 写法
37
+ result = x.max(dim = 1 ), x.argmax(dim = 1 )
38
+ ```
39
+
40
+ --------------------------------------------------------------
41
+
42
+ ### [ torch.Tensor.max] ( https://pytorch.org/docs/stable/generated/torch.Tensor.max.html )
43
+
44
+ ``` python
45
+ torch.Tensor.max(other)
46
+ ```
47
+
48
+ ### [ paddle.Tensor.maximum] ( https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#maximum-y-axis-1-name-none )
49
+
50
+ ``` python
51
+ paddle.Tensor.maximum(y)
52
+ ```
53
+
54
+ 两者功能一致且参数用法一致,仅参数名不一致,具体如下:
55
+
56
+ ### 参数映射
57
+
58
+ | PyTorch | PaddlePaddle | 备注 |
59
+ | ----------------- | ---------------------- | ------------------------------------ |
60
+ | other | y | 输⼊ Tensor ,仅参数名不一致。 |
Original file line number Diff line number Diff line change
1
+ ## [ 返回参数类型不一致 ] torch.Tensor.min
2
+
3
+ 该 api 有两组参数列表重载,因此有两组差异分析。
4
+
5
+ -----------------------------------------------
6
+
7
+ ### [ torch.Tensor.min] ( https://pytorch.org/docs/stable/generated/torch.Tensor.min.html )
8
+
9
+ ``` python
10
+ torch.Tensor.min(dim = None , keepdim = False )
11
+ ```
12
+
13
+ ### [ paddle.Tensor.min] ( https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#min-axis-none-keepdim-false-name-none )
14
+
15
+ ``` python
16
+ paddle.Tensor.min(axis = None , keepdim = False , name = None )
17
+ ```
18
+
19
+ 其中 PyTorch 与 Paddle 指定 ` dim ` 后返回值不一致,具体如下:
20
+
21
+ ### 参数映射
22
+
23
+ | PyTorch | PaddlePaddle | 备注 |
24
+ | ------------- | ------------ | ------------------------------------------------------ |
25
+ | dim | axis | 求最小值运算的维度, 仅参数名不一致。 |
26
+ | keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 |
27
+ | 返回值 | 返回值 | 表示返回结果,当指定 dim 后,PyTorch 会返回比较结果和元素索引, Paddle 不会返回元素索引,需要转写。 |
28
+
29
+ ### 转写示例
30
+
31
+ #### 指定 dim 后的返回值
32
+ ``` python
33
+ # PyTorch 写法
34
+ result = x.min(dim = 1 )
35
+
36
+ # Paddle 写法
37
+ result = x.min(dim = 1 ), x.argmin(dim = 1 )
38
+ ```
39
+
40
+ --------------------------------------------------------------
41
+
42
+ ### [ torch.Tensor.min] ( https://pytorch.org/docs/stable/generated/torch.Tensor.min.html )
43
+
44
+ ``` python
45
+ torch.Tensor.min(other)
46
+ ```
47
+
48
+ ### [ paddle.Tensor.minimum] ( https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#minimum-y-axis-1-name-none )
49
+
50
+ ``` python
51
+ paddle.Tensor.minimum(y)
52
+ ```
53
+
54
+ 两者功能一致且参数用法一致,仅参数名不一致,具体如下:
55
+
56
+ ### 参数映射
57
+
58
+ | PyTorch | PaddlePaddle | 备注 |
59
+ | ----------------- | ---------------------- | ------------------------------------ |
60
+ | other | y | 输⼊ Tensor ,仅参数名不一致。 |
Original file line number Diff line number Diff line change 1
1
## [ 返回参数类型不一致 ] torch.max
2
2
输入一个 Tensor 对应 paddle.max,输入两个 Tensor 对应 paddle.maximum,因此有两组差异分析,分别如下:
3
3
4
- --------------------------------------------------------------------------------------------------
4
+ -------------------------------------------------------------------------------------------------
5
+
5
6
### [ torch.max] ( https://pytorch.org/docs/stable/generated/torch.max.html?highlight=max#torch.max )
6
7
7
8
``` python
Original file line number Diff line number Diff line change @@ -132,6 +132,7 @@ def get_meta_from_diff_file(filepath):
132
132
args_pattern = re .compile (r"^### 参数映射$" )
133
133
ARGS_EXPECT_HEADERS = ["PyTorch" , "PaddlePaddle" , "备注" ]
134
134
135
+ mapping_type = ""
135
136
signature_cache = None
136
137
137
138
with open (filepath , "r" , encoding = "utf-8" ) as f :
You can’t perform that action at this time.
0 commit comments