Skip to content

#235 Added Notebook Example for Torchscript #2349

#235 Added Notebook Example for Torchscript

#235 Added Notebook Example for Torchscript #2349

Workflow file for this run

# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Build
on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: "15 21 * * FRI"
permissions: read-all
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-24.04, macos-14, windows-2022]
python-version: ['3.9', '3.10', '3.11']
env:
TVM_VERSION_TAG: v0.17.0
PYTORCH_VERSION: 2.2.0
LLVM_VERSION: 18
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Lint with flake8
run: |
python -m pip install --upgrade pip
python -m pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# The GitHub editor is 127 chars wide
flake8 . --count --max-complexity=10 --max-line-length=127 --statistics
# PyTorch CPU for Linux has different pip syntax wrt Win and Mac.
- name: Install torch-${{ env.PYTORCH_VERSION }}+cpu if linux
if: ${{ startsWith(matrix.os, 'ubuntu') }}
run: python -m pip install torch==${{ env.PYTORCH_VERSION }} --extra-index-url https://download.pytorch.org/whl/cpu
- name: Install torch-${{ env.PYTORCH_VERSION }}+cpu if not linux
if: ${{ !startsWith(matrix.os, 'ubuntu') }}
run: python -m pip install torch==${{ env.PYTORCH_VERSION }}
- name: Install basic dependencies
run: |
python -m pip install -e .[tests] -f https://download.pytorch.org/whl/torch_stable.html
- name: Test with older SKLearn on Linux with py3.9 to check backward compatibility
if: ${{ matrix.python-version == '3.9' && startsWith(matrix.os, 'ubuntu') == true }}
run: python -m pip install scikit-learn==1.2.1 numpy==1.26.4
- name: Pin SKLearn<1.5.0 on not Linux with py3.9
if: ${{ !(matrix.python-version == '3.9' && startsWith(matrix.os, 'ubuntu') == true) }}
run: python -m pip install "scikit-learn<1.5.0" numpy==1.26.4
- name: Run basic tests without extra
run: pytest
- 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: ${{ startsWith(matrix.os, 'macos')}}
run: |
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/fb8323f2b170bd4ae97e1bac9bf3e2983af3fdb0/Formula/libomp.rb
brew install ./libomp.rb
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
export CPPFLAGS="$CPPFLAGS -Xpreprocessor -fopenmp"
export CFLAGS="$CFLAGS -I/usr/local/opt/libomp/include"
export CXXFLAGS="$CXXFLAGS -I/usr/local/opt/libomp/include"
export LDFLAGS="$LDFLAGS -Wl,-rpath,/usr/local/opt/libomp/lib -L/usr/local/opt/libomp/lib -lomp"
- name: Install extra dependencies
run: |
python -m pip install .[extra,onnx,sparkml]
python -m pip install pandas
- uses: actions/cache@v3
# TVM takes forever, we try to cache it.
if: ${{ startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')}}
id: cache
env:
CACHE_NUMBER: 13
with:
path: ~/work/hummingbird/tvm
key: ${{ matrix.os }}-python${{ matrix.python-version }}-tvm-${{ env.TVM_VERSION_TAG }}-${{ env.CACHE_NUMBER }}
# Getting TVM requires: 1) Install LLVM 2) fetching TVM from github, 3) cmake, 4) make, 5) install python dependency.
# 2 to 4 will be retrieved from the cache.
# The pipeline only works for Unix systems. For windows we will have to compile LLVM from source which is a no go.
- name: Install LLVM if Ubuntu
if: ${{ startsWith(matrix.os, 'ubuntu')}}
run: |
sudo apt install llvm-${{ env.LLVM_VERSION }}-dev libpolly-${{ env.LLVM_VERSION }}-dev
- name: Install LLVM if Mac
if: ${{ startsWith(matrix.os, 'macos')}}
run: |
brew install llvm@${{ env.LLVM_VERSION }}
- name: Fetch and prepare TVM for compilation if Ubuntu or Mac
if: ${{ steps.cache.outputs.cache-hit != 'true' && (startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')) }}
run: |
cd ~/work/hummingbird
git clone https://github.com/apache/tvm.git
cd tvm
git checkout tags/${{env.TVM_VERSION_TAG}}
git submodule update --recursive --init
cmake -E make_directory build
- name: CMake TVM if Ubuntu
if: ${{ steps.cache.outputs.cache-hit != 'true' && startsWith(matrix.os, 'ubuntu') }}
run: |
cd ~/work/hummingbird/tvm
cmake -S . -B build \
-DUSE_RPC=ON \
-DUSE_GRAPH_RUNTIME=ON \
-DUSE_LLVM="llvm-config-${{ env.LLVM_VERSION }} --link-static" \
-DHIDE_PRIVATE_SYMBOLS=ON
- name: CMake TVM if Mac
if: ${{ steps.cache.outputs.cache-hit != 'true' && startsWith(matrix.os, 'macos') }}
run: |
cd ~/work/hummingbird/tvm
cmake -S . -B build \
-DUSE_RPC=ON \
-DUSE_GRAPH_RUNTIME=ON \
-DUSE_LLVM="$(brew --prefix llvm@${{ env.LLVM_VERSION }})/bin/llvm-config --link-static" \
-DHIDE_PRIVATE_SYMBOLS=ON
- name: Build TVM if Ubuntu or Mac
if: ${{ steps.cache.outputs.cache-hit != 'true' && (startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')) }}
run: |
cd ~/work/hummingbird/tvm
cmake --build build
- name: Install python TVM if Ubuntu or Mac
if: ${{ (startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'ubuntu')) }}
run: |
cd ~/work/hummingbird/tvm/python
python3 -m pip install -e .
# We don't run pytest for ubuntu py3.9 since we do coverage for that case.
- name: Test with pytest
if: ${{ matrix.python-version != '3.9' || startsWith(matrix.os, 'ubuntu') != true }}
run: pytest
# Run and push coverage only for ubuntu py3.9
- name: Coverage 3.9 ubuntu
if: ${{ matrix.python-version == '3.9' && startsWith(matrix.os, 'ubuntu') }}
run: |
coverage run -a -m pytest tests
coverage xml
- name: Upload coverage to Codecov
if: ${{ matrix.python-version == '3.9' && startsWith(matrix.os, 'ubuntu') }}
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: unittests
page-build:
needs: build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04]
python-version: ['3.9']
permissions: # here we push documentation
actions: read
contents: write
if: github.ref == 'refs/heads/main' # only run this on main after PR merged
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Generate Documentation
run: |
# We're mocking out the torch. So now we also need to sub this on out
find ../. -type f -exec sed -i 's/{torch.__version__}/1.12.0/g' {} +
find ../. -type f -exec sed -i 's/torch.__version__/"1.12.0"/g' {} +
make sphinx-site -C website/
# now refresh the code
git checkout . && python -m pip install -e .[tests] -f https://download.pytorch.org/whl/torch_stable.html
- name: Deploy to GitHub pages 🚀
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: website/public