Skip to content

Commit 71ca0c5

Browse files
authored
build: Update OpenVINO model generation script with new API (#7811)
1 parent 75588dc commit 71ca0c5

File tree

6 files changed

+53
-57
lines changed

6 files changed

+53
-57
lines changed

qa/common/gen_qa_dyna_sequence_models.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,27 +1292,26 @@ def create_openvino_modelfile(models_dir, model_version, max_batch, dtype, shape
12921292
)
12931293
model_version_dir = models_dir + "/" + model_name + "/" + str(model_version)
12941294

1295-
in0 = ng.parameter(shape=batch_dim + shape, dtype=dtype, name="INPUT")
1296-
start = ng.parameter(shape=batch_dim + shape, dtype=dtype, name="START")
1297-
end = ng.parameter(shape=batch_dim + shape, dtype=dtype, name="END")
1298-
ready = ng.parameter(shape=batch_dim + shape, dtype=dtype, name="READY")
1299-
corrid = ng.parameter(shape=batch_dim + shape, dtype=dtype, name="CORRID")
1295+
in0 = ov.opset1.parameter(shape=batch_dim + shape, dtype=dtype, name="INPUT")
1296+
start = ov.opset1.parameter(shape=batch_dim + shape, dtype=dtype, name="START")
1297+
end = ov.opset1.parameter(shape=batch_dim + shape, dtype=dtype, name="END")
1298+
ready = ov.opset1.parameter(shape=batch_dim + shape, dtype=dtype, name="READY")
1299+
corrid = ov.opset1.parameter(shape=batch_dim + shape, dtype=dtype, name="CORRID")
13001300

1301-
tmp1 = ng.add(in0, start)
1302-
tmp2 = ng.multiply(end, corrid)
1303-
tmp = ng.add(tmp1, tmp2)
1304-
op0 = ng.multiply(tmp, ready, name="OUTPUT")
1301+
tmp1 = ov.opset1.add(in0, start)
1302+
tmp2 = ov.opset1.multiply(end, corrid)
1303+
tmp = ov.opset1.add(tmp1, tmp2)
1304+
op0 = ov.opset1.multiply(tmp, ready, name="OUTPUT")
13051305

1306-
function = ng.impl.Function([op0], [in0, start, end, ready, corrid], model_name)
1307-
ie_network = IENetwork(ng.impl.Function.to_capsule(function))
1306+
model = ov.Model([op0], [in0, start, end, ready, corrid], model_name)
13081307

13091308
try:
13101309
os.makedirs(model_version_dir)
13111310
except OSError as ex:
13121311
pass # ignore existing dir
13131312

1314-
ie_network.serialize(
1315-
model_version_dir + "/model.xml", model_version_dir + "/model.bin"
1313+
ov.serialize(
1314+
model, model_version_dir + "/model.xml", model_version_dir + "/model.bin"
13161315
)
13171316

13181317

@@ -1560,8 +1559,7 @@ def create_models(models_dir, dtype, shape, no_batch=True):
15601559
import torch
15611560
from torch import nn
15621561
if FLAGS.openvino:
1563-
from openvino.inference_engine import IENetwork
1564-
import ngraph as ng
1562+
import openvino.runtime as ov
15651563

15661564
import test_util as tu
15671565

qa/common/gen_qa_identity_models.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -574,17 +574,18 @@ def create_openvino_modelfile(
574574
in_name = "INPUT{}".format(io_num)
575575
out_name = "OUTPUT{}".format(io_num)
576576
openvino_inputs.append(
577-
ng.parameter(shape=batch_dim + shape, dtype=dtype, name=in_name)
577+
ov.opset1.parameter(shape=batch_dim + shape, dtype=dtype, name=in_name)
578+
)
579+
openvino_outputs.append(
580+
ov.opset1.result(openvino_inputs[io_num], name=out_name)
578581
)
579-
openvino_outputs.append(ng.result(openvino_inputs[io_num], name=out_name))
580582

581-
function = ng.impl.Function(openvino_outputs, openvino_inputs, model_name)
582-
ie_network = IENetwork(ng.impl.Function.to_capsule(function))
583+
model = ov.Model(openvino_outputs, openvino_inputs, model_name)
583584

584585
os.makedirs(model_version_dir, exist_ok=True)
585586

586-
ie_network.serialize(
587-
model_version_dir + "/model.xml", model_version_dir + "/model.bin"
587+
ov.serialize(
588+
model, model_version_dir + "/model.xml", model_version_dir + "/model.bin"
588589
)
589590

590591

@@ -1317,8 +1318,7 @@ def create_models(models_dir, dtype, shape, io_cnt=1, no_batch=True):
13171318
):
13181319
import tensorrt as trt
13191320
if FLAGS.openvino:
1320-
from openvino.inference_engine import IENetwork
1321-
import ngraph as ng
1321+
import openvino.runtime as ov
13221322

13231323
import test_util as tu
13241324

qa/common/gen_qa_model_repository

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ONNX_VERSION=1.16.1
5555
ONNX_OPSET=0
5656

5757
# OPENVINO version
58-
OPENVINO_VERSION=2023.3.0
58+
OPENVINO_VERSION=2024.4.0
5959

6060
UBUNTU_IMAGE=${UBUNTU_IMAGE:=ubuntu:22.04}
6161
PYTORCH_IMAGE=${PYTORCH_IMAGE:=nvcr.io/nvidia/pytorch:$TRITON_VERSION-py3}

qa/common/gen_qa_models.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,28 +1809,31 @@ def create_openvino_modelfile(
18091809
)
18101810
model_version_dir = models_dir + "/" + model_name + "/" + str(model_version)
18111811

1812-
in0 = ng.parameter(shape=batch_dim + input_shape, dtype=input_dtype, name="INPUT0")
1813-
in1 = ng.parameter(shape=batch_dim + input_shape, dtype=input_dtype, name="INPUT1")
1812+
in0 = ov.opset1.parameter(
1813+
shape=batch_dim + input_shape, dtype=input_dtype, name="INPUT0"
1814+
)
1815+
in1 = ov.opset1.parameter(
1816+
shape=batch_dim + input_shape, dtype=input_dtype, name="INPUT1"
1817+
)
18141818

1815-
r0 = ng.add(in0, in1) if not swap else ng.subtract(in0, in1)
1816-
r1 = ng.subtract(in0, in1) if not swap else ng.add(in0, in1)
1819+
r0 = ov.opset1.add(in0, in1) if not swap else ov.opset1.subtract(in0, in1)
1820+
r1 = ov.opset1.subtract(in0, in1) if not swap else ov.opset1.add(in0, in1)
18171821

1818-
result0 = ng.reshape(r0, batch_dim + output0_shape, special_zero=False)
1819-
result1 = ng.reshape(r1, batch_dim + output1_shape, special_zero=False)
1822+
result0 = ov.opset1.reshape(r0, batch_dim + output0_shape, special_zero=False)
1823+
result1 = ov.opset1.reshape(r1, batch_dim + output1_shape, special_zero=False)
18201824

1821-
op0 = ng.convert(result0, destination_type=output0_dtype, name="OUTPUT0")
1822-
op1 = ng.convert(result1, destination_type=output1_dtype, name="OUTPUT1")
1825+
op0 = ov.opset1.convert(result0, destination_type=output0_dtype, name="OUTPUT0")
1826+
op1 = ov.opset1.convert(result1, destination_type=output1_dtype, name="OUTPUT1")
18231827

1824-
function = ng.impl.Function([op0, op1], [in0, in1], model_name)
1825-
ie_network = IENetwork(ng.impl.Function.to_capsule(function))
1828+
model = ov.Model([op0, op1], [in0, in1], model_name)
18261829

18271830
try:
18281831
os.makedirs(model_version_dir)
18291832
except OSError as ex:
18301833
pass # ignore existing dir
18311834

1832-
ie_network.serialize(
1833-
model_version_dir + "/model.xml", model_version_dir + "/model.bin"
1835+
ov.serialize(
1836+
model, model_version_dir + "/model.xml", model_version_dir + "/model.bin"
18341837
)
18351838

18361839

@@ -2486,8 +2489,7 @@ def create_fixed_models(
24862489
import torch
24872490
from torch import nn
24882491
if FLAGS.openvino:
2489-
from openvino.inference_engine import IENetwork
2490-
import ngraph as ng
2492+
import openvino.runtime as ov
24912493

24922494
import test_util as tu
24932495

qa/common/gen_qa_reshape_models.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -934,30 +934,29 @@ def create_openvino_modelfile(
934934
in_name = "INPUT{}".format(io_num)
935935
out_name = "OUTPUT{}".format(io_num)
936936
openvino_inputs.append(
937-
ng.parameter(
937+
ov.opset1.parameter(
938938
shape=batch_dim + input_shapes[io_num], dtype=dtype, name=in_name
939939
)
940940
)
941941

942942
openvino_outputs.append(
943-
ng.reshape(
943+
ov.opset1.reshape(
944944
openvino_inputs[io_num],
945945
batch_dim + output_shapes[io_num],
946946
name=out_name,
947947
special_zero=False,
948948
)
949949
)
950950

951-
function = ng.impl.Function(openvino_outputs, openvino_inputs, model_name)
952-
ie_network = IENetwork(ng.impl.Function.to_capsule(function))
951+
model = ov.Model(openvino_outputs, openvino_inputs, model_name)
953952

954953
try:
955954
os.makedirs(model_version_dir)
956955
except OSError as ex:
957956
pass # ignore existing dir
958957

959-
ie_network.serialize(
960-
model_version_dir + "/model.xml", model_version_dir + "/model.bin"
958+
ov.serialize(
959+
model, model_version_dir + "/model.xml", model_version_dir + "/model.bin"
961960
)
962961

963962

@@ -1463,8 +1462,7 @@ def create_openvino_models(
14631462
import torch
14641463
from torch import nn
14651464
if FLAGS.openvino:
1466-
from openvino.inference_engine import IENetwork
1467-
import ngraph as ng
1465+
import openvino.runtime as ov
14681466

14691467
import test_util as tu
14701468

qa/common/gen_qa_sequence_models.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,23 +1145,22 @@ def create_openvino_modelfile(models_dir, model_version, max_batch, dtype, shape
11451145
)
11461146
model_version_dir = models_dir + "/" + model_name + "/" + str(model_version)
11471147

1148-
in0 = ng.parameter(shape=batch_dim + shape, dtype=dtype, name="INPUT")
1149-
start = ng.parameter(shape=batch_dim + shape, dtype=dtype, name="START")
1150-
ready = ng.parameter(shape=batch_dim + shape, dtype=dtype, name="READY")
1148+
in0 = ov.opset1.parameter(shape=batch_dim + shape, dtype=dtype, name="INPUT")
1149+
start = ov.opset1.parameter(shape=batch_dim + shape, dtype=dtype, name="START")
1150+
ready = ov.opset1.parameter(shape=batch_dim + shape, dtype=dtype, name="READY")
11511151

1152-
tmp = ng.add(in0, start)
1153-
op0 = ng.multiply(tmp, ready, name="OUTPUT")
1152+
tmp = ov.opset1.add(in0, start)
1153+
op0 = ov.opset1.multiply(tmp, ready, name="OUTPUT")
11541154

1155-
function = ng.impl.Function([op0], [in0, start, ready], model_name)
1156-
ie_network = IENetwork(ng.impl.Function.to_capsule(function))
1155+
model = ov.Model([op0], [in0, start, ready], model_name)
11571156

11581157
try:
11591158
os.makedirs(model_version_dir)
11601159
except OSError as ex:
11611160
pass # ignore existing dir
11621161

1163-
ie_network.serialize(
1164-
model_version_dir + "/model.xml", model_version_dir + "/model.bin"
1162+
ov.serialize(
1163+
model, model_version_dir + "/model.xml", model_version_dir + "/model.bin"
11651164
)
11661165

11671166

@@ -1421,8 +1420,7 @@ def create_models(models_dir, dtype, shape, no_batch=True):
14211420
import torch
14221421
from torch import nn
14231422
if FLAGS.openvino:
1424-
from openvino.inference_engine import IENetwork
1425-
import ngraph as ng
1423+
import openvino.runtime as ov
14261424

14271425
import test_util as tu
14281426

0 commit comments

Comments
 (0)