From d8803b80af210632563cf512a297aeb84e60e84e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Dupr=C3=A9?= Date: Fri, 1 Oct 2021 18:05:46 +0200 Subject: [PATCH] Make opset 15 default (#749) * Make opset 15 default * fix missing target opset in polynomial features --- .azure-pipelines/linux-CI-nightly.yml | 12 ------------ .azure-pipelines/linux-conda-CI.yml | 2 +- docs/tutorial/plot_bbegin_measure_time.py | 3 ++- docs/tutorial/plot_mcustom_parser.py | 3 ++- docs/tutorial/plot_wext_pyod_forest.py | 3 ++- skl2onnx/__init__.py | 4 ++-- skl2onnx/common/_topology.py | 4 ++-- tests/test_algebra_complex.py | 2 +- tests/test_algebra_onnx_operators.py | 6 +++--- tests/test_opset13.py | 4 ++-- tests/test_sklearn_double_tensor_type_tr.py | 3 ++- tests/test_sklearn_polynomial_features_converter.py | 12 ++++++++++++ tests/test_utils/__init__.py | 6 +++++- 13 files changed, 36 insertions(+), 28 deletions(-) diff --git a/.azure-pipelines/linux-CI-nightly.yml b/.azure-pipelines/linux-CI-nightly.yml index bc3418d0e..40497aa5f 100644 --- a/.azure-pipelines/linux-CI-nightly.yml +++ b/.azure-pipelines/linux-CI-nightly.yml @@ -37,18 +37,6 @@ jobs: onnx.version: '==1.6.0' onnxrt.version: '-i https://test.pypi.org/simple/ ort-nightly' sklearn.version: '==0.22.1' - Py37-Onnx160-Sk0213: - python.version: '3.7' - numpy.version: '==1.18.1' - onnx.version: '==1.6.0' - onnxrt.version: '-i https://test.pypi.org/simple/ ort-nightly' - sklearn.version: '==0.21.3' - Py37-Onnx150: - python.version: '3.7' - numpy.version: '==1.18.1' - onnx.version: '==1.6.0' - onnxrt.version: '-i https://test.pypi.org/simple/ ort-nightly' - sklearn.version: '==0.21.3' maxParallel: 3 steps: diff --git a/.azure-pipelines/linux-conda-CI.yml b/.azure-pipelines/linux-conda-CI.yml index 9a904b7a9..e313ce2c2 100644 --- a/.azure-pipelines/linux-conda-CI.yml +++ b/.azure-pipelines/linux-conda-CI.yml @@ -42,7 +42,7 @@ jobs: onnxrt.version: 'onnxruntime==1.8.1' # '-i https://test.pypi.org/simple/ ort-nightly' sklearn.version: '>=0.24.2' onnxcc.version: '>=1.8.1' # git - run.example: '1' + run.example: '0' Py39-Onnx190-Rt180-Skl0242: do.bench: '0' python.version: '3.9' diff --git a/docs/tutorial/plot_bbegin_measure_time.py b/docs/tutorial/plot_bbegin_measure_time.py index 05e6a0644..c9222bd85 100644 --- a/docs/tutorial/plot_bbegin_measure_time.py +++ b/docs/tutorial/plot_bbegin_measure_time.py @@ -87,7 +87,8 @@ # The same is done with the two ONNX runtime # available. -onx = to_onnx(ereg, X_train[:1].astype(numpy.float32)) +onx = to_onnx(ereg, X_train[:1].astype(numpy.float32), + target_opset=14) sess = InferenceSession(onx.SerializeToString()) oinf = OnnxInference(onx, runtime="python_compiled") diff --git a/docs/tutorial/plot_mcustom_parser.py b/docs/tutorial/plot_mcustom_parser.py index bde1f1290..5d2da8de8 100644 --- a/docs/tutorial/plot_mcustom_parser.py +++ b/docs/tutorial/plot_mcustom_parser.py @@ -157,7 +157,8 @@ def decorrelate_transformer_parser( ############################################# # And conversion. -onx = to_onnx(dec, X.astype(numpy.float32)) +onx = to_onnx(dec, X.astype(numpy.float32), + target_opset=14) sess = InferenceSession(onx.SerializeToString()) diff --git a/docs/tutorial/plot_wext_pyod_forest.py b/docs/tutorial/plot_wext_pyod_forest.py index fe7d25160..af7255ae8 100644 --- a/docs/tutorial/plot_wext_pyod_forest.py +++ b/docs/tutorial/plot_wext_pyod_forest.py @@ -171,7 +171,8 @@ def pyod_iforest_converter(scope, operator, container): # And the conversion. if IForest is not None: - onx = to_onnx(model1, initial_types=initial_type) + onx = to_onnx(model1, initial_types=initial_type, + target_opset=14) ############################################### # Checking discrepencies diff --git a/skl2onnx/__init__.py b/skl2onnx/__init__.py index d6a001551..7c1437cf8 100644 --- a/skl2onnx/__init__.py +++ b/skl2onnx/__init__.py @@ -3,13 +3,13 @@ """ Main entry point to the converter from the *scikit-learn* to *onnx*. """ -__version__ = "1.9.4.dev" +__version__ = "1.10.0" __author__ = "Microsoft" __producer__ = "skl2onnx" __producer_version__ = __version__ __domain__ = "ai.onnx" __model_version__ = 0 -__max_supported_opset__ = 14 # Converters are tested up to this version. +__max_supported_opset__ = 15 # Converters are tested up to this version. from .convert import convert_sklearn, to_onnx, wrap_as_onnx_mixin # noqa diff --git a/skl2onnx/common/_topology.py b/skl2onnx/common/_topology.py index 60d008728..93fa1f083 100644 --- a/skl2onnx/common/_topology.py +++ b/skl2onnx/common/_topology.py @@ -48,11 +48,11 @@ def _default_OPSET_TO_IR_VERSION(): try: from onnxconverter_common.topology import OPSET_TO_IR_VERSION - assert OPSET_TO_IR_VERSION[14] is not None + assert OPSET_TO_IR_VERSION[15] is not None except (ImportError, KeyError): OPSET_TO_IR_VERSION = _default_OPSET_TO_IR_VERSION() -OPSET_ML_TO_OPSET = {1: 11, 2: 14} +OPSET_ML_TO_OPSET = {1: 11, 2: 15} logger = getLogger('skl2onnx') diff --git a/tests/test_algebra_complex.py b/tests/test_algebra_complex.py index a79732fd6..90594d735 100644 --- a/tests/test_algebra_complex.py +++ b/tests/test_algebra_complex.py @@ -29,7 +29,7 @@ def test_complex(self): X = np.array([[1-2j, -12j], [-1-2j, 1+2j]]).astype(dt) - for opv in (10, 11, 12, 13, TARGET_OPSET): + for opv in range(10, 20): if opv > TARGET_OPSET: continue with self.subTest(dt=dt, opset=opv): diff --git a/tests/test_algebra_onnx_operators.py b/tests/test_algebra_onnx_operators.py index 1aad6694a..c6838bdfc 100644 --- a/tests/test_algebra_onnx_operators.py +++ b/tests/test_algebra_onnx_operators.py @@ -205,11 +205,11 @@ def test_constant(self): self.assertEqual(cst.value, "a") def test_constant_of_shape(self): - for opset in [TARGET_OPSET, 14, 13, 12, 11, 10, 9]: + for opset in range(20, 8, -1): + if opset > TARGET_OPSET: + continue for value in [np.array([5], dtype=np.float32), np.array(5, dtype=np.float32)]: - if opset > TARGET_OPSET: - continue with self.subTest(opset=opset, value=value): tensor_value = onnx.helper.make_tensor( "value", onnx.TensorProto.FLOAT, diff --git a/tests/test_opset13.py b/tests/test_opset13.py index ae28902e9..fc6eeef9f 100644 --- a/tests/test_opset13.py +++ b/tests/test_opset13.py @@ -18,7 +18,7 @@ class TestOpset13(unittest.TestCase): def test_reduce_sum(self): X = numpy.array([[2, 1], [0, 1]], dtype=numpy.float32) - for opset in (10, 11, 12, 13): + for opset in range(10, 20): if opset > TARGET_OPSET: continue with self.subTest(opset=opset): @@ -62,7 +62,7 @@ def test_split(self): def test_squeeze(self): x = numpy.random.randn(20, 1).astype(numpy.float32) y = numpy.squeeze(x) - for opset in (10, 11, 12, 13): + for opset in range(10, 20): if opset > TARGET_OPSET: continue with self.subTest(opset=opset): diff --git a/tests/test_sklearn_double_tensor_type_tr.py b/tests/test_sklearn_double_tensor_type_tr.py index f4448c32f..b8b71fc8d 100644 --- a/tests/test_sklearn_double_tensor_type_tr.py +++ b/tests/test_sklearn_double_tensor_type_tr.py @@ -395,7 +395,8 @@ def test_binarizer(self): model = Binarizer(threshold=0.5) model_onnx = convert_sklearn( model, "scikit-learn binarizer", - [("input", DoubleTensorType(data.shape))]) + [("input", DoubleTensorType(data.shape))], + target_opset=TARGET_OPSET) self.assertTrue(model_onnx is not None) dump_data_and_model( data, model, model_onnx, diff --git a/tests/test_sklearn_polynomial_features_converter.py b/tests/test_sklearn_polynomial_features_converter.py index c0b4a725c..c14e2ea48 100644 --- a/tests/test_sklearn_polynomial_features_converter.py +++ b/tests/test_sklearn_polynomial_features_converter.py @@ -7,6 +7,12 @@ from distutils.version import StrictVersion import numpy as np import onnx +try: + # scikit-learn >= 0.22 + from sklearn.utils._testing import ignore_warnings +except ImportError: + # scikit-learn < 0.22 + from sklearn.utils.testing import ignore_warnings from sklearn.preprocessing import PolynomialFeatures from skl2onnx import convert_sklearn from skl2onnx.common.data_types import FloatTensorType, Int64TensorType @@ -17,6 +23,7 @@ class TestSklearnPolynomialFeatures(unittest.TestCase): @unittest.skipIf(StrictVersion(onnx.__version__) < StrictVersion("1.4.0"), reason="ConstantOfShape not available") + @ignore_warnings(category=FutureWarning) def test_model_polynomial_features_float_degree_2(self): X = np.array([[1.2, 3.2, 1.3, -5.6], [4.3, -3.2, 5.7, 1.0], [0, 3.2, 4.7, -8.9]]) @@ -32,6 +39,7 @@ def test_model_polynomial_features_float_degree_2(self): @unittest.skipIf(StrictVersion(onnx.__version__) < StrictVersion("1.4.0"), reason="ConstantOfShape not available") + @ignore_warnings(category=FutureWarning) def test_model_polynomial_features_int_degree_2(self): X = np.array([ [1, 3, 4, 0], @@ -52,6 +60,7 @@ def test_model_polynomial_features_int_degree_2(self): @unittest.skipIf(StrictVersion(onnx.__version__) < StrictVersion("1.4.0"), reason="ConstantOfShape not available") + @ignore_warnings(category=FutureWarning) def test_model_polynomial_features_float_degree_3(self): X = np.array([[1.2, 3.2, 1.2], [4.3, 3.2, 4.5], [3.2, 4.7, 1.1]]) model = PolynomialFeatures(degree=3).fit(X) @@ -66,6 +75,7 @@ def test_model_polynomial_features_float_degree_3(self): @unittest.skipIf(StrictVersion(onnx.__version__) < StrictVersion("1.4.0"), reason="ConstantOfShape not available") + @ignore_warnings(category=FutureWarning) def test_model_polynomial_features_int_degree_3(self): X = np.array([ [1, 3, 33], @@ -87,6 +97,7 @@ def test_model_polynomial_features_int_degree_3(self): @unittest.skipIf(StrictVersion(onnx.__version__) < StrictVersion("1.4.0"), reason="ConstantOfShape not available") + @ignore_warnings(category=FutureWarning) def test_model_polynomial_features_float_degree_4(self): X = np.array([[1.2, 3.2, 3.1, 1.3], [4.3, 3.2, 0.5, 1.3], [3.2, 4.7, 5.4, 7.1]]) @@ -102,6 +113,7 @@ def test_model_polynomial_features_float_degree_4(self): @unittest.skipIf(StrictVersion(onnx.__version__) < StrictVersion("1.4.0"), reason="ConstantOfShape not available") + @ignore_warnings(category=FutureWarning) def test_model_polynomial_features_int_degree_4(self): X = np.array([[1, 3, 4, 1], [3, 7, 3, 5], [1, 0, 5, 4]]) model = PolynomialFeatures(degree=4).fit(X) diff --git a/tests/test_utils/__init__.py b/tests/test_utils/__init__.py index 05e79e3ef..1a2f8dcb8 100644 --- a/tests/test_utils/__init__.py +++ b/tests/test_utils/__init__.py @@ -36,6 +36,8 @@ def create_tensor(N, C, H=None, W=None): def _get_ir_version(opv): + if opv >= 15: + return 8 if opv >= 12: return 7 if opv >= 11: @@ -55,7 +57,9 @@ def max_onnxruntime_opset(): `_. """ - vi = StrictVersion(ort_version.split("+")[0]) + vi = StrictVersion(ort_version.split('+')[0]) + if vi >= StrictVersion("1.9.0"): + return 15 if vi >= StrictVersion("1.8.0"): return 14 if vi >= StrictVersion("1.6.0"):