Repository navigation
Expand file tree
/
Copy pathhash_tests.cpp
More file actions
99 lines (80 loc) · 3.68 KB
/
Copy pathhash_tests.cpp
File metadata and controls
99 lines (80 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (C) 2018-2026 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include "openvino/core/model.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/parameter.hpp"
#include "openvino/util/container_util.hpp"
#include "transformations/hash.hpp"
namespace v0 = ov::op::v0;
namespace ov::test {
using v0::Parameter, v0::Constant, ov::op::v1::Add;
TEST(HashTest, same_model_hashed_without_weights) {
uint64_t hash1 = 0, hash2 = 0;
constexpr auto skip_weights = true;
// create same model twice and hash without weights
// detects issue when first 8-byte value used instead weights which may have some bits in uninitialized state
{
int data_value = 121;
const auto data = Tensor(element::i32, {1}, &data_value);
auto out = std::make_shared<Add>(std::make_shared<Parameter>(element::i32, Shape{1}),
std::make_shared<Constant>(data));
auto model = std::make_shared<Model>(OutputVector{out}, "TestModel");
ov::pass::Hash hasher(hash1, skip_weights);
hasher.run_on_model(model);
}
{
int data_value = 121;
const auto data = ov::Tensor(element::i32, {1}, &data_value);
auto out = std::make_shared<Add>(std::make_shared<Parameter>(element::i32, Shape{1}),
std::make_shared<Constant>(data));
auto model = std::make_shared<Model>(OutputVector{out}, "TestModel");
ov::pass::Hash hasher(hash2, skip_weights);
hasher.run_on_model(model);
}
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);
}
TEST(HashTest, same_model_struct_different_weigth_by_offset) {
constexpr auto weights = ov::util::make_array<int>(11, 11, 12);
uint64_t hash1 = 0, hash2 = 0;
{
auto out = std::make_shared<Add>(std::make_shared<Parameter>(element::i32, Shape{1}),
std::make_shared<Constant>(element::i32, Shape{1}, weights.data()));
out = std::make_shared<Add>(out, std::make_shared<Constant>(element::i32, Shape{1}, weights.data() + 1));
auto model = std::make_shared<Model>(OutputVector{out}, "TestModel");
ov::pass::Hash hasher(hash1);
hasher.run_on_model(model);
}
{
auto out = std::make_shared<Add>(std::make_shared<Parameter>(element::i32, Shape{1}),
std::make_shared<Constant>(element::i32, Shape{1}, weights.data()));
out = std::make_shared<Add>(out, std::make_shared<Constant>(element::i32, Shape{1}, weights.data() + 2));
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::test