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
7b1639f1
Unverified
Commit
7b1639f1
authored
Jun 26, 2023
by
Andrzej Kotłowski
Committed by
GitHub
Jun 26, 2023
Browse files
[TESTS] Make pytorch test_nn.py fully reproducible (#5887)
parent
3e2b5a04
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
0 deletions
+26
-0
tests/backend/backend_unittest.py
tests/backend/backend_unittest.py
+5
-0
tests/backend/mxnet/__init__.py
tests/backend/mxnet/__init__.py
+4
-0
tests/backend/pytorch/__init__.py
tests/backend/pytorch/__init__.py
+4
-0
tests/backend/tensorflow/__init__.py
tests/backend/tensorflow/__init__.py
+4
-0
tests/python/pytorch/nn/test_nn.py
tests/python/pytorch/nn/test_nn.py
+9
-0
No files found.
tests/backend/backend_unittest.py
View file @
7b1639f1
...
@@ -126,6 +126,11 @@ def abs(a):
...
@@ -126,6 +126,11 @@ def abs(a):
pass
pass
def
seed
(
a
):
"""Set seed to for random generator"""
pass
###############################################################################
###############################################################################
# Tensor functions used *only* on index tensor
# Tensor functions used *only* on index tensor
# ----------------
# ----------------
...
...
tests/backend/mxnet/__init__.py
View file @
7b1639f1
...
@@ -100,3 +100,7 @@ def dot(a, b):
...
@@ -100,3 +100,7 @@ def dot(a, b):
def
abs
(
a
):
def
abs
(
a
):
return
nd
.
abs
(
a
)
return
nd
.
abs
(
a
)
def
seed
(
a
):
return
mx
.
random
.
seed
(
a
)
tests/backend/pytorch/__init__.py
View file @
7b1639f1
...
@@ -93,3 +93,7 @@ def dot(a, b):
...
@@ -93,3 +93,7 @@ def dot(a, b):
def
abs
(
a
):
def
abs
(
a
):
return
a
.
abs
()
return
a
.
abs
()
def
seed
(
a
):
return
th
.
manual_seed
(
a
)
tests/backend/tensorflow/__init__.py
View file @
7b1639f1
...
@@ -104,3 +104,7 @@ def dot(a, b):
...
@@ -104,3 +104,7 @@ def dot(a, b):
def
abs
(
a
):
def
abs
(
a
):
return
tf
.
abs
(
a
)
return
tf
.
abs
(
a
)
def
seed
(
a
):
return
tf
.
random
.
set_seed
(
a
)
tests/python/pytorch/nn/test_nn.py
View file @
7b1639f1
import
io
import
io
import
pickle
import
pickle
import
random
from
copy
import
deepcopy
from
copy
import
deepcopy
import
backend
as
F
import
backend
as
F
...
@@ -8,6 +9,7 @@ import dgl
...
@@ -8,6 +9,7 @@ import dgl
import
dgl.function
as
fn
import
dgl.function
as
fn
import
dgl.nn.pytorch
as
nn
import
dgl.nn.pytorch
as
nn
import
networkx
as
nx
import
networkx
as
nx
import
numpy
as
np
# For setting seed for scipy
import
pytest
import
pytest
import
scipy
as
sp
import
scipy
as
sp
import
torch
import
torch
...
@@ -24,6 +26,13 @@ from utils.graph_cases import (
...
@@ -24,6 +26,13 @@ from utils.graph_cases import (
random_graph
,
random_graph
,
)
)
# Set seeds to make tests fully reproducible.
SEED
=
12345
# random.randint(1, 99999)
random
.
seed
(
SEED
)
# For networkx
np
.
random
.
seed
(
SEED
)
# For scipy
dgl
.
seed
(
SEED
)
F
.
seed
(
SEED
)
tmp_buffer
=
io
.
BytesIO
()
tmp_buffer
=
io
.
BytesIO
()
...
...
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