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
4692e325
Commit
4692e325
authored
Dec 18, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let StagingInput figure out the device by itself.
parent
46991853
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
42 additions
and
47 deletions
+42
-47
examples/GAN/GAN.py
examples/GAN/GAN.py
+1
-1
tensorpack/callbacks/saver.py
tensorpack/callbacks/saver.py
+1
-1
tensorpack/input_source/input_source.py
tensorpack/input_source/input_source.py
+36
-42
tensorpack/models/batch_norm.py
tensorpack/models/batch_norm.py
+1
-1
tensorpack/tfutils/tower.py
tensorpack/tfutils/tower.py
+1
-0
tensorpack/train/interface.py
tensorpack/train/interface.py
+1
-1
tensorpack/trainv1/multigpu.py
tensorpack/trainv1/multigpu.py
+1
-1
No files found.
examples/GAN/GAN.py
View file @
4692e325
...
@@ -141,7 +141,7 @@ class MultiGPUGANTrainer(TowerTrainer):
...
@@ -141,7 +141,7 @@ class MultiGPUGANTrainer(TowerTrainer):
raw_devices
=
[
'/gpu:{}'
.
format
(
k
)
for
k
in
range
(
nr_gpu
)]
raw_devices
=
[
'/gpu:{}'
.
format
(
k
)
for
k
in
range
(
nr_gpu
)]
# Setup input
# Setup input
input
=
StagingInput
(
input
,
list
(
range
(
nr_gpu
))
)
input
=
StagingInput
(
input
)
cbs
=
input
.
setup
(
model
.
get_inputs_desc
())
cbs
=
input
.
setup
(
model
.
get_inputs_desc
())
self
.
register_callback
(
cbs
)
self
.
register_callback
(
cbs
)
...
...
tensorpack/callbacks/saver.py
View file @
4692e325
...
@@ -21,7 +21,7 @@ class ModelSaver(Callback):
...
@@ -21,7 +21,7 @@ class ModelSaver(Callback):
def
__init__
(
self
,
max_to_keep
=
10
,
def
__init__
(
self
,
max_to_keep
=
10
,
keep_checkpoint_every_n_hours
=
0.5
,
keep_checkpoint_every_n_hours
=
0.5
,
checkpoint_dir
=
None
,
checkpoint_dir
=
None
,
var_collections
=
tf
.
GraphKeys
.
GLOBAL_VARIABLES
):
var_collections
=
[
tf
.
GraphKeys
.
GLOBAL_VARIABLES
,
tf
.
GraphKeys
.
MODEL_VARIABLES
]
):
"""
"""
Args:
Args:
max_to_keep (int): the same as in ``tf.train.Saver``.
max_to_keep (int): the same as in ``tf.train.Saver``.
...
...
tensorpack/input_source/input_source.py
View file @
4692e325
...
@@ -483,13 +483,18 @@ class StagingInput(FeedfreeInput):
...
@@ -483,13 +483,18 @@ class StagingInput(FeedfreeInput):
A callback registered by this input source, to make sure stage/unstage
A callback registered by this input source, to make sure stage/unstage
is run at each step.
is run at each step.
"""
"""
def
__init__
(
self
,
stage_op
,
unstage_op
,
nr_stage
):
def
__init__
(
self
,
stage_op
_fn
,
unstage_op_fn
,
nr_stage
):
self
.
nr_stage
=
nr_stage
self
.
nr_stage
=
nr_stage
self
.
stage_op
=
stage_op
self
.
stage_op_fn
=
stage_op_fn
self
.
fetches
=
tf
.
train
.
SessionRunArgs
(
self
.
unstage_op_fn
=
unstage_op_fn
fetches
=
[
stage_op
,
unstage_op
])
self
.
_initialized
=
False
self
.
_initialized
=
False
def
_setup_graph
(
self
):
self
.
stage_op
=
self
.
stage_op_fn
()
unstage_op
=
self
.
unstage_op_fn
()
self
.
fetches
=
tf
.
train
.
SessionRunArgs
(
fetches
=
[
self
.
stage_op
,
unstage_op
])
def
_prefill
(
self
):
def
_prefill
(
self
):
logger
.
info
(
"Pre-filling staging area ..."
)
logger
.
info
(
"Pre-filling staging area ..."
)
for
k
in
range
(
self
.
nr_stage
):
for
k
in
range
(
self
.
nr_stage
):
...
@@ -502,21 +507,17 @@ class StagingInput(FeedfreeInput):
...
@@ -502,21 +507,17 @@ class StagingInput(FeedfreeInput):
self
.
_prefill
()
self
.
_prefill
()
return
self
.
fetches
return
self
.
fetches
def
__init__
(
self
,
input
,
towers
,
nr_stage
=
5
):
def
__init__
(
self
,
input
,
towers
=
None
,
nr_stage
=
5
):
"""
"""
Args:
Args:
input (FeedfreeInput):
input (FeedfreeInput):
towers ([int]): list of GPU ids to prefetch on.
nr_stage: number of elements to prefetch on each GPU.
nr_stage: number of elements to prefetch on each GPU.
towers: deprecated
"""
"""
assert
isinstance
(
input
,
FeedfreeInput
),
input
assert
isinstance
(
input
,
FeedfreeInput
),
input
self
.
_input
=
input
self
.
_input
=
input
if
not
isinstance
(
towers
[
0
],
int
):
if
towers
is
not
None
:
# API changed
log_deprecated
(
"StagingInput(towers=) has no effect! Devices are handled automatically."
)
log_deprecated
(
"StagingInput(devices=)"
,
"Use (towers=) instead!"
,
"2018-01-31"
)
self
.
_devices
=
towers
else
:
self
.
_devices
=
[
'/gpu:{}'
.
format
(
k
)
for
k
in
towers
]
self
.
_nr_stage
=
nr_stage
self
.
_nr_stage
=
nr_stage
self
.
_areas
=
[]
self
.
_areas
=
[]
...
@@ -525,21 +526,21 @@ class StagingInput(FeedfreeInput):
...
@@ -525,21 +526,21 @@ class StagingInput(FeedfreeInput):
def
_setup
(
self
,
inputs
):
def
_setup
(
self
,
inputs
):
self
.
_input
.
setup
(
inputs
)
self
.
_input
.
setup
(
inputs
)
self
.
_setup_staging_areas
()
def
_get_callbacks
(
self
):
def
_get_callbacks
(
self
):
cbs
=
self
.
_input
.
get_callbacks
()
cbs
=
self
.
_input
.
get_callbacks
()
# Pass a lambda to be called later, because stage ops have not been built
cbs
.
append
(
cbs
.
append
(
StagingInput
.
StagingCallback
(
StagingInput
.
StagingCallback
(
self
.
_get_stage_op
(),
self
.
_get_unstage_op
(),
self
.
_nr_stage
))
lambda
:
self
.
_get_stage_op
(),
lambda
:
self
.
_get_unstage_op
(),
self
.
_nr_stage
))
return
cbs
return
cbs
def
_setup_staging_areas
(
self
):
def
_size
(
self
):
logger
.
info
(
"Setting up StagingArea for GPU prefetching ..."
)
return
self
.
_input
.
size
()
def
_get_input_tensors
(
self
):
with
self
.
cached_name_scope
():
with
self
.
cached_name_scope
():
for
idx
,
device
in
enumerate
(
self
.
_devices
):
with
tf
.
device
(
device
):
inputs
=
self
.
_input
.
get_input_tensors
()
inputs
=
self
.
_input
.
get_input_tensors
()
# Putting variables to stagingarea will cause trouble
# Putting variables to stagingarea will cause trouble
...
@@ -559,14 +560,7 @@ class StagingInput(FeedfreeInput):
...
@@ -559,14 +560,7 @@ class StagingInput(FeedfreeInput):
for
vin
,
vout
in
zip
(
inputs
,
outputs
):
for
vin
,
vout
in
zip
(
inputs
,
outputs
):
vout
.
set_shape
(
vin
.
get_shape
())
vout
.
set_shape
(
vin
.
get_shape
())
self
.
_unstage_ops
.
append
(
outputs
)
self
.
_unstage_ops
.
append
(
outputs
)
return
outputs
def
_size
(
self
):
return
self
.
_input
.
size
()
def
_get_input_tensors
(
self
):
ctx
=
get_current_tower_context
()
ret
=
self
.
_unstage_ops
[
ctx
.
index
]
return
ret
def
_get_stage_op
(
self
):
def
_get_stage_op
(
self
):
with
self
.
cached_name_scope
():
with
self
.
cached_name_scope
():
...
...
tensorpack/models/batch_norm.py
View file @
4692e325
...
@@ -136,7 +136,7 @@ def BatchNorm(x, use_local_stat=None, decay=0.9, epsilon=1e-5,
...
@@ -136,7 +136,7 @@ def BatchNorm(x, use_local_stat=None, decay=0.9, epsilon=1e-5,
assert
get_tf_version_number
()
>=
1.4
,
\
assert
get_tf_version_number
()
>=
1.4
,
\
"Fine tuning a BatchNorm model with fixed statistics is only "
\
"Fine tuning a BatchNorm model with fixed statistics is only "
\
"supported after https://github.com/tensorflow/tensorflow/pull/12580 "
"supported after https://github.com/tensorflow/tensorflow/pull/12580 "
if
ctx
.
i
ndex
==
0
:
# only warn in first tower
if
ctx
.
i
s_main_training_tower
:
# only warn in first tower
logger
.
warn
(
"[BatchNorm] Using moving_mean/moving_variance in training."
)
logger
.
warn
(
"[BatchNorm] Using moving_mean/moving_variance in training."
)
# Using moving_mean/moving_variance in training, which means we
# Using moving_mean/moving_variance in training, which means we
# loaded a pre-trained BN and only fine-tuning the affine part.
# loaded a pre-trained BN and only fine-tuning the affine part.
...
...
tensorpack/tfutils/tower.py
View file @
4692e325
...
@@ -87,6 +87,7 @@ class TowerContext(object):
...
@@ -87,6 +87,7 @@ class TowerContext(object):
"""
"""
return
self
.
_collection_guard
.
get_collection_in_tower
(
key
)
return
self
.
_collection_guard
.
get_collection_in_tower
(
key
)
# TODO currently only used in StagingInput
@
property
@
property
def
index
(
self
):
def
index
(
self
):
return
self
.
_index
return
self
.
_index
...
...
tensorpack/train/interface.py
View file @
4692e325
...
@@ -39,7 +39,7 @@ def apply_default_prefetch(input_source_or_dataflow, trainer):
...
@@ -39,7 +39,7 @@ def apply_default_prefetch(input_source_or_dataflow, trainer):
assert
tf
.
test
.
is_gpu_available
()
assert
tf
.
test
.
is_gpu_available
()
if
not
isinstance
(
input
,
(
StagingInput
,
DummyConstantInput
)):
if
not
isinstance
(
input
,
(
StagingInput
,
DummyConstantInput
)):
input
=
StagingInput
(
input
,
towers
)
input
=
StagingInput
(
input
)
return
input
return
input
...
...
tensorpack/trainv1/multigpu.py
View file @
4692e325
...
@@ -44,7 +44,7 @@ def apply_prefetch_policy(config, gpu_prefetch=True):
...
@@ -44,7 +44,7 @@ def apply_prefetch_policy(config, gpu_prefetch=True):
# seem to only improve on >1 GPUs
# seem to only improve on >1 GPUs
if
not
isinstance
(
config
.
data
,
(
StagingInput
,
DummyConstantInput
)):
if
not
isinstance
(
config
.
data
,
(
StagingInput
,
DummyConstantInput
)):
config
.
data
=
StagingInput
(
config
.
data
,
config
.
tower
)
config
.
data
=
StagingInput
(
config
.
data
)
class
SyncMultiGPUTrainerParameterServer
(
Trainer
):
class
SyncMultiGPUTrainerParameterServer
(
Trainer
):
...
...
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