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/04/06 14:28:53 UTC

[1/2] incubator-singa git commit: SINGA-131 Implement and optimize hybrid training using both CPU and GPU

Repository: incubator-singa
Updated Branches:
  refs/heads/master c97b970dc -> 040cbb2e1


SINGA-131 Implement and optimize hybrid training using both CPU and GPU

Allow users set the batchsize of instances of StoreInputLayer manually.
We can then assign different workload for GPU and CPU workers who have
different input layers, e.g.,
```
 batchsize: 128
 batchsize: 16
 ```
 If the first worker is GPU and the second worker is CPU, then the
 above setting would assign 128 images per mini-batch to the GPU worker
 and assign 16 images to the CPU worker.

 Internally, StoreInputLayer gets its batchsize based on its partition
 ID.
 Currently, it works for MNIST example which has no Conv layers.
 For Conv layers, since the GPU and CPU implementations have different
 layer names, we cannot using the single net config.


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

Branch: refs/heads/master
Commit: a91e82f3c8771980bff916511a7c750f5f6d039d
Parents: c97b970
Author: Wei Wang <wa...@comp.nus.edu.sg>
Authored: Mon Apr 4 13:39:19 2016 +0800
Committer: Wei Wang <wa...@comp.nus.edu.sg>
Committed: Wed Apr 6 17:51:14 2016 +0800

----------------------------------------------------------------------
 src/neuralnet/input_layer/store.cc | 11 ++++++++---
 src/proto/job.proto                |  2 +-
 2 files changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/a91e82f3/src/neuralnet/input_layer/store.cc
----------------------------------------------------------------------
diff --git a/src/neuralnet/input_layer/store.cc b/src/neuralnet/input_layer/store.cc
index 283b0c7..f213227 100644
--- a/src/neuralnet/input_layer/store.cc
+++ b/src/neuralnet/input_layer/store.cc
@@ -34,10 +34,15 @@ StoreInputLayer::~StoreInputLayer() {
 void StoreInputLayer::Setup(const LayerProto& conf,
     const vector<Layer*>& srclayers) {
   InputLayer::Setup(conf, srclayers);
-  batchsize_ = conf.store_conf().batchsize();
+  const auto& batchsize = conf.store_conf().batchsize();
+  CHECK(batchsize.size());
   if (conf.partition_dim() == 0) {
-    batchsize_ /= conf.num_partitions();
-  }
+    if (batchsize.size() == 1)  // equal partition
+      batchsize_ = batchsize.Get(0) / conf.num_partitions();
+    else  // manual partition
+      batchsize_ = batchsize.Get(conf.partition_id());
+  } else
+    batchsize_ = conf.store_conf().batchsize(0);
 }
 
 void StoreInputLayer::ComputeFeature(int flag,

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/a91e82f3/src/proto/job.proto
----------------------------------------------------------------------
diff --git a/src/proto/job.proto b/src/proto/job.proto
index 6afc599..1a6ab42 100644
--- a/src/proto/job.proto
+++ b/src/proto/job.proto
@@ -374,7 +374,7 @@ message StoreProto {
   optional string std_file = 5;
   optional float mean_value = 6;
   optional float std_value = 7;
-  optional int32 batchsize = 8 [default = 1];
+  repeated int32 batchsize = 8;
   repeated int32 shape = 9;
   optional bool encoded = 10 [default = false];
   optional int32 random_skip = 11 [default = 0];


[2/2] incubator-singa git commit: SINGA-131 Implement and optimize hybrid training using both CPU and GPU

Posted by wa...@apache.org.
SINGA-131 Implement and optimize hybrid training using both CPU and GPU

update test files
checked with cpplint


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

Branch: refs/heads/master
Commit: 040cbb2e121164268284c4a8d005bd9aea83f40c
Parents: a91e82f
Author: WANG Sheng <wa...@gmail.com>
Authored: Wed Apr 6 20:27:48 2016 +0800
Committer: WANG Sheng <wa...@gmail.com>
Committed: Wed Apr 6 20:27:48 2016 +0800

----------------------------------------------------------------------
 src/neuralnet/input_layer/store.cc  | 3 ++-
 src/test/test_csv_input_layer.cc    | 2 +-
 src/test/test_gru_layer.cc          | 4 ++--
 src/test/test_record_input_layer.cc | 2 +-
 4 files changed, 6 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/040cbb2e/src/neuralnet/input_layer/store.cc
----------------------------------------------------------------------
diff --git a/src/neuralnet/input_layer/store.cc b/src/neuralnet/input_layer/store.cc
index f213227..3b642ca 100644
--- a/src/neuralnet/input_layer/store.cc
+++ b/src/neuralnet/input_layer/store.cc
@@ -41,8 +41,9 @@ void StoreInputLayer::Setup(const LayerProto& conf,
       batchsize_ = batchsize.Get(0) / conf.num_partitions();
     else  // manual partition
       batchsize_ = batchsize.Get(conf.partition_id());
-  } else
+  } else {
     batchsize_ = conf.store_conf().batchsize(0);
+  }
 }
 
 void StoreInputLayer::ComputeFeature(int flag,

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/040cbb2e/src/test/test_csv_input_layer.cc
----------------------------------------------------------------------
diff --git a/src/test/test_csv_input_layer.cc b/src/test/test_csv_input_layer.cc
index 6613d87..86eaff9 100644
--- a/src/test/test_csv_input_layer.cc
+++ b/src/test/test_csv_input_layer.cc
@@ -38,7 +38,7 @@ class CSVInputLayerTest : public ::testing::Test {
     ofs.close();
     auto conf = csv_conf.mutable_store_conf();
     conf->set_path(path);
-    conf->set_batchsize(2);
+    conf->add_batchsize(2);
     conf->add_shape(3);
     conf->set_backend("textfile");
   }

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/040cbb2e/src/test/test_gru_layer.cc
----------------------------------------------------------------------
diff --git a/src/test/test_gru_layer.cc b/src/test/test_gru_layer.cc
index d7c8fe8..e0e381f 100644
--- a/src/test/test_gru_layer.cc
+++ b/src/test/test_gru_layer.cc
@@ -45,7 +45,7 @@ class GRULayerTest: public ::testing::Test {
     ofs1.close();
     auto conf1 = in1_conf.mutable_store_conf();
     conf1->set_path(path1);
-    conf1->set_batchsize(2);
+    conf1->add_batchsize(2);
     conf1->add_shape(4);
     conf1->set_backend("textfile");
     conf1->set_has_label(false);
@@ -61,7 +61,7 @@ class GRULayerTest: public ::testing::Test {
     auto conf2 = in2_conf.mutable_store_conf();
     conf2->set_path(path2);
 
-    conf2->set_batchsize(2);
+    conf2->add_batchsize(2);
     conf2->add_shape(4);
     conf2->set_backend("textfile");
     conf2->set_has_label(false);

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/040cbb2e/src/test/test_record_input_layer.cc
----------------------------------------------------------------------
diff --git a/src/test/test_record_input_layer.cc b/src/test/test_record_input_layer.cc
index 9c953c1..64e1ad4 100644
--- a/src/test/test_record_input_layer.cc
+++ b/src/test/test_record_input_layer.cc
@@ -69,7 +69,7 @@ class RecordInputLayerTest : public ::testing::Test {
 
     auto conf = image_conf.mutable_store_conf();
     conf->set_path(path);
-    conf->set_batchsize(2);
+    conf->add_batchsize(2);
     conf->add_shape(3);
     conf->set_backend("kvfile");
   }