diff --git a/_doc/examples/plot_op_einsum.py b/_doc/examples/plot_op_einsum.py index b396770c9..cf094be78 100644 --- a/_doc/examples/plot_op_einsum.py +++ b/_doc/examples/plot_op_einsum.py @@ -52,7 +52,7 @@ torch_einsum = None -def build_ort_einsum(equation, op_version=13): +def build_ort_einsum(equation, op_version=14): # opset=13, 14, ... node = OnnxEinsum('x', 'y', equation=equation, op_version=op_version, output_names=['z']) @@ -63,7 +63,7 @@ def build_ort_einsum(equation, op_version=13): return lambda x, y: sess.run(None, {'x': x, 'y': y}) -def build_ort_decomposed(equation, op_version=13): +def build_ort_decomposed(equation, op_version=14): # opset=13, 14, ... cache = _einsum(equation, numpy.float32, opset=op_version, optimize=True, verbose=True, runtime="python") if not hasattr(cache, 'onnx_'): diff --git a/_doc/examples/plot_op_reducemax.py b/_doc/examples/plot_op_reducemax.py index f880c4870..eea414a2c 100644 --- a/_doc/examples/plot_op_reducemax.py +++ b/_doc/examples/plot_op_reducemax.py @@ -43,7 +43,7 @@ torch_max = None -def build_ort_reducemax(axes, op_version=13): +def build_ort_reducemax(axes, op_version=14): # opset=13, 14, ... node = OnnxReduceMax('x', axes=axes, op_version=op_version, output_names=['z']) onx = node.to_onnx(inputs=[('x', FloatTensorType())], diff --git a/_doc/examples/plot_op_reducemean.py b/_doc/examples/plot_op_reducemean.py index 4bbdec919..df5e56cc2 100644 --- a/_doc/examples/plot_op_reducemean.py +++ b/_doc/examples/plot_op_reducemean.py @@ -43,7 +43,7 @@ torch_mean = None -def build_ort_reducemean(axes, op_version=13): +def build_ort_reducemean(axes, op_version=14): # opset=13, 14, ... node = OnnxReduceMean('x', axes=axes, op_version=op_version, output_names=['z']) onx = node.to_onnx(inputs=[('x', FloatTensorType())], diff --git a/_doc/examples/plot_op_reducesum.py b/_doc/examples/plot_op_reducesum.py index 4e03ae4a9..33ef7709d 100644 --- a/_doc/examples/plot_op_reducesum.py +++ b/_doc/examples/plot_op_reducesum.py @@ -44,7 +44,7 @@ torch_sum = None -def build_ort_reducesum(axes, op_version=13): +def build_ort_reducesum(axes, op_version=14): # opset=13, 14, ... node = OnnxReduceSumApi11('x', axes=axes, op_version=op_version, output_names=['z']) onx = node.to_onnx(inputs=[('x', FloatTensorType())], diff --git a/_doc/examples/plot_op_reducesumsquare.py b/_doc/examples/plot_op_reducesumsquare.py index d27091fc8..132ce3968 100644 --- a/_doc/examples/plot_op_reducesumsquare.py +++ b/_doc/examples/plot_op_reducesumsquare.py @@ -43,7 +43,7 @@ torch_sum = None -def build_ort_reducesumsquare(axes, op_version=13): +def build_ort_reducesumsquare(axes, op_version=14): # opset=13, 14, ... node = OnnxReduceSumSquare('x', axes=axes, op_version=op_version, output_names=['z']) onx = node.to_onnx(inputs=[('x', FloatTensorType())], diff --git a/_doc/sphinxdoc/source/blog/2021/2021-05-05_numpyapionnx2.rst b/_doc/sphinxdoc/source/blog/2021/2021-05-05_numpyapionnx2.rst index be7ad1565..de349916a 100644 --- a/_doc/sphinxdoc/source/blog/2021/2021-05-05_numpyapionnx2.rst +++ b/_doc/sphinxdoc/source/blog/2021/2021-05-05_numpyapionnx2.rst @@ -46,7 +46,7 @@ X_train, X_test, y_train, y_test = train_test_split(X, y) - @onnxsklearn_class("onnx_transform", op_version=13) + @onnxsklearn_class("onnx_transform", op_version=14) # opset=13, 14, ... class DecorrelateTransformerOnnx(TransformerMixin, BaseEstimator): def __init__(self, alpha=0.): BaseEstimator.__init__(self) @@ -69,7 +69,7 @@ model.fit(X_train) print(model.transform(X_test[:5])) - onx = to_onnx(model, X_test[:5], target_opset=13) + onx = to_onnx(model, X_test[:5], target_opset=14) # opset=13, 14, ... print(onx) The tutorial :ref:`l-numpy-api-for-onnx` extends this example diff --git a/_doc/sphinxdoc/source/tutorial/numpy_api_onnx.rst b/_doc/sphinxdoc/source/tutorial/numpy_api_onnx.rst index e0b50b953..1b7beffb8 100644 --- a/_doc/sphinxdoc/source/tutorial/numpy_api_onnx.rst +++ b/_doc/sphinxdoc/source/tutorial/numpy_api_onnx.rst @@ -322,7 +322,7 @@ is used. Let's see how to do it. X_train, X_test, y_train, y_test = train_test_split(X, y) - @onnxsklearn_class('onnx_graph', op_version=13) + @onnxsklearn_class('onnx_graph', op_version=14) # opset=13, 14, ... class TwoLogisticRegressionOnnx(ClassifierMixin, BaseEstimator): def __init__(self): @@ -377,7 +377,7 @@ is used. Let's see how to do it. model.fit(X_train, y_train) print(model.predict(X_test[:5]), model.predict_proba(X_test[:5])) - onx = to_onnx(model, X_test[:5], target_opset=13) + onx = to_onnx(model, X_test[:5], target_opset=14) # opset=13, 14, ... # print(onx) # too long to be displayed The decorator ``@onnxsklearn_class('onnx_graph')`` @@ -396,7 +396,7 @@ When one of them is called, it follows the steps: * Create an instance with a runtime if it does not exist * Returns the output of the runtime -The instruction ``to_onnx(model, X_test[:5], target_opset=13)`` creates +The instruction ``to_onnx(model, X_test[:5], target_opset=?)`` creates an ONNX graph by calling method *onnx_graph* registered as a converter in *skl2onnx*. It is equivalent to something like ``model.onnx_graph(X_test[:5]).to_algebra()[0].to_onnx({'X': X})``. @@ -410,7 +410,7 @@ Custom Transformer ^^^^^^^^^^^^^^^^^^ The syntax is the same. The decorator -``@onnxsklearn_class("onnx_transform", op_version=13)`` detects +``@onnxsklearn_class("onnx_transform", op_version=?)`` detects the class is a transformer and automatically adds method *transform*. @@ -434,7 +434,7 @@ the class is a transformer and automatically adds method X_train, X_test, y_train, y_test = train_test_split(X, y) - @onnxsklearn_class("onnx_transform", op_version=13) + @onnxsklearn_class("onnx_transform", op_version=14) # opset=13, 14, ... class DecorrelateTransformerOnnx(TransformerMixin, BaseEstimator): def __init__(self, alpha=0.): BaseEstimator.__init__(self) @@ -457,7 +457,7 @@ the class is a transformer and automatically adds method model.fit(X_train) print(model.transform(X_test[:5])) - onx = to_onnx(model, X_test[:5], target_opset=13) + onx = to_onnx(model, X_test[:5], target_opset=14) # opset=13, 14, ... print(onx) More options diff --git a/_unittests/ut__skl2onnx/test_sklearn_label_encoder_converter.py b/_unittests/ut__skl2onnx/test_sklearn_label_encoder_converter.py index 3a17f58df..42f3f33bb 100644 --- a/_unittests/ut__skl2onnx/test_sklearn_label_encoder_converter.py +++ b/_unittests/ut__skl2onnx/test_sklearn_label_encoder_converter.py @@ -50,7 +50,7 @@ def test_model_label_encoder_int(self): model = LabelEncoder() data = numpy.array([10, 3, 5, -34, 0], dtype=numpy.int64) model.fit(data) - for op in sorted(set([9, 10, 11, 12, 13, TARGET_OPSET])): + for op in sorted(set([9, 10, 11, 12, 13, 14, TARGET_OPSET])): # opset=13, 14, ... if op > TARGET_OPSET: continue with self.subTest(opset=op): diff --git a/_unittests/ut_asv_benchmark/test_create_asv_benchmark_pyspy.py b/_unittests/ut_asv_benchmark/test_create_asv_benchmark_pyspy.py index 0f8f09985..f11d13f18 100644 --- a/_unittests/ut_asv_benchmark/test_create_asv_benchmark_pyspy.py +++ b/_unittests/ut_asv_benchmark/test_create_asv_benchmark_pyspy.py @@ -56,6 +56,7 @@ def test_create_asv_benchmark_pyspy_knn(self): self.assertNotEmpty(created) verif = False + target_opset = get_opset_number_from_onnx() allnames = [] for path, _, files in os.walk(os.path.join(temp, 'pyspy')): for zoo in files: @@ -67,7 +68,7 @@ def test_create_asv_benchmark_pyspy_knn(self): content = f.read() if (zoo.endswith( "bench_KNNClas_default_k3_b_cl_64_algorithmbrute_n_neighbors3" - "_10000_20_13_double_optcdist-zm0.py") and + "_10000_20_%d_double_optcdist-zm0.py" % target_opset) and compare_module_version(sklearn.__version__, "0.21") >= 0): if "setup_profile" not in content: raise AssertionError(content) diff --git a/_unittests/ut_onnx_conv/test_onnx_conv_knn.py b/_unittests/ut_onnx_conv/test_onnx_conv_knn.py index 7008fd18a..02d449cde 100644 --- a/_unittests/ut_onnx_conv/test_onnx_conv_knn.py +++ b/_unittests/ut_onnx_conv/test_onnx_conv_knn.py @@ -244,7 +244,7 @@ def onnx_test_knn_single_classreg(self, dtype, n_targets=1, debug=False, if target_opset is None: opsets = list(sorted(set([ - 9, 10, 11, 12, 13, get_opset_number_from_onnx()]))) + 9, 10, 11, 12, 13, 14, get_opset_number_from_onnx()]))) # opset=13, 14, ... else: opsets = [target_opset] for ops in opsets: @@ -475,7 +475,7 @@ def test_onnx_test_knn_transform(self): clr = NearestNeighbors(n_neighbors=3) clr.fit(X_train) - for to in (10, 11, 12, 13): + for to in (10, 11, 12, 13, 14): # opset=13, 14, ... if to > get_opset_number_from_onnx(): break try: diff --git a/_unittests/ut_onnxrt/test_benchmark_replay.py b/_unittests/ut_onnxrt/test_benchmark_replay.py index fc4486f36..abf3b4cb8 100644 --- a/_unittests/ut_onnxrt/test_benchmark_replay.py +++ b/_unittests/ut_onnxrt/test_benchmark_replay.py @@ -17,8 +17,8 @@ def test_benchmark_replay(self): enumerate_benchmark_replay(temp, runtime='python')), FileNotFoundError) res = list(enumerate_validated_operator_opsets( - 0, fLOG=None, models={"LogisticRegression"}, opset_min=13, - opset_max=13, benchmark=False, store_models=True, dump_all=True, + 0, fLOG=None, models={"LogisticRegression"}, opset_min=14, # opset=13, 14, ... + opset_max=14, benchmark=False, store_models=True, dump_all=True, dump_folder=temp, filter_exp=lambda m, p: ( "64" not in p and "b-cl" in p and "dec" not in p))) self.assertNotEmpty(res) diff --git a/_unittests/ut_onnxrt/test_coverage_runtime_ops.py b/_unittests/ut_onnxrt/test_coverage_runtime_ops.py deleted file mode 100644 index 337fc2f98..000000000 --- a/_unittests/ut_onnxrt/test_coverage_runtime_ops.py +++ /dev/null @@ -1,31 +0,0 @@ -""" -@brief test log(time=2s) -""" -import unittest -import numpy -from onnx.numpy_helper import from_array -from pyquickhelper.pycode import ExtTestCase -from skl2onnx.algebra.onnx_ops import ( # pylint: disable=E0611 - OnnxConstant, OnnxAdd) -from mlprodict.onnxrt import OnnxInference - - -class TestCoverageRuntimeOps(ExtTestCase): - - def test_op_constant(self): - for opv in [9, 10, 11, 12, 13]: - for dtype in [numpy.float32, numpy.float64, - numpy.int32, numpy.int64]: - with self.subTest(opv=opv, dtype=dtype): - X = numpy.array([1], dtype=dtype) - pX = from_array(X) - op = OnnxAdd('X', OnnxConstant(op_version=opv, value=pX), - output_names=['Y'], op_version=opv) - onx = op.to_onnx({'X': X}) - oinf = OnnxInference(onx) - res = oinf.run({'X': X}) - self.assertEqualArray(res['Y'], X + X) - - -if __name__ == "__main__": - unittest.main() diff --git a/_unittests/ut_onnxrt/test_onnx_profiling.py b/_unittests/ut_onnxrt/test_onnx_profiling.py index 6ce08ee55..933aa0fb6 100644 --- a/_unittests/ut_onnxrt/test_onnx_profiling.py +++ b/_unittests/ut_onnxrt/test_onnx_profiling.py @@ -41,7 +41,7 @@ def test_profile_onnxruntime1(self): del model_def.opset_import[:] # pylint: disable=E1101 op_set = model_def.opset_import.add() # pylint: disable=E1101 op_set.domain = '' - op_set.version = 13 + op_set.version = 14 # opset=13, 14, ... X = (numpy.random.randn(4, 2) * 100000).astype( # pylint: disable=E1101 numpy.float32) diff --git a/_unittests/ut_onnxrt/test_onnxrt_python_runtime_.py b/_unittests/ut_onnxrt/test_onnxrt_python_runtime_.py index 93d6592f1..a99c73c48 100644 --- a/_unittests/ut_onnxrt/test_onnxrt_python_runtime_.py +++ b/_unittests/ut_onnxrt/test_onnxrt_python_runtime_.py @@ -15,6 +15,7 @@ from onnx import TensorProto, __version__ as onnx_version from onnx.helper import make_sparse_tensor, make_tensor from onnx.defs import onnx_opset_version +from onnx.numpy_helper import from_array from pyquickhelper.pycode import ExtTestCase from pyquickhelper.texthelper import compare_module_version from sklearn.utils.extmath import softmax @@ -73,7 +74,7 @@ from skl2onnx.algebra.onnx_ops import OnnxBatchNormalization_14 except ImportError: OnnxBatchNormalization_14 = None -from skl2onnx import __version__ as skl2onnx_version +from skl2onnx import __version__ as skl2onnx_version, __max_supported_opset__ from mlprodict.onnxrt import OnnxInference from mlprodict.tools.asv_options_helper import ( get_opset_number_from_onnx, get_ir_version_from_onnx) @@ -82,13 +83,15 @@ _batchnorm_test_mode, _batchnorm_training_mode) from mlprodict.onnxrt.ops_cpu.op_global_average_pool import _global_average_pool from mlprodict.onnxrt.ops_cpu._op_onnx_numpy import ( # pylint: disable=E0611,E0401 - topk_element_min_double, topk_element_max_double, topk_element_fetch_double, + topk_element_min_double, topk_element_max_double, + topk_element_fetch_double, topk_element_min_float, topk_element_max_float, topk_element_fetch_float, topk_element_min_int64, topk_element_max_int64, topk_element_fetch_int64) from mlprodict.onnxrt.ops_cpu.op_celu import _vcelu1, pycelu from mlprodict.onnxrt.ops_cpu.op_topk import topk_sorted_implementation from mlprodict.onnxrt.ops_cpu.op_pad import _pad_impl -from mlprodict.onnxrt.ops_cpu.op_max_pool import _pool_get_output_shape, _pool_impl +from mlprodict.onnxrt.ops_cpu.op_max_pool import ( + _pool_get_output_shape, _pool_impl) from mlprodict.onnxrt.ops_cpu.op_dropout import _dropout from mlprodict.onnxrt.ops_cpu._op_helper import proto2dtype from mlprodict.onnx_tools.onnx2py_helper import ( @@ -190,6 +193,11 @@ def setUp(self): logger = getLogger('skl2onnx') logger.disabled = True + def test_opset_skl2onnx(self): + opset_mlprodict = get_opset_number_from_onnx() + opset_skl2onnx = __max_supported_opset__ + self.assertGreater(opset_skl2onnx, opset_mlprodict) + @ignore_warnings(category=(RuntimeWarning, DeprecationWarning, SparseEfficiencyWarning, PendingDeprecationWarning)) def common_test_onnxt_runtime_unary(self, onnx_cl, np_fct, @@ -2866,7 +2874,7 @@ def test_onnxt_runtime_reduce_prod(self): def test_onnxt_runtime_reduce_sum(self): X = numpy.array([[2, 1], [0, 1]], dtype=float) - for opset in (10, 11, 12, 13, get_opset_number_from_onnx()): + for opset in (10, 11, 12, 13, 14, get_opset_number_from_onnx()): # opset=13, 14, ... if onnx_opset_version() < opset: continue if opset < 13: @@ -2902,7 +2910,7 @@ def test_onnxt_runtime_reduce_sum(self): else: self.assertEqual(name, 'ReduceSum_1') - for opset in (11, 12, 13): + for opset in (11, 12, 13, 14): # opset=13, 14, ... if onnx_opset_version() < opset: continue onx = OnnxReduceSumApi11('X', output_names=['Y'], axes=1, keepdims=1, @@ -2969,7 +2977,7 @@ def test_onnxt_runtime_reduce_sum_square(self): def test_onnxt_runtime_reduce_sum_noop(self): X = numpy.array([], dtype=float).reshape((2, 0)) - for opset in (13, get_opset_number_from_onnx()): + for opset in (13, 14, get_opset_number_from_onnx()): # opset=13, 14, ... if onnx_opset_version() < opset: continue cl = OnnxReduceSum @@ -3183,7 +3191,7 @@ def test_onnxt_runtime_slice(self): @wraplog() def test_onnxt_runtime_slice_step_none(self): - for opset in [13, get_opset_number_from_onnx()]: + for opset in [13, 14, get_opset_number_from_onnx()]: # opset=13, 14, ... if opset > get_opset_number_from_onnx(): continue with self.subTest(opset=opset): @@ -3203,7 +3211,7 @@ def test_onnxt_runtime_slice_step_none(self): @wraplog() def test_onnxt_runtime_split(self): - for opset in [10, 11, 12, 13, get_opset_number_from_onnx()]: + for opset in [10, 11, 12, 13, 14, get_opset_number_from_onnx()]: # opset=13, 14, ... if opset > get_opset_number_from_onnx(): continue with self.subTest(opset=opset): @@ -3251,7 +3259,7 @@ def test_onnxt_runtime_sqrt(self): @wraplog() def test_onnxt_runtime_squeeze(self): - for opset in [10, 11, 12, 13, get_opset_number_from_onnx()]: + for opset in [10, 11, 12, 13, 14, get_opset_number_from_onnx()]: # opset=13, 14, ... if opset > get_opset_number_from_onnx(): continue with self.subTest(opset=opset): @@ -3436,7 +3444,7 @@ def test_onnxt_runtime_transpose(self): @wraplog() def test_onnxt_runtime_unsqueeze(self): - for opset in [10, 11, 12, 13, get_opset_number_from_onnx()]: + for opset in [10, 11, 12, 13, 14, get_opset_number_from_onnx()]: # opset=13, 14, ... if opset > get_opset_number_from_onnx(): continue with self.subTest(opset=opset): @@ -3749,7 +3757,7 @@ def test_make_sparse_tensor_12(self): def bprint(*args): rows.append(str(args)) # pylint: disable=W0640 try: - oinf.run({'X': X.astype(nty)}, + oinf.run({'X': X.astype(nty)}, # opset=13, 14, ... verbose=13, fLOG=bprint) except Exception: # pylint: disable=W0703 pass @@ -3813,6 +3821,20 @@ def test_make_constant(self): self.assertEqual(list(sorted(got)), ['Ad_C0']) self.assertEqualArray(exp, got['Ad_C0']) + def test_op_constant(self): + for opv in [9, 10, 11, 12, 13, 14]: # opset=13, 14, ... + for dtype in [numpy.float32, numpy.float64, + numpy.int32, numpy.int64]: + with self.subTest(opv=opv, dtype=dtype): + X = numpy.array([1], dtype=dtype) + pX = from_array(X) + op = OnnxAdd('X', OnnxConstant(op_version=opv, value=pX), + output_names=['Y'], op_version=opv) + onx = op.to_onnx({'X': X}) + oinf = OnnxInference(onx) + res = oinf.run({'X': X}) + self.assertEqualArray(res['Y'], X + X) + if __name__ == "__main__": # Working diff --git a/_unittests/ut_onnxrt/test_onnxrt_switch_types.py b/_unittests/ut_onnxrt/test_onnxrt_switch_types.py index 63ae5257c..6ac32e1ac 100644 --- a/_unittests/ut_onnxrt/test_onnxrt_switch_types.py +++ b/_unittests/ut_onnxrt/test_onnxrt_switch_types.py @@ -107,7 +107,7 @@ def test_onnxt_iris_gaussian_process_exp_sine_squared_13(self): model_def = to_onnx( clr, X_train.astype(numpy.float32), options={GaussianProcessRegressor: {'return_std': True}}, - target_opset=13) + target_opset=14) # opset=13, 14, ... oinf = OnnxInference(model_def, runtime='python') res = oinf.run({'X': X_test.astype(numpy.float32)}) diff --git a/_unittests/ut_tools/test_ort.py b/_unittests/ut_tools/test_ort.py index dee2ecdeb..03c0423fe 100644 --- a/_unittests/ut_tools/test_ort.py +++ b/_unittests/ut_tools/test_ort.py @@ -13,10 +13,11 @@ class TestOrt(ExtTestCase): def test_prepare_c_profiling(self): + opset = 14 # opset=13, 14, ... dtype = numpy.float32 x = numpy.array([1, 2, 4, 5, 5, 4]).astype( numpy.float32).reshape((3, 2)) - cop = OnnxAdd('X', numpy.array([1], dtype=dtype), op_version=13) + cop = OnnxAdd('X', numpy.array([1], dtype=dtype), op_version=opset) cop2 = OnnxAdd('X', numpy.array([1], dtype=dtype), op_version=13) cop3 = OnnxAdd('X', numpy.array([2], dtype=dtype), op_version=13, output_names=['inter']) diff --git a/mlprodict/testing/einsum/einsum_bench.py b/mlprodict/testing/einsum/einsum_bench.py index 5dfb2fa61..d7d20fd29 100644 --- a/mlprodict/testing/einsum/einsum_bench.py +++ b/mlprodict/testing/einsum/einsum_bench.py @@ -11,7 +11,7 @@ from .einsum_impl import decompose_einsum_equation, apply_einsum_sequence -def _make_einsum_model(equation, opset=13): +def _make_einsum_model(equation, opset=14): # opset=13, 14, ... from skl2onnx.common._topology import OPSET_TO_IR_VERSION # pylint: disable=E0611,E0001 inputs = equation.split('->')[0].split(',') @@ -57,7 +57,7 @@ def _make_inputs(equation, shapes): def einsum_benchmark(equation="abc,cd->abd", shape=30, perm=False, runtime='python', use_tqdm=False, - number=5, repeat=5, opset=13): + number=5, repeat=5, opset=14): # opset=13, 14, ... """ Investigates whether or not the decomposing einsum is faster. diff --git a/mlprodict/tools/asv_options_helper.py b/mlprodict/tools/asv_options_helper.py index 178d8867c..e1b5b9802 100644 --- a/mlprodict/tools/asv_options_helper.py +++ b/mlprodict/tools/asv_options_helper.py @@ -74,7 +74,7 @@ def benchmark_version(): from mlprodict.tools.asv_options_helper import benchmark_version print(benchmark_version()) """ - return [13] + return [14] # opset=13, 14, ... def ir_version():