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 13, 2023
1 parent f1ea4fc commit ffab2ff
Showing 1 changed file with 110 additions and 13 deletions.
123 changes: 110 additions & 13 deletions .github/workflows/build-wheels-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ on:
workflow_dispatch:
inputs:
version:
description: 'Version tag of llama-cpp-python to build: v0.1.83'
default: 'v0.1.83'
description: 'Version tag of llama-cpp-python to build: v0.2.2'
default: 'v0.2.2'
required: false
type: string
workflow_call:
inputs:
version:
description: 'Version tag of llama-cpp-python to build: v0.1.83'
default: 'v0.1.83'
description: 'Version tag of llama-cpp-python to build: v0.2.2'
default: 'v0.2.2'
required: false
type: string

Expand All @@ -21,16 +21,25 @@ permissions:

jobs:
build_wheels:
name: ${{ matrix.os }} ${{ matrix.pyver }}
name: Build ${{ matrix.os }} ROCm ${{ matrix.rocm }} Wheel ${{ matrix.pyver }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-13]
pyver: ["3.10", "3.8", "3.9", "3.11"]
arch: ["x86_64","arm64"]
os: [ubuntu-20.04, windows-latest]
pyver: ["3.10"]
rocm: ['5.4.2','5.5.1']
rename: ['0', '1']
exclude:
- os: windows-latest
rocm: '5.4.2'
- os: ubuntu-20.04
rocm: '5.5.1'
defaults:
run:
shell: pwsh
env:
CMAKE_OSX_ARCHITECTURES: ${{ matrix.arch }}
PCKGVER: ${{ inputs.version }}
ROCM_VERSION: ${{ matrix.rocm }}

steps:
- uses: actions/checkout@v4
Expand All @@ -39,20 +48,108 @@ jobs:
ref: ${{ inputs.version }}
submodules: 'recursive'

- name: Free Disk Space
if: runner.os == 'Linux'
uses: jlumbroso/free-disk-space@v1.2.0
with:
tool-cache: false
android: true
dotnet: true
haskell: true
large-packages: false
swap-storage: false

- name: Install Linux ROCm SDK
if: runner.os == 'Linux'
run: |
[ ! -d /etc/apt/keyrings ] && sudo mkdir --parents --mode=0755 /etc/apt/keyrings
wget https://repo.radeon.com/rocm/rocm.gpg.key -O - | gpg --dearmor | sudo tee /etc/apt/keyrings/rocm.gpg > /dev/null
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
echo -e 'Package: *\nPin: release o=repo.radeon.com\nPin-Priority: 600' | sudo tee /etc/apt/preferences.d/rocm-pin-600
sudo apt update
sudo apt install rocm-dev rocblas-dev hipblas-dev -y
echo "/opt/rocm/bin" >> $env:GITHUB_PATH
echo "ROCM_PATH=/opt/rocm" >> $env:$GITHUB_ENV
echo "HIP_PATH=/opt/rocm" >> $env:GITHUB_ENV
shell: bash

- name: Install Windows ROCm SDK
if: runner.os == 'Windows'
run: |
curl -LO https://download.amd.com/developer/eula/rocm-hub/AMD-Software-PRO-Edition-23.Q3-Win10-Win11-For-HIP.exe
Start-Process 'AMD-Software-PRO-Edition-23.Q3-Win10-Win11-For-HIP.exe' -ArgumentList '-install' -NoNewWindow -Wait
echo "C:\Program Files\AMD\ROCm\5.5\bin" >> $env:GITHUB_PATH
echo 'ROCM_PATH=C:\Program Files\AMD\ROCm\5.5' >> $env:GITHUB_ENV
echo 'HIP_PATH=C:\Program Files\AMD\ROCm\5.5' >> $env:GITHUB_ENV
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.pyver }}

- name: Install Dependencies
run: |
python -m pip install build wheel cmake
python -m pip install build wheel cmake scikit-build ninja
- name: Change Package Name
if: matrix.rename == '1'
run: |
$packageVersion = [version]$env:PCKGVER.TrimStart('v')
$pyproject = Get-Content 'pyproject.toml' -raw
$cmakelists = Get-Content 'CMakeLists.txt' -raw
if ($packageVersion -lt [version]'0.2.0') {
$setup = Get-Content 'setup.py' -raw
$regexstr = '(?s)name="llama_cpp_python",(.+)(package_dir={"llama_cpp": "llama_cpp", "llama_cpp.server": "llama_cpp/server"},.+?packages=\["llama_cpp", "llama_cpp.server"],)'
if ($packageVersion -gt [version]'0.1.77') {$regexstr = '(?s)name="llama_cpp_python",(.+)(package_dir={"llama_cpp": "llama_cpp", "llama_cpp.server": "llama_cpp/server"},.+?package_data={"llama_cpp": \["py.typed"]},.+?packages=\["llama_cpp", "llama_cpp.server"],)'}
$regexmatch = [Regex]::Matches($setup,$regexstr)
if (!($regexmatch[0].Success)) {throw 'setup.py parsing failed'}
$newstr = 'name="llama_cpp_python_cuda",' + $regexmatch[0].Groups[1].Value + $regexmatch[0].Groups[2].Value.Replace('llama_cpp','llama_cpp_cuda')
$newsetup = $regexmatch[0].Result(('$`'+$newstr+'$'''))
New-Item 'setup.py' -itemType File -value $newsetup -force
$regexstr = '(?s)(?<=name = ")llama_cpp_python(".+?packages = \[{include = ")llama_cpp(".+)'
$regexmatch = [Regex]::Matches($pyproject,$regexstr)
if (!($regexmatch[0].Success)) {throw 'pyproject.toml parsing failed'}
$newpyproject = $regexmatch[0].Result(('$`'+'llama_cpp_python_cuda'+'$1llama_cpp_cuda$2'))
} else {
$regexstr = '(?s)(?<=\[project]\s+?name = ")llama_cpp_python(".+?all = \[\s+?")llama_cpp_python(\[.+?wheel.packages = \[")llama_cpp("].+?input = ")llama_cpp(?=/__init__.py")'
$regexmatch = [Regex]::Matches($pyproject,$regexstr)
if (!($regexmatch[0].Success)) {throw 'pyproject.toml parsing failed'}
$newpyproject = $regexmatch[0].Result(('$`' + 'llama_cpp_python_cuda' + '$1llama_cpp_cuda$2' + 'llama_cpp_cuda$3llama_cpp_cuda' + '$'''))
}
Copy-Item 'llama_cpp' 'llama_cpp_cuda' -recurse
New-Item 'pyproject.toml' -itemType File -value $newpyproject -force
New-Item 'CMakeLists.txt' -itemType File -value $cmakelists.Replace('llama_cpp','llama_cpp_cuda') -force
- name: Build Wheel
run: |
export CMAKE_ARGS="-DCMAKE_SYSTEM_PROCESSOR=$CMAKE_OSX_ARCHITECTURES -DLLAMA_METAL=on"
NPY_BLAS_ORDER='accelerate' NPY_LAPACK_ORDER='accelerate' FORCE_CMAKE=1 VERBOSE=1 python -m build --wheel
if ($IsLinux) {
$env:CC = '/opt/rocm/llvm/bin/clang'
$env:CXX = '/opt/rocm/llvm/bin/clang++'
$env:CMAKE_PREFIX_PATH = '/opt/rocm'
} else {
$env:CC = 'C:\Program Files\AMD\ROCm\5.5\bin\clang.exe'
$env:CXX = 'C:\Program Files\AMD\ROCm\5.5\bin\clang++.exe'
$env:CMAKE_PREFIX_PATH = 'C:\Program Files\AMD\ROCm\5.5'
}
$env:VERBOSE = '1'
$packageVersion = [version]$env:PCKGVER.TrimStart('v')
$gputargets = 'gfx803;gfx900;gfx906:xnack-;gfx908:xnack-;gfx90a:xnack+;gfx90a:xnack-;gfx1010;gfx1012;gfx1030;gfx1100;gfx1101;gfx1102'
if ([version]$env:ROCM_VERSION -lt [version]'5.5') {$gputargets = 'gfx803;gfx900;gfx906:xnack-;gfx908:xnack-;gfx90a:xnack+;gfx90a:xnack-;gfx1010;gfx1012;gfx1030'}
$env:CMAKE_ARGS = "-GNinja -DLLAMA_HIPBLAS=ON -DGPU_TARGETS=$gputargets"
$buildtag = "+rocm$env:ROCM_VERSION"
if ($packageVersion -lt [version]'0.2.0') {
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
}
- uses: actions/upload-artifact@v3
with:
name: macos-wheels
name: 'rocm-wheels'
path: ./dist/*.whl

0 comments on commit ffab2ff

Please sign in to comment.