[PyOV] Replace legacy assert (#21268)

* [PyOV] Replace legacy assert

* codestyle

* apply comments

* Update src/bindings/python/src/pyopenvino/graph/dict_attribute_visitor.cpp
This commit is contained in:
Anastasia Kuporosova 2023-11-27 11:51:01 +04:00 committed by GitHub
parent ed061d5179
commit 815980f290
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 27 deletions

View File

@ -262,7 +262,7 @@ void util::DictAttributeDeserializer::on_adapter(const std::string& name,
auto body = std::make_shared<ov::Model>(body_outputs, body_parameters);
adapter.set(body);
} else {
NGRAPH_CHECK(false, "No AttributeVisitor support for accessing attribute named: ", name);
OPENVINO_THROW("No AttributeVisitor support for accessing attribute named: ", name);
}
}
}
@ -272,7 +272,7 @@ util::DictAttributeSerializer::DictAttributeSerializer(const std::shared_ptr<ov:
}
void util::DictAttributeSerializer::on_adapter(const std::string& name, ov::ValueAccessor<void>& adapter) {
if (m_attributes.contains(name)) {
NGRAPH_CHECK(false, "No AttributeVisitor support for accessing attribute named: ", name);
OPENVINO_THROW("No AttributeVisitor support for accessing attribute named: ", name);
}
}
void util::DictAttributeSerializer::on_adapter(const std::string& name, ov::ValueAccessor<bool>& adapter) {

View File

@ -86,10 +86,10 @@ public:
template <typename T>
T get_attribute(const std::string& name) {
NGRAPH_CHECK(m_attributes.contains(name),
"Couldn't find attribute \"",
name,
"\" in serialized node attribute dictionary.");
OPENVINO_ASSERT(m_attributes.contains(name),
"Couldn't find attribute \"",
name,
"\" in serialized node attribute dictionary.");
return m_attributes[name.c_str()].cast<T>();
}

View File

@ -44,7 +44,7 @@ static ov::SinkVector cast_to_sink_vector(const std::vector<std::shared_ptr<ov::
ov::SinkVector sinks;
for (const auto& node : nodes) {
auto sink = std::dynamic_pointer_cast<ov::op::Sink>(node);
NGRAPH_CHECK(sink != nullptr, "Node {} is not instance of Sink");
OPENVINO_ASSERT(sink != nullptr, "Node {} is not instance of Sink");
sinks.push_back(sink);
}
return sinks;
@ -54,7 +54,7 @@ static std::vector<std::shared_ptr<ov::Node>> cast_to_node_vector(const ov::Sink
std::vector<std::shared_ptr<ov::Node>> nodes;
for (const auto& sink : sinks) {
auto node = std::dynamic_pointer_cast<ov::Node>(sink);
NGRAPH_CHECK(node != nullptr, "Sink {} is not instance of Node");
OPENVINO_ASSERT(node != nullptr, "Sink {} is not instance of Node");
nodes.push_back(node);
}
return nodes;
@ -823,7 +823,7 @@ void regclass_graph_Model(py::module m) {
for (py::handle sink : sinks) {
auto sink_cpp =
std::dynamic_pointer_cast<ov::op::Sink>(sink.cast<std::shared_ptr<ov::op::v6::Assign>>());
NGRAPH_CHECK(sink_cpp != nullptr, "Assign {} is not instance of Sink");
OPENVINO_ASSERT(sink_cpp != nullptr, "Assign {} is not instance of Sink");
sinks_cpp.push_back(sink_cpp);
}
self.add_sinks(sinks_cpp);

View File

@ -43,24 +43,24 @@ public:
auto ext_it = m_opset_so_extensions.find(op_type_name);
if (ext_it != m_opset_so_extensions.end()) {
auto op_extension = std::dynamic_pointer_cast<ov::BaseOpExtension>(ext_it->second->extension());
NGRAPH_CHECK(op_extension); // guaranteed by add_extension method
OPENVINO_ASSERT(op_extension); // guaranteed by add_extension method
util::DictAttributeDeserializer visitor(attributes, m_variables);
auto outputs = op_extension->create(arguments, visitor);
NGRAPH_CHECK(outputs.size() > 0,
"Failed to create extension operation with type: ",
op_type_name,
" because it doesn't contain output ports. Operation should has at least one output port.");
OPENVINO_ASSERT(outputs.size() > 0,
"Failed to create extension operation with type: ",
op_type_name,
" because it doesn't contain output ports. Operation should has at least one output port.");
auto node = outputs[0].get_node_shared_ptr();
return node;
} else {
std::shared_ptr<ov::Node> op_node = std::shared_ptr<ov::Node>(m_opset.create(op_type_name));
NGRAPH_CHECK(op_node != nullptr, "Couldn't create operation: ", op_type_name);
NGRAPH_CHECK(!ov::op::util::is_constant(op_node),
"Currently NodeFactory doesn't support Constant operation: ",
op_type_name);
OPENVINO_ASSERT(op_node != nullptr, "Couldn't create operation: ", op_type_name);
OPENVINO_ASSERT(!ov::op::util::is_constant(op_node),
"Currently NodeFactory doesn't support Constant operation: ",
op_type_name);
util::DictAttributeDeserializer visitor(attributes, m_variables);
@ -76,18 +76,18 @@ public:
// Check for available extensions first, because they may override ops from main opset
auto ext_it = m_opset_so_extensions.find(op_type_name);
// No way to instantiate operation without inputs, so if extension operation is found report an error.
NGRAPH_CHECK(ext_it == m_opset_so_extensions.end(),
"Couldn't create operation of type ",
op_type_name,
" from an extension library as no inputs were provided. Currently NodeFactory doesn't support ",
"operations without inputs. Provide at least one input.");
OPENVINO_ASSERT(ext_it == m_opset_so_extensions.end(),
"Couldn't create operation of type ",
op_type_name,
" from an extension library as no inputs were provided. Currently NodeFactory doesn't support ",
"operations without inputs. Provide at least one input.");
std::shared_ptr<ov::Node> op_node = std::shared_ptr<ov::Node>(m_opset.create(op_type_name));
NGRAPH_CHECK(op_node != nullptr, "Couldn't create operation: ", op_type_name);
NGRAPH_CHECK(!ov::op::util::is_constant(op_node),
"Currently NodeFactory doesn't support Constant node: ",
op_type_name);
OPENVINO_ASSERT(op_node != nullptr, "Couldn't create operation: ", op_type_name);
OPENVINO_ASSERT(!ov::op::util::is_constant(op_node),
"Currently NodeFactory doesn't support Constant node: ",
op_type_name);
OPENVINO_WARN << "Empty op created! Please assign inputs and attributes and run validate() before op is used.";