Skip to content

add config_parser in trainer_config_helpers to seperate trainer config #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
529f24c
cpu cmrnorm
hedaoyuan Dec 12, 2016
9503590
add CrossMapNormal
hedaoyuan Dec 13, 2016
e357f27
add GPU CrossMapNormal
hedaoyuan Dec 13, 2016
0eac399
priorbox layer for ssd
Dec 13, 2016
39d689e
Format the priorbox code
Dec 14, 2016
438a704
add rnn_cn.md
Dec 14, 2016
9600932
Add fake gpu support of the priorbox layer for the moment
Dec 14, 2016
c007608
Format the python file.
Dec 14, 2016
a1d2abc
add Function
hedaoyuan Dec 14, 2016
ce1d98e
Add a Tensor to use as a Function argument
hedaoyuan Dec 15, 2016
214343a
modify details
Dec 15, 2016
660b310
modify line183 beam search
Dec 15, 2016
4ebb3eb
imporve Function
hedaoyuan Dec 15, 2016
9171ab0
Merge branch 'develop' of https://github.com/baidu/Paddle into cmrnorm
hedaoyuan Dec 15, 2016
707a9c9
Fix variable name and add the annotation
Dec 15, 2016
520342e
Fix code format
Dec 15, 2016
d2d0010
add CrossMapNormalGradFunc
hedaoyuan Dec 15, 2016
22a5e47
move Function to function dir
hedaoyuan Dec 15, 2016
558e869
add CMakeLists
hedaoyuan Dec 15, 2016
d11e2b4
Remove some useless code
hedaoyuan Dec 15, 2016
f13aeb5
fix swig_api
hedaoyuan Dec 15, 2016
1048aee
Add input layer check
Dec 15, 2016
cee9346
add some comments
hedaoyuan Dec 15, 2016
5222b58
support UBUNTU MIRROR and modify doc
wen-bo-yang Dec 16, 2016
2b91bf1
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wen-bo-yang Dec 16, 2016
5b746fb
modify doc doc/getstarted/build_and_install/docker_install_en.rst
wen-bo-yang Dec 16, 2016
36af605
modify doc
wen-bo-yang Dec 16, 2016
9f990d9
Add unittest of the priorbox layer
Dec 16, 2016
8d9f675
Add header files
Dec 16, 2016
d40bb72
modify rnn_config_cn.rst
Dec 16, 2016
cad325f
Add header file
Dec 16, 2016
38723e7
remove random flag
Dec 19, 2016
7dfe3bd
remove gpu memory alloc
Dec 19, 2016
148bd4d
add Layer::createFunction
hedaoyuan Dec 19, 2016
1a06697
travis for check broken links
luotao1 Dec 19, 2016
706c572
Matrix API refactor, when passing parameters, convert shared_ptr (Mat…
Dec 16, 2016
4fbf949
Refactor MUL functions, pass object reference instead of shared_ptr.
Dec 20, 2016
4855821
Merge branch 'develop' into checker
luotao1 Dec 20, 2016
204152c
set -e for docs.sh
luotao1 Dec 20, 2016
8f08fa1
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wen-bo-yang Dec 20, 2016
bf26679
update docker_install_en.rst
wen-bo-yang Dec 20, 2016
6f8f468
Add priorbox layer gpu unit test.
Dec 20, 2016
5fddd99
move TEST from test_matrixCompare.cpp to cross_map_normal_op_test.cpp
hedaoyuan Dec 20, 2016
bf32411
Merge branch 'develop' of https://github.com/baidu/Paddle into cmrnorm
hedaoyuan Dec 20, 2016
f1a94e3
follow comments
hedaoyuan Dec 20, 2016
f4f0f2d
Fix bug in config_parse.py when batch_norm layer is used in Recurrent…
qingqing01 Dec 20, 2016
35bbb4f
change float to real in two test
Dec 20, 2016
dadd48a
Merge pull request #963 from reyoung/feature/add_const_in_parameter_u…
reyoung Dec 20, 2016
9049369
Merge pull request #934 from tianbingsz/paddle_function_mat
tianbingsz Dec 20, 2016
42e1217
Merge pull request #854 from hedaoyuan/cmrnorm
tianbingsz Dec 20, 2016
37f7595
Merge pull request #927 from wen-bo-yang/develop_test
wangkuiyi Dec 20, 2016
84ad724
Adding namespace in timing macros
Dec 21, 2016
5bb29ec
close log info in BN.
qingqing01 Dec 21, 2016
a6f772b
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
qingqing01 Dec 21, 2016
67fcd89
fix array style problem
Dec 21, 2016
5471e87
Merge branch 'develop' into checker
luotao1 Dec 21, 2016
de8927e
refine docs.sh
luotao1 Dec 21, 2016
f202929
Change type float to real.
Dec 21, 2016
1b8e151
Support user specified label input in tests
Dec 21, 2016
06ea2bf
Merge pull request #967 from pengli09/fix_test_type
pengli09 Dec 21, 2016
39a5477
refine docs.sh
luotao1 Dec 21, 2016
4e34220
Merge pull request #970 from reyoung/feature/clean_parameter_updater_…
reyoung Dec 21, 2016
e4c492d
change type to bool.
qingqing01 Dec 21, 2016
567871f
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
qingqing01 Dec 21, 2016
446e3c2
Merge pull request #946 from luotao1/checker
luotao1 Dec 21, 2016
8bd4752
Merge branch 'develop' into add_label_seq_pos_to_inputdef
Dec 21, 2016
1f4f044
A tiny fix in PyDataProvider2
reyoung Dec 21, 2016
bbf3b47
Merge pull request #966 from qingqing01/batch_norm
qingqing01 Dec 21, 2016
adc5839
Merge pull request #969 from reyoung/feature/clean_gradient_machine_s…
reyoung Dec 21, 2016
d09564b
change std::vector<int> to const reference
Dec 21, 2016
cf5bf5b
Merge branch 'feature/fix_param_hidden_in_pydp2' into feature/mnist_t…
reyoung Dec 21, 2016
28c5010
Merge pull request #976 from pengli09/add_label_seq_pos_to_inputdef
pengli09 Dec 21, 2016
22aacbf
Add const to GradientMachine::eval
reyoung Dec 21, 2016
4d81b36
A tiny fix in PyDataProvider2
reyoung Dec 21, 2016
4d5a0b0
Also add const to makeEvaluator
reyoung Dec 21, 2016
1e6c87b
Merge branch 'feature/add_const_in_gradient_machine_eval' into featur…
reyoung Dec 21, 2016
e8e58fb
add config_parser in trainer_config_helpers to seperate trainer config
jacquesqiao Dec 21, 2016
8d24931
Change member variables from public to protected
Dec 21, 2016
eaba2e2
Expose Evaluator API
reyoung Dec 21, 2016
409a577
Complete a very simple mnist demo.
reyoung Dec 21, 2016
06dc66b
Merge branch 'feature/fix_param_hidden_in_pydp2' into feature/mnist_t…
reyoung Dec 21, 2016
b53bdcd
Merge pull request #867 from Noplz/ssd
qingqing01 Dec 22, 2016
e031f0c
Fix typo in PyDataProvider2.py
Dec 22, 2016
9baf7fc
Fix data provider bug in srl demo
Dec 22, 2016
c1b294a
Merge pull request #974 from emailweixu/timer_namespace
backyes Dec 22, 2016
db82a0e
Merge pull request #980 from reyoung/feature/add_const_in_gradient_ma…
gangliao Dec 22, 2016
89bf2e4
Change float to real in NormLayer.h
Dec 22, 2016
680dd92
Add AverageOptimizer, Add save parameter
reyoung Dec 22, 2016
c6b2bfe
Merge pull request #986 from pengli09/fix-pydata-provider-doc-typo
pengli09 Dec 22, 2016
a7b5d94
Merge pull request #987 from pengli09/fix-srl-demo-data-provider-bug
pengli09 Dec 22, 2016
4f70880
Merge pull request #881 from livc/rnn
Zrachel Dec 22, 2016
5bca268
Add gitignore
reyoung Dec 22, 2016
4490bf9
Merge pull request #990 from pengli09/norm-layer
qingqing01 Dec 22, 2016
59009ba
Always use copy method for numpy.
reyoung Dec 22, 2016
a31ef0c
Merge branch 'feature/mnist_train_api' of github.com:reyoung/Paddle i…
reyoung Dec 22, 2016
f06b64f
Test GPU
reyoung Dec 22, 2016
65e957c
Merge branch 'feature/mnist_train_api' of github.com:reyoung/Paddle i…
reyoung Dec 22, 2016
5a68584
Test on GPU
reyoung Dec 22, 2016
16ea66e
Merge branch 'develop' of github.com:baidu/Paddle into feature/mnist_…
reyoung Dec 22, 2016
3a80272
Add comments.
reyoung Dec 22, 2016
87d4e60
add config_parser_utils
jacquesqiao Dec 22, 2016
7029247
add config_parser_utils
jacquesqiao Dec 22, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo paddle/scripts/travis/before_install.linux.sh; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then paddle/scripts/travis/before_install.osx.sh; fi
- if [[ "$JOB" == "PRE_COMMIT" ]]; then sudo ln -s /usr/bin/clang-format-3.8 /usr/bin/clang-format; fi
- pip install wheel protobuf sphinx recommonmark virtualenv numpy sphinx_rtd_theme pre-commit
- pip install wheel protobuf sphinx recommonmark virtualenv numpy sphinx_rtd_theme pre-commit requests==2.9.2 LinkChecker
script:
- paddle/scripts/travis/main.sh
notifications:
Expand Down
2 changes: 2 additions & 0 deletions cmake/util.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function(link_paddle_exe TARGET_NAME)
target_circle_link_libraries(${TARGET_NAME}
ARCHIVE_START
paddle_gserver
paddle_function
${METRIC_LIBS}
ARCHIVE_END
paddle_pserver
Expand All @@ -106,6 +107,7 @@ function(link_paddle_exe TARGET_NAME)
paddle_parameter
paddle_proto
paddle_cuda
paddle_test_main
${METRIC_LIBS}
${PROTOBUF_LIBRARY}
${LIBGLOG_LIBRARY}
Expand Down
1 change: 1 addition & 0 deletions demo/mnist/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ mnist_vgg_model
plot.png
train.log
*pyc
.ipynb_checkpoints
164 changes: 143 additions & 21 deletions demo/mnist/api_train.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,49 @@
"""
A very basic example for how to use current Raw SWIG API to train mnist network.

Current implementation uses Raw SWIG, which means the API call is directly \
passed to C++ side of Paddle.

The user api could be simpler and carefully designed.
"""
import py_paddle.swig_paddle as api
from py_paddle import DataProviderConverter
import paddle.trainer.PyDataProvider2 as dp
import paddle.trainer.config_parser
import numpy as np
import random
from mnist_util import read_from_mnist

import paddle.trainer_config_helpers.config_parser_utils as config_parser_utils
from paddle.trainer_config_helpers import *


def optimizer_config():
settings(
learning_rate=1e-4,
learning_method=AdamOptimizer(),
batch_size=1000,
model_average=ModelAverage(average_window=0.5),
regularization=L2Regularization(rate=0.5))


def network_config():
imgs = data_layer(name='pixel', size=784)
hidden1 = fc_layer(input=imgs, size=200)
hidden2 = fc_layer(input=hidden1, size=200)
inference = fc_layer(input=hidden2, size=10, act=SoftmaxActivation())
cost = classification_cost(
input=inference, label=data_layer(
name='label', size=10))
outputs(cost)


def init_parameter(network):
assert isinstance(network, api.GradientMachine)
for each_param in network.getParameters():
assert isinstance(each_param, api.Parameter)
array = each_param.getBuf(api.PARAMETER_VALUE).toNumpyArrayInplace()
assert isinstance(array, np.ndarray)
for i in xrange(len(array)):
array[i] = np.random.uniform(-1.0, 1.0)
array_size = len(each_param)
array = np.random.uniform(-1.0, 1.0, array_size).astype('float32')
each_param.getBuf(api.PARAMETER_VALUE).copyFromNumpyArray(array)


def generator_to_batch(generator, batch_size):
Expand All @@ -27,56 +57,148 @@ def generator_to_batch(generator, batch_size):
yield ret_val


class BatchPool(object):
def __init__(self, generator, batch_size):
self.data = list(generator)
self.batch_size = batch_size

def __call__(self):
random.shuffle(self.data)
for offset in xrange(0, len(self.data), self.batch_size):
limit = min(offset + self.batch_size, len(self.data))
yield self.data[offset:limit]


def input_order_converter(generator):
for each_item in generator:
yield each_item['pixel'], each_item['label']


def main():
api.initPaddle("-use_gpu=false", "-trainer_count=4") # use 4 cpu cores
config = paddle.trainer.config_parser.parse_config(
'simple_mnist_network.py', '')

opt_config = api.OptimizationConfig.createFromProto(config.opt_config)
# get enable_types for each optimizer.
# enable_types = [value, gradient, momentum, etc]
# For each optimizer(SGD, Adam), GradientMachine should enable different
# buffers.
opt_config_proto = config_parser_utils.parse_optimizer_config(
optimizer_config)
opt_config = api.OptimizationConfig.createFromProto(opt_config_proto)
_temp_optimizer_ = api.ParameterOptimizer.create(opt_config)
enable_types = _temp_optimizer_.getParameterTypes()

# Create Simple Gradient Machine.
model_config = config_parser_utils.parse_network_config(network_config)
m = api.GradientMachine.createFromConfigProto(
config.model_config, api.CREATE_MODE_NORMAL, enable_types)
model_config, api.CREATE_MODE_NORMAL, enable_types)

# This type check is not useful. Only enable type hint in IDE.
# Such as PyCharm
assert isinstance(m, api.GradientMachine)

# Initialize Parameter by numpy.
init_parameter(network=m)

# Create Local Updater. Local means not run in cluster.
# For a cluster training, here we can change to createRemoteUpdater
# in future.
updater = api.ParameterUpdater.createLocalUpdater(opt_config)
assert isinstance(updater, api.ParameterUpdater)

# Initialize ParameterUpdater.
updater.init(m)

# DataProvider Converter is a utility convert Python Object to Paddle C++
# Input. The input format is as same as Paddle's DataProvider.
converter = DataProviderConverter(
input_types=[dp.dense_vector(784), dp.integer_value(10)])

train_file = './data/raw_data/train'
test_file = './data/raw_data/t10k'

# start gradient machine.
# the gradient machine must be started before invoke forward/backward.
# not just for training, but also for inference.
m.start()

for _ in xrange(100):
# evaluator can print error rate, etc. It is a C++ class.
batch_evaluator = m.makeEvaluator()
test_evaluator = m.makeEvaluator()

# Get Train Data.
# TrainData will stored in a data pool. Currently implementation is not care
# about memory, speed. Just a very naive implementation.
train_data_generator = input_order_converter(read_from_mnist(train_file))
train_data = BatchPool(train_data_generator, 512)

# outArgs is Neural Network forward result. Here is not useful, just passed
# to gradient_machine.forward
outArgs = api.Arguments.createArguments(0)

for pass_id in xrange(2): # we train 2 passes.
updater.startPass()
outArgs = api.Arguments.createArguments(0)
train_data_generator = input_order_converter(
read_from_mnist(train_file))
for batch_id, data_batch in enumerate(
generator_to_batch(train_data_generator, 256)):
trainRole = updater.startBatch(len(data_batch))

def update_callback(param):
updater.update(param)
for batch_id, data_batch in enumerate(train_data()):
# data_batch is input images.
# here, for online learning, we could get data_batch from network.

# Start update one batch.
pass_type = updater.startBatch(len(data_batch))

m.forwardBackward(
converter(data_batch), outArgs, trainRole, update_callback)
# Start BatchEvaluator.
# batch_evaluator can be used between start/finish.
batch_evaluator.start()

# forwardBackward is a shortcut for forward and backward.
# It is sometimes faster than invoke forward/backward separately,
# because in GradientMachine, it may be async.
m.forwardBackward(converter(data_batch), outArgs, pass_type)

for each_param in m.getParameters():
updater.update(each_param)

# Get cost. We use numpy to calculate total cost for this batch.
cost_vec = outArgs.getSlotValue(0)
cost_vec = cost_vec.copyToNumpyMat()
cost = cost_vec.sum() / len(data_batch)
print 'Batch id', batch_id, 'with cost=', cost

# Make evaluator works.
m.eval(batch_evaluator)

# Print logs.
print 'Pass id', pass_id, 'Batch id', batch_id, 'with cost=', \
cost, batch_evaluator

batch_evaluator.finish()
# Finish batch.
# * will clear gradient.
# * ensure all values should be updated.
updater.finishBatch(cost)

# testing stage. use test data set to test current network.
updater.apply()
test_evaluator.start()
test_data_generator = input_order_converter(read_from_mnist(test_file))
for data_batch in generator_to_batch(test_data_generator, 512):
# in testing stage, only forward is needed.
m.forward(converter(data_batch), outArgs, api.PASS_TEST)
m.eval(test_evaluator)

# print error rate for test data set
print 'Pass', pass_id, ' test evaluator: ', test_evaluator
test_evaluator.finish()
updater.restore()

updater.catchUpWith()
params = m.getParameters()
for each_param in params:
assert isinstance(each_param, api.Parameter)
value = each_param.getBuf(api.PARAMETER_VALUE)
value = value.copyToNumpyArray()

# Here, we could save parameter to every where you want
print each_param.getName(), value

updater.finishPass()

m.finish()
Expand Down
16 changes: 0 additions & 16 deletions demo/mnist/simple_mnist_network.py

This file was deleted.

2 changes: 1 addition & 1 deletion demo/semantic_role_labeling/dataprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_batch_size(yeild_data):
init_hook=hook,
should_shuffle=True,
calc_batch_size=get_batch_size,
can_over_batch_size=False,
can_over_batch_size=True,
cache=CacheType.CACHE_PASS_IN_MEM)
def process(settings, file_name):
with open(file_name, 'r') as fdata:
Expand Down
10 changes: 9 additions & 1 deletion doc/getstarted/build_and_install/docker_install_en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ The general development workflow with Docker and Bazel is as follows:
code. This image contains all the development tools and
dependencies of PaddlePaddle.


.. code-block:: bash

cd paddle
docker build -t paddle:dev -f paddle/scripts/docker/Dockerfile .

Sometimes docker build might suffer from a slow network connection to the official Ubuntu apt-source servers. In such case, we can specify an apt-source mirror server that is geologically nearer to us. In the following example, we specified an apt-source server that responds fast in China.You can specify the UBUNTU MIRROR with :code:`--build-arg UBUNTU_MIRROR` like the example below.

.. code-block:: bash

docker build \
--build-arg UBUNTU_MIRROR="http://mirrors.163.com" \
-t paddle:dev \
-f paddle/scripts/docker/Dockerfile .


3. Run the image as a container and mounting local source code
directory into the container. This allows us to change the code on
Expand Down
Loading