Skip to content

Commit e6800c7

Browse files
authored
映射文档 No. 54 (#5852)
* 新增5个api映射文档,修改5个原有文档的内容 * modify torch.nn.CTCLoss.md
1 parent 4da15bc commit e6800c7

10 files changed

+231
-16
lines changed

docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCELoss.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ paddle.nn.BCELoss(weight=None,
2121
| PyTorch | PaddlePaddle | 备注 |
2222
| ------------- | ------------ | ------------------------------------------------------ |
2323
| weight | weight | 表示每个 batch 二值交叉熵的权重。 |
24-
| size_average | - | PyTorch 已弃用 |
25-
| reduce | - | PyTorch 已弃用 |
24+
| size_average | - | PyTorch 已弃用,paddle 需要转写。 |
25+
| reduce | - | PyTorch 已弃用,paddle 需要转写。 |
2626
| reduction | reduction | 表示应用于输出结果的计算方式。 |
2727

2828
### 转写示例

docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCEWithLogitsLoss.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# [ torch 参数更多 ]torch.nn.BCEWithLogitsLoss
2-
### [torch.nn.BCEWithLogitsLoss](https)
2+
### [torch.nn.BCEWithLogitsLoss](https://pytorch.org/docs/1.13/generated/torch.nn.BCEWithLogitsLoss.html#bcewithlogitsloss)
33

44
```python
55
torch.nn.BCEWithLogitsLoss(weight=None,
@@ -23,8 +23,8 @@ paddle.nn.BCEWithLogitsLoss(weight=None,
2323
| PyTorch | PaddlePaddle | 备注 |
2424
| ------------- | ------------ | ------------------------------------------------------ |
2525
| weight | weight | 表示每个 batch 二值交叉熵的权重。 |
26-
| size_average | - | PyTorch 已弃用 |
27-
| reduce | - | PyTorch 已弃用 |
26+
| size_average | - | PyTorch 已弃用,paddle 需要转写。 |
27+
| reduce | - | PyTorch 已弃用,paddle 需要转写。 |
2828
| reduction | reduction | 表示应用于输出结果的计算方式。 |
2929
| pos_weight | pos_weight | 表示正类的权重。 |
3030

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# [torch 参数更多]torch.nn.CTCLoss
2+
3+
### [torch.nn.CTCLoss](https://pytorch.org/docs/1.13/generated/torch.nn.CTCLoss.html#torch.nn.CTCLoss)
4+
5+
```python
6+
torch.nn.CTCLoss(blank=0,
7+
reduction='mean',
8+
zero_infinity=False)
9+
```
10+
11+
### [paddle.nn.CTCLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/CTCLoss_cn.html#ctcloss)
12+
13+
```python
14+
paddle.nn.CTCLoss(blank=0,
15+
reduction='mean')
16+
```
17+
18+
其中,Pytorch 相比 Paddle 支持更多其他参数,具体如下:
19+
20+
### 参数映射
21+
22+
| PyTorch | Paddle | 备注 |
23+
| ------------- | --------- | ------------------------------------------------------------ |
24+
| blank | blank | 空格标记的 ID 值。 |
25+
| reduction | reduction | 表示应用于输出结果的计算方式。 |
26+
| zero_infinity | - | 是否将无穷大损失及其梯度置 0,Paddle 无此参数,需要转写,paddle 暂无转写方式。 |

docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CrossEntropyLoss.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# [torch 参数更多]torch.nn.CrossEntropyLoss
2-
### [torch.nn.CrossEntropyLoss](https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html?highlight=crossentropyloss#torch.nn.CrossEntropyLoss)
2+
### [torch.nn.CrossEntropyLoss](https://pytorch.org/docs/1.13/generated/torch.nn.CrossEntropyLoss.html#torch.nn.CrossEntropyLoss)
33

44
```python
55
torch.nn.CrossEntropyLoss(weight=None,
@@ -26,13 +26,13 @@ paddle.nn.CrossEntropyLoss(weight=None,
2626
| PyTorch | PaddlePaddle | 备注 |
2727
| ------------- | ------------ | ------------------------------------------------------ |
2828
| weight | weight | 表示每个类别的权重。 |
29-
| <font color='red'> size_average </font> | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
29+
| size_average | - | PyTorch 已弃用,Paddle 无此参数,需要转写。|
3030
| ignore_index | ignore_index | 表示忽略的一个标签值。 |
31-
| <font color='red'> reduce </font> | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
31+
| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
3232
| reduction | reduction | 表示应用于输出结果的计算方式。 |
33-
| <font color='red'> label_smoothing </font> | - | 指定计算损失时的平滑量,Paddle 无此功能,暂无转写方式。 |
34-
| - | <font color='red'> soft_label </font> | 指明 label 是否为软标签,Pytorch 无此参数,Paddle 保持默认即可。 |
35-
| - | <font color='red'> axis </font> | 进行 softmax 计算的维度索引,Pytorch 无此参数,Paddle 保持默认即可。 |
33+
| label_smoothing | - | 指定计算损失时的平滑量,Paddle 无此功能,暂无转写方式。 |
34+
| - | soft_label | 指明 label 是否为软标签,Pytorch 无此参数,Paddle 保持默认即可。 |
35+
| - | axis | 进行 softmax 计算的维度索引,Pytorch 无此参数,Paddle 保持默认即可。 |
3636

3737
### 转写示例
3838
#### size_average
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# [torch 参数更多]torch.nn.HingeEmbeddingLoss
2+
3+
### [torch.nn.HingeEmbeddingLoss](https://pytorch.org/docs/1.13/generated/torch.nn.HingeEmbeddingLoss.html#hingeembeddingloss)
4+
5+
```python
6+
torch.nn.HingeEmbeddingLoss(margin=1.0,
7+
size_average=None,
8+
reduce=None,
9+
reduction='mean')
10+
```
11+
12+
### [paddle.nn.HingeEmbeddingLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/HingeEmbeddingLoss_cn.html#hingeembeddingloss)
13+
14+
```python
15+
paddle.nn.HingeEmbeddingLoss(margin=1.0,
16+
reduction='mean',
17+
name=None)
18+
```
19+
20+
Pytorch 相比 Paddle 支持更多其他参数,具体如下:
21+
22+
### 参数映射
23+
24+
| PyTorch | Paddle | 备注 |
25+
| ------------ | --------- | ------------------------------------------------------------ |
26+
| margin | margin | 当 label 为-1 时,该值决定了小于 margin 的 input 才需要纳入 hinge embedding loss 的计算。 |
27+
| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
28+
| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
29+
| reduction | reduction | 表示应用于输出结果的计算方式。 |
30+
31+
### 转写示例
32+
33+
#### size_average
34+
35+
```python
36+
# Pytorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数
37+
if size_average is None:
38+
size_average = True
39+
if reduce is None:
40+
reduce = True
41+
42+
if size_average and reduce:
43+
reduction = 'mean'
44+
elif reduce:
45+
reduction = 'sum'
46+
else:
47+
reduction = 'none'
48+
```

docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.KLDivLoss.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ paddle.nn.KLDivLoss(reduction='mean')
1818
### 参数差异
1919
| PyTorch | PaddlePaddle | 备注 |
2020
| ------------- | ------------ | ------------------------------------------------------ |
21-
| size_average | - | 已弃用 |
22-
| reduce | - | 已弃用 |
21+
| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
22+
| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
2323
| reduction | reduction | 表示对输出结果的计算方式。 |
2424
| log_target | - | 指定目标是否为日志空间,Paddle 无此功能,暂无转写方式。 |
2525

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# [torch 参数更多]torch.nn.MarginRankingLoss
2+
3+
### [torch.nn.MarginRankingLoss](https://pytorch.org/docs/1.13/generated/torch.nn.MarginRankingLoss.html#marginrankingloss)
4+
5+
```python
6+
torch.nn.MarginRankingLoss(margin=0.0,
7+
size_average=None,
8+
reduce=None,
9+
reduction='mean')
10+
```
11+
12+
### [paddle.nn.MarginRankingLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/MarginRankingLoss_cn.html#marginrankingloss)
13+
14+
```python
15+
paddle.nn.MarginRankingLoss(margin=0.0,
16+
reduction='mean',
17+
name=None)
18+
```
19+
20+
Pytorch 相比 Paddle 支持更多其他参数,具体如下:
21+
22+
### 参数映射
23+
24+
| PyTorch | Paddle | 备注 |
25+
| ------------ | --------- | -------------------------------------------- |
26+
| margin | margin | 用于加和的 margin 值。 |
27+
| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
28+
| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
29+
| reduction | reduction | 表示应用于输出结果的计算方式。 |
30+
31+
### 转写示例
32+
33+
#### size_average
34+
35+
```python
36+
# Pytorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数
37+
if size_average is None:
38+
size_average = True
39+
if reduce is None:
40+
reduce = True
41+
42+
if size_average and reduce:
43+
reduction = 'mean'
44+
elif reduce:
45+
reduction = 'sum'
46+
else:
47+
reduction = 'none'
48+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# [torch 参数更多]torch.nn.NLLLoss
2+
3+
### [torch.nn.NLLLoss](https://pytorch.org/docs/1.13/generated/torch.nn.NLLLoss.html?highlight=nllloss#torch.nn.NLLLoss)
4+
5+
```python
6+
torch.nn.NLLLoss(weight=None,
7+
size_average=None,
8+
ignore_index=- 100,
9+
reduce=None,
10+
reduction='mean')
11+
```
12+
13+
### [paddle.nn.NLLLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/NLLLoss_cn.html#nllloss)
14+
15+
```python
16+
paddle.nn.NLLLoss(weight=None,
17+
ignore_index=- 100,
18+
reduction='mean',
19+
name=None)
20+
```
21+
22+
Pytorch 相比 Paddle 支持更多其他参数,具体如下:
23+
24+
### 参数映射
25+
| PyTorch | Paddle | 备注 |
26+
| ------------ | ------------ | -------------------------------------------- |
27+
| weight | weight | 表示每个类别的权重。 |
28+
| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
29+
| ignore_index | ignore_index | 表示忽略的一个标签值。 |
30+
| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
31+
| reduction | reduction | 表示应用于输出结果的计算方式。 |
32+
33+
### 转写示例
34+
#### size_average
35+
```python
36+
# Pytorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数
37+
if size_average is None:
38+
size_average = True
39+
if reduce is None:
40+
reduce = True
41+
42+
if size_average and reduce:
43+
reduction = 'mean'
44+
elif reduce:
45+
reduction = 'sum'
46+
else:
47+
reduction = 'none'
48+
```

docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SmoothL1Loss.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ paddle.nn.SmoothL1Loss(reduction='mean',
2020
### 参数映射
2121
| PyTorch | PaddlePaddle | 备注 |
2222
| ------------- | ------------ | ------------------------------------------------------ |
23-
| size_average | - | 已弃用 |
24-
| reduce | - | 已弃用 |
25-
| reduction | reduction | 表示对输出 Tensor 的计算方式。 |
23+
| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
24+
| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
25+
| reduction | reduction | 表示应用于输出结果的计算方式。 |
2626
| beta | delta | SmoothL1Loss 损失的阈值参数。 |
2727

2828
### 转写示例
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# [torch 参数更多]torch.nn.SoftMarginLoss
2+
3+
### [torch.nn.SoftMarginLosss](https://pytorch.org/docs/1.13/generated/torch.nn.SoftMarginLoss.html#torch.nn.SoftMarginLoss)
4+
5+
```python
6+
torch.nn.SoftMarginLoss(size_average=None,
7+
reduce=None,
8+
reduction='mean')
9+
```
10+
11+
### [paddle.nn.SoftMarginLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/SoftMarginLoss_cn.html#softmarginloss)
12+
13+
```python
14+
paddle.nn.SoftMarginloss(reduction='mean',
15+
name=None)
16+
```
17+
18+
Pytorch 相比 Paddle 支持更多其他参数,具体如下:
19+
20+
### 参数映射
21+
22+
| PyTorch | Paddle | 备注 |
23+
| ------------ | --------- | -------------------------------------------- |
24+
| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
25+
| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 |
26+
| reduction | reduction | 表示应用于输出结果的计算方式。 |
27+
28+
### 转写示例
29+
30+
#### size_average
31+
32+
```python
33+
# Pytorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数
34+
if size_average is None:
35+
size_average = True
36+
if reduce is None:
37+
reduce = True
38+
39+
if size_average and reduce:
40+
reduction = 'mean'
41+
elif reduce:
42+
reduction = 'sum'
43+
else:
44+
reduction = 'none'
45+
```

0 commit comments

Comments
 (0)