From 4639641ec3c54f785ccc7c60bc37f0b31ee0b3d2 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Thu, 6 Mar 2025 18:13:42 +0800 Subject: [PATCH] for linux arm64 --- .github/workflows/ubuntu-arm64-cpu-wheels.yml | 168 ++++++++++++++++++ .github/workflows/ubuntu-cuda-wheels.yml | 2 +- .../github_actions/build-ubuntu-cpu-arm64.sh | 49 +++++ .../github_actions/generate_build_matrix.py | 26 ++- 4 files changed, 239 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/ubuntu-arm64-cpu-wheels.yml create mode 100755 scripts/github_actions/build-ubuntu-cpu-arm64.sh diff --git a/.github/workflows/ubuntu-arm64-cpu-wheels.yml b/.github/workflows/ubuntu-arm64-cpu-wheels.yml new file mode 100644 index 0000000..38f3f00 --- /dev/null +++ b/.github/workflows/ubuntu-arm64-cpu-wheels.yml @@ -0,0 +1,168 @@ +name: build-wheels-cpu-arm64-ubuntu + +on: + push: + branches: + - fix-cuda-12.6 + tags: + - '*' + workflow_dispatch: + +concurrency: + group: build-wheels-cpu-arm64-ubuntu-${{ github.ref }} + cancel-in-progress: true + +jobs: + generate_build_matrix: + # see https://github.com/pytorch/pytorch/pull/50633 + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Generating build matrix + id: set-matrix + run: | + # outputting for debugging purposes + # python ./scripts/github_actions/generate_build_matrix.py --for-arm64 + # MATRIX=$(python ./scripts/github_actions/generate_build_matrix.py --for-arm64) + + python ./scripts/github_actions/generate_build_matrix.py --test-only-latest-torch --for-arm64 + MATRIX=$(python ./scripts/github_actions/generate_build_matrix.py --test-only-latest-torch --for-arm64) + echo "::set-output name=matrix::${MATRIX}" + + build-manylinux-wheels: + needs: generate_build_matrix + name: ${{ matrix.torch }} ${{ matrix.python-version }} + runs-on: ubuntu-22.04-arm + strategy: + fail-fast: false + matrix: + ${{ fromJson(needs.generate_build_matrix.outputs.matrix) }} + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # see https://github.com/pytorch/test-infra/blob/9e3d392690719fac85bad0c9b67f530e48375ca1/tools/scripts/generate_binary_build_matrix.py + # https://github.com/pytorch/builder/tree/main/manywheel + # https://github.com/pytorch/builder/pull/476 + # https://github.com/k2-fsa/k2/issues/733 + # https://github.com/pytorch/pytorch/pull/50633 (generate build matrix) + - name: Run the build process with Docker + uses: addnab/docker-run-action@v3 + with: + image: ${{ matrix.image }} + options: -v ${{ github.workspace }}:/var/www -e IS_2_28=${{ matrix.is_2_28 }} -e PYTHON_VERSION=${{ matrix.python-version }} -e TORCH_VERSION=${{ matrix.torch }} + run: | + echo "pwd: $PWD" + uname -a + id + cat /etc/*release + gcc --version + python3 --version + which python3 + + ls -lh /opt/python/ + + echo "---" + + ls -lh /opt/python/cp* + + ls -lh /opt/python/*/bin + + echo "---" + find /opt/python/cp* -name "libpython*" + echo "-----" + find /opt/_internal/cp* -name "libpython*" + + echo "-----" + find / -name "libpython*" + + # cp36-cp36m + # cp37-cp37m + # cp38-cp38 + # cp39-cp39 + # cp310-cp310 + # cp311-cp311 + # cp312-cp312 + # cp313-cp313 + # cp313-cp313t (no gil) + if [[ $PYTHON_VERSION == "3.6" ]]; then + python_dir=/opt/python/cp36-cp36m + export PYTHONPATH=/opt/python/cp36-cp36m/lib/python3.6/site-packages:$PYTHONPATH + elif [[ $PYTHON_VERSION == "3.7" ]]; then + python_dir=/opt/python/cp37-cp37m + export PYTHONPATH=/opt/python/cp37-cp37m/lib/python3.7/site-packages:$PYTHONPATH + elif [[ $PYTHON_VERSION == "3.8" ]]; then + python_dir=/opt/python/cp38-cp38 + export PYTHONPATH=/opt/python/cp38-cp38/lib/python3.8/site-packages:$PYTHONPATH + elif [[ $PYTHON_VERSION == "3.9" ]]; then + python_dir=/opt/python/cp39-cp39 + export PYTHONPATH=/opt/python/cp39-cp39/lib/python3.9/site-packages:$PYTHONPATH + elif [[ $PYTHON_VERSION == "3.10" ]]; then + python_dir=/opt/python/cp310-cp310 + export PYTHONPATH=/opt/python/cp310-cp310/lib/python3.10/site-packages:$PYTHONPATH + elif [[ $PYTHON_VERSION == "3.11" ]]; then + python_dir=/opt/python/cp311-cp311 + export PYTHONPATH=/opt/python/cp311-cp311/lib/python3.11/site-packages:$PYTHONPATH + elif [[ $PYTHON_VERSION == "3.12" ]]; then + python_dir=/opt/python/cp312-cp312 + export PYTHONPATH=/opt/python/cp312-cp312/lib/python3.12/site-packages:$PYTHONPATH + elif [[ $PYTHON_VERSION == "3.13" ]]; then + python_dir=/opt/python/cp313-cp313 + export PYTHONPATH=/opt/python/cp313-cp313/lib/python3.13/site-packages:$PYTHONPATH + else + echo "Unsupported Python version $PYTHON_VERSION" + exit 1 + fi + + export PYTHON_INSTALL_DIR=$python_dir + export PATH=$PYTHON_INSTALL_DIR/bin:$PATH + + # There are no libpython.so inside $PYTHON_INSTALL_DIR + # since they are statically linked. + + python3 --version + which python3 + + /var/www/scripts/github_actions/build-ubuntu-cpu-arm64.sh + + - name: Display wheels + shell: bash + run: | + ls -lh ./wheelhouse/ + + # https://huggingface.co/docs/hub/spaces-github-actions + - name: Publish to huggingface + if: github.repository_owner == 'csukuangfj' + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + uses: nick-fields/retry@v2 + with: + max_attempts: 20 + timeout_seconds: 200 + shell: bash + command: | + git config --global user.email "csukuangfj@gmail.com" + git config --global user.name "Fangjun Kuang" + + rm -rf huggingface + + export GIT_LFS_SKIP_SMUDGE=1 + + git clone https://huggingface.co/csukuangfj/kaldifeat huggingface + cd huggingface + git pull + + d=cpu/1.25.5.dev20250306/linux-arm64 + mkdir -p $d + cp -v ../wheelhouse/*.whl ./$d + git status + git lfs track "*.whl" + git add . + git commit -m "upload ubuntu-arm64-cpu wheel for torch ${{ matrix.torch }} python ${{ matrix.python-version }}" + git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/kaldifeat main diff --git a/.github/workflows/ubuntu-cuda-wheels.yml b/.github/workflows/ubuntu-cuda-wheels.yml index 0eaf7ba..a7f750c 100644 --- a/.github/workflows/ubuntu-cuda-wheels.yml +++ b/.github/workflows/ubuntu-cuda-wheels.yml @@ -3,7 +3,7 @@ name: build-wheels-cuda-ubuntu on: push: branches: - - fix-cuda-12.6 + - wheel tags: - '*' workflow_dispatch: diff --git a/scripts/github_actions/build-ubuntu-cpu-arm64.sh b/scripts/github_actions/build-ubuntu-cpu-arm64.sh new file mode 100755 index 0000000..d20d262 --- /dev/null +++ b/scripts/github_actions/build-ubuntu-cpu-arm64.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# +set -ex + +if [ -z $PYTHON_VERSION ]; then + echo "Please set the environment variable PYTHON_VERSION" + echo "Example: export PYTHON_VERSION=3.8" + # Valid values: 3.8, 3.9, 3.10, 3.11 + exit 1 +fi + +if [ -z $TORCH_VERSION ]; then + echo "Please set the environment variable TORCH_VERSION" + echo "Example: export TORCH_VERSION=1.10.0" + exit 1 +fi + +export PATH=$PYTHON_INSTALL_DIR/bin:$PATH +export LD_LIBRARY_PATH=$PYTHON_INSTALL_DIR/lib:$LD_LIBRARY_PATH +ls -lh $PYTHON_INSTALL_DIR/lib/ + +python3 --version +which python3 + +python3 -m pip install scikit-build +python3 -m pip install -U pip cmake +python3 -m pip install wheel twine typing_extensions +python3 -m pip install bs4 requests tqdm auditwheel + +echo "Installing torch" +python3 -m pip install -qq torch==$TORCH_VERSION -f https://download.pytorch.org/whl/torch_stable.html || \ +python3 -m pip install -qq torch==$TORCH_VERSION -f https://download.pytorch.org/whl/torch/ + +rm -rf ~/.cache/pip +yum clean all + +cd /var/www + +export CMAKE_CUDA_COMPILER_LAUNCHER= +export KALDIFEAT_CMAKE_ARGS=" -DPYTHON_EXECUTABLE=$PYTHON_INSTALL_DIR/bin/python3 " +export KALDIFEAT_MAKE_ARGS=" -j " + + +python3 setup.py bdist_wheel + +mkdir /var/www/wheelhouse +cp -v dist/*.whl /var/www/wheelhouse + +ls -lh /var/www diff --git a/scripts/github_actions/generate_build_matrix.py b/scripts/github_actions/generate_build_matrix.py index a4e1661..dd01ab4 100755 --- a/scripts/github_actions/generate_build_matrix.py +++ b/scripts/github_actions/generate_build_matrix.py @@ -48,6 +48,13 @@ def get_args(): help="True for macOS", ) + parser.add_argument( + "--for-arm64", + action="store_true", + default=False, + help="True for arm64", + ) + parser.add_argument( "--test-only-latest-torch", action="store_true", @@ -58,7 +65,9 @@ def get_args(): return parser.parse_args() -def generate_build_matrix(enable_cuda, for_windows, for_macos, test_only_latest_torch): +def generate_build_matrix( + enable_cuda, for_windows, for_macos, test_only_latest_torch, for_arm64 +): matrix = { # 1.5.x is removed because there are compilation errors. # See @@ -296,7 +305,7 @@ def generate_build_matrix(enable_cuda, for_windows, for_macos, test_only_latest_ # https://github.com/Jimver/cuda-toolkit/blob/master/src/links/windows-links.ts } if test_only_latest_torch: - latest = "2.6.0" + latest = "2.4.0" matrix = {latest: matrix[latest]} if for_windows or for_macos: @@ -368,7 +377,9 @@ def generate_build_matrix(enable_cuda, for_windows, for_macos, test_only_latest_ "torch": torch, "python-version": p, # "image": "pytorch/manylinux-builder:cpu-2.4", - "image": "pytorch/manylinux-builder:cpu-27677ead7c8293c299a885ae2c474bf445e653a5", + "image": "pytorch/manylinux-builder:cpu-27677ead7c8293c299a885ae2c474bf445e653a5" + if not for_arm64 + else "pytorch/manylinuxaarch64-builder:cpu-aarch64-195148266541a9789074265141cb7dc19dc14c54", "is_2_28": "0", } ) @@ -377,7 +388,9 @@ def generate_build_matrix(enable_cuda, for_windows, for_macos, test_only_latest_ { "torch": torch, "python-version": p, - "image": "pytorch/manylinux-builder:cpu-2.2", + "image": "pytorch/manylinux-builder:cpu-2.2" + if not for_arm64 + else "pytorch/manylinuxaarch64-builder:cpu-aarch64-195148266541a9789074265141cb7dc19dc14c54", "is_2_28": "0", } ) @@ -386,7 +399,9 @@ def generate_build_matrix(enable_cuda, for_windows, for_macos, test_only_latest_ { "torch": torch, "python-version": p, - "image": f"pytorch/manylinux-builder:cuda10.2", + "image": "pytorch/manylinux-builder:cuda10.2" + if not for_arm64 + else "pytorch/manylinuxaarch64-builder:cpu-aarch64-195148266541a9789074265141cb7dc19dc14c54", "is_2_28": "0", } ) @@ -400,6 +415,7 @@ def main(): enable_cuda=args.enable_cuda, for_windows=args.for_windows, for_macos=args.for_macos, + for_arm64=args.for_arm64, test_only_latest_torch=args.test_only_latest_torch, )