-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Frontend][Paddle]Handle Exception in Op Conversion. (#7296)
* [Frontend][Paddle]Handle Exception in Op Conversion. * [Frontend][Paddle]revise comments * [Frontend][Paddle]add tests for error handling * [Frontend]fix typo * [Frontend][Paddle]relax model version check to 2.0.0 * [Frontend][Paddle]fix typo
- Loading branch information
1 parent
0bc17a2
commit f1f7376
Showing
5 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
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
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
39 changes: 39 additions & 0 deletions
39
ngraph/test/frontend/paddlepaddle/test_models/gen_scripts/generate_lower_version.py
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,39 @@ | ||
import paddle | ||
import numpy as np | ||
import os | ||
import sys | ||
from paddle.fluid.proto import framework_pb2 | ||
|
||
paddle.enable_static() | ||
|
||
inp_blob = np.random.randn(1, 3, 4, 4).astype(np.float32) | ||
print(sys.path) | ||
main_program = paddle.static.Program() | ||
startup_program = paddle.static.Program() | ||
|
||
with paddle.static.program_guard(main_program, startup_program): | ||
x = paddle.static.data(name='x', shape=[1, 3, 4, 4], dtype='float32') | ||
test_layer = paddle.static.nn.conv2d(input=x, num_filters=5, filter_size=(1, 1), stride=(1, 1), padding=(1, 1), | ||
dilation=(1, 1), groups=1, bias_attr=False) | ||
|
||
cpu = paddle.static.cpu_places(1) | ||
exe = paddle.static.Executor(cpu[0]) | ||
exe.run(startup_program) | ||
inp_dict = {'x': inp_blob} | ||
var = [test_layer] | ||
res_paddle = exe.run(paddle.static.default_main_program(), fetch_list=var, feed=inp_dict) | ||
paddle.static.save_inference_model(os.path.join(sys.argv[1], "lower_version/", "lower_version"), [x], [test_layer], exe, program=main_program) | ||
|
||
|
||
fw_model = framework_pb2.ProgramDesc() | ||
with open(os.path.join(sys.argv[1], "lower_version", "lower_version.pdmodel"), mode='rb') as file: | ||
fw_model.ParseFromString(file.read()) | ||
|
||
fw_model.version.version = 1800000 | ||
print(fw_model.version.version) | ||
with open(os.path.join(sys.argv[1], "lower_version", "lower_version.pdmodel"), "wb") as f: | ||
f.write(fw_model.SerializeToString()) | ||
|
||
|
||
|
||
|
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
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,39 @@ | ||
// Copyright (C) 2018-2021 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <frontend_manager/frontend_exceptions.hpp> | ||
#include <frontend_manager/frontend_manager.hpp> | ||
|
||
#include "common_test_utils/ngraph_test_utils.hpp" | ||
#include "paddle_utils.hpp" | ||
#include "utils.hpp" | ||
|
||
using namespace ngraph; | ||
using namespace ngraph::frontend; | ||
|
||
TEST(FrontEndConvertModelTest, throw_in_conversion) { | ||
FrontEndManager fem; | ||
FrontEnd::Ptr frontEnd; | ||
InputModel::Ptr inputModel; | ||
ASSERT_NO_THROW(frontEnd = fem.load_by_framework(PADDLE_FE)); | ||
ASSERT_NE(frontEnd, nullptr); | ||
auto model_filename = FrontEndTestUtils::make_model_path( | ||
std::string(TEST_PADDLE_MODELS_DIRNAME) + std::string("throw_in_conversion/throw_in_conversion.pdmodel")); | ||
ASSERT_NO_THROW(inputModel = frontEnd->load(model_filename)); | ||
ASSERT_NE(inputModel, nullptr); | ||
std::shared_ptr<ngraph::Function> function; | ||
ASSERT_THROW(function = frontEnd->convert(inputModel), OpConversionFailure); | ||
} | ||
|
||
TEST(FrontEndConvertModelTest, unsupported_version) { | ||
FrontEndManager fem; | ||
FrontEnd::Ptr frontEnd; | ||
InputModel::Ptr inputModel; | ||
ASSERT_NO_THROW(frontEnd = fem.load_by_framework(PADDLE_FE)); | ||
ASSERT_NE(frontEnd, nullptr); | ||
auto model_filename = FrontEndTestUtils::make_model_path(std::string(TEST_PADDLE_MODELS_DIRNAME) + | ||
std::string("lower_version/lower_version.pdmodel")); | ||
|
||
ASSERT_THROW(inputModel = frontEnd->load(model_filename), GeneralFailure); | ||
} |