Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nnfw_tests] Move a test from wrong location #13545

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions tests/nnfw_api/src/GenModelTests/BranchModelTrain.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,26 @@ TEST_F(GenModelTrain, BranchOps_FC_Add)

SUCCEED();
}
}

TEST_F(GenModelTrain, BranchOps_FC_Sub)
{
// (( Input 0 )) --------------\
// |=> [ Sub ] -> (( Output 0 ))
// (( Input 1 )) -> [ FC ] ----/
// (( Input 0 )) -> [ FC ] -> (fc_out) --------------------------╲
// ╲ |=> [ Add ] -> (( Output 0 ))
// ╲-> [ Relu6 ]⎼> (ea_out) -╱
{
CirclePlusGen cgen;

uint32_t weight_buf = cgen.addBuffer(std::vector<float>(8 * 2, 0.f));
uint32_t bias_buf = cgen.addBuffer(std::vector<float>(8, 0.f));
int input0 = cgen.addTensor({{1, 8}, circle::TensorType::TensorType_FLOAT32});
int input1 = cgen.addTensor({{1, 2}, circle::TensorType::TensorType_FLOAT32});
int input0 = cgen.addTensor({{1, 2}, circle::TensorType::TensorType_FLOAT32});
int weight = cgen.addTensor({{8, 2}, circle::TensorType::TensorType_FLOAT32, weight_buf});
int bias = cgen.addTensor({{8}, circle::TensorType::TensorType_FLOAT32, bias_buf});
int fc_output = cgen.addTensor({{1, 8}, circle::TensorType::TensorType_FLOAT32});
int ea_output = cgen.addTensor({{1, 8}, circle::TensorType::TensorType_FLOAT32});
int output = cgen.addTensor({{1, 8}, circle::TensorType::TensorType_FLOAT32});
cgen.addOperatorFullyConnected({{input1, weight, bias}, {fc_output}});
cgen.addOperatorSub({{input0, fc_output}, {output}},
cgen.addOperatorFullyConnected({{input0, weight, bias}, {fc_output}});
cgen.addOperatorRelu6({{fc_output}, {ea_output}});
cgen.addOperatorAdd({{fc_output, ea_output}, {output}},
circle::ActivationFunctionType::ActivationFunctionType_NONE);
cgen.setInputsAndOutputs({input0, input1}, {output});
cgen.setInputsAndOutputs({input0}, {output});

float learning_rate = 0.01f;
int32_t batch_size = 1;
Expand All @@ -87,37 +85,40 @@ TEST_F(GenModelTrain, BranchOps_FC_Sub)
NNFW_TRAIN_TRAINABLE_ALL});

_context = std::make_unique<GenModelTrainContext>(cgen.finish());
_context->addTrainCase(uniformTCD<float>(
{{{0, 1, 2, 3, 4, 5, 1, 3}, {6, 7}}, {{5, 4, 3, 2, 1, 0, 2, 1}, {7, 6}}}, // inputs
{{{2, 1, 5, 5, 2, 1, 5, 5}}, {{2, 1, 5, 5, 2, 1, 5, 6}}}, // expected
{{7.3265f}, {4.6811f}, {3.6735f}, {3.2863f}} // loss
));
_context->addTrainCase(
uniformTCD<float>({{{1, 3}}, {{2, 1}}}, // inputs
{{{2, 1, 5, 5, 2, 1, 5, 5}}, {{2, 1, 5, 5, 2, 1, 5, 6}}}, // expected
// TODO Modify loss values to results of tensorflow
{{14.0124f}, {11.0036f}, {8.1681f}, {6.0974f}} // loss
));

_context->setBackends({"train"});
_context->setEpoch(4);

SUCCEED();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block just moved from BranchOps_FC_Sub.

}

// (( Input 0 )) -> [ FC ] -> (fc_out) --------------------------╲
// ╲ |=> [ Add ] -> (( Output 0 ))
// ╲-> [ Relu6 ]⎼> (ea_out) -╱
TEST_F(GenModelTrain, BranchOps_FC_Sub)
{
// (( Input 0 )) --------------\
// |=> [ Sub ] -> (( Output 0 ))
// (( Input 1 )) -> [ FC ] ----/
{
CirclePlusGen cgen;

uint32_t weight_buf = cgen.addBuffer(std::vector<float>(8 * 2, 0.f));
uint32_t bias_buf = cgen.addBuffer(std::vector<float>(8, 0.f));
int input0 = cgen.addTensor({{1, 2}, circle::TensorType::TensorType_FLOAT32});
int input0 = cgen.addTensor({{1, 8}, circle::TensorType::TensorType_FLOAT32});
int input1 = cgen.addTensor({{1, 2}, circle::TensorType::TensorType_FLOAT32});
int weight = cgen.addTensor({{8, 2}, circle::TensorType::TensorType_FLOAT32, weight_buf});
int bias = cgen.addTensor({{8}, circle::TensorType::TensorType_FLOAT32, bias_buf});
int fc_output = cgen.addTensor({{1, 8}, circle::TensorType::TensorType_FLOAT32});
int ea_output = cgen.addTensor({{1, 8}, circle::TensorType::TensorType_FLOAT32});
int output = cgen.addTensor({{1, 8}, circle::TensorType::TensorType_FLOAT32});
cgen.addOperatorFullyConnected({{input0, weight, bias}, {fc_output}});
cgen.addOperatorRelu6({{fc_output}, {ea_output}});
cgen.addOperatorAdd({{fc_output, ea_output}, {output}},
cgen.addOperatorFullyConnected({{input1, weight, bias}, {fc_output}});
cgen.addOperatorSub({{input0, fc_output}, {output}},
circle::ActivationFunctionType::ActivationFunctionType_NONE);
cgen.setInputsAndOutputs({input0}, {output});
cgen.setInputsAndOutputs({input0, input1}, {output});

float learning_rate = 0.01f;
int32_t batch_size = 1;
Expand All @@ -127,12 +128,11 @@ TEST_F(GenModelTrain, BranchOps_FC_Sub)
NNFW_TRAIN_TRAINABLE_ALL});

_context = std::make_unique<GenModelTrainContext>(cgen.finish());
_context->addTrainCase(
uniformTCD<float>({{{1, 3}}, {{2, 1}}}, // inputs
{{{2, 1, 5, 5, 2, 1, 5, 5}}, {{2, 1, 5, 5, 2, 1, 5, 6}}}, // expected
// TODO Modify loss values to results of tensorflow
{{14.0124f}, {11.0036f}, {8.1681f}, {6.0974f}} // loss
));
_context->addTrainCase(uniformTCD<float>(
{{{0, 1, 2, 3, 4, 5, 1, 3}, {6, 7}}, {{5, 4, 3, 2, 1, 0, 2, 1}, {7, 6}}}, // inputs
{{{2, 1, 5, 5, 2, 1, 5, 5}}, {{2, 1, 5, 5, 2, 1, 5, 6}}}, // expected
{{7.3265f}, {4.6811f}, {3.6735f}, {3.2863f}} // loss
));

_context->setBackends({"train"});
_context->setEpoch(4);
Expand Down