-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathtest_model_builder.py
68 lines (57 loc) · 2.25 KB
/
test_model_builder.py
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
# Copyright (c) 2025 Intel Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from pathlib import Path
import openvino as ov
import pytest
from nncf.openvino.graph.model_builder import OVModelBuilder
from tests.openvino.native.common import compare_nncf_graphs
from tests.openvino.native.common import get_actual_reference_for_current_openvino
from tests.openvino.native.models import ConvModel
from tests.openvino.native.models import DynamicModel
from tests.openvino.native.models import FPModel
from tests.openvino.native.models import LinearModel
REFERENCE_GRAPHS_DIR = Path("reference_graphs") / "original_nncf_graph"
MODEL_BUILDER = OVModelBuilder()
FAST_BC_CASES = [
{
"model": ConvModel(),
"input_ids": [("Conv", 0)],
"output_ids": [("Conv", 0)],
},
{
"model": FPModel(const_dtype=ov.Type.bf16),
"input_ids": [("MatMul", 0)],
"output_ids": [("MatMul", 0)],
},
{
"model": LinearModel(),
"input_ids": [("MatMul", 0)],
"output_ids": [("MatMul", 0)],
},
{
"model": DynamicModel(),
"input_ids": [("Conv", 0)],
"output_ids": [("Conv", 0)],
},
]
TESTING_MODELS_DATA = FAST_BC_CASES
@pytest.mark.parametrize("model_data", TESTING_MODELS_DATA)
def test_model_building(model_data):
model_to_test = model_data["model"]
model = model_to_test.ov_model
node_mapping = {op.get_friendly_name(): op for op in model.get_ops()}
built_model = MODEL_BUILDER.build(
input_ids=model_data["input_ids"], output_ids=model_data["output_ids"], node_mapping=node_mapping
)
path_to_dot = get_actual_reference_for_current_openvino(
REFERENCE_GRAPHS_DIR / f"built_{model_to_test.ref_graph_name}"
)
compare_nncf_graphs(built_model, path_to_dot)