Skip to content

Commit a29e5f0

Browse files
committed
Update test workflow
1 parent f1ea4fc commit a29e5f0

File tree

1 file changed

+89
-16
lines changed

1 file changed

+89
-16
lines changed

.github/workflows/build-wheels-test.yml

Lines changed: 89 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,34 @@ on:
44
workflow_dispatch:
55
inputs:
66
version:
7-
description: 'Version tag of llama-cpp-python to build: v0.1.83'
8-
default: 'v0.1.83'
7+
description: 'Version tag of llama-cpp-python to build: v0.2.2'
8+
default: 'v0.2.2'
99
required: false
1010
type: string
1111
workflow_call:
1212
inputs:
1313
version:
14-
description: 'Version tag of llama-cpp-python to build: v0.1.83'
15-
default: 'v0.1.83'
14+
description: 'Version tag of llama-cpp-python to build: v0.2.2'
15+
default: 'v0.2.2'
1616
required: false
1717
type: string
1818

19-
permissions:
20-
contents: write
21-
2219
jobs:
2320
build_wheels:
24-
name: ${{ matrix.os }} ${{ matrix.pyver }}
21+
name: Build Wheel ${{ matrix.os }} ${{ matrix.pyver }} ${{ matrix.cuda }} ${{ matrix.releasetag == 'wheels' && 'AVX2' || matrix.releasetag }}
2522
runs-on: ${{ matrix.os }}
2623
strategy:
2724
matrix:
28-
os: [macos-13]
29-
pyver: ["3.10", "3.8", "3.9", "3.11"]
30-
arch: ["x86_64","arm64"]
25+
os: [ubuntu-20.04, windows-latest]
26+
pyver: ["3.10"]
27+
cuda: ["11.7.1"]
28+
releasetag: ["wheels"]
29+
defaults:
30+
run:
31+
shell: pwsh
3132
env:
32-
CMAKE_OSX_ARCHITECTURES: ${{ matrix.arch }}
33+
CUDAVER: ${{ matrix.cuda }}
34+
AVXVER: ${{ matrix.releasetag }}
3335
PCKGVER: ${{ inputs.version }}
3436

3537
steps:
@@ -42,17 +44,88 @@ jobs:
4244
- uses: actions/setup-python@v4
4345
with:
4446
python-version: ${{ matrix.pyver }}
47+
48+
- name: Setup Mamba
49+
uses: conda-incubator/setup-miniconda@v2.2.0
50+
with:
51+
activate-environment: "build"
52+
python-version: ${{ matrix.pyver }}
53+
miniforge-variant: Mambaforge
54+
miniforge-version: latest
55+
use-mamba: true
56+
add-pip-as-python-dependency: true
57+
auto-activate-base: false
58+
59+
- name: VS Integration Cache
60+
id: vs-integration-cache
61+
if: runner.os == 'Windows'
62+
uses: actions/cache@v3.3.2
63+
with:
64+
path: ./MSBuildExtensions
65+
key: cuda-${{ matrix.cuda }}-vs-integration
66+
67+
- name: Get Visual Studio Integration
68+
if: runner.os == 'Windows' && steps.vs-integration-cache.outputs.cache-hit != 'true'
69+
run: |
70+
if ($env:CUDAVER -eq '12.1.1') {$x = '12.1.0'} else {$x = $env:CUDAVER}
71+
$links = (Invoke-RestMethod 'https://github.com/Jimver/cuda-toolkit/raw/257a101bc5c656053b5dc220126744980ef7f5b8/src/links/windows-links.ts').Trim().split().where({$_ -ne ''})
72+
for ($i=$q=0;$i -lt $links.count -and $q -lt 2;$i++) {if ($links[$i] -eq "'$x',") {$q++}}
73+
Invoke-RestMethod $links[$i].Trim("'") -OutFile 'cudainstaller.zip'
74+
& 'C:\Program Files\7-Zip\7z.exe' e cudainstaller.zip -oMSBuildExtensions -r *\MSBuildExtensions\* > $null
75+
Remove-Item 'cudainstaller.zip'
76+
77+
- name: Install Visual Studio Integration
78+
if: runner.os == 'Windows'
79+
run: |
80+
$y = (gi '.\MSBuildExtensions').fullname + '\*'
81+
(gi 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\*\BuildCustomizations').fullname.foreach({cp $y $_})
82+
$cupath = 'CUDA_PATH_V' + $env:CUDAVER.Remove($env:CUDAVER.LastIndexOf('.')).Replace('.','_')
83+
echo "$cupath=$env:CONDA_PREFIX" >> $env:GITHUB_ENV
4584
4685
- name: Install Dependencies
4786
run: |
48-
python -m pip install build wheel cmake
87+
$cudaVersion = $env:CUDAVER
88+
$cudaChannels = ''
89+
$cudaNum = [int]$cudaVersion.substring($cudaVersion.LastIndexOf('.')+1)
90+
while ($cudaNum -ge 0) { $cudaChannels += '-c nvidia/label/cuda-' + $cudaVersion.Remove($cudaVersion.LastIndexOf('.')+1) + $cudaNum + ' '; $cudaNum-- }
91+
mamba install -y 'cuda' $cudaChannels.TrimEnd().Split()
92+
if (!(mamba list cuda)[-1].contains('cuda')) {sleep -s 10; mamba install -y 'cuda' $cudaChannels.TrimEnd().Split()}
93+
if (!(mamba list cuda)[-1].contains('cuda')) {throw 'CUDA Toolkit failed to install!'}
94+
python -m pip install build wheel
4995
5096
- name: Build Wheel
5197
run: |
52-
export CMAKE_ARGS="-DCMAKE_SYSTEM_PROCESSOR=$CMAKE_OSX_ARCHITECTURES -DLLAMA_METAL=on"
53-
NPY_BLAS_ORDER='accelerate' NPY_LAPACK_ORDER='accelerate' FORCE_CMAKE=1 VERBOSE=1 python -m build --wheel
98+
$packageVersion = [version]$env:PCKGVER.TrimStart('v')
99+
$cudaVersion = $env:CUDAVER.Remove($env:CUDAVER.LastIndexOf('.')).Replace('.','')
100+
$env:CUDA_PATH = $env:CONDA_PREFIX
101+
$env:CUDA_HOME = $env:CONDA_PREFIX
102+
if ($IsLinux) {$env:LD_LIBRARY_PATH = $env:CONDA_PREFIX + '/lib:' + $env:LD_LIBRARY_PATH}
103+
$env:VERBOSE = '1'
104+
$env:CMAKE_ARGS = '-DLLAMA_CUBLAS=on -DCMAKE_CUDA_ARCHITECTURES=all'
105+
if ($packageVersion -gt [version]'0.1.68' -and $packageVersion -lt [version]'0.1.71') {$env:CMAKE_ARGS = '-DLLAMA_CUBLAS=on -DCMAKE_CUDA_ARCHITECTURES=35-real;37-real;52;61-real;70-real;72-real;75-real;80-real;86-real;89-real;90'}
106+
if ($packageVersion -gt [version]'0.1.68' -and $packageVersion -lt [version]'0.1.71' -and [version]$env:CUDAVER -ge [version]'12.0') {$env:CMAKE_ARGS = '-DLLAMA_CUBLAS=on -DCMAKE_CUDA_ARCHITECTURES=52;61-real;70-real;72-real;75-real;80-real;86-real;89-real;90'}
107+
if ($packageVersion -gt [version]'0.1.68' -and $packageVersion -lt [version]'0.1.71' -and [version]$env:CUDAVER -lt [version]'11.8') {$env:CMAKE_ARGS = '-DLLAMA_CUBLAS=on -DCMAKE_CUDA_ARCHITECTURES=35-real;37-real;52;61-real;70-real;72-real;75-real;80-real;86'}
108+
if ($packageVersion -lt [version]'0.1.66') {$env:CUDAFLAGS = '-arch=all'}
109+
if ($env:AVXVER -eq 'AVX') {$env:CMAKE_ARGS = $env:CMAKE_ARGS + ' -DLLAMA_AVX2=off -DLLAMA_FMA=off -DLLAMA_F16C=off'}
110+
if ($env:AVXVER -eq 'AVX512') {$env:CMAKE_ARGS = $env:CMAKE_ARGS + ' -DLLAMA_AVX512=on'}
111+
if ($env:AVXVER -eq 'basic') {$env:CMAKE_ARGS = $env:CMAKE_ARGS + ' -DLLAMA_AVX=off -DLLAMA_AVX2=off -DLLAMA_FMA=off -DLLAMA_F16C=off'}
112+
$buildtag = "+cu$cudaVersion"
113+
if ($packageVersion -lt [version]'0.2.0') {
114+
$env:FORCE_CMAKE = '1'
115+
python -m build --wheel -C--build-option=egg_info "-C--build-option=--tag-build=$buildtag"
116+
} else {
117+
$initpath = Join-Path '.' 'llama_cpp' '__init__.py' -resolve
118+
$initcontent = Get-Content $initpath -raw
119+
$regexstr = '(?s)(?<=__version__ \= ")\d+(?:\.\d+)*(?=")'
120+
$regexmatch = [Regex]::Matches($initcontent,$regexstr)
121+
if (!($regexmatch[0].Success)) {throw '__init__.py parsing failed'}
122+
$newinit = $regexmatch[0].Result(('$`' + '$&' + $buildtag + '$'''))
123+
New-Item $initpath -itemType File -value $newinit -force
124+
python -m build --wheel
125+
}
54126
55127
- uses: actions/upload-artifact@v3
128+
if: steps.upload-release.outcome == 'failure'
56129
with:
57-
name: macos-wheels
130+
name: ${{ matrix.releasetag == 'wheels' && 'AVX2' || matrix.releasetag }}
58131
path: ./dist/*.whl

0 commit comments

Comments
 (0)