Skip to content

Commit 01ddcd2

Browse files
authored
[Core] Validate model before serialization (#26184)
### Details: - Added model validate model before serialization. - Added test. ### Tickets: - CVS-133613
1 parent fd25ea4 commit 01ddcd2

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/core/src/pass/serialize.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,8 @@ namespace ov {
12361236
bool pass::Serialize::run_on_model(const std::shared_ptr<ov::Model>& model) {
12371237
RUN_ON_FUNCTION_SCOPE(Serialize);
12381238

1239+
model->validate_nodes_and_infer_types();
1240+
12391241
// TODO xxx-105807: if rt_info is set in python api as a string ['precise_0'] = '',
12401242
// we need to convert value to a class in order to have rt_info in the IR. The code below will convert
12411243
// ['precise_0'] = '' into => rt_info['precise_0'] = DisableFP16Compression{}

src/core/tests/pass/serialization/cleanup.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,12 @@ TEST_F(SerializationCleanupTest, SerializationShouldWorkWithDynamicFunction) {
5656
ASSERT_TRUE(std::ifstream(m_out_xml_path, std::ios::in).good());
5757
ASSERT_TRUE(std::ifstream(m_out_bin_path, std::ios::in).good());
5858
}
59+
60+
TEST_F(SerializationCleanupTest, SerializationShouldNotWorkWithMissingParameter) {
61+
const auto model = create_test_model("RemovedParameter", ov::PartialShape{2});
62+
model->remove_parameter(model->get_parameters()[0]);
63+
64+
ASSERT_ANY_THROW(ov::pass::Serialize(m_out_xml_path, m_out_bin_path).run_on_model(model));
65+
EXPECT_FALSE(std::ifstream(m_out_xml_path, std::ios::in).good());
66+
EXPECT_FALSE(std::ifstream(m_out_bin_path, std::ios::in).good());
67+
}

0 commit comments

Comments
 (0)