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

PDPD: Install generated PDPD test models as 'test' component #6783

Merged
merged 3 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion .ci/azure/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ jobs:
displayName: 'Model Optimizer UT'
continueOnError: false

- script: . $(SETUPVARS) && $(INSTALL_TEST_DIR)/unit-test --gtest_print_time=1 --gtest_filter=-backend_api.config_unsupported:*IE_GPU* --gtest_output=xml:TEST-NGraphUT.xml
- script: |
export FE_TEST_MODELS=$(INSTALL_DIR)/tests
. $(SETUPVARS) && $(INSTALL_TEST_DIR)/unit-test --gtest_print_time=1 --gtest_filter=-backend_api.config_unsupported:*IE_GPU* --gtest_output=xml:TEST-NGraphUT.xml
displayName: 'nGraph UT'
continueOnError: false

Expand Down
12 changes: 10 additions & 2 deletions ngraph/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -549,15 +549,18 @@ file(GLOB FRONTEND_SHARED_TESTS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/frontend/shared/
file(GLOB FRONTEND_SHARED_TESTS_HDR ${CMAKE_CURRENT_SOURCE_DIR}/frontend/shared/include/*.hpp)
set(SRC ${FRONTEND_SHARED_TESTS_SRC} ${SRC})

add_definitions("-DTEST_MODEL_BUILD_DIR=\"${CMAKE_CURRENT_BINARY_DIR}\"")

# ---- PaddlePaddle FrontEnd testing ------
if (NGRAPH_PDPD_FRONTEND_ENABLE)
ie_check_pip_package(paddlepaddle WARNING)

if(paddlepaddle_FOUND)
file(GLOB FRONTEND_PDPD_TESTS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/frontend/paddlepaddle/*.cpp)
set(SRC ${FRONTEND_PDPD_TESTS_SRC} ${SRC})
set(TEST_PDPD_MODELS ${CMAKE_CURRENT_BINARY_DIR}/pdpd_test_models/)
add_definitions("-DTEST_PDPD_MODELS=\"${TEST_PDPD_MODELS}\"")
set(PDPD_TEST_MODELS_DIRNAME pdpd_test_models)
set(TEST_PDPD_MODELS ${CMAKE_CURRENT_BINARY_DIR}/${PDPD_TEST_MODELS_DIRNAME}/)
add_definitions("-DTEST_PDPD_MODELS_DIRNAME=\"${PDPD_TEST_MODELS_DIRNAME}/\"")
endif()
endif()
# ---- End PaddlePaddle FrontEnd testing ------
Expand Down Expand Up @@ -657,4 +660,9 @@ if (NGRAPH_PDPD_FRONTEND_ENABLE AND paddlepaddle_FOUND)
add_custom_target(pdpd_test_models DEPENDS ${OUT_FILES})
add_dependencies(unit-test pdpd_test_models)
add_dependencies(unit-test paddlepaddle_ngraph_frontend)

install(DIRECTORY ${TEST_PDPD_MODELS}
DESTINATION tests/${PDPD_TEST_MODELS_DIRNAME}
COMPONENT tests
EXCLUDE_FROM_ALL)
endif()
13 changes: 7 additions & 6 deletions ngraph/test/frontend/paddlepaddle/basic_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ static const std::vector<std::string> models{
std::string("2in_2out_dynbatch/2in_2out_dynbatch.pdmodel"),
};

INSTANTIATE_TEST_SUITE_P(PDPDBasicTest,
FrontEndBasicTest,
::testing::Combine(::testing::Values(PDPD),
::testing::Values(std::string(TEST_PDPD_MODELS)),
::testing::ValuesIn(models)),
FrontEndBasicTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(
PDPDBasicTest,
FrontEndBasicTest,
::testing::Combine(::testing::Values(PDPD),
::testing::Values(std::string(TEST_PDPD_MODELS_DIRNAME)),
::testing::ValuesIn(models)),
FrontEndBasicTest::getTestCaseName);
2 changes: 1 addition & 1 deletion ngraph/test/frontend/paddlepaddle/cut_specific_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static CutModelParam getTestData_2in_2out()
{
CutModelParam res;
res.m_frontEndName = PDPD;
res.m_modelsPath = std::string(TEST_PDPD_MODELS);
res.m_modelsPath = std::string(TEST_PDPD_MODELS_DIRNAME);
res.m_modelName = "2in_2out/2in_2out.pdmodel";
res.m_oldInputs = {"inputX1", "inputX2"};
res.m_newInputs = {"add1.tmp_0"};
Expand Down
2 changes: 1 addition & 1 deletion ngraph/test/frontend/paddlepaddle/load_from.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static LoadFromFEParam getTestData()
{
LoadFromFEParam res;
res.m_frontEndName = PDPD;
res.m_modelsPath = std::string(TEST_PDPD_MODELS);
res.m_modelsPath = std::string(TEST_PDPD_MODELS_DIRNAME);
res.m_file = "conv2d";
res.m_files = {"2in_2out/2in_2out.pdmodel", "2in_2out/2in_2out.pdiparams"};
res.m_stream = "relu/relu.pdmodel";
Expand Down
13 changes: 7 additions & 6 deletions ngraph/test/frontend/paddlepaddle/op_fuzzy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ static const std::vector<std::string> models{
std::string("relu"),
};

INSTANTIATE_TEST_SUITE_P(PDPDFuzzyOpTest,
FrontEndFuzzyOpTest,
::testing::Combine(::testing::Values(PDPD),
::testing::Values(std::string(TEST_PDPD_MODELS)),
::testing::ValuesIn(models)),
PDPDFuzzyOpTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(
PDPDFuzzyOpTest,
FrontEndFuzzyOpTest,
::testing::Combine(::testing::Values(PDPD),
::testing::Values(std::string(TEST_PDPD_MODELS_DIRNAME)),
::testing::ValuesIn(models)),
PDPDFuzzyOpTest::getTestCaseName);
2 changes: 1 addition & 1 deletion ngraph/test/frontend/paddlepaddle/partial_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static PartShape getTestShape_conv2d_relu()
INSTANTIATE_TEST_SUITE_P(PDPDPartialShapeTest,
FrontEndPartialShapeTest,
::testing::Combine(::testing::Values(BaseFEParam{
PDPD, std::string(TEST_PDPD_MODELS)}),
PDPD, std::string(TEST_PDPD_MODELS_DIRNAME)}),
::testing::ValuesIn(std::vector<PartShape>{
getTestShape_2in_2out(),
getTestShape_conv2d_relu(),
Expand Down
29 changes: 15 additions & 14 deletions ngraph/test/frontend/paddlepaddle/places.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

using namespace ngraph::frontend;

const std::string model_file = "place_test_model/place_test_model.pdmodel";
const std::string model_file =
std::string(TEST_PDPD_MODELS_DIRNAME) + "place_test_model/place_test_model.pdmodel";

/***
model:
Expand Down Expand Up @@ -57,7 +58,7 @@ TEST(PDPD_Places, check_tensor_names)
FrontEndTestUtils::setupTestEnv();
auto m_fem = FrontEndManager();
auto frontend = m_fem.load_by_framework("pdpd");
auto input_model = frontend->load(TEST_PDPD_MODELS + model_file);
auto input_model = frontend->load(FrontEndTestUtils::make_model_path(model_file));

for (const auto& tensor_name : tensor_names)
{
Expand All @@ -71,7 +72,7 @@ TEST(PDPD_Places, check_input_outputs)
FrontEndTestUtils::setupTestEnv();
auto m_fem = FrontEndManager();
auto frontend = m_fem.load_by_framework("pdpd");
auto input_model = frontend->load(TEST_PDPD_MODELS + model_file);
auto input_model = frontend->load(FrontEndTestUtils::make_model_path(model_file));

auto inputs = input_model->get_inputs();
auto outputs = input_model->get_outputs();
Expand Down Expand Up @@ -106,7 +107,7 @@ TEST(PDPD_Places, check_out_port_of_all_ops)
FrontEndTestUtils::setupTestEnv();
auto m_fem = FrontEndManager();
auto frontend = m_fem.load_by_framework("pdpd");
auto input_model = frontend->load(TEST_PDPD_MODELS + model_file);
auto input_model = frontend->load(FrontEndTestUtils::make_model_path(model_file));

for (const auto& tensor_name : tensor_names)
{
Expand All @@ -129,7 +130,7 @@ TEST(PDPD_Places, check_in_out_ports_of_model_outputs)
FrontEndTestUtils::setupTestEnv();
auto m_fem = FrontEndManager();
auto frontend = m_fem.load_by_framework("pdpd");
auto input_model = frontend->load(TEST_PDPD_MODELS + model_file);
auto input_model = frontend->load(FrontEndTestUtils::make_model_path(model_file));

auto outputs = input_model->get_outputs();
for (const auto& output : outputs)
Expand Down Expand Up @@ -164,7 +165,7 @@ TEST(PDPD_Places, check_source_target_tensors_of_model_outputs)
FrontEndTestUtils::setupTestEnv();
auto m_fem = FrontEndManager();
auto frontend = m_fem.load_by_framework("pdpd");
auto input_model = frontend->load(TEST_PDPD_MODELS + model_file);
auto input_model = frontend->load(FrontEndTestUtils::make_model_path(model_file));

auto outputs = input_model->get_outputs();
for (const auto& output : outputs)
Expand Down Expand Up @@ -199,7 +200,7 @@ TEST(PDPD_Places, check_producing_consuming_ops_of_model_outputs)
FrontEndTestUtils::setupTestEnv();
auto m_fem = FrontEndManager();
auto frontend = m_fem.load_by_framework("pdpd");
auto input_model = frontend->load(TEST_PDPD_MODELS + model_file);
auto input_model = frontend->load(FrontEndTestUtils::make_model_path(model_file));

auto outputs = input_model->get_outputs();
for (const auto& output : outputs)
Expand Down Expand Up @@ -235,7 +236,7 @@ TEST(PDPD_Places, check_data_flow)
FrontEndTestUtils::setupTestEnv();
auto m_fem = FrontEndManager();
auto frontend = m_fem.load_by_framework("pdpd");
auto input_model = frontend->load(TEST_PDPD_MODELS + model_file);
auto input_model = frontend->load(FrontEndTestUtils::make_model_path(model_file));

for (const auto& tensor_name : tensor_names)
{
Expand Down Expand Up @@ -276,7 +277,7 @@ TEST(PDPD_Places, check_tensor_to_multiple_ports)
FrontEndTestUtils::setupTestEnv();
auto m_fem = FrontEndManager();
auto frontend = m_fem.load_by_framework("pdpd");
auto input_model = frontend->load(TEST_PDPD_MODELS + model_file);
auto input_model = frontend->load(FrontEndTestUtils::make_model_path(model_file));

for (const auto& tensor_name : tensor_names)
{
Expand Down Expand Up @@ -308,7 +309,7 @@ TEST(PDPD_Places, check_consuming_ops)
FrontEndTestUtils::setupTestEnv();
auto m_fem = FrontEndManager();
auto frontend = m_fem.load_by_framework("pdpd");
auto input_model = frontend->load(TEST_PDPD_MODELS + model_file);
auto input_model = frontend->load(FrontEndTestUtils::make_model_path(model_file));

for (const auto& tensor_name : tensor_names)
{
Expand Down Expand Up @@ -353,7 +354,7 @@ TEST(PDPD_Places, check_consuming_ops_2)
FrontEndTestUtils::setupTestEnv();
auto m_fem = FrontEndManager();
auto frontend = m_fem.load_by_framework("pdpd");
auto input_model = frontend->load(TEST_PDPD_MODELS + model_file);
auto input_model = frontend->load(FrontEndTestUtils::make_model_path(model_file));

auto it = find(tensor_names.begin(), tensor_names.end(), "lstm_0.tmp_2");
EXPECT_NE(it, tensor_names.end());
Expand Down Expand Up @@ -395,7 +396,7 @@ TEST(PDPD_Places, check_producing_ops)
FrontEndTestUtils::setupTestEnv();
auto m_fem = FrontEndManager();
auto frontend = m_fem.load_by_framework("pdpd");
auto input_model = frontend->load(TEST_PDPD_MODELS + model_file);
auto input_model = frontend->load(FrontEndTestUtils::make_model_path(model_file));

for (const auto& tensor_name : tensor_names)
{
Expand All @@ -419,7 +420,7 @@ TEST(PDPD_Places, check_input_output_ports_dy_idx)
FrontEndTestUtils::setupTestEnv();
auto m_fem = FrontEndManager();
auto frontend = m_fem.load_by_framework("pdpd");
auto input_model = frontend->load(TEST_PDPD_MODELS + model_file);
auto input_model = frontend->load(FrontEndTestUtils::make_model_path(model_file));

std::vector<std::string> output_names = {"save_infer_model/scale_0.tmp_1",
"save_infer_model/scale_1.tmp_1",
Expand All @@ -446,7 +447,7 @@ TEST(PDPD_Places, check_ops_tensors_by_idx)
FrontEndTestUtils::setupTestEnv();
auto m_fem = FrontEndManager();
auto frontend = m_fem.load_by_framework("pdpd");
auto input_model = frontend->load(TEST_PDPD_MODELS + model_file);
auto input_model = frontend->load(FrontEndTestUtils::make_model_path(model_file));

std::vector<std::string> output_names = {"save_infer_model/scale_0.tmp_1",
"save_infer_model/scale_1.tmp_1",
Expand Down
2 changes: 1 addition & 1 deletion ngraph/test/frontend/paddlepaddle/set_element_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static SetTypeFEParam getTestData_relu()
{
SetTypeFEParam res;
res.m_frontEndName = PDPD;
res.m_modelsPath = std::string(TEST_PDPD_MODELS);
res.m_modelsPath = std::string(TEST_PDPD_MODELS_DIRNAME);
res.m_modelName = "relu/relu.pdmodel";
return res;
}
Expand Down
23 changes: 23 additions & 0 deletions ngraph/test/frontend/shared/include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

#pragma once

#include <fstream>
#include <string>
#include "backend.hpp"
#include "ngraph/env_util.hpp"
#include "ngraph/file_util.hpp"

// Helper functions
Expand Down Expand Up @@ -46,4 +48,25 @@ namespace FrontEndTestUtils
ngraph::runtime::Backend::get_backend_shared_library_search_directory());
set_test_env("OV_FRONTEND_PATH", fePath.c_str());
}

inline bool exists(const std::string& file)
{
std::ifstream str(file, std::ios::in | std::ifstream::binary);
return str.is_open();
}

inline std::string make_model_path(const std::string& modelsRelativePath)
{
// First try build path
auto res = std::string(TEST_MODEL_BUILD_DIR) + "/" + modelsRelativePath;
if (exists(res))
{
return res;
}
else
{
// Install case: if model file does not exist, use base path from env variable
return std::string(ngraph::getenv_string("FE_TEST_MODELS")) + "/" + modelsRelativePath;
}
}
} // namespace FrontEndTestUtils
2 changes: 1 addition & 1 deletion ngraph/test/frontend/shared/src/basic_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void FrontEndBasicTest::SetUp()
void FrontEndBasicTest::initParamTest()
{
std::tie(m_feName, m_pathToModels, m_modelFile) = GetParam();
m_modelFile = m_pathToModels + m_modelFile;
m_modelFile = FrontEndTestUtils::make_model_path(m_pathToModels + m_modelFile);
}

void FrontEndBasicTest::doLoadFromFile()
Expand Down
3 changes: 2 additions & 1 deletion ngraph/test/frontend/shared/src/cut_specific_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ void FrontEndCutModelTest::SetUp()
void FrontEndCutModelTest::initParamTest()
{
m_param = GetParam();
m_param.m_modelName = m_param.m_modelsPath + m_param.m_modelName;
m_param.m_modelName =
FrontEndTestUtils::make_model_path(m_param.m_modelsPath + m_param.m_modelName);
}

void FrontEndCutModelTest::doLoadFromFile()
Expand Down
24 changes: 15 additions & 9 deletions ngraph/test/frontend/shared/src/load_from.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ void FrontEndLoadFromTest::SetUp()

TEST_P(FrontEndLoadFromTest, testLoadFromFilePath)
{
std::string model_path = m_param.m_modelsPath + m_param.m_file;
std::string model_path =
FrontEndTestUtils::make_model_path(m_param.m_modelsPath + m_param.m_file);
std::vector<std::string> frontends;
FrontEnd::Ptr fe;
ASSERT_NO_THROW(frontends = m_fem.get_available_front_ends());
Expand All @@ -44,8 +45,10 @@ TEST_P(FrontEndLoadFromTest, testLoadFromFilePath)

TEST_P(FrontEndLoadFromTest, testLoadFromTwoFiles)
{
std::string model_path = m_param.m_modelsPath + m_param.m_files[0];
std::string weights_path = m_param.m_modelsPath + m_param.m_files[1];
std::string model_path =
FrontEndTestUtils::make_model_path(m_param.m_modelsPath + m_param.m_files[0]);
std::string weights_path =
FrontEndTestUtils::make_model_path(m_param.m_modelsPath + m_param.m_files[1]);
std::vector<std::string> frontends;
FrontEnd::Ptr fe;
ASSERT_NO_THROW(frontends = m_fem.get_available_front_ends());
Expand All @@ -62,8 +65,9 @@ TEST_P(FrontEndLoadFromTest, testLoadFromTwoFiles)

TEST_P(FrontEndLoadFromTest, testLoadFromStream)
{
auto ifs = std::make_shared<std::ifstream>(m_param.m_modelsPath + m_param.m_stream,
std::ios::in | std::ifstream::binary);
auto ifs = std::make_shared<std::ifstream>(
FrontEndTestUtils::make_model_path(m_param.m_modelsPath + m_param.m_stream),
std::ios::in | std::ifstream::binary);
auto is = std::dynamic_pointer_cast<std::istream>(ifs);
std::vector<std::string> frontends;
FrontEnd::Ptr fe;
Expand All @@ -81,10 +85,12 @@ TEST_P(FrontEndLoadFromTest, testLoadFromStream)

TEST_P(FrontEndLoadFromTest, testLoadFromTwoStreams)
{
auto model_ifs = std::make_shared<std::ifstream>(m_param.m_modelsPath + m_param.m_streams[0],
std::ios::in | std::ifstream::binary);
auto weights_ifs = std::make_shared<std::ifstream>(m_param.m_modelsPath + m_param.m_streams[1],
std::ios::in | std::ifstream::binary);
auto model_ifs = std::make_shared<std::ifstream>(
FrontEndTestUtils::make_model_path(m_param.m_modelsPath + m_param.m_streams[0]),
std::ios::in | std::ifstream::binary);
auto weights_ifs = std::make_shared<std::ifstream>(
FrontEndTestUtils::make_model_path(m_param.m_modelsPath + m_param.m_streams[1]),
std::ios::in | std::ifstream::binary);
auto model_is = std::dynamic_pointer_cast<std::istream>(model_ifs);
auto weights_is = std::dynamic_pointer_cast<std::istream>(weights_ifs);

Expand Down
2 changes: 1 addition & 1 deletion ngraph/test/frontend/shared/src/op_fuzzy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void FrontEndFuzzyOpTest::SetUp()
void FrontEndFuzzyOpTest::initParamTest()
{
std::tie(m_feName, m_pathToModels, m_modelFile) = GetParam();
m_modelFile = m_pathToModels + m_modelFile;
m_modelFile = FrontEndTestUtils::make_model_path(m_pathToModels + m_modelFile);
}

void FrontEndFuzzyOpTest::doLoadFromFile()
Expand Down
3 changes: 2 additions & 1 deletion ngraph/test/frontend/shared/src/partial_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ void FrontEndPartialShapeTest::SetUp()
void FrontEndPartialShapeTest::initParamTest()
{
std::tie(m_baseParam, m_partShape) = GetParam();
m_partShape.m_modelName = m_baseParam.m_modelsPath + m_partShape.m_modelName;
m_partShape.m_modelName =
FrontEndTestUtils::make_model_path(m_baseParam.m_modelsPath + m_partShape.m_modelName);
}

void FrontEndPartialShapeTest::doLoadFromFile()
Expand Down
3 changes: 2 additions & 1 deletion ngraph/test/frontend/shared/src/set_element_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ void FrontEndElementTypeTest::SetUp()
void FrontEndElementTypeTest::initParamTest()
{
m_param = GetParam();
m_param.m_modelName = m_param.m_modelsPath + m_param.m_modelName;
m_param.m_modelName =
FrontEndTestUtils::make_model_path(m_param.m_modelsPath + m_param.m_modelName);
}

void FrontEndElementTypeTest::doLoadFromFile()
Expand Down