Skip to content

Commit

Permalink
Support for opset 15 and update version to 1.10.0 (#505)
Browse files Browse the repository at this point in the history
* Support for opset 15
* add target_opset to all unit tests
  • Loading branch information
xadupre authored Oct 7, 2021
1 parent f089575 commit a1588df
Show file tree
Hide file tree
Showing 71 changed files with 545 additions and 203 deletions.
19 changes: 10 additions & 9 deletions .azure-pipelines/linux-conda-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
vmImage: 'ubuntu-latest'
strategy:
matrix:
Python39-1101-RT181-xgb11:
Python39-1101-RT190:
python.version: '3.9'
ONNX_PATH: onnx==1.10.1 # '-i https://test.pypi.org/simple/ onnx==1.9.101'
ONNXRT_PATH: onnxruntime==1.8.1
ONNXRT_PATH: onnxruntime==1.9.0
COREML_PATH: git+https://github.com/apple/coremltools@3.1
xgboost.version: '>=1.2'
Python39-190-RT180-xgb11:
Expand Down Expand Up @@ -105,8 +105,9 @@ jobs:
- script: |
export PYTHONPATH=.
python -c "import onnxconverter_common;print(onnxconverter_common.__version__)"
python -c "import onnxruntime;print(onnxruntime.__version__)"
python -c "import onnxruntime;print('onnx:',onnx.__version__)"
python -c "import onnxconverter_common;print('cc:',onnxconverter_common.__version__)"
python -c "import onnxruntime;print('ort:',onnxruntime.__version__)"
displayName: 'version'
- script: |
Expand All @@ -119,11 +120,6 @@ jobs:
pytest tests/catboost --durations=0
displayName: 'pytest - catboost'
- script: |
export PYTHONPATH=.
pytest tests/coreml --durations=0
displayName: 'pytest - coreml'
- script: |
export PYTHONPATH=.
pytest tests/lightgbm --durations=0
Expand Down Expand Up @@ -165,6 +161,11 @@ jobs:
pytest tests/hummingbirdml --durations=0
displayName: 'pytest - hummingbirdml'
- script: |
export PYTHONPATH=.
pytest tests/coreml --durations=0
displayName: 'pytest - coreml'
- task: PublishTestResults@2
inputs:
testResultsFiles: '**/test-results.xml'
Expand Down
4 changes: 2 additions & 2 deletions .azure-pipelines/win32-conda-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
vmImage: 'windows-latest'
strategy:
matrix:
Python39-1101-RT181:
Python39-1101-RT190:
python.version: '3.9'
ONNX_PATH: 'onnx==1.10.1' # '-i https://test.pypi.org/simple/ onnx==1.9.101'
ONNXRT_PATH: onnxruntime==1.8.1
ONNXRT_PATH: onnxruntime==1.9.0
COREML_PATH: git+https://github.com/apple/coremltools@3.1

Python39-190-RT181:
Expand Down
2 changes: 1 addition & 1 deletion onnxmltools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This framework converts any machine learned model into onnx format
which is a common language to describe any machine learned model.
"""
__version__ = "1.9.1"
__version__ = "1.10.0"
__author__ = "Microsoft"
__producer__ = "OnnxMLTools"
__producer_version__ = __version__
Expand Down
10 changes: 10 additions & 0 deletions onnxmltools/convert/common/onnx_ex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-License-Identifier: Apache-2.0

from onnx.defs import onnx_opset_version
from onnxconverter_common.onnx_ex import (
get_maximum_opset_supported as _get_maximum_opset_supported)


def get_maximum_opset_supported():
return min(onnx_opset_version(),
max(15, _get_maximum_opset_supported()))
2 changes: 1 addition & 1 deletion onnxmltools/convert/coreml/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import coremltools
from uuid import uuid4
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
import onnx
from ...proto import onnx_proto
from ..common._topology import convert_topology
from ..common.onnx_ex import get_maximum_opset_supported
from ._parse import parse_coreml

# Import modules to invoke function registrations
Expand Down
2 changes: 1 addition & 1 deletion onnxmltools/convert/h2o/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import tempfile
import h2o

from onnxconverter_common.onnx_ex import get_maximum_opset_supported
import onnx
from ..common.onnx_ex import get_maximum_opset_supported
from ..common._topology import convert_topology
from ..common.data_types import FloatTensorType
from ._parse import parse_h2o
Expand Down
2 changes: 1 addition & 1 deletion onnxmltools/convert/libsvm/convert.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: Apache-2.0

from uuid import uuid4
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
import onnx
from ..common.onnx_ex import get_maximum_opset_supported
from ..common._topology import convert_topology
from ._parse import parse_libsvm

Expand Down
2 changes: 1 addition & 1 deletion onnxmltools/convert/lightgbm/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from uuid import uuid4
import onnx
import lightgbm
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
from ..common.onnx_ex import get_maximum_opset_supported
from ..common._topology import convert_topology
from ..common.utils import hummingbird_installed
from ._parse import parse_lightgbm, WrappedBooster
Expand Down
2 changes: 1 addition & 1 deletion onnxmltools/convert/sparkml/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from uuid import uuid4
import onnx
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
from ..common.onnx_ex import get_maximum_opset_supported
from ..common._topology import convert_topology
from ._parse import parse_sparkml
from . import operator_converters
Expand Down
2 changes: 1 addition & 1 deletion onnxmltools/convert/xgboost/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from uuid import uuid4
import xgboost
from onnxconverter_common.onnx_ex import get_maximum_opset_supported
import onnx
from ..common.onnx_ex import get_maximum_opset_supported
from ..common._topology import convert_topology
from ._parse import parse_xgboost, WrappedBooster

Expand Down
22 changes: 16 additions & 6 deletions onnxmltools/utils/tests_helper.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# SPDX-License-Identifier: Apache-2.0

import numpy
import pickle
import os
import warnings
import numpy
from onnx.defs import onnx_opset_version
from onnxconverter_common.onnx_ex import DEFAULT_OPSET_NUMBER
from ..convert.common.data_types import FloatTensorType
from .utils_backend import compare_backend, extract_options, evaluate_condition, is_backend_enabled


TARGET_OPSET = min(DEFAULT_OPSET_NUMBER, onnx_opset_version())


def dump_data_and_model(data, model, onnx=None, basename="model", folder=None,
inputs=None, backend="onnxruntime", context=None,
allow_failure=None, verbose=False):
Expand Down Expand Up @@ -248,7 +253,8 @@ def dump_one_class_classification(model, suffix="", folder=None, allow_failure=N
X = numpy.array(X, dtype=numpy.float32)
y = [1, 1, 1]
model.fit(X, y)
model_onnx, prefix = convert_model(model, 'one_class', [('input', FloatTensorType([None, 2]))])
model_onnx, prefix = convert_model(model, 'one_class', [('input', FloatTensorType([None, 2]))],
target_opset=TARGET_OPSET)
return dump_data_and_model(X, model, model_onnx, folder=folder, allow_failure=allow_failure,
basename=prefix + "One" + model.__class__.__name__ + suffix)

Expand All @@ -274,7 +280,8 @@ def dump_binary_classification(model, suffix="", folder=None, allow_failure=None
X = numpy.array(X, dtype=numpy.float32)
y = [0, 1, 0]
model.fit(X, y)
model_onnx, prefix = convert_model(model, 'tree-based binary classifier', [('input', FloatTensorType([None, 2]))])
model_onnx, prefix = convert_model(model, 'tree-based binary classifier', [('input', FloatTensorType([None, 2]))],
target_opset=TARGET_OPSET)
dump_data_and_model(X, model, model_onnx, folder=folder, allow_failure=allow_failure,
basename=prefix + "Bin" + model.__class__.__name__ + suffix,
verbose=verbose)
Expand All @@ -299,7 +306,8 @@ def dump_multiple_classification(model, suffix="", folder=None, allow_failure=No
X = numpy.array(X, dtype=numpy.float32)
y = [0, 1, 2, 1, 1, 2]
model.fit(X, y)
model_onnx, prefix = convert_model(model, 'tree-based multi-output regressor', [('input', FloatTensorType([None, 2]))])
model_onnx, prefix = convert_model(model, 'tree-based multi-output regressor', [('input', FloatTensorType([None, 2]))],
target_opset=TARGET_OPSET)
dump_data_and_model(X, model, model_onnx, folder=folder, allow_failure=allow_failure,
basename=prefix + "Mcl" + model.__class__.__name__ + suffix)

Expand All @@ -324,7 +332,8 @@ def dump_multiple_regression(model, suffix="", folder=None, allow_failure=None):
X = numpy.array(X, dtype=numpy.float32)
y = numpy.array([[100, 50], [100, 49], [100, 99]], dtype=numpy.float32)
model.fit(X, y)
model_onnx, prefix = convert_model(model, 'tree-based multi-output regressor', [('input', FloatTensorType([None, 2]))])
model_onnx, prefix = convert_model(model, 'tree-based multi-output regressor', [('input', FloatTensorType([None, 2]))],
target_opset=TARGET_OPSET)
dump_data_and_model(X, model, model_onnx, folder=folder, allow_failure=allow_failure,
basename=prefix + "MRg" + model.__class__.__name__ + suffix)

Expand All @@ -350,7 +359,8 @@ def dump_single_regression(model, suffix="", folder=None, allow_failure=None):
X = numpy.array(X, dtype=numpy.float32)
y = numpy.array([100, -10, 50], dtype=numpy.float32)
model.fit(X, y)
model_onnx, prefix = convert_model(model, 'tree-based regressor', [('input', FloatTensorType([None, 2]))])
model_onnx, prefix = convert_model(model, 'tree-based regressor', [('input', FloatTensorType([None, 2]))],
target_opset=TARGET_OPSET)
dump_data_and_model(X, model, model_onnx, folder=folder, allow_failure=allow_failure,
basename=prefix + "Reg" + model.__class__.__name__ + suffix)

Expand Down
7 changes: 6 additions & 1 deletion tests/baseline/test_convert_baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
import os
import re
import unittest
from onnx.defs import onnx_opset_version
from onnxmltools.convert import convert_coreml
from onnxconverter_common.onnx_ex import DEFAULT_OPSET_NUMBER
import coremltools


TARGET_OPSET = min(DEFAULT_OPSET_NUMBER, onnx_opset_version())


class TestBaseLine(unittest.TestCase):

def check_baseline(self, input_file, ref_file):
Expand All @@ -20,7 +25,7 @@ def get_diff(self, input_file, ref_file):
this = os.path.dirname(__file__)
coreml_file = os.path.join(this, "models", input_file)
cml = coremltools.utils.load_spec(coreml_file)
onnx_model = convert_coreml(cml)
onnx_model = convert_coreml(cml, target_opset=TARGET_OPSET)
output_dir = os.path.join(this, "outmodels")
output_file = os.path.join(this, "outmodels", ref_file)
if not os.path.exists(output_dir):
Expand Down
Loading

0 comments on commit a1588df

Please sign in to comment.