Skip to content

Commit 3754c04

Browse files
authored
feat(ci): add ROCm wheel builds (abetlen#2252)
* feat(ci): add ROCm wheel builds * docs: update changelog for ROCm wheel builds * docs: add ROCm wheel install instructions
1 parent ab7a9b0 commit 3754c04

4 files changed

Lines changed: 257 additions & 1 deletion

File tree

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
name: Build Wheels (ROCm)
2+
3+
on: workflow_dispatch
4+
5+
permissions:
6+
contents: write
7+
8+
jobs:
9+
build_wheels:
10+
name: Build Wheel ${{ matrix.os }} ${{ matrix.pyver }} ROCm ${{ matrix.rocm }}
11+
runs-on: ${{ matrix.os }}
12+
container:
13+
image: rocm/dev-ubuntu-22.04:${{ matrix.rocm }}-complete
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
include:
18+
- os: ubuntu-22.04
19+
pyver: "3.9"
20+
rocm: "7.2.4"
21+
amdgpu_targets: gfx908;gfx90a;gfx942;gfx1030;gfx1100;gfx1101;gfx1102;gfx1150;gfx1151;gfx1200;gfx1201
22+
23+
steps:
24+
- name: Install system dependencies
25+
run: |
26+
apt-get update
27+
apt-get install -y --no-install-recommends git cmake lsb-release ninja-build
28+
29+
- uses: actions/checkout@v4
30+
with:
31+
submodules: "recursive"
32+
33+
- uses: actions/setup-python@v6
34+
with:
35+
python-version: ${{ matrix.pyver }}
36+
cache: "pip"
37+
38+
- name: Install build dependencies
39+
run: |
40+
python -m pip install --upgrade pip
41+
python -m pip install build wheel
42+
43+
- name: Build ROCm wheel
44+
run: |
45+
export ROCM_PATH="${ROCM_PATH:-/opt/rocm}"
46+
export HIP_PATH="${HIP_PATH:-$ROCM_PATH}"
47+
export PATH="$ROCM_PATH/bin:$ROCM_PATH/llvm/bin:$PATH"
48+
export LD_LIBRARY_PATH="$ROCM_PATH/lib:$ROCM_PATH/lib64:${LD_LIBRARY_PATH:-}"
49+
export CC="$ROCM_PATH/llvm/bin/clang"
50+
export CXX="$ROCM_PATH/llvm/bin/clang++"
51+
export HIPCXX="$ROCM_PATH/llvm/bin/clang"
52+
export CMAKE_GENERATOR=Ninja
53+
54+
hipconfig --version
55+
hipcc --version
56+
57+
rocm_tag="$(hipconfig --version | sed -E 's/^([0-9]+)\.([0-9]+).*/\1\2/')"
58+
echo "ROCM_VERSION=$rocm_tag" >> "$GITHUB_ENV"
59+
60+
amdgpu_targets="${{ matrix.amdgpu_targets }}"
61+
export CMAKE_ARGS="-DGGML_HIP=on -DGGML_NATIVE=off -DGGML_AVX=off -DGGML_AVX2=off -DGGML_FMA=off -DGGML_F16C=off -DAMDGPU_TARGETS=$amdgpu_targets -DCMAKE_HIP_ARCHITECTURES=$amdgpu_targets"
62+
python -m build --wheel
63+
mkdir -p wheelhouse
64+
cp dist/*.whl wheelhouse/
65+
66+
- uses: actions/upload-artifact@v7
67+
with:
68+
name: wheels-rocm${{ env.ROCM_VERSION }}-${{ matrix.os }}
69+
path: ./wheelhouse/*.whl
70+
71+
build_wheels_windows_hip:
72+
name: Build Wheel windows-2022 ${{ matrix.pyver }} HIP ${{ matrix.name }}
73+
runs-on: windows-2022
74+
env:
75+
HIPSDK_INSTALLER_VERSION: "26.Q1"
76+
strategy:
77+
fail-fast: false
78+
matrix:
79+
include:
80+
- name: radeon
81+
pyver: "3.9"
82+
amdgpu_targets: gfx1150;gfx1151;gfx1200;gfx1201;gfx1100;gfx1101;gfx1102;gfx1030;gfx1031;gfx1032
83+
84+
steps:
85+
- uses: actions/checkout@v4
86+
with:
87+
submodules: "recursive"
88+
89+
- uses: actions/setup-python@v6
90+
with:
91+
python-version: ${{ matrix.pyver }}
92+
cache: "pip"
93+
94+
- name: Set up MSVC
95+
uses: ilammy/msvc-dev-cmd@v1
96+
with:
97+
arch: x64
98+
99+
- name: Install build dependencies
100+
run: |
101+
python -m pip install --upgrade pip
102+
python -m pip install build wheel
103+
104+
- name: Grab rocWMMA package
105+
run: |
106+
curl -o rocwmma.deb "https://repo.radeon.com/rocm/apt/7.2.1/pool/main/r/rocwmma-dev/rocwmma-dev_2.2.0.70201-81~24.04_amd64.deb"
107+
7z x rocwmma.deb
108+
7z x data.tar
109+
110+
- name: Cache ROCm installation
111+
id: cache-rocm
112+
uses: actions/cache@v5
113+
with:
114+
path: C:\Program Files\AMD\ROCm
115+
key: cache-gha-rocm-${{ env.HIPSDK_INSTALLER_VERSION }}-${{ runner.os }}
116+
117+
- name: Install ROCm
118+
if: steps.cache-rocm.outputs.cache-hit != 'true'
119+
run: |
120+
$ErrorActionPreference = "Stop"
121+
Invoke-WebRequest `
122+
-Uri "https://download.amd.com/developer/eula/rocm-hub/AMD-Software-PRO-Edition-${{ env.HIPSDK_INSTALLER_VERSION }}-Win11-For-HIP.exe" `
123+
-OutFile "${env:RUNNER_TEMP}\rocm-install.exe"
124+
$proc = Start-Process "${env:RUNNER_TEMP}\rocm-install.exe" -ArgumentList '-install' -NoNewWindow -PassThru
125+
$completed = $proc.WaitForExit(1800000)
126+
if (-not $completed) {
127+
$proc.Kill()
128+
throw "ROCm installation timed out after 30 minutes"
129+
}
130+
if ($proc.ExitCode -ne 0) {
131+
throw "ROCm installation failed with exit code $($proc.ExitCode)"
132+
}
133+
134+
- name: Verify ROCm
135+
run: |
136+
$clangPath = Get-ChildItem 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' | Select-Object -First 1
137+
if (-not $clangPath) {
138+
throw "ROCm installation not found"
139+
}
140+
& $clangPath.FullName --version
141+
142+
- name: Build HIP wheel
143+
run: |
144+
$ErrorActionPreference = "Stop"
145+
$hipPath = Resolve-Path 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' | Split-Path | Split-Path
146+
$rocwmmaInclude = (Join-Path $PWD 'opt\rocm-7.2.1\include').Replace('\', '/')
147+
$amdgpuTargets = "${{ matrix.amdgpu_targets }}"
148+
149+
$env:HIP_PATH = $hipPath
150+
$env:ROCM_PATH = $hipPath
151+
$env:CMAKE_PREFIX_PATH = $hipPath
152+
$env:HIP_PLATFORM = 'amd'
153+
$env:PATH = "$hipPath\bin;$env:PATH"
154+
$env:CC = "$hipPath\bin\clang.exe"
155+
$env:CXX = "$hipPath\bin\clang++.exe"
156+
$env:HIPCXX = "$hipPath\bin\clang.exe"
157+
$env:CMAKE_GENERATOR = 'Unix Makefiles'
158+
$env:CXXFLAGS = "-I$rocwmmaInclude -Wno-ignored-attributes -Wno-nested-anon-types"
159+
$env:CMAKE_ARGS = "-DGGML_HIP=ON -DGGML_HIP_ROCWMMA_FATTN=ON -DGGML_NATIVE=OFF -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF -DGPU_TARGETS=$amdgpuTargets"
160+
161+
python -m build --wheel
162+
163+
- name: Bundle ROCm runtime DLLs
164+
run: |
165+
$ErrorActionPreference = "Stop"
166+
$hipPath = Resolve-Path 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' | Split-Path | Split-Path
167+
$wheel = Get-ChildItem dist\*.whl | Select-Object -First 1
168+
python -m wheel unpack $wheel.FullName -d wheel-unpacked
169+
$wheelRoot = Get-ChildItem wheel-unpacked -Directory | Select-Object -First 1
170+
$libDir = Join-Path $wheelRoot.FullName 'llama_cpp\lib'
171+
New-Item -ItemType Directory -Force $libDir | Out-Null
172+
173+
$dllPatterns = @(
174+
'amdhip64.dll',
175+
'hiprtc*.dll',
176+
'libhipblas.dll',
177+
'libhipblaslt.dll',
178+
'rocblas.dll'
179+
)
180+
foreach ($pattern in $dllPatterns) {
181+
Copy-Item (Join-Path $hipPath "bin\$pattern") $libDir -ErrorAction SilentlyContinue
182+
}
183+
184+
New-Item -ItemType Directory -Force (Join-Path $libDir 'rocblas\library') | Out-Null
185+
New-Item -ItemType Directory -Force (Join-Path $libDir 'hipblaslt\library') | Out-Null
186+
Copy-Item "$hipPath\bin\rocblas\library\*" (Join-Path $libDir 'rocblas\library') -Recurse -Force
187+
Copy-Item "$hipPath\bin\hipblaslt\library\*" (Join-Path $libDir 'hipblaslt\library') -Recurse -Force
188+
189+
Remove-Item dist\*.whl
190+
python -m wheel pack $wheelRoot.FullName -d dist
191+
New-Item -ItemType Directory -Force wheelhouse | Out-Null
192+
Copy-Item dist/*.whl wheelhouse/
193+
194+
- uses: actions/upload-artifact@v7
195+
with:
196+
name: wheels-hip-${{ matrix.name }}-windows-2022
197+
path: ./wheelhouse/*.whl
198+
199+
release_rocm:
200+
name: Release ROCm
201+
needs: [build_wheels]
202+
if: startsWith(github.ref, 'refs/tags/')
203+
runs-on: ubuntu-latest
204+
205+
steps:
206+
- uses: actions/download-artifact@v4
207+
with:
208+
merge-multiple: true
209+
path: dist
210+
211+
- uses: softprops/action-gh-release@v2
212+
with:
213+
files: dist/*
214+
# Set release name to <tag>-rocm<rocm_version>.
215+
tag_name: ${{ github.ref_name }}-rocm72
216+
env:
217+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
218+
219+
release_hip:
220+
name: Release HIP
221+
needs: [build_wheels_windows_hip]
222+
if: startsWith(github.ref, 'refs/tags/')
223+
runs-on: ubuntu-latest
224+
225+
steps:
226+
- uses: actions/download-artifact@v4
227+
with:
228+
merge-multiple: true
229+
path: dist
230+
231+
- uses: softprops/action-gh-release@v2
232+
with:
233+
files: dist/*
234+
# Set release name to <tag>-hip-radeon.
235+
tag_name: ${{ github.ref_name }}-hip-radeon
236+
env:
237+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/generate-index-from-release.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Wheels Index
33
on:
44
# Trigger on new release
55
workflow_run:
6-
workflows: ["Release", "Build Wheels (CUDA)", "Build Wheels (Metal)", "Build Wheels (Vulkan)"]
6+
workflows: ["Release", "Build Wheels (CUDA)", "Build Wheels (Metal)", "Build Wheels (Vulkan)", "Build Wheels (ROCm)"]
77
types:
88
- completed
99

@@ -46,6 +46,8 @@ jobs:
4646
./scripts/releases-to-pep-503.sh index/whl/cu124 '^[v]?[0-9]+\.[0-9]+\.[0-9]+-cu124$'
4747
# ./scripts/releases-to-pep-503.sh index/whl/cu125 '^[v]?[0-9]+\.[0-9]+\.[0-9]+-cu124$'
4848
# ./scripts/releases-to-pep-503.sh index/whl/cu126 '^[v]?[0-9]+\.[0-9]+\.[0-9]+-cu124$'
49+
./scripts/releases-to-pep-503.sh index/whl/rocm72 '^[v]?[0-9]+\.[0-9]+\.[0-9]+-rocm72$'
50+
./scripts/releases-to-pep-503.sh index/whl/hip-radeon '^[v]?[0-9]+\.[0-9]+\.[0-9]+-hip-radeon$'
4951
./scripts/releases-to-pep-503.sh index/whl/vulkan '^[v]?[0-9]+\.[0-9]+\.[0-9]+-vulkan$'
5052
./scripts/releases-to-pep-503.sh index/whl/metal '^[v]?[0-9]+\.[0-9]+\.[0-9]+-metal$'
5153
- name: Upload artifact

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
- feat(ci): add ROCm wheel builds by @abetlen in #2252
1011
- feat(ci): add Vulkan wheel builds by @abetlen in #2251
1112
- fix: handle additional `from_pretrained` files in subfolders by @TNing in #2085
1213

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,22 @@ To install with HIP / ROCm support for AMD cards, set the `GGML_HIP=on` environm
185185
CMAKE_ARGS="-DGGML_HIP=on" pip install llama-cpp-python
186186
```
187187

188+
**Pre-built Wheel (New)**
189+
190+
It is also possible to install a pre-built wheel with ROCm support for Linux:
191+
192+
```bash
193+
pip install llama-cpp-python \
194+
--extra-index-url https://abetlen.github.io/llama-cpp-python/whl/rocm72
195+
```
196+
197+
Or a pre-built wheel with HIP Radeon support for Windows:
198+
199+
```powershell
200+
pip install llama-cpp-python `
201+
--extra-index-url https://abetlen.github.io/llama-cpp-python/whl/hip-radeon
202+
```
203+
188204
</details>
189205

190206
<details>

0 commit comments

Comments
 (0)