Skip to content

Commit f144cf4

Browse files
authored
Python 3.9 ROCm build test
1 parent ee0e84b commit f144cf4

File tree

1 file changed

+229
-0
lines changed

1 file changed

+229
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
name: Build Wheels & Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
release:
7+
description: 'Release? 1 = yes, 0 = no'
8+
default: '0'
9+
required: true
10+
type: string
11+
12+
permissions:
13+
contents: write
14+
15+
jobs:
16+
build_wheels:
17+
name: ${{ matrix.os }} Python=${{ matrix.pyver }} CUDA=${{ matrix.cuda }} ROCm=${{ matrix.rocm }} Torch=${{ matrix.torch }}
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
matrix:
21+
include:
22+
23+
# - { artname: 'wheel', os: ubuntu-20.04, pyver: '3.8', cuda: '11.7.0', rocm: '', torch: '2.0.1', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6+PTX' }
24+
# - { artname: 'wheel', os: ubuntu-20.04, pyver: '3.8', cuda: '11.8.0', rocm: '', torch: '2.3.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
25+
# - { artname: 'wheel', os: ubuntu-20.04, pyver: '3.8', cuda: '12.1.0', rocm: '', torch: '2.3.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
26+
# - { artname: 'wheel', os: ubuntu-20.04, pyver: '3.9', cuda: '11.7.0', rocm: '', torch: '2.0.1', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6+PTX' }
27+
# - { artname: 'wheel', os: ubuntu-20.04, pyver: '3.9', cuda: '11.8.0', rocm: '', torch: '2.3.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
28+
# - { artname: 'wheel', os: ubuntu-20.04, pyver: '3.9', cuda: '12.1.0', rocm: '', torch: '2.3.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
29+
# - { artname: 'wheel', os: ubuntu-20.04, pyver: '3.10', cuda: '11.7.0', rocm: '', torch: '2.0.1', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6+PTX' }
30+
# - { artname: 'wheel', os: ubuntu-20.04, pyver: '3.10', cuda: '11.8.0', rocm: '', torch: '2.3.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
31+
# - { artname: 'wheel', os: ubuntu-20.04, pyver: '3.10', cuda: '12.1.0', rocm: '', torch: '2.3.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
32+
# - { artname: 'wheel', os: ubuntu-20.04, pyver: '3.11', cuda: '11.7.0', rocm: '', torch: '2.0.1', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6+PTX' }
33+
# - { artname: 'wheel', os: ubuntu-20.04, pyver: '3.11', cuda: '11.8.0', rocm: '', torch: '2.3.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
34+
# - { artname: 'wheel', os: ubuntu-20.04, pyver: '3.11', cuda: '12.1.0', rocm: '', torch: '2.3.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
35+
# - { artname: 'wheel', os: windows-latest, pyver: '3.8', cuda: '11.7.0', rocm: '', torch: '2.0.1', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6+PTX' }
36+
# - { artname: 'wheel', os: windows-latest, pyver: '3.8', cuda: '11.8.0', rocm: '', torch: '2.3.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
37+
# - { artname: 'wheel', os: windows-latest, pyver: '3.8', cuda: '12.1.0', rocm: '', torch: '2.3.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
38+
# - { artname: 'wheel', os: windows-latest, pyver: '3.9', cuda: '11.7.0', rocm: '', torch: '2.0.1', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6+PTX' }
39+
# - { artname: 'wheel', os: windows-latest, pyver: '3.9', cuda: '11.8.0', rocm: '', torch: '2.3.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
40+
# - { artname: 'wheel', os: windows-latest, pyver: '3.9', cuda: '12.1.0', rocm: '', torch: '2.3.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
41+
# - { artname: 'wheel', os: windows-latest, pyver: '3.10', cuda: '11.7.0', rocm: '', torch: '2.0.1', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6+PTX' }
42+
# - { artname: 'wheel', os: windows-latest, pyver: '3.10', cuda: '11.8.0', rocm: '', torch: '2.3.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
43+
# - { artname: 'wheel', os: windows-latest, pyver: '3.10', cuda: '12.1.0', rocm: '', torch: '2.3.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
44+
# - { artname: 'wheel', os: windows-latest, pyver: '3.11', cuda: '11.7.0', rocm: '', torch: '2.0.1', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6+PTX' }
45+
# - { artname: 'wheel', os: windows-latest, pyver: '3.11', cuda: '11.8.0', rocm: '', torch: '2.3.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
46+
# - { artname: 'wheel', os: windows-latest, pyver: '3.11', cuda: '12.1.0', rocm: '', torch: '2.3.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
47+
- { artname: 'wheel', os: ubuntu-20.04, pyver: '3.9', cuda: '', rocm: '5.6', torch: '2.2.2', cudaarch: '' }
48+
- { artname: 'wheel', os: ubuntu-20.04, pyver: '3.9', cuda: '', rocm: '6.0', torch: '2.3.0', cudaarch: '' }
49+
# - { artname: 'wheel', os: ubuntu-20.04, pyver: '3.10', cuda: '', rocm: '5.6', torch: '2.2.2', cudaarch: '' }
50+
# - { artname: 'wheel', os: ubuntu-20.04, pyver: '3.10', cuda: '', rocm: '6.0', torch: '2.3.0', cudaarch: '' }
51+
# - { artname: 'wheel', os: ubuntu-20.04, pyver: '3.11', cuda: '', rocm: '5.6', torch: '2.2.2', cudaarch: '' }
52+
# - { artname: 'wheel', os: ubuntu-20.04, pyver: '3.11', cuda: '', rocm: '6.0', torch: '2.3.0', cudaarch: '' }
53+
54+
# sdist
55+
# - { artname: 'sdist', os: ubuntu-20.04, pyver: '3.11', cuda: '', rocm: '', torch: '2.3.0', cudaarch: '' }
56+
57+
# Extra Torch 2.2 wheels for Windows until PyTorch resolves the shm.dll issue
58+
# - { artname: 'wheel', os: windows-latest, pyver: '3.8', cuda: '11.8.0', rocm: '', torch: '2.2.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
59+
# - { artname: 'wheel', os: windows-latest, pyver: '3.8', cuda: '12.1.0', rocm: '', torch: '2.2.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
60+
# - { artname: 'wheel', os: windows-latest, pyver: '3.9', cuda: '11.8.0', rocm: '', torch: '2.2.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
61+
# - { artname: 'wheel', os: windows-latest, pyver: '3.9', cuda: '12.1.0', rocm: '', torch: '2.2.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
62+
# - { artname: 'wheel', os: windows-latest, pyver: '3.10', cuda: '11.8.0', rocm: '', torch: '2.2.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
63+
# - { artname: 'wheel', os: windows-latest, pyver: '3.10', cuda: '12.1.0', rocm: '', torch: '2.2.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
64+
# - { artname: 'wheel', os: windows-latest, pyver: '3.11', cuda: '11.8.0', rocm: '', torch: '2.2.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
65+
# - { artname: 'wheel', os: windows-latest, pyver: '3.11', cuda: '12.1.0', rocm: '', torch: '2.2.0', cudaarch: '6.0 6.1 7.0 7.5 8.0 8.6 8.9 9.0+PTX' }
66+
67+
defaults:
68+
run:
69+
shell: pwsh
70+
71+
steps:
72+
73+
# Free disk space
74+
75+
- name: Free Disk Space
76+
uses: jlumbroso/free-disk-space@v1.3.1
77+
if: runner.os == 'Linux'
78+
with:
79+
tool-cache: true
80+
android: true
81+
dotnet: true
82+
haskell: true
83+
large-packages: false
84+
swap-storage: true
85+
86+
# Setup Python
87+
88+
- uses: actions/checkout@v3
89+
90+
- uses: actions/setup-python@v3
91+
with:
92+
python-version: ${{ matrix.pyver }}
93+
94+
# Get version string from package
95+
96+
- name: Get version string
97+
id: package_version
98+
run: |
99+
$versionString = Get-Content $(Join-Path 'exllamav2' 'version.py') -raw
100+
if ($versionString -match '__version__ = "(\d+\.(?:\d+\.?(?:dev\d+)?)*)"')
101+
{
102+
Write-Output $('::notice file=build-wheels-release.yml,line=200,title=Package Version::Detected package version is: {0}' -f $Matches[1])
103+
Write-Output "PACKAGE_VERSION=$($Matches[1])" >> "$env:GITHUB_OUTPUT"
104+
}
105+
else
106+
{
107+
Write-Output '::error file=build-wheels-release.yml,line=203::Could not parse version from exllamav2/version.py! You must upload wheels manually!'
108+
Write-Output "PACKAGE_VERSION=None" >> "$env:GITHUB_OUTPUT"
109+
}
110+
111+
# Install ROCm SDK, apparently needs to happen before setting up Python
112+
113+
- name: Build for ROCm
114+
if: matrix.rocm != ''
115+
shell: bash
116+
run: |
117+
# --- Install ROCm SDK
118+
119+
export ROCM_VERSION=${{ matrix.rocm }}
120+
export TORCH_VERSION=${{ matrix.torch }}
121+
122+
[ ! -d /etc/apt/keyrings ] && sudo mkdir --parents --mode=0755 /etc/apt/keyrings
123+
wget https://repo.radeon.com/rocm/rocm.gpg.key -O - | gpg --dearmor | sudo tee /etc/apt/keyrings/rocm.gpg > /dev/null
124+
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/$ROCM_VERSION focal main" | sudo tee --append /etc/apt/sources.list.d/rocm.list
125+
echo -e 'Package: *\nPin: release o=repo.radeon.com\nPin-Priority: 600' | sudo tee /etc/apt/preferences.d/rocm-pin-600
126+
127+
sudo apt update
128+
sudo apt install rocm-hip-sdk -y
129+
sudo apt clean -y
130+
131+
echo "/opt/rocm/bin" >> $GITHUB_PATH
132+
echo "ROCM_PATH=/opt/rocm" >> $GITHUB_ENV
133+
echo "ROCM_VERSION=$ROCM_VERSION" >> $GITHUB_ENV
134+
echo "USE_ROCM=1" >> $GITHUB_ENV
135+
136+
# --- Install dependencies
137+
138+
pip3 install torch==${{ matrix.torch }} --index-url="https://download.pytorch.org/whl/rocm$ROCM_VERSION"
139+
pip3 install --upgrade build wheel safetensors sentencepiece ninja
140+
pip3 cache purge
141+
142+
# --- Build wheel
143+
144+
python3 -m build -n --wheel -C--build-option=egg_info "-C--build-option=--tag-build=+rocm${{ matrix.rocm }}-torch${{ matrix.torch }}"
145+
146+
# Build for CUDA
147+
148+
- name: Setup Mamba
149+
if: matrix.cuda != ''
150+
uses: conda-incubator/setup-miniconda@v2.3.0
151+
with:
152+
activate-environment: "build"
153+
python-version: ${{ matrix.pyver }}
154+
miniforge-variant: Mambaforge
155+
miniforge-version: latest
156+
use-mamba: true
157+
add-pip-as-python-dependency: true
158+
auto-activate-base: false
159+
160+
- name: Build for CUDA
161+
if: matrix.cuda != ''
162+
run: |
163+
# --- Install CUDA using Conda
164+
165+
$cudaVersion = '${{ matrix.cuda }}'
166+
$cudaVersionPytorch = '${{ matrix.cuda }}'.Remove('${{ matrix.cuda }}'.LastIndexOf('.')).Replace('.','')
167+
168+
$cudaChannels = ''
169+
$cudaNum = [int]$cudaVersion.substring($cudaVersion.LastIndexOf('.')+1)
170+
while ($cudaNum -ge 0) { $cudaChannels += '-c nvidia/label/cuda-' + $cudaVersion.Remove($cudaVersion.LastIndexOf('.')+1) + $cudaNum + ' '; $cudaNum-- }
171+
mamba install -y 'cuda' $cudaChannels.TrimEnd().Split()
172+
173+
if (!(mamba list cuda)[-1].contains('cuda')) {sleep -s 10; mamba install -y 'cuda' $cudaChannels.TrimEnd().Split()}
174+
if (!(mamba list cuda)[-1].contains('cuda')) {throw 'CUDA Toolkit failed to install!'}
175+
176+
$env:CUDA_PATH = $env:CONDA_PREFIX
177+
$env:CUDA_HOME = $env:CONDA_PREFIX
178+
if ($IsLinux) {$env:LD_LIBRARY_PATH = $env:CONDA_PREFIX + '/lib:' + $env:LD_LIBRARY_PATH}
179+
180+
# --- Install dependencies
181+
182+
python -m pip install torch==${{ matrix.torch }} --index-url https://download.pytorch.org/whl/cu$cudaVersionPytorch
183+
python -m pip install --upgrade setuptools==65.5.1
184+
python -m pip install --upgrade build wheel safetensors sentencepiece ninja
185+
186+
# --- Build wheel
187+
188+
$BUILDTAG = "+cu$cudaVersionPytorch-torch${{ matrix.torch }}"
189+
$env:TORCH_CUDA_ARCH_LIST = '${{ matrix.cudaarch }}'
190+
python -m build -n --wheel -C--build-option=egg_info "-C--build-option=--tag-build=$BUILDTAG"
191+
192+
# Build sdist
193+
194+
- name: Build sdist
195+
if: matrix.cuda == '' && matrix.rocm == ''
196+
run: |
197+
# --- Install dependencies
198+
199+
python -m pip install torch==${{ matrix.torch }} --index-url https://download.pytorch.org/whl/cpu
200+
python -m pip install build wheel ninja
201+
202+
# --- Build wheel
203+
204+
$env:EXLLAMA_NOCOMPILE=1
205+
python -m build -n
206+
207+
# Upload files
208+
209+
- uses: actions/upload-artifact@v3
210+
if: matrix.artname == 'wheel'
211+
with:
212+
name: 'wheel'
213+
path: ./dist/*
214+
215+
- uses: actions/upload-artifact@v3
216+
if: matrix.artname == 'sdist'
217+
with:
218+
name: 'sdist'
219+
path: ./dist/*
220+
221+
- name: Upload files to GitHub release
222+
if: steps.package_version.outputs.PACKAGE_VERSION != 'None' && inputs.release == '1'
223+
uses: svenstaro/upload-release-action@2.6.1
224+
with:
225+
file: ./dist/*.whl
226+
tag: ${{ format('v{0}', steps.package_version.outputs.PACKAGE_VERSION) }}
227+
file_glob: true
228+
overwrite: true
229+
release_name: ${{ steps.package_version.outputs.PACKAGE_VERSION }}

0 commit comments

Comments
 (0)