deprecate torch1.7, push to macOS11 (#594)
This commit is contained in:
Родитель
833447520f
Коммит
a4aaabf0ee
|
@ -18,7 +18,7 @@ jobs:
|
|||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-18.04, macos-10.15, windows-2019]
|
||||
os: [ubuntu-18.04, macos-11, windows-2019]
|
||||
python-version: [3.8, 3.9]
|
||||
|
||||
steps:
|
||||
|
@ -36,19 +36,11 @@ jobs:
|
|||
# The GitHub editor is 127 chars wide
|
||||
flake8 . --count --max-complexity=10 --max-line-length=127 --statistics
|
||||
# PyTorch for Mac has different pip syntax wrt Win and Linux.
|
||||
# We want to test torch 1.6.0 (in this case on python3.7) and torch 1.11.x.
|
||||
# The following cases address the situations above.
|
||||
- name: Install pytorch 1.6.0 if python 3.7 (mac)
|
||||
if: ${{ matrix.python-version == '3.7' && matrix.os == 'macos-10.15' }}
|
||||
run: pip install torch==1.6.0
|
||||
- name: Install pytorch 1.11.0 if python > 3.7 (mac)
|
||||
if: ${{ matrix.python-version != '3.7' && matrix.os == 'macos-10.15' }}
|
||||
- name: Install pytorch 1.11.0 if mac
|
||||
if: ${{ matrix.os == 'macos-11' }}
|
||||
run: pip install torch==1.11.0
|
||||
- name: Install pytorch 1.6.0+cpu if python 3.7 (not mac)
|
||||
if: ${{ matrix.python-version == '3.7' && matrix.os != 'macos-10.15' }}
|
||||
run: pip install torch==1.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
|
||||
- name: Install pytorch 1.11.0+cpu if python > 3.7 (not mac)
|
||||
if: ${{ matrix.python-version != '3.7' && matrix.os != 'macos-10.15' }}
|
||||
- name: Install pytorch 1.11.0+cpu if not mac
|
||||
if: ${{ matrix.os != 'macos-11' }}
|
||||
run: pip install torch==1.11.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
|
||||
- name: Install basic dependencies
|
||||
run: |
|
||||
|
@ -58,7 +50,7 @@ jobs:
|
|||
- name: Coverage on basic tests without extra
|
||||
run: coverage run -a -m pytest tests/test_no_extra_install.py
|
||||
- name: If mac, install libomp to facilitate lgbm install
|
||||
if: matrix.os == 'macos-10.15'
|
||||
if: matrix.os == 'macos-11'
|
||||
run: |
|
||||
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/fb8323f2b170bd4ae97e1bac9bf3e2983af3fdb0/Formula/libomp.rb
|
||||
brew unlink libomp
|
||||
|
@ -97,19 +89,19 @@ jobs:
|
|||
git submodule update --recursive --init
|
||||
cmake -E make_directory build
|
||||
- name: Get LLVM on Linux
|
||||
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.python-version != '3.7' && matrix.os == 'ubuntu-18.04' }}
|
||||
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.os == 'ubuntu-18.04' }}
|
||||
working-directory: ../../../tvm
|
||||
run: |
|
||||
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz
|
||||
tar -xf clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz && mv clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04 llvm
|
||||
- name: Get LLVM on Mac
|
||||
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.python-version != '3.7' && matrix.os == 'macos-10.15' }}
|
||||
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.os == 'macos-11' }}
|
||||
working-directory: ../../../tvm
|
||||
run: |
|
||||
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-apple-darwin.tar.xz
|
||||
tar -xf clang+llvm-10.0.0-x86_64-apple-darwin.tar.xz && mv clang+llvm-10.0.0-x86_64-apple-darwin llvm
|
||||
- name: CMake TVM
|
||||
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.python-version != '3.7' && matrix.os != 'windows-2019' }}
|
||||
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.os != 'windows-2019' }}
|
||||
working-directory: ../../../tvm/build
|
||||
run: >-
|
||||
cmake
|
||||
|
@ -118,51 +110,40 @@ jobs:
|
|||
"-DUSE_LLVM=../llvm/bin/llvm-config"
|
||||
..
|
||||
- name: Build TVM
|
||||
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.python-version != '3.7' && matrix.os != 'windows-2019' }}
|
||||
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.os != 'windows-2019' }}
|
||||
working-directory: ../../../tvm/build
|
||||
run: |
|
||||
make -j3
|
||||
- name: Install python TVM
|
||||
if: ${{ matrix.python-version != '3.7' && matrix.os != 'windows-2019' }}
|
||||
if: ${{ matrix.os != 'windows-2019' }}
|
||||
working-directory: ../../../tvm/python
|
||||
run: |
|
||||
python setup.py install
|
||||
- name: pip list
|
||||
run: pip list
|
||||
# We don't run pytest for Linux py3.7 since we do coverage for that case.
|
||||
# We don't run pytest for Linux py3.8 since we do coverage for that case.
|
||||
- name: Test with pytest
|
||||
if: ${{ matrix.python-version != '3.7' || matrix.os != 'ubuntu-18.04' }}
|
||||
if: ${{ matrix.python-version != '3.8' || matrix.os != 'ubuntu-18.04' }}
|
||||
run: pytest
|
||||
# Run and push coverage only for two runs (Linux py3.7 and py3.8).
|
||||
- name: Coverage 3.7 Linux
|
||||
if: ${{ matrix.python-version == '3.7' && matrix.os == 'ubuntu-18.04' }}
|
||||
run: |
|
||||
coverage run -a -m pytest tests
|
||||
coverage xml
|
||||
# Run and push coverage only for Linux py3.8
|
||||
- name: Coverage 3.8 Linux
|
||||
if: ${{ matrix.python-version == '3.8' && matrix.os == 'ubuntu-18.04' }}
|
||||
run: |
|
||||
coverage run -a -m pytest tests
|
||||
coverage xml
|
||||
- name: Upload coverage to Codecov 3.7
|
||||
if: ${{ matrix.python-version == '3.7' && matrix.os == 'ubuntu-18.04' }}
|
||||
uses: codecov/codecov-action@v1
|
||||
with:
|
||||
file: ./coverage.xml
|
||||
flags: unittests
|
||||
- name: Upload coverage to Codecov 8
|
||||
- name: Upload coverage to Codecov
|
||||
if: ${{ matrix.python-version == '3.8' && matrix.os == 'ubuntu-18.04' }}
|
||||
uses: codecov/codecov-action@v1
|
||||
with:
|
||||
file: ./coverage.xml
|
||||
flags: unittests
|
||||
# Compile and push documentation only for one of the runs (Linux py3.7).
|
||||
# Compile and push documentation only for one of the runs (Linux py3.8).
|
||||
- name: Generate Documentation
|
||||
if: ${{ matrix.python-version == '3.7' && matrix.os == 'ubuntu-18.04' }}
|
||||
if: ${{ matrix.python-version == '3.8' && matrix.os == 'ubuntu-18.04' }}
|
||||
run: |
|
||||
make sphinx-site -C website/
|
||||
- name: Deploy to GitHub pages 🚀
|
||||
if: ${{ github.ref == 'refs/heads/main' && matrix.python-version == '3.7' && matrix.os == 'ubuntu-18.04' }}
|
||||
if: ${{ github.ref == 'refs/heads/main' && matrix.python-version == '3.9' && matrix.os == 'ubuntu-18.04' }}
|
||||
uses: JamesIves/github-pages-deploy-action@4.0.0
|
||||
with:
|
||||
branch: gh-pages
|
||||
|
|
|
@ -25,6 +25,9 @@ def torch_installed():
|
|||
"""
|
||||
try:
|
||||
import torch
|
||||
assert (
|
||||
LooseVersion(torch.__version__) > LooseVersion("1.7.0")
|
||||
), "Please install torch >1.7.0"
|
||||
|
||||
return True
|
||||
except ImportError:
|
||||
|
@ -32,7 +35,7 @@ def torch_installed():
|
|||
|
||||
|
||||
def assert_torch_installed():
|
||||
assert torch_installed(), "To use Hummingbird you need to install torch."
|
||||
assert torch_installed(), "To use Hummingbird you need to install torch>1.7.0."
|
||||
|
||||
|
||||
def onnx_ml_tools_installed():
|
||||
|
|
|
@ -52,15 +52,7 @@ def convert_gbdt_classifier_common(
|
|||
n_classes -= 1
|
||||
if classes is None:
|
||||
classes = [i for i in range(n_classes)]
|
||||
# There is a bug in torch < 1.7.0 that causes a mismatch. See Issue #10
|
||||
if n_classes > 2:
|
||||
from distutils.version import LooseVersion
|
||||
import torch
|
||||
|
||||
if LooseVersion(torch.__version__) < LooseVersion("1.7.0"):
|
||||
import warnings
|
||||
|
||||
warnings.warn("torch < 1.7.0 may give a mismatch on multiclass. See issue #10.")
|
||||
reorder_trees = True
|
||||
if constants.REORDER_TREES in extra_config:
|
||||
reorder_trees = extra_config[constants.REORDER_TREES]
|
||||
|
|
|
@ -35,16 +35,6 @@ def convert_sklearn_random_forest_classifier(operator, device, extra_config):
|
|||
n_features = operator.raw_operator.n_features_
|
||||
classes = operator.raw_operator.classes_.tolist()
|
||||
|
||||
# There is a bug in torch < 1.7.0 that causes a mismatch. See Issue #10
|
||||
if len(classes) > 2:
|
||||
from distutils.version import LooseVersion
|
||||
import torch
|
||||
|
||||
if LooseVersion(torch.__version__) < LooseVersion("1.7.0"):
|
||||
import warnings
|
||||
|
||||
warnings.warn("torch < 1.7.0 may give a mismatch on multiclass. See issue #10.")
|
||||
|
||||
# For Sklearn Trees we need to know how many trees are there for normalization.
|
||||
extra_config[constants.NUM_TREES] = len(tree_infos)
|
||||
|
||||
|
|
|
@ -32,15 +32,6 @@ def convert_sklearn_linear_model(operator, device, extra_config):
|
|||
|
||||
supported_loss = {"log", "modified_huber", "squared_hinge"}
|
||||
classes = [0] if not hasattr(operator.raw_operator, "classes_") else operator.raw_operator.classes_
|
||||
# There is a bug in torch < 1.7.0 that causes a mismatch. See Issue #10
|
||||
if len(classes) > 2:
|
||||
from distutils.version import LooseVersion
|
||||
import torch
|
||||
|
||||
if LooseVersion(torch.__version__) < LooseVersion("1.7.0"):
|
||||
import warnings
|
||||
|
||||
warnings.warn("torch < 1.7.0 may give a mismatch on multiclass. See issue #10.")
|
||||
|
||||
if not all(["int" in str(type(x)) for x in classes]):
|
||||
raise RuntimeError(
|
||||
|
|
|
@ -30,16 +30,6 @@ def convert_sklearn_mlp_classifier(operator, device, extra_config):
|
|||
assert operator is not None, "Cannot convert None operator"
|
||||
|
||||
classes = operator.raw_operator.classes_
|
||||
# There is a bug in torch < 1.7.0 that causes a mismatch. See Issue #10
|
||||
if len(classes) > 2:
|
||||
from distutils.version import LooseVersion
|
||||
import torch
|
||||
|
||||
if LooseVersion(torch.__version__) < LooseVersion("1.7.0"):
|
||||
import warnings
|
||||
|
||||
warnings.warn("torch < 1.7.0 may give a mismatch on multiclass. See issue #10.")
|
||||
|
||||
if not all([type(x) in [int, np.int32, np.int64] for x in classes]):
|
||||
raise RuntimeError("Hummingbird supports only integer labels for class labels.")
|
||||
|
||||
|
|
4
setup.py
4
setup.py
|
@ -26,7 +26,7 @@ install_requires = [
|
|||
"onnxconverter-common>=1.6.0",
|
||||
"scipy",
|
||||
"scikit-learn",
|
||||
"torch>=1.4",
|
||||
"torch>1.7.0",
|
||||
"psutil",
|
||||
"dill",
|
||||
"protobuf>=3.20.0,<=3.20.1",
|
||||
|
@ -69,5 +69,5 @@ setup(
|
|||
"Operating System :: OS Independent",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
],
|
||||
python_requires=">=3.6",
|
||||
python_requires=">=3.8",
|
||||
)
|
||||
|
|
|
@ -54,9 +54,6 @@ class TestProphet(unittest.TestCase):
|
|||
@unittest.skipIf(
|
||||
not (pandas_installed() and prophet_installed()), reason="Test requires Prophet, Pandas and ONNX runtime.",
|
||||
)
|
||||
@unittest.skipIf(
|
||||
LooseVersion(torch.__version__) < LooseVersion("1.8.1"), reason="Test requires Torch 1.8.1.",
|
||||
)
|
||||
@unittest.skipIf(
|
||||
not onnx_runtime_installed() or LooseVersion(onnxruntime.__version__) < LooseVersion("1.7.0"),
|
||||
reason="Prophet test requires onnxruntime => 1.7.0",
|
||||
|
|
|
@ -54,11 +54,7 @@ class TestSklearnTreeConverter(unittest.TestCase):
|
|||
self.assertIsNotNone(torch_model)
|
||||
np.testing.assert_allclose(model.predict_proba(X), torch_model.predict_proba(X), rtol=1e-06, atol=1e-06)
|
||||
|
||||
from distutils.version import LooseVersion
|
||||
import torch
|
||||
|
||||
if LooseVersion(torch.__version__) >= LooseVersion("1.7.0"):
|
||||
np.testing.assert_allclose(model.predict(X), torch_model.predict(X), rtol=1e-06, atol=1e-06)
|
||||
np.testing.assert_allclose(model.predict(X), torch_model.predict(X), rtol=1e-06, atol=1e-06)
|
||||
|
||||
# Random forest binary classifier
|
||||
def test_random_forest_classifier_binary_converter(self):
|
||||
|
|
|
@ -201,9 +201,6 @@ class TestSklearnLinearClassifiers(unittest.TestCase):
|
|||
self._test_sgd_classifier(3)
|
||||
|
||||
# SGDClassifier with modified huber loss
|
||||
@unittest.skipIf(
|
||||
LooseVersion(torch.__version__) < LooseVersion("1.7.0"), reason="Modified Huber loss test requires torch >= 1.7.0"
|
||||
)
|
||||
def test_modified_huber(self):
|
||||
X = np.array([[-0.5, -1], [-1, -1], [-0.1, -0.1], [0.1, -0.2], [0.5, 1], [1, 1], [0.1, 0.1], [-0.1, 0.2]])
|
||||
Y = np.array([1, 1, 1, 1, 2, 2, 2, 2])
|
||||
|
@ -217,9 +214,6 @@ class TestSklearnLinearClassifiers(unittest.TestCase):
|
|||
inputs = [[-1, -1], [1, 1], [-0.2, 0.1], [0.2, -0.1]]
|
||||
np.testing.assert_allclose(model.predict_proba(inputs), hb_model.predict_proba(inputs), rtol=1e-6, atol=1e-6)
|
||||
|
||||
@unittest.skipIf(
|
||||
LooseVersion(torch.__version__) < LooseVersion("1.7.0"), reason="Modified Huber loss test requires torch >= 1.7.0"
|
||||
)
|
||||
def test_modified_huber2(self):
|
||||
X = np.array([[-0.5, -1], [-1, -1], [-0.1, -0.1], [0.1, -0.2], [0.5, 1], [1, 1], [0.1, 0.1], [-0.1, 0.2]])
|
||||
Y = np.array([1, 1, 1, 1, 2, 2, 2, 2])
|
||||
|
@ -232,10 +226,6 @@ class TestSklearnLinearClassifiers(unittest.TestCase):
|
|||
|
||||
np.testing.assert_allclose(model.predict_proba(X), hb_model.predict_proba(X), rtol=1e-6, atol=1e-6)
|
||||
|
||||
# SGDClassifier with modified huber loss multiclass
|
||||
@unittest.skipIf(
|
||||
LooseVersion(torch.__version__) < LooseVersion("1.7.0"), reason="Modified Huber loss test requires torch >= 1.7.0"
|
||||
)
|
||||
def test_modified_huber_multi(self):
|
||||
X = np.array([[-0.5, -1], [-1, -1], [-0.1, -0.1], [0.1, -0.2], [0.5, 1], [1, 1], [0.1, 0.1], [-0.1, 0.2]])
|
||||
Y = np.array([0, 1, 1, 1, 2, 2, 2, 2])
|
||||
|
|
|
@ -24,6 +24,7 @@ clean-sphinx-site:
|
|||
sphinx-site: #clean-sphinx-site
|
||||
pip install sphinx sphinx_rtd_theme psutil
|
||||
# TODO: There is a bug with torch 1.6 causing a "has no attribute 'training')" error. Using 1.5 for now.
|
||||
# Update: there are even more bugs with newer versions. I'm not quite sure what to do.
|
||||
pip install torch==1.5.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
|
||||
sphinx-apidoc --private -o sphinx/api -t sphinx/_templates ../hummingbird -d 1 -f -e
|
||||
$(MAKE) -C sphinx
|
||||
|
|
Загрузка…
Ссылка в новой задаче