Skip to content

Commit

Permalink
Update CI to onnx==1.10.1 (#490)
Browse files Browse the repository at this point in the history
* check onnx==1.10.1
* better error message
* change skipping condition
* one condition less strict on lightgbm
  • Loading branch information
xadupre authored Aug 20, 2021
1 parent c1651b1 commit 3d81a0a
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .azure-pipelines/linux-conda-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ jobs:
vmImage: 'ubuntu-latest'
strategy:
matrix:
Python39-1101-RT181-xgb11:
python.version: '3.9'
ONNX_PATH: onnx==1.10.1 # '-i https://test.pypi.org/simple/ onnx==1.9.101'
ONNXRT_PATH: onnxruntime==1.8.1
COREML_PATH: git+https://github.com/apple/[email protected]
xgboost.version: '>=1.2'
Python39-190-RT180-xgb11:
python.version: '3.9'
ONNX_PATH: onnx==1.9.0
Expand Down
37 changes: 34 additions & 3 deletions .azure-pipelines/win32-conda-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ jobs:
vmImage: 'windows-latest'
strategy:
matrix:
Python39-1101-RT181:
python.version: '3.9'
ONNX_PATH: 'onnx==1.10.1' # '-i https://test.pypi.org/simple/ onnx==1.9.101'
ONNXRT_PATH: onnxruntime==1.8.1
COREML_PATH: git+https://github.com/apple/[email protected]
sklearn.version: ''

Python39-190-RT181:
python.version: '3.9'
ONNX_PATH: 'onnx==1.9.0'
ONNXRT_PATH: onnxruntime==1.8.1
COREML_PATH: git+https://github.com/apple/[email protected]
sklearn.version: ''

Python39-190-RT180:
python.version: '3.9'
ONNX_PATH: onnx==1.9.0
Expand Down Expand Up @@ -66,15 +80,32 @@ jobs:
call activate py$(python.version)
python -m pip install --upgrade pip numpy
echo Test numpy installation... && python -c "import numpy"
python -m pip install %COREML_PATH% %ONNX_PATH%
python -m pip install scikit-learn
python -m pip install %ONNX_PATH%
python -m pip install humming-bird-ml --no-deps
python -m pip install -r requirements.txt
python -m pip install torch==1.8.1+cpu torchvision==0.9.1+cpu torchaudio===0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
displayName: 'Install dependencies (1)'
- script: |
call activate py$(python.version)
python -m pip install -r requirements-dev.txt
displayName: 'Install dependencies (2)'
- script: |
call activate py$(python.version)
python -m pip install %COREML_PATH%
displayName: 'Install coremltools'
- script: |
call activate py$(python.version)
python -m pip install %ONNXRT_PATH%
displayName: 'Install onnxruntime'
- script: |
call activate py$(python.version)
python -m pip install scikit-learn$(sklearn.version)
python -m pip show pytest
displayName: 'Install dependencies'
displayName: 'Install scikit-learn'
- script: |
call activate py$(python.version)
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
-f https://download.pytorch.org/whl/torch_stable.html
catboost
codecov
coremltools
cython
dill
flake8
Expand Down
19 changes: 17 additions & 2 deletions tests/coreml/test_cml_DictVectorizerConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"""
Tests CoreML DictVectorizer converter.
"""
import sys
from distutils.version import StrictVersion
import unittest
import onnx
import sklearn
try:
from sklearn.impute import SimpleImputer as Imputer
import sklearn.preprocessing
Expand All @@ -12,19 +17,29 @@
except ImportError:
from sklearn.preprocessing import Imputer
import coremltools
import unittest
from sklearn.feature_extraction import DictVectorizer
from onnxmltools.convert.coreml.convert import convert
from onnxmltools.utils import dump_data_and_model


class TestCoreMLDictVectorizerConverter(unittest.TestCase):

@unittest.skipIf(
StrictVersion(coremltools.__version__) > StrictVersion("3.1"),
reason="untested")
def test_dict_vectorizer(self):
model = DictVectorizer()
data = [{'amy': 1., 'chin': 200.}, {'nice': 3., 'amy': 1.}]
model.fit_transform(data)
model_coreml = coremltools.converters.sklearn.convert(model)
try:
model_coreml = coremltools.converters.sklearn.convert(model)
except NameError as e:
raise AssertionError(
"Unable to use coremltools, coremltools.__version__=%r, "
"onnx.__version__=%r, sklearn.__version__=%r, "
"sys.platform=%r." % (
coremltools.__version__, onnx.__version__,
sklearn.__version__, sys.platform)) from e
model_onnx = convert(model_coreml.get_spec())
self.assertTrue(model_onnx is not None)
dump_data_and_model(data, model, model_onnx, basename="CmlDictVectorizer-OneOff-SkipDim1",
Expand Down
4 changes: 4 additions & 0 deletions tests/coreml/test_cml_GLMClassifierConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Tests CoreML GLMClassifier converter.
"""
import unittest
from distutils.version import StrictVersion
import numpy
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
Expand Down Expand Up @@ -31,6 +32,9 @@ def validate_zipmap(self, model):
self.assertEqual(len(node.output), 1)
self.assertTrue('classProbability' in node.output)

@unittest.skipIf(
StrictVersion(coremltools.__version__) > StrictVersion("3.1"),
reason="untested")
def test_glm_classifier(self):
iris = load_iris()
X = iris.data[:, :2]
Expand Down
4 changes: 4 additions & 0 deletions tests/coreml/test_cml_GLMRegressorConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Tests CoreML GLMRegressor converter.
"""
import unittest
from distutils.version import StrictVersion
import numpy
try:
from sklearn.impute import SimpleImputer as Imputer
Expand All @@ -23,6 +24,9 @@

class TestCoreMLGLMRegressorConverter(unittest.TestCase):

@unittest.skipIf(
StrictVersion(coremltools.__version__) > StrictVersion("3.1"),
reason="untested")
def test_glm_regressor(self):
X, y = make_regression(n_features=4, random_state=0)

Expand Down
7 changes: 6 additions & 1 deletion tests/coreml/test_cml_ImputerConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"""
Tests CoreML Imputer converter.
"""
import numpy as np
import unittest
from distutils.version import StrictVersion
import numpy as np
try:
from sklearn.impute import SimpleImputer as Imputer
import sklearn.preprocessing
Expand All @@ -14,11 +15,15 @@
except ImportError:
from sklearn.preprocessing import Imputer
import sklearn.preprocessing
import coremltools
from onnxmltools.utils import dump_data_and_model


class TestCoreMLImputerConverter(unittest.TestCase):

@unittest.skipIf(
StrictVersion(coremltools.__version__) > StrictVersion("3.1"),
reason="untested")
def test_imputer(self):
try:
model = Imputer(missing_values='NaN', strategy='mean', axis=0)
Expand Down
6 changes: 6 additions & 0 deletions tests/coreml/test_cml_OneHotEncoderConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
"""
Main functions to convert machine learned model from *Core ML* model to *ONNX*.
"""
import sys
import os
import unittest
import warnings
from distutils.version import StrictVersion
import numpy
import onnx
try:
from sklearn.impute import SimpleImputer as Imputer
import sklearn.preprocessing
Expand All @@ -23,6 +26,9 @@

class TestCoremlOneHotEncoderConverter(unittest.TestCase):

@unittest.skipIf(
StrictVersion(coremltools.__version__) > StrictVersion("3.1"),
reason="untested")
def test_one_hot_encoder(self):
script_dir = os.path.dirname(__file__)
relative_path = "../data/onehot_simple.mlmodel"
Expand Down
4 changes: 4 additions & 0 deletions tests/coreml/test_cml_ScalerConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Tests CoreML Scaler converter.
"""
import unittest
from distutils.version import StrictVersion
import numpy
try:
from sklearn.impute import SimpleImputer as Imputer
Expand All @@ -21,6 +22,9 @@

class TestCoreMLScalerConverter(unittest.TestCase):

@unittest.skipIf(
StrictVersion(coremltools.__version__) > StrictVersion("3.1"),
reason="untested")
def test_scaler(self):
model = StandardScaler()
data = numpy.array([[0, 0, 3], [1, 1, 0], [0, 2, 1], [1, 0, 2]], dtype=numpy.float32)
Expand Down
13 changes: 13 additions & 0 deletions tests/coreml/test_cml_SupportVectorClassifierConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
Tests CoreML SupportVectorClassifier converter.
"""
from distutils.version import StrictVersion
try:
from sklearn.impute import SimpleImputer as Imputer
import sklearn.preprocessing
Expand Down Expand Up @@ -59,6 +60,9 @@ def validate_zipmap(self, model):
self.assertEqual(len(node.output), 1)
self.assertTrue('classProbability' in node.output)

@unittest.skipIf(
StrictVersion(coremltools.__version__) > StrictVersion("3.1"),
reason="untested")
def test_support_vector_classifier_binary_no_prob(self):
svm, X = self._fit_binary_classification(SVC(gamma=0.5))
svm_coreml = coremltools.converters.sklearn.convert(svm)
Expand All @@ -71,6 +75,9 @@ def test_support_vector_classifier_binary_no_prob(self):
dump_data_and_model(X, svm, svm_onnx, basename="CmlBinSVC-Out0",
allow_failure=True)

@unittest.skipIf(
StrictVersion(coremltools.__version__) > StrictVersion("3.1"),
reason="untested")
def test_support_vector_classifier_binary_with_prob(self):
svm, X = self._fit_binary_classification(SVC(probability=True, gamma=0.5))
svm_coreml = coremltools.converters.sklearn.convert(svm)
Expand All @@ -79,6 +86,9 @@ def test_support_vector_classifier_binary_with_prob(self):
self.validate_zipmap(svm_onnx)
self._check_model_outputs(svm_onnx, ['classLabel', 'classProbability'])

@unittest.skipIf(
StrictVersion(coremltools.__version__) > StrictVersion("3.1"),
reason="untested")
def test_support_vector_classifier_multiclass_no_prob(self):
svm, X = self._fit_multi_classification(SVC(gamma=0.5))
svm_coreml = coremltools.converters.sklearn.convert(svm)
Expand All @@ -88,6 +98,9 @@ def test_support_vector_classifier_multiclass_no_prob(self):
self.assertEqual(len(nodes), 1)
self._check_model_outputs(svm_onnx, ['classLabel'])

@unittest.skipIf(
StrictVersion(coremltools.__version__) > StrictVersion("3.1"),
reason="untested")
def test_support_vector_classifier_multiclass_with_prob(self):
svm, X = self._fit_multi_classification(SVC(probability=True, gamma=0.5))
svm_coreml = coremltools.converters.sklearn.convert(svm)
Expand Down
4 changes: 4 additions & 0 deletions tests/coreml/test_cml_SupportVectorRegressorConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
Tests SupportVectorRegressor converter.
"""
from distutils.version import StrictVersion
try:
from sklearn.impute import SimpleImputer as Imputer
import sklearn.preprocessing
Expand All @@ -22,6 +23,9 @@

class TestCoreMLSupportVectorRegressorConverter(unittest.TestCase):

@unittest.skipIf(
StrictVersion(coremltools.__version__) > StrictVersion("3.1"),
reason="untested")
def test_support_vector_regressor(self):
X, y = make_regression(n_features=4, random_state=0)

Expand Down
4 changes: 4 additions & 0 deletions tests/coreml/test_cml_TreeEnsembleClassifierConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Tests CoreML TreeEnsembleClassifier converter.
"""
import unittest
from distutils.version import StrictVersion
import numpy
try:
from sklearn.impute import SimpleImputer as Imputer
Expand All @@ -29,6 +30,9 @@ def validate_zipmap(self, model):
self.assertEqual(len(node.output), 1)
self.assertTrue('classProbability' in node.output)

@unittest.skipIf(
StrictVersion(coremltools.__version__) > StrictVersion("3.1"),
reason="untested")
def test_tree_ensemble_classifier(self):
X = numpy.array([[0, 1], [1, 1], [2, 0]], dtype=numpy.float32)
y = [1, 0, 1]
Expand Down
4 changes: 4 additions & 0 deletions tests/coreml/test_cml_TreeEnsembleRegressorConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Tests CoreML TreeEnsembleRegressor converter.
"""
import unittest
from distutils.version import StrictVersion
import numpy
try:
from sklearn.impute import SimpleImputer as Imputer
Expand All @@ -22,6 +23,9 @@

class TestCoreMLTreeEnsembleRegressorConverter(unittest.TestCase):

@unittest.skipIf(
StrictVersion(coremltools.__version__) > StrictVersion("3.1"),
reason="untested")
def test_tree_ensemble_regressor(self):
X, y = make_regression(n_features=4, random_state=0)
model = RandomForestRegressor().fit(X, y)
Expand Down
3 changes: 1 addition & 2 deletions tests/lightgbm/test_lightgbm_tree_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import unittest
import copy
from onnxmltools.convert.lightgbm.operator_converters.LightGbm import (
modify_tree_for_rule_in_set
)
modify_tree_for_rule_in_set)


def count_nodes(tree, done=None):
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 @@ -15,7 +15,7 @@
_N_ROWS=10_000
_N_COLS=10
_N_DECIMALS=5
_FRAC = 0.9999
_FRAC = 0.9997

_X = pd.DataFrame(np.random.random(size=(_N_ROWS, _N_COLS)))
_Y = pd.Series(np.random.random(size=_N_ROWS))
Expand Down

0 comments on commit 3d81a0a

Please sign in to comment.