diff --git a/src/core/src/pass/visualize_tree.cpp b/src/core/src/pass/visualize_tree.cpp index a0d0b4a05e3094..cf7bb6e85bdf37 100644 --- a/src/core/src/pass/visualize_tree.cpp +++ b/src/core/src/pass/visualize_tree.cpp @@ -540,15 +540,7 @@ std::string ov::pass::VisualizeTree::get_constant_value(std::shared_ptr no ss << pretty_partial_shape(node->get_output_partial_shape(0), m_symbol_to_name); if (const auto& constant = ov::as_type_ptr(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(); } diff --git a/src/core/tests/pass/visualize_tree.cpp b/src/core/tests/pass/visualize_tree.cpp new file mode 100644 index 00000000000000..1b21f2b294e3db --- /dev/null +++ b/src/core/tests/pass/visualize_tree.cpp @@ -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 make_dummy_add_model(const element::Type& precision) { + const auto c = Constant::create(precision, Shape{3}, {1.0f, -23.21f, std::numeric_limits::infinity()}); + const auto input = std::make_shared(precision, Shape{}); + const auto add = std::make_shared(c, input); + const auto output = std::make_shared(add); + return std::make_shared(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