Skip to content

Commit

Permalink
Python backend: use packaging.version to parse ONNX version (#11800)
Browse files Browse the repository at this point in the history
Unlike the previous code, this handles version strings like "1.12.0rc3".

Unblocks #11640.
  • Loading branch information
garymm authored Jun 14, 2022
1 parent f6d2b62 commit 52f6db1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions onnxruntime/python/backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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
Expand Down Expand Up @@ -127,8 +128,8 @@ def prepare(cls, model, device=None, **kwargs):
# 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)
Expand Down

0 comments on commit 52f6db1

Please sign in to comment.