Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
0698e91a
Unverified
Commit
0698e91a
authored
Jan 03, 2023
by
czkkkkkk
Committed by
GitHub
Jan 03, 2023
Browse files
[Sparse] Use Pytorch dense computation in SpMM tests (#5096)
parent
774709d3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
10 deletions
+7
-10
tests/pytorch/sparse/test_matmul.py
tests/pytorch/sparse/test_matmul.py
+6
-8
tests/pytorch/sparse/utils.py
tests/pytorch/sparse/utils.py
+1
-2
No files found.
tests/pytorch/sparse/test_matmul.py
View file @
0698e91a
...
...
@@ -37,18 +37,16 @@ def test_spmm(create_func, shape, nnz, out_dim):
grad
=
torch
.
randn_like
(
sparse_result
)
sparse_result
.
backward
(
grad
)
adj
=
sparse_matrix_to_
torch_spar
se
(
A
)
adj
=
sparse_matrix_to_
den
se
(
A
)
XX
=
clone_detach_and_grad
(
X
)
torch_sparse_result
=
torch
.
sparse
.
mm
(
adj
,
XX
.
view
(
-
1
,
1
)
if
out_dim
is
None
else
XX
)
dense_result
=
torch
.
matmul
(
adj
,
XX
)
if
out_dim
is
None
:
torch_spar
se_result
=
torch_spar
se_result
.
view
(
-
1
)
torch_spar
se_result
.
backward
(
grad
)
assert
torch
.
allclose
(
sparse_result
,
torch_spar
se_result
,
atol
=
1e-05
)
den
se_result
=
den
se_result
.
view
(
-
1
)
den
se_result
.
backward
(
grad
)
assert
torch
.
allclose
(
sparse_result
,
den
se_result
,
atol
=
1e-05
)
assert
torch
.
allclose
(
X
.
grad
,
XX
.
grad
,
atol
=
1e-05
)
assert
torch
.
allclose
(
adj
.
grad
.
coalesce
().
to_dense
(
),
dense_mask
(
adj
.
grad
,
A
),
sparse_matrix_to_dense
(
val_like
(
A
,
A
.
val
.
grad
)),
atol
=
1e-05
,
)
...
...
tests/pytorch/sparse/utils.py
View file @
0698e91a
...
...
@@ -107,8 +107,7 @@ def rand_csc_uncoalesced(shape, nnz, dev):
def
sparse_matrix_to_dense
(
A
:
SparseMatrix
):
dense
=
A
.
dense
()
dense
.
requires_grad_
()
return
dense
return
clone_detach_and_grad
(
dense
)
def
sparse_matrix_to_torch_sparse
(
A
:
SparseMatrix
,
val
=
None
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment