Skip to content

Commit

Permalink
Update test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jllllll committed Sep 17, 2023
1 parent eb5021f commit 8bfb842
Showing 1 changed file with 15 additions and 90 deletions.
105 changes: 15 additions & 90 deletions .github/workflows/build-wheels-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,128 +4,53 @@ on:
workflow_dispatch:
inputs:
version:
description: 'Version tag of llama-cpp-python to build: v0.2.2'
default: 'v0.2.2'
description: 'Version tag of llama-cpp-python to build: v0.2.6'
default: 'v0.2.6'
required: false
type: string
workflow_call:
inputs:
version:
description: 'Version tag of llama-cpp-python to build: v0.2.2'
default: 'v0.2.2'
description: 'Version tag of llama-cpp-python to build: v0.2.6'
default: 'v0.2.6'
required: false
type: string

jobs:
build_wheels:
name: Build Wheel ${{ matrix.os }} ${{ matrix.pyver }} ${{ matrix.cuda }} ${{ matrix.releasetag == 'wheels' && 'AVX2' || matrix.releasetag }}
build_wheels_main:
name: ${{ matrix.os }} ${{ matrix.pyver }} ${{ matrix.avx }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, windows-latest]
os: [macos-13, macos-12, macos-11]
arch: ["x86_64","arm64"]
pyver: ["3.10"]
cuda: ["11.7.1"]
releasetag: ["wheels"]
defaults:
run:
shell: pwsh
env:
CUDAVER: ${{ matrix.cuda }}
AVXVER: ${{ matrix.releasetag }}
CMAKE_OSX_ARCHITECTURES: ${{ matrix.arch }}
PCKGVER: ${{ inputs.version }}

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
with:
repository: 'abetlen/llama-cpp-python'
ref: ${{ inputs.version }}
submodules: 'recursive'

- uses: actions/setup-python@v4
- uses: actions/setup-python@v3
with:
python-version: ${{ matrix.pyver }}

- name: Setup Mamba
uses: conda-incubator/setup-miniconda@v2.2.0
with:
activate-environment: "build"
python-version: ${{ matrix.pyver }}
miniforge-variant: Mambaforge
miniforge-version: latest
use-mamba: true
add-pip-as-python-dependency: true
auto-activate-base: false

- name: VS Integration Cache
id: vs-integration-cache
if: runner.os == 'Windows'
uses: actions/cache@v3.3.2
with:
path: ./MSBuildExtensions
key: cuda-${{ matrix.cuda }}-vs-integration

- name: Get Visual Studio Integration
if: runner.os == 'Windows' && steps.vs-integration-cache.outputs.cache-hit != 'true'
run: |
if ($env:CUDAVER -eq '12.1.1') {$x = '12.1.0'} else {$x = $env:CUDAVER}
$links = (Invoke-RestMethod 'https://github.com/Jimver/cuda-toolkit/raw/257a101bc5c656053b5dc220126744980ef7f5b8/src/links/windows-links.ts').Trim().split().where({$_ -ne ''})
for ($i=$q=0;$i -lt $links.count -and $q -lt 2;$i++) {if ($links[$i] -eq "'$x',") {$q++}}
Invoke-RestMethod $links[$i].Trim("'") -OutFile 'cudainstaller.zip'
& 'C:\Program Files\7-Zip\7z.exe' e cudainstaller.zip -oMSBuildExtensions -r *\MSBuildExtensions\* > $null
Remove-Item 'cudainstaller.zip'
- name: Install Visual Studio Integration
if: runner.os == 'Windows'
run: |
$y = (gi '.\MSBuildExtensions').fullname + '\*'
(gi 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\*\BuildCustomizations').fullname.foreach({cp $y $_})
$cupath = 'CUDA_PATH_V' + $env:CUDAVER.Remove($env:CUDAVER.LastIndexOf('.')).Replace('.','_')
echo "$cupath=$env:CONDA_PREFIX" >> $env:GITHUB_ENV

- name: Install Dependencies
run: |
$cudaVersion = $env:CUDAVER
$cudaChannels = ''
$cudaNum = [int]$cudaVersion.substring($cudaVersion.LastIndexOf('.')+1)
while ($cudaNum -ge 0) { $cudaChannels += '-c nvidia/label/cuda-' + $cudaVersion.Remove($cudaVersion.LastIndexOf('.')+1) + $cudaNum + ' '; $cudaNum-- }
mamba install -y 'cuda' $cudaChannels.TrimEnd().Split()
if (!(mamba list cuda)[-1].contains('cuda')) {sleep -s 10; mamba install -y 'cuda' $cudaChannels.TrimEnd().Split()}
if (!(mamba list cuda)[-1].contains('cuda')) {throw 'CUDA Toolkit failed to install!'}
python -m pip install build wheel
python -m pip install build wheel cmake
- name: Build Wheel
run: |
$packageVersion = [version]$env:PCKGVER.TrimStart('v')
$cudaVersion = $env:CUDAVER.Remove($env:CUDAVER.LastIndexOf('.')).Replace('.','')
$env:CUDA_PATH = $env:CONDA_PREFIX
$env:CUDA_HOME = $env:CONDA_PREFIX
if ($IsLinux) {$env:LD_LIBRARY_PATH = $env:CONDA_PREFIX + '/lib:' + $env:LD_LIBRARY_PATH}
$env:VERBOSE = '1'
$env:CMAKE_ARGS = '-DLLAMA_CUBLAS=on -DCMAKE_CUDA_ARCHITECTURES=all'
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'}
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'}
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'}
if ($packageVersion -lt [version]'0.1.66') {$env:CUDAFLAGS = '-arch=all'}
if ($env:AVXVER -eq 'AVX') {$env:CMAKE_ARGS = $env:CMAKE_ARGS + ' -DLLAMA_AVX2=off -DLLAMA_FMA=off -DLLAMA_F16C=off'}
if ($env:AVXVER -eq 'AVX512') {$env:CMAKE_ARGS = $env:CMAKE_ARGS + ' -DLLAMA_AVX512=on'}
if ($env:AVXVER -eq 'basic') {$env:CMAKE_ARGS = $env:CMAKE_ARGS + ' -DLLAMA_AVX=off -DLLAMA_AVX2=off -DLLAMA_FMA=off -DLLAMA_F16C=off'}
$buildtag = "+cu$cudaVersion"
if ($packageVersion -lt [version]'0.2.0') {
$env:FORCE_CMAKE = '1'
python -m build --wheel -C--build-option=egg_info "-C--build-option=--tag-build=$buildtag"
} else {
$initpath = Join-Path '.' 'llama_cpp' '__init__.py' -resolve
$initcontent = Get-Content $initpath -raw
$regexstr = '(?s)(?<=__version__ \= ")\d+(?:\.\d+)*(?=")'
$regexmatch = [Regex]::Matches($initcontent,$regexstr)
if (!($regexmatch[0].Success)) {throw '__init__.py parsing failed'}
$newinit = $regexmatch[0].Result(('$`' + '$&' + $buildtag + '$'''))
New-Item $initpath -itemType File -value $newinit -force
python -m build --wheel
}
export CMAKE_ARGS="-DLLAMA_METAL=on"
CMAKE_ARGS="-DLLAMA_METAL=on" VERBOSE=1 python -m build --wheel
- uses: actions/upload-artifact@v3
if: steps.upload-release.outcome == 'failure'
with:
name: ${{ matrix.releasetag == 'wheels' && 'AVX2' || matrix.releasetag }}
name: ${{ format('wheel-{0}-{1}', matrix.os, matrix.arch) }}
path: ./dist/*.whl

0 comments on commit 8bfb842

Please sign in to comment.