Skip to content

Commit

Permalink
build: Update OpenVINO model generation script with new API (#7811)
Browse files Browse the repository at this point in the history
  • Loading branch information
yinggeh authored Nov 28, 2024
1 parent 75588dc commit 71ca0c5
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 57 deletions.
28 changes: 13 additions & 15 deletions qa/common/gen_qa_dyna_sequence_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1292,27 +1292,26 @@ def create_openvino_modelfile(models_dir, model_version, max_batch, dtype, shape
)
model_version_dir = models_dir + "/" + model_name + "/" + str(model_version)

in0 = ng.parameter(shape=batch_dim + shape, dtype=dtype, name="INPUT")
start = ng.parameter(shape=batch_dim + shape, dtype=dtype, name="START")
end = ng.parameter(shape=batch_dim + shape, dtype=dtype, name="END")
ready = ng.parameter(shape=batch_dim + shape, dtype=dtype, name="READY")
corrid = ng.parameter(shape=batch_dim + shape, dtype=dtype, name="CORRID")
in0 = ov.opset1.parameter(shape=batch_dim + shape, dtype=dtype, name="INPUT")
start = ov.opset1.parameter(shape=batch_dim + shape, dtype=dtype, name="START")
end = ov.opset1.parameter(shape=batch_dim + shape, dtype=dtype, name="END")
ready = ov.opset1.parameter(shape=batch_dim + shape, dtype=dtype, name="READY")
corrid = ov.opset1.parameter(shape=batch_dim + shape, dtype=dtype, name="CORRID")

tmp1 = ng.add(in0, start)
tmp2 = ng.multiply(end, corrid)
tmp = ng.add(tmp1, tmp2)
op0 = ng.multiply(tmp, ready, name="OUTPUT")
tmp1 = ov.opset1.add(in0, start)
tmp2 = ov.opset1.multiply(end, corrid)
tmp = ov.opset1.add(tmp1, tmp2)
op0 = ov.opset1.multiply(tmp, ready, name="OUTPUT")

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

try:
os.makedirs(model_version_dir)
except OSError as ex:
pass # ignore existing dir

ie_network.serialize(
model_version_dir + "/model.xml", model_version_dir + "/model.bin"
ov.serialize(
model, model_version_dir + "/model.xml", model_version_dir + "/model.bin"
)


Expand Down Expand Up @@ -1560,8 +1559,7 @@ def create_models(models_dir, dtype, shape, no_batch=True):
import torch
from torch import nn
if FLAGS.openvino:
from openvino.inference_engine import IENetwork
import ngraph as ng
import openvino.runtime as ov

import test_util as tu

Expand Down
16 changes: 8 additions & 8 deletions qa/common/gen_qa_identity_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,17 +574,18 @@ def create_openvino_modelfile(
in_name = "INPUT{}".format(io_num)
out_name = "OUTPUT{}".format(io_num)
openvino_inputs.append(
ng.parameter(shape=batch_dim + shape, dtype=dtype, name=in_name)
ov.opset1.parameter(shape=batch_dim + shape, dtype=dtype, name=in_name)
)
openvino_outputs.append(
ov.opset1.result(openvino_inputs[io_num], name=out_name)
)
openvino_outputs.append(ng.result(openvino_inputs[io_num], name=out_name))

function = ng.impl.Function(openvino_outputs, openvino_inputs, model_name)
ie_network = IENetwork(ng.impl.Function.to_capsule(function))
model = ov.Model(openvino_outputs, openvino_inputs, model_name)

os.makedirs(model_version_dir, exist_ok=True)

ie_network.serialize(
model_version_dir + "/model.xml", model_version_dir + "/model.bin"
ov.serialize(
model, model_version_dir + "/model.xml", model_version_dir + "/model.bin"
)


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

import test_util as tu

Expand Down
2 changes: 1 addition & 1 deletion qa/common/gen_qa_model_repository
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ONNX_VERSION=1.16.1
ONNX_OPSET=0

# OPENVINO version
OPENVINO_VERSION=2023.3.0
OPENVINO_VERSION=2024.4.0

UBUNTU_IMAGE=${UBUNTU_IMAGE:=ubuntu:22.04}
PYTORCH_IMAGE=${PYTORCH_IMAGE:=nvcr.io/nvidia/pytorch:$TRITON_VERSION-py3}
Expand Down
30 changes: 16 additions & 14 deletions qa/common/gen_qa_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1809,28 +1809,31 @@ def create_openvino_modelfile(
)
model_version_dir = models_dir + "/" + model_name + "/" + str(model_version)

in0 = ng.parameter(shape=batch_dim + input_shape, dtype=input_dtype, name="INPUT0")
in1 = ng.parameter(shape=batch_dim + input_shape, dtype=input_dtype, name="INPUT1")
in0 = ov.opset1.parameter(
shape=batch_dim + input_shape, dtype=input_dtype, name="INPUT0"
)
in1 = ov.opset1.parameter(
shape=batch_dim + input_shape, dtype=input_dtype, name="INPUT1"
)

r0 = ng.add(in0, in1) if not swap else ng.subtract(in0, in1)
r1 = ng.subtract(in0, in1) if not swap else ng.add(in0, in1)
r0 = ov.opset1.add(in0, in1) if not swap else ov.opset1.subtract(in0, in1)
r1 = ov.opset1.subtract(in0, in1) if not swap else ov.opset1.add(in0, in1)

result0 = ng.reshape(r0, batch_dim + output0_shape, special_zero=False)
result1 = ng.reshape(r1, batch_dim + output1_shape, special_zero=False)
result0 = ov.opset1.reshape(r0, batch_dim + output0_shape, special_zero=False)
result1 = ov.opset1.reshape(r1, batch_dim + output1_shape, special_zero=False)

op0 = ng.convert(result0, destination_type=output0_dtype, name="OUTPUT0")
op1 = ng.convert(result1, destination_type=output1_dtype, name="OUTPUT1")
op0 = ov.opset1.convert(result0, destination_type=output0_dtype, name="OUTPUT0")
op1 = ov.opset1.convert(result1, destination_type=output1_dtype, name="OUTPUT1")

function = ng.impl.Function([op0, op1], [in0, in1], model_name)
ie_network = IENetwork(ng.impl.Function.to_capsule(function))
model = ov.Model([op0, op1], [in0, in1], model_name)

try:
os.makedirs(model_version_dir)
except OSError as ex:
pass # ignore existing dir

ie_network.serialize(
model_version_dir + "/model.xml", model_version_dir + "/model.bin"
ov.serialize(
model, model_version_dir + "/model.xml", model_version_dir + "/model.bin"
)


Expand Down Expand Up @@ -2486,8 +2489,7 @@ def create_fixed_models(
import torch
from torch import nn
if FLAGS.openvino:
from openvino.inference_engine import IENetwork
import ngraph as ng
import openvino.runtime as ov

import test_util as tu

Expand Down
14 changes: 6 additions & 8 deletions qa/common/gen_qa_reshape_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,30 +934,29 @@ def create_openvino_modelfile(
in_name = "INPUT{}".format(io_num)
out_name = "OUTPUT{}".format(io_num)
openvino_inputs.append(
ng.parameter(
ov.opset1.parameter(
shape=batch_dim + input_shapes[io_num], dtype=dtype, name=in_name
)
)

openvino_outputs.append(
ng.reshape(
ov.opset1.reshape(
openvino_inputs[io_num],
batch_dim + output_shapes[io_num],
name=out_name,
special_zero=False,
)
)

function = ng.impl.Function(openvino_outputs, openvino_inputs, model_name)
ie_network = IENetwork(ng.impl.Function.to_capsule(function))
model = ov.Model(openvino_outputs, openvino_inputs, model_name)

try:
os.makedirs(model_version_dir)
except OSError as ex:
pass # ignore existing dir

ie_network.serialize(
model_version_dir + "/model.xml", model_version_dir + "/model.bin"
ov.serialize(
model, model_version_dir + "/model.xml", model_version_dir + "/model.bin"
)


Expand Down Expand Up @@ -1463,8 +1462,7 @@ def create_openvino_models(
import torch
from torch import nn
if FLAGS.openvino:
from openvino.inference_engine import IENetwork
import ngraph as ng
import openvino.runtime as ov

import test_util as tu

Expand Down
20 changes: 9 additions & 11 deletions qa/common/gen_qa_sequence_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,23 +1145,22 @@ def create_openvino_modelfile(models_dir, model_version, max_batch, dtype, shape
)
model_version_dir = models_dir + "/" + model_name + "/" + str(model_version)

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

tmp = ng.add(in0, start)
op0 = ng.multiply(tmp, ready, name="OUTPUT")
tmp = ov.opset1.add(in0, start)
op0 = ov.opset1.multiply(tmp, ready, name="OUTPUT")

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

try:
os.makedirs(model_version_dir)
except OSError as ex:
pass # ignore existing dir

ie_network.serialize(
model_version_dir + "/model.xml", model_version_dir + "/model.bin"
ov.serialize(
model, model_version_dir + "/model.xml", model_version_dir + "/model.bin"
)


Expand Down Expand Up @@ -1421,8 +1420,7 @@ def create_models(models_dir, dtype, shape, no_batch=True):
import torch
from torch import nn
if FLAGS.openvino:
from openvino.inference_engine import IENetwork
import ngraph as ng
import openvino.runtime as ov

import test_util as tu

Expand Down

0 comments on commit 71ca0c5

Please sign in to comment.