Skip to content

Commit 0c37a49

Browse files
committed
Simplify code
Signed-off-by: Maxim Vafin <maxim.vafin@intel.com>
1 parent 5b33188 commit 0c37a49

File tree

8 files changed

+199
-182
lines changed

8 files changed

+199
-182
lines changed

src/frontends/common/include/openvino/frontend/unconverted_ops_report.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
#include <vector>
1414

1515
#include "openvino/frontend/visibility.hpp"
16+
namespace ov {
17+
namespace op {
18+
namespace util {
19+
class FrameworkNodeAttrs;
20+
} // namespace util
21+
} // namespace op
22+
} // namespace ov
1623

1724
namespace ov {
1825
class Model;
@@ -36,6 +43,12 @@ FRONTEND_API std::string format_unconverted_ops_report(const UnconvertedOpMap& u
3643
const std::string& additional_error = std::string{},
3744
const std::string& header = "Model wasn't fully converted.");
3845

46+
FRONTEND_API FrameworkNodeErrorInfo
47+
build_framework_node_error_info(const ov::op::util::FrameworkNodeAttrs& attrs,
48+
const std::string& op_type_attr_key = std::string{},
49+
const std::string& failure_attr_key = std::string{},
50+
const std::string& version_attr_key = std::string{});
51+
3952
template <class TNode, class Callback>
4053
UnconvertedOpExtractor make_unconverted_op_extractor(Callback&& callback) {
4154
return [cb = std::forward<Callback>(callback)](

src/frontends/common/src/unconverted_ops_report.cpp

Lines changed: 62 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include <sstream>
88

9-
#include "openvino/core/graph_util.hpp"
109
#include "openvino/core/model.hpp"
1110
#include "openvino/core/node.hpp"
1211
#include "openvino/op/util/framework_node.hpp"
@@ -16,17 +15,11 @@ namespace ov {
1615
namespace frontend {
1716
namespace {
1817

19-
struct CollectorContext {
20-
const std::vector<UnconvertedOpExtractor>& extractors;
21-
UnconvertedOpMap& report;
22-
};
23-
2418
std::optional<FrameworkNodeErrorInfo> extract_from_framework_node(
2519
const std::shared_ptr<ov::op::util::FrameworkNode>& fw_node) {
2620
if (!fw_node) {
2721
return std::nullopt;
2822
}
29-
3023
FrameworkNodeErrorInfo info;
3124
const auto& attrs = fw_node->get_attrs();
3225
info.op_type = attrs.get_type_name();
@@ -36,16 +29,7 @@ std::optional<FrameworkNodeErrorInfo> extract_from_framework_node(
3629
if (info.op_type.empty()) {
3730
info.op_type = fw_node->get_friendly_name();
3831
}
39-
40-
std::stringstream consumer;
41-
if (fw_node->get_output_size() > 0) {
42-
auto inputs = fw_node->output(0).get_target_inputs();
43-
if (!inputs.empty()) {
44-
consumer << " Consumer: " << *(inputs.begin()->get_node());
45-
}
46-
}
47-
info.failure_message = "This is OpenVINO internal type." + consumer.str();
48-
32+
info.failure_message = "This is OpenVINO internal type.";
4933
return info;
5034
}
5135

@@ -54,51 +38,81 @@ std::optional<FrameworkNodeErrorInfo> extract_node_info(const std::shared_ptr<ov
5438
if (!node) {
5539
return std::nullopt;
5640
}
57-
5841
for (const auto& extractor : extractors) {
59-
if (!extractor) {
60-
continue;
61-
}
62-
if (auto info = extractor(node)) {
63-
return info;
42+
if (extractor) {
43+
if (auto info = extractor(node)) {
44+
return info;
45+
}
6446
}
6547
}
66-
6748
if (const auto& fw_node = ov::as_type_ptr<ov::op::util::FrameworkNode>(node)) {
6849
return extract_from_framework_node(fw_node);
6950
}
70-
7151
return std::nullopt;
7252
}
7353

74-
void collect_from_model(const std::shared_ptr<ov::Model>& model, const CollectorContext& ctx) {
54+
void collect_from_model(const std::shared_ptr<ov::Model>& model,
55+
const std::vector<UnconvertedOpExtractor>& extractors,
56+
UnconvertedOpMap& report) {
7557
if (!model) {
7658
return;
7759
}
78-
7960
for (const auto& node : model->get_ordered_ops()) {
80-
if (auto info = extract_node_info(node, ctx.extractors)) {
81-
if (!info->op_type.empty() && ctx.report.count(info->op_type) == 0) {
82-
ctx.report.emplace(info->op_type, info->failure_message);
61+
if (auto info = extract_node_info(node, extractors)) {
62+
if (!info->op_type.empty() && report.count(info->op_type) == 0) {
63+
report.emplace(info->op_type, info->failure_message);
8364
}
8465
}
85-
8666
if (const auto& multigraph = ov::as_type_ptr<ov::op::util::MultiSubGraphOp>(node)) {
8767
const size_t subgraphs = multigraph->get_internal_subgraphs_size();
8868
for (size_t idx = 0; idx < subgraphs; ++idx) {
89-
collect_from_model(multigraph->get_function(idx), ctx);
69+
collect_from_model(multigraph->get_function(idx), extractors, report);
9070
}
9171
}
9272
}
9373
}
9474

9575
} // namespace
9676

77+
FrameworkNodeErrorInfo build_framework_node_error_info(const ov::op::util::FrameworkNodeAttrs& attrs,
78+
const std::string& op_type_attr_key,
79+
const std::string& failure_attr_key,
80+
const std::string& version_attr_key) {
81+
FrameworkNodeErrorInfo info;
82+
auto find_attr = [&](const std::string& key) -> std::string {
83+
const auto it = attrs.find(key);
84+
return it == attrs.end() ? std::string{} : it->second;
85+
};
86+
87+
info.op_type = op_type_attr_key.empty() ? std::string{} : find_attr(op_type_attr_key);
88+
if (info.op_type.empty()) {
89+
info.op_type = attrs.get_type_name();
90+
}
91+
if (info.op_type.empty()) {
92+
info.op_type = "<unknown>";
93+
}
94+
95+
const auto version = version_attr_key.empty() ? std::string{} : find_attr(version_attr_key);
96+
if (!version.empty()) {
97+
info.op_type += "-" + version;
98+
}
99+
100+
const auto& opset_name = attrs.get_opset_name();
101+
if (!opset_name.empty()) {
102+
info.op_type = opset_name + "." + info.op_type;
103+
}
104+
105+
if (!failure_attr_key.empty()) {
106+
info.failure_message = find_attr(failure_attr_key);
107+
}
108+
109+
return info;
110+
}
111+
97112
UnconvertedOpMap collect_unconverted_ops(const std::shared_ptr<ov::Model>& model,
98113
const std::vector<UnconvertedOpExtractor>& custom_extractors) {
99114
UnconvertedOpMap report;
100-
CollectorContext ctx{custom_extractors, report};
101-
collect_from_model(model, ctx);
115+
collect_from_model(model, custom_extractors, report);
102116
return report;
103117
}
104118

@@ -108,41 +122,41 @@ std::string format_unconverted_ops_report(const UnconvertedOpMap& unconverted_op
108122
std::stringstream error_msg;
109123
error_msg << (header.empty() ? "Model wasn't fully converted." : header);
110124

111-
std::stringstream unconverted_ops_msg;
112-
std::stringstream failed_ops_msg;
113-
std::stringstream failed_ops_short;
114-
unconverted_ops_msg << "-- No conversion rule found for operations: ";
115-
failed_ops_msg << " Failed operations detailed log:";
116-
failed_ops_short << "-- Conversion is failed for: ";
125+
std::stringstream unsupported_msg;
126+
std::stringstream failures_msg;
127+
std::stringstream failed_short;
128+
unsupported_msg << "-- No conversion rule found for operations: ";
129+
failures_msg << " Failed operations detailed log:";
130+
failed_short << "-- Conversion is failed for: ";
117131

118132
bool has_unsupported = false;
119133
bool has_failures = false;
120134
for (const auto& op : unconverted_ops) {
121135
if (op.second.empty()) {
122136
if (has_unsupported) {
123-
unconverted_ops_msg << ", ";
137+
unsupported_msg << ", ";
124138
}
125-
unconverted_ops_msg << op.first;
139+
unsupported_msg << op.first;
126140
has_unsupported = true;
127141
} else {
128142
if (has_failures) {
129-
failed_ops_short << ", ";
143+
failed_short << ", ";
130144
}
131-
failed_ops_short << op.first;
132-
failed_ops_msg << "\n-- " << op.first << " with a message:\n" << op.second;
145+
failed_short << op.first;
146+
failures_msg << "\n-- " << op.first << " with a message:\n" << op.second;
133147
has_failures = true;
134148
}
135149
}
136150

137151
if (has_failures) {
138-
error_msg << failed_ops_msg.str();
152+
error_msg << failures_msg.str();
139153
}
140154
error_msg << "\nSummary:" << additional_error;
141155
if (has_unsupported) {
142-
error_msg << '\n' << unconverted_ops_msg.str();
156+
error_msg << '\n' << unsupported_msg.str();
143157
}
144158
if (has_failures) {
145-
error_msg << '\n' << failed_ops_short.str();
159+
error_msg << '\n' << failed_short.str();
146160
}
147161

148162
return error_msg.str();

src/frontends/jax/src/frontend.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@ const std::vector<UnconvertedOpExtractor>& get_unconverted_extractors() {
2929
ov::frontend::make_unconverted_op_extractor<JaxFrameworkNode>(
3030
[](const std::shared_ptr<JaxFrameworkNode>& node) -> std::optional<FrameworkNodeErrorInfo> {
3131
const auto& attrs = node->get_attrs();
32-
auto type_it = attrs.find(JaxFrameworkNode::op_type_key);
33-
FRONT_END_GENERAL_CHECK(type_it != attrs.end(),
32+
auto info = ov::frontend::build_framework_node_error_info(attrs,
33+
JaxFrameworkNode::op_type_key,
34+
JaxFrameworkNode::failed_conversion_key,
35+
std::string{});
36+
FRONT_END_GENERAL_CHECK(!info.op_type.empty(),
3437
"FrameworkNode attributes do not contain operation type.");
35-
FrameworkNodeErrorInfo info;
36-
info.op_type = type_it->second;
37-
auto failure_it = attrs.find(JaxFrameworkNode::failed_conversion_key);
38-
if (failure_it != attrs.end()) {
39-
info.failure_message = failure_it->second;
40-
}
4138
return info;
4239
})};
4340
return extractors;
@@ -59,9 +56,6 @@ std::shared_ptr<Model> FrontEnd::convert(const ov::frontend::InputModel::Ptr& mo
5956
if (m_telemetry) {
6057
for (const auto& entry : unconverted_ops) {
6158
m_telemetry->send_event("error_cause", "jax_" + entry.first);
62-
if (!entry.second.empty()) {
63-
m_telemetry->send_event("error_info", entry.second);
64-
}
6559
}
6660
}
6761
FRONT_END_OP_CONVERSION_CHECK(

src/frontends/onnx/frontend/src/frontend.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,29 +122,20 @@ const std::vector<UnconvertedOpExtractor>& get_onnx_extractors() {
122122
ov::frontend::make_unconverted_op_extractor<ov::frontend::onnx::ONNXFrameworkNode>(
123123
[](const std::shared_ptr<ov::frontend::onnx::ONNXFrameworkNode>& node)
124124
-> std::optional<FrameworkNodeErrorInfo> {
125-
FrameworkNodeErrorInfo info;
126125
const auto& attrs = node->get_attrs();
127-
info.op_type = attrs.get_type_name();
128-
if (!attrs.get_opset_name().empty()) {
129-
info.op_type = attrs.get_opset_name() + "." + info.op_type;
130-
}
131-
if (const auto it = attrs.find(ONNX_OPSET_VERSION_ATTR); it != attrs.end()) {
132-
info.op_type += "-" + it->second;
133-
}
134-
return info;
126+
return ov::frontend::build_framework_node_error_info(attrs,
127+
std::string{},
128+
std::string{},
129+
ONNX_OPSET_VERSION_ATTR);
135130
}),
136131
ov::frontend::make_unconverted_op_extractor<ov::frontend::onnx::NotSupportedONNXNode>(
137132
[](const std::shared_ptr<ov::frontend::onnx::NotSupportedONNXNode>& node)
138133
-> std::optional<FrameworkNodeErrorInfo> {
139-
FrameworkNodeErrorInfo info;
140134
const auto& attrs = node->get_attrs();
141-
info.op_type = attrs.get_type_name();
142-
if (!attrs.get_opset_name().empty()) {
143-
info.op_type = attrs.get_opset_name() + "." + info.op_type;
144-
}
145-
if (const auto it = attrs.find(ONNX_OPSET_VERSION_ATTR); it != attrs.end()) {
146-
info.op_type += "-" + it->second;
147-
}
135+
FrameworkNodeErrorInfo info = ov::frontend::build_framework_node_error_info(attrs,
136+
std::string{},
137+
std::string{},
138+
ONNX_OPSET_VERSION_ATTR);
148139
info.failure_message = node->additional_error_message();
149140
return info;
150141
})};

src/frontends/paddle/src/frontend.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@ const std::vector<UnconvertedOpExtractor>& get_unconverted_extractors() {
150150
static const std::vector<UnconvertedOpExtractor> extractors{
151151
ov::frontend::make_unconverted_op_extractor<FrameworkNode>(
152152
[](const std::shared_ptr<FrameworkNode>& node) -> std::optional<FrameworkNodeErrorInfo> {
153-
FrameworkNodeErrorInfo info;
154-
info.op_type = node->get_op_type();
155-
return info;
153+
const auto& attrs = node->get_attrs();
154+
return ov::frontend::build_framework_node_error_info(attrs);
156155
})};
157156
return extractors;
158157
}
@@ -520,9 +519,6 @@ std::shared_ptr<ov::Model> FrontEnd::convert(const InputModel::Ptr& model) const
520519
if (m_telemetry) {
521520
for (const auto& entry : unconverted_ops) {
522521
m_telemetry->send_event("error_cause", "paddle_" + entry.first);
523-
if (!entry.second.empty()) {
524-
m_telemetry->send_event("error_info", entry.second);
525-
}
526522
}
527523
}
528524
FRONT_END_OP_CONVERSION_CHECK(
@@ -553,9 +549,6 @@ void FrontEnd::convert(const std::shared_ptr<ov::Model>& partiallyConverted) con
553549
if (m_telemetry) {
554550
for (const auto& entry : unconverted_ops) {
555551
m_telemetry->send_event("error_cause", "paddle_" + entry.first);
556-
if (!entry.second.empty()) {
557-
m_telemetry->send_event("error_info", entry.second);
558-
}
559552
}
560553
}
561554
FRONT_END_OP_CONVERSION_CHECK(

src/frontends/pytorch/src/frontend.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,12 @@ const std::vector<UnconvertedOpExtractor>& get_unconverted_extractors() {
6161
ov::frontend::make_unconverted_op_extractor<PtFrameworkNode>(
6262
[](const std::shared_ptr<PtFrameworkNode>& node) -> std::optional<FrameworkNodeErrorInfo> {
6363
const auto& attrs = node->get_attrs();
64-
auto op_type_it = attrs.find(PtFrameworkNode::op_type_key);
65-
FRONT_END_GENERAL_CHECK(op_type_it != attrs.end(),
64+
auto info = ov::frontend::build_framework_node_error_info(attrs,
65+
PtFrameworkNode::op_type_key,
66+
PtFrameworkNode::failed_conversion_key,
67+
std::string{});
68+
FRONT_END_GENERAL_CHECK(!info.op_type.empty(),
6669
"FrameworkNode attributes do not contain operation type.");
67-
FrameworkNodeErrorInfo info;
68-
info.op_type = op_type_it->second;
69-
auto exception_it = attrs.find(PtFrameworkNode::failed_conversion_key);
70-
if (exception_it != attrs.end()) {
71-
info.failure_message = exception_it->second;
72-
}
7370
return info;
7471
})};
7572
return extractors;

0 commit comments

Comments
 (0)