From 593f6ed659499ee26d073191c20dfd88cdb6d6a4 Mon Sep 17 00:00:00 2001 From: Jihoon Lee Date: Mon, 20 Dec 2021 16:26:21 +0900 Subject: [PATCH] [Test] Add test with dangling output This patch add test with dangling output, this test passes test but fails optimized run. Current aim is to make this pass optimized run as well. **Self evaluation:** 1. Build test: [X]Passed [ ]Failed [ ]Skipped 2. Run test: [X]Passed [ ]Failed [ ]Skipped Signed-off-by: Jihoon Lee --- packaging/unittest_models_multiout.tar.gz | Bin 1301 -> 45 bytes test/input_gen/genModelsMultiout_v2.py | 45 +++++++++++++++++++++- test/unittest/models/unittest_models_multiout.cpp | 39 +++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/packaging/unittest_models_multiout.tar.gz b/packaging/unittest_models_multiout.tar.gz index 14c42f0c23c303a8aa9074377d8d3ce445b8ae82..02c486b227df4a2f7ebdbec6854a8f3740835f73 100644 GIT binary patch literal 45 vcmb2|=3o#oK9I=3{PrLtF9QR^p#|UlbNS2{0GSZbV9q@2o~$~91_J{C3KR-% literal 1301 zcmV+w1?u`AiwFSV5T0QG1MSs)OcQ4u2k;6aQjmf=f`=wa-|}@-%miPpcrM$ z`NAxn6r_|ErO2E#Saop&LC`TWCF15br@}y|yp3LcAx=S^I^SR-h*Ks*M8u#tb-go7 zmYB_dRO0e{k|&qv?w;po*y-ty&)UNQ+YLj%aDowmj6RXnlo*!Qee}9U- zilq|Ye_lD%M2aV-#FUg0`}$Fq`(jEWp?D(S=UBtPN=?x#mx)9?wMM1-ulJty{1s(o zX?#mNsGN!patRt9&p`DtM|28G!jP%sO&yc@rjfC>JoA(a=o>~oRG+v9>>TMH z8!&iIIhKujeah^Fjdb6`V+>nI<6I+1eD*@-y~*HqDGmoWQy4yIGLF&2p*&5Fk`G4U zBFB7gj%ZsqurAyUv)>(qTdB|K#j}(&TL(A}fr^mMnx+fc&>PUh?DJAGn(H5Nbqp$P zGX+*v(eb~X;pT|S-DVp8rO_t8K9qjMZeHJ$-m|D!s7qz{QEzZe?O^& zJwu5(HR<{6OHWFs6amM`tws<}_1-IY6%hko~;9*0u9Zs&8gD%|( zbbw+Uw^uDYX$PZ*kAu|UnarLNCvg;E=Uijsuaxy(n1)AslsNZHHEhXr$Cb*>^s4hUFs)UKl?O(n*P?ou)EKFDUOAc@PP!7$KlDswTh=eMkH56JS18J}QhWc$;-2LM&& zfU+rXaQ!HoR_4Q@)i8T)6L;Qs8MeXkgEr=i=Q_ALMGm=8Sv&(4G9g%Mp9Pxm#gO=x zFAlgG0UqPCAtl-ihq^dGi&rsZ7x1yv)(De+UkYLKCLlZBGh-17Bb#CU{0J76@mqB4~5dFAzJVph$a^nZC8;qOuVtRPB03+(Y z1KlCZ{xs$q?Xc7h4_t9V=Wm(BDYQ#+ilFkYfskcZA}rR|GAHmrn_+KVpHM;Lrb0TwG$p(zwm4u zbEmZ&Hgq>|>-6)1J>;+MD4vh8m#M}i;-f*=TjAP9mW2!bF8f*=Tjc$NGG LinYgp04M+ef$o3< diff --git a/test/input_gen/genModelsMultiout_v2.py b/test/input_gen/genModelsMultiout_v2.py index aa3a8ea..6fff417 100644 --- a/test/input_gen/genModelsMultiout_v2.py +++ b/test/input_gen/genModelsMultiout_v2.py @@ -28,6 +28,39 @@ class SplitAndJoin(torch.nn.Module): return out, loss +class SplitAndJoinDangle(torch.nn.Module): + def __init__(self): + super().__init__() + self.fc = torch.nn.Linear(3, 4) + self.sigmoid = torch.nn.Sigmoid() + self.fc1 = torch.nn.Linear(1, 3) + self.loss = torch.nn.MSELoss() + + def forward(self, inputs, labels): + out = self.fc(inputs[0]) + # input + # (split) + # a0 a1 a2 a3 + # | | + # b0 b1 + # (add) + # c0 + # + # only c0 is fed to loss, a1 and a2 is dangled + a0, a1, a2, a3 = torch.split(out, 1, dim=1) + a0 = self.sigmoid(a0) + a1 = self.sigmoid(a1) + a2 = self.sigmoid(a2) + a3 = self.sigmoid(a3) + + b0 = self.fc1(a0) + b3 = self.fc1(a3) # shared + c0 = b0 + b3 + out = self.sigmoid(c0) + loss = self.loss(out, labels[0]) + return out, loss + + class OneToOne(torch.nn.Module): def __init__(self): super().__init__() @@ -41,6 +74,7 @@ class OneToOne(torch.nn.Module): loss = self.loss(out, labels[0]) return out, loss + class OneToMany(torch.nn.Module): def __init__(self): super().__init__() @@ -56,6 +90,7 @@ class OneToMany(torch.nn.Module): loss = self.loss(d0, labels[0]) return d0, loss + if __name__ == "__main__": record_v2( SplitAndJoin(), @@ -66,6 +101,14 @@ if __name__ == "__main__": ) record_v2( + SplitAndJoinDangle(), + iteration=3, + input_dims=[(5, 3)], + label_dims=[(5, 3)], + name="split_and_join_dangle" + ) + + record_v2( OneToOne(), iteration=2, input_dims=[(5, 3)], @@ -81,4 +124,4 @@ if __name__ == "__main__": name="one_to_many" ) - inspect_file("one_to_many.nnmodelgolden") +# inspect_file("split_and_join_dangle.nnmodelgolden") diff --git a/test/unittest/models/unittest_models_multiout.cpp b/test/unittest/models/unittest_models_multiout.cpp index db1452f..6d874dc 100644 --- a/test/unittest/models/unittest_models_multiout.cpp +++ b/test/unittest/models/unittest_models_multiout.cpp @@ -137,6 +137,42 @@ static std::unique_ptr one_to_many() { return nn; } +/// input +/// (split) +/// a0 a1 a2 a3 +/// (fc) (fc) +/// b0 b1 +/// (add) +/// c0 +/// +/// only c0 is fed to loss, a1 and a2 is dangled +/// @note we are not supporting explicit layer with dangling output, It is also +/// unclear that if this should be supported. +static std::unique_ptr split_and_join_dangle() { + std::unique_ptr nn(new NeuralNetwork()); + nn->setProperty({"batch_size=5"}); + + auto graph = makeGraph({ + {"fully_connected", {"name=fc", "input_shape=1:1:3", "unit=4"}}, + {"split", {"name=a", "input_layers=fc", "axis=3"}}, + {"activation", {"name=a0", "activation=sigmoid", "input_layers=a(0)"}}, + {"activation", {"name=a3", "activation=sigmoid", "input_layers=a(3)"}}, + {"fully_connected", + {"name=b0", "input_layers=a0", "unit=3", "shared_from=b0"}}, + {"fully_connected", + {"name=b1", "input_layers=a3", "unit=3", "shared_from=b0"}}, + {"addition", {"name=c0", "input_layers=b0,b1", "activation=sigmoid"}}, + {"mse", {"name=loss", "input_layers=c0"}}, + }); + + for (auto &node : graph) { + nn->addLayer(node); + } + + nn->setOptimizer(ml::train::createOptimizer("sgd", {"learning_rate = 0.1"})); + return nn; +} + INSTANTIATE_TEST_CASE_P( multiInoutModels, nntrainerModelTest, ::testing::ValuesIn({ @@ -145,6 +181,9 @@ INSTANTIATE_TEST_CASE_P( mkModelTc_V2(one_to_one_reversed, "one_to_one__reversed", ModelTestOption::ALL_V2), mkModelTc_V2(one_to_many, "one_to_many", ModelTestOption::ALL_V2), + mkModelTc_V2(split_and_join_dangle, "split_and_join_dangle", + ModelTestOption::NO_THROW_RUN_V2), + // ModelTestOption::ALL_V2), }), [](const testing::TestParamInfo &info) { return std::get<1>(info.param); -- 2.7.4