Skip to content

Commit e4d20fa

Browse files
committed
[API Compatibility No.155] Keep input/target alias for bce_with_logits-part
1 parent eb0a495 commit e4d20fa

6 files changed

Lines changed: 273 additions & 60 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ lint:
3636
test: unit-test
3737

3838
unit-test:
39-
PYTHONPATH=. pytest tests
39+
PYTHONPATH=.:tests pytest tests
4040

4141
# # # # # # # # # # # # # # # Coverage Block # # # # # # # # # # # # # # #
4242

paconvert/api_mapping.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8848,7 +8848,7 @@
88488848
"min_input_args": 2
88498849
},
88508850
"torch.nn.functional.binary_cross_entropy_with_logits": {
8851-
"Matcher": "SizeAverageMatcher",
8851+
"Matcher": "ChangePrefixMatcher",
88528852
"paddle_api": "paddle.nn.functional.binary_cross_entropy_with_logits",
88538853
"args_list": [
88548854
"input",
@@ -8859,10 +8859,6 @@
88598859
"reduction",
88608860
"pos_weight"
88618861
],
8862-
"kwargs_change": {
8863-
"input": "logit",
8864-
"target": "label"
8865-
},
88668862
"min_input_args": 2
88678863
},
88688864
"torch.nn.functional.celu": {

scripts/unittest_check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ python -m pip install -r requirements.txt
4747
echo '************************************************************************************************************'
4848
echo "Checking code unit test by pytest ..."
4949
python -m pip install pytest-timeout
50-
python -m pytest ./tests;check_error=$?
50+
PYTHONPATH=.:tests python -m pytest ./tests;check_error=$?
5151

5252
echo '************************************************************************************************************'
5353
echo "______ _____ _ "

scripts/unittest_check_gpu.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ python -m pip install -r requirements.txt
4747
echo '************************************************************************************************************'
4848
echo "Checking code unit test by pytest ..."
4949
python -m pip install pytest-timeout pytest-xdist pytest-rerunfailures
50-
python -m pytest -n 1 --reruns=3 ./tests; check_error=$?
50+
PYTHONPATH=.:tests python -m pytest -n 1 --reruns=3 ./tests; check_error=$?
5151
if [ ${check_error} != 0 ];then
5252
echo "Rerun unit test check."
53-
python -m pytest -n 1 --lf ./tests; check_error=$?
53+
PYTHONPATH=.:tests python -m pytest -n 1 --lf ./tests; check_error=$?
5454
fi
5555

5656
echo '************************************************************************************************************'

tests/test_nn_BCEWithLogitsLoss.py

Lines changed: 73 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ def test_case_1():
2525
import torch
2626
import torch.nn as nn
2727
loss = torch.nn.BCEWithLogitsLoss(reduction='none')
28-
input = torch.tensor([1.,0.7,0.2], requires_grad=True)
29-
target = torch.tensor([1.,0., 0.])
28+
input = torch.zeros(3)
29+
input[0] = 1.0
30+
input[1] = 0.7
31+
input[2] = 0.2
32+
input.requires_grad = True
33+
target = torch.zeros(3)
34+
target[0] = 1.0
3035
result = loss(input, target)
3136
"""
3237
)
@@ -38,9 +43,17 @@ def test_case_2():
3843
"""
3944
import torch
4045
import torch.nn as nn
41-
loss = nn.BCEWithLogitsLoss(weight=torch.tensor([1.0,0.2, 0.2]), reduction='none')
42-
input = torch.tensor([1.,0.7,0.2], requires_grad=True)
43-
target = torch.tensor([1.,0., 0.])
46+
weight = torch.ones(3)
47+
weight[1] = 0.2
48+
weight[2] = 0.2
49+
loss = nn.BCEWithLogitsLoss(weight=weight, reduction='none')
50+
input = torch.zeros(3)
51+
input[0] = 1.0
52+
input[1] = 0.7
53+
input[2] = 0.2
54+
input.requires_grad = True
55+
target = torch.zeros(3)
56+
target[0] = 1.0
4457
result = loss(input, target)
4558
"""
4659
)
@@ -52,9 +65,14 @@ def test_case_3():
5265
"""
5366
import torch
5467
import torch.nn as nn
55-
loss= nn.BCEWithLogitsLoss(pos_weight = torch.ones([3]))
56-
input = torch.tensor([1.,0.7,0.2], requires_grad=True)
57-
target = torch.tensor([1.,0., 0.])
68+
loss= nn.BCEWithLogitsLoss(pos_weight=torch.ones(3))
69+
input = torch.zeros(3)
70+
input[0] = 1.0
71+
input[1] = 0.7
72+
input[2] = 0.2
73+
input.requires_grad = True
74+
target = torch.zeros(3)
75+
target[0] = 1.0
5876
result = loss(input, target)
5977
"""
6078
)
@@ -67,8 +85,13 @@ def test_case_4():
6785
import torch
6886
import torch.nn as nn
6987
loss = nn.BCEWithLogitsLoss(size_average=True)
70-
input = torch.tensor([1.,0.7,0.2], requires_grad=True)
71-
target = torch.tensor([1.,0., 0.])
88+
input = torch.zeros(3)
89+
input[0] = 1.0
90+
input[1] = 0.7
91+
input[2] = 0.2
92+
input.requires_grad = True
93+
target = torch.zeros(3)
94+
target[0] = 1.0
7295
result = loss(input, target)
7396
"""
7497
)
@@ -81,8 +104,13 @@ def test_case_5():
81104
import torch
82105
import torch.nn as nn
83106
loss = nn.BCEWithLogitsLoss()
84-
input = torch.tensor([1.,0.7,0.2], requires_grad=True)
85-
target = torch.tensor([1.,0., 0.])
107+
input = torch.zeros(3)
108+
input[0] = 1.0
109+
input[1] = 0.7
110+
input[2] = 0.2
111+
input.requires_grad = True
112+
target = torch.zeros(3)
113+
target[0] = 1.0
86114
result = loss(input, target)
87115
"""
88116
)
@@ -94,9 +122,17 @@ def test_case_6():
94122
"""
95123
import torch
96124
import torch.nn as nn
97-
loss = nn.BCEWithLogitsLoss(weight=torch.tensor([1.0,0.2, 0.2]), size_average=None, reduce=None, reduction='none', pos_weight=None)
98-
input = torch.tensor([1.,0.7,0.2], requires_grad=True)
99-
target = torch.tensor([1.,0., 0.])
125+
weight = torch.ones(3)
126+
weight[1] = 0.2
127+
weight[2] = 0.2
128+
loss = nn.BCEWithLogitsLoss(weight=weight, size_average=None, reduce=None, reduction='none', pos_weight=None)
129+
input = torch.zeros(3)
130+
input[0] = 1.0
131+
input[1] = 0.7
132+
input[2] = 0.2
133+
input.requires_grad = True
134+
target = torch.zeros(3)
135+
target[0] = 1.0
100136
result = loss(input, target)
101137
"""
102138
)
@@ -109,9 +145,17 @@ def test_case_7():
109145
"""
110146
import torch
111147
import torch.nn as nn
112-
loss = nn.BCEWithLogitsLoss(torch.tensor([1.0,0.2, 0.2]), None, None, 'none', None)
113-
input = torch.tensor([1.,0.7,0.2], requires_grad=True)
114-
target = torch.tensor([1.,0., 0.])
148+
weight = torch.ones(3)
149+
weight[1] = 0.2
150+
weight[2] = 0.2
151+
loss = nn.BCEWithLogitsLoss(weight, None, None, 'none', None)
152+
input = torch.zeros(3)
153+
input[0] = 1.0
154+
input[1] = 0.7
155+
input[2] = 0.2
156+
input.requires_grad = True
157+
target = torch.zeros(3)
158+
target[0] = 1.0
115159
result = loss(input, target)
116160
"""
117161
)
@@ -124,9 +168,17 @@ def test_case_8():
124168
"""
125169
import torch
126170
import torch.nn as nn
127-
loss = nn.BCEWithLogitsLoss(pos_weight=None, reduction='none', reduce=None, size_average=None, weight=torch.tensor([1.0,0.2, 0.2]))
128-
input = torch.tensor([1.,0.7,0.2], requires_grad=True)
129-
target = torch.tensor([1.,0., 0.])
171+
weight = torch.ones(3)
172+
weight[1] = 0.2
173+
weight[2] = 0.2
174+
loss = nn.BCEWithLogitsLoss(pos_weight=None, reduction='none', reduce=None, size_average=None, weight=weight)
175+
input = torch.zeros(3)
176+
input[0] = 1.0
177+
input[1] = 0.7
178+
input[2] = 0.2
179+
input.requires_grad = True
180+
target = torch.zeros(3)
181+
target[0] = 1.0
130182
result = loss(input, target)
131183
"""
132184
)

0 commit comments

Comments
 (0)