From 52f6db19da584d7e41c869ab8c7c8197db1e08ae Mon Sep 17 00:00:00 2001 From: Gary Miguel Date: Tue, 14 Jun 2022 10:17:35 -0700 Subject: [PATCH] Python backend: use packaging.version to parse ONNX version (#11800) Unlike the previous code, this handles version strings like "1.12.0rc3". Unblocks https://github.com/microsoft/onnxruntime/issues/11640. --- onnxruntime/python/backend/backend.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/onnxruntime/python/backend/backend.py b/onnxruntime/python/backend/backend.py index cbe01a630f..cfb5231173 100644 --- a/onnxruntime/python/backend/backend.py +++ b/onnxruntime/python/backend/backend.py @@ -8,6 +8,7 @@ Implements ONNX's backend API. import os import unittest +import packaging.version from onnx import ModelProto, helper, version from onnx.backend.base import Backend from onnx.checker import check_model @@ -127,8 +128,8 @@ class OnnxRuntimeBackend(Backend): # check_model serializes the model anyways, so serialize the model once here # and reuse it below in the cls.prepare call to avoid an additional serialization # only works with onnx >= 1.10.0 hence the version check - onnx_version = tuple(map(int, (version.version.split(".")[:3]))) - onnx_supports_serialized_model_check = onnx_version >= (1, 10, 0) + onnx_version = packaging.version.parse(version.version) or packaging.version.Version("0") + onnx_supports_serialized_model_check = onnx_version.release >= (1, 10, 0) bin_or_model = model.SerializeToString() if onnx_supports_serialized_model_check else model check_model(bin_or_model) opset_supported, error_message = cls.is_opset_supported(model)