Skip to content

Commit 0aa6b07

Browse files
zhangYiIntelmangguo321luo-cheng2021
authored
[FrontEnd]enable pdpd ops conversion part3 (openvinotoolkit#6636)
* [FrontEnd]enable pdpd ops conversion part3 * Add adaptive pool2d op conversion (#1) * param support tensor (#2) * add missing sync_batch_norm * Update pow.cpp * deal empty axis (#5) * deal empty axis * apply review comments * fix code style * fix code style * change shape to i32 * fix code in shape * fix code style * fix paddle code style * remove redandent ops * fix maxAdativePool * fix expand_v2 * remove redandent code Co-authored-by: Mang Guo <[email protected]> Co-authored-by: Luo Cheng <[email protected]>
1 parent 6f23458 commit 0aa6b07

File tree

16 files changed

+1358
-50
lines changed

16 files changed

+1358
-50
lines changed

ngraph/frontend/paddlepaddle/src/op/expand_v2.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ namespace ngraph
6161
fixed_shape_node, input_shape_node, false);
6262

6363
return node.default_single_output_mapping(
64-
{std::make_shared<ngraph::opset6::Tile>(x, repeated_node)}, {"Out"});
64+
{std::make_shared<ngraph::opset6::Tile>(
65+
x,
66+
std::make_shared<ngraph::opset6::Convert>(repeated_node,
67+
element::i64))},
68+
{"Out"});
6569
}
6670

6771
} // namespace op
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright (C) 2018-2021 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#include <ngraph/opsets/opset6.hpp>
6+
#include <node_context.hpp>
7+
8+
namespace ngraph
9+
{
10+
namespace frontend
11+
{
12+
namespace pdpd
13+
{
14+
namespace op
15+
{
16+
NamedOutputs mul(const NodeContext& node)
17+
{
18+
auto x = node.get_ng_input("X");
19+
auto y = node.get_ng_input("Y");
20+
PDPD_OP_VALIDATION_CHECK(node,
21+
x.get_partial_shape().rank().is_static(),
22+
"matmul: X rank must be static!");
23+
int64_t x_rank = x.get_partial_shape().rank().get_length();
24+
PDPD_OP_VALIDATION_CHECK(node,
25+
y.get_partial_shape().rank().is_static() &&
26+
y.get_partial_shape().rank().get_length() == 2,
27+
"matmul: Y rank must be static, and 2!");
28+
if (x_rank > 2)
29+
{
30+
auto shape = std::make_shared<ngraph::opset6::ShapeOf>(x);
31+
int64_t x_num_col_dims = node.get_attribute<int32_t>("x_num_col_dims");
32+
auto axis = ngraph::opset6::Constant::create(ngraph::element::i64, {}, {0});
33+
auto split_lengths = ngraph::opset6::Constant::create(
34+
ngraph::element::i64, {2}, {x_num_col_dims, x_rank - x_num_col_dims});
35+
auto split = std::make_shared<ngraph::opset6::VariadicSplit>(
36+
shape, axis, split_lengths);
37+
auto f_dim_red_axis =
38+
ngraph::opset6::Constant::create(ngraph::element::i64, {}, {0});
39+
auto first_dim_reduce = std::make_shared<ngraph::opset6::ReduceProd>(
40+
split->output(0), f_dim_red_axis);
41+
auto f_dim_shape =
42+
ngraph::opset6::Constant::create(ngraph::element::i64, {1}, {1});
43+
auto first_dim = std::make_shared<ngraph::opset6::Reshape>(
44+
first_dim_reduce, f_dim_shape, false);
45+
auto s_dim_red_axis =
46+
ngraph::opset6::Constant::create(ngraph::element::i64, {}, {0});
47+
auto second_dim_reduce = std::make_shared<ngraph::opset6::ReduceProd>(
48+
split->output(1), s_dim_red_axis);
49+
auto s_dim_shape =
50+
ngraph::opset6::Constant::create(ngraph::element::i64, {1}, {1});
51+
auto second_dim = std::make_shared<ngraph::opset6::Reshape>(
52+
second_dim_reduce, s_dim_shape, false);
53+
auto out_shape = std::make_shared<ngraph::opset6::Concat>(
54+
ngraph::NodeVector{first_dim, second_dim}, 0);
55+
auto x_reshaped =
56+
std::make_shared<ngraph::opset6::Reshape>(x, out_shape, false);
57+
return node.default_single_output_mapping(
58+
{std::make_shared<ngraph::opset6::MatMul>(x_reshaped, y)}, {"Out"});
59+
}
60+
return node.default_single_output_mapping(
61+
{std::make_shared<ngraph::opset6::MatMul>(x, y)}, {"Out"});
62+
}
63+
64+
} // namespace op
65+
} // namespace pdpd
66+
} // namespace frontend
67+
} // namespace ngraph
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Copyright (C) 2018-2021 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#include <ngraph/opsets/opset6.hpp>
6+
#include <node_context.hpp>
7+
8+
namespace ngraph
9+
{
10+
namespace frontend
11+
{
12+
namespace pdpd
13+
{
14+
namespace op
15+
{
16+
NamedOutputs pad3d(const NodeContext& node)
17+
{
18+
auto data = node.get_ng_input("X");
19+
auto mode = node.get_attribute<std::string>("mode");
20+
auto value = node.get_attribute<float>("value", 0.0);
21+
auto data_format = node.get_attribute<std::string>("data_format");
22+
23+
auto paddings = std::vector<int32_t>(6, 0);
24+
25+
// padding of type int feature only supported by PaddlePaddle 'develop'
26+
// version(>=2.1.0)
27+
if (node.has_attribute<std::vector<int32_t>>("paddings"))
28+
{
29+
auto paddings_vector = node.get_attribute<std::vector<int32_t>>("paddings");
30+
PDPD_OP_VALIDATION_CHECK(node,
31+
paddings_vector.size() == 6,
32+
"paddings Params size should be 6 in pad3d!");
33+
paddings = paddings_vector;
34+
}
35+
else if (node.has_attribute<int32_t>("paddings"))
36+
{
37+
auto padding_int = node.get_attribute<int32_t>("paddings");
38+
for (int i = 0; i < 6; i++)
39+
paddings[i] = padding_int;
40+
}
41+
else
42+
{
43+
throw ngraph::ngraph_error("Unsupported paddings attribute!");
44+
}
45+
46+
auto pads_begin = std::vector<int32_t>(5, 0);
47+
auto pads_end = std::vector<int32_t>(5, 0);
48+
49+
Output<ngraph::Node> values;
50+
Output<ngraph::Node> padding_begin;
51+
Output<ngraph::Node> padding_end;
52+
53+
ngraph::op::PadMode pad_mode;
54+
// TODO Support Circular mode in #55704
55+
if (mode == "constant")
56+
{
57+
pad_mode = ngraph::op::PadMode::CONSTANT;
58+
values = ngraph::opset6::Constant::create(
59+
element::f32, ngraph::Shape{}, {value});
60+
}
61+
else if (mode == "reflect")
62+
{
63+
pad_mode = ngraph::op::PadMode::REFLECT;
64+
}
65+
else if (mode == "replicate")
66+
{
67+
pad_mode = ngraph::op::PadMode::EDGE;
68+
}
69+
else
70+
{
71+
throw ngraph::ngraph_error("Unsupported 3d paddings mode: [" + mode + "]");
72+
}
73+
74+
if (data_format == "NCDHW")
75+
{
76+
pads_begin[4] = paddings[0]; // left
77+
pads_end[4] = paddings[1]; // right
78+
pads_begin[3] = paddings[2]; // top
79+
pads_end[3] = paddings[3]; // down
80+
pads_begin[2] = paddings[4]; // front
81+
pads_end[2] = paddings[5]; // back
82+
}
83+
else if (data_format == "NDHWC")
84+
{
85+
pads_begin[3] = paddings[0]; // left
86+
pads_end[3] = paddings[1]; // right
87+
pads_begin[2] = paddings[2]; // top
88+
pads_end[2] = paddings[3]; // down
89+
pads_begin[1] = paddings[4]; // front
90+
pads_end[1] = paddings[5]; // back
91+
}
92+
else
93+
{
94+
throw ngraph::ngraph_error("Unsupported 3d paddings data_format: [" +
95+
data_format + "]");
96+
}
97+
98+
padding_begin = ngraph::opset6::Constant::create(
99+
element::i32, ngraph::Shape{pads_begin.size()}, pads_begin);
100+
padding_end = ngraph::opset6::Constant::create(
101+
element::i32, ngraph::Shape{pads_end.size()}, pads_end);
102+
103+
if (mode == "constant")
104+
return node.default_single_output_mapping(
105+
{std::make_shared<ngraph::opset6::Pad>(
106+
data, padding_begin, padding_end, values, pad_mode)},
107+
{"Out"});
108+
else
109+
return node.default_single_output_mapping(
110+
{std::make_shared<ngraph::opset6::Pad>(
111+
data, padding_begin, padding_end, pad_mode)},
112+
{"Out"});
113+
}
114+
} // namespace op
115+
} // namespace pdpd
116+
} // namespace frontend
117+
} // namespace ngraph

0 commit comments

Comments
 (0)