Skip to content

Commit ee74fd0

Browse files
authored
【映射文档】添加了 torch.Tensor.maxtorch.Tensor.min 映射文档 (#6681)
* fix error * add torch.Tensor.max * add torch.Tensor.min
1 parent 86e31cc commit ee74fd0

File tree

4 files changed

+123
-1
lines changed

4 files changed

+123
-1
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 ,仅参数名不一致。 |
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 ,仅参数名不一致。 |

docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.max.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
## [ 返回参数类型不一致 ]torch.max
22
输入一个 Tensor 对应 paddle.max,输入两个 Tensor 对应 paddle.maximum,因此有两组差异分析,分别如下:
33

4-
--------------------------------------------------------------------------------------------------
4+
-------------------------------------------------------------------------------------------------
5+
56
### [torch.max](https://pytorch.org/docs/stable/generated/torch.max.html?highlight=max#torch.max)
67

78
```python

docs/guides/model_convert/convert_from_pytorch/validate_mapping_in_api_difference.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def get_meta_from_diff_file(filepath):
132132
args_pattern = re.compile(r"^### 参数映射$")
133133
ARGS_EXPECT_HEADERS = ["PyTorch", "PaddlePaddle", "备注"]
134134

135+
mapping_type = ""
135136
signature_cache = None
136137

137138
with open(filepath, "r", encoding="utf-8") as f:

0 commit comments

Comments
 (0)