Commit f2d06a64 authored by Yuxin Wu's avatar Yuxin Wu

update docs

parent f0243500
...@@ -10,12 +10,8 @@ TensorFlow itself also changed APIs before 1.0 and those are not listed here. ...@@ -10,12 +10,8 @@ TensorFlow itself also changed APIs before 1.0 and those are not listed here.
+ [2017/10/21] + [2017/10/21]
tensorpack is gradually switching to a new Trainer API. tensorpack is gradually switching to a new Trainer API.
The old API will keep working for a while. The old API will keep working for a while. See [issue](https://github.com/ppwwyyxx/tensorpack/issues/458)
To switch to new API, the easiest way is to: for details.
1. `export TENSORPACK_TRAIN_API=v2` (will be default soon in the future).
2. Replace `SomeTrainer(config, ...).train()` with `launch_train_with_config(config, SomeTrainer(...))`.
+ [2017/10/18] + [2017/10/18]
`TrainConfig(predict_tower)` was deprecated. You can set the inference device directly when creating the `InferenceRunner` callback. `TrainConfig(predict_tower)` was deprecated. You can set the inference device directly when creating the `InferenceRunner` callback.
+ [2017/10/12](https://github.com/ppwwyyxx/tensorpack/commit/7e963996f615b85f7459455596b4ee9bbd0bce8e). + [2017/10/12](https://github.com/ppwwyyxx/tensorpack/commit/7e963996f615b85f7459455596b4ee9bbd0bce8e).
......
...@@ -18,7 +18,7 @@ You will need to define two things for a new Trainer: ...@@ -18,7 +18,7 @@ You will need to define two things for a new Trainer:
1. What is the graph. 1. What is the graph.
Add any tensors and ops you like, either before creating the trainer or inside `Trainer.__init__`. Add any tensors and ops you like, either before creating the trainer or inside `Trainer.__init__`.
* What is the iteration. There are 2 ways to define an iteration: 2. What is the iteration. There are 2 ways to define an iteration:
1. Set `Trainer.train_op`. This op will be run by default. 1. Set `Trainer.train_op`. This op will be run by default.
2. Subclass `Trainer` and override the `run_step()` method. This way you can do something more than running an op. 2. Subclass `Trainer` and override the `run_step()` method. This way you can do something more than running an op.
......
...@@ -3,17 +3,17 @@ ...@@ -3,17 +3,17 @@
Tensorpack follows the "define-and-run" paradigm. A training has two steps: Tensorpack follows the "define-and-run" paradigm. A training has two steps:
1. Build graph for the model. 1. __Define__: Build graph for the model.
Users can call whatever tensorflow functions to setup the graph. Users can call whatever tensorflow functions to setup the graph.
Users may or may not use tensorpack `InputSource`, `ModelDesc` to build the graph. Users may or may not use tensorpack `InputSource`, `ModelDesc` or other utilities to build the graph.
This step defines "what to run" in every training step. This goal of this step is to define "what to run" in later training steps,
It can happen either inside or outside the trainer. and it can happen either inside or outside tensorpack trainer.
2. Train the model (the [Trainer.train() method](http://tensorpack.readthedocs.io/en/latest/modules/train.html#tensorpack.train.Trainer.train)): 2. __Run__: Train the model (the [Trainer.train() method](http://tensorpack.readthedocs.io/en/latest/modules/train.html#tensorpack.train.Trainer.train)):
1. Setup callbacks/monitors. 1. Setup callbacks/monitors.
2. Finalize the graph, initialize session. 2. Finalize graph, initialize session.
3. Run the main loop. 3. Run the training loop.
## Assumptions of Base Trainer ## Assumptions of Base Trainer
...@@ -43,17 +43,18 @@ In other words, an "epoch" in tensorpack is the __default period to run callback ...@@ -43,17 +43,18 @@ In other words, an "epoch" in tensorpack is the __default period to run callback
Most neural network training tasks are single-cost optimization. Most neural network training tasks are single-cost optimization.
Tensorpack provides some trainer implementations for such tasks. Tensorpack provides some trainer implementations for such tasks.
These trainers will build the graph by itself, with the following arguments: These trainers will take care of step 1, by building the graph by itself, with the following arguments:
1. Some `InputDesc`, the metadata about the input. 1. Some `InputDesc`, the metadata about the input.
2. An `InputSource`, where the input come from. See [Input Pipeline](input-source.html). 2. An `InputSource`, where the input come from. See [Input Pipeline](input-source.html).
3. A function which takes input tensors and returns the cost. 3. A function which takes input tensors and returns the cost.
4. A function which returns an optimizer. 4. A function which returns an optimizer.
See [SingleCostTrainer.setup_graph](http://tensorpack.readthedocs.io/en/latest/modules/train.html#tensorpack.train.SingleCostTrainer.setup_graph) These are documented better in [SingleCostTrainer.setup_graph](http://tensorpack.readthedocs.io/en/latest/modules/train.html#tensorpack.train.SingleCostTrainer.setup_graph).
for details. Often you'll not use this method directly, but use [high-level interface](training-interface.html#with-modeldesc-and-trainconfig)
instead.
Existing multi-GPU trainers include the logic of data-parallel training. Existing multi-GPU trainers include the logic of single-cost data-parallel training.
You can enable them by just one line, and all the necessary logic to achieve the best performance was baked into the trainers already. You can enable them by just one line, and all the necessary logic to achieve the best performance was baked into the trainers already.
The trainers can reach the same performance as the [official tensorflow benchmark](https://www.tensorflow.org/performance/benchmarks). The trainers can reach the same performance as the [official tensorflow benchmark](https://www.tensorflow.org/performance/benchmarks).
...@@ -61,9 +62,6 @@ Please note that in data-parallel training, in each iteration all towers (all re ...@@ -61,9 +62,6 @@ Please note that in data-parallel training, in each iteration all towers (all re
tensors from the `InputSource` (instead of taking one for all and split). So the total batch size tensors from the `InputSource` (instead of taking one for all and split). So the total batch size
would be ``(batch size of InputSource/DataFlow) * #GPU``. would be ``(batch size of InputSource/DataFlow) * #GPU``.
There are also high-level wrappers that have slightly simpler interface (but exist mainly for old users).
See [High-Level Training Interface](training-interface.html)
### Custom Trainers ### Custom Trainers
You can easily write a trainer for other types of training. You can easily write a trainer for other types of training.
......
...@@ -2,16 +2,16 @@ ...@@ -2,16 +2,16 @@
# Training Interface # Training Interface
Tensorpack trainers have an interface for maximum flexibility. Tensorpack trainers have an interface for maximum flexibility.
There are also interfaces built on top of trainers to simplify the use, Then, there are interfaces built on top of trainers to simplify the use,
when you don't want to customize too much. when you don't want to customize too much.
### Raw Trainer Interface ### Raw Trainer Interface
For general trainer, build the graph by yourself. __Define__: For general trainer, build the graph by yourself.
For single-cost trainer, build the graph by For single-cost trainer, build the graph by
[SingleCostTrainer.setup_graph](http://tensorpack.readthedocs.io/en/latest/modules/train.html#tensorpack.train.SingleCostTrainer.setup_graph). [SingleCostTrainer.setup_graph](http://tensorpack.readthedocs.io/en/latest/modules/train.html#tensorpack.train.SingleCostTrainer.setup_graph).
Then, call __Run__: Then, call
[Trainer.train()](http://tensorpack.readthedocs.io/en/latest/modules/train.html#tensorpack.train.Trainer.train) [Trainer.train()](http://tensorpack.readthedocs.io/en/latest/modules/train.html#tensorpack.train.Trainer.train)
or or
[Trainer.train_with_defaults()](http://tensorpack.readthedocs.io/en/latest/modules/train.html#tensorpack.train.Trainer.train_with_defaults) [Trainer.train_with_defaults()](http://tensorpack.readthedocs.io/en/latest/modules/train.html#tensorpack.train.Trainer.train_with_defaults)
...@@ -19,6 +19,10 @@ which applies some defaults options for normal use cases. ...@@ -19,6 +19,10 @@ which applies some defaults options for normal use cases.
### With ModelDesc and TrainConfig ### With ModelDesc and TrainConfig
This is an interface that's most familiar to old tensorpack users,
and is now mainly useful for single-cost tasks.
A lot of examples are written in this interface.
[SingleCost trainers](trainer.html#single-cost-trainers) [SingleCost trainers](trainer.html#single-cost-trainers)
expects 4 arguments in `setup_graph`: `InputDesc`, `InputSource`, get_cost function, and an optimizer. expects 4 arguments in `setup_graph`: `InputDesc`, `InputSource`, get_cost function, and an optimizer.
`ModelDesc` describes a model by packing 3 of them together into one object: `ModelDesc` describes a model by packing 3 of them together into one object:
...@@ -55,7 +59,9 @@ config = TrainConfig( ...@@ -55,7 +59,9 @@ config = TrainConfig(
model=MyModel() model=MyModel()
dataflow=my_dataflow, dataflow=my_dataflow,
# data=my_inputsource, # alternatively, use a customized InputSource # data=my_inputsource, # alternatively, use a customized InputSource
callbacks=[...] callbacks=[...], # some default callbacks are automatically applied
# some default monitors are automatically applied
steps_per_epoch=300, # default to the size of your InputSource/DataFlow
) )
trainer = SomeTrainer() trainer = SomeTrainer()
...@@ -63,5 +69,7 @@ trainer = SomeTrainer() ...@@ -63,5 +69,7 @@ trainer = SomeTrainer()
launch_train_with_config(config, trainer) launch_train_with_config(config, trainer)
``` ```
See the docs of See the docs of
[TrainConfig](http://tensorpack.readthedocs.io/en/latest/modules/train.html#tensorpack.train.TrainConfig)
and
[launch_train_with_config](http://tensorpack.readthedocs.io/en/latest/modules/train.html#tensorpack.train.launch_train_with_config) [launch_train_with_config](http://tensorpack.readthedocs.io/en/latest/modules/train.html#tensorpack.train.launch_train_with_config)
for its usage and detailed functionalities. for usage and detailed functionalities.
...@@ -42,11 +42,6 @@ class TrainConfig(object): ...@@ -42,11 +42,6 @@ class TrainConfig(object):
nr_tower=1, tower=None, nr_tower=1, tower=None,
**kwargs): **kwargs):
""" """
Note:
It depends on the specific trainer what fields are necessary.
Most existing trainers in tensorpack requires one of `dataflow` or `data`,
and `model` to be present in the config.
Args: Args:
dataflow (DataFlow): dataflow (DataFlow):
data (InputSource): data (InputSource):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment