Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ lint:
test: unit-test

unit-test:
PYTHONPATH=. pytest tests
PYTHONPATH=.:tests pytest tests

# # # # # # # # # # # # # # # Coverage Block # # # # # # # # # # # # # # #

Expand Down
6 changes: 1 addition & 5 deletions paconvert/api_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -8404,7 +8404,7 @@
"min_input_args": 2
},
"torch.nn.functional.binary_cross_entropy_with_logits": {
"Matcher": "SizeAverageMatcher",
"Matcher": "ChangePrefixMatcher",
"paddle_api": "paddle.nn.functional.binary_cross_entropy_with_logits",
"args_list": [
"input",
Expand All @@ -8415,10 +8415,6 @@
"reduction",
"pos_weight"
],
"kwargs_change": {
"input": "logit",
"target": "label"
},
"min_input_args": 2
},
"torch.nn.functional.celu": {
Expand Down
2 changes: 1 addition & 1 deletion scripts/unittest_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ python -m pip install -r requirements.txt
echo '************************************************************************************************************'
echo "Checking code unit test by pytest ..."
python -m pip install pytest-timeout
python -m pytest -v -s -p no:warnings ./tests;check_error=$?
PYTHONPATH=.:tests python -m pytest -v -s -p no:warnings ./tests;check_error=$?

echo '************************************************************************************************************'
echo "______ _____ _ "
Expand Down
4 changes: 2 additions & 2 deletions scripts/unittest_check_gpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ python -m pip install -r requirements.txt
echo '************************************************************************************************************'
echo "Checking code unit test by pytest ..."
python -m pip install pytest-timeout pytest-xdist pytest-rerunfailures
python -m pytest -v -s -p no:warnings -n 1 --reruns=3 ./tests; check_error=$?
PYTHONPATH=.:tests python -m pytest -v -s -p no:warnings -n 1 --reruns=3 ./tests; check_error=$?
if [ ${check_error} != 0 ];then
echo "Rerun unit test check."
python -m pytest -v -s -p no:warnings -n 1 --lf ./tests; check_error=$?
PYTHONPATH=.:tests python -m pytest -v -s -p no:warnings -n 1 --lf ./tests; check_error=$?
fi

echo '************************************************************************************************************'
Expand Down
94 changes: 73 additions & 21 deletions tests/test_nn_BCEWithLogitsLoss.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ def test_case_1():
import torch
import torch.nn as nn
loss = torch.nn.BCEWithLogitsLoss(reduction='none')
input = torch.tensor([1.,0.7,0.2], requires_grad=True)
target = torch.tensor([1.,0., 0.])
input = torch.zeros(3)
input[0] = 1.0
input[1] = 0.7
input[2] = 0.2
input.requires_grad = True
target = torch.zeros(3)
target[0] = 1.0
result = loss(input, target)
"""
)
Expand All @@ -38,9 +43,17 @@ def test_case_2():
"""
import torch
import torch.nn as nn
loss = nn.BCEWithLogitsLoss(weight=torch.tensor([1.0,0.2, 0.2]), reduction='none')
input = torch.tensor([1.,0.7,0.2], requires_grad=True)
target = torch.tensor([1.,0., 0.])
weight = torch.ones(3)
weight[1] = 0.2
weight[2] = 0.2
loss = nn.BCEWithLogitsLoss(weight=weight, reduction='none')
input = torch.zeros(3)
input[0] = 1.0
input[1] = 0.7
input[2] = 0.2
input.requires_grad = True
target = torch.zeros(3)
target[0] = 1.0
result = loss(input, target)
"""
)
Expand All @@ -52,9 +65,14 @@ def test_case_3():
"""
import torch
import torch.nn as nn
loss= nn.BCEWithLogitsLoss(pos_weight = torch.ones([3]))
input = torch.tensor([1.,0.7,0.2], requires_grad=True)
target = torch.tensor([1.,0., 0.])
loss= nn.BCEWithLogitsLoss(pos_weight=torch.ones(3))
input = torch.zeros(3)
input[0] = 1.0
input[1] = 0.7
input[2] = 0.2
input.requires_grad = True
target = torch.zeros(3)
target[0] = 1.0
result = loss(input, target)
"""
)
Expand All @@ -67,8 +85,13 @@ def test_case_4():
import torch
import torch.nn as nn
loss = nn.BCEWithLogitsLoss(size_average=True)
input = torch.tensor([1.,0.7,0.2], requires_grad=True)
target = torch.tensor([1.,0., 0.])
input = torch.zeros(3)
input[0] = 1.0
input[1] = 0.7
input[2] = 0.2
input.requires_grad = True
target = torch.zeros(3)
target[0] = 1.0
result = loss(input, target)
"""
)
Expand All @@ -81,8 +104,13 @@ def test_case_5():
import torch
import torch.nn as nn
loss = nn.BCEWithLogitsLoss()
input = torch.tensor([1.,0.7,0.2], requires_grad=True)
target = torch.tensor([1.,0., 0.])
input = torch.zeros(3)
input[0] = 1.0
input[1] = 0.7
input[2] = 0.2
input.requires_grad = True
target = torch.zeros(3)
target[0] = 1.0
result = loss(input, target)
"""
)
Expand All @@ -94,9 +122,17 @@ def test_case_6():
"""
import torch
import torch.nn as nn
loss = nn.BCEWithLogitsLoss(weight=torch.tensor([1.0,0.2, 0.2]), size_average=None, reduce=None, reduction='none', pos_weight=None)
input = torch.tensor([1.,0.7,0.2], requires_grad=True)
target = torch.tensor([1.,0., 0.])
weight = torch.ones(3)
weight[1] = 0.2
weight[2] = 0.2
loss = nn.BCEWithLogitsLoss(weight=weight, size_average=None, reduce=None, reduction='none', pos_weight=None)
input = torch.zeros(3)
input[0] = 1.0
input[1] = 0.7
input[2] = 0.2
input.requires_grad = True
target = torch.zeros(3)
target[0] = 1.0
result = loss(input, target)
"""
)
Expand All @@ -109,9 +145,17 @@ def test_case_7():
"""
import torch
import torch.nn as nn
loss = nn.BCEWithLogitsLoss(torch.tensor([1.0,0.2, 0.2]), None, None, 'none', None)
input = torch.tensor([1.,0.7,0.2], requires_grad=True)
target = torch.tensor([1.,0., 0.])
weight = torch.ones(3)
weight[1] = 0.2
weight[2] = 0.2
loss = nn.BCEWithLogitsLoss(weight, None, None, 'none', None)
input = torch.zeros(3)
input[0] = 1.0
input[1] = 0.7
input[2] = 0.2
input.requires_grad = True
target = torch.zeros(3)
target[0] = 1.0
result = loss(input, target)
"""
)
Expand All @@ -124,9 +168,17 @@ def test_case_8():
"""
import torch
import torch.nn as nn
loss = nn.BCEWithLogitsLoss(pos_weight=None, reduction='none', reduce=None, size_average=None, weight=torch.tensor([1.0,0.2, 0.2]))
input = torch.tensor([1.,0.7,0.2], requires_grad=True)
target = torch.tensor([1.,0., 0.])
weight = torch.ones(3)
weight[1] = 0.2
weight[2] = 0.2
loss = nn.BCEWithLogitsLoss(pos_weight=None, reduction='none', reduce=None, size_average=None, weight=weight)
input = torch.zeros(3)
input[0] = 1.0
input[1] = 0.7
input[2] = 0.2
input.requires_grad = True
target = torch.zeros(3)
target[0] = 1.0
result = loss(input, target)
"""
)
Expand Down
Loading