Skip to content

Commit cbe4988

Browse files
committed
fix the loss docs
1 parent 9e9b535 commit cbe4988

17 files changed

+802
-176
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
2525
| reduction | reduction | 表示应用于输出结果的计算方式。 |
2626

2727
### 转写示例
28-
#### size_averagesize_average 为 True
28+
#### size_average
29+
size_average 为 True
2930
```python
3031
# PyTorch 写法
3132
torch.nn.BCELoss(weight=w, size_average=True)
@@ -43,7 +44,8 @@ torch.nn.BCELoss(weight=w, size_average=False)
4344
paddle.nn.BCELoss(weight=w, reduction='sum')
4445
```
4546

46-
#### reducereduce 为 True
47+
#### reduce
48+
reduce 为 True
4749
```python
4850
# PyTorch 写法
4951
torch.nn.BCELoss(weight=w, reduce=True)
@@ -61,7 +63,8 @@ torch.nn.BCELoss(weight=w, reduce=False)
6163
paddle.nn.BCELoss(weight=w, reduction='none')
6264
```
6365

64-
#### reductionreduction 为'none'
66+
#### reduction
67+
reduction 为'none'
6568
```python
6669
# PyTorch 写法
6770
torch.nn.BCELoss(weight=w, reduction='none')

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
2828
| pos_weight | pos_weight | 表示正类的权重。 |
2929

3030
### 转写示例
31-
#### size_averagesize_average 为 True
31+
#### size_average
32+
size_average 为 True
3233
```python
3334
# PyTorch 写法
3435
torch.nn.BCEWithLogitsLoss(weight=w, size_average=True)
@@ -46,7 +47,8 @@ torch.nn.BCEWithLogitsLoss(weight=w, size_average=False)
4647
paddle.nn.BCEWithLogitsLoss(weight=w, reduction='sum')
4748
```
4849

49-
#### reducereduce 为 True
50+
#### reduce
51+
reduce 为 True
5052
```python
5153
# PyTorch 写法
5254
torch.nn.BCEWithLogitsLoss(weight=w, reduce=True)
@@ -64,7 +66,8 @@ torch.nn.BCEWithLogitsLoss(weight=w, reduce=False)
6466
paddle.nn.BCEWithLogitsLoss(weight=w, reduction='none')
6567
```
6668

67-
#### reductionreduction 为'none'
69+
#### reduction
70+
reduction 为'none'
6871
```python
6972
# PyTorch 写法
7073
torch.nn.BCEWithLogitsLoss(weight=w, reduction='none')

docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.CosineEmbeddingLoss.md

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,77 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
2121
| reduction | reduction | 指定应用于输出结果的计算方式。 |
2222

2323
### 转写示例
24+
#### size_average
25+
size_average 为 True
26+
2427
```python
25-
# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数
26-
if size_average is None:
27-
size_average = True
28-
if reduce is None:
29-
reduce = True
30-
31-
if size_average and reduce:
32-
reduction = 'mean'
33-
elif reduce:
34-
reduction = 'sum'
35-
else:
36-
reduction = 'none'
28+
# PyTorch 写法
29+
torch.nn.CosineEmbeddingLoss(weight=w, size_average=True)
30+
31+
# Paddle 写法
32+
paddle.nn.CosineEmbeddingLoss(weight=w, reduction='mean')
33+
```
34+
35+
size_average 为 False
36+
37+
```python
38+
# PyTorch 写法
39+
torch.nn.CosineEmbeddingLoss(weight=w, size_average=False)
40+
41+
# Paddle 写法
42+
paddle.nn.CosineEmbeddingLoss(weight=w, reduction='sum')
43+
```
44+
45+
#### reduce
46+
reduce 为 True
47+
48+
```python
49+
# PyTorch 写法
50+
torch.nn.CosineEmbeddingLoss(weight=w, reduce=True)
51+
52+
# Paddle 写法
53+
paddle.nn.CosineEmbeddingLoss(weight=w, reduction='mean')
54+
```
55+
56+
reduce 为 False
57+
58+
```python
59+
# PyTorch 写法
60+
torch.nn.CosineEmbeddingLoss(weight=w, reduce=False)
61+
62+
# Paddle 写法
63+
paddle.nn.CosineEmbeddingLoss(weight=w, reduction='none')
64+
```
65+
66+
#### reduction
67+
reduction 为'none'
68+
69+
```python
70+
# PyTorch 写法
71+
torch.nn.CosineEmbeddingLoss(weight=w, reduction='none')
72+
73+
# Paddle 写法
74+
paddle.nn.CosineEmbeddingLoss(weight=w, reduction='none')
75+
```
76+
77+
reduction 为'mean'
78+
79+
```python
80+
# PyTorch 写法
81+
torch.nn.CosineEmbeddingLoss(weight=w, reduction='mean')
82+
83+
# Paddle 写法
84+
paddle.nn.CosineEmbeddingLoss(weight=w, reduction='mean')
85+
```
86+
87+
reduction 为'sum'
88+
89+
```python
90+
# PyTorch 写法
91+
torch.nn.CosineEmbeddingLoss(weight=w, reduction='sum')
92+
93+
# Paddle 写法
94+
paddle.nn.CosineEmbeddingLoss(weight=w, reduction='sum')
95+
```
96+
reduction = 'none'
3797
```

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
3636
| - | axis | 进行 softmax 计算的维度索引,PyTorch 无此参数,Paddle 保持默认即可。 |
3737

3838
### 转写示例
39-
#### size_averagesize_average 为 True
39+
#### size_average
40+
size_average 为 True
4041
```python
4142
# PyTorch 写法
4243
torch.nn.CrossEntropyLoss(weight=w, size_average=True)
@@ -54,7 +55,8 @@ torch.nn.CrossEntropyLoss(weight=w, size_average=False)
5455
paddle.nn.CrossEntropyLoss(weight=w, reduction='sum')
5556
```
5657

57-
#### reducereduce 为 True
58+
#### reduce
59+
reduce 为 True
5860
```python
5961
# PyTorch 写法
6062
torch.nn.CrossEntropyLoss(weight=w, reduce=True)
@@ -72,7 +74,8 @@ torch.nn.CrossEntropyLoss(weight=w, reduce=False)
7274
paddle.nn.CrossEntropyLoss(weight=w, reduction='none')
7375
```
7476

75-
#### reductionreduction 为'none'
77+
#### reduction
78+
reduction 为'none'
7679
```python
7780
# PyTorch 写法
7881
torch.nn.CrossEntropyLoss(weight=w, reduction='none')

docs/guides/model_convert/convert_from_pytorch/api_difference/torch_more_args/torch.nn.HingeEmbeddingLoss.md

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,76 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
2727

2828
### 转写示例
2929
#### size_average
30+
size_average 为 True
31+
3032
```python
31-
# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数
32-
if size_average is None:
33-
size_average = True
34-
if reduce is None:
35-
reduce = True
36-
37-
if size_average and reduce:
38-
reduction = 'mean'
39-
elif reduce:
40-
reduction = 'sum'
41-
else:
42-
reduction = 'none'
33+
# PyTorch 写法
34+
torch.nn.HingeEmbeddingLoss(weight=w, size_average=True)
35+
36+
# Paddle 写法
37+
paddle.nn.HingeEmbeddingLoss(weight=w, reduction='mean')
38+
```
39+
40+
size_average 为 False
41+
42+
```python
43+
# PyTorch 写法
44+
torch.nn.HingeEmbeddingLoss(weight=w, size_average=False)
45+
46+
# Paddle 写法
47+
paddle.nn.HingeEmbeddingLoss(weight=w, reduction='sum')
48+
```
49+
50+
#### reduce
51+
reduce 为 True
52+
53+
```python
54+
# PyTorch 写法
55+
torch.nn.HingeEmbeddingLoss(weight=w, reduce=True)
56+
57+
# Paddle 写法
58+
paddle.nn.HingeEmbeddingLoss(weight=w, reduction='mean')
59+
```
60+
61+
reduce 为 False
62+
63+
```python
64+
# PyTorch 写法
65+
torch.nn.HingeEmbeddingLoss(weight=w, reduce=False)
66+
67+
# Paddle 写法
68+
paddle.nn.HingeEmbeddingLoss(weight=w, reduction='none')
69+
```
70+
71+
#### reduction
72+
reduction 为'none'
73+
74+
```python
75+
# PyTorch 写法
76+
torch.nn.HingeEmbeddingLoss(weight=w, reduction='none')
77+
78+
# Paddle 写法
79+
paddle.nn.HingeEmbeddingLoss(weight=w, reduction='none')
80+
```
81+
82+
reduction 为'mean'
83+
84+
```python
85+
# PyTorch 写法
86+
torch.nn.HingeEmbeddingLoss(weight=w, reduction='mean')
87+
88+
# Paddle 写法
89+
paddle.nn.HingeEmbeddingLoss(weight=w, reduction='mean')
90+
```
91+
92+
reduction 为'sum'
93+
94+
```python
95+
# PyTorch 写法
96+
torch.nn.HingeEmbeddingLoss(weight=w, reduction='sum')
97+
98+
# Paddle 写法
99+
paddle.nn.HingeEmbeddingLoss(weight=w, reduction='sum')
100+
```
101+
reduction = 'none'
43102
```

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

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,74 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下:
2525

2626
### 转写示例
2727
#### size_average
28+
size_average 为 True
29+
30+
```python
31+
# PyTorch 写法
32+
torch.nn.KLDivLoss(weight=w, size_average=True)
33+
34+
# Paddle 写法
35+
paddle.nn.KLDivLoss(weight=w, reduction='mean')
36+
```
37+
38+
size_average 为 False
39+
40+
```python
41+
# PyTorch 写法
42+
torch.nn.KLDivLoss(weight=w, size_average=False)
43+
44+
# Paddle 写法
45+
paddle.nn.KLDivLoss(weight=w, reduction='sum')
46+
```
47+
48+
#### reduce
49+
reduce 为 True
50+
51+
```python
52+
# PyTorch 写法
53+
torch.nn.KLDivLoss(weight=w, reduce=True)
54+
55+
# Paddle 写法
56+
paddle.nn.KLDivLoss(weight=w, reduction='mean')
57+
```
58+
59+
reduce 为 False
60+
2861
```python
29-
# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数
30-
if size_average is None:
31-
size_average = True
32-
if reduce is None:
33-
reduce = True
34-
35-
if size_average and reduce:
36-
reduction = 'mean'
37-
elif reduce:
38-
reduction = 'sum'
39-
else:
40-
reduction = 'none'
62+
# PyTorch 写法
63+
torch.nn.KLDivLoss(weight=w, reduce=False)
64+
65+
# Paddle 写法
66+
paddle.nn.KLDivLoss(weight=w, reduction='none')
67+
```
68+
69+
#### reduction
70+
reduction 为'none'
71+
72+
```python
73+
# PyTorch 写法
74+
torch.nn.KLDivLoss(weight=w, reduction='none')
75+
76+
# Paddle 写法
77+
paddle.nn.KLDivLoss(weight=w, reduction='none')
78+
```
79+
80+
reduction 为'mean'
81+
82+
```python
83+
# PyTorch 写法
84+
torch.nn.KLDivLoss(weight=w, reduction='mean')
85+
86+
# Paddle 写法
87+
paddle.nn.KLDivLoss(weight=w, reduction='mean')
88+
```
89+
90+
reduction 为'sum'
91+
92+
```python
93+
# PyTorch 写法
94+
torch.nn.KLDivLoss(weight=w, reduction='sum')
95+
96+
# Paddle 写法
97+
paddle.nn.KLDivLoss(weight=w, reduction='sum')
4198
```

0 commit comments

Comments
 (0)