-
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]Added and fixed Paddle convert. (#28347)
### Details: 1. *added proto::AttrType::SCALARS* 2. support 0D inputs and fixes: - argmax:[argmax](https://www.paddlepaddle.org.cn/documentation/docs/en/api/paddle/argmax_en.html#argmax) - assign_value - divide:[divide](https://www.paddlepaddle.org.cn/documentation/docs/en/api/paddle/divide_en.html#divide) - fill_any_like:[full_like](https://www.paddlepaddle.org.cn/documentation/docs/en/api/paddle/full_like_en.html#full-like) - fill_constan:[full](https://www.paddlepaddle.org.cn/documentation/docs/en/api/paddle/full_en.html#full)\ - set_value - slice:[slice](https://www.paddlepaddle.org.cn/documentation/docs/en/api/paddle/slice_en.html#slice) - tile:[tile](https://www.paddlepaddle.org.cn/documentation/docs/en/api/paddle/tile_en.html#tile) 3. Added convert: - abs:[abs](https://www.paddlepaddle.org.cn/documentation/docs/en/api/paddle/abs_en.html#abs) - argmin:[argmin](https://www.paddlepaddle.org.cn/documentation/docs/en/api/paddle/argmin_en.html#argmin) - scatter:[scatter](https://www.paddlepaddle.org.cn/documentation/docs/en/api/paddle/scatter_en.html#scatter) - scatter_nd_add:[scatter_nd_add](https://www.paddlepaddle.org.cn/documentation/docs/en/api/paddle/scatter_nd_add_en.html#scatter-nd-add) - take_along_axis:[take_along_axis](https://www.paddlepaddle.org.cn/documentation/docs/en/api/paddle/take_along_axis_en.html#take-along-axis) ### Tickets: --------- Co-authored-by: cecilia peng <cecilia.peng@intel.com> Co-authored-by: Yu Xu <yu.xu@intel.com>
- Loading branch information
1 parent
6929f7e
commit 334c971
Showing
26 changed files
with
808 additions
and
68 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,20 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "openvino/frontend/paddle/node_context.hpp" | ||
#include "openvino/opsets/opset6.hpp" | ||
|
||
namespace ov { | ||
namespace frontend { | ||
namespace paddle { | ||
namespace op { | ||
NamedOutputs abs(const NodeContext& node) { | ||
auto data = node.get_input("X"); | ||
return node.default_single_output_mapping({std::make_shared<ov::opset6::Abs>(data)}, {"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,46 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "openvino/frontend/paddle/node_context.hpp" | ||
#include "openvino/opsets/opset6.hpp" | ||
|
||
namespace ov { | ||
namespace frontend { | ||
namespace paddle { | ||
namespace op { | ||
NamedOutputs argmin(const NodeContext& node) { | ||
auto data = node.get_input("X"); | ||
bool flatten = node.get_attribute<bool>("flatten"); | ||
auto dtype = node.get_attribute<ov::element::Type>("dtype"); | ||
const Output<ov::Node> k = ov::opset6::Constant::create(ov::element::i64, {}, {1}); | ||
|
||
if (!flatten) { | ||
auto axis = node.get_attribute<int64_t>("axis"); | ||
const auto axis_to_remove = ov::opset6::Constant::create(element::u64, Shape{}, {axis}); | ||
auto node_topk = std::make_shared<ov::opset6::TopK>(data, k, axis, "min", "index", dtype); | ||
const auto reshaped_indices = std::make_shared<ov::opset6::Squeeze>(node_topk->output(1), axis_to_remove); | ||
return node.default_single_output_mapping({std::make_shared<ov::opset6::Convert>(reshaped_indices, dtype)}, | ||
{"Out"}); | ||
} else { | ||
int64_t axis = 0; | ||
const Output<ov::Node> reshape_flatten = ov::opset6::Constant::create(ov::element::i64, {1}, {-1}); | ||
auto node_reshape = std::make_shared<ov::opset6::Reshape>(data, reshape_flatten, true); | ||
auto node_topk = std::make_shared<ov::opset6::TopK>(node_reshape, k, axis, "min", "index", dtype); | ||
const auto output_info = node.get_output_port_infos("Out"); | ||
size_t output_size = output_info[0].second.size(); | ||
if (output_size == 0) { | ||
auto out = std::make_shared<ov::opset6::Squeeze>(node_topk->output(1)); | ||
return node.default_single_output_mapping({std::make_shared<ov::opset6::Convert>(out, dtype)}, {"Out"}); | ||
} else { | ||
return node.default_single_output_mapping( | ||
{std::make_shared<ov::opset6::Convert>(node_topk->output(1), dtype)}, | ||
{"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,85 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
#include "openvino/frontend/paddle/node_context.hpp" | ||
#include "openvino/op/add.hpp" | ||
#include "openvino/op/atan.hpp" | ||
#include "openvino/op/constant.hpp" | ||
#include "openvino/op/convert_like.hpp" | ||
#include "openvino/op/divide.hpp" | ||
#include "openvino/op/equal.hpp" | ||
#include "openvino/op/greater.hpp" | ||
#include "openvino/op/greater_eq.hpp" | ||
#include "openvino/op/less.hpp" | ||
#include "openvino/op/logical_and.hpp" | ||
#include "openvino/op/multiply.hpp" | ||
#include "openvino/op/select.hpp" | ||
#include "openvino/op/subtract.hpp" | ||
#include "openvino/opsets/opset6.hpp" | ||
using namespace std; | ||
using namespace ov::op; | ||
|
||
namespace ov { | ||
namespace frontend { | ||
namespace paddle { | ||
|
||
template <typename T> | ||
ov::Output<ov::Node> create_same_type_const_scalar(const ov::Output<ov::Node>& same_type_output, const T& value) { | ||
if (same_type_output.get_element_type().is_static()) { | ||
return std::make_shared<ov::op::v0::Constant>(same_type_output.get_element_type(), ov::Shape{}, value); | ||
} else { | ||
ov::Output<ov::Node> const_res = | ||
std::make_shared<ov::op::v0::Constant>(ov::element::from<T>(), ov::Shape{}, value); | ||
const_res = std::make_shared<ov::op::v1::ConvertLike>(const_res, same_type_output); | ||
return const_res; | ||
} | ||
} | ||
|
||
namespace op { | ||
NamedOutputs atan2(const NodeContext& node) { | ||
// default_op_checks(node, 2, {"Atan2"}); | ||
auto y = node.get_input("X1"); | ||
auto x = node.get_input("X2"); | ||
|
||
// handle the first condition : x>0 | ||
auto div_y_x = make_shared<v1::Divide>(y, x); | ||
auto atan = make_shared<v0::Atan>(div_y_x); | ||
auto const_zero = create_same_type_const_scalar<int32_t>(x, 0); | ||
auto result = atan->output(0); | ||
|
||
// handle the second condition : x<0 && y>=0 | ||
auto const_pi = create_same_type_const_scalar<double>(x, std::atan(1.0) * 4); | ||
auto is_x_negative = make_shared<v1::Less>(x, const_zero); | ||
auto y_non_negative = make_shared<v1::GreaterEqual>(y, const_zero); | ||
auto cond1 = make_shared<v1::LogicalAnd>(is_x_negative, y_non_negative); | ||
auto atan_y_x_plus_pi = make_shared<v1::Add>(atan, const_pi); | ||
result = make_shared<v1::Select>(cond1, atan_y_x_plus_pi, result); | ||
|
||
// handle the third condition : x<0 && y<0 | ||
auto is_y_negative = make_shared<v1::Less>(y, const_zero); | ||
auto cond2 = make_shared<v1::LogicalAnd>(is_x_negative, is_y_negative); | ||
auto atan_y_x_minus_pi = make_shared<v1::Subtract>(atan, const_pi); | ||
result = make_shared<v1::Select>(cond2, atan_y_x_minus_pi, result); | ||
|
||
// handle the fourth condition : x=0 && y>0 | ||
auto is_x_zero = make_shared<v1::Equal>(x, const_zero); | ||
auto is_y_positive = make_shared<v1::Greater>(y, const_zero); | ||
auto cond3 = make_shared<v1::LogicalAnd>(is_x_zero, is_y_positive); | ||
auto const_two = create_same_type_const_scalar<int32_t>(x, 2); | ||
auto pi_div_two = make_shared<v1::Divide>(const_pi, const_two); | ||
result = make_shared<v1::Select>(cond3, pi_div_two, result); | ||
|
||
// handle the fifth condition : x=0 && y<0 | ||
auto cond4 = make_shared<v1::LogicalAnd>(is_x_zero, is_y_negative); | ||
auto const_minus_two = create_same_type_const_scalar<int32_t>(x, -2); | ||
auto pi_div_minus_two = make_shared<v1::Divide>(const_pi, const_minus_two); | ||
result = make_shared<v1::Select>(cond4, pi_div_two, result); | ||
NamedOutputs named_outputs; | ||
named_outputs["Out"] = {result}; | ||
return named_outputs; | ||
} | ||
|
||
} // 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
Oops, something went wrong.