Skip to content

Enable legacy_nn unit tests. #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 21, 2018
Merged
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
22 changes: 21 additions & 1 deletion test/common_nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import torch
import torch.cuda
from torch.nn.functional import _Reduction
from common import TestCase, to_gpu, freeze_rng_state, is_iterable
from common import TestCase, to_gpu, freeze_rng_state, is_iterable, TEST_WITH_ROCM
from common_cuda import TEST_CUDA
from torch.autograd.gradcheck import get_numerical_jacobian, iter_tensors
import torch.backends.cudnn
Expand Down Expand Up @@ -102,11 +102,13 @@ def get_weight(m):
constructor_args=(1,),
input_size=(10, 20),
reference_fn=lambda i, _: torch.exp(i).div(torch.exp(i).sum(1, True).expand(10, 20)),
test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='Softmax2d',
input_size=(1, 3, 10, 20),
reference_fn=lambda i, _: torch.exp(i).div(torch.exp(i).sum(1, False)),
test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='LogSoftmax',
Expand All @@ -120,6 +122,7 @@ def get_weight(m):
input_size=(1, 3, 10, 20),
reference_fn=lambda i, _: torch.exp(i).div_(torch.exp(i).sum(1, False)).log_(),
desc='multiparam',
test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='ELU',
Expand Down Expand Up @@ -198,48 +201,56 @@ def get_weight(m):
input_size=(2, 3, 4),
desc='1d_multiparam',
reference_fn=lambda i, p: torch.clamp(i, min=0) + torch.clamp(i, max=0) * p[0][0],
test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='PReLU',
input_size=(2, 3, 4, 5),
desc='2d',
reference_fn=lambda i, p: torch.clamp(i, min=0) + torch.clamp(i, max=0) * p[0][0],
#test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='PReLU',
constructor_args=(3,),
input_size=(2, 3, 4, 5),
desc='2d_multiparam',
reference_fn=lambda i, p: torch.clamp(i, min=0) + torch.clamp(i, max=0) * p[0][0],
test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='PReLU',
input_size=(2, 3, 4, 5, 6),
reference_fn=lambda i, p: torch.clamp(i, min=0) + torch.clamp(i, max=0) * p[0][0],
desc='3d',
#test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='PReLU',
constructor_args=(3,),
input_size=(2, 3, 4, 5, 6),
desc='3d_multiparam',
reference_fn=lambda i, p: torch.clamp(i, min=0) + torch.clamp(i, max=0) * p[0][0],
test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='Softsign',
input_size=(3, 2, 5),
reference_fn=lambda i, _: i.div(1 + torch.abs(i)),
test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='Softmin',
constructor_args=(1,),
input_size=(10, 20),
test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='Softmin',
constructor_args=(1,),
input_size=(2, 3, 5, 10),
desc='multidim',
test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='Tanhshrink',
Expand Down Expand Up @@ -576,6 +587,7 @@ def ctcloss_reference(log_probs, targets, input_lengths, target_lengths, blank=0
reference_fn=lambda i, t, m: -(t * i.log() + (1 - t) * (1 - i).log()).sum() /
(i.numel() if get_reduction(m) else 1),
check_gradgrad=False,
test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='BCELoss',
Expand All @@ -586,6 +598,7 @@ def ctcloss_reference(log_probs, targets, input_lengths, target_lengths, blank=0
(i.numel() if get_reduction(m) else 1),
desc='weights',
check_gradgrad=False,
test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='CrossEntropyLoss',
Expand All @@ -606,6 +619,7 @@ def ctcloss_reference(log_probs, targets, input_lengths, target_lengths, blank=0
reference_fn=lambda i, t, m:
hingeembeddingloss_reference(i, t, reduction=get_reduction(m)),
check_sum_reduction=True,
test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='HingeEmbeddingLoss',
Expand All @@ -616,6 +630,7 @@ def ctcloss_reference(log_probs, targets, input_lengths, target_lengths, blank=0
hingeembeddingloss_reference(i, t, margin=0.5, reduction=get_reduction(m)),
desc='margin',
check_sum_reduction=True,
test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='MultiLabelMarginLoss',
Expand All @@ -642,6 +657,7 @@ def ctcloss_reference(log_probs, targets, input_lengths, target_lengths, blank=0
target_fn=lambda: torch.rand(5, 10).mul(2).floor(),
reference_fn=lambda i, t, m: -(t * i.sigmoid().log() + (1 - t) * (-i).sigmoid().log()).sum() / i.numel(),
check_gradgrad=False,
test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='MultiMarginLoss',
Expand Down Expand Up @@ -720,6 +736,7 @@ def ctcloss_reference(log_probs, targets, input_lengths, target_lengths, blank=0
reference_fn=lambda i, t, m:
cosineembeddingloss_reference(i[0], i[1], t, reduction=get_reduction(m)),
check_sum_reduction=True,
test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='CosineEmbeddingLoss',
Expand All @@ -730,6 +747,7 @@ def ctcloss_reference(log_probs, targets, input_lengths, target_lengths, blank=0
cosineembeddingloss_reference(i[0], i[1], t, margin=0.7, reduction=get_reduction(m)),
desc='margin',
check_sum_reduction=True,
test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='MarginRankingLoss',
Expand All @@ -738,6 +756,7 @@ def ctcloss_reference(log_probs, targets, input_lengths, target_lengths, blank=0
reference_fn=lambda i, t, m:
marginrankingloss_reference(i[0], i[1], t, reduction=get_reduction(m)),
check_sum_reduction=True,
test_cuda = (not TEST_WITH_ROCM)
),
dict(
module_name='MarginRankingLoss',
Expand All @@ -748,6 +767,7 @@ def ctcloss_reference(log_probs, targets, input_lengths, target_lengths, blank=0
marginrankingloss_reference(i[0], i[1], t, margin=0.5, reduction=get_reduction(m)),
desc='margin',
check_sum_reduction=True,
test_cuda = (not TEST_WITH_ROCM)
),
]

Expand Down
1 change: 0 additions & 1 deletion test/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
'cuda',
'distributed',
'distributions',
'legacy_nn',
'multiprocessing',
'nccl',
'nn',
Expand Down
Loading