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
53fc6392
Unverified
Commit
53fc6392
authored
Jul 24, 2020
by
Jinjing Zhou
Committed by
GitHub
Jul 24, 2020
Browse files
[Torch] Fix inter-process communication for PyTorch (#1858)
* fix * add comment
parent
62077ef3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
3 deletions
+35
-3
python/dgl/heterograph_index.py
python/dgl/heterograph_index.py
+13
-3
tests/pytorch/test_ipc.py
tests/pytorch/test_ipc.py
+22
-0
No files found.
python/dgl/heterograph_index.py
View file @
53fc6392
...
@@ -25,7 +25,12 @@ class HeteroGraphIndex(ObjectBase):
...
@@ -25,7 +25,12 @@ class HeteroGraphIndex(ObjectBase):
return
obj
return
obj
def
__getstate__
(
self
):
def
__getstate__
(
self
):
return
_CAPI_DGLHeteroPickle
(
self
)
"""Issue: https://github.com/pytorch/pytorch/issues/32351
Need to set the tensor created in the __getstate__ function
as object attribute to avoid potential bugs
"""
self
.
_pk_state
=
_CAPI_DGLHeteroPickle
(
self
)
return
self
.
_pk_state
def
__setstate__
(
self
,
state
):
def
__setstate__
(
self
,
state
):
self
.
_cache
=
{}
self
.
_cache
=
{}
...
@@ -1230,8 +1235,12 @@ class HeteroPickleStates(ObjectBase):
...
@@ -1230,8 +1235,12 @@ class HeteroPickleStates(ObjectBase):
return
[
arr_func
(
i
)
for
i
in
range
(
num_arr
)]
return
[
arr_func
(
i
)
for
i
in
range
(
num_arr
)]
def
__getstate__
(
self
):
def
__getstate__
(
self
):
arrays
=
[
F
.
zerocopy_from_dgl_ndarray
(
arr
)
for
arr
in
self
.
arrays
]
"""Issue: https://github.com/pytorch/pytorch/issues/32351
return
self
.
version
,
self
.
meta
,
arrays
Need to set the tensor created in the __getstate__ function
as object attribute to avoid potential bugs
"""
self
.
_pk_arrays
=
[
F
.
zerocopy_from_dgl_ndarray
(
arr
)
for
arr
in
self
.
arrays
]
return
self
.
version
,
self
.
meta
,
self
.
_pk_arrays
def
__setstate__
(
self
,
state
):
def
__setstate__
(
self
,
state
):
if
isinstance
(
state
[
0
],
int
):
if
isinstance
(
state
[
0
],
int
):
...
@@ -1244,4 +1253,5 @@ class HeteroPickleStates(ObjectBase):
...
@@ -1244,4 +1253,5 @@ class HeteroPickleStates(ObjectBase):
num_nodes_per_type
=
F
.
zerocopy_to_dgl_ndarray
(
num_nodes_per_type
)
num_nodes_per_type
=
F
.
zerocopy_to_dgl_ndarray
(
num_nodes_per_type
)
self
.
__init_handle_by_constructor__
(
self
.
__init_handle_by_constructor__
(
_CAPI_DGLCreateHeteroPickleStatesOld
,
metagraph
,
num_nodes_per_type
,
adjs
)
_CAPI_DGLCreateHeteroPickleStatesOld
,
metagraph
,
num_nodes_per_type
,
adjs
)
_init_api
(
"dgl.heterograph_index"
)
_init_api
(
"dgl.heterograph_index"
)
tests/pytorch/test_ipc.py
0 → 100644
View file @
53fc6392
import
dgl
import
torch
as
th
import
torch.multiprocessing
as
mp
import
os
import
unittest
def
sub_ipc
(
g
):
print
(
g
)
return
g
@
unittest
.
skipIf
(
os
.
name
==
'nt'
,
reason
=
'Do not support windows yet'
)
def
test_torch_ipc
():
g
=
dgl
.
graph
([(
0
,
1
),
(
1
,
2
),
(
2
,
3
)])
ctx
=
mp
.
get_context
(
"spawn"
)
p
=
ctx
.
Process
(
target
=
sub_ipc
,
args
=
(
g
,
))
p
.
start
()
p
.
join
()
if
__name__
==
"__main__"
:
test_torch_ipc
()
\ No newline at end of file
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