[Bugfix] Regenerate lstmcell unittest
authorhyeonseok lee <hs89.lee@samsung.com>
Thu, 4 Nov 2021 10:56:44 +0000 (19:56 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Wed, 10 Nov 2021 09:11:55 +0000 (18:11 +0900)
 - Set lstm bias_ih to unused in init to fix the bug
 - Regenerate the lstmcell unittest
 - Fix typo

Self evaluation:

Build test: [X]Passed [ ]Failed [ ]Skipped
Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: hyeonseok lee <hs89.lee@samsung.com>
api/ccapi/include/layer.h
nntrainer/layers/meson.build
nntrainer/layers/rnn.cpp
packaging/unittest_models_v2.tar.gz
test/input_gen/genModelsRecurrent_v2.py
test/unittest/layers/unittest_layers_lstmcell.cpp
test/unittest/models/unittest_models_recurrent.cpp

index e1eb03c64b483d9f7b30e02fbb4cd8efc98e33b8..dc3e602f0c000236eb1f40eb6e701640cb9372d4 100644 (file)
@@ -254,14 +254,6 @@ Reshape(const std::vector<std::string> &properties = {}) {
   return createLayer(LayerType::LAYER_RESHAPE, properties);
 }
 
-/**
- * @brief Helper function to create LSTMCell layer
- */
-inline std::unique_ptr<Layer>
-LSTMCell(const std::vector<std::string> &properties = {}) {
-  return createLayer(LayerType::LAYER_LSTMCELL, properties);
-}
-
 /**
  * @brief Helper function to create addition layer
  */
@@ -326,6 +318,14 @@ LSTM(const std::vector<std::string> &properties = {}) {
   return createLayer(LayerType::LAYER_LSTM, properties);
 }
 
+/**
+ * @brief Helper function to create LSTMCell layer
+ */
+inline std::unique_ptr<Layer>
+LSTMCell(const std::vector<std::string> &properties = {}) {
+  return createLayer(LayerType::LAYER_LSTMCELL, properties);
+}
+
 /**
  * @brief Helper function to create GRU layer
  */
index ba5b1a5acc640ca8713ea69e2208427233a72992..3a5ae43d140611170cb041357cb8556fb36133e6 100644 (file)
@@ -23,6 +23,7 @@ layer_sources = [
   'rnn.cpp',
   'acti_func.cpp',
   'lstm.cpp',
+  'lstmcell.cpp',
   'time_dist.cpp',
   'common_properties.cpp',
   'split_layer.cpp',
@@ -33,7 +34,6 @@ layer_sources = [
   'centroid_knn.cpp',
   'layer_context.cpp',
   'reshape_layer.cpp',
-  'lstmcell.cpp'
 ]
 
 layer_headers = [
index b6dfd4d10006203537f8ca478523cc261c30533b..08045c88b77da373ac0c90e775c8624bd8d5e48a 100644 (file)
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: Apache-2.0
 /**
- * Copyright (C) 2020 Jijoong Moon <jijoong.moon@samsung.com>
+ * Copyright (C) 2021 Jijoong Moon <jijoong.moon@samsung.com>
  *
  * @file   rnn.cpp
  * @date   17 March 2021
@@ -89,7 +89,7 @@ void RNNLayer::finalize(InitLayerContext &context) {
   dim_hh.height(unit);
   dim_hh.batch(1);
 
-  // weight_initializer can be set sepeartely. weight_xh initializer,
+  // weight_initializer can be set seperately. weight_xh initializer,
   // weight_hh initializer kernel initializer & recurrent_initializer in keras
   // for now, it is set same way.
 
@@ -103,7 +103,7 @@ void RNNLayer::finalize(InitLayerContext &context) {
     bias_dim, bias_initializer, WeightRegularizer::NONE, 1.0f, "bias_h", true);
 
   // We do not need this if we reuse net_hidden[0]. But if we do, then the unit
-  // test will fail. Becuase it modifies the date during gradient calculation
+  // test will fail. Becuase it modifies the data during gradient calculation
   // TODO : We could control with something like #define test to save memory
   TensorDim d = input_dim;
   d.width(unit);
index d689aebad70ed011c651aec64f58b4251470d20b..06d35aa32fc56e05e6aca824e521236b52795a84 100644 (file)
Binary files a/packaging/unittest_models_v2.tar.gz and b/packaging/unittest_models_v2.tar.gz differ
index 6f968da77fd27b3361b42a7b0237b0bb0e8f07bc..cec962262e8db69ecdc3111155ba3530d1cf8850 100644 (file)
@@ -28,7 +28,6 @@ class FCUnroll(torch.nn.Module):
         # loss = self.loss(output, labels[0])
         return output, loss
 
-
 class LSTMStacked(torch.nn.Module):
     def __init__(self, unroll_for=2, num_lstm=1):
         super().__init__()
@@ -42,12 +41,15 @@ class LSTMStacked(torch.nn.Module):
         # self.lstm.weight_hh.data.fill_(1.0)
         # self.lstm.weight_ih.data.fill_(1.0)
         # self.lstm.bias_hh.data.fill_(1.0)
+        for lstm in self.lstms:
+            lstm.bias_ih.data.fill_(0.0)
+            lstm.bias_ih.requires_grad=False
         self.unroll_for = unroll_for
         self.loss = torch.nn.MSELoss()
 
     def forward(self, inputs, labels):
         # second bias is always set to make it always zero grad.
-        # this is because that we are only keepting one bias
+        # this is because that we are only keeping one bias
         for lstm in self.lstms:
             lstm.bias_ih.data.fill_(0.0)
 
@@ -65,7 +67,6 @@ class LSTMStacked(torch.nn.Module):
         loss = self.loss(ret, labels[0])
         return ret, loss
 
-
 if __name__ == "__main__":
     record_v2(
         FCUnroll(unroll_for=5),
index 4765ed73a55f52bb143b29d11a533d4d572556f1..daf70e3b78cf244c8e2b967fafdc11dd7a25aeda 100644 (file)
@@ -2,9 +2,9 @@
 /**
  * Copyright (C) 2021 Parichay Kapoor <pk.kapoor@samsung.com>
  *
- * @file unittest_layers_lstm.cpp
+ * @file unittest_layers_lstmcell.cpp
  * @date 22 October 2021
- * @brief LSTM Layer Test
+ * @brief LSTMCell Layer Test
  * @see        https://github.com/nnstreamer/nntrainer
  * @author Parichay Kapoor <pk.kapoor@samsung.com>
  * @bug No known bugs except for NYI items
index 780a4e24ed8f7c821b75db99eed6175ef6856b09..10b21287169123724e4362339048127fd29b33ee 100644 (file)
@@ -81,7 +81,7 @@ static std::unique_ptr<NeuralNetwork> makeSingleLSTM() {
 
   auto outer_graph = makeGraph({
     {"input", {"name=input", "input_shape=1:1:2"}},
-    /// here lstm_cells is being inserted
+    /// here lstm is being inserted
     {"mse", {"name=loss", "input_layers=lstm_scope/a1"}},
   });
   for (auto &node : outer_graph) {
@@ -111,7 +111,7 @@ static std::unique_ptr<NeuralNetwork> makeStackedLSTM() {
 
   auto outer_graph = makeGraph({
     {"input", {"name=input", "input_shape=1:1:2"}},
-    /// here lstm_cells is being inserted
+    /// here lstm is being inserted
     {"mse", {"name=loss", "input_layers=lstm_scope/a2"}},
   });
   for (auto &node : outer_graph) {