Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
8df2d7c5
Commit
8df2d7c5
authored
Aug 04, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use ps_device=cpu when #gpu>=4
parent
8419ee3f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
9 deletions
+20
-9
examples/DeepQNetwork/DQN.py
examples/DeepQNetwork/DQN.py
+2
-5
tensorpack/train/distributed.py
tensorpack/train/distributed.py
+1
-0
tensorpack/train/multigpu.py
tensorpack/train/multigpu.py
+17
-4
No files found.
examples/DeepQNetwork/DQN.py
View file @
8df2d7c5
...
@@ -96,7 +96,6 @@ class Model(DQNModel):
...
@@ -96,7 +96,6 @@ class Model(DQNModel):
def
get_config
():
def
get_config
():
M
=
Model
()
expreplay
=
ExpReplay
(
expreplay
=
ExpReplay
(
predictor_io_names
=
([
'state'
],
[
'Qvalue'
]),
predictor_io_names
=
([
'state'
],
[
'Qvalue'
]),
player
=
get_player
(
train
=
True
),
player
=
get_player
(
train
=
True
),
...
@@ -111,6 +110,7 @@ def get_config():
...
@@ -111,6 +110,7 @@ def get_config():
return
TrainConfig
(
return
TrainConfig
(
dataflow
=
expreplay
,
dataflow
=
expreplay
,
model
=
Model
(),
callbacks
=
[
callbacks
=
[
ModelSaver
(),
ModelSaver
(),
PeriodicTrigger
(
PeriodicTrigger
(
...
@@ -128,11 +128,8 @@ def get_config():
...
@@ -128,11 +128,8 @@ def get_config():
every_k_epochs
=
10
),
every_k_epochs
=
10
),
HumanHyperParamSetter
(
'learning_rate'
),
HumanHyperParamSetter
(
'learning_rate'
),
],
],
model
=
M
,
steps_per_epoch
=
STEPS_PER_EPOCH
,
steps_per_epoch
=
STEPS_PER_EPOCH
,
max_epoch
=
1000
,
max_epoch
=
1000
,
# run the simulator on a separate GPU if available
predict_tower
=
[
1
]
if
get_nr_gpu
()
>
1
else
[
0
],
)
)
...
@@ -172,5 +169,5 @@ if __name__ == '__main__':
...
@@ -172,5 +169,5 @@ if __name__ == '__main__':
os
.
path
.
basename
(
ROM_FILE
)
.
split
(
'.'
)[
0
])))
os
.
path
.
basename
(
ROM_FILE
)
.
split
(
'.'
)[
0
])))
config
=
get_config
()
config
=
get_config
()
if
args
.
load
:
if
args
.
load
:
config
.
session_init
=
SaverRestore
(
args
.
load
)
config
.
session_init
=
get_model_loader
(
args
.
load
)
QueueInputTrainer
(
config
)
.
train
()
QueueInputTrainer
(
config
)
.
train
()
tensorpack/train/distributed.py
View file @
8df2d7c5
...
@@ -42,6 +42,7 @@ class DistributedTrainerReplicated(MultiGPUTrainerBase):
...
@@ -42,6 +42,7 @@ class DistributedTrainerReplicated(MultiGPUTrainerBase):
and get synchronously applied to the global copy of variables located on PS.
and get synchronously applied to the global copy of variables located on PS.
Then each worker copy the latest variables from PS back to local.
Then each worker copy the latest variables from PS back to local.
See https://www.tensorflow.org/performance/benchmarks for details.
Note:
Note:
Gradients are not averaged across workers.
Gradients are not averaged across workers.
...
...
tensorpack/train/multigpu.py
View file @
8df2d7c5
...
@@ -153,18 +153,23 @@ class SyncMultiGPUTrainerParameterServer(MultiGPUTrainerBase):
...
@@ -153,18 +153,23 @@ class SyncMultiGPUTrainerParameterServer(MultiGPUTrainerBase):
A data-parallel multi-GPU trainer. It builds one tower on each GPU with
A data-parallel multi-GPU trainer. It builds one tower on each GPU with
shared variable scope. It synchronoizes the gradients computed
shared variable scope. It synchronoizes the gradients computed
from each tower, averages them and applies to the shared variables.
from each tower, averages them and applies to the shared variables.
See https://www.tensorflow.org/performance/benchmarks for details.
"""
"""
def
__init__
(
self
,
config
,
ps_device
=
'gpu'
,
gpu_prefetch
=
True
):
def
__init__
(
self
,
config
,
ps_device
=
None
,
gpu_prefetch
=
True
):
"""
"""
Args:
Args:
config(TrainConfig): Must contain 'model' and either one of 'data' or 'dataflow'.
config(TrainConfig): Must contain 'model' and either one of 'data' or 'dataflow'.
ps_device: either 'gpu' or 'cpu', where variables are stored.
ps_device: either 'gpu' or 'cpu', where variables are stored. Setting to 'cpu' might help if #gpu>=4
Defaults to 'cpu' when #gpu >= 4.
gpu_prefetch(bool): whether to prefetch the data to each GPU. Usually improve performance.
gpu_prefetch(bool): whether to prefetch the data to each GPU. Usually improve performance.
"""
"""
apply_prefetch_policy
(
config
,
gpu_prefetch
)
apply_prefetch_policy
(
config
,
gpu_prefetch
)
self
.
_input_source
=
config
.
data
self
.
_input_source
=
config
.
data
if
ps_device
is
None
:
ps_device
=
'cpu'
if
config
.
nr_tower
>=
4
else
'gpu'
assert
ps_device
in
[
'gpu'
,
'cpu'
],
ps_device
assert
ps_device
in
[
'gpu'
,
'cpu'
],
ps_device
self
.
_ps_device
=
ps_device
self
.
_ps_device
=
ps_device
super
(
SyncMultiGPUTrainerParameterServer
,
self
)
.
__init__
(
config
)
super
(
SyncMultiGPUTrainerParameterServer
,
self
)
.
__init__
(
config
)
...
@@ -248,6 +253,8 @@ class SyncMultiGPUTrainerReplicated(MultiGPUTrainerBase):
...
@@ -248,6 +253,8 @@ class SyncMultiGPUTrainerReplicated(MultiGPUTrainerBase):
Data-parallel multi-GPU trainer where each GPU contains a replicate of the whole model.
Data-parallel multi-GPU trainer where each GPU contains a replicate of the whole model.
It will build one tower on each GPU under its own variable scope.
It will build one tower on each GPU under its own variable scope.
Each gradient update is averaged across or GPUs through NCCL.
Each gradient update is averaged across or GPUs through NCCL.
See https://www.tensorflow.org/performance/benchmarks for details.
"""
"""
def
__init__
(
self
,
config
,
gpu_prefetch
=
True
):
def
__init__
(
self
,
config
,
gpu_prefetch
=
True
):
"""
"""
...
@@ -381,8 +388,14 @@ class AsyncMultiGPUTrainer(MultiGPUTrainerBase):
...
@@ -381,8 +388,14 @@ class AsyncMultiGPUTrainer(MultiGPUTrainerBase):
"""
"""
callbacks
=
input
.
setup
(
model
.
get_inputs_desc
())
callbacks
=
input
.
setup
(
model
.
get_inputs_desc
())
raw_devices
=
[
'/gpu:{}'
.
format
(
k
)
for
k
in
tower
]
ps_device
=
'cpu'
if
len
(
tower
)
>=
4
else
'gpu'
devices
=
[
LeastLoadedDeviceSetter
(
d
,
raw_devices
)
for
d
in
raw_devices
]
if
ps_device
==
'gpu'
:
raw_devices
=
[
'/gpu:{}'
.
format
(
k
)
for
k
in
tower
]
devices
=
[
LeastLoadedDeviceSetter
(
d
,
raw_devices
)
for
d
in
raw_devices
]
else
:
devices
=
[
tf
.
train
.
replica_device_setter
(
worker_device
=
d
,
ps_device
=
'/cpu:0'
,
ps_tasks
=
1
)
for
d
in
raw_devices
]
grad_list
=
MultiGPUTrainerBase
.
build_on_multi_tower
(
grad_list
=
MultiGPUTrainerBase
.
build_on_multi_tower
(
tower
,
tower
,
lambda
:
MultiGPUTrainerBase
.
_build_graph_get_grads
(
model
,
input
),
devices
)
lambda
:
MultiGPUTrainerBase
.
_build_graph_get_grads
(
model
,
input
),
devices
)
...
...
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