Skip to content

Commit

Permalink
Add self-hosted M1 Mac runner (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterJH5574 authored Jun 21, 2023
1 parent 2e3e759 commit 290724f
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 41 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/llm_conda_nightly_apple_silicon_mac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# GH actions.
name: MLC-Chat-CLI-Conda-Nightly-Apple-Silicon-Mac

on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: '0 8 * * *' # 8 AM UTC -> 4 AM EDT


jobs:
Build:
strategy:
matrix:
pkg: ['mlc-chat-cli-nightly']
sys:
- conda_pkg_path: osx-arm64
shell: 'bash -l {0}'

runs-on: [self-hosted, macOS, ARM64]
defaults:
run:
shell: ${{ matrix.sys.shell }}

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Build Conda
env:
CONDA_HOME: ${{ secrets.M1_MAC_CONDA_HOME }}
run: |
scripts/build_mlc_chat_cli_conda_apple_silicon.sh
- name: Conda-Deploy
if: github.ref == 'refs/heads/main'
env:
ANACONDA_API_TOKEN: ${{ secrets.MLC_ANACONDA_TOKEN }}
run: >-
anaconda upload --force --label main conda/pkg/${{ matrix.sys.conda_pkg_path }}/*.tar.bz2
85 changes: 85 additions & 0 deletions .github/workflows/wheel_applesiliconmac_nightly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# GH actions.
name: Wheel-AppleSiliconMac-Nightly

on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: '0 8 * * *' # 8 AM UTC -> 4 AM EDT

jobs:
Build:
runs-on: [self-hosted, macOS, ARM64]
defaults:
run:
shell: 'bash -l {0}'

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Setup script env
run: |
mv conda/tvm-unity/build-environment.yaml 3rdparty/tlcpack/conda/build-environment.yaml
rm -rf conda
ln -s 3rdparty/tlcpack/conda conda
- name: Checkout source
run: |
git clone https://github.com/mlc-ai/relax tvm --recursive --single-branch --branch mlc
git clone https://github.com/mlc-ai/mlc-llm mlc-llm --recursive --single-branch --branch main
- name: Build mlc-ai @ 3.8
env:
CONDA_HOME: ${{ secrets.M1_MAC_CONDA_HOME }}
run: |
scripts/build_mlc_ai_wheel_single_python_apple_silicon.sh wheel-3-8
- name: Build mlc-ai @ 3.9
env:
CONDA_HOME: ${{ secrets.M1_MAC_CONDA_HOME }}
run: |
scripts/build_mlc_ai_wheel_single_python_apple_silicon.sh wheel-3-9
- name: Build mlc-ai @ 3.10
env:
CONDA_HOME: ${{ secrets.M1_MAC_CONDA_HOME }}
run: |
scripts/build_mlc_ai_wheel_single_python_apple_silicon.sh wheel-3-10
- name: Build mlc-ai @ 3.11
env:
CONDA_HOME: ${{ secrets.M1_MAC_CONDA_HOME }}
run: |
scripts/build_mlc_ai_wheel_single_python_apple_silicon.sh wheel-3-11
- name: Build mlc-chat @ 3.8
env:
CONDA_HOME: ${{ secrets.M1_MAC_CONDA_HOME }}
run: |
scripts/build_mlc_chat_wheel_single_python_apple_silicon.sh wheel-3-8
- name: Build mlc-chat @ 3.9
env:
CONDA_HOME: ${{ secrets.M1_MAC_CONDA_HOME }}
run: |
scripts/build_mlc_chat_wheel_single_python_apple_silicon.sh wheel-3-9
- name: Build mlc-chat @ 3.10
env:
CONDA_HOME: ${{ secrets.M1_MAC_CONDA_HOME }}
run: |
scripts/build_mlc_chat_wheel_single_python_apple_silicon.sh wheel-3-10
- name: Build mlc-chat @ 3.11
env:
CONDA_HOME: ${{ secrets.M1_MAC_CONDA_HOME }}
run: |
scripts/build_mlc_chat_wheel_single_python_apple_silicon.sh wheel-3-11
# Use system python instead of conda for upload
- name: Wheel-Deploy
if: github.ref == 'refs/heads/main'
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.MLC_GITHUB_TOKEN }}
with:
files: |
tvm/python/dist/*.whl
mlc-llm/python/dist/*.whl
tag_name: v0.9.dev0
prerelease: true
23 changes: 5 additions & 18 deletions scripts/build_mlc_ai_wheel_apple_silicon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,12 @@ eval "$(command conda 'shell.bash' 'hook' 2> /dev/null)"
# - install dependencies in https://github.com/tlc-pack/tlcpack/blob/main/conda/build-environment.yaml for these env.
declare -a conda_env_names=("wheel-3-8" "wheel-3-9" "wheel-3-10" "wheel-3-11")

export GITHUB_TOKEN=$1
export DEPLOY_WHEEL=1

# cleanup and clone tvm mlc
rm -rf tvm && git clone https://github.com/mlc-ai/relax tvm --recursive --single-branch --branch mlc

for name in "${conda_env_names[@]}"
do
echo "Start build for $name"

# conda activate
conda activate $name

# cleanup and clone tvm mlc
rm -rf tvm && git clone https://github.com/mlc-ai/relax tvm --recursive --single-branch --branch mlc
# sync package
python scripts/sync_package.py --package tvm --package-name mlc-ai-nightly --revision origin/mlc
# build tvm
./scripts/build_mlc_ai_lib_apple_silicon.sh

# build wheel
cd tvm/python && python setup.py bdist_wheel && cd -

# deploy wheel
python scripts/wheel_upload.py --repo mlc-ai/package --tag v0.9.dev0 tvm/python/dist
./scripts/build_mlc_ai_wheel_single_python_apple_silicon.sh $name
done
27 changes: 27 additions & 0 deletions scripts/build_mlc_ai_wheel_single_python_apple_silicon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
set -euxo pipefail

eval "$(command conda 'shell.bash' 'hook' 2> /dev/null)"

CONDA_ENV_NAME=$1
deploy="${DEPLOY_WHEEL:-0}"

source $CONDA_HOME/etc/profile.d/conda.sh

echo "Start build for $CONDA_ENV_NAME"

# conda activate
conda activate $CONDA_ENV_NAME

# sync package
python scripts/sync_package.py --package tvm --package-name mlc-ai-nightly --revision origin/mlc --skip-checkout --skip-conda
# build tvm
./scripts/build_mlc_ai_lib_apple_silicon.sh

# build wheel
cd tvm/python && python setup.py bdist_wheel && cd -

# deploy wheel
if [ "$deploy" -eq "1" ]; then
python scripts/wheel_upload.py --repo mlc-ai/package --tag v0.9.dev0 tvm/python/dist
fi
15 changes: 10 additions & 5 deletions scripts/build_mlc_chat_cli_conda_apple_silicon.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
set -e
set -u
#!/bin/bash
set -euxo pipefail

PKG="mlc-chat-nightly"
PKG="mlc-chat-cli-nightly"
CONDA_ENV_NAME="mlc-llm-build"
export CONDA_PKG_PATH="osx-arm64"
deploy="${DEPLOY_WHEEL:-0}"

rm -rf mlc-llm
git clone git@github.com:mlc-ai/mlc-llm.git mlc-llm --recursive
git clone https://github.com/mlc-ai/mlc-llm.git mlc-llm --recursive

python3 scripts/sync_package.py --package mlc-llm --package-name $PKG

source "$CONDA_HOME/etc/profile.d/conda.sh"
conda deactivate
conda env remove -n ${CONDA_ENV_NAME}
conda env create --file conda/mlc-llm/osx-build-environment.yaml
conda activate ${CONDA_ENV_NAME}
conda build -c conda-forge --output-folder=conda/pkg -m conda/mlc-llm/build_config.yaml conda/mlc-llm/recipe
anaconda upload -u mlc-ai --force --label main conda/pkg/${CONDA_PKG_PATH}/*.tar.bz2

if [ "$deploy" -eq "1" ]; then
anaconda upload -u mlc-ai --force --label main conda/pkg/${CONDA_PKG_PATH}/*.tar.bz2
fi
23 changes: 5 additions & 18 deletions scripts/build_mlc_chat_wheel_apple_silicon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,12 @@ eval "$(command conda 'shell.bash' 'hook' 2> /dev/null)"
# - install dependencies in https://github.com/tlc-pack/tlcpack/blob/main/conda/build-environment.yaml for these env.
declare -a conda_env_names=("wheel-3-8" "wheel-3-9" "wheel-3-10" "wheel-3-11")

export GITHUB_TOKEN=$1
export DEPLOY_WHEEL=1

# cleanup and clone mlc-llm
rm -rf mlc-llm && git clone https://github.com/mlc-ai/mlc-llm mlc-llm --recursive --single-branch --branch main

for name in "${conda_env_names[@]}"
do
echo "Start build for $name"

# conda activate
conda activate $name

# cleanup and clone mlc-llm
rm -rf mlc-llm && git clone https://github.com/mlc-ai/mlc-llm mlc-llm --recursive --single-branch --branch main
# sync package
python scripts/sync_package.py --package mlc-llm --package-name mlc-chat-nightly --revision origin/main
# build mlc-llm
./scripts/build_mlc_chat_lib_apple_silicon.sh

# build wheel
cd mlc-llm/python && python setup.py bdist_wheel && cd -

# deploy wheel
python scripts/wheel_upload.py --repo mlc-ai/package --tag v0.9.dev0 mlc-llm/python/dist
./scripts/build_mlc_chat_wheel_single_python_apple_silicon.sh $name
done
27 changes: 27 additions & 0 deletions scripts/build_mlc_chat_wheel_single_python_apple_silicon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
set -euxo pipefail

eval "$(command conda 'shell.bash' 'hook' 2> /dev/null)"

CONDA_ENV_NAME=$1
deploy="${DEPLOY_WHEEL:-0}"

source $CONDA_HOME/etc/profile.d/conda.sh

echo "Start build for $CONDA_ENV_NAME"

# conda activate
conda activate $CONDA_ENV_NAME

# sync package
python scripts/sync_package.py --package mlc-llm --package-name mlc-chat-nightly --revision origin/main --skip-checkout --skip-conda
# build mlc-llm
./scripts/build_mlc_chat_lib_apple_silicon.sh

# build wheel
cd mlc-llm/python && python setup.py bdist_wheel && cd -

# deploy wheel
if [ "$deploy" -eq "1" ]; then
python scripts/wheel_upload.py --repo mlc-ai/package --tag v0.9.dev0 mlc-llm/python/dist
fi

0 comments on commit 290724f

Please sign in to comment.