Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ GLUFusion::GLUFusion() {

auto variadic_split =
ov::as_type_ptr<v1::VariadicSplit>(pattern_map.at(variadic_split_m).get_node_shared_ptr());
if (!variadic_split)
return false;
auto variadic_split_in_ps = variadic_split->get_input_partial_shape(0);
auto last_dim = variadic_split_in_ps.rank().get_length() - 1;

Expand All @@ -106,7 +108,7 @@ GLUFusion::GLUFusion() {
if (split_lengths_value != split_length)
return false;

auto data = pattern_map.at(data_m);
const auto& data = pattern_map.at(data_m);
auto output_type = m.get_match_root()->get_output_element_type(0);

auto swiglu = std::make_shared<ov::op::internal::GLU>(data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,17 @@ namespace {
std::string make_unique_tensor_name(const TensorNamesMap& names_map, const std::string& name, size_t hash) {
static const auto port_num_pattern = std::regex(R"((.*?)(:\d+)?$)");
std::smatch matches;
std::regex_match(name, matches, port_num_pattern);
// "." doesn't match line terminators, so names containing them don't match port_num_pattern.
const bool has_port_num = std::regex_match(name, matches, port_num_pattern);
const std::string base_name = has_port_num ? matches[1].str() : name;
const std::string port_suffix = (has_port_num && matches[2].matched) ? matches[2].str() : std::string();

auto idx = 1;

auto new_name = matches[1].str() + ov::descriptor::unique_name_sep + std::to_string(idx);
if (matches[2].matched) {
new_name += matches[2];
}
auto new_name = base_name + ov::descriptor::unique_name_sep + std::to_string(idx) + port_suffix;

for (auto it = names_map.find(name); it != names_map.end() && hash != it->second; ++idx) {
new_name = matches[1].str() + ov::descriptor::unique_name_sep + std::to_string(idx);
if (matches[2].matched) {
new_name += matches[2];
}

new_name = base_name + ov::descriptor::unique_name_sep + std::to_string(idx) + port_suffix;
it = names_map.find(new_name);
}

Expand Down Expand Up @@ -143,7 +139,7 @@ bool ResolveNameCollisions::run_on_model(const std::shared_ptr<Model>& model) {
}
}
};
const auto resolve_node_name = m_resolve_all_names ? resolve_nodes_any_name : resolve_nodes_generated_name;
const auto& resolve_node_name = m_resolve_all_names ? resolve_nodes_any_name : resolve_nodes_generated_name;

collect_name_collisions_map(model, node_names_map);
for (const auto& [_, same_name_ops] : node_names_map) {
Expand Down
21 changes: 21 additions & 0 deletions src/common/transformations/tests/resolve_names_collisions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,27 @@ TEST_F(ResolveTensorNamesTest, collision_on_outputsinputs) {
EXPECT_THAT(result_2->output(0).get_names(), UnorderedElementsAre("result_1"));
}

TEST_F(ResolveTensorNamesTest, collision_with_multiline_name) {
// "." in the port-number regex doesn't match line terminators, so a colliding name
// containing '\n' must still be made unique via the non-regex fallback path.
auto input_1 = std::make_shared<Parameter>(element::f32, Shape{1, 3});
auto input_2 = std::make_shared<Parameter>(element::f32, Shape{1, 3});
auto result_1 = std::make_shared<Result>(input_1);
auto result_2 = std::make_shared<Result>(input_2);

input_1->output(0).set_names({"foo\nbar"});
input_2->output(0).set_names({"foo\nbar"});

auto model = std::make_shared<Model>(ResultVector{result_1, result_2}, ParameterVector{input_1, input_2});

pass::Manager pass_manager;
pass_manager.register_pass<pass::ResolveNameCollisions>();
pass_manager.run_passes(model);

EXPECT_THAT(input_1->output(0).get_names(), UnorderedElementsAre("foo\nbar"));
EXPECT_THAT(input_2->output(0).get_names(), UnorderedElementsAre("foo\nbar_1"));
}

TEST(ResolveNameCollisionsTest, FixTensorNamesMultiSubgraphOp) {
// external params
auto X = std::make_shared<Parameter>(element::f32, Shape{4});
Expand Down
Loading