[test] Added unittests for LSTM
authorParichay Kapoor <pk.kapoor@samsung.com>
Fri, 8 Oct 2021 11:36:58 +0000 (20:36 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Sat, 9 Oct 2021 00:42:53 +0000 (09:42 +0900)
This patch adds unittests for LSTM layer
1. single and multi timesteps
2. with and without return sequences
3. with setting activations differently

Signed-off-by: Parichay Kapoor <pk.kapoor@samsung.com>
packaging/unittest_layers_v2.tar.gz
test/input_gen/genLayerTests.py
test/unittest/layers/unittest_layers_lstm.cpp

index 04eeaff..888ac14 100644 (file)
Binary files a/packaging/unittest_layers_v2.tar.gz and b/packaging/unittest_layers_v2.tar.gz differ
index 3c70b67..d0b1bbf 100644 (file)
@@ -90,5 +90,28 @@ if __name__ == "__main__":
     record_single(attention, [(2, 5, 7), (2, 3, 7), (2, 3, 7)],
                  "attention_batched", {}, input_type='float')
 
-inspect_file("conv_sb_no_overlap.nnlayergolden")
+    lstm = K.layers.LSTM(units=5,
+                         recurrent_activation="sigmoid",
+                         activation="tanh",
+                         return_sequences=False,
+                         return_state=False)
+    record_single(lstm, (3, 1, 7), "lstm_single_step")
+    record_single(lstm, (3, 4, 7), "lstm_multi_step")
+
+    lstm = K.layers.LSTM(units=5,
+                         recurrent_activation="sigmoid",
+                         activation="tanh",
+                         return_sequences=True,
+                         return_state=False)
+    record_single(lstm, (3, 1, 7), "lstm_single_step_seq")
+    record_single(lstm, (3, 4, 7), "lstm_multi_step_seq")
+
+    lstm = K.layers.LSTM(units=5,
+                         recurrent_activation="tanh",
+                         activation="sigmoid",
+                         return_sequences=True,
+                         return_state=False)
+    record_single(lstm, (3, 4, 7), "lstm_multi_step_seq_act")
+
+inspect_file("lstm_single_step_seq.nnlayergolden")
 
index 9ad7315..df22bb6 100644 (file)
@@ -21,3 +21,42 @@ auto semantic_lstm =
                           nntrainer::LSTMLayer::type, {"unit=1"}, 0, false, 1);
 
 INSTANTIATE_TEST_CASE_P(LSTM, LayerSemantics, ::testing::Values(semantic_lstm));
+
+auto lstm_single_step = LayerGoldenTestParamType(
+  nntrainer::createLayer<nntrainer::LSTMLayer>, {"unit=5"}, "3:1:1:7",
+  "lstm_single_step.nnlayergolden", LayerGoldenTestParamOptions::DEFAULT);
+
+auto lstm_multi_step = LayerGoldenTestParamType(
+  nntrainer::createLayer<nntrainer::LSTMLayer>, {"unit=5"}, "3:1:4:7",
+  "lstm_multi_step.nnlayergolden", LayerGoldenTestParamOptions::DEFAULT);
+
+auto lstm_single_step_seq = LayerGoldenTestParamType(
+  nntrainer::createLayer<nntrainer::LSTMLayer>,
+  {"unit=5", "return_sequences=true"}, "3:1:1:7",
+  "lstm_single_step_seq.nnlayergolden", LayerGoldenTestParamOptions::DEFAULT);
+
+auto lstm_multi_step_seq = LayerGoldenTestParamType(
+  nntrainer::createLayer<nntrainer::LSTMLayer>,
+  {"unit=5", "return_sequences=true"}, "3:1:4:7",
+  "lstm_multi_step_seq.nnlayergolden", LayerGoldenTestParamOptions::DEFAULT);
+
+auto lstm_multi_step_seq_act_orig = LayerGoldenTestParamType(
+  nntrainer::createLayer<nntrainer::LSTMLayer>,
+  {"unit=5", "return_sequences=true", "hidden_state_activation=tanh",
+   "recurrent_activation=sigmoid"},
+  "3:1:4:7", "lstm_multi_step_seq.nnlayergolden",
+  LayerGoldenTestParamOptions::DEFAULT);
+
+auto lstm_multi_step_seq_act = LayerGoldenTestParamType(
+  nntrainer::createLayer<nntrainer::LSTMLayer>,
+  {"unit=5", "return_sequences=true", "hidden_state_activation=sigmoid",
+   "recurrent_activation=tanh"},
+  "3:1:4:7", "lstm_multi_step_seq_act.nnlayergolden",
+  LayerGoldenTestParamOptions::DEFAULT);
+
+INSTANTIATE_TEST_CASE_P(LSTM, LayerGoldenTest,
+                        ::testing::Values(lstm_single_step, lstm_multi_step,
+                                          lstm_single_step_seq,
+                                          lstm_multi_step_seq,
+                                          lstm_multi_step_seq_act_orig,
+                                          lstm_multi_step_seq_act));