7
7
#include < fstream>
8
8
9
9
#include " common_test_utils/common_utils.hpp"
10
+ #include " common_test_utils/graph_comparator.hpp"
10
11
#include " common_test_utils/test_common.hpp"
11
12
#include " openvino/opsets/opset8.hpp"
12
13
#include " openvino/pass/serialize.hpp"
14
+ #include " openvino/runtime/core.hpp"
13
15
#include " transformations/common_optimizations/compress_float_constants.hpp"
14
16
15
17
class SerializationConstantCompressionTest : public ov ::test::TestsCommon {
@@ -312,3 +314,72 @@ TEST_F(SerializationConstantCompressionTest, IdenticalConstantsDifferentTypesI32
312
314
313
315
ASSERT_EQ (file_size (bin_1), unique_const_count * ov::shape_size (shape) * sizeof (int32_t ));
314
316
}
317
+
318
+ TEST_F (SerializationConstantCompressionTest, EmptyConstants) {
319
+ constexpr int unique_const_count = 1 ;
320
+ auto A = ov::opset8::Constant::create (ov::element::i32, ov::Shape{0 }, std::vector<int32_t >{});
321
+ auto B = ov::opset8::Constant::create (ov::element::i32, ov::Shape{0 }, std::vector<int32_t >{});
322
+
323
+ auto model_initial = std::make_shared<ov::Model>(ov::NodeVector{A, B}, ov::ParameterVector{});
324
+
325
+ ov::pass::Serialize (m_out_xml_path_1, m_out_bin_path_1).run_on_model (model_initial);
326
+
327
+ std::ifstream xml_1 (m_out_xml_path_1, std::ios::binary);
328
+ std::ifstream bin_1 (m_out_bin_path_1, std::ios::binary);
329
+
330
+ ASSERT_EQ (file_size (bin_1), unique_const_count * sizeof (int8_t ));
331
+
332
+ ov::Core core;
333
+ auto model_imported = core.read_model (m_out_xml_path_1, m_out_bin_path_1);
334
+
335
+ bool success;
336
+ std::string message;
337
+ std::tie (success, message) = compare_functions (model_initial, model_imported, true , true , false , true , true );
338
+ ASSERT_TRUE (success) << message;
339
+ }
340
+
341
+ TEST_F (SerializationConstantCompressionTest, EmptyAndNotEmptyConstantSameValues) {
342
+ constexpr int unique_const_count = 1 ;
343
+ auto A = ov::opset8::Constant::create (ov::element::i32, ov::Shape{0 }, std::vector<int32_t >{});
344
+ auto B = ov::opset8::Constant::create (ov::element::i8, ov::Shape{1 }, std::vector<int8_t >{0 });
345
+
346
+ auto model_initial = std::make_shared<ov::Model>(ov::NodeVector{A, B}, ov::ParameterVector{});
347
+
348
+ ov::pass::Serialize (m_out_xml_path_1, m_out_bin_path_1).run_on_model (model_initial);
349
+
350
+ std::ifstream xml_1 (m_out_xml_path_1, std::ios::binary);
351
+ std::ifstream bin_1 (m_out_bin_path_1, std::ios::binary);
352
+
353
+ ASSERT_EQ (file_size (bin_1), unique_const_count * sizeof (int8_t ));
354
+
355
+ ov::Core core;
356
+ auto model_imported = core.read_model (m_out_xml_path_1, m_out_bin_path_1);
357
+
358
+ bool success;
359
+ std::string message;
360
+ std::tie (success, message) = compare_functions (model_initial, model_imported, true , true , false , true , true );
361
+ ASSERT_TRUE (success) << message;
362
+ }
363
+
364
+ TEST_F (SerializationConstantCompressionTest, EmptyAndNotEmptyConstantsDifferentValues) {
365
+ constexpr int unique_const_count = 2 ;
366
+ auto A = ov::opset8::Constant::create (ov::element::i32, ov::Shape{0 }, std::vector<int32_t >{});
367
+ auto B = ov::opset8::Constant::create (ov::element::i8, ov::Shape{1 }, std::vector<int8_t >{1 });
368
+
369
+ auto model_initial = std::make_shared<ov::Model>(ov::NodeVector{A, B}, ov::ParameterVector{});
370
+
371
+ ov::pass::Serialize (m_out_xml_path_1, m_out_bin_path_1).run_on_model (model_initial);
372
+
373
+ std::ifstream xml_1 (m_out_xml_path_1, std::ios::binary);
374
+ std::ifstream bin_1 (m_out_bin_path_1, std::ios::binary);
375
+
376
+ ASSERT_EQ (file_size (bin_1), unique_const_count * sizeof (int8_t ));
377
+
378
+ ov::Core core;
379
+ auto model_imported = core.read_model (m_out_xml_path_1, m_out_bin_path_1);
380
+
381
+ bool success;
382
+ std::string message;
383
+ std::tie (success, message) = compare_functions (model_initial, model_imported, true , true , false , true , true );
384
+ ASSERT_TRUE (success) << message;
385
+ }
0 commit comments