Build LibTorch #38
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
workflow_dispatch: | |
inputs: | |
branch: | |
type: string | |
description: The name of the branch you want to build. | |
required: true | |
for_r: | |
type: string | |
required: true | |
description: Wether to build with opinionated options for R. | |
release_name: | |
type: string | |
required: false | |
default: "" | |
description: The release name to output to. | |
name: Build LibTorch | |
jobs: | |
build: | |
runs-on: ['self-hosted', 'm1'] | |
timeout-minutes: 120 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Toggle R specific options | |
id: options | |
run: | | |
if ${{ github.event.inputs.for_r }} | |
then | |
echo "::set-output name=tag_name::LibTorch-for-R" | |
echo "::set-output name=cmake::-DBUILD_PYTHON=OFF -DUSE_OPENMP=OFF -DUSE_KINETO=OFF" | |
else | |
echo "::set-output name=tag_name::LibTorch${{ github.event.inputs.release_name }}" | |
echo "::set-output name=cmake:: " | |
fi | |
- name: Clone | |
run: | | |
git clone -b ${{ github.event.inputs.branch }} --recurse-submodule https://github.com/pytorch/pytorch.git | |
- name: Apply patch | |
if: ${{ github.event.inputs.for_r == 'true' }} | |
run: | | |
ls | |
cd pytorch | |
git apply ../patch/MPSAllocator-${{ github.event.inputs.branch }}.patch || true | |
- name: Build Libtorch | |
run: | | |
mkdir pytorch-build | |
cd pytorch-build | |
cmake \ | |
-DBUILD_SHARED_LIBS:BOOL=ON \ | |
-DCMAKE_BUILD_TYPE:STRING=Release \ | |
-DPYTHON_EXECUTABLE:PATH=/Users/dfalbel/opt/miniconda3/bin/python3 \ | |
${{ steps.options.outputs.cmake }} \ | |
-DCMAKE_INSTALL_PREFIX:PATH=../libtorch \ | |
-DUSE_MPS=ON \ | |
../pytorch | |
cmake --build . --target install --parallel 8 | |
# See https://discuss.pytorch.org/t/precompiled-libtorch-for-apple-silicon/162635/7 | |
- name: Copy libomp.dylib | |
if: ${{ github.event.inputs.for_r != 'true' }} | |
run: | | |
cp /opt/homebrew/lib/libomp.dylib libtorch/lib/libomp.dylib | |
- name: Patch search path | |
if: ${{ github.event.inputs.release_name == 'OpenMP' }} | |
run: | | |
install_name_tool -change /opt/homebrew/opt/libomp/lib/libomp.dylib @rpath/libomp.dylib libtorch/lib/libtorch_cpu.dylib | |
- name: Create archive | |
run: | | |
zip -r libtorch-${{ github.event.inputs.branch }}.zip libtorch/ | |
- uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: libtorch-${{ github.event.inputs.branch }}.zip | |
overwrite: true | |
file_glob: true | |
tag: ${{ steps.options.outputs.tag_name }} | |