Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CORE] Fix visualize tree when Constant has got inf values #25451

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
10 changes: 1 addition & 9 deletions src/core/src/pass/visualize_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,15 +540,7 @@ std::string ov::pass::VisualizeTree::get_constant_value(std::shared_ptr<Node> no
ss << pretty_partial_shape(node->get_output_partial_shape(0), m_symbol_to_name);

if (const auto& constant = ov::as_type_ptr<ov::op::v0::Constant>(node)) {
std::string value;
try {
value = get_value(constant, max_elements);
} catch (ov::AssertFailure& ex) {
value = std::string("ov::AssertFailure: ") + ex.what();
} catch (std::exception& ex) {
value = ex.what();
}
ss << "\nvalue: " << value;
ss << "\nvalue: " << get_value(constant, max_elements);
}
return ss.str();
}
Expand Down
66 changes: 66 additions & 0 deletions src/core/tests/pass/visualize_tree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "openvino/pass/visualize_tree.hpp"

#include "common_test_utils/file_utils.hpp"
#include "common_test_utils/test_assertions.hpp"
#include "openvino/core/model.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/constant.hpp"

namespace ov {
namespace test {

using ov::op::v0::Constant;
using ov::op::v0::Parameter;
using ov::op::v0::Result;
using ov::op::v1::Add;

class VisualizeTreeTest : public testing::Test {
protected:
void TearDown() override {
if (util::file_exists(vt_svg_file_path)) {
std::remove(vt_svg_file_path.c_str());
}

if (util::file_exists(dot_file_path)) {
std::remove(dot_file_path.c_str());
}
}

static std::shared_ptr<Model> make_dummy_add_model(const element::Type& precision) {
const auto c = Constant::create(precision, Shape{3}, {1.0f, -23.21f, std::numeric_limits<float>::infinity()});
const auto input = std::make_shared<Parameter>(precision, Shape{});
const auto add = std::make_shared<Add>(c, input);
const auto output = std::make_shared<Result>(add);
return std::make_shared<Model>(ResultVector{output}, ParameterVector{input});
}

const std::string vt_svg_file_path =
util::path_join({utils::getExecutableDirectory(), utils::generateTestFilePrefix() + "_tree.svg"});
const std::string dot_file_path = vt_svg_file_path + ".dot";
};

TEST_F(VisualizeTreeTest, model_has_constant_with_inf) {
constexpr auto precision = element::f32;
const auto model = make_dummy_add_model(precision);

pass::VisualizeTree vt(vt_svg_file_path);

OV_ASSERT_NO_THROW(vt.run_on_model(model));
ASSERT_TRUE(util::file_exists(dot_file_path)) << dot_file_path;
}

TEST_F(VisualizeTreeTest, model_has_constant_with_no_inf) {
constexpr auto precision = element::f16;
const auto model = make_dummy_add_model(precision);

pass::VisualizeTree vt(vt_svg_file_path);

OV_ASSERT_NO_THROW(vt.run_on_model(model));
ASSERT_TRUE(util::file_exists(dot_file_path)) << dot_file_path;
}
} // namespace test
} // namespace ov
Loading