Skip to content

Commit

Permalink
Test onnx==1.14.0 (#988)
Browse files Browse the repository at this point in the history
* Test onnx==1.14.0

Signed-off-by: xadupre <xadupre@microsoft.com>

* fix yml syntax

Signed-off-by: xadupre <xadupre@microsoft.com>

* fix requirements

Signed-off-by: xadupre <xadupre@microsoft.com>

* fix broken unit test

Signed-off-by: xadupre <xadupre@microsoft.com>

* fix ir_version

Signed-off-by: xadupre <xadupre@microsoft.com>

* fix misspelling

Signed-off-by: xadupre <xadupre@microsoft.com>

* fix error

Signed-off-by: xadupre <xadupre@microsoft.com>

* update to rc3

Signed-off-by: xiaowuhu <xiaowuhu@microsoft.com>

* change np.float to np.float32

Signed-off-by: xiaowuhu <xiaowuhu@microsoft.com>

* Test onnx==1.14.0

Signed-off-by: xadupre <xadupre@microsoft.com>

* fix yml syntax

Signed-off-by: xadupre <xadupre@microsoft.com>

* fix requirements

Signed-off-by: xadupre <xadupre@microsoft.com>

* fix broken unit test

Signed-off-by: xadupre <xadupre@microsoft.com>

* fix ir_version

Signed-off-by: xadupre <xadupre@microsoft.com>

* fix misspelling

Signed-off-by: xadupre <xadupre@microsoft.com>

* fix error

Signed-off-by: xadupre <xadupre@microsoft.com>

* update to rc3

Signed-off-by: xiaowuhu <xiaowuhu@microsoft.com>
Signed-off-by: xadupre <xadupre@microsoft.com>

* change np.float to np.float32

Signed-off-by: xiaowuhu <xiaowuhu@microsoft.com>
Signed-off-by: xadupre <xadupre@microsoft.com>

* use official release

Signed-off-by: xadupre <xadupre@microsoft.com>

* disable documentation on one CI

Signed-off-by: xadupre <xadupre@microsoft.com>

* disable test for sklearn==1.0.2

Signed-off-by: xadupre <xadupre@microsoft.com>

* lint

Signed-off-by: xadupre <xadupre@microsoft.com>

* fix issue for an old scikit-learn on windows

Signed-off-by: xadupre <xadupre@microsoft.com>

* update CI

Signed-off-by: xadupre <xadupre@microsoft.com>

* pin numpy version for old build on windows

Signed-off-by: xadupre <xadupre@microsoft.com>

* resolve comment

Signed-off-by: xiaowuhu <xiaowuhu@microsoft.com>

* update

Signed-off-by: xiaowuhu <xiaowuhu@microsoft.com>

---------

Signed-off-by: xadupre <xadupre@microsoft.com>
Signed-off-by: xiaowuhu <xiaowuhu@microsoft.com>
Co-authored-by: xiaowuhu <xiaowuhu@microsoft.com>
  • Loading branch information
xadupre and xiaowuhu authored May 8, 2023
1 parent 7e39c47 commit 2669f0d
Show file tree
Hide file tree
Showing 14 changed files with 243 additions and 139 deletions.
19 changes: 16 additions & 3 deletions .azure-pipelines/linux-conda-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,24 @@ jobs:
strategy:
matrix:

Py310-Onnx130-Rt140-Skl121:
Py310-Onnx140-Rt140-Skl122:
do.bench: '0'
python.version: '3.10'
python.version: '3.10' # onnxruntime cannot support python 3.11 yet
numpy.version: '>=1.21.1'
scipy.version: '>=1.7.0'
onnx.version: 'onnx==1.14.0' # '-i https://test.pypi.org/simple/ onnx==1.14.0rc3'
onnx.target_opset: ''
onnxrt.version: 'onnxruntime==1.14.0' # -i https://test.pypi.org/simple/ ort-nightly==1.11.0.dev20220311003
sklearn.version: '>=1.2.2'
lgbm.version: ''
onnxcc.version: '>=1.8.1' # git
run.example: '1'

Py310-Onnx130-Rt140-Skl122:
do.bench: '0'
python.version: '3.10'
numpy.version: '>=1.21.2'
scipy.version: '>=1.7.0'
onnx.version: 'onnx==1.13.0' #'-i https://test.pypi.org/simple/ onnx==1.13.0rc1'
onnx.target_opset: ''
onnxrt.version: 'onnxruntime==1.14.0' # -i https://test.pypi.org/simple/ ort-nightly==1.11.0.dev20220311003
Expand Down Expand Up @@ -51,7 +64,7 @@ jobs:
sklearn.version: '==1.2.0'
lgbm.version: ''
onnxcc.version: '>=1.8.1' # git
run.example: '1'
run.example: '0'
Py310-Onnx120-Rt1201-Skl11:
do.bench: '0'
python.version: '3.10'
Expand Down
26 changes: 13 additions & 13 deletions .azure-pipelines/win32-conda-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ jobs:
vmImage: 'windows-latest'
strategy:
matrix:
Py310-Onnx140-Rt140-Skl122:
python.version: '3.10' # onnxruntime cannot support python 3.11 yet
onnx.version: 'onnx==1.14.0' # '-i https://test.pypi.org/simple/ onnx==1.14.0rc3'
onnx.target_opset: ''
numpy.version: 'numpy>=1.22.3'
scipy.version: 'scipy'
onnxrt.version: 'onnxruntime==1.14.0' # -i https://test.pypi.org/simple/ ort-nightly==1.11.0.dev20220311003
onnxcc.version: 'onnxconverter-common>=1.8.1' # git+https://github.com/microsoft/onnxconverter-common.git
sklearn.version: '>=1.2.2'
Py310-Onnx130-Rt140-Skl121:
python.version: '3.10'
onnx.version: 'onnx==1.13.0' #'-i https://test.pypi.org/simple/ onnx==1.12.0rc4'
Expand All @@ -21,7 +30,7 @@ jobs:
scipy.version: 'scipy'
onnxrt.version: 'onnxruntime==1.14.0' # -i https://test.pypi.org/simple/ ort-nightly==1.11.0.dev20220311003
onnxcc.version: 'onnxconverter-common>=1.8.1' # git+https://github.com/microsoft/onnxconverter-common.git
sklearn.version: '>=1.2.1'
sklearn.version: '>=1.2.2'
Py310-Onnx130-Rt131-Skl120:
python.version: '3.10'
onnx.version: 'onnx==1.13.0' #'-i https://test.pypi.org/simple/ onnx==1.12.0rc4'
Expand Down Expand Up @@ -71,7 +80,7 @@ jobs:
python.version: '3.9'
onnx.version: 'onnx==1.11.0' # '-i https://test.pypi.org/simple/ onnx==1.11.0rc2'
onnx.target_opset: ''
numpy.version: 'numpy>=1.22.3'
numpy.version: 'numpy==1.23.5'
scipy.version: 'scipy'
onnxrt.version: 'onnxruntime==1.11.1' # -i https://test.pypi.org/simple/ ort-nightly==1.11.0.dev20220311003
onnxcc.version: 'onnxconverter-common>=1.8.1' # git+https://github.com/microsoft/onnxconverter-common.git
Expand All @@ -80,7 +89,7 @@ jobs:
python.version: '3.9'
onnx.version: 'onnx==1.11.0' # '-i https://test.pypi.org/simple/ onnx==1.11.0rc2'
onnx.target_opset: ''
numpy.version: 'numpy>=1.18.1'
numpy.version: 'numpy==1.23.5'
scipy.version: 'scipy'
onnxrt.version: 'onnxruntime==1.10.0' # -i https://test.pypi.org/simple/ ort-nightly'
onnxcc.version: 'onnxconverter-common>=1.8.1' # git+https://github.com/microsoft/onnxconverter-common.git
Expand All @@ -89,20 +98,11 @@ jobs:
python.version: '3.9'
onnx.version: 'onnx==1.10.2' # -i https://test.pypi.org/simple/ onnx'
onnx.target_opset: ''
numpy.version: 'numpy>=1.18.1'
numpy.version: 'numpy==1.23.5'
scipy.version: 'scipy'
onnxrt.version: 'onnxruntime==1.10.0' # -i https://test.pypi.org/simple/ ort-nightly'
onnxcc.version: 'onnxconverter-common>=1.8.1' # git+https://github.com/microsoft/onnxconverter-common.git
sklearn.version: '==1.0.2'
Py39-Onnx1101-Rt190-Skl10:
python.version: '3.9'
onnx.version: 'onnx==1.10.1' # -i https://test.pypi.org/simple/ onnx'
onnx.target_opset: ''
numpy.version: 'numpy>=1.18.1'
scipy.version: 'scipy'
onnxrt.version: 'onnxruntime==1.9.0' # -i https://test.pypi.org/simple/ ort-nightly'
onnxcc.version: 'onnxconverter-common>=1.8.1' # git+https://github.com/microsoft/onnxconverter-common.git
sklearn.version: '==1.0.2'

maxParallel: 3

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ coverage.xml
.coverage
__dump_data/
junit/
tests_dump/
skl2onnx/algebra/_cache/*.rst
docs/auto_examples
docs/examples/graph*.*
Expand Down
1 change: 0 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
autopep8
catboost
category_encoders
codecov
coverage
flake8
furo
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# tests
codecov
flatbuffers
pandas
py-cpuinfo
Expand Down
3 changes: 2 additions & 1 deletion skl2onnx/common/_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def _default_OPSET_TO_IR_VERSION():
return {
1: 3, 2: 3, 3: 3, 4: 3, 5: 3, 6: 3,
7: 3, 8: 4, 9: 4, 10: 5, 11: 6, 12: 7,
13: 7, 14: 7, 15: 8, 16: 8, 17: 8, 18: 8
13: 7, 14: 7, 15: 8, 16: 8, 17: 8, 18: 8,
19: 9
}


Expand Down
4 changes: 2 additions & 2 deletions skl2onnx/operator_converters/label_binariser.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def convert_sklearn_label_binariser(scope: Scope, operator: Operator,
name=scope.get_unique_operator_name('identity'))
else:
zeros_tensor = np.full((1, len(classes)),
binariser_op.neg_label, dtype=np.float)
binariser_op.neg_label, dtype=np.float32)
unit_tensor = np.full((1, len(classes)),
binariser_op.pos_label, dtype=np.float)
binariser_op.pos_label, dtype=np.float32)

classes_tensor_name = scope.get_unique_variable_name('classes_tensor')
equal_condition_tensor_name = scope.get_unique_variable_name(
Expand Down
3 changes: 2 additions & 1 deletion skl2onnx/operator_converters/one_vs_rest_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ def convert_constant_predictor_classifier(scope: Scope, operator: Operator,
proba_flat = OnnxTile(cst, first, op_version=op_version)
proba_reshape = OnnxReshape(
proba_flat, np.array([-1, 2], dtype=np.int64),
output_names=[operator.outputs[1].full_name])
output_names=[operator.outputs[1].full_name],
op_version=op_version)

labels.add_to(scope, container)
proba_reshape.add_to(scope, container)
Expand Down
7 changes: 5 additions & 2 deletions tests/test_optimisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from onnx import TensorProto as tp
from skl2onnx.common.onnx_optimisation_identity import (
onnx_remove_node_identity)
from test_utils import TARGET_OPSET, InferenceSessionEx as InferenceSession
from test_utils import (
TARGET_OPSET, TARGET_IR,
InferenceSessionEx as InferenceSession)


class TestOptimisation(unittest.TestCase):
Expand Down Expand Up @@ -58,7 +60,8 @@ def test_coptimisation_identity_removal(self):

# Create the model and check
m = helper.make_model(
g, opset_imports=[helper.make_opsetid('', TARGET_OPSET)])
g, opset_imports=[helper.make_opsetid('', TARGET_OPSET)],
ir_version=TARGET_IR)
checker.check_model(m)

sess = InferenceSession(
Expand Down
108 changes: 70 additions & 38 deletions tests/test_sklearn_adaboost_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import packaging.version as pv
from onnx.defs import onnx_opset_version
from onnxruntime import __version__ as ort_version
from sklearn import __version__ as sklearn_version
from sklearn.ensemble import AdaBoostClassifier, AdaBoostRegressor
from sklearn.linear_model import LinearRegression, LogisticRegression
from sklearn.tree import DecisionTreeClassifier
Expand All @@ -23,15 +24,22 @@


ort_version = '.'.join(ort_version.split('.')[:2])
skl_version = '.'.join(sklearn_version.split('.')[:2])


class TestSklearnAdaBoostModels(unittest.TestCase):
@unittest.skipIf(TARGET_OPSET < 11, reason="not available")
def test_ada_boost_classifier_samme_r(self):
model, X_test = fit_classification_model(AdaBoostClassifier(
n_estimators=10, algorithm="SAMME.R", random_state=42,
base_estimator=DecisionTreeClassifier(
max_depth=2, random_state=42)), 3)
if pv.Version(skl_version) < pv.Version("1.2"):
model, X_test = fit_classification_model(AdaBoostClassifier(
n_estimators=10, algorithm="SAMME.R", random_state=42,
base_estimator=DecisionTreeClassifier(
max_depth=2, random_state=42)), 3)
else:
model, X_test = fit_classification_model(AdaBoostClassifier(
n_estimators=10, algorithm="SAMME.R", random_state=42,
estimator=DecisionTreeClassifier(
max_depth=2, random_state=42)), 3)
model_onnx = convert_sklearn(
model,
"AdaBoost classification",
Expand All @@ -47,10 +55,16 @@ def test_ada_boost_classifier_samme_r(self):

@unittest.skipIf(TARGET_OPSET < 11, reason="not available")
def test_ada_boost_classifier_samme_r_decision_function(self):
model, X_test = fit_classification_model(AdaBoostClassifier(
n_estimators=10, algorithm="SAMME.R", random_state=42,
base_estimator=DecisionTreeClassifier(
max_depth=2, random_state=42)), 4)
if pv.Version(skl_version) < pv.Version("1.2"):
model, X_test = fit_classification_model(AdaBoostClassifier(
n_estimators=10, algorithm="SAMME.R", random_state=42,
base_estimator=DecisionTreeClassifier(
max_depth=2, random_state=42)), 4)
else:
model, X_test = fit_classification_model(AdaBoostClassifier(
n_estimators=10, algorithm="SAMME.R", random_state=42,
estimator=DecisionTreeClassifier(
max_depth=2, random_state=42)), 4)
options = {id(model): {'raw_scores': True}}
model_onnx = convert_sklearn(
model,
Expand All @@ -69,10 +83,16 @@ def test_ada_boost_classifier_samme_r_decision_function(self):

@unittest.skipIf(TARGET_OPSET < 11, reason="not available")
def test_ada_boost_classifier_samme_r_logreg(self):
model, X_test = fit_classification_model(AdaBoostClassifier(
n_estimators=5, algorithm="SAMME.R",
base_estimator=LogisticRegression(
solver='liblinear')), 4)
if pv.Version(skl_version) < pv.Version("1.2"):
model, X_test = fit_classification_model(AdaBoostClassifier(
n_estimators=5, algorithm="SAMME.R",
base_estimator=LogisticRegression(
solver='liblinear')), 4)
else:
model, X_test = fit_classification_model(AdaBoostClassifier(
n_estimators=5, algorithm="SAMME.R",
estimator=LogisticRegression(
solver='liblinear')), 4)
model_onnx = convert_sklearn(
model,
"AdaBoost classification",
Expand All @@ -88,10 +108,16 @@ def test_ada_boost_classifier_samme_r_logreg(self):

@unittest.skipIf(TARGET_OPSET < 11, reason="not available")
def test_ada_boost_classifier_samme(self):
model, X_test = fit_classification_model(AdaBoostClassifier(
n_estimators=5, algorithm="SAMME", random_state=42,
base_estimator=DecisionTreeClassifier(
max_depth=6, random_state=42)), 2, n_features=7)
if pv.Version(skl_version) < pv.Version("1.2"):
model, X_test = fit_classification_model(AdaBoostClassifier(
n_estimators=5, algorithm="SAMME", random_state=42,
base_estimator=DecisionTreeClassifier(
max_depth=6, random_state=42)), 2, n_features=7)
else:
model, X_test = fit_classification_model(AdaBoostClassifier(
n_estimators=5, algorithm="SAMME", random_state=42,
estimator=DecisionTreeClassifier(
max_depth=6, random_state=42)), 2, n_features=7)
model_onnx = convert_sklearn(
model,
"AdaBoostClSamme",
Expand All @@ -107,10 +133,16 @@ def test_ada_boost_classifier_samme(self):

@unittest.skipIf(TARGET_OPSET < 11, reason="not available")
def test_ada_boost_classifier_samme_decision_function(self):
model, X_test = fit_classification_model(AdaBoostClassifier(
n_estimators=5, algorithm="SAMME", random_state=42,
base_estimator=DecisionTreeClassifier(
max_depth=6, random_state=42)), 2)
if pv.Version(skl_version) < pv.Version("1.2"):
model, X_test = fit_classification_model(AdaBoostClassifier(
n_estimators=5, algorithm="SAMME", random_state=42,
base_estimator=DecisionTreeClassifier(
max_depth=6, random_state=42)), 2)
else:
model, X_test = fit_classification_model(AdaBoostClassifier(
n_estimators=5, algorithm="SAMME", random_state=42,
estimator=DecisionTreeClassifier(
max_depth=6, random_state=42)), 2)
options = {id(model): {'raw_scores': True}}
model_onnx = convert_sklearn(
model,
Expand Down Expand Up @@ -174,25 +206,28 @@ def test_ada_boost_regressor(self):
target_opset=10)
self.assertIsNotNone(model_onnx)
dump_data_and_model(
X,
model,
model_onnx,
X, model, model_onnx,
backend="onnxruntime",
basename="SklearnAdaBoostRegressor-Dec4")

@unittest.skipIf(TARGET_OPSET < 11, reason="not available")
def test_ada_boost_regressor_lreg(self):
model, X = fit_regression_model(
AdaBoostRegressor(n_estimators=5,
base_estimator=LinearRegression()))
if pv.Version(skl_version) < pv.Version("1.2"):
model, X = fit_regression_model(
AdaBoostRegressor(n_estimators=5,
base_estimator=LinearRegression()))
else:
model, X = fit_regression_model(
AdaBoostRegressor(n_estimators=5,
estimator=LinearRegression()))
model_onnx = convert_sklearn(
model, "AdaBoost regression",
[("input", FloatTensorType([None, X.shape[1]]))],
target_opset=10)
self.assertIsNotNone(model_onnx)
dump_data_and_model(
X,
model,
model_onnx,
X, model, model_onnx,
backend="onnxruntime",
basename="SklearnAdaBoostRegressorLReg-Dec4")

@unittest.skipIf(TARGET_OPSET < 11, reason="not available")
Expand All @@ -205,9 +240,8 @@ def test_ada_boost_regressor_int(self):
target_opset=10)
self.assertIsNotNone(model_onnx)
dump_data_and_model(
X,
model,
model_onnx,
X, model, model_onnx,
backend="onnxruntime",
basename="SklearnAdaBoostRegressorInt-Dec4")

@unittest.skipIf(TARGET_OPSET < 11, reason="not available")
Expand All @@ -220,9 +254,8 @@ def test_ada_boost_regressor_lr10(self):
target_opset=10)
self.assertIsNotNone(model_onnx)
dump_data_and_model(
X,
model,
model_onnx,
X, model, model_onnx,
backend="onnxruntime",
basename="SklearnAdaBoostRegressorLR-Dec4")

@unittest.skipIf((pv.Version(ort_version) <
Expand Down Expand Up @@ -262,9 +295,8 @@ def test_ada_boost_regressor_bool(self):
)
self.assertIsNotNone(model_onnx)
dump_data_and_model(
X,
model,
model_onnx,
X, model, model_onnx,
backend="onnxruntime",
basename="SklearnAdaBoostRegressorBool")


Expand Down
10 changes: 7 additions & 3 deletions tests/test_sklearn_feature_hasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
from skl2onnx.common.data_types import (
StringTensorType, Int64TensorType, FloatTensorType,
DoubleTensorType)
from test_utils import TARGET_OPSET, InferenceSessionEx as InferenceSession
from test_utils import (
TARGET_OPSET, TARGET_IR,
InferenceSessionEx as InferenceSession)


class TestSklearnFeatureHasher(unittest.TestCase):
Expand All @@ -33,7 +35,8 @@ def test_ort_murmurhash3_int(self):
graph = make_graph([node], 'hash', [X], [Y])
onnx_model = make_model(graph, opset_imports=[
make_opsetid('', TARGET_OPSET),
make_opsetid('com.microsoft', 1)])
make_opsetid('com.microsoft', 1)],
ir_version=TARGET_IR)
check_model(onnx_model)
sess = InferenceSession(
onnx_model.SerializeToString(),
Expand All @@ -53,7 +56,8 @@ def test_ort_murmurhash3_string(self):
graph = make_graph([node], 'hash', [X], [Y])
onnx_model = make_model(graph, opset_imports=[
make_opsetid('', TARGET_OPSET),
make_opsetid('com.microsoft', 1)])
make_opsetid('com.microsoft', 1)],
ir_version=TARGET_IR)
check_model(onnx_model)
sess = InferenceSession(
onnx_model.SerializeToString(),
Expand Down
Loading

0 comments on commit 2669f0d

Please sign in to comment.