You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by wa...@apache.org on 2016/08/17 18:02:48 UTC
[27/51] [abbrv] incubator-singa git commit: Merge commits for
updating layer identifers and commits for updating the installation page.
Merge commits for updating layer identifers and commits for updating the installation page.
Conflicts:
examples/cifar10/vgg.py
src/python/singa/device.py
src/python/singa/layer.py
src/python/singa/optimizer.py
src/python/singa/tensor.py
test/CMakeLists.txt
Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/5db7eb61
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/5db7eb61
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/5db7eb61
Branch: refs/heads/master
Commit: 5db7eb61ed1e5e189aad9c4b02f85cae6fa23df9
Parents: 2c049d6 9c71bd6
Author: Wei Wang <wa...@comp.nus.edu.sg>
Authored: Mon Aug 15 20:04:54 2016 +0800
Committer: Wei Wang <wa...@comp.nus.edu.sg>
Committed: Mon Aug 15 20:04:54 2016 +0800
----------------------------------------------------------------------
CMakeLists.txt | 9 +-
cmake/Dependencies.cmake | 7 ++
cmake/Thirdparty/FindCUDNN.cmake | 2 +-
examples/char-rnn/train.py | 2 +-
examples/cifar10/alexnet.cc | 2 +-
examples/cifar10/alexnet.py | 2 +-
examples/cifar10/train.py | 2 +-
examples/cifar10/vgg-parallel.cc | 1 +
examples/cifar10/vgg.py | 18 ++--
examples/imagenet/alexnet.cc | 50 ++++++-----
examples/mnist/README.md | 18 ++++
examples/mnist/train.py | 134 ++++++++++++++++++++++++++++++
include/singa/core/device.h | 15 ++--
include/singa/core/tensor.h | 19 +++++
include/singa/model/layer.h | 13 ++-
include/singa/model/loss.h | 1 -
src/CMakeLists.txt | 10 +--
src/core/device/cpp_cpu.cc | 2 +-
src/core/tensor/math_kernel.cu | 53 +++++++++++-
src/core/tensor/math_kernel.h | 14 +++-
src/core/tensor/tensor.cc | 15 +++-
src/core/tensor/tensor_math.h | 24 ++++++
src/core/tensor/tensor_math_cpp.h | 42 ++++++++++
src/core/tensor/tensor_math_cuda.h | 40 ++++++++-
src/model/layer/activation.cc | 10 +++
src/model/layer/batchnorm.cc | 3 +
src/model/layer/convolution.cc | 1 +
src/model/layer/cudnn_batchnorm.cc | 16 ++--
src/model/layer/dense.cc | 3 +
src/model/layer/dropout.cc | 3 +
src/model/layer/flatten.cc | 3 +
src/model/layer/lrn.cc | 3 +
src/model/layer/pooling.cc | 1 +
src/model/layer/prelu.cc | 3 +
src/model/layer/rnn.cc | 3 +
src/model/layer/softmax.cc | 3 +
src/python/singa/device.py | 5 +-
src/python/singa/layer.py | 28 ++++---
src/python/singa/optimizer.py | 63 ++++++++------
src/python/singa/tensor.py | 45 +++++++---
src/python/swig/core_device.i | 4 +-
src/python/swig/core_tensor.i | 10 +++
test/CMakeLists.txt | 1 -
test/python/test_layer.py | 11 +--
test/singa/test_cpp_cpu.cc | 2 +-
test/singa/test_cudnn_batchnorm.cc | 22 ++---
test/singa/test_image_transformer.cc | 20 ++---
test/singa/test_layer.cc | 2 +-
48 files changed, 602 insertions(+), 158 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/5db7eb61/src/python/singa/device.py
----------------------------------------------------------------------
diff --cc src/python/singa/device.py
index eff6783,897fdf5..65824c2
--- a/src/python/singa/device.py
+++ b/src/python/singa/device.py
@@@ -113,7 -113,7 +113,10 @@@ def create_cuda_gpu_on(device_id)
devices = create_cuda_gpus_on([device_id])
return devices[0]
+
+ default_device = singa.Platform.GetDefaultDevice()
++
++
def get_default_device():
'''Get the default host device which is a CppCPU device'''
- return singa.Platform.GetDefaultDevice()
+ return default_device
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/5db7eb61/src/python/singa/optimizer.py
----------------------------------------------------------------------
diff --cc src/python/singa/optimizer.py
index 7c8cc39,86e68af..14cf3c0
--- a/src/python/singa/optimizer.py
+++ b/src/python/singa/optimizer.py
@@@ -54,8 -54,8 +54,8 @@@ class Optimizer(object)
lr (float): a constant for the learning rate, mutually exclusive with
'lr_gen'.
momentum (float): a constant for the momentum value
- decay (float): the coefficent for L2 regularizer, which is mutually
- weight_decay (float): the coefficent for L2 regularizer, which is mutually
-- exclusive with 'regularizer'.
++ weight_decay (float): the coefficent for L2 regularizer, which is
++ mutually exclusive with 'regularizer'.
lr_gen (function): a function returns the learning rate given
the current training step/epoch. It is mutually exclusive with lr.
If both are not set, the apply_with_lr function should be used for
@@@ -67,7 -67,7 +67,8 @@@
constraint would be applied inside apply_with_lr(). Users can
also do regularization outside.
'''
- def __init__(self, lr=None, momentum=None, decay=None, lr_gen=None,
++
+ def __init__(self, lr=None, momentum=None, weight_decay=None, lr_gen=None,
regularizer=None, constraint=None):
if lr is not None:
assert lr_gen is None, 'Cannot set lr and lr_gen at the same time'
@@@ -108,11 -108,14 +109,14 @@@
name (str): parameter name
specs (ParamSpec): protobuf obj, including regularizer and
constraint, multipliers for learning rate and weight decay.
+
'''
- assert type(specs) == model_pb2.ParamSpec, \
- 'specs should be model_pb2.ParamSpec instance'
++ assert isinstance(specs, model_pb2.ParamSpec), \
++ 'specs should be model_pb2.ParamSpec instance'
if specs.HasField('regularizer'):
- self.regularizers[name] = CppRegularizer(specs.constraint)
+ self.regularizers[name] = CppRegularizer(specs.regularizer)
if specs.HasField('constraint'):
- self.constraints[name] = CppConstraint(specs.regularizer)
+ self.constraints[name] = CppConstraint(specs.constraint)
if specs.lr_mult != 1:
self.learning_rate_multiplier[name] = specs.lr_mult
if specs.decay_mult != 1:
@@@ -190,12 -193,13 +194,20 @@@ class SGD(Optimizer)
See the base Optimizer for all arguments.
'''
- def __init__(self, lr=None, momentum=None, decay=None, lr_gen=None,
+ def __init__(self, lr=None, momentum=None, weight_decay=None, lr_gen=None,
regularizer=None, constraint=None):
- super(SGD, self).__init__(lr, momentum, decay, lr_gen, regularizer,
- super(SGD, self).__init__(lr, momentum, weight_decay, lr_gen, regularizer,
-- constraint)
++ super(
++ SGD,
++ self).__init__(
++ lr,
++ momentum,
++ weight_decay,
++ lr_gen,
++ regularizer,
++ constraint)
conf = model_pb2.OptimizerConf()
- conf.momentum = self.momentum
+ if self.momentum is not None:
+ conf.momentum = self.momentum
conf.type = 'sgd'
self.opt = singa.CreateOptimizer('SGD')
self.opt.Setup(conf.SerializeToString())
@@@ -212,12 -216,13 +224,13 @@@ class Nesterov(Optimizer)
See the base Optimizer for all arguments.
'''
- def __init__(self, lr=None, momentum=0.9, decay=None, lr_gen=None,
+ def __init__(self, lr=None, momentum=0.9, weight_decay=None, lr_gen=None,
regularizer=None, constraint=None):
- super(Nesterov, self).__init__(lr, momentum, decay, lr_gen, regularizer,
- super(Nesterov, self).__init__(lr, momentum, weight_decay, lr_gen, regularizer,
-- constraint)
++ super(Nesterov, self).__init__(lr, momentum, weight_decay, lr_gen,
++ regularizer, constraint)
conf = model_pb2.OptimizerConf()
- conf.momentum = momentum
+ if self.momentum is not None:
+ conf.momentum = momentum
conf.type = 'nesterov'
self.opt = singa.CreateOptimizer('Nesterov')
self.opt.Setup(conf.SerializeToString())
@@@ -236,9 -241,9 +249,10 @@@ class AdaGrad(Optimizer)
Args:
epsilon (float): small number for preventing numeric error.
'''
- def __init__(self, epsilon=1e-8, lr=None, decay=None, lr_gen=None,
++
+ def __init__(self, epsilon=1e-8, lr=None, weight_decay=None, lr_gen=None,
regularizer=None, constraint=None):
- super(RMSProp, self).__init__(lr, decay, lr_gen, regularizer,
+ super(RMSProp, self).__init__(lr, weight_decay, lr_gen, regularizer,
constraint)
conf = model_pb2.OptimizerConf()
conf.delta = epsilon
@@@ -262,9 -267,9 +276,9 @@@ class RMSProp(Optimizer)
epsilon (float): small value for preventing numeric error
'''
- def __init__(self, rho=0.9, epsilon=1e-8, lr=None, decay=None, lr_gen=None,
- def __init__(self, rho=0.9, epsilon=1e-8, lr=None, weight_decay=None, lr_gen=None,
-- regularizer=None, constraint=None):
- super(RMSProp, self).__init__(lr, decay, lr_gen, regularizer,
++ def __init__(self, rho=0.9, epsilon=1e-8, lr=None, weight_decay=None,
++ lr_gen=None, regularizer=None, constraint=None):
+ super(RMSProp, self).__init__(lr, weight_decay, lr_gen, regularizer,
constraint)
conf = model_pb2.OptimizerConf()
conf.rho = rho
@@@ -333,6 -338,6 +347,7 @@@ class CppConstraint(Constraint)
Args:
conf (ConstraintConf): protobuf message for the configuration.
'''
++
def __init__(self, conf):
self.constraint = singa.CreateConstraint(conf.type)
self.constraint.Setup(conf.SerializeToString())
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/5db7eb61/src/python/singa/tensor.py
----------------------------------------------------------------------
diff --cc src/python/singa/tensor.py
index 2e60554,5086fdc..6641a71
--- a/src/python/singa/tensor.py
+++ b/src/python/singa/tensor.py
@@@ -206,7 -207,7 +207,7 @@@ class Tensor(object)
Args:
t (Tensor): source Tensor.
'''
-- assert type(t) == Tensor, 't must be a singa Tensor instance'
++ assert isinstance(t, Tensor), 't must be a singa Tensor instance'
self.singa_tensor.CopyData(t.singa_tensor)
def clone(self):
@@@ -404,16 -403,28 +403,38 @@@
self.singa_tensor, rhs)
def __lt__(self, rhs):
- return _call_singa_func(singa.LT_Tf, self.singa_tensor, rhs)
+ if isinstance(rhs, Tensor):
- return _call_singa_func(singa.LT_TT, self.singa_tensor, rhs.singa_tensor)
++ return _call_singa_func(singa.LT_TT, self.singa_tensor,
++ rhs.singa_tensor)
+ else:
+ return _call_singa_func(singa.LT_Tf, self.singa_tensor, rhs)
def __le__(self, rhs):
- return _call_singa_func(singa.LE_Tf, self.singa_tensor, rhs)
+ if isinstance(rhs, Tensor):
- return _call_singa_func(singa.LE_TT, self.singa_tensor, rhs.singa_tensor)
++ return _call_singa_func(
++ singa.LE_TT,
++ self.singa_tensor,
++ rhs.singa_tensor)
+ else:
+ return _call_singa_func(singa.LE_Tf, self.singa_tensor, rhs)
def __gt__(self, rhs):
- return _call_singa_func(singa.GT_Tf, self.singa_tensor, rhs)
+ if isinstance(rhs, Tensor):
- return _call_singa_func(singa.GT_TT, self.singa_tensor, rhs.singa_tensor)
++ return _call_singa_func(
++ singa.GT_TT,
++ self.singa_tensor,
++ rhs.singa_tensor)
+ else:
+ return _call_singa_func(singa.GT_Tf, self.singa_tensor, rhs)
def __ge__(self, rhs):
- return _call_singa_func(singa.GE_Tf, self.singa_tensor, rhs)
+ if isinstance(rhs, Tensor):
- return _call_singa_func(singa.GE_TT, self.singa_tensor, rhs.singa_tensor)
++ return _call_singa_func(
++ singa.GE_TT,
++ self.singa_tensor,
++ rhs.singa_tensor)
+ else:
+ return _call_singa_func(singa.GE_Tf, self.singa_tensor, rhs)
''' python functions for global functions in Tensor.h
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/5db7eb61/test/CMakeLists.txt
----------------------------------------------------------------------
diff --cc test/CMakeLists.txt
index 6e7dd84,6fc4d77..6c21034
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@@ -22,9 -22,5 +22,8 @@@ ADD_EXECUTABLE(test_singa "gtest/gtest_
ADD_DEPENDENCIES(test_singa singa_core singa_utils)
#MESSAGE(STATUS "link libs" ${singa_linker_libs})
TARGET_LINK_LIBRARIES(test_singa gtest singa_core singa_utils singa_model
- singa_io singa_proto protobuf ${SINGA_LINKER_LIBS})
-SET_TARGET_PROPERTIES(test_singa PROPERTIES LINK_FLAGS "${LINK_FLAGS} -pthread")
+ singa_io proto protobuf ${SINGA_LINKER_LIBS})
+IF(UNIX AND (NOT APPLE))
+ LIST(APPEND LINK_FLAGS "-pthread")
+ENDIF()
+SET_TARGET_PROPERTIES(test_singa PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
-