From d166236b566b5f39b2bc05f20f433a4f9f58b533 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Thu, 20 Aug 2026 14:14:44 +0200 Subject: [PATCH 1/2] workflows: add build-torchaudio.yml for riscv64 wheels torchaudio (github.com/pytorch/audio) is in maintenance phase: a plain setuptools build whose only real dependency is torch itself. It ships no PyPI sdist and its setup.py imports torch at module top with no [build-system] table, so we build from an upstream checkout (like build-onnx.yml) with cibuildwheel + --no-build-isolation. The build installs torch from our registry (public PyPI has no riscv64 torch wheel), builds against its stable libtorch ABI (torchaudio 2.11 is forward-compatible with any torch >=2.11), and excludes the torch-owned shared libs from the auditwheel repair so libtorch is not vendored into the wheel - yielding a 1.2 MB wheel instead of ~130 MB. Verified locally under QEMU (build + upstream smoke test) for cp313. Co-Authored-By: Claude Opus 4.8 --- .github/workflows/build-torchaudio.yml | 135 +++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 .github/workflows/build-torchaudio.yml diff --git a/.github/workflows/build-torchaudio.yml b/.github/workflows/build-torchaudio.yml new file mode 100644 index 00000000..f0a1dc84 --- /dev/null +++ b/.github/workflows/build-torchaudio.yml @@ -0,0 +1,135 @@ +# SPDX-FileCopyrightText: 2026 The RISE Project +# SPDX-License-Identifier: MIT +--- +# This workflow is based on: https://github.com/pytorch/audio/blob/main/.github/workflows/build_wheels_linux.yml +name: Build torchaudio wheels (riscv64) + +on: + workflow_dispatch: + inputs: + version: + description: 'torchaudio version to build (git tag without leading v, e.g. 2.11.0)' + required: true + default: '2.11.0' + pull_request: + paths: + - '.github/workflows/build-torchaudio.yml' + +run-name: build-torchaudio - ${{ inputs.version || '2.11.0' }} + +concurrency: + group: ${{ github.workflow }}-${{ inputs.version || '2.11.0' }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +permissions: + contents: read # to fetch code (actions/checkout) + +env: + # `inputs.version` is empty on pull_request events; default there. + TORCHAUDIO_VERSION: ${{ inputs.version || '2.11.0' }} + # torch (the sole build dependency) and torchaudio's own test/runtime deps + # have no riscv64 wheels on public PyPI - pull them from our registry. + UV_EXTRA_INDEX_URL: https://pypi.riseproject.dev/simple/ + UV_INDEX_STRATEGY: unsafe-best-match + UV_ONLY_BINARY: ':all:' + MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64 + # torch version to build against. torchaudio 2.11 is forward-compatible with + # any torch >=2.11 (it builds against the stable libtorch ABI - see + # TORCH_TARGET_VERSION in tools/setup_helpers/extension.py - and pins no torch + # version at runtime), so we build against the latest torch on our registry. + TORCH_VERSION: 2.13.0+cpu + +jobs: + build_wheels: + name: Build torchaudio ${{ inputs.version || '2.11.0' }} cp${{ matrix.python-version }}-manylinux_riscv64 + runs-on: ubuntu-24.04-riscv + timeout-minutes: 120 + strategy: + fail-fast: false + matrix: + # Match torch's own riscv64 matrix on the registry. torchaudio links + # libtorch_python (version-specific), so - despite py_limited_api=True - + # each CPython needs its own build; there is no single abi3 wheel. + # See https://pypi.riseproject.dev/python-wheels/development.html#target-python-versions + python-version: [312, 313, 314, 314t] + + steps: + - name: Checkout torchaudio v${{ env.TORCHAUDIO_VERSION }} + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + repository: pytorch/audio + ref: v${{ env.TORCHAUDIO_VERSION }} + persist-credentials: false + + - uses: pypa/cibuildwheel@1828c10ab37f080699c7b81cea34097c684a7074 # v4.2.0 + env: + CIBW_BUILD: "cp${{ matrix.python-version }}-manylinux_riscv64" + CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }} + # torchaudio's setup.py does `import torch` at module top and declares + # no [build-system] table, so the build backend is legacy setuptools + # with no PEP 517 isolation available anyway. Preinstall torch (+ the + # setuptools/ninja build tools) and disable isolation so setup.py can + # import the already-installed torch. + CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation" + # --only-binary=:all: torch: never let pip fall back to building torch + # from an sdist inside the container (public PyPI has no riscv64 torch + # wheel; ours does). ninja/setuptools/wheel likewise come as wheels. + CIBW_BEFORE_BUILD: >- + pip install --only-binary=:all: + torch==${{ env.TORCH_VERSION }} setuptools wheel ninja + # USE_CUDA=0: CPU-only build (no CUDA toolchain on riscv64). + # BUILD_VERSION pins a clean wheel version; without it setup.py appends + # + to version.txt. The tag maps 1:1 to the package version + # (v2.11.0 -> 2.11.0), so no tag->version translation is needed. + # PIP_EXTRA_INDEX_URL lets torch's deps (and the before-build torch + # itself) resolve from our registry inside the container. + CIBW_ENVIRONMENT: >- + USE_CUDA=0 + BUILD_VERSION=${{ env.TORCHAUDIO_VERSION }} + PIP_EXTRA_INDEX_URL=https://pypi.riseproject.dev/simple/ + CIBW_ENVIRONMENT_PASS_LINUX: PIP_EXTRA_INDEX_URL + # torchaudio's extension links libtorch/libc10/libgomp etc., which are + # provided by the torch wheel at runtime (torch is imported before + # torchaudio and loads them RTLD_GLOBAL). Exclude them from the repair + # so auditwheel does not vendor ~130MB of libtorch into our wheel - + # this mirrors how upstream torchaudio wheels are built. + CIBW_REPAIR_WHEEL_COMMAND: >- + auditwheel repair -w {dest_dir} {wheel} + --exclude libtorch.so + --exclude libtorch_cpu.so + --exclude libtorch_python.so + --exclude libtorch_global_deps.so + --exclude libc10.so + --exclude libgomp.so.1 + --exclude libgfortran.so.5 + --exclude libopenblas.so.0 + # Run torchaudio's own smoke test (imports torchaudio + all + # subpackages) against the freshly built wheel. torch is pulled from + # our registry; numpy silences torch's "Failed to initialize NumPy" + # warning and exercises the tensor<->numpy path torchaudio relies on. + CIBW_TEST_REQUIRES: torch==${{ env.TORCH_VERSION }} numpy + CIBW_TEST_COMMAND: python {project}/test/smoke_test/smoke_test.py + + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: torchaudio-${{ env.TORCHAUDIO_VERSION }}-cp${{ matrix.python-version }}-manylinux_riscv64 + path: ./wheelhouse/*.whl + if-no-files-found: error + + publish: + name: Publish torchaudio ${{ inputs.version || '2.11.0' }} to GitLab + needs: [build_wheels] + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Publish wheels and open docs PR + uses: riseproject-dev/python-wheels/actions/publish-wheels@main + with: + artifact-pattern: torchaudio-${{ env.TORCHAUDIO_VERSION }}-*-manylinux_riscv64 + gitlab-username: ${{ vars.GITLAB_DEPLOY_USER }} + gitlab-token: ${{ secrets.GITLAB_DEPLOY_TOKEN }} + gitlab-project-id: ${{ vars.GITLAB_PROJECT_ID }} + gh-token: ${{ secrets.GITHUB_TOKEN }} From be0b9a33909e1612b4c626d23e31918ebbdd4d7f Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Thu, 20 Aug 2026 14:31:51 +0200 Subject: [PATCH 2/2] workflows: torchaudio: use torch>=2.11 instead of pinning build torch Resolve the build/test torch to the latest on the registry rather than a hardcoded 2.13.0+cpu pin. torchaudio 2.11 targets the stable libtorch ABI and pins no torch at runtime, so any torch >=2.11 works. Co-Authored-By: Claude Opus 4.8 --- .github/workflows/build-torchaudio.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-torchaudio.yml b/.github/workflows/build-torchaudio.yml index f0a1dc84..2ebaacab 100644 --- a/.github/workflows/build-torchaudio.yml +++ b/.github/workflows/build-torchaudio.yml @@ -33,11 +33,6 @@ env: UV_INDEX_STRATEGY: unsafe-best-match UV_ONLY_BINARY: ':all:' MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64 - # torch version to build against. torchaudio 2.11 is forward-compatible with - # any torch >=2.11 (it builds against the stable libtorch ABI - see - # TORCH_TARGET_VERSION in tools/setup_helpers/extension.py - and pins no torch - # version at runtime), so we build against the latest torch on our registry. - TORCH_VERSION: 2.13.0+cpu jobs: build_wheels: @@ -74,9 +69,13 @@ jobs: # --only-binary=:all: torch: never let pip fall back to building torch # from an sdist inside the container (public PyPI has no riscv64 torch # wheel; ours does). ninja/setuptools/wheel likewise come as wheels. + # torch>=2.11 (not a pin): torchaudio 2.11 builds against the stable + # libtorch ABI (TORCH_TARGET_VERSION in tools/setup_helpers/extension.py) + # and pins no torch at runtime, so it's forward-compatible with any + # torch >=2.11 - resolve to the latest on our registry. CIBW_BEFORE_BUILD: >- pip install --only-binary=:all: - torch==${{ env.TORCH_VERSION }} setuptools wheel ninja + torch>=2.11 setuptools wheel ninja # USE_CUDA=0: CPU-only build (no CUDA toolchain on riscv64). # BUILD_VERSION pins a clean wheel version; without it setup.py appends # + to version.txt. The tag maps 1:1 to the package version @@ -107,7 +106,7 @@ jobs: # subpackages) against the freshly built wheel. torch is pulled from # our registry; numpy silences torch's "Failed to initialize NumPy" # warning and exercises the tensor<->numpy path torchaudio relies on. - CIBW_TEST_REQUIRES: torch==${{ env.TORCH_VERSION }} numpy + CIBW_TEST_REQUIRES: torch>=2.11 numpy CIBW_TEST_COMMAND: python {project}/test/smoke_test/smoke_test.py - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1