Skip to content
Closed
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 @@ -35,6 +35,8 @@ class OPENVINO_API WeightlessCacheAttribute : public RuntimeAttribute {

bool is_copyable() const override;

bool visit_attributes(AttributeVisitor& visitor) override;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can some test be added in src/core/tests/pass/serialization/serialize.cpp


size_t original_size;
size_t bin_offset;
ov::element::Type original_dtype;
Expand Down
7 changes: 7 additions & 0 deletions src/core/src/op/util/weightless_caching_attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ bool ov::WeightlessCacheAttribute::is_copyable() const {
return false;
}

bool ov::WeightlessCacheAttribute::visit_attributes(AttributeVisitor& visitor) {
visitor.on_attribute("original_size", original_size);
visitor.on_attribute("bin_offset", bin_offset);
visitor.on_attribute("original_dtype", original_dtype);
return true;
}

OPENVINO_API void ov::copy_weightless_cache_attr(const std::shared_ptr<ov::Node>& from,
const std::shared_ptr<ov::Node>& to) {
const auto& rt_info = from->get_rt_info();
Expand Down
44 changes: 44 additions & 0 deletions src/core/tests/pass/serialization/serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "common_test_utils/file_utils.hpp"
#include "common_test_utils/graph_comparator.hpp"
#include "common_test_utils/test_common.hpp"
#include "openvino/core/rt_info/weightless_caching_attributes.hpp"
#include "openvino/util/file_util.hpp"
#include "read_ir.hpp"

Expand Down Expand Up @@ -509,3 +510,46 @@ TEST_F(MetaDataSerialize, set_complex_meta_information) {
check_rt_info(s_model);
}
}

TEST_F(MetaDataSerialize, check_weightless_cache_attribute_after_serialization) {
auto model = ov::test::readModel(ir_with_meta);
size_t actual_count_of_attribs = 0;
size_t expected_count_of_attribs = 0;
auto const_node = std::make_shared<ov::op::v0::Constant>(ov::element::f32, ov::Shape{1}, std::vector<float>{-5.0f});
auto ref_weightless_cache_attribute =
ov::WeightlessCacheAttribute(/* original_size = */ const_node->get_byte_size(),
/* bin_offset = */ 0,
/* original_dtype = */ const_node->get_element_type());

for (auto&& ov_node : model->get_ops()) {
if (ov_node->get_friendly_name() == "activation") { // ReLU
ov_node->set_argument(1, const_node->get_default_output());
model->set_topological_sort(
ov::topological_sort<std::vector<std::shared_ptr<ov::Node>>>); // invalidate topological sort
const_node->get_rt_info().emplace(ov::WeightlessCacheAttribute::get_type_info_static(),
ref_weightless_cache_attribute);
++expected_count_of_attribs;
}
}

// Serialize the model
ov::serialize(model, m_out_xml_path, m_out_bin_path);

auto s_model = ov::test::readModel(m_out_xml_path, m_out_bin_path);
for (auto&& ov_node : s_model->get_ops()) {
if (auto it_weightless_cache_attribute =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also check that this condition is true for expected nodes?

ov_node->get_rt_info().find(ov::WeightlessCacheAttribute::get_type_info_static());
it_weightless_cache_attribute != ov_node->get_rt_info().end()) {
auto weightless_cache_attribute =
(*it_weightless_cache_attribute).second.as<ov::WeightlessCacheAttribute>();

EXPECT_EQ(weightless_cache_attribute.original_size, ref_weightless_cache_attribute.original_size);
EXPECT_EQ(weightless_cache_attribute.bin_offset, ref_weightless_cache_attribute.bin_offset);
EXPECT_EQ(weightless_cache_attribute.original_dtype, ref_weightless_cache_attribute.original_dtype);

++actual_count_of_attribs;
}
}

EXPECT_EQ(expected_count_of_attribs, actual_count_of_attribs);
}
Loading