From 99a94a30467956cd2264996e7498cbc43f83ef64 Mon Sep 17 00:00:00 2001 From: foefl Date: Thu, 12 Mar 2026 12:26:45 +0100 Subject: [PATCH] add automatic build and publishing scripts --- .gitignore | 1 + build_llama-cpp-python.bat | 66 +++++++++++++++++++++ pdm.lock | 13 +++- pyproject.toml | 2 +- scripts/publish.ps1 | 2 +- src/{py311 => llama_cpp_wheels}/__init__.py | 0 6 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 build_llama-cpp-python.bat rename src/{py311 => llama_cpp_wheels}/__init__.py (100%) diff --git a/.gitignore b/.gitignore index 21e6a91..549accc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # own +llama_cpp_python_src/ prototypes/ data/ reports/ diff --git a/build_llama-cpp-python.bat b/build_llama-cpp-python.bat new file mode 100644 index 0000000..f8556d0 --- /dev/null +++ b/build_llama-cpp-python.bat @@ -0,0 +1,66 @@ +@echo off +SETLOCAL EnableDelayedExpansion + +:: path to VS Build Tools (example for VS 2022 Community) (otherwise not found in default terminal) +set "VS_PATH=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" + +if exist "%VS_PATH%" ( + call "%VS_PATH%" +) else ( + echo [X] Setup script for Visual Studio env variables could not be found! + pause + exit /b +) + +:: --- Configuration --- +set "REPO_URL=https://github.com/abetlen/llama-cpp-python.git" +set "SOURCE_DIR=llama_cpp_python_src" +set "WHEEL_DIR=.\dist" + +:: Optional: specify CUDA architecture (e.g. "89" für RTX 1000 Ada Laptop GPU) +:: "native" architecture only possible if device is identified properly +:: see https://developer.nvidia.com/cuda/gpus for compute compatibility +:: set "CMAKE_ARGS=-DGGML_CUDA=on -DCMAKE_CUDA_ARCHITECTURES=native" +set "CMAKE_ARGS=-DGGML_CUDA=on -DCMAKE_CUDA_ARCHITECTURES='89'" +set "FORCE_CMAKE=1" +set "CMAKE_BUILD_PARALLEL_LEVEL=4" +set "MAX_JOBS=4" + +echo [*] Check source directory... + +if exist "%SOURCE_DIR%" ( + echo [*] Directory exists. Update repository... + cd "%SOURCE_DIR%" + git fetch --all + git reset --hard origin/main + git pull origin main + :: update submodules (contains the actual llama.cpp) + git submodule update --init --recursive +) else ( + echo [*] Clone repository... + git clone --recurse-submodules %REPO_URL% %SOURCE_DIR% + cd "%SOURCE_DIR%" +) + +echo [*] Start compilation und wheel generation... + +:: build wheel from current directory (.) +@REM pdm run -p ..\ python --version +@REM pdm run -p ..\ python -m pip --version +@REM pause +@REM exit /b + +pdm run -p ..\ python -m pip wheel . --wheel-dir="..\%WHEEL_DIR%" --no-cache-dir --no-deps -vv + +if %ERRORLEVEL% EQU 0 ( + echo. + echo [!] SUCCESS: Wheel with CUDA support placed in: %WHEEL_DIR% + dir "..\%WHEEL_DIR%\llama_cpp_python*.whl" +) else ( + echo. + echo [X] ERROR: Build process failed. +) + +cd .. +pause +ENDLOCAL \ No newline at end of file diff --git a/pdm.lock b/pdm.lock index f96da8b..8a411b4 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev", "lint"] strategy = ["inherit_metadata"] lock_version = "4.5.0" -content_hash = "sha256:b23e8c0ac043347792e09d8cc5ed2b185120ad3cec1a2a179842a690a9618d33" +content_hash = "sha256:281a45dbbe9fe4927e83d52f27e165b12498964c56e3d2600e5a5562ba627a23" [[metadata.targets]] requires_python = ">=3.11" @@ -423,6 +423,17 @@ files = [ {file = "pdoc3-0.11.6.tar.gz", hash = "sha256:1ea5e84b87a754d191fb64bf5e517ca6c50d0d84a614c1efecf6b46d290ae387"}, ] +[[package]] +name = "pip" +version = "26.0.1" +requires_python = ">=3.9" +summary = "The PyPA recommended tool for installing Python packages." +groups = ["default"] +files = [ + {file = "pip-26.0.1-py3-none-any.whl", hash = "sha256:bdb1b08f4274833d62c1aa29e20907365a2ceb950410df15fc9521bad440122b"}, + {file = "pip-26.0.1.tar.gz", hash = "sha256:c4037d8a277c89b320abe636d59f91e6d0922d08a05b60e85e53b296613346d8"}, +] + [[package]] name = "platformdirs" version = "4.9.4" diff --git a/pyproject.toml b/pyproject.toml index 7a74ce7..fde83ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ description = "project to build CUDA-enabled builds of Python bindings for 'llam authors = [ {name = "Florian Förster", email = "f.foerster@d-opt.com"}, ] -dependencies = [] +dependencies = ["pip>=26.0.1"] requires-python = ">=3.11" readme = "README.md" license = {text = "LicenseRef-Proprietary"} diff --git a/scripts/publish.ps1 b/scripts/publish.ps1 index d16fc9c..e1b2f7f 100644 --- a/scripts/publish.ps1 +++ b/scripts/publish.ps1 @@ -1 +1 @@ -pdm publish -r local --skip-existing \ No newline at end of file +pdm publish -r local -d .\dist --skip-existing --no-build \ No newline at end of file diff --git a/src/py311/__init__.py b/src/llama_cpp_wheels/__init__.py similarity index 100% rename from src/py311/__init__.py rename to src/llama_cpp_wheels/__init__.py