-
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.
- Loading branch information
1 parent
56808c7
commit b8cf8b2
Showing
4 changed files
with
100 additions
and
0 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
65 changes: 65 additions & 0 deletions
65
src/core/tests/frontend/paddle/test_models/gen_scripts/generate_sum.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,65 @@ | ||
# Copyright (C) 2018-2022 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# | ||
# stack paddle model generator | ||
# | ||
import numpy as np | ||
from save_model import saveModel | ||
import sys | ||
|
||
|
||
def sum(name:str, input1, input2, input3): | ||
import paddle | ||
paddle.enable_static() | ||
|
||
with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): | ||
data1 = paddle.static.data( | ||
'data1', shape=input1.shape, dtype=input1.dtype) | ||
data2 = paddle.static.data( | ||
'data2', shape=input2.shape, dtype=input2.dtype) | ||
data3 = paddle.static.data( | ||
'data3', shape=input3.shape, dtype=input3.dtype) | ||
|
||
out = paddle.fluid.layers.sum([data1, data2, data3]) | ||
cpu = paddle.static.cpu_places(1) | ||
exe = paddle.static.Executor(cpu[0]) | ||
exe.run(paddle.static.default_startup_program()) | ||
|
||
outs = exe.run( | ||
feed={"data1": input1, | ||
"data2": input2, | ||
"data3": input3}, | ||
fetch_list=[out]) | ||
saveModel(name, exe, feedkeys=['data1', 'data2', 'data3'], fetchlist=[out], inputs=[ | ||
input1, input2, input3], outputs=[outs[0]], target_dir=sys.argv[1]) | ||
|
||
return outs[0] | ||
|
||
|
||
def main(): | ||
|
||
in_type = np.float32 | ||
in_shape = [1, 5] | ||
input1 = np.random.random(in_shape).astype(in_type) | ||
input2 = np.random.random(in_shape).astype(in_type) | ||
input3 = np.random.random(in_shape).astype(in_type) | ||
sum("sum_float_1", input1, input2, input3) | ||
|
||
in_type = np.float32 | ||
in_shape = [5, 5] | ||
input1 = np.random.random(in_shape).astype(in_type) | ||
input2 = np.random.random(in_shape).astype(in_type) | ||
input3 = np.random.random(in_shape).astype(in_type) | ||
sum("sum_float_2", input1, input2, input3) | ||
|
||
in_type = np.float32 | ||
in_shape = [5, 10] | ||
input1 = np.random.random(in_shape).astype(in_type) | ||
input2 = np.random.random(in_shape).astype(in_type) | ||
input3 = np.random.random(in_shape).astype(in_type) | ||
sum("sum_float_3", input1, input2, input3) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,30 @@ | ||
// Copyright (C) 2018-2022 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
#include "default_opset.hpp" | ||
#include "openvino/frontend/paddle/node_context.hpp" | ||
|
||
namespace ov { | ||
namespace frontend { | ||
namespace paddle { | ||
namespace op { | ||
NamedOutputs sum(const NodeContext& node) { | ||
auto datas = node.get_ng_inputs("X"); | ||
auto data_type = datas[0].get_element_type(); | ||
auto data_shape = datas[0].get_shape(); | ||
std::shared_ptr<Node> out_node = datas[0].get_node_shared_ptr(); | ||
for (int i = 1; i < datas.size(); ++i) { | ||
PADDLE_OP_CHECK(node, | ||
data_type == datas[i].get_element_type(), | ||
"sum input tensor must have the same data types!"); | ||
PADDLE_OP_CHECK(node, | ||
data_shape == datas[i].get_shape(), | ||
"sum input tensor must have the same shape!"); | ||
out_node = std::make_shared<default_opset::Add>(datas[i], out_node); | ||
} | ||
return node.default_single_output_mapping({out_node}, {"Out"}); | ||
} | ||
} // namespace op | ||
} // namespace paddle | ||
} // namespace frontend | ||
} // namespace ov |
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