-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Unittest] FSU Unittest with Simple FC Model
Add Unittest for FSU - Use Simple FC Model that consist with 6-FC layer - FP16-FP16 / Lookahead 1 **Self evaluation:** 1. Build test: [X]Passed [ ]Failed [ ]Skipped 2. Run test: [X]Passed [ ]Failed [ ]Skipped Signed-off-by: Donghak PARK <[email protected]>
- Loading branch information
1 parent
18635c2
commit a159899
Showing
2 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
test/unittest/integration_tests/integration_test_fsu.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
/** | ||
* Copyright (C) 2024 Donghak Park <[email protected]> | ||
* | ||
* @file integration_test_fsu.cpp | ||
* @date 20 Dec 2024 | ||
* @brief Unit Test for Asynch FSU | ||
* @see https://github.com/nnstreamer/nntrainer | ||
* @author Donghak Park <[email protected]> | ||
* @bug No known bugs except for NYI items | ||
*/ | ||
|
||
#include <array> | ||
#include <chrono> | ||
#include <ctime> | ||
#include <gtest/gtest.h> | ||
#include <iostream> | ||
#include <layer.h> | ||
#include <memory> | ||
#include <model.h> | ||
#include <optimizer.h> | ||
#include <sstream> | ||
#include <vector> | ||
#include <app_context.h> | ||
|
||
using LayerHandle = std::shared_ptr<ml::train::Layer>; | ||
using ModelHandle = std::unique_ptr<ml::train::Model>; | ||
|
||
template <typename T> | ||
static std::string withKey(const std::string &key, const T &value) { | ||
std::stringstream ss; | ||
ss << key << "=" << value; | ||
return ss.str(); | ||
} | ||
|
||
template <typename T> | ||
static std::string withKey(const std::string &key, | ||
std::initializer_list<T> value) { | ||
if (std::empty(value)) { | ||
throw std::invalid_argument("empty data cannot be converted"); | ||
} | ||
|
||
std::stringstream ss; | ||
ss << key << "="; | ||
|
||
auto iter = value.begin(); | ||
for (; iter != value.end() - 1; ++iter) { | ||
ss << *iter << ','; | ||
} | ||
ss << *iter; | ||
|
||
return ss.str(); | ||
} | ||
|
||
TEST(fsu, simple_fc) { | ||
|
||
std::unique_ptr<ml::train::Model> model = ml::train::createModel( | ||
ml::train::ModelType::NEURAL_NET, {withKey("loss", "mse")}); | ||
|
||
model->addLayer( | ||
ml::train::createLayer("input", {withKey("name", "input0"), | ||
withKey("input_shape", "1:1:320")})); | ||
model->addLayer( | ||
ml::train::createLayer("fully_connected", | ||
{withKey("unit", 1000), | ||
withKey("weight_initializer", "xavier_uniform"), | ||
withKey("bias_initializer", "zeros")})); | ||
model->addLayer( | ||
ml::train::createLayer("fully_connected", | ||
{withKey("unit", 1000), | ||
withKey("weight_initializer", "xavier_uniform"), | ||
withKey("bias_initializer", "zeros")})); | ||
model->addLayer( | ||
ml::train::createLayer("fully_connected", | ||
{withKey("unit", 1000), | ||
withKey("weight_initializer", "xavier_uniform"), | ||
withKey("bias_initializer", "zeros")})); | ||
model->addLayer( | ||
ml::train::createLayer("fully_connected", | ||
{withKey("unit", 1000), | ||
withKey("weight_initializer", "xavier_uniform"), | ||
withKey("bias_initializer", "zeros")})); | ||
model->addLayer( | ||
ml::train::createLayer("fully_connected", | ||
{withKey("unit", 1000), | ||
withKey("weight_initializer", "xavier_uniform"), | ||
withKey("bias_initializer", "zeros")})); | ||
model->addLayer( | ||
ml::train::createLayer("fully_connected", | ||
{withKey("unit", 100), | ||
withKey("weight_initializer", "xavier_uniform"), | ||
withKey("bias_initializer", "zeros")})); | ||
|
||
model->setProperty({withKey("batch_size", 1), withKey("epochs", 1), | ||
withKey("memory_swap", "true"), | ||
withKey("memory_swap_lookahead", "1"), | ||
withKey("model_tensor_type", "FP16-FP16")}); | ||
|
||
auto optimizer = ml::train::createOptimizer("sgd", {"learning_rate=0.001"}); | ||
model->setOptimizer(std::move(optimizer)); | ||
|
||
int status = model->compile(ml::train::ExecutionMode::INFERENCE); | ||
EXPECT_EQ(status, ML_ERROR_NONE); | ||
|
||
status = model->initialize(ml::train::ExecutionMode::INFERENCE); | ||
EXPECT_EQ(status, ML_ERROR_NONE); | ||
|
||
model->save("simplefc_weight_fp16_fp16_100.bin", | ||
ml::train::ModelFormat::MODEL_FORMAT_BIN); | ||
model->load("./simplefc_weight_fp16_fp16_100.bin"); | ||
|
||
|
||
uint feature_size = 320; | ||
|
||
float input[320]; | ||
float label[1]; | ||
|
||
for (uint j = 0; j < feature_size; ++j) | ||
input[j] = j; | ||
|
||
std::vector<float *> in; | ||
std::vector<float *> l; | ||
std::vector<float *> answer; | ||
|
||
in.push_back(input); | ||
l.push_back(label); | ||
|
||
answer = model->inference(1, in, l); | ||
|
||
in.clear(); | ||
l.clear(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters