Skip to content

Commit

Permalink
Align friendly names uniqueization (#22729)
Browse files Browse the repository at this point in the history
### Details:
Removed code that makes friendly names unique from Serialization and a
name uniqueness check from Deserializator.
Enabled the mode of ResolveNameCollisions transformation to uniqueize
all friendly names, not only autogenerated in Frontends

### Tickets:
 - *CVS-131567*

---------

Co-authored-by: Evgenya Nugmanova <[email protected]>
Co-authored-by: Andrei Kochin <[email protected]>
  • Loading branch information
3 people authored Mar 25, 2024
1 parent 9093db5 commit 1049c03
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ bool ov::pass::MOCTransformations::run_on_model(const std::shared_ptr<ov::Model>
REGISTER_PASS(manager, AlignEltwiseInputRanks)
REGISTER_PASS(manager, SharedOpOptimization)
REGISTER_PASS(manager, ConstantFolding)
REGISTER_PASS(manager, ResolveNameCollisions)
manager.register_pass<ResolveNameCollisions>(true);
manager.run_passes(f);

if (!m_use_shapes) {
Expand Down
25 changes: 1 addition & 24 deletions src/core/src/pass/serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,28 +783,6 @@ std::string escape_delim(const std::string& name, const char delim = ',') {
return result_name;
}

std::string generate_unique_name(const std::unordered_set<std::string>& unique_names,
const std::string& base_name,
int suffix) {
std::string new_name = base_name + std::to_string(suffix);
if (unique_names.find(new_name) == unique_names.end()) {
return new_name;
} else {
suffix++;
return generate_unique_name(unique_names, base_name, suffix);
}
}

// TODO: remove when CNNNetwork will be supporting not-unique names
std::string get_node_unique_name(std::unordered_set<std::string>& unique_names, const ov::Node* n) {
std::string name = n->get_friendly_name();
if (unique_names.find(name) != unique_names.end()) {
name = generate_unique_name(unique_names, name, 0);
}
unique_names.insert(name);
return name;
}

void visit_exec_graph_node(pugi::xml_node& layer, const ov::Node* n) {
auto data = layer.child("data");
for (const auto& param : n->get_rt_info()) {
Expand Down Expand Up @@ -936,7 +914,6 @@ void ngfunction_2_ir(pugi::xml_node& netXml,
pugi::xml_node layers = netXml.append_child("layers");

const std::unordered_map<ov::Node*, int> layer_ids = create_layer_ids(model);
std::unordered_set<std::string> unique_names;

const bool exec_graph = is_exec_graph(model);

Expand Down Expand Up @@ -976,7 +953,7 @@ void ngfunction_2_ir(pugi::xml_node& netXml,
// If determinism is not required, include auto-generated names into xml
// layer name is not critical for hash computing
if (!deterministic) {
layer.append_attribute("name").set_value(get_node_unique_name(unique_names, node).c_str());
layer.append_attribute("name").set_value(node->get_friendly_name().c_str());
}
layer.append_attribute("type").set_value(translate_type_name(node_type_name).c_str());
if (!exec_graph) {
Expand Down
4 changes: 0 additions & 4 deletions src/frontends/ir/src/ir_deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,13 @@ std::shared_ptr<ov::Model> ov::XmlDeserializer::parse_function(const pugi::xml_n
std::map<size_t /*layer-id*/, NodeParams> params;

std::vector<size_t /*layer-id*/> outputs;
std::unordered_set<std::string> opName;

std::vector<size_t> order;
std::set<size_t> dfs_used_nodes;
std::map<size_t /*to-layer-id*/, std::vector<Edge>> edges;
// Read all layers and store their parameters in params map
FOREACH_CHILD (node, root.child("layers"), "layer") {
auto node_param = parse_generic_params(node);
if (opName.find(node_param.name) != opName.end() && node_param.type != "Result")
OPENVINO_THROW("Invalid IR! ", node_param.name, " name is not unique!");
opName.insert(node_param.name);
params[node_param.layerId] = {node, node_param};
if (node_param.type == "Result" || node_param.type == "Assign") {
outputs.push_back(node_param.layerId);
Expand Down
2 changes: 1 addition & 1 deletion src/frontends/ir/tests/frontend_test_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ TEST_F(IRFrontendTests, name_is_not_unique) {
createTemporalModelFile(xmlModel, buffer);
std::shared_ptr<ov::Model> model;

ASSERT_THROW(core.read_model(xmlFileName, binFileName), ov::Exception);
EXPECT_NO_THROW(core.read_model(xmlFileName, binFileName));
}

TEST_F(IRFrontendTests, edge_has_wrong_port_id) {
Expand Down
2 changes: 1 addition & 1 deletion src/frontends/onnx/frontend/src/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void FrontEnd::normalize(const std::shared_ptr<ov::Model>& model) const {
// Here, you can register transformations as a second step of importing process
// In particular, you can operate on not supported ops (it allows to N:N ONNX->OV mapping).
ov::pass::Manager manager;
manager.register_pass<pass::ResolveNameCollisions>();
manager.register_pass<pass::ResolveNameCollisions>(true);
manager.run_passes(model);
}

Expand Down
2 changes: 1 addition & 1 deletion src/frontends/paddle/src/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ void FrontEnd::add_extension(const std::shared_ptr<ov::Extension>& extension) {

void FrontEnd::normalize(const std::shared_ptr<ov::Model>& model) const {
ov::pass::Manager manager;
manager.register_pass<ov::pass::ResolveNameCollisions>();
manager.register_pass<ov::pass::ResolveNameCollisions>(true);
manager.run_passes(model);
}

Expand Down
2 changes: 1 addition & 1 deletion src/frontends/tensorflow/src/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ void FrontEnd::normalize(const std::shared_ptr<ov::Model>& model) const {
manager.register_pass<ov::pass::RemoveConcatZeroDimInput>();
manager.register_pass<ov::pass::TransposeSinkingGeneral>();
manager.register_pass<ov::pass::ReverseShapeAndTypeInfer>();
manager.register_pass<ov::pass::ResolveNameCollisions>();
manager.register_pass<ov::pass::ResolveNameCollisions>(true);
manager.run_passes(model);
}

Expand Down
2 changes: 1 addition & 1 deletion src/frontends/tensorflow_lite/src/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void FrontEnd::normalize(const std::shared_ptr<ov::Model>& function) const {
manager.register_pass<ov::frontend::tensorflow_lite::pass::Rfft2dSimplifier>();
manager.register_pass<ov::pass::TransposeSinking>();
manager.register_pass<ov::pass::TransposeSinkingGeneral>();
manager.register_pass<ov::pass::ResolveNameCollisions>();
manager.register_pass<ov::pass::ResolveNameCollisions>(true);
manager.run_passes(function);
}

Expand Down

0 comments on commit 1049c03

Please sign in to comment.