Skip to content

Commit

Permalink
[CORE] Fix visualize tree when Constant has got inf values (openvinot…
Browse files Browse the repository at this point in the history
…oolkit#25451)

### Details:
- Remove catch exception when get Constant data as there is no exception
 - Add test to check `inf` values are serialized correctly

### Tickets:
 - CVS-121479

---------

Co-authored-by: Michal Lukaszewski <[email protected]>
  • Loading branch information
praasz and mlukasze authored Jul 10, 2024
1 parent 3f98a75 commit eab547b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 9 deletions.
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

0 comments on commit eab547b

Please sign in to comment.