Compare commits

...

3 Commits

Author SHA1 Message Date
Nicolas Mowen
1cb4dd01f4 Cleanup 2025-09-15 07:23:51 -06:00
Nicolas Mowen
13b7c0fce0 Catch case where input tensor can't be pre-defined 2025-09-15 06:49:41 -06:00
Nicolas Mowen
562ad3d373 Don't try to use OpenVINO when CPU is set as device 2025-09-15 06:47:51 -06:00

View File

@ -33,7 +33,7 @@ def get_openvino_available_devices() -> list[str]:
try:
core = ov.Core()
available_devices = core.available_devices
logger.info(f"OpenVINO available devices: {available_devices}")
logger.debug(f"OpenVINO available devices: {available_devices}")
return available_devices
except Exception as e:
logger.warning(f"Failed to get OpenVINO available devices: {e}")
@ -180,9 +180,14 @@ class OpenVINOModelRunner(BaseModelRunner):
# Create reusable inference request
self.infer_request = self.compiled_model.create_infer_request()
input_shape = self.compiled_model.inputs[0].get_shape()
input_element_type = self.compiled_model.inputs[0].get_element_type()
self.input_tensor = ov.Tensor(input_element_type, input_shape)
try:
input_shape = self.compiled_model.inputs[0].get_shape()
input_element_type = self.compiled_model.inputs[0].get_element_type()
self.input_tensor = ov.Tensor(input_element_type, input_shape)
except RuntimeError:
# model is complex and has dynamic shape
self.input_tensor = None
def get_input_names(self) -> list[str]:
"""Get input names for the model."""
@ -204,7 +209,11 @@ class OpenVINOModelRunner(BaseModelRunner):
List of output tensors
"""
# Handle single input case for backward compatibility
if len(inputs) == 1 and len(self.compiled_model.inputs) == 1:
if (
len(inputs) == 1
and len(self.compiled_model.inputs) == 1
and self.input_tensor is not None
):
# Single input case - use the pre-allocated tensor for efficiency
input_data = list(inputs.values())[0]
np.copyto(self.input_tensor.data, input_data)
@ -354,7 +363,7 @@ def get_optimized_runner(
if rknn_path:
return RKNNModelRunner(rknn_path)
if is_openvino_gpu_npu_available():
if device != "CPU" and is_openvino_gpu_npu_available():
return OpenVINOModelRunner(model_path, device, **kwargs)
providers, options = get_ort_providers(device == "CPU", device, **kwargs)