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
deepspeed
Commits
ccec2463
Unverified
Commit
ccec2463
authored
Feb 27, 2020
by
Jeff Rasley
Committed by
GitHub
Feb 27, 2020
Browse files
add some csr addition unit tests (#110)
parent
5aa58b38
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
0 deletions
+50
-0
tests/unit/test_csr.py
tests/unit/test_csr.py
+50
-0
No files found.
tests/unit/test_csr.py
0 → 100644
View file @
ccec2463
import
torch
import
random
from
deepspeed.pt.deepspeed_csr_tensor
import
CSRTensor
def
test_csr_addition_self
():
row_count
=
10
random
.
seed
(
1234
)
x
=
torch
.
ones
(
1
,
5
)
for
i
in
range
(
row_count
-
1
):
if
random
.
random
()
>
0.75
:
x
=
torch
.
cat
([
x
,
torch
.
ones
(
1
,
5
)])
else
:
x
=
torch
.
cat
([
x
,
torch
.
zeros
(
1
,
5
)])
dense_x
=
x
.
clone
()
cx
=
CSRTensor
(
x
)
assert
torch
.
all
(
dense_x
==
cx
.
to_dense
())
cx
.
add
(
cx
)
assert
torch
.
all
(
dense_x
+
dense_x
==
cx
.
to_dense
())
def
test_csr_addition_different
():
row_count
=
10
random
.
seed
(
1234
)
x
=
torch
.
ones
(
1
,
5
)
for
i
in
range
(
row_count
-
1
):
if
random
.
random
()
>
0.75
:
x
=
torch
.
cat
([
x
,
torch
.
ones
(
1
,
5
)])
else
:
x
=
torch
.
cat
([
x
,
torch
.
zeros
(
1
,
5
)])
dense_x
=
x
.
clone
()
cx
=
CSRTensor
(
x
)
y
=
torch
.
ones
(
1
,
5
)
for
i
in
range
(
row_count
-
1
):
if
random
.
random
()
>
0.75
:
y
=
torch
.
cat
([
y
,
torch
.
ones
(
1
,
5
)])
else
:
y
=
torch
.
cat
([
y
,
torch
.
zeros
(
1
,
5
)])
dense_y
=
y
.
clone
()
cy
=
CSRTensor
(
y
)
dense_sum
=
dense_x
+
dense_y
cx
.
add
(
cy
)
assert
torch
.
all
(
dense_sum
==
cx
.
to_dense
())
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