Skip to content

Commit

Permalink
[ Test ] Mixed Precision Test Case
Browse files Browse the repository at this point in the history
This PR includes the mixed precision test case.

. Input - FC - MSE
 : "batch_size=2", "model_tensor_type=FP16-FP16", "loss_scale=128"

**Self evaluation:**
1. Build test:	 [X]Passed [ ]Failed [ ]Skipped
2. Run test:	 [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: jijoong.moon <[email protected]>
  • Loading branch information
jijoongmoon committed May 7, 2024
1 parent 8b7b44f commit b51af11
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Applications/KNN/jni/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ e = executable('knn_sample',
install_dir: application_install_dir
)

test('app_knn', e, args: [nntr_app_resdir / 'KNN'])
test('app_knn', e, args: [nntr_app_resdir / 'KNN/'])
4 changes: 4 additions & 0 deletions test/unittest/models/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ models_targets = [
# disable temperally
]

if get_option('enable-fp16')
models_targets += 'unittest_models_mixed_precision.cpp'
endif

test_target += models_targets
exe = executable(
test_name,
Expand Down
54 changes: 54 additions & 0 deletions test/unittest/models/unittest_models_mixed_precision.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: Apache-2.0
/**
* Copyright (C) 2024 Jijoong Moon <[email protected]>
*
* @file unittest_models_mixed_precision.cpp
* @date 3 May 2024
* @brief unittest models to cover mixed precision
* @see https://github.com/nnstreamer/nntrainer
* @author Jijoong Moon <[email protected]>
* @bug No known bugs except for NYI items
*/

#include <gtest/gtest.h>

#include <memory>

#include <ini_wrapper.h>
#include <neuralnet.h>
#include <nntrainer_test_util.h>

#include <models_golden_test.h>

using namespace nntrainer;

static std::unique_ptr<NeuralNetwork> fc_mixed_training() {
std::unique_ptr<NeuralNetwork> nn(new NeuralNetwork());
nn->setProperty(
{"batch_size=2", "model_tensor_type=FP16-FP16", "loss_scale=128"});

auto graph = makeGraph({
{"input", {"name=in", "input_shape=1:1:3"}},
{"Fully_connected", {"name=fc", "input_layers=in", "unit=10"}},
{"mse", {"name=loss", "input_layers=fc"}},
});
for (auto &node : graph) {
nn->addLayer(node);
}

nn->setOptimizer(ml::train::createOptimizer("adam", {"learning_rate = 0.1"}));

return nn;
}

GTEST_PARAMETER_TEST(
MixedPrecision, nntrainerModelTest,
::testing::ValuesIn({
mkModelTc_V2(fc_mixed_training, "fc_mixed_training",
ModelTestOption::NO_THROW_RUN_V2),
/** ModelTestOption::ALL_V2),
* Disabled for now to check
*/
}),
[](const testing::TestParamInfo<nntrainerModelTest::ParamType> &info)
-> const auto & { return std::get<1>(info.param); });

0 comments on commit b51af11

Please sign in to comment.