1
1
name : Build Wheels test
2
2
3
- on : workflow_dispatch
3
+ on :
4
+ workflow_dispatch :
5
+ inputs :
6
+ version :
7
+ description : ' Version tag of llama-cpp-python to build: v0.2.9'
8
+ default : ' v0.2.9'
9
+ required : true
10
+ type : string
4
11
5
12
jobs :
13
+ define_matrix_main :
14
+ name : Define Build Matrix
15
+ runs-on : ubuntu-latest
16
+ outputs :
17
+ matrix : ${{ steps.set-matrix.outputs.matrix }}
18
+ defaults :
19
+ run :
20
+ shell : pwsh
21
+ env :
22
+ CONFIGIN : ' cuda:11.8.0;releasetag:basic'
23
+ EXCLUDEIN : ' pyver:3.8'
24
+
25
+ steps :
26
+ - name : Define Job Output
27
+ id : set-matrix
28
+ run : |
29
+ $matrix = @{
30
+ 'os' = 'ubuntu-20.04', 'windows-latest'
31
+ 'pyver' = "3.10", "3.8", "3.9", "3.11"
32
+ 'cuda' = "11.6.2", "11.7.1", "11.8.0", "12.0.1", "12.1.1", "12.2.0"
33
+ 'releasetag' = "AVX", "wheels", "AVX512", "basic"
34
+ }
35
+
36
+ if ($env:CONFIGIN -ne 'Default') {$env:CONFIGIN.split(';').foreach({$matrix[$_.split(':')[0]] = $_.split(':')[1].split(',')})}
37
+
38
+ if ($env:EXCLUDEIN -ne 'None') {
39
+ $exclusions = @()
40
+ $exclusions += $env:EXCLUDEIN.split(';').replace(':','=').replace(',',"`n") | ConvertFrom-StringData
41
+ $matrix['exclude'] = $exclusions
42
+ }
43
+
44
+ $matrixOut = ConvertTo-Json $matrix -Compress
45
+ Write-Output ('matrix=' + $matrixOut) >> $env:GITHUB_OUTPUT
46
+
6
47
build_wheels_main :
48
+ name : Build Wheel ${{ matrix.os }} ${{ matrix.pyver }} ${{ matrix.cuda }} ${{ matrix.releasetag == 'wheels' && 'AVX2' || matrix.releasetag }}
49
+ needs : define_matrix_main
50
+ runs-on : ${{ matrix.os }}
51
+ strategy :
52
+ matrix : ${{ fromJSON(needs.define_matrix_main.outputs.matrix) }}
53
+ defaults :
54
+ run :
55
+ shell : pwsh
56
+ env :
57
+ CUDAVER : ${{ matrix.cuda }}
58
+ AVXVER : ${{ matrix.releasetag }}
59
+ PCKGVER : ${{ inputs.version }}
60
+
61
+ steps :
62
+ - uses : actions/checkout@v4
63
+ with :
64
+ repository : ' abetlen/llama-cpp-python'
65
+ ref : ${{ inputs.version }}
66
+ submodules : ' recursive'
67
+
68
+ - uses : actions/setup-python@v4
69
+ with :
70
+ python-version : ${{ matrix.pyver }}
71
+
72
+ - name : Setup Mamba
73
+ uses : conda-incubator/setup-miniconda@v2.2.0
74
+ with :
75
+ activate-environment : " build"
76
+ python-version : ${{ matrix.pyver }}
77
+ miniforge-variant : Mambaforge
78
+ miniforge-version : latest
79
+ use-mamba : true
80
+ add-pip-as-python-dependency : true
81
+ auto-activate-base : false
82
+
83
+ - name : VS Integration Cache
84
+ id : vs-integration-cache
85
+ if : runner.os == 'Windows'
86
+ uses : actions/cache@v3.3.2
87
+ with :
88
+ path : ./MSBuildExtensions
89
+ key : cuda-${{ matrix.cuda }}-vs-integration
90
+
91
+ - name : Get Visual Studio Integration
92
+ if : runner.os == 'Windows' && steps.vs-integration-cache.outputs.cache-hit != 'true'
93
+ run : |
94
+ if ($env:CUDAVER -eq '12.1.1') {$x = '12.1.0'} else {$x = $env:CUDAVER}
95
+ $links = (Invoke-RestMethod 'https://github.com/Jimver/cuda-toolkit/raw/257a101bc5c656053b5dc220126744980ef7f5b8/src/links/windows-links.ts').Trim().split().where({$_ -ne ''})
96
+ for ($i=$q=0;$i -lt $links.count -and $q -lt 2;$i++) {if ($links[$i] -eq "'$x',") {$q++}}
97
+ Invoke-RestMethod $links[$i].Trim("'") -OutFile 'cudainstaller.zip'
98
+ & 'C:\Program Files\7-Zip\7z.exe' e cudainstaller.zip -oMSBuildExtensions -r *\MSBuildExtensions\* > $null
99
+ Remove-Item 'cudainstaller.zip'
100
+
101
+ - name : Install Visual Studio Integration
102
+ if : runner.os == 'Windows'
103
+ run : |
104
+ $y = (gi '.\MSBuildExtensions').fullname + '\*'
105
+ (gi 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\*\BuildCustomizations').fullname.foreach({cp $y $_})
106
+ $cupath = 'CUDA_PATH_V' + $env:CUDAVER.Remove($env:CUDAVER.LastIndexOf('.')).Replace('.','_')
107
+ echo "$cupath=$env:CONDA_PREFIX" >> $env:GITHUB_ENV
108
+
109
+ - name : Install Dependencies
110
+ run : |
111
+ $cudaVersion = $env:CUDAVER
112
+ $cudaChannels = ''
113
+ $cudaNum = [int]$cudaVersion.substring($cudaVersion.LastIndexOf('.')+1)
114
+ while ($cudaNum -ge 0) { $cudaChannels += '-c nvidia/label/cuda-' + $cudaVersion.Remove($cudaVersion.LastIndexOf('.')+1) + $cudaNum + ' '; $cudaNum-- }
115
+ mamba install -y 'cuda' $cudaChannels.TrimEnd().Split()
116
+ if (!(mamba list cuda)[-1].contains('cuda')) {sleep -s 10; mamba install -y 'cuda' $cudaChannels.TrimEnd().Split()}
117
+ if (!(mamba list cuda)[-1].contains('cuda')) {throw 'CUDA Toolkit failed to install!'}
118
+ python -m pip install build wheel
119
+
120
+ - name : Build Wheel
121
+ run : |
122
+ $packageVersion = [version]$env:PCKGVER.TrimStart('v')
123
+ $cudaVersion = $env:CUDAVER.Remove($env:CUDAVER.LastIndexOf('.')).Replace('.','')
124
+ $env:CUDA_PATH = $env:CONDA_PREFIX
125
+ $env:CUDA_HOME = $env:CONDA_PREFIX
126
+ if ($IsLinux) {$env:LD_LIBRARY_PATH = $env:CONDA_PREFIX + '/lib:' + $env:LD_LIBRARY_PATH}
127
+ $env:VERBOSE = '1'
128
+ $env:CMAKE_ARGS = '-DLLAMA_CUBLAS=on -DCMAKE_CUDA_ARCHITECTURES=all'
129
+ 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'}
130
+ 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'}
131
+ 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'}
132
+ if ($packageVersion -lt [version]'0.1.66') {$env:CUDAFLAGS = '-arch=all'}
133
+ if ($env:AVXVER -eq 'AVX') {$env:CMAKE_ARGS = $env:CMAKE_ARGS + ' -DLLAMA_AVX2=off -DLLAMA_FMA=off -DLLAMA_F16C=off'}
134
+ if ($env:AVXVER -eq 'AVX512') {$env:CMAKE_ARGS = $env:CMAKE_ARGS + ' -DLLAMA_AVX512=on'}
135
+ if ($env:AVXVER -eq 'basic') {$env:CMAKE_ARGS = $env:CMAKE_ARGS + ' -DLLAMA_AVX=off -DLLAMA_AVX2=off -DLLAMA_FMA=off -DLLAMA_F16C=off'}
136
+ $buildtag = "+cu$cudaVersion"
137
+ if ($packageVersion -lt [version]'0.2.0') {
138
+ $env:FORCE_CMAKE = '1'
139
+ python -m build --wheel -C--build-option=egg_info "-C--build-option=--tag-build=$buildtag"
140
+ } else {
141
+ $initpath = Join-Path '.' 'llama_cpp' '__init__.py' -resolve
142
+ $initcontent = Get-Content $initpath -raw
143
+ $regexstr = '(?s)(?<=__version__ \= ")\d+(?:\.\d+)*(?=")'
144
+ $regexmatch = [Regex]::Matches($initcontent,$regexstr)
145
+ if (!($regexmatch[0].Success)) {throw '__init__.py parsing failed'}
146
+ $newinit = $regexmatch[0].Result(('$`' + '$&' + $buildtag + '$'''))
147
+ New-Item $initpath -itemType File -value $newinit -force
148
+ python -m build --wheel
149
+ }
150
+
151
+ - uses : actions/upload-artifact@v3
152
+ with :
153
+ name : ${{ matrix.releasetag == 'wheels' && 'AVX2' || matrix.releasetag }}
154
+ path : ./dist/*.whl
155
+
156
+ define_matrix_macos :
157
+ name : Define Build Matrix
158
+ needs : build_wheels_main
159
+ runs-on : ubuntu-latest
160
+ outputs :
161
+ matrix : ${{ steps.set-matrix.outputs.matrix }}
162
+ defaults :
163
+ run :
164
+ shell : pwsh
165
+ env :
166
+ CONFIGIN : ' Default'
167
+ EXCLUDEIN : ' os:macos-13;pyver:3.11;os:macos-12,pyver:3.8'
168
+
169
+ steps :
170
+ - name : Define Job Output
171
+ id : set-matrix
172
+ run : |
173
+ $matrix = @{
174
+ 'os' = "macos-13", "macos-12", "macos-11"
175
+ 'pyver' = "3.10", "3.8", "3.9", "3.11"
176
+ }
177
+
178
+ if ($env:CONFIGIN -ne 'Default') {$env:CONFIGIN.split(';').foreach({$matrix[$_.split(':')[0]] = $_.split(':')[1].split(',')})}
179
+
180
+ if ($env:EXCLUDEIN -ne 'None') {
181
+ $exclusions = @()
182
+ $exclusions += $env:EXCLUDEIN.split(';').replace(':','=').replace(',',"`n") | ConvertFrom-StringData
183
+ $matrix['exclude'] = $exclusions
184
+ }
185
+
186
+ $matrixOut = ConvertTo-Json $matrix -Compress
187
+ Write-Output ('matrix=' + $matrixOut) >> $env:GITHUB_OUTPUT
188
+
189
+ build_wheels_macos :
7
190
name : ${{ matrix.os }} Python ${{ matrix.pyver }}
191
+ needs : define_matrix_macos
8
192
runs-on : ${{ matrix.os }}
9
193
strategy :
10
- matrix :
11
- os : [macos-13]
12
- pyver : ["3.10", "3.8", "3.9", "3.11"]
13
- pckgver : ['v0.2.5','v0.2.6','v0.2.7']
194
+ matrix : ${{ fromJSON(needs.define_matrix_macos.outputs.matrix) }}
14
195
env :
15
196
OSVER : ${{ matrix.os }}
16
197
17
198
steps :
18
199
- uses : actions/checkout@v4
19
200
with :
20
201
repository : ' abetlen/llama-cpp-python'
21
- ref : ${{ matrix.pckgver }}
202
+ ref : ${{ inputs.version }}
22
203
submodules : ' recursive'
23
204
24
205
- uses : actions/setup-python@v4
@@ -34,17 +215,27 @@ jobs:
34
215
XCODE15PATH="/Applications/Xcode_15.0.app/Contents/Developer"
35
216
XCODE15BINPATH="${XCODE15PATH}/Toolchains/XcodeDefault.xctoolchain/usr/bin"
36
217
export CMAKE_ARGS="-DLLAMA_METAL=on"
37
- export CC="${XCODE15BINPATH}/cc" && export CXX="${XCODE15BINPATH}/c++"
218
+ [[ "$OSVER" == "macos-13" ]] && export CC="${XCODE15BINPATH}/cc" && export CXX="${XCODE15BINPATH}/c++" && export MACOSX_DEPLOYMENT_TARGET="13.0"
219
+ [[ "$OSVER" == "macos-12" ]] && export MACOSX_DEPLOYMENT_TARGET="12.0"
220
+ [[ "$OSVER" == "macos-11" ]] && export MACOSX_DEPLOYMENT_TARGET="11.0"
38
221
39
222
export CMAKE_OSX_ARCHITECTURES="arm64" && export ARCHFLAGS="-arch arm64"
40
- export SDKROOT="${XCODE15PATH}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk"
41
- export MACOSX_DEPLOYMENT_TARGET="14.0"
42
223
VERBOSE=1 python -m build --wheel
43
224
225
+ if [[ "$OSVER" == "macos-13" ]]; then
226
+ export SDKROOT="${XCODE15PATH}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk"
227
+ export MACOSX_DEPLOYMENT_TARGET="14.0"
228
+ VERBOSE=1 python -m build --wheel
229
+ fi
230
+
44
231
export CMAKE_OSX_ARCHITECTURES="x86_64" && export CMAKE_ARGS="-DLLAMA_AVX=off -DLLAMA_AVX2=off -DLLAMA_FMA=off -DLLAMA_F16C=off -DLLAMA_METAL=on" && export ARCHFLAGS="-arch x86_64"
45
- export SDKROOT="${XCODE15PATH}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk"
46
- export MACOSX_DEPLOYMENT_TARGET="14.0"
47
232
VERBOSE=1 python -m build --wheel
233
+
234
+ if [[ "$OSVER" == "macos-13" ]]; then
235
+ export SDKROOT="${XCODE15PATH}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk"
236
+ export MACOSX_DEPLOYMENT_TARGET="14.0"
237
+ VERBOSE=1 python -m build --wheel
238
+ fi
48
239
49
240
- uses : actions/upload-artifact@v3
50
241
with :
0 commit comments