Skip to content

Commit b678ab2

Browse files
authored
Merge pull request #119 from jithunnair-amd/enable_test_sparse
Enable test_sparse unit tests for ROCm builds in CI
2 parents 6eef9c2 + ef1586f commit b678ab2

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

test/run_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
'multiprocessing',
5151
'nccl',
5252
'nn',
53-
'sparse',
5453
'utils',
5554
]
5655

test/test_sparse.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import functools
66
import random
77
import unittest
8-
from common import TestCase, run_tests
8+
from common import TestCase, run_tests, skipIfRocm
99
from common_cuda import TEST_CUDA
1010
from test_torch import TestTorch
1111
from numbers import Number
@@ -107,6 +107,7 @@ def randn(self, *args, **kwargs):
107107
# TODO: Put this in torch.cuda.randn
108108
return self.ValueTensor(*args, **kwargs).normal_()
109109

110+
@skipIfRocm
110111
def test_basic(self):
111112
x, i, v = self._gen_sparse(3, 10, 100)
112113

@@ -155,6 +156,7 @@ def test_ctor_size_checks(self):
155156
RuntimeError,
156157
lambda: self.SparseTensor(indices, values, torch.Size([2, 4, 2, 1])))
157158

159+
@skipIfRocm
158160
def test_to_dense(self):
159161
i = self.IndexTensor([
160162
[0, 1, 2, 2],
@@ -184,6 +186,7 @@ def test_to_dense(self):
184186
self.assertEqual(res, x.to_dense())
185187
self.assertEqual(res, self.safeToDense(x))
186188

189+
@skipIfRocm
187190
def test_shared(self):
188191
i = self.IndexTensor([[2]])
189192
v = self.ValueTensor([5])
@@ -193,6 +196,7 @@ def test_shared(self):
193196
i[0][0] = 0
194197
self.assertEqual(self.ValueTensor([6, 0, 0]), self.safeToDense(x))
195198

199+
@skipIfRocm
196200
def test_to_dense_hybrid(self):
197201
i = self.IndexTensor([
198202
[0, 1, 2, 2],
@@ -221,6 +225,7 @@ def test_to_dense_hybrid(self):
221225
self.assertEqual(res, x.to_dense())
222226
self.assertEqual(res, self.safeToDense(x))
223227

228+
@skipIfRocm
224229
def test_contig(self):
225230
i = self.IndexTensor([
226231
[1, 0, 35, 14, 39, 6, 71, 66, 40, 27],
@@ -274,6 +279,7 @@ def test_contig(self):
274279
self.assertEqual(exp_i, x._indices())
275280
self.assertEqual(exp_v, x._values())
276281

282+
@skipIfRocm
277283
def test_contig_hybrid(self):
278284
i = self.IndexTensor([
279285
[1, 0, 35, 14, 39, 6, 71, 66, 40, 27],
@@ -333,6 +339,7 @@ def test_contig_hybrid(self):
333339
self.assertEqual(exp_i, x._indices())
334340
self.assertEqual(exp_v, x._values())
335341

342+
@skipIfRocm
336343
def test_clone(self):
337344
x, _, _ = self._gen_sparse(4, 20, 5)
338345
if self.is_uncoalesced:
@@ -354,6 +361,7 @@ def test_cuda_empty(self):
354361
self.assertEqual(y._sparseDims(), x._sparseDims())
355362
self.assertEqual(y._denseDims(), x._denseDims())
356363

364+
@skipIfRocm
357365
def test_transpose(self):
358366
x = self._gen_sparse(4, 20, 5)[0]
359367
y = self.safeToDense(x)
@@ -367,6 +375,7 @@ def test_transpose(self):
367375
y = y.transpose(i, j)
368376
self.assertEqual(self.safeToDense(x), y)
369377

378+
@skipIfRocm
370379
def test_transpose_coalesce_invariant(self):
371380
# If a sparse tensor is coalesced, its transpose should be the same
372381
# If a sparse tensor is uncoalesed, its transpose should be the same
@@ -407,6 +416,7 @@ def test_t_empty(self):
407416
self.assertEqual(x._sparseDims(), 2)
408417
self.assertEqual(x._denseDims(), 0)
409418

419+
@skipIfRocm
410420
def test_add_zeros(self):
411421
def test_shape(sparse_dims, sizes):
412422
x, _, _ = self._gen_sparse(sparse_dims, 20, sizes)
@@ -470,6 +480,7 @@ def test_shape(di, dj, dk):
470480
test_shape(1000, 100, 100)
471481
test_shape(3000, 64, 300)
472482

483+
@skipIfRocm
473484
def test_dsmm(self):
474485
def test_shape(di, dj, dk):
475486
x = self._gen_sparse(2, 20, [di, dj])[0]
@@ -483,6 +494,7 @@ def test_shape(di, dj, dk):
483494
test_shape(1000, 100, 100)
484495
test_shape(3000, 64, 300)
485496

497+
@skipIfRocm
486498
def test_hsmm(self):
487499
def test_shape(di, dj, dk):
488500
x = self._gen_sparse(2, 20, [di, dj])[0]
@@ -543,18 +555,21 @@ def _test_spadd_shape(self, shape_i, shape_v=None):
543555
expected = y + r * self.safeToDense(x_)
544556
self.assertEqual(res, expected)
545557

558+
@skipIfRocm
546559
def test_spadd(self):
547560
self._test_spadd_shape([5, 6])
548561
self._test_spadd_shape([10, 10, 10])
549562
self._test_spadd_shape([50, 30, 20])
550563
self._test_spadd_shape([5, 5, 5, 5, 5, 5])
551564

565+
@skipIfRocm
552566
def test_spadd_hybrid(self):
553567
self._test_spadd_shape([5, 6], [2, 3])
554568
self._test_spadd_shape([10, 10, 10], [3])
555569
self._test_spadd_shape([50, 30, 20], [2])
556570
self._test_spadd_shape([5, 5, 5, 5, 5, 5], [2])
557571

572+
@skipIfRocm
558573
def test_norm(self):
559574
x, _, _ = self._gen_sparse(3, 10, 100)
560575
y = x.coalesce()
@@ -623,18 +638,21 @@ def _test_basic_ops_shape(self, shape_i, shape_v=None):
623638
y._values().add_(1)
624639
self.assertEqual(z._values() + 1, y._values())
625640

641+
@skipIfRocm
626642
def test_basic_ops(self):
627643
self._test_basic_ops_shape([5, 6])
628644
self._test_basic_ops_shape([10, 10, 10])
629645
self._test_basic_ops_shape([50, 30, 20])
630646
self._test_basic_ops_shape([5, 5, 5, 5, 5, 5])
631647

648+
@skipIfRocm
632649
def test_basic_ops_hybrid(self):
633650
self._test_basic_ops_shape([5, 6], [2, 3])
634651
self._test_basic_ops_shape([10, 10, 10], [3])
635652
self._test_basic_ops_shape([50, 30, 20], [2])
636653
self._test_basic_ops_shape([5, 5, 5, 5, 5, 5], [2])
637654

655+
@skipIfRocm
638656
def test_add_dense_sparse_mismatch(self):
639657
x = torch.zeros([3, 4], dtype=self.value_dtype, device=self.device)
640658
sparse_y = self.SparseTensor(torch.zeros(1, 4, dtype=torch.int64, device=self.device),
@@ -673,6 +691,7 @@ def _test_sparse_mask_fixed(self):
673691
expected = self.SparseTensor(i, exp_v, torch.Size([5, 4]))
674692
self.assertEqual(res, expected)
675693

694+
@skipIfRocm
676695
def test_sparse_mask(self):
677696
self._test_sparse_mask_fixed()
678697

@@ -692,6 +711,7 @@ def _test_zeros(self, shape, out_shape_i, out_shape_v=None):
692711
self.assertEqual(out._sparseDims(), len(shape))
693712
self.assertEqual(out._denseDims(), 0)
694713

714+
@skipIfRocm
695715
def test_log1p(self):
696716
if self.is_cuda:
697717
input = torch.cuda.sparse.DoubleTensor(
@@ -775,6 +795,7 @@ def _test_sparse_mask_hybrid_fixed(self):
775795
expected = self.SparseTensor(i, exp_v, torch.Size([5, 4, 2]))
776796
self.assertEqual(res, expected)
777797

798+
@skipIfRocm
778799
def test_sparse_variable_methods(self):
779800
# TODO: delete when tensor/variable are merged
780801
from torch.autograd import Variable
@@ -870,6 +891,7 @@ def test_sparse_variable_methods(self):
870891
self.assertEqual(test_fn(sp_var, de_var).data,
871892
test_fn(sp_mat, de_mat), test_name)
872893

894+
@skipIfRocm
873895
def test_sparse_mask_hybrid(self):
874896
self._test_sparse_mask_hybrid_fixed()
875897

@@ -878,6 +900,7 @@ def test_sparse_mask_hybrid(self):
878900
self._test_sparse_mask_shape([50, 30, 20], [2])
879901
self._test_sparse_mask_shape([5, 5, 5, 5, 5, 5], [2])
880902

903+
@skipIfRocm
881904
def test_sparse_add_coalesce(self):
882905
i = self.IndexTensor([[1, 2, 1]])
883906
v = self.ValueTensor([3, 4, 5])
@@ -932,6 +955,7 @@ def test_new_device_multi_gpu(self):
932955
self._test_new_device((30, 20), 1)
933956
self._test_new_device((30, 20, 10), 1)
934957

958+
@skipIfRocm
935959
def test_new(self):
936960
x, indices, values = self._gen_sparse(3, 10, 100)
937961
if not x.is_cuda:
@@ -1062,6 +1086,7 @@ def test_is_sparse(self):
10621086
x = self.SparseTensor()
10631087
self.assertTrue(x.is_sparse)
10641088

1089+
@skipIfRocm
10651090
def test_resize_as(self):
10661091
def do_test(t):
10671092
y = t.new().resize_as_(t).zero_()

0 commit comments

Comments
 (0)