-
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.
[PDPD] fix ops for baidu customer (#27222)
### Details: - *fix the negative dim issue when run into `reduce_fusion` pass* - *enable eye op* - *enable elu op* - *add tests* - *upgrade paddlepaddle to 2.6.2* - *upgrade opset to 14 version* ### Tickets: - *N/A*
- Loading branch information
Showing
11 changed files
with
175 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "default_opset.hpp" | ||
#include "openvino/frontend/paddle/node_context.hpp" | ||
#include "openvino/frontend/paddle/visibility.hpp" | ||
|
||
namespace ov { | ||
namespace frontend { | ||
namespace paddle { | ||
namespace op { | ||
NamedOutputs elu(const NodeContext& node) { | ||
auto data = node.get_input("X"); | ||
auto alpha = node.get_attribute<float>("alpha", 1.0); | ||
const auto& elu_node = std::make_shared<default_opset::Elu>(data, alpha); | ||
return node.default_single_output_mapping({elu_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
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,36 @@ | ||
// Copyright (C) 2018-2024 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 eye(const NodeContext& node) { | ||
auto row = node.get_attribute<int64_t>("num_rows"); | ||
auto col = node.get_attribute<int64_t>("num_columns", row); | ||
auto dtype = node.get_attribute<ov::element::Type>("dtype", ov::element::f32); | ||
|
||
const auto& row_node = std::make_shared<default_opset::Constant>(ov::element::i64, Shape{}, (row)); | ||
const auto& col_node = std::make_shared<default_opset::Constant>(ov::element::i64, Shape{}, (col)); | ||
const auto& diagonal_index_node = std::make_shared<default_opset::Constant>(ov::element::i32, Shape{}, (0)); | ||
|
||
std::shared_ptr<Node> out_node; | ||
if (dtype == ov::element::i32 || dtype == ov::element::i64) { | ||
out_node = std::make_shared<default_opset::Eye>(row_node, col_node, diagonal_index_node, dtype); | ||
} else { | ||
const auto& eye_node = | ||
std::make_shared<default_opset::Eye>(row_node, col_node, diagonal_index_node, ov::element::i32); | ||
out_node = std::make_shared<default_opset::Convert>(eye_node, dtype); | ||
} | ||
|
||
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
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
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
44 changes: 44 additions & 0 deletions
44
src/frontends/paddle/tests/test_models/gen_scripts/generate_elu.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,44 @@ | ||
# Copyright (C) 2018-2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# | ||
# relu6 paddle model generator | ||
# | ||
import numpy as np | ||
from save_model import saveModel | ||
import paddle | ||
import sys | ||
|
||
|
||
def elu(name: str, x, alpha=None, data_type='float32'): | ||
paddle.enable_static() | ||
|
||
with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): | ||
node_x = paddle.static.data(name='x', shape=x.shape, dtype=data_type) | ||
|
||
if paddle.__version__ >= '2.0.0': | ||
out = paddle.nn.functional.elu(node_x, alpha, name='elu') | ||
else: | ||
out = paddle.fluid.layers.elu(node_x, alpha, name='elu') | ||
cpu = paddle.static.cpu_places(1) | ||
exe = paddle.static.Executor(cpu[0]) | ||
# startup program will call initializer to initialize the parameters. | ||
exe.run(paddle.static.default_startup_program()) | ||
|
||
outs = exe.run( | ||
feed={'x': x}, | ||
fetch_list=[out]) | ||
|
||
saveModel(name, exe, feed_vars=[node_x], fetchlist=[out], | ||
inputs=[x], outputs=[outs[0]], target_dir=sys.argv[1]) | ||
|
||
return outs[0] | ||
|
||
|
||
def main(): | ||
data_type = 'float32' | ||
data = np.random.randn(2, 3, 4).astype('float32') | ||
elu("elu", data) | ||
|
||
if __name__ == "__main__": | ||
main() |
41 changes: 41 additions & 0 deletions
41
src/frontends/paddle/tests/test_models/gen_scripts/generate_eye.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,41 @@ | ||
# Copyright (C) 2018-2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# | ||
# fill_const paddle model generator | ||
# | ||
import numpy as np | ||
from save_model import saveModel | ||
import paddle | ||
import sys | ||
|
||
|
||
def eye(name : str, rows, cols = None, dtype = None): | ||
paddle.enable_static() | ||
with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): | ||
if paddle.__version__ >= '2.0.0': | ||
x1 = paddle.eye(num_rows=rows, num_columns=cols, dtype=dtype, name='fill') | ||
x2 = paddle.eye(num_rows=rows, num_columns=cols, dtype=dtype, name='fill') | ||
else: | ||
x1 = paddle.fluid.layers.eye(num_rows=rows, num_columns=cols, dtype=dtype, name='fill_constant') | ||
x2 = paddle.fluid.layers.eye(num_rows=rows, num_columns=cols, dtype=dtype, name='fill_constant') | ||
out = paddle.add(x1, x2) | ||
cpu = paddle.static.cpu_places(1) | ||
exe = paddle.static.Executor(cpu[0]) | ||
# startup program will call initializer to initialize the parameters. | ||
exe.run(paddle.static.default_startup_program()) | ||
|
||
outs = exe.run( | ||
fetch_list=[out]) | ||
|
||
saveModel(name, exe, feed_vars=[], fetchlist=[out], inputs=[], outputs=[outs[0]], target_dir=sys.argv[1]) | ||
|
||
return outs[0] | ||
|
||
def main(): | ||
eye("eye", 3) | ||
eye("eye_int32", 2, 3, "int32") | ||
eye("eye_int64", 2, 3, "int64") | ||
|
||
if __name__ == "__main__": | ||
main() |