You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by ka...@apache.org on 2017/04/11 12:04:39 UTC

[1/3] incubator-singa git commit: SINGA-311 Add unittest for Adam updater

Repository: incubator-singa
Updated Branches:
  refs/heads/master 38da78914 -> b35e03f6f


SINGA-311 Add unittest for Adam updater

fix a bug in Adam optimizer about the step counting
add python unittest for Adam in test_optimzier.py


Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/4fd44ed2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/4fd44ed2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/4fd44ed2

Branch: refs/heads/master
Commit: 4fd44ed28309fa54c720cbd5783244fda645b7c4
Parents: 85dbad7
Author: wangwei <wa...@comp.nus.edu.sg>
Authored: Tue Apr 11 18:21:15 2017 +0800
Committer: wangwei <wa...@comp.nus.edu.sg>
Committed: Tue Apr 11 18:21:15 2017 +0800

----------------------------------------------------------------------
 python/singa/optimizer.py     |  8 +++++---
 test/python/test_optimizer.py | 42 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/4fd44ed2/python/singa/optimizer.py
----------------------------------------------------------------------
diff --git a/python/singa/optimizer.py b/python/singa/optimizer.py
index 164921f..614fe6d 100644
--- a/python/singa/optimizer.py
+++ b/python/singa/optimizer.py
@@ -323,9 +323,9 @@ class Adam(Optimizer):
         self.epsilon = epsilon
         self.m = {}
         self.v = {}
-        self.t = 1
-        self.last_epoch = 0
-        self.last_step = 0
+        self.t = 0
+        self.last_epoch = -1
+        self.last_step = -1
 
     def apply_with_lr(self, epoch, lr, grad, value, name, step):
         '''Update one parameter object.
@@ -339,6 +339,8 @@ class Adam(Optimizer):
         assert step != -1, 'step should >= 0'
         if epoch != self.last_epoch or step != self.last_step:
             self.t += 1
+            self.last_step = step
+            self.last_epoch = epoch
         grad = self.apply_regularizer_constraint(epoch, value, grad, name, step)
         if name is not None and name in self.learning_rate_multiplier:
             lr = lr * self.learning_rate_multiplier[name]

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/4fd44ed2/test/python/test_optimizer.py
----------------------------------------------------------------------
diff --git a/test/python/test_optimizer.py b/test/python/test_optimizer.py
index 601aada..cfd13c0 100644
--- a/test/python/test_optimizer.py
+++ b/test/python/test_optimizer.py
@@ -16,6 +16,7 @@
 # under the License.
 # =============================================================================
 import unittest
+import math
 import numpy as np
 
 
@@ -28,6 +29,16 @@ if singa_wrap.USE_CUDA:
     cuda = device.create_cuda_gpu()
 
 
+def np_adam(plist, glist, mlist, vlist, lr, t, b1=0.9, b2=0.999):
+    for p, g, m, v in zip(plist, glist, mlist, vlist):
+        m *=b1
+        m += (1-b1) * g
+        v *= b2
+        v += (1-b2) * g * g
+        alpha = lr * math.sqrt(1. - math.pow(b2, t)) / (1. - math.pow(b1, t))
+        p -= alpha * m / (np.sqrt(v) + 1e-8)
+
+
 class TestOptimizer(unittest.TestCase):
 
     def setUp(self):
@@ -48,6 +59,37 @@ class TestOptimizer(unittest.TestCase):
         for i in range(self.W.size()):
             self.assertAlmostEqual(w[i], self.np_W[i] - lr * self.np_g[i])
 
+    def test_adam(self):
+        lr = 0.1
+        n, m = 4, 6
+        p1 = np.random.rand(n, m)
+        p2 = np.random.rand(n, m)
+        g1 = np.random.rand(n, m) * 0.01
+        g2 = np.random.rand(n, m) * 0.01
+        m1 = np.zeros((n, m))
+        m2 = np.zeros((n, m))
+        v1 = np.zeros((n, m))
+        v2 = np.zeros((n, m))
+        t1 = tensor.from_numpy(p1)
+        t2 = tensor.from_numpy(p2)
+        tg1 = tensor.from_numpy(g1)
+        tg2 = tensor.from_numpy(g2)
+
+        for t in range(1, 10):
+            np_adam([p1, p2], [g1, g2], [m1, m2], [v1, v2], lr, t)
+
+        adam = opt.Adam(lr=lr)
+        for t in range(1, 10):
+            adam.apply(0, tg1, t1, 'p1', t)
+            adam.apply(0, tg2, t2, 'p2', t)
+
+        t1 = tensor.to_numpy(t1)
+        t2 = tensor.to_numpy(t2)
+        for t, p in zip([t1, t2], [p1, p2]):
+            for i in range(n):
+                for j in range(m):
+                    self.assertAlmostEqual(t[i, j], p[i, j], 6)
+
     @unittest.skipIf(not singa_wrap.USE_CUDA, 'CUDA is not enabled')
     def test_sgd_cuda(self):
         lr = 0.1


[3/3] incubator-singa git commit: Merge PR #319

Posted by ka...@apache.org.
Merge PR #319


Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/b35e03f6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/b35e03f6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/b35e03f6

Branch: refs/heads/master
Commit: b35e03f6f6ea8fa529c8c9ce25ae426b9e14e2b7
Parents: 38da789 f5cb70c
Author: kaiping <ka...@comp.nus.edu.sg>
Authored: Tue Apr 11 19:51:54 2017 +0800
Committer: kaiping <ka...@comp.nus.edu.sg>
Committed: Tue Apr 11 19:51:54 2017 +0800

----------------------------------------------------------------------
 python/singa/optimizer.py                       |  8 ++-
 test/python/test_optimizer.py                   | 42 ++++++++++++
 tool/conda/build.sh                             |  2 +
 tool/conda/meta.yaml                            |  6 +-
 tool/jenkins/README.md                          |  1 +
 tool/jenkins/docker/devel/Dockerfile            | 67 --------------------
 tool/jenkins/docker/devel/centos6/Dockerfile    | 64 +++++++++++++++++++
 .../jenkins/docker/devel/ubuntu14.04/Dockerfile | 67 ++++++++++++++++++++
 8 files changed, 186 insertions(+), 71 deletions(-)
----------------------------------------------------------------------



[2/3] incubator-singa git commit: SINGA-310 Create conda packages on CentOS

Posted by ka...@apache.org.
SINGA-310 Create conda packages on CentOS

Add dockerfile for centos6 which is used to create conda package for old linux systems whose glibc is 2.14
Add gcc and libgcc as requirements for linux (not osx).

Add include and library path in conda build.sh for cudnn header and library

update readme and repo link in meta.yml


Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/f5cb70c2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/f5cb70c2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/f5cb70c2

Branch: refs/heads/master
Commit: f5cb70c21327a7abdf07986c067730b6284ee0fc
Parents: 4fd44ed
Author: Wei Wang <wa...@comp.nus.edu.sg>
Authored: Tue Apr 11 14:22:47 2017 +0800
Committer: wangwei <wa...@comp.nus.edu.sg>
Committed: Tue Apr 11 18:22:46 2017 +0800

----------------------------------------------------------------------
 tool/conda/build.sh                             |  2 +
 tool/conda/meta.yaml                            |  6 +-
 tool/jenkins/README.md                          |  1 +
 tool/jenkins/docker/devel/Dockerfile            | 67 --------------------
 tool/jenkins/docker/devel/centos6/Dockerfile    | 64 +++++++++++++++++++
 .../jenkins/docker/devel/ubuntu14.04/Dockerfile | 67 ++++++++++++++++++++
 6 files changed, 139 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/f5cb70c2/tool/conda/build.sh
----------------------------------------------------------------------
diff --git a/tool/conda/build.sh b/tool/conda/build.sh
index 926da71..2716452 100644
--- a/tool/conda/build.sh
+++ b/tool/conda/build.sh
@@ -20,6 +20,8 @@ export export CPLUS_INCLUDE_PATH=`python -c "import numpy; print numpy.get_inclu
 
 # to let cmake use the dependent libs installed by conda, including python
 export CMAKE_PREFIX_PATH=$PREFIX
+export CMAKE_INCLUDE_PATH=$SINGA_INCLUDE_PATH
+export CMAKE_LIBRARY_PATH=$SINGA_LIBRARY_PATH
 
 mkdir build
 cd build

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/f5cb70c2/tool/conda/meta.yaml
----------------------------------------------------------------------
diff --git a/tool/conda/meta.yaml b/tool/conda/meta.yaml
index a322f3a..67aeec7 100644
--- a/tool/conda/meta.yaml
+++ b/tool/conda/meta.yaml
@@ -3,13 +3,15 @@ package:
   version: "{{ GIT_DESCRIBE_TAG }}"
 
 source:
-  git_url: https://github.com/nusdbsystem/singa-osx.git
+  git_url: https://github.com/apache/incubator-singa.git
 
 
 build:
   number: {{ GIT_DESCRIBE_NUMBER }}
   script_env:
     - CONDA_BLD_PATH
+    - SINGA_INCLUDE_PATH
+    - SINGA_LIBRARY_PATH
 
 requirements:
   build:
@@ -19,6 +21,7 @@ requirements:
     - openblas >=0.2.10
     - protobuf 3.0.0
     - glog 0.3.4
+    - gcc 4.8.5 # [linux]
 
   run:
     - python 2.7*
@@ -29,6 +32,7 @@ requirements:
     - flask >=0.10.1
     - flask-cors >=3.0.2
     - pillow >=2.3.0
+    - libgcc 4.8.5 # [linux]
 
 test:
   source_files:

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/f5cb70c2/tool/jenkins/README.md
----------------------------------------------------------------------
diff --git a/tool/jenkins/README.md b/tool/jenkins/README.md
index 9a76ee8..b734b8f 100644
--- a/tool/jenkins/README.md
+++ b/tool/jenkins/README.md
@@ -28,6 +28,7 @@ Each node should configure the following environment variable
 3. ANACONDA_UPLOAD_TOKEN
 4. SINGA_NAME=singa-cuda${CUDA_VERSION}-cudnn${CUDNN_VERSION}
 5. OS_VERSION, e.g., ubuntu14.04
+6. SINGA_INCLUDE_PATH and SINGA_LIBRARY_PATH for the cudnn.h and libcudnn.so folder respectively
 
 ### General
   * Discard old builds - Max # of builds to keep - 50

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/f5cb70c2/tool/jenkins/docker/devel/Dockerfile
----------------------------------------------------------------------
diff --git a/tool/jenkins/docker/devel/Dockerfile b/tool/jenkins/docker/devel/Dockerfile
deleted file mode 100644
index 2ef191b..0000000
--- a/tool/jenkins/docker/devel/Dockerfile
+++ /dev/null
@@ -1,67 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# Base unbuntu 14.04 image from nvidia/cuda
-# Change tags to build with different cuda/cudnn versions:
-#   FROM nvidia/cuda:8.0-cudnn5-devel-ubuntu14.04
-#   FROM nvidia/cuda:7.5-cudnn5-devel-ubuntu14.04
-#   FROM nvidia/cuda:7.5-cudnn4-devel-ubuntu14.04
-#   FROM nvidia/cuda:7.0-cudnn4-devel-ubuntu14.04
-FROM nvidia/cuda:7.5-cudnn5-devel-ubuntu14.04
-
-# install dependencies
-RUN apt-get update \
-    && apt-get install -y --no-install-recommends git build-essential autoconf libtool cmake libprotobuf-dev libopenblas-dev libpcre3-dev python-dev python-pip protobuf-compiler wget openssh-server \
-    && apt-get clean && apt-get autoremove && apt-get autoclean \
-    && rm -rf /var/lib/apt/lists/* \
-    && pip install -U pip wheel numpy setuptools unittest-xml-reporting protobuf
-
-
-# install swig 3.0
-RUN wget http://prdownloads.sourceforge.net/swig/swig-3.0.10.tar.gz && \
-    tar zxf swig-3.0.10.tar.gz && cd swig-3.0.10 && \
-    ./configure && make && make install
-
-# install conda, conda-build and anaconda-client
-RUN wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh;
-RUN bash miniconda.sh -b -p $HOME/miniconda
-RUN $HOME/miniconda/bin/conda config --set always_yes yes --set changeps1 no
-RUN $HOME/miniconda/bin/conda update -q conda
-RUN $HOME/miniconda/bin/conda install conda-build
-RUN $HOME/miniconda/bin/conda install anaconda-client
-ENV PATH $HOME/miniconda/bin:${PATH}
-
-# set environment
-ENV CPLUS_INCLUDE_PATH /usr/local/lib/python2.7/dist-packages/numpy/core/include:${CPLUS_INCLUDE_PATH}
-# ENV CMAKE_INCLUDE_PATH /usr/local/cuda/include:${CMAKE_INCLUDE_PATH}
-# ENV CMAKE_LIBRARY_PATH /usr/local/cuda/lib64:${CMAKE_LIBRARY_PATH}
-
-# download singa source
-# RUN git clone https://github.com/apache/incubator-singa.git
-
-# config ssh service
-RUN mkdir /var/run/sshd
-RUN echo 'root:singa' | chpasswd
-RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
-# SSH login fix. Otherwise user is kicked off after login
-RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
-
-# dump environment variables into files, so that ssh can see also
-RUN env | grep _ >> /etc/environment
-
-EXPOSE 22
-
-CMD ["/usr/sbin/sshd", "-D"]

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/f5cb70c2/tool/jenkins/docker/devel/centos6/Dockerfile
----------------------------------------------------------------------
diff --git a/tool/jenkins/docker/devel/centos6/Dockerfile b/tool/jenkins/docker/devel/centos6/Dockerfile
new file mode 100644
index 0000000..61b30f6
--- /dev/null
+++ b/tool/jenkins/docker/devel/centos6/Dockerfile
@@ -0,0 +1,64 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Base unbuntu 14.04 image from nvidia/cuda
+# Change tags to build with different cuda/cudnn versions:
+#   FROM nvidia/cuda:8.0-cudnn5-devel-ubuntu14.04
+#   FROM nvidia/cuda:7.5-cudnn5-devel-ubuntu14.04
+#   FROM nvidia/cuda:7.5-cudnn4-devel-ubuntu14.04
+#   FROM nvidia/cuda:7.0-cudnn4-devel-ubuntu14.04
+FROM nvidia/cuda:7.5-cudnn5-devel-centos6
+
+# install dependencies
+RUN yum -y update && yum -y install git wget openssh-server cmake
+
+
+# install conda, conda-build and anaconda-client
+RUN wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh;
+RUN bash miniconda.sh -b -p /root/miniconda
+ENV PATH /root/miniconda/bin:${PATH}
+RUN /root/miniconda/bin/conda config --set always_yes yes --set changeps1 no
+RUN /root/miniconda/bin/conda update -q conda
+RUN /root/miniconda/bin/conda install conda-build
+RUN /root/miniconda/bin/conda install anaconda-client
+
+# set environment
+ENV CPLUS_INCLUDE_PATH /usr/local/lib/python2.7/dist-packages/numpy/core/include:${CPLUS_INCLUDE_PATH}
+# ENV CMAKE_INCLUDE_PATH /usr/local/cuda/include:${CMAKE_INCLUDE_PATH}
+# ENV CMAKE_LIBRARY_PATH /usr/local/cuda/lib64:${CMAKE_LIBRARY_PATH}
+
+# download singa source
+# RUN git clone https://github.com/apache/incubator-singa.git
+
+# config ssh service
+RUN mkdir /var/run/sshd
+RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
+RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
+
+RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
+RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config
+RUN echo 'root:singa' | chpasswd
+
+#RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
+# SSH login fix. Otherwise user is kicked off after login
+#RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
+
+# dump environment variables into files, so that ssh can see also
+RUN env | grep _ >> /etc/environment
+
+EXPOSE 22
+
+CMD ["/usr/sbin/sshd", "-D"]

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/f5cb70c2/tool/jenkins/docker/devel/ubuntu14.04/Dockerfile
----------------------------------------------------------------------
diff --git a/tool/jenkins/docker/devel/ubuntu14.04/Dockerfile b/tool/jenkins/docker/devel/ubuntu14.04/Dockerfile
new file mode 100644
index 0000000..f907e07
--- /dev/null
+++ b/tool/jenkins/docker/devel/ubuntu14.04/Dockerfile
@@ -0,0 +1,67 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Base unbuntu 14.04 image from nvidia/cuda
+# Change tags to build with different cuda/cudnn versions:
+#   FROM nvidia/cuda:8.0-cudnn5-devel-ubuntu14.04
+#   FROM nvidia/cuda:7.5-cudnn5-devel-ubuntu14.04
+#   FROM nvidia/cuda:7.5-cudnn4-devel-ubuntu14.04
+#   FROM nvidia/cuda:7.0-cudnn4-devel-ubuntu14.04
+FROM nvidia/cuda:7.5-cudnn5-devel-ubuntu14.04
+
+# install dependencies
+RUN apt-get update \
+    && apt-get install -y --no-install-recommends git build-essential autoconf libtool cmake libprotobuf-dev libopenblas-dev libpcre3-dev python-dev python-pip protobuf-compiler wget openssh-server \
+    && apt-get clean && apt-get autoremove && apt-get autoclean \
+    && rm -rf /var/lib/apt/lists/* \
+    && pip install -U pip wheel numpy setuptools unittest-xml-reporting protobuf
+
+
+# install swig 3.0
+RUN wget http://prdownloads.sourceforge.net/swig/swig-3.0.10.tar.gz && \
+    tar zxf swig-3.0.10.tar.gz && cd swig-3.0.10 && \
+    ./configure && make && make install
+
+# install conda, conda-build and anaconda-client
+RUN wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh;
+RUN bash miniconda.sh -b -p /root/miniconda
+RUN /root/miniconda/bin/conda config --set always_yes yes --set changeps1 no
+RUN /root/miniconda/bin/conda update -q conda
+RUN /root/miniconda/bin/conda install conda-build
+RUN /root/miniconda/bin/conda install anaconda-client
+ENV PATH /root/miniconda/bin:${PATH}
+
+# set environment
+ENV CPLUS_INCLUDE_PATH /usr/local/lib/python2.7/dist-packages/numpy/core/include:${CPLUS_INCLUDE_PATH}
+# ENV CMAKE_INCLUDE_PATH /usr/local/cuda/include:${CMAKE_INCLUDE_PATH}
+# ENV CMAKE_LIBRARY_PATH /usr/local/cuda/lib64:${CMAKE_LIBRARY_PATH}
+
+# download singa source
+# RUN git clone https://github.com/apache/incubator-singa.git
+
+# config ssh service
+RUN mkdir /var/run/sshd
+RUN echo 'root:singa' | chpasswd
+RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
+# SSH login fix. Otherwise user is kicked off after login
+RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
+
+# dump environment variables into files, so that ssh can see also
+RUN env | grep _ >> /etc/environment
+
+EXPOSE 22
+
+CMD ["/usr/sbin/sshd", "-D"]