Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ppwwyyxx committed Oct 18, 2017
1 parent caf9ee8 commit c33a3cc
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 17 deletions.
5 changes: 4 additions & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SPHINXPROJ = tensorpack
SOURCEDIR = .
BUILDDIR = build

.PHONY: help Makefile docset
.PHONY: help Makefile docset clean

all: html

Expand All @@ -24,3 +24,6 @@ docset: html
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
html: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

clean:
rm -rf build
2 changes: 1 addition & 1 deletion tensorpack/callbacks/prof.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def _write_event(self, metadata):
class PeakMemoryTracker(Callback):
"""
Track peak memory in each session run, by
:module:`tf.contrib.memory_stats`.
:mod:`tf.contrib.memory_stats`.
It can only be used for GPUs.
"""
def __init__(self, devices=['/gpu:0']):
Expand Down
14 changes: 9 additions & 5 deletions tensorpack/graph_builder/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,15 @@ def build(self, input, get_cost_fn, get_opt_fn):
get_opt_fn (-> tf.train.Optimizer): callable which returns an optimizer
Returns:
tf.Operation: the training op
tf.Operation: the op which sync all the local variables from PS.
This op sholud be run before training.
tf.Operation: the op which sync all the local `MODEL_VARIABLES` from PS.
You can choose how often to run it by yourself.
(tf.Operation, tf.Operation, tf.Operation):
1. the training op.
2. the op which sync all the local variables from PS.
This op sholud be run before training.
3. the op which sync all the local `MODEL_VARIABLES` from PS.
You can choose how often to run it by yourself.
"""
with override_to_local_variable():
get_global_step_var()
Expand Down
7 changes: 5 additions & 2 deletions tensorpack/graph_builder/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,11 @@ def build(self, input, get_cost_fn, get_opt_fn):
get_opt_fn (-> tf.train.Optimizer): callable which returns an optimizer
Returns:
tf.Operation: the training op.
tf.Operation: the op which sync variables from GPU 0 to other GPUs.
(tf.Operation, tf.Operation)
1. the training op.
2. the op which sync variables from GPU 0 to other GPUs.
It has to be run before the training has started.
And you can optionally run it later to sync non-trainable variables.
"""
Expand Down
2 changes: 1 addition & 1 deletion tensorpack/input_source/input_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
__all__ = ['PlaceholderInput', 'FeedInput', 'DataParallelFeedInput',
'FeedfreeInput',
'QueueInput', 'BatchQueueInput',
'ZMQInput', 'DummyConstantInput', 'TensorInput',
'DummyConstantInput', 'TensorInput',
'TFDatasetInput',
'StagingInputWrapper']

Expand Down
7 changes: 6 additions & 1 deletion tensorpack/input_source/input_source_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,23 @@ def _setup(self, inputs_desc):
pass

def setup_done(self):
"""
Returns:
bool: whether :meth:`setup()` has been called.
"""
return self._setup_done

@memoized
def get_callbacks(self):
"""
An InputSource might need some extra maintainance during training,
which is done also through the Callback interface.
This method returns the Callbacks and the return value will be memoized.
This method returns the callbacks and the return value will be memoized.
Returns:
list[Callback]: extra callbacks needed by this InputSource.
"""
assert self.setup_done()
return [CallbackFactory(
before_train=lambda _: self.reset_state())] + self._get_callbacks()

Expand Down
21 changes: 15 additions & 6 deletions tensorpack/train/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class TrainLoop(object):
"""
Manage the double for loop.
"""

def __init__(self):
self._epoch_num = 0
self._global_step = 0
Expand Down Expand Up @@ -82,7 +83,7 @@ def global_step(self):
@property
def local_step(self):
"""
The number of (tensorpack) steps that have finished in the current epoch.
The number of steps that have finished in the current epoch.
"""
return self._local_step

Expand All @@ -97,9 +98,12 @@ class Trainer(object):
hooked_sess (tf.train.MonitoredSession): the session with hooks.
monitors (Monitors): the monitors. Other callbacks can use it for logging.
"""
# step attr only available after before_train?

is_chief = True
"""
Whether this process is the chief worker in distributed training.
Only chief worker will run some callbacks.
"""

def __init__(self, config):
"""
Expand Down Expand Up @@ -283,17 +287,22 @@ def vs_name_for_predictor(self):
return ""


def _delegate_attr(name):
def _get_property(name):
"""
Delegate property to self.loop
"""
setattr(Trainer, name, property(
lambda self: getattr(self.loop, name)))
ret = property(
lambda self: getattr(self.loop, name))
try:
ret.__doc__ = getattr(TrainLoop, name).__doc__
except AttributeError:
pass
return ret


for name in ['global_step', 'local_step', 'steps_per_epoch',
'epoch_num', 'starting_epoch', 'max_epoch']:
_delegate_attr(name)
setattr(Trainer, name, _get_property(name))


def launch_train(
Expand Down

0 comments on commit c33a3cc

Please sign in to comment.