Skip to content

Commit

Permalink
update CI with the latest version of onnx, onnxruntime (#706)
Browse files Browse the repository at this point in the history
* update CI

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

* lint

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

* fix architecture

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

* remove architecture

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

* move one line

* fix xgboost

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

* catch unable to import

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

* adjust import

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

* import

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

* none or

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

* another fix

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

* xgb

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

* fix comparison

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

* fix ut

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

* fix unittest

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

* atol

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

---------

Signed-off-by: xadupre <xadupre@microsoft.com>
  • Loading branch information
xadupre authored Dec 23, 2024
1 parent 3ae696a commit 4133713
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 38 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
python_version: ['3.12', '3.11', '3.10', '3.9']
include:
- python_version: '3.12'
documentation: 1
numpy_version: '>=1.21.1'
scipy_version: '>=1.7.0'
onnx_version: 'onnx==1.17.0'
onnxrt_version: 'onnxruntime==1.20.1'
sklearn_version: '==1.6.0'
lgbm_version: ">=4"
xgboost_version: ">=2"
- python_version: '3.12'
documentation: 0
numpy_version: '>=1.21.1'
Expand All @@ -19,7 +28,7 @@ jobs:
lgbm_version: ">=4"
xgboost_version: ">=2"
- python_version: '3.11'
documentation: 1
documentation: 0
numpy_version: '>=1.21.1'
scipy_version: '>=1.7.0'
onnx_version: 'onnx<1.16.0'
Expand Down Expand Up @@ -82,20 +91,19 @@ jobs:

- name: versions
run: |
python -c "from numpy import __version__;print('numpy', __version__)"
python -c "from pandas import __version__;print('pandas', __version__)"
python -c "from scipy import __version__;print('scipy', __version__)"
python -c "from sklearn import __version__;print('sklearn', __version__)"
python -c "from onnxruntime import __version__;print('onnxruntime', __version__)"
python -c "from onnx import __version__;print('onnx', __version__)"
python -c "from xgboost import __version__;print('xgboost', __version__)"
python -c "from catboost import __version__;print('catboost', __version__)"
python -c "import onnx.defs;print('onnx_opset_version', onnx.defs.onnx_opset_version())"
- name: versions lightgbm
if: matrix.os != 'macos-latest'
run: |
python -c "from lightgbm import __version__;print('lightgbm', __version__)"
python -c "from xgboost import __version__;print('xgboost', __version__)"
- name: Run tests baseline
run: pytest --maxfail=10 --durations=10 tests/baseline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def calculate_one_hot_encoder_output_shapes(operator):
operator.outputs[0].type = FloatTensorType(
[N, len(int_categories)], doc_string=operator.outputs[0].type.doc_string
)
elif len(str_categories) > 0 and type(operator.inputs[0].type) == StringTensorType:
elif len(str_categories) > 0 and type(operator.inputs[0].type) is StringTensorType:
operator.outputs[0].type = FloatTensorType(
[N, len(str_categories)], doc_string=operator.outputs[0].type.doc_string
)
Expand Down
13 changes: 10 additions & 3 deletions onnxmltools/utils/tests_helper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: Apache-2.0

import unittest
import pickle
import os
import numpy
Expand Down Expand Up @@ -87,16 +88,22 @@ def dump_data_and_model(
if not os.path.exists(folder):
os.makedirs(folder)

if hasattr(model, "predict"):
if "LGBM" in model.__class__.__name__:
try:
import lightgbm
except ImportError:
lightgbm = None
raise unittest.SkipTest("lightgbm cannot be imported.")
else:
lightgbm = None
if "XGB" in model.__class__.__name__ or "Booster" in model.__class__.__name__:
try:
import xgboost
except ImportError:
xgboost = None
raise unittest.SkipTest("xgboost cannot be imported.")
else:
xgboost = None

if hasattr(model, "predict"):
if lightgbm is not None and isinstance(model, lightgbm.Booster):
# LightGBM Booster
model_dict = model.dump_model()
Expand Down
24 changes: 24 additions & 0 deletions onnxmltools/utils/utils_backend_onnxruntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,30 @@ def _compare_expected(
(len(expected), len(output.ravel()) // len(expected))
)
if len(expected) != len(output):
if (
len(output) == 2
and len(expected) == 1
and output[0].dtype in (numpy.int64, numpy.int32)
):
# a classifier
if len(expected[0].shape) == 1:
expected = [
numpy.hstack(
[
1 - expected[0].reshape((-1, 1)),
expected[0].reshape((-1, 1)),
]
)
]
return _compare_expected(
expected,
output[1:],
sess,
onnx,
decimal=5,
onnx_shape=None,
**kwargs
)
raise OnnxRuntimeAssertionError(
"Unexpected number of outputs '{0}', expected={1}, got={2}".format(
onnx, len(expected), len(output)
Expand Down
Loading

0 comments on commit 4133713

Please sign in to comment.