Skip to content

Commit 2669f0d

Browse files
xaduprexiaowuhu
andauthored
Test onnx==1.14.0 (#988)
* Test onnx==1.14.0 Signed-off-by: xadupre <[email protected]> * fix yml syntax Signed-off-by: xadupre <[email protected]> * fix requirements Signed-off-by: xadupre <[email protected]> * fix broken unit test Signed-off-by: xadupre <[email protected]> * fix ir_version Signed-off-by: xadupre <[email protected]> * fix misspelling Signed-off-by: xadupre <[email protected]> * fix error Signed-off-by: xadupre <[email protected]> * update to rc3 Signed-off-by: xiaowuhu <[email protected]> * change np.float to np.float32 Signed-off-by: xiaowuhu <[email protected]> * Test onnx==1.14.0 Signed-off-by: xadupre <[email protected]> * fix yml syntax Signed-off-by: xadupre <[email protected]> * fix requirements Signed-off-by: xadupre <[email protected]> * fix broken unit test Signed-off-by: xadupre <[email protected]> * fix ir_version Signed-off-by: xadupre <[email protected]> * fix misspelling Signed-off-by: xadupre <[email protected]> * fix error Signed-off-by: xadupre <[email protected]> * update to rc3 Signed-off-by: xiaowuhu <[email protected]> Signed-off-by: xadupre <[email protected]> * change np.float to np.float32 Signed-off-by: xiaowuhu <[email protected]> Signed-off-by: xadupre <[email protected]> * use official release Signed-off-by: xadupre <[email protected]> * disable documentation on one CI Signed-off-by: xadupre <[email protected]> * disable test for sklearn==1.0.2 Signed-off-by: xadupre <[email protected]> * lint Signed-off-by: xadupre <[email protected]> * fix issue for an old scikit-learn on windows Signed-off-by: xadupre <[email protected]> * update CI Signed-off-by: xadupre <[email protected]> * pin numpy version for old build on windows Signed-off-by: xadupre <[email protected]> * resolve comment Signed-off-by: xiaowuhu <[email protected]> * update Signed-off-by: xiaowuhu <[email protected]> --------- Signed-off-by: xadupre <[email protected]> Signed-off-by: xiaowuhu <[email protected]> Co-authored-by: xiaowuhu <[email protected]>
1 parent 7e39c47 commit 2669f0d

14 files changed

+243
-139
lines changed

.azure-pipelines/linux-conda-CI.yml

+16-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,24 @@ jobs:
1414
strategy:
1515
matrix:
1616

17-
Py310-Onnx130-Rt140-Skl121:
17+
Py310-Onnx140-Rt140-Skl122:
1818
do.bench: '0'
19-
python.version: '3.10'
19+
python.version: '3.10' # onnxruntime cannot support python 3.11 yet
2020
numpy.version: '>=1.21.1'
2121
scipy.version: '>=1.7.0'
22+
onnx.version: 'onnx==1.14.0' # '-i https://test.pypi.org/simple/ onnx==1.14.0rc3'
23+
onnx.target_opset: ''
24+
onnxrt.version: 'onnxruntime==1.14.0' # -i https://test.pypi.org/simple/ ort-nightly==1.11.0.dev20220311003
25+
sklearn.version: '>=1.2.2'
26+
lgbm.version: ''
27+
onnxcc.version: '>=1.8.1' # git
28+
run.example: '1'
29+
30+
Py310-Onnx130-Rt140-Skl122:
31+
do.bench: '0'
32+
python.version: '3.10'
33+
numpy.version: '>=1.21.2'
34+
scipy.version: '>=1.7.0'
2235
onnx.version: 'onnx==1.13.0' #'-i https://test.pypi.org/simple/ onnx==1.13.0rc1'
2336
onnx.target_opset: ''
2437
onnxrt.version: 'onnxruntime==1.14.0' # -i https://test.pypi.org/simple/ ort-nightly==1.11.0.dev20220311003
@@ -51,7 +64,7 @@ jobs:
5164
sklearn.version: '==1.2.0'
5265
lgbm.version: ''
5366
onnxcc.version: '>=1.8.1' # git
54-
run.example: '1'
67+
run.example: '0'
5568
Py310-Onnx120-Rt1201-Skl11:
5669
do.bench: '0'
5770
python.version: '3.10'

.azure-pipelines/win32-conda-CI.yml

+13-13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ jobs:
1313
vmImage: 'windows-latest'
1414
strategy:
1515
matrix:
16+
Py310-Onnx140-Rt140-Skl122:
17+
python.version: '3.10' # onnxruntime cannot support python 3.11 yet
18+
onnx.version: 'onnx==1.14.0' # '-i https://test.pypi.org/simple/ onnx==1.14.0rc3'
19+
onnx.target_opset: ''
20+
numpy.version: 'numpy>=1.22.3'
21+
scipy.version: 'scipy'
22+
onnxrt.version: 'onnxruntime==1.14.0' # -i https://test.pypi.org/simple/ ort-nightly==1.11.0.dev20220311003
23+
onnxcc.version: 'onnxconverter-common>=1.8.1' # git+https://github.com/microsoft/onnxconverter-common.git
24+
sklearn.version: '>=1.2.2'
1625
Py310-Onnx130-Rt140-Skl121:
1726
python.version: '3.10'
1827
onnx.version: 'onnx==1.13.0' #'-i https://test.pypi.org/simple/ onnx==1.12.0rc4'
@@ -21,7 +30,7 @@ jobs:
2130
scipy.version: 'scipy'
2231
onnxrt.version: 'onnxruntime==1.14.0' # -i https://test.pypi.org/simple/ ort-nightly==1.11.0.dev20220311003
2332
onnxcc.version: 'onnxconverter-common>=1.8.1' # git+https://github.com/microsoft/onnxconverter-common.git
24-
sklearn.version: '>=1.2.1'
33+
sklearn.version: '>=1.2.2'
2534
Py310-Onnx130-Rt131-Skl120:
2635
python.version: '3.10'
2736
onnx.version: 'onnx==1.13.0' #'-i https://test.pypi.org/simple/ onnx==1.12.0rc4'
@@ -71,7 +80,7 @@ jobs:
7180
python.version: '3.9'
7281
onnx.version: 'onnx==1.11.0' # '-i https://test.pypi.org/simple/ onnx==1.11.0rc2'
7382
onnx.target_opset: ''
74-
numpy.version: 'numpy>=1.22.3'
83+
numpy.version: 'numpy==1.23.5'
7584
scipy.version: 'scipy'
7685
onnxrt.version: 'onnxruntime==1.11.1' # -i https://test.pypi.org/simple/ ort-nightly==1.11.0.dev20220311003
7786
onnxcc.version: 'onnxconverter-common>=1.8.1' # git+https://github.com/microsoft/onnxconverter-common.git
@@ -80,7 +89,7 @@ jobs:
8089
python.version: '3.9'
8190
onnx.version: 'onnx==1.11.0' # '-i https://test.pypi.org/simple/ onnx==1.11.0rc2'
8291
onnx.target_opset: ''
83-
numpy.version: 'numpy>=1.18.1'
92+
numpy.version: 'numpy==1.23.5'
8493
scipy.version: 'scipy'
8594
onnxrt.version: 'onnxruntime==1.10.0' # -i https://test.pypi.org/simple/ ort-nightly'
8695
onnxcc.version: 'onnxconverter-common>=1.8.1' # git+https://github.com/microsoft/onnxconverter-common.git
@@ -89,20 +98,11 @@ jobs:
8998
python.version: '3.9'
9099
onnx.version: 'onnx==1.10.2' # -i https://test.pypi.org/simple/ onnx'
91100
onnx.target_opset: ''
92-
numpy.version: 'numpy>=1.18.1'
101+
numpy.version: 'numpy==1.23.5'
93102
scipy.version: 'scipy'
94103
onnxrt.version: 'onnxruntime==1.10.0' # -i https://test.pypi.org/simple/ ort-nightly'
95104
onnxcc.version: 'onnxconverter-common>=1.8.1' # git+https://github.com/microsoft/onnxconverter-common.git
96105
sklearn.version: '==1.0.2'
97-
Py39-Onnx1101-Rt190-Skl10:
98-
python.version: '3.9'
99-
onnx.version: 'onnx==1.10.1' # -i https://test.pypi.org/simple/ onnx'
100-
onnx.target_opset: ''
101-
numpy.version: 'numpy>=1.18.1'
102-
scipy.version: 'scipy'
103-
onnxrt.version: 'onnxruntime==1.9.0' # -i https://test.pypi.org/simple/ ort-nightly'
104-
onnxcc.version: 'onnxconverter-common>=1.8.1' # git+https://github.com/microsoft/onnxconverter-common.git
105-
sklearn.version: '==1.0.2'
106106

107107
maxParallel: 3
108108

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ coverage.xml
3030
.coverage
3131
__dump_data/
3232
junit/
33+
tests_dump/
3334
skl2onnx/algebra/_cache/*.rst
3435
docs/auto_examples
3536
docs/examples/graph*.*

docs/requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
autopep8
22
catboost
33
category_encoders
4-
codecov
54
coverage
65
flake8
76
furo

requirements-dev.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# tests
2-
codecov
32
flatbuffers
43
pandas
54
py-cpuinfo

skl2onnx/common/_topology.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def _default_OPSET_TO_IR_VERSION():
4040
return {
4141
1: 3, 2: 3, 3: 3, 4: 3, 5: 3, 6: 3,
4242
7: 3, 8: 4, 9: 4, 10: 5, 11: 6, 12: 7,
43-
13: 7, 14: 7, 15: 8, 16: 8, 17: 8, 18: 8
43+
13: 7, 14: 7, 15: 8, 16: 8, 17: 8, 18: 8,
44+
19: 9
4445
}
4546

4647

skl2onnx/operator_converters/label_binariser.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def convert_sklearn_label_binariser(scope: Scope, operator: Operator,
3030
name=scope.get_unique_operator_name('identity'))
3131
else:
3232
zeros_tensor = np.full((1, len(classes)),
33-
binariser_op.neg_label, dtype=np.float)
33+
binariser_op.neg_label, dtype=np.float32)
3434
unit_tensor = np.full((1, len(classes)),
35-
binariser_op.pos_label, dtype=np.float)
35+
binariser_op.pos_label, dtype=np.float32)
3636

3737
classes_tensor_name = scope.get_unique_variable_name('classes_tensor')
3838
equal_condition_tensor_name = scope.get_unique_variable_name(

skl2onnx/operator_converters/one_vs_rest_classifier.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ def convert_constant_predictor_classifier(scope: Scope, operator: Operator,
199199
proba_flat = OnnxTile(cst, first, op_version=op_version)
200200
proba_reshape = OnnxReshape(
201201
proba_flat, np.array([-1, 2], dtype=np.int64),
202-
output_names=[operator.outputs[1].full_name])
202+
output_names=[operator.outputs[1].full_name],
203+
op_version=op_version)
203204

204205
labels.add_to(scope, container)
205206
proba_reshape.add_to(scope, container)

tests/test_optimisation.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
from onnx import TensorProto as tp
99
from skl2onnx.common.onnx_optimisation_identity import (
1010
onnx_remove_node_identity)
11-
from test_utils import TARGET_OPSET, InferenceSessionEx as InferenceSession
11+
from test_utils import (
12+
TARGET_OPSET, TARGET_IR,
13+
InferenceSessionEx as InferenceSession)
1214

1315

1416
class TestOptimisation(unittest.TestCase):
@@ -58,7 +60,8 @@ def test_coptimisation_identity_removal(self):
5860

5961
# Create the model and check
6062
m = helper.make_model(
61-
g, opset_imports=[helper.make_opsetid('', TARGET_OPSET)])
63+
g, opset_imports=[helper.make_opsetid('', TARGET_OPSET)],
64+
ir_version=TARGET_IR)
6265
checker.check_model(m)
6366

6467
sess = InferenceSession(

tests/test_sklearn_adaboost_converter.py

+70-38
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import packaging.version as pv
66
from onnx.defs import onnx_opset_version
77
from onnxruntime import __version__ as ort_version
8+
from sklearn import __version__ as sklearn_version
89
from sklearn.ensemble import AdaBoostClassifier, AdaBoostRegressor
910
from sklearn.linear_model import LinearRegression, LogisticRegression
1011
from sklearn.tree import DecisionTreeClassifier
@@ -23,15 +24,22 @@
2324

2425

2526
ort_version = '.'.join(ort_version.split('.')[:2])
27+
skl_version = '.'.join(sklearn_version.split('.')[:2])
2628

2729

2830
class TestSklearnAdaBoostModels(unittest.TestCase):
2931
@unittest.skipIf(TARGET_OPSET < 11, reason="not available")
3032
def test_ada_boost_classifier_samme_r(self):
31-
model, X_test = fit_classification_model(AdaBoostClassifier(
32-
n_estimators=10, algorithm="SAMME.R", random_state=42,
33-
base_estimator=DecisionTreeClassifier(
34-
max_depth=2, random_state=42)), 3)
33+
if pv.Version(skl_version) < pv.Version("1.2"):
34+
model, X_test = fit_classification_model(AdaBoostClassifier(
35+
n_estimators=10, algorithm="SAMME.R", random_state=42,
36+
base_estimator=DecisionTreeClassifier(
37+
max_depth=2, random_state=42)), 3)
38+
else:
39+
model, X_test = fit_classification_model(AdaBoostClassifier(
40+
n_estimators=10, algorithm="SAMME.R", random_state=42,
41+
estimator=DecisionTreeClassifier(
42+
max_depth=2, random_state=42)), 3)
3543
model_onnx = convert_sklearn(
3644
model,
3745
"AdaBoost classification",
@@ -47,10 +55,16 @@ def test_ada_boost_classifier_samme_r(self):
4755

4856
@unittest.skipIf(TARGET_OPSET < 11, reason="not available")
4957
def test_ada_boost_classifier_samme_r_decision_function(self):
50-
model, X_test = fit_classification_model(AdaBoostClassifier(
51-
n_estimators=10, algorithm="SAMME.R", random_state=42,
52-
base_estimator=DecisionTreeClassifier(
53-
max_depth=2, random_state=42)), 4)
58+
if pv.Version(skl_version) < pv.Version("1.2"):
59+
model, X_test = fit_classification_model(AdaBoostClassifier(
60+
n_estimators=10, algorithm="SAMME.R", random_state=42,
61+
base_estimator=DecisionTreeClassifier(
62+
max_depth=2, random_state=42)), 4)
63+
else:
64+
model, X_test = fit_classification_model(AdaBoostClassifier(
65+
n_estimators=10, algorithm="SAMME.R", random_state=42,
66+
estimator=DecisionTreeClassifier(
67+
max_depth=2, random_state=42)), 4)
5468
options = {id(model): {'raw_scores': True}}
5569
model_onnx = convert_sklearn(
5670
model,
@@ -69,10 +83,16 @@ def test_ada_boost_classifier_samme_r_decision_function(self):
6983

7084
@unittest.skipIf(TARGET_OPSET < 11, reason="not available")
7185
def test_ada_boost_classifier_samme_r_logreg(self):
72-
model, X_test = fit_classification_model(AdaBoostClassifier(
73-
n_estimators=5, algorithm="SAMME.R",
74-
base_estimator=LogisticRegression(
75-
solver='liblinear')), 4)
86+
if pv.Version(skl_version) < pv.Version("1.2"):
87+
model, X_test = fit_classification_model(AdaBoostClassifier(
88+
n_estimators=5, algorithm="SAMME.R",
89+
base_estimator=LogisticRegression(
90+
solver='liblinear')), 4)
91+
else:
92+
model, X_test = fit_classification_model(AdaBoostClassifier(
93+
n_estimators=5, algorithm="SAMME.R",
94+
estimator=LogisticRegression(
95+
solver='liblinear')), 4)
7696
model_onnx = convert_sklearn(
7797
model,
7898
"AdaBoost classification",
@@ -88,10 +108,16 @@ def test_ada_boost_classifier_samme_r_logreg(self):
88108

89109
@unittest.skipIf(TARGET_OPSET < 11, reason="not available")
90110
def test_ada_boost_classifier_samme(self):
91-
model, X_test = fit_classification_model(AdaBoostClassifier(
92-
n_estimators=5, algorithm="SAMME", random_state=42,
93-
base_estimator=DecisionTreeClassifier(
94-
max_depth=6, random_state=42)), 2, n_features=7)
111+
if pv.Version(skl_version) < pv.Version("1.2"):
112+
model, X_test = fit_classification_model(AdaBoostClassifier(
113+
n_estimators=5, algorithm="SAMME", random_state=42,
114+
base_estimator=DecisionTreeClassifier(
115+
max_depth=6, random_state=42)), 2, n_features=7)
116+
else:
117+
model, X_test = fit_classification_model(AdaBoostClassifier(
118+
n_estimators=5, algorithm="SAMME", random_state=42,
119+
estimator=DecisionTreeClassifier(
120+
max_depth=6, random_state=42)), 2, n_features=7)
95121
model_onnx = convert_sklearn(
96122
model,
97123
"AdaBoostClSamme",
@@ -107,10 +133,16 @@ def test_ada_boost_classifier_samme(self):
107133

108134
@unittest.skipIf(TARGET_OPSET < 11, reason="not available")
109135
def test_ada_boost_classifier_samme_decision_function(self):
110-
model, X_test = fit_classification_model(AdaBoostClassifier(
111-
n_estimators=5, algorithm="SAMME", random_state=42,
112-
base_estimator=DecisionTreeClassifier(
113-
max_depth=6, random_state=42)), 2)
136+
if pv.Version(skl_version) < pv.Version("1.2"):
137+
model, X_test = fit_classification_model(AdaBoostClassifier(
138+
n_estimators=5, algorithm="SAMME", random_state=42,
139+
base_estimator=DecisionTreeClassifier(
140+
max_depth=6, random_state=42)), 2)
141+
else:
142+
model, X_test = fit_classification_model(AdaBoostClassifier(
143+
n_estimators=5, algorithm="SAMME", random_state=42,
144+
estimator=DecisionTreeClassifier(
145+
max_depth=6, random_state=42)), 2)
114146
options = {id(model): {'raw_scores': True}}
115147
model_onnx = convert_sklearn(
116148
model,
@@ -174,25 +206,28 @@ def test_ada_boost_regressor(self):
174206
target_opset=10)
175207
self.assertIsNotNone(model_onnx)
176208
dump_data_and_model(
177-
X,
178-
model,
179-
model_onnx,
209+
X, model, model_onnx,
210+
backend="onnxruntime",
180211
basename="SklearnAdaBoostRegressor-Dec4")
181212

182213
@unittest.skipIf(TARGET_OPSET < 11, reason="not available")
183214
def test_ada_boost_regressor_lreg(self):
184-
model, X = fit_regression_model(
185-
AdaBoostRegressor(n_estimators=5,
186-
base_estimator=LinearRegression()))
215+
if pv.Version(skl_version) < pv.Version("1.2"):
216+
model, X = fit_regression_model(
217+
AdaBoostRegressor(n_estimators=5,
218+
base_estimator=LinearRegression()))
219+
else:
220+
model, X = fit_regression_model(
221+
AdaBoostRegressor(n_estimators=5,
222+
estimator=LinearRegression()))
187223
model_onnx = convert_sklearn(
188224
model, "AdaBoost regression",
189225
[("input", FloatTensorType([None, X.shape[1]]))],
190226
target_opset=10)
191227
self.assertIsNotNone(model_onnx)
192228
dump_data_and_model(
193-
X,
194-
model,
195-
model_onnx,
229+
X, model, model_onnx,
230+
backend="onnxruntime",
196231
basename="SklearnAdaBoostRegressorLReg-Dec4")
197232

198233
@unittest.skipIf(TARGET_OPSET < 11, reason="not available")
@@ -205,9 +240,8 @@ def test_ada_boost_regressor_int(self):
205240
target_opset=10)
206241
self.assertIsNotNone(model_onnx)
207242
dump_data_and_model(
208-
X,
209-
model,
210-
model_onnx,
243+
X, model, model_onnx,
244+
backend="onnxruntime",
211245
basename="SklearnAdaBoostRegressorInt-Dec4")
212246

213247
@unittest.skipIf(TARGET_OPSET < 11, reason="not available")
@@ -220,9 +254,8 @@ def test_ada_boost_regressor_lr10(self):
220254
target_opset=10)
221255
self.assertIsNotNone(model_onnx)
222256
dump_data_and_model(
223-
X,
224-
model,
225-
model_onnx,
257+
X, model, model_onnx,
258+
backend="onnxruntime",
226259
basename="SklearnAdaBoostRegressorLR-Dec4")
227260

228261
@unittest.skipIf((pv.Version(ort_version) <
@@ -262,9 +295,8 @@ def test_ada_boost_regressor_bool(self):
262295
)
263296
self.assertIsNotNone(model_onnx)
264297
dump_data_and_model(
265-
X,
266-
model,
267-
model_onnx,
298+
X, model, model_onnx,
299+
backend="onnxruntime",
268300
basename="SklearnAdaBoostRegressorBool")
269301

270302

tests/test_sklearn_feature_hasher.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
from skl2onnx.common.data_types import (
1919
StringTensorType, Int64TensorType, FloatTensorType,
2020
DoubleTensorType)
21-
from test_utils import TARGET_OPSET, InferenceSessionEx as InferenceSession
21+
from test_utils import (
22+
TARGET_OPSET, TARGET_IR,
23+
InferenceSessionEx as InferenceSession)
2224

2325

2426
class TestSklearnFeatureHasher(unittest.TestCase):
@@ -33,7 +35,8 @@ def test_ort_murmurhash3_int(self):
3335
graph = make_graph([node], 'hash', [X], [Y])
3436
onnx_model = make_model(graph, opset_imports=[
3537
make_opsetid('', TARGET_OPSET),
36-
make_opsetid('com.microsoft', 1)])
38+
make_opsetid('com.microsoft', 1)],
39+
ir_version=TARGET_IR)
3740
check_model(onnx_model)
3841
sess = InferenceSession(
3942
onnx_model.SerializeToString(),
@@ -53,7 +56,8 @@ def test_ort_murmurhash3_string(self):
5356
graph = make_graph([node], 'hash', [X], [Y])
5457
onnx_model = make_model(graph, opset_imports=[
5558
make_opsetid('', TARGET_OPSET),
56-
make_opsetid('com.microsoft', 1)])
59+
make_opsetid('com.microsoft', 1)],
60+
ir_version=TARGET_IR)
5761
check_model(onnx_model)
5862
sess = InferenceSession(
5963
onnx_model.SerializeToString(),

0 commit comments

Comments
 (0)