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/01/06 15:56:16 UTC
[3/5] incubator-singa git commit: SINGA-120 - Implemented GRU and BPTT
SINGA-120 - Implemented GRU and BPTT
Add configuration fields (vocab_size) for OneHotLayer.
Configure gpu to 0 for all examples.
Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/c72ef0fc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/c72ef0fc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/c72ef0fc
Branch: refs/heads/master
Commit: c72ef0fc6a0982b0cc61e551bc44a393a45dcb01
Parents: c45ff1c
Author: Wei Wang <wa...@comp.nus.edu.sg>
Authored: Wed Jan 6 17:52:08 2016 +0800
Committer: Wei Wang <wa...@comp.nus.edu.sg>
Committed: Wed Jan 6 22:30:38 2016 +0800
----------------------------------------------------------------------
examples/alexnet/cudnn.conf | 2 +-
examples/char-rnn/job.conf | 3 +++
examples/cifar10/cudnn.conf | 2 +-
include/singa/neuralnet/neuron_layer.h | 4 +---
src/neuralnet/input_layer/onehot.cc | 2 +-
src/neuralnet/neuron_layer/gru.cc | 8 +++++---
src/proto/job.proto | 5 +++++
7 files changed, 17 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/c72ef0fc/examples/alexnet/cudnn.conf
----------------------------------------------------------------------
diff --git a/examples/alexnet/cudnn.conf b/examples/alexnet/cudnn.conf
index 6324185..e8d14c6 100644
--- a/examples/alexnet/cudnn.conf
+++ b/examples/alexnet/cudnn.conf
@@ -5,7 +5,7 @@ test_freq: 1000
disp_freq: 20
checkpoint_freq: 100000
checkpoint_after: 100000
-gpu: 2
+gpu: 0
#debug: true
#checkpoint_path: "examples/alexnet/checkpoint/step10000-worker0"
train_one_batch {
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/c72ef0fc/examples/char-rnn/job.conf
----------------------------------------------------------------------
diff --git a/examples/char-rnn/job.conf b/examples/char-rnn/job.conf
index 2e1c761..bd648f1 100644
--- a/examples/char-rnn/job.conf
+++ b/examples/char-rnn/job.conf
@@ -42,6 +42,9 @@ neuralnet {
type: kOneHot
srclayers: "data"
unroll_conn_type: kUnrollOneToAll
+ onehot_conf {
+ vocab_size: 101
+ }
}
layer {
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/c72ef0fc/examples/cifar10/cudnn.conf
----------------------------------------------------------------------
diff --git a/examples/cifar10/cudnn.conf b/examples/cifar10/cudnn.conf
index 136435b..0f9402e 100644
--- a/examples/cifar10/cudnn.conf
+++ b/examples/cifar10/cudnn.conf
@@ -5,7 +5,7 @@ test_freq: 1000
#validate_steps: 100
#validate_freq: 300
disp_freq: 200
-gpu: 2
+gpu: 0
#checkpoint_path: "examples/cifar10/checkpoint/step1000-worker0"
train_one_batch {
alg: kBP
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/c72ef0fc/include/singa/neuralnet/neuron_layer.h
----------------------------------------------------------------------
diff --git a/include/singa/neuralnet/neuron_layer.h b/include/singa/neuralnet/neuron_layer.h
index 8471aeb..3fe08f4 100644
--- a/include/singa/neuralnet/neuron_layer.h
+++ b/include/singa/neuralnet/neuron_layer.h
@@ -202,9 +202,7 @@ class GRULayer : public NeuronLayer {
int batchsize_; // batch size
int vdim_, hdim_; // dimensions
- Blob<float> *update_gate_, *reset_gate_, *new_memory_, *reset_context_;
- //!< gru layer connect to two dst layers, hence need to grad blobs.
- Blob<float> aux_grad_;
+ Blob<float> *update_gate_, *reset_gate_, *new_memory_;
Param *weight_z_hx_, *weight_z_hh_, *bias_z_; // update gate
Param *weight_r_hx_, *weight_r_hh_, *bias_r_; // reset gate
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/c72ef0fc/src/neuralnet/input_layer/onehot.cc
----------------------------------------------------------------------
diff --git a/src/neuralnet/input_layer/onehot.cc b/src/neuralnet/input_layer/onehot.cc
index 056656a..4b83705 100644
--- a/src/neuralnet/input_layer/onehot.cc
+++ b/src/neuralnet/input_layer/onehot.cc
@@ -25,7 +25,7 @@ void OneHotLayer::Setup(const LayerProto& conf,
const vector<Layer*>& srclayers) {
InputLayer::Setup(conf, srclayers);
batchsize_ = srclayers.at(0)->data(unroll_index()).shape(0);
- dim_ = 101 ; // proto.onehot_conf().vocab_size();
+ dim_ = conf.onehot_conf().vocab_size();
data_.Reshape(batchsize_, dim_);
}
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/c72ef0fc/src/neuralnet/neuron_layer/gru.cc
----------------------------------------------------------------------
diff --git a/src/neuralnet/neuron_layer/gru.cc b/src/neuralnet/neuron_layer/gru.cc
index 149543f..8ca189f 100644
--- a/src/neuralnet/neuron_layer/gru.cc
+++ b/src/neuralnet/neuron_layer/gru.cc
@@ -34,20 +34,22 @@ using std::vector;
GRULayer::~GRULayer() {
delete weight_z_hx_;
delete weight_z_hh_;
- delete bias_z_;
+ if (bias_z_ != nullptr)
+ delete bias_z_;
delete weight_r_hx_;
delete weight_r_hh_;
+ if (bias_r_ != nullptr)
delete bias_r_;
delete weight_c_hx_;
delete weight_c_hh_;
- delete bias_c_;
+ if (bias_c_ != nullptr)
+ delete bias_c_;
delete update_gate_;
delete reset_gate_;
delete new_memory_;
- delete reset_context_;
}
void GRULayer::Setup(const LayerProto& conf,
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/c72ef0fc/src/proto/job.proto
----------------------------------------------------------------------
diff --git a/src/proto/job.proto b/src/proto/job.proto
index 28a3a68..da52ea9 100644
--- a/src/proto/job.proto
+++ b/src/proto/job.proto
@@ -228,6 +228,7 @@ message LayerProto {
optional RGBImageProto rgbimage_conf = 193;
optional DataProto sharddata_conf = 194;
optional CharRNNProto char_rnn_conf = 195;
+ optional OnehotProto onehot_conf = 196;
// configuration for neuron layers id range [200, 300)
optional ActivationProto activation_conf = 200;
@@ -336,6 +337,10 @@ message ActivationProto {
optional ActivationType type = 1 [default = RELU];
}
+message OnehotProto {
+ optional int32 vocab_size = 1 [default = 0];
+}
+
message RGBImageProto {
// scale factor for each pixel
optional float scale = 1 [default = 1.0];