OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
OV model hashing: fix the hashing of the weights (#33631)
Razvan Apetroaie794c53ead731
diff --git a/src/common/transformations/tests/hash_tests.cpp b/src/common/transformations/tests/hash_tests.cppindex 3e5e8be8b33..4366a1e84f0 100644--- a/src/common/transformations/tests/hash_tests.cpp+++ b/src/common/transformations/tests/hash_tests.cpp@@ -43,4 +43,30 @@ TEST(HashTest, same_model_hashed_without_weights) {EXPECT_EQ(hash1, hash2);}++TEST(HashTest, same_model_struct_different_weigth) {+ uint64_t hash1 = 0, hash2 = 0;++ {+ int data_value = 121;+ auto out = std::make_shared<Add>(std::make_shared<Parameter>(element::i32, Shape{1}),+ std::make_shared<Constant>(element::i32, Shape{1}, &data_value));+ auto model = std::make_shared<Model>(OutputVector{out}, "TestModel");++ ov::pass::Hash hasher(hash1);+ hasher.run_on_model(model);+ }+ {+ int data_value = 13;+ auto out = std::make_shared<Add>(std::make_shared<Parameter>(element::i32, Shape{1}),+ std::make_shared<Constant>(element::i32, Shape{1}, &data_value));+ auto model = std::make_shared<Model>(OutputVector{out}, "TestModel");++ ov::pass::Hash hasher(hash2);+ hasher.run_on_model(model);+ }++ EXPECT_NE(hash1, hash2);+}+} // namespace ov::testdiff --git a/src/core/src/xml_util/constant_writer.cpp b/src/core/src/xml_util/constant_writer.cppindex 1bf98a716e7..e5e112a6338 100644--- a/src/core/src/xml_util/constant_writer.cpp+++ b/src/core/src/xml_util/constant_writer.cpp@@ -81,7 +81,8 @@ ConstantWriter::FilePosition ConstantWriter::write(const char* ptr,m_hash_to_file_positions.insert({hash, {offset, static_cast<const void*>(ptr)}});}if (m_write_hash_value) {- m_binary_output.get().write(reinterpret_cast<const char*>(&hash), sizeof(uint64_t));+ // hash stored with special ostream only+ m_binary_output.get().write(reinterpret_cast<const char*>(&hash), hash);} else {m_binary_output.get().write(ptr_to_write, new_size);}