Skip to content

Commit e600639

Browse files
authored
Provide pre-built wheels with CUDA support. (k2-fsa#1143)
1 parent e4c33be commit e600639

File tree

4 files changed

+233
-2
lines changed

4 files changed

+233
-2
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: build-wheels-linux-cuda
2+
3+
on:
4+
push:
5+
branches:
6+
- wheel
7+
tags:
8+
- 'v[0-9]+.[0-9]+.[0-9]+*'
9+
workflow_dispatch:
10+
11+
env:
12+
SHERPA_ONNX_IS_IN_GITHUB_ACTIONS: 1
13+
14+
concurrency:
15+
group: build-wheels-linux-cuda-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
build_wheels_linux_cuda:
20+
name: ${{ matrix.manylinux }} ${{ matrix.python-version }}
21+
runs-on: ${{ matrix.os }}
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
os: [ubuntu-20.04]
26+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- name: Setup Python ${{ matrix.python-version }}
32+
uses: actions/setup-python@v5
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
36+
- name: Install Python dependencies
37+
shell: bash
38+
run: |
39+
pip install -U pip wheel setuptools twine
40+
41+
- name: Build alsa-lib
42+
shell: bash
43+
run: |
44+
git clone --depth 1 --branch v1.2.12 https://github.com/alsa-project/alsa-lib
45+
cd alsa-lib
46+
./gitcompile
47+
48+
- name: Build sherpa-onnx
49+
shell: bash
50+
run: |
51+
export CPLUS_INCLUDE_PATH=$PWD/alsa-lib/include:$CPLUS_INCLUDE_PATH
52+
export SHERPA_ONNX_ALSA_LIB_DIR=$PWD/alsa-lib/src/.libs
53+
export LD_LIBRARY_PATH=$SHERPA_ONNX_ALSA_LIB_DIR:$LD_LIBRARY_PATH
54+
55+
echo "CPLUS_INCLUDE_PATH: $CPLUS_INCLUDE_PATH"
56+
ls -lh $PWD/alsa-lib/include
57+
echo "---"
58+
ls -lh $PWD/alsa-lib/src/.libs
59+
60+
export SHERPA_ONNX_MAKE_ARGS="VERBOSE=1"
61+
export SHERPA_ONNX_ENABLE_ALSA=1
62+
export SHERPA_ONNX_CMAKE_ARGS="-DSHERPA_ONNX_ENABLE_GPU=ON"
63+
64+
python3 setup.py bdist_wheel
65+
66+
ls -lh dist
67+
68+
mv dist wheelhouse
69+
70+
- name: Display wheels
71+
shell: bash
72+
run: |
73+
ls -lh ./wheelhouse/
74+
75+
- name: Install patchelf
76+
shell: bash
77+
run: |
78+
sudo apt-get update -q
79+
sudo apt-get install -q -y patchelf
80+
patchelf --help
81+
82+
- name: Patch wheels
83+
shell: bash
84+
run: |
85+
mkdir ./wheels
86+
sudo ./scripts/wheel/patch_wheel.py --in-dir ./wheelhouse --out-dir ./wheels
87+
88+
ls -lh ./wheels/
89+
rm -rf ./wheelhouse
90+
mv ./wheels ./wheelhouse
91+
92+
- uses: actions/upload-artifact@v4
93+
with:
94+
name: wheel-cuda-${{ matrix.python-version }}
95+
path: ./wheelhouse/*.whl
96+
97+
- name: Publish to huggingface
98+
env:
99+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
100+
uses: nick-fields/retry@v3
101+
with:
102+
max_attempts: 20
103+
timeout_seconds: 200
104+
shell: bash
105+
command: |
106+
git config --global user.email "[email protected]"
107+
git config --global user.name "Fangjun Kuang"
108+
109+
rm -rf huggingface
110+
export GIT_LFS_SKIP_SMUDGE=1
111+
export GIT_CLONE_PROTECTION_ACTIVE=false
112+
113+
SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
114+
echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
115+
116+
d=cuda/$SHERPA_ONNX_VERSION
117+
118+
git clone https://huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface
119+
cd huggingface
120+
git fetch
121+
git pull
122+
git merge -m "merge remote" --ff origin main
123+
124+
mkdir -p $d
125+
126+
cp -v ../wheelhouse/*.whl $d/
127+
128+
git status
129+
git add .
130+
git commit -m "add more wheels"
131+
git push https://csukuangfj:[email protected]/csukuangfj/sherpa-onnx-wheels main

.github/workflows/build-wheels-linux.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ jobs:
5656
ls -lh ./wheelhouse/
5757
5858
- name: Install patchelf
59-
if: matrix.os == 'ubuntu-latest'
6059
shell: bash
6160
run: |
6261
sudo apt-get update -q
@@ -65,7 +64,6 @@ jobs:
6564
6665
- name: Patch wheels
6766
shell: bash
68-
if: matrix.os == 'ubuntu-latest'
6967
run: |
7068
mkdir ./wheels
7169
sudo ./scripts/wheel/patch_wheel.py --in-dir ./wheelhouse --out-dir ./wheels
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: build-wheels-win64-cuda
2+
3+
on:
4+
push:
5+
branches:
6+
- wheel
7+
tags:
8+
- 'v[0-9]+.[0-9]+.[0-9]+*'
9+
workflow_dispatch:
10+
11+
env:
12+
SHERPA_ONNX_IS_IN_GITHUB_ACTIONS: 1
13+
14+
concurrency:
15+
group: build-wheels-win64-cuda-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
build_wheels_win64_cuda:
20+
name: ${{ matrix.python-version }}
21+
runs-on: ${{ matrix.os }}
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
os: [windows-2019]
26+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- name: Setup Python ${{ matrix.python-version }}
32+
uses: actions/setup-python@v5
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
36+
- name: Build wheels
37+
shell: bash
38+
run: |
39+
pip install setuptools wheel
40+
41+
export SHERPA_ONNX_CMAKE_ARGS="-DSHERPA_ONNX_ENABLE_GPU=ON"
42+
43+
python3 setup.py bdist_wheel
44+
45+
ls -lh ./dist/
46+
47+
mv dist wheelhouse
48+
49+
- name: Display wheels
50+
shell: bash
51+
run: |
52+
ls -lh ./wheelhouse/
53+
54+
- uses: actions/upload-artifact@v4
55+
with:
56+
name: wheel-${{ matrix.python-version }}
57+
path: ./wheelhouse/*.whl
58+
59+
- name: Publish to huggingface
60+
env:
61+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
62+
uses: nick-fields/retry@v3
63+
with:
64+
max_attempts: 20
65+
timeout_seconds: 200
66+
shell: bash
67+
command: |
68+
git config --global user.email "[email protected]"
69+
git config --global user.name "Fangjun Kuang"
70+
71+
rm -rf huggingface
72+
export GIT_LFS_SKIP_SMUDGE=1
73+
export GIT_CLONE_PROTECTION_ACTIVE=false
74+
75+
SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
76+
echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
77+
78+
d=cuda/$SHERPA_ONNX_VERSION
79+
80+
git clone https://huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface
81+
cd huggingface
82+
git fetch
83+
git pull
84+
git merge -m "merge remote" --ff origin main
85+
86+
mkdir -p $d
87+
88+
cp -v ../wheelhouse/*.whl $d/
89+
90+
git status
91+
git add .
92+
git commit -m "add more wheels"
93+
git push https://csukuangfj:[email protected]/csukuangfj/sherpa-onnx-wheels main

setup.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22

3+
import os
34
import re
45
from pathlib import Path
56

@@ -26,6 +27,14 @@ def get_package_version():
2627

2728
match = re.search(r"set\(SHERPA_ONNX_VERSION (.*)\)", content)
2829
latest_version = match.group(1).strip('"')
30+
31+
cmake_args = os.environ.get("SHERPA_ONNX_CMAKE_ARGS", "")
32+
extra_version = ""
33+
if "-DSHERPA_ONNX_ENABLE_GPU=ON" in cmake_args:
34+
extra_version = "+cuda"
35+
36+
latest_version += extra_version
37+
2938
return latest_version
3039

3140

0 commit comments

Comments
 (0)