Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _doc/examples/plot_op_einsum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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_'):
Expand Down
2 changes: 1 addition & 1 deletion _doc/examples/plot_op_reducemax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())],
Expand Down
2 changes: 1 addition & 1 deletion _doc/examples/plot_op_reducemean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())],
Expand Down
2 changes: 1 addition & 1 deletion _doc/examples/plot_op_reducesum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())],
Expand Down
2 changes: 1 addition & 1 deletion _doc/examples/plot_op_reducesumsquare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())],
Expand Down
4 changes: 2 additions & 2 deletions _doc/sphinxdoc/source/blog/2021/2021-05-05_numpyapionnx2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions _doc/sphinxdoc/source/tutorial/numpy_api_onnx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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')``
Expand All @@ -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})``.
Expand All @@ -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*.

Expand All @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions _unittests/ut_onnx_conv/test_onnx_conv_knn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions _unittests/ut_onnxrt/test_benchmark_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 0 additions & 31 deletions _unittests/ut_onnxrt/test_coverage_runtime_ops.py

This file was deleted.

2 changes: 1 addition & 1 deletion _unittests/ut_onnxrt/test_onnx_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
44 changes: 33 additions & 11 deletions _unittests/ut_onnxrt/test_onnxrt_python_runtime_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion _unittests/ut_onnxrt/test_onnxrt_switch_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)})
Expand Down
3 changes: 2 additions & 1 deletion _unittests/ut_tools/test_ort.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
Loading