4
4
workflow_dispatch :
5
5
inputs :
6
6
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 '
9
9
required : false
10
10
type : string
11
11
workflow_call :
12
12
inputs :
13
13
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 '
16
16
required : false
17
17
type : string
18
18
19
- permissions :
20
- contents : write
21
-
22
19
jobs :
23
20
build_wheels :
24
- name : ${{ matrix.os }} ${{ matrix.pyver }}
21
+ name : Build Wheel ${{ matrix.os }} ${{ matrix.pyver }} ${{ matrix.cuda }} ${{ matrix.releasetag == 'wheels' && 'AVX2' || matrix.releasetag }}
25
22
runs-on : ${{ matrix.os }}
26
23
strategy :
27
24
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
31
32
env :
32
- CMAKE_OSX_ARCHITECTURES : ${{ matrix.arch }}
33
+ CUDAVER : ${{ matrix.cuda }}
34
+ AVXVER : ${{ matrix.releasetag }}
33
35
PCKGVER : ${{ inputs.version }}
34
36
35
37
steps :
@@ -42,17 +44,88 @@ jobs:
42
44
- uses : actions/setup-python@v4
43
45
with :
44
46
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
45
84
46
85
- name : Install Dependencies
47
86
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
49
95
50
96
- name : Build Wheel
51
97
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
+ }
54
126
55
127
- uses : actions/upload-artifact@v3
128
+ if : steps.upload-release.outcome == 'failure'
56
129
with :
57
- name : macos- wheels
130
+ name : ${{ matrix.releasetag == ' wheels' && 'AVX2' || matrix.releasetag }}
58
131
path : ./dist/*.whl
0 commit comments