From 48be9ce14b088effe4efdc0690419d17a40bef91 Mon Sep 17 00:00:00 2001
From: Yingge He <157551214+yinggeh@users.noreply.github.com>
Date: Fri, 3 Jan 2025 14:23:27 -0800
Subject: [PATCH] ci: Fix OpenVINO models (#7904)

---
 LICENSE                                  |  2 +-
 qa/common/gen_common.py                  | 20 +++++++++++++++++++-
 qa/common/gen_qa_dyna_sequence_models.py | 13 +++----------
 qa/common/gen_qa_identity_models.py      | 10 +++-------
 qa/common/gen_qa_model_repository        |  4 ++--
 qa/common/gen_qa_models.py               | 13 +++----------
 qa/common/gen_qa_reshape_models.py       | 13 +++----------
 qa/common/gen_qa_sequence_models.py      | 13 +++----------
 8 files changed, 37 insertions(+), 51 deletions(-)

diff --git a/LICENSE b/LICENSE
index 914565ec7d..d367cc74ad 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
+Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
diff --git a/qa/common/gen_common.py b/qa/common/gen_common.py
index 417ad9477a..5b7709504b 100644
--- a/qa/common/gen_common.py
+++ b/qa/common/gen_common.py
@@ -1,4 +1,4 @@
-# Copyright 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# Copyright 2023-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -24,6 +24,7 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+import os
 from typing import List
 
 # Common utilities for model generation scripts
@@ -168,3 +169,20 @@ def np_to_torch_dtype(np_dtype):
     elif np_dtype == np_dtype_string:
         return List[str]
     return None
+
+
+def openvino_save_model(model_version_dir, model):
+    import openvino as ov
+
+    # W/A for error moving to OpenVINO new APIs "Attempt to get a name for a Tensor without names".
+    # For more details, check https://github.com/triton-inference-server/openvino_backend/issues/89
+    if len(model.outputs) == 0:
+        model.outputs[0].get_tensor().set_names({"OUTPUT"})
+    else:
+        for idx, out in enumerate(model.outputs):
+            out.get_tensor().set_names({f"OUTPUT{idx}"})
+
+    os.makedirs(model_version_dir, exist_ok=True)
+    ov.serialize(
+        model, model_version_dir + "/model.xml", model_version_dir + "/model.bin"
+    )
diff --git a/qa/common/gen_qa_dyna_sequence_models.py b/qa/common/gen_qa_dyna_sequence_models.py
index 94087cb8c6..bd5f2b758c 100755
--- a/qa/common/gen_qa_dyna_sequence_models.py
+++ b/qa/common/gen_qa_dyna_sequence_models.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 
-# Copyright 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# Copyright 2019-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -36,6 +36,7 @@
     np_to_tf_dtype,
     np_to_torch_dtype,
     np_to_trt_dtype,
+    openvino_save_model,
 )
 
 FLAGS = None
@@ -1304,15 +1305,7 @@ def create_openvino_modelfile(models_dir, model_version, max_batch, dtype, shape
     op0 = ov.opset1.multiply(tmp, ready, name="OUTPUT")
 
     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
-
-    ov.serialize(
-        model, model_version_dir + "/model.xml", model_version_dir + "/model.bin"
-    )
+    openvino_save_model(model_version_dir, model)
 
 
 def create_openvino_modelconfig(models_dir, model_version, max_batch, dtype, shape):
diff --git a/qa/common/gen_qa_identity_models.py b/qa/common/gen_qa_identity_models.py
index abc57ab48a..e74a4f62b7 100755
--- a/qa/common/gen_qa_identity_models.py
+++ b/qa/common/gen_qa_identity_models.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 
-# Copyright 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# Copyright 2019-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -37,6 +37,7 @@
     np_to_onnx_dtype,
     np_to_tf_dtype,
     np_to_trt_dtype,
+    openvino_save_model,
 )
 
 FLAGS = None
@@ -581,12 +582,7 @@ def create_openvino_modelfile(
         )
 
     model = ov.Model(openvino_outputs, openvino_inputs, model_name)
-
-    os.makedirs(model_version_dir, exist_ok=True)
-
-    ov.serialize(
-        model, model_version_dir + "/model.xml", model_version_dir + "/model.bin"
-    )
+    openvino_save_model(model_version_dir, model)
 
 
 def create_openvino_modelconfig(
diff --git a/qa/common/gen_qa_model_repository b/qa/common/gen_qa_model_repository
index 555c8d7817..c4bd68753c 100755
--- a/qa/common/gen_qa_model_repository
+++ b/qa/common/gen_qa_model_repository
@@ -1,5 +1,5 @@
 #!/bin/bash
-# Copyright 2018-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# Copyright 2018-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -55,7 +55,7 @@ ONNX_VERSION=1.16.1
 ONNX_OPSET=0
 
 # OPENVINO version
-OPENVINO_VERSION=2024.4.0
+OPENVINO_VERSION=2024.5.0
 
 UBUNTU_IMAGE=${UBUNTU_IMAGE:=ubuntu:22.04}
 PYTORCH_IMAGE=${PYTORCH_IMAGE:=nvcr.io/nvidia/pytorch:$TRITON_VERSION-py3}
diff --git a/qa/common/gen_qa_models.py b/qa/common/gen_qa_models.py
index 1af7762869..bb9d5f530b 100755
--- a/qa/common/gen_qa_models.py
+++ b/qa/common/gen_qa_models.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 
-# Copyright 2018-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# Copyright 2018-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -39,6 +39,7 @@
     np_to_tf_dtype,
     np_to_torch_dtype,
     np_to_trt_dtype,
+    openvino_save_model,
 )
 
 FLAGS = None
@@ -1826,15 +1827,7 @@ def create_openvino_modelfile(
     op1 = ov.opset1.convert(result1, destination_type=output1_dtype, name="OUTPUT1")
 
     model = ov.Model([op0, op1], [in0, in1], model_name)
-
-    try:
-        os.makedirs(model_version_dir)
-    except OSError as ex:
-        pass  # ignore existing dir
-
-    ov.serialize(
-        model, model_version_dir + "/model.xml", model_version_dir + "/model.bin"
-    )
+    openvino_save_model(model_version_dir, model)
 
 
 def create_openvino_modelconfig(
diff --git a/qa/common/gen_qa_reshape_models.py b/qa/common/gen_qa_reshape_models.py
index a27355574f..17806cf87a 100755
--- a/qa/common/gen_qa_reshape_models.py
+++ b/qa/common/gen_qa_reshape_models.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 
-# Copyright 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# Copyright 2019-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -38,6 +38,7 @@
     np_to_tf_dtype,
     np_to_torch_dtype,
     np_to_trt_dtype,
+    openvino_save_model,
 )
 
 FLAGS = None
@@ -949,15 +950,7 @@ def create_openvino_modelfile(
         )
 
     model = ov.Model(openvino_outputs, openvino_inputs, model_name)
-
-    try:
-        os.makedirs(model_version_dir)
-    except OSError as ex:
-        pass  # ignore existing dir
-
-    ov.serialize(
-        model, model_version_dir + "/model.xml", model_version_dir + "/model.bin"
-    )
+    openvino_save_model(model_version_dir, model)
 
 
 def create_openvino_modelconfig(
diff --git a/qa/common/gen_qa_sequence_models.py b/qa/common/gen_qa_sequence_models.py
index 25c35b7603..ca0e2536c2 100755
--- a/qa/common/gen_qa_sequence_models.py
+++ b/qa/common/gen_qa_sequence_models.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 
-# Copyright 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# Copyright 2019-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -37,6 +37,7 @@
     np_to_tf_dtype,
     np_to_torch_dtype,
     np_to_trt_dtype,
+    openvino_save_model,
 )
 
 FLAGS = None
@@ -1153,15 +1154,7 @@ def create_openvino_modelfile(models_dir, model_version, max_batch, dtype, shape
     op0 = ov.opset1.multiply(tmp, ready, name="OUTPUT")
 
     model = ov.Model([op0], [in0, start, ready], model_name)
-
-    try:
-        os.makedirs(model_version_dir)
-    except OSError as ex:
-        pass  # ignore existing dir
-
-    ov.serialize(
-        model, model_version_dir + "/model.xml", model_version_dir + "/model.bin"
-    )
+    openvino_save_model(model_version_dir, model)
 
 
 def create_openvino_modelconfig(models_dir, model_version, max_batch, dtype, shape):