Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make opset 15 default #749

Merged
merged 11 commits into from
Oct 1, 2021
12 changes: 0 additions & 12 deletions .azure-pipelines/linux-CI-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .azure-pipelines/linux-conda-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion docs/tutorial/plot_bbegin_measure_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
3 changes: 2 additions & 1 deletion docs/tutorial/plot_mcustom_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
3 changes: 2 additions & 1 deletion docs/tutorial/plot_wext_pyod_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions skl2onnx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions skl2onnx/common/_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion tests/test_algebra_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_algebra_onnx_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_opset13.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_sklearn_double_tensor_type_tr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions tests/test_sklearn_polynomial_features_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]])
Expand All @@ -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],
Expand All @@ -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)
Expand All @@ -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],
Expand All @@ -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]])
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion tests/test_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -55,7 +57,9 @@ def max_onnxruntime_opset():
<https://github.com/microsoft/onnxruntime/blob/
master/docs/Versioning.md>`_.
"""
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"):
Expand Down