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
1232961e
Unverified
Commit
1232961e
authored
Aug 04, 2020
by
xiang song(charlie.song)
Committed by
GitHub
Aug 04, 2020
Browse files
Fix timing (#1930)
Co-authored-by:
Ubuntu
<
ubuntu@ip-172-31-51-214.ec2.internal
>
parent
fae26dd1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
7 deletions
+6
-7
examples/pytorch/graphsage/train_cv.py
examples/pytorch/graphsage/train_cv.py
+3
-4
examples/pytorch/graphsage/train_sampling.py
examples/pytorch/graphsage/train_sampling.py
+3
-3
No files found.
examples/pytorch/graphsage/train_cv.py
View file @
1232961e
...
@@ -176,7 +176,7 @@ def load_subtensor(g, labels, blocks, hist_blocks, dev_id, aggregation_on_device
...
@@ -176,7 +176,7 @@ def load_subtensor(g, labels, blocks, hist_blocks, dev_id, aggregation_on_device
"""
"""
blocks
[
0
].
srcdata
[
'features'
]
=
g
.
ndata
[
'features'
][
blocks
[
0
].
srcdata
[
dgl
.
NID
]]
blocks
[
0
].
srcdata
[
'features'
]
=
g
.
ndata
[
'features'
][
blocks
[
0
].
srcdata
[
dgl
.
NID
]]
blocks
[
-
1
].
dstdata
[
'label'
]
=
labels
[
blocks
[
-
1
].
dstdata
[
dgl
.
NID
]]
blocks
[
-
1
].
dstdata
[
'label'
]
=
labels
[
blocks
[
-
1
].
dstdata
[
dgl
.
NID
]]
ret_blocks
=
[]
ret_blocks
=
[]
ret_hist_blocks
=
[]
ret_hist_blocks
=
[]
for
i
,
(
block
,
hist_block
)
in
enumerate
(
zip
(
blocks
,
hist_blocks
)):
for
i
,
(
block
,
hist_block
)
in
enumerate
(
zip
(
blocks
,
hist_blocks
)):
hist_col
=
'features'
if
i
==
0
else
'hist_%d'
%
i
hist_col
=
'features'
if
i
==
0
else
'hist_%d'
%
i
...
@@ -257,9 +257,8 @@ def run(args, dev_id, data):
...
@@ -257,9 +257,8 @@ def run(args, dev_id, data):
for
epoch
in
range
(
args
.
num_epochs
):
for
epoch
in
range
(
args
.
num_epochs
):
tic
=
time
.
time
()
tic
=
time
.
time
()
model
.
train
()
model
.
train
()
tic_step
=
time
.
time
()
for
step
,
(
blocks
,
hist_blocks
)
in
enumerate
(
dataloader
):
for
step
,
(
blocks
,
hist_blocks
)
in
enumerate
(
dataloader
):
tic_step
=
time
.
time
()
# The nodes for input lies at the LHS side of the first block.
# The nodes for input lies at the LHS side of the first block.
# The nodes for output lies at the RHS side of the last block.
# The nodes for output lies at the RHS side of the last block.
input_nodes
=
blocks
[
0
].
srcdata
[
dgl
.
NID
]
input_nodes
=
blocks
[
0
].
srcdata
[
dgl
.
NID
]
...
@@ -283,7 +282,7 @@ def run(args, dev_id, data):
...
@@ -283,7 +282,7 @@ def run(args, dev_id, data):
acc
=
compute_acc
(
batch_pred
,
batch_labels
)
acc
=
compute_acc
(
batch_pred
,
batch_labels
)
print
(
'Epoch {:05d} | Step {:05d} | Loss {:.4f} | Train Acc {:.4f} | Speed (samples/sec) {:.4f}'
.
format
(
print
(
'Epoch {:05d} | Step {:05d} | Loss {:.4f} | Train Acc {:.4f} | Speed (samples/sec) {:.4f}'
.
format
(
epoch
,
step
,
loss
.
item
(),
acc
.
item
(),
np
.
mean
(
iter_tput
[
3
:])))
epoch
,
step
,
loss
.
item
(),
acc
.
item
(),
np
.
mean
(
iter_tput
[
3
:])))
tic_step
=
time
.
time
()
toc
=
time
.
time
()
toc
=
time
.
time
()
print
(
'Epoch Time(s): {:.4f}'
.
format
(
toc
-
tic
))
print
(
'Epoch Time(s): {:.4f}'
.
format
(
toc
-
tic
))
if
epoch
>=
5
:
if
epoch
>=
5
:
...
...
examples/pytorch/graphsage/train_sampling.py
View file @
1232961e
...
@@ -155,9 +155,8 @@ def run(args, device, data):
...
@@ -155,9 +155,8 @@ def run(args, device, data):
# Loop over the dataloader to sample the computation dependency graph as a list of
# Loop over the dataloader to sample the computation dependency graph as a list of
# blocks.
# blocks.
tic_step
=
time
.
time
()
for
step
,
(
input_nodes
,
seeds
,
blocks
)
in
enumerate
(
dataloader
):
for
step
,
(
input_nodes
,
seeds
,
blocks
)
in
enumerate
(
dataloader
):
tic_step
=
time
.
time
()
# Load the input features as well as output labels
# Load the input features as well as output labels
batch_inputs
,
batch_labels
=
load_subtensor
(
train_g
,
seeds
,
input_nodes
,
device
)
batch_inputs
,
batch_labels
=
load_subtensor
(
train_g
,
seeds
,
input_nodes
,
device
)
blocks
=
[
block
.
to
(
device
)
for
block
in
blocks
]
blocks
=
[
block
.
to
(
device
)
for
block
in
blocks
]
...
@@ -175,6 +174,7 @@ def run(args, device, data):
...
@@ -175,6 +174,7 @@ def run(args, device, data):
gpu_mem_alloc
=
th
.
cuda
.
max_memory_allocated
()
/
1000000
if
th
.
cuda
.
is_available
()
else
0
gpu_mem_alloc
=
th
.
cuda
.
max_memory_allocated
()
/
1000000
if
th
.
cuda
.
is_available
()
else
0
print
(
'Epoch {:05d} | Step {:05d} | Loss {:.4f} | Train Acc {:.4f} | Speed (samples/sec) {:.4f} | GPU {:.1f} MiB'
.
format
(
print
(
'Epoch {:05d} | Step {:05d} | Loss {:.4f} | Train Acc {:.4f} | Speed (samples/sec) {:.4f} | GPU {:.1f} MiB'
.
format
(
epoch
,
step
,
loss
.
item
(),
acc
.
item
(),
np
.
mean
(
iter_tput
[
3
:]),
gpu_mem_alloc
))
epoch
,
step
,
loss
.
item
(),
acc
.
item
(),
np
.
mean
(
iter_tput
[
3
:]),
gpu_mem_alloc
))
tic_step
=
time
.
time
()
toc
=
time
.
time
()
toc
=
time
.
time
()
print
(
'Epoch Time(s): {:.4f}'
.
format
(
toc
-
tic
))
print
(
'Epoch Time(s): {:.4f}'
.
format
(
toc
-
tic
))
...
@@ -207,7 +207,7 @@ if __name__ == '__main__':
...
@@ -207,7 +207,7 @@ if __name__ == '__main__':
argparser
.
add_argument
(
'--inductive'
,
action
=
'store_true'
,
argparser
.
add_argument
(
'--inductive'
,
action
=
'store_true'
,
help
=
"Inductive learning setting"
)
help
=
"Inductive learning setting"
)
args
=
argparser
.
parse_args
()
args
=
argparser
.
parse_args
()
if
args
.
gpu
>=
0
:
if
args
.
gpu
>=
0
:
device
=
th
.
device
(
'cuda:%d'
%
args
.
gpu
)
device
=
th
.
device
(
'cuda:%d'
%
args
.
gpu
)
else
:
else
:
...
...
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