[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:
parent
ed061d5179
commit
815980f290
@ -262,7 +262,7 @@ void util::DictAttributeDeserializer::on_adapter(const std::string& name,
|
|||||||
auto body = std::make_shared<ov::Model>(body_outputs, body_parameters);
|
auto body = std::make_shared<ov::Model>(body_outputs, body_parameters);
|
||||||
adapter.set(body);
|
adapter.set(body);
|
||||||
} else {
|
} 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) {
|
void util::DictAttributeSerializer::on_adapter(const std::string& name, ov::ValueAccessor<void>& adapter) {
|
||||||
if (m_attributes.contains(name)) {
|
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) {
|
void util::DictAttributeSerializer::on_adapter(const std::string& name, ov::ValueAccessor<bool>& adapter) {
|
||||||
|
@ -86,10 +86,10 @@ public:
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T get_attribute(const std::string& name) {
|
T get_attribute(const std::string& name) {
|
||||||
NGRAPH_CHECK(m_attributes.contains(name),
|
OPENVINO_ASSERT(m_attributes.contains(name),
|
||||||
"Couldn't find attribute \"",
|
"Couldn't find attribute \"",
|
||||||
name,
|
name,
|
||||||
"\" in serialized node attribute dictionary.");
|
"\" in serialized node attribute dictionary.");
|
||||||
return m_attributes[name.c_str()].cast<T>();
|
return m_attributes[name.c_str()].cast<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ static ov::SinkVector cast_to_sink_vector(const std::vector<std::shared_ptr<ov::
|
|||||||
ov::SinkVector sinks;
|
ov::SinkVector sinks;
|
||||||
for (const auto& node : nodes) {
|
for (const auto& node : nodes) {
|
||||||
auto sink = std::dynamic_pointer_cast<ov::op::Sink>(node);
|
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);
|
sinks.push_back(sink);
|
||||||
}
|
}
|
||||||
return sinks;
|
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;
|
std::vector<std::shared_ptr<ov::Node>> nodes;
|
||||||
for (const auto& sink : sinks) {
|
for (const auto& sink : sinks) {
|
||||||
auto node = std::dynamic_pointer_cast<ov::Node>(sink);
|
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);
|
nodes.push_back(node);
|
||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
@ -823,7 +823,7 @@ void regclass_graph_Model(py::module m) {
|
|||||||
for (py::handle sink : sinks) {
|
for (py::handle sink : sinks) {
|
||||||
auto sink_cpp =
|
auto sink_cpp =
|
||||||
std::dynamic_pointer_cast<ov::op::Sink>(sink.cast<std::shared_ptr<ov::op::v6::Assign>>());
|
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);
|
sinks_cpp.push_back(sink_cpp);
|
||||||
}
|
}
|
||||||
self.add_sinks(sinks_cpp);
|
self.add_sinks(sinks_cpp);
|
||||||
|
@ -43,24 +43,24 @@ public:
|
|||||||
auto ext_it = m_opset_so_extensions.find(op_type_name);
|
auto ext_it = m_opset_so_extensions.find(op_type_name);
|
||||||
if (ext_it != m_opset_so_extensions.end()) {
|
if (ext_it != m_opset_so_extensions.end()) {
|
||||||
auto op_extension = std::dynamic_pointer_cast<ov::BaseOpExtension>(ext_it->second->extension());
|
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);
|
util::DictAttributeDeserializer visitor(attributes, m_variables);
|
||||||
auto outputs = op_extension->create(arguments, visitor);
|
auto outputs = op_extension->create(arguments, visitor);
|
||||||
|
|
||||||
NGRAPH_CHECK(outputs.size() > 0,
|
OPENVINO_ASSERT(outputs.size() > 0,
|
||||||
"Failed to create extension operation with type: ",
|
"Failed to create extension operation with type: ",
|
||||||
op_type_name,
|
op_type_name,
|
||||||
" because it doesn't contain output ports. Operation should has at least one output port.");
|
" because it doesn't contain output ports. Operation should has at least one output port.");
|
||||||
|
|
||||||
auto node = outputs[0].get_node_shared_ptr();
|
auto node = outputs[0].get_node_shared_ptr();
|
||||||
return node;
|
return node;
|
||||||
} else {
|
} else {
|
||||||
std::shared_ptr<ov::Node> op_node = std::shared_ptr<ov::Node>(m_opset.create(op_type_name));
|
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);
|
OPENVINO_ASSERT(op_node != nullptr, "Couldn't create operation: ", op_type_name);
|
||||||
NGRAPH_CHECK(!ov::op::util::is_constant(op_node),
|
OPENVINO_ASSERT(!ov::op::util::is_constant(op_node),
|
||||||
"Currently NodeFactory doesn't support Constant operation: ",
|
"Currently NodeFactory doesn't support Constant operation: ",
|
||||||
op_type_name);
|
op_type_name);
|
||||||
|
|
||||||
util::DictAttributeDeserializer visitor(attributes, m_variables);
|
util::DictAttributeDeserializer visitor(attributes, m_variables);
|
||||||
|
|
||||||
@ -76,18 +76,18 @@ public:
|
|||||||
// Check for available extensions first, because they may override ops from main opset
|
// Check for available extensions first, because they may override ops from main opset
|
||||||
auto ext_it = m_opset_so_extensions.find(op_type_name);
|
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.
|
// 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(),
|
OPENVINO_ASSERT(ext_it == m_opset_so_extensions.end(),
|
||||||
"Couldn't create operation of type ",
|
"Couldn't create operation of type ",
|
||||||
op_type_name,
|
op_type_name,
|
||||||
" from an extension library as no inputs were provided. Currently NodeFactory doesn't support ",
|
" from an extension library as no inputs were provided. Currently NodeFactory doesn't support ",
|
||||||
"operations without inputs. Provide at least one input.");
|
"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));
|
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);
|
OPENVINO_ASSERT(op_node != nullptr, "Couldn't create operation: ", op_type_name);
|
||||||
NGRAPH_CHECK(!ov::op::util::is_constant(op_node),
|
OPENVINO_ASSERT(!ov::op::util::is_constant(op_node),
|
||||||
"Currently NodeFactory doesn't support Constant node: ",
|
"Currently NodeFactory doesn't support Constant node: ",
|
||||||
op_type_name);
|
op_type_name);
|
||||||
|
|
||||||
OPENVINO_WARN << "Empty op created! Please assign inputs and attributes and run validate() before op is used.";
|
OPENVINO_WARN << "Empty op created! Please assign inputs and attributes and run validate() before op is used.";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user