Skip to content

Commit

Permalink
Fixes for onnx==1.11.0 (#527)
Browse files Browse the repository at this point in the history
* add onnx==1.11.0
* Fixes one unit test involving sklearn-onnx.
* use CPUExecutionProvider
* remove one unnecessary initializer
  • Loading branch information
xadupre authored Mar 22, 2022
1 parent 2f96f95 commit 8ac872b
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 10 deletions.
8 changes: 7 additions & 1 deletion .azure-pipelines/linux-conda-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ jobs:
vmImage: 'ubuntu-latest'
strategy:
matrix:
Python39-1110-RT1100:
python.version: '3.9'
ONNX_PATH: onnx==1.11.0 # '-i https://test.pypi.org/simple/ onnx==1.9.101'
ONNXRT_PATH: onnxruntime==1.10.0
COREML_PATH: git+https://github.com/apple/[email protected]
xgboost.version: '>=1.2'
Python39-1101-RT190:
python.version: '3.9'
ONNX_PATH: onnx==1.10.1 # '-i https://test.pypi.org/simple/ onnx==1.9.101'
ONNX_PATH: onnx==1.10.1
ONNXRT_PATH: onnxruntime==1.9.0
COREML_PATH: git+https://github.com/apple/[email protected]
xgboost.version: '>=1.2'
Expand Down
10 changes: 8 additions & 2 deletions .azure-pipelines/win32-conda-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ jobs:
vmImage: 'windows-latest'
strategy:
matrix:
Python39-1101-RT190:
Python39-1110-RT190:
python.version: '3.9'
ONNX_PATH: 'onnx==1.10.1' # '-i https://test.pypi.org/simple/ onnx==1.9.101'
ONNX_PATH: 'onnx==1.11.0' # '-i https://test.pypi.org/simple/ onnx==1.9.101'
ONNXRT_PATH: onnxruntime==1.10.0
COREML_PATH: git+https://github.com/apple/[email protected]

Python39-1102-RT190:
python.version: '3.9'
ONNX_PATH: 'onnx==1.10.2' # '-i https://test.pypi.org/simple/ onnx==1.9.101'
ONNXRT_PATH: onnxruntime==1.9.0
COREML_PATH: git+https://github.com/apple/[email protected]

Expand Down
2 changes: 1 addition & 1 deletion onnxmltools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This framework converts any machine learned model into onnx format
which is a common language to describe any machine learned model.
"""
__version__ = "1.10.0"
__version__ = "1.11.0"
__author__ = "Microsoft"
__producer__ = "OnnxMLTools"
__producer_version__ = __version__
Expand Down
2 changes: 0 additions & 2 deletions onnxmltools/convert/sparkml/operator_converters/word2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def convert_word2vec(scope, operator, container):
container.add_initializer(one, onnx_proto.TensorProto.INT64, [1], [1])
zero = scope.get_unique_variable_name('zero_tensor')
container.add_initializer(zero, onnx_proto.TensorProto.INT64, [1], [0])
word_count_tensor = scope.get_unique_variable_name('word_count_tensor')
container.add_initializer(word_count_tensor, onnx_proto.TensorProto.INT64, [1], [word_count])

sliced_outputs = []
for i in range(0, word_count):
Expand Down
4 changes: 3 additions & 1 deletion tests/lightgbm/test_LightGbmTreeEnsembleConvertersPkl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

TARGET_OPSET = min(DEFAULT_OPSET_NUMBER, onnx_opset_version())

ort_version = ".".join(onnxruntime.__version__.split('.')[:2])


class TestLightGbmTreeEnsembleModelsPkl(unittest.TestCase):

Expand All @@ -37,7 +39,7 @@ def test_root_leave(self):
@unittest.skipIf(sys.platform.startswith('lin'), reason="recover linux CI build, needs to be fixed")
@unittest.skipIf(not hummingbird_installed(), reason="Hummingbird is not installed")
@unittest.skipIf(
StrictVersion(onnxruntime.__version__) < StrictVersion('1.0.0'), reason="Hummingbird supports only latest versions of ORT"
StrictVersion(ort_version) < StrictVersion('1.0.0'), reason="Hummingbird supports only latest versions of ORT"
)
def test_root_leave_onnx_only(self):
this = os.path.abspath(os.path.dirname(__file__))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@


TARGET_OPSET = min(DEFAULT_OPSET_NUMBER, onnx_opset_version())
ort_version = ".".join(ort_version.split('.')[:2])


class TestLightGbmTreeEnsembleModelsSplit(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/lightgbm/test_objective_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _assert_almost_equal(actual: np.array, desired: np.array, decimal: int=7, fr
success_rel = success_abs / len(actual)
assert success_rel >= frac, f"Only {success_abs} out of {len(actual)} rows are almost equal to {decimal} decimals."

@unittest.skipIf(tuple(int(ver) for ver in onnxruntime.__version__.split(".")) < (1, 3), "not supported in this library version")
@unittest.skipIf(tuple(int(ver) for ver in onnxruntime.__version__.split(".")[:2]) < (1, 3), "not supported in this library version")
def test_objective(self):
"""
Test if a LGBMRegressor a with certain objective (e.g. 'poisson') can be converted to ONNX
Expand Down
2 changes: 1 addition & 1 deletion tests/sparkml/sparkml_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def save_data_models(input, expected, model, onnx_model, basename="model", folde


def run_onnx_model(output_names, input, onnx_model):
sess = onnxruntime.InferenceSession(onnx_model)
sess = onnxruntime.InferenceSession(onnx_model, providers=['CPUExecutionProvider'])
if isinstance(input, dict):
inputs = input
elif isinstance(input, list):
Expand Down
3 changes: 2 additions & 1 deletion tests/xgboost/test_xgboost_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@


TARGET_OPSET = min(DEFAULT_OPSET_NUMBER, onnx_opset_version())
TARGET_OPSET_ML = 2


@unittest.skipIf(sys.version_info[:2] <= (3, 5), reason="not available")
Expand Down Expand Up @@ -134,7 +135,7 @@ def common_test_xgboost_10_skl(self, missing, replace=False):
input_xgb[input_xgb[:, :] == missing] = np.nan
onnx_last = convert_sklearn(model.steps[1][-1],
initial_types=[('X', FloatTensorType(shape=[None, input_xgb.shape[1]]))],
target_opset=TARGET_OPSET)
target_opset={'': TARGET_OPSET, 'ai.onnx.ml': TARGET_OPSET_ML})
session = rt.InferenceSession(onnx_last.SerializeToString())
pred_skl = model.steps[1][-1].predict(input_xgb).ravel()
pred_onx = session.run(None, {'X': input_xgb})[0].ravel()
Expand Down

0 comments on commit 8ac872b

Please sign in to comment.