From 734545677933fe36c84401e4c8b3918eb0293019 Mon Sep 17 00:00:00 2001 From: Andrei Betlen Date: Thu, 8 Jun 2023 21:49:42 -0400 Subject: [PATCH 1/6] Migrate to scikit-build-core --- .github/workflows/build-and-release.yaml | 12 ++--- .github/workflows/build-docker.yaml | 39 ----------------- .github/workflows/publish-to-test.yaml | 30 ------------- .github/workflows/publish.yaml | 4 +- .github/workflows/test.yaml | 18 ++++---- CMakeLists.txt | 2 +- Makefile | 23 ++++++---- pyproject.toml | 56 +++++++++++++++++------- setup.py | 32 -------------- 9 files changed, 73 insertions(+), 143 deletions(-) delete mode 100644 .github/workflows/build-docker.yaml delete mode 100644 .github/workflows/publish-to-test.yaml delete mode 100644 setup.py diff --git a/.github/workflows/build-and-release.yaml b/.github/workflows/build-and-release.yaml index 2c0ca4a..1a9c192 100644 --- a/.github/workflows/build-and-release.yaml +++ b/.github/workflows/build-and-release.yaml @@ -22,14 +22,15 @@ jobs: - uses: actions/setup-python@v3 - name: Install cibuildwheel - run: python -m pip install cibuildwheel==2.12.1 + run: python3 -m pip install cibuildwheel==2.12.1 - name: Install dependencies run: | - python -m pip install --upgrade pip pytest cmake scikit-build setuptools + python3 -m pip install --upgrade pip + python3 -m pip install --verbose --editable . - name: Build wheels - run: python -m cibuildwheel --output-dir wheelhouse + run: python3 -m cibuildwheel --output-dir wheelhouse - uses: actions/upload-artifact@v3 with: @@ -46,10 +47,11 @@ jobs: - uses: actions/setup-python@v3 - name: Install dependencies run: | - python -m pip install --upgrade pip pytest cmake scikit-build setuptools + python3 -m pip install --upgrade pip build + python3 -m pip install --verbose --editable . - name: Build source distribution run: | - python setup.py sdist + python3 -m build --sdist - uses: actions/upload-artifact@v3 with: path: ./dist/*.tar.gz diff --git a/.github/workflows/build-docker.yaml b/.github/workflows/build-docker.yaml deleted file mode 100644 index 16b00a2..0000000 --- a/.github/workflows/build-docker.yaml +++ /dev/null @@ -1,39 +0,0 @@ -name: Build Docker - -on: workflow_dispatch - -permissions: - contents: write - packages: write - -jobs: - docker: - name: Build and push Docker image - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - submodules: "true" - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v4 - with: - context: . - push: true # push to registry - pull: true # always fetch the latest base images - platforms: linux/amd64,linux/arm64 # build for both amd64 and arm64 - tags: ghcr.io/abetlen/llama-cpp-python:latest \ No newline at end of file diff --git a/.github/workflows/publish-to-test.yaml b/.github/workflows/publish-to-test.yaml deleted file mode 100644 index 5a9f339..0000000 --- a/.github/workflows/publish-to-test.yaml +++ /dev/null @@ -1,30 +0,0 @@ -# Based on: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ - -name: Publish to TestPyPI - -on: workflow_dispatch - -jobs: - build-n-publish: - name: Build and publish - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - with: - submodules: "true" - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.8" - - name: Install dependencies - run: | - python -m pip install --upgrade pip pytest cmake scikit-build setuptools - - name: Build source distribution - run: | - python setup.py sdist - - name: Publish to Test PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - password: ${{ secrets.TEST_PYPI_API_TOKEN }} - repository-url: https://test.pypi.org/legacy/ \ No newline at end of file diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index ddefd68..9a84fea 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -19,10 +19,10 @@ jobs: python-version: "3.8" - name: Install dependencies run: | - python -m pip install --upgrade pip pytest cmake scikit-build setuptools + python3 -m pip install --upgrade pip build - name: Build source distribution run: | - python setup.py sdist + python3 -m build --sdist - name: Publish distribution to PyPI # TODO: move to tag based releases # if: startsWith(github.ref, 'refs/tags') diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 56524e0..8dcd3ef 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -26,11 +26,11 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - python -m pip install --upgrade pip pytest cmake scikit-build setuptools fastapi sse-starlette httpx uvicorn - pip install . -v + python3 -m pip install --upgrade pip + python3 -m pip install --verbose --editable .[server,test] - name: Test with pytest run: | - pytest + python3 -m pytest build-windows: @@ -49,11 +49,11 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - python -m pip install --upgrade pip pytest cmake scikit-build setuptools fastapi sse-starlette httpx uvicorn - pip install . -v + python3 -m pip install --upgrade pip + python3 -m pip install --verbose --editable .[server,test] - name: Test with pytest run: | - pytest + python3 -m pytest build-macos: @@ -72,8 +72,8 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - python -m pip install --upgrade pip pytest cmake scikit-build setuptools fastapi sse-starlette httpx uvicorn - pip install . -v + python3 -m pip install --upgrade pip + python3 -m pip install --verbose --editable .[server,test] - name: Test with pytest run: | - pytest \ No newline at end of file + python3 -m pytest \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index e5fac6a..3255053 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ if (UNIX AND NOT FORCE_CMAKE) ) install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/vendor/llama.cpp/libllama.so - DESTINATION llama_cpp + DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/llama_cpp ) else() set(BUILD_SHARED_LIBS "On") diff --git a/Makefile b/Makefile index d2f38da..3443698 100644 --- a/Makefile +++ b/Makefile @@ -1,30 +1,38 @@ update: poetry install + python3 -m pip install --upgrade pip git submodule update --init --recursive update.vendor: cd vendor/llama.cpp && git pull origin master build: - python3 setup.py develop + python3 -m pip install --upgrade pip + python3 -m pip install --verbose --editable . build.cuda: - CMAKE_ARGS="-DLLAMA_CUBLAS=on" FORCE_CMAKE=1 python3 setup.py develop + python3 -m pip install --upgrade pip + CMAKE_ARGS="-DLLAMA_CUBLAS=on" FORCE_CMAKE=1 python3 -m pip install --verbose --editable . build.opencl: - CMAKE_ARGS="-DLLAMA_CLBLAST=on" FORCE_CMAKE=1 python3 setup.py develop + python3 -m pip install --upgrade pip + CMAKE_ARGS="-DLLAMA_CLBLAST=on" FORCE_CMAKE=1 python3 -m pip install --verbose --editable . build.openblas: - CMAKE_ARGS="-DLLAMA_OPENBLAS=on" FORCE_CMAKE=1 python3 setup.py develop + python3 -m pip install --upgrade pip + CMAKE_ARGS="-DLLAMA_OPENBLAS=on" FORCE_CMAKE=1 python3 -m pip install --verbose --editable . build.blis: - CMAKE_ARGS="-DLLAMA_OPENBLAS=on -DLLAMA_OPENBLAS_VENDOR=blis" FORCE_CMAKE=1 python3 setup.py develop + python3 -m pip install --upgrade pip + CMAKE_ARGS="-DLLAMA_OPENBLAS=on -DLLAMA_OPENBLAS_VENDOR=blis" FORCE_CMAKE=1 python3 -m pip install --verbose --editable . build.metal: - CMAKE_ARGS="-DLLAMA_METAL=on" FORCE_CMAKE=1 python3 setup.py develop + python3 -m pip install --upgrade pip + CMAKE_ARGS="-DLLAMA_METAL=on" FORCE_CMAKE=1 python3 -m pip install --verbose --editable . build.sdist: - python3 setup.py sdist + python3 -m pip install --upgrade pip build + python3 -m build --sdist deploy.pypi: python3 -m twine upload dist/* @@ -36,7 +44,6 @@ deploy.gh-docs: clean: - cd vendor/llama.cpp && make clean - cd vendor/llama.cpp && rm libllama.so - - rm -rf _skbuild - rm llama_cpp/*.so - rm llama_cpp/*.dylib - rm llama_cpp/*.dll diff --git a/pyproject.toml b/pyproject.toml index 05c9271..3017d5c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,16 +1,47 @@ -[tool.poetry] +[build-system] +requires = [ + "scikit-build-core>=0.4.4", + "cmake>=3.18", + "ninja", +] +build-backend = "scikit_build_core.build" + +[project] name = "llama_cpp_python" version = "0.1.59" description = "Python bindings for the llama.cpp library" -authors = ["Andrei Betlen "] -license = "MIT" readme = "README.md" -homepage = "https://github.com/abetlen/llama-cpp-python" -repository = "https://github.com/abetlen/llama-cpp-python" -packages = [{include = "llama_cpp"}] -include = [ - "LICENSE.md", +license = { text = "MIT" } +authors = [ + { name = "Andrei Betlen", email = "abetlen@gmail.com" }, ] +requires-python = ">=3.7" +dependencies = [ + "typing-extensions>=4.5.0", + "numpy>=1.20.0", + "diskcache>=5.6.1", +] +classifiers = [ + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", +] + +[tool.scikit-build] +wheel.packages = ["llama_cpp", "llama_cpp.server"] +wheel.expand-macos-universal-tags = true +cmake.verbose = true + +[project.optional-dependencies] +server = [ + "uvicorn>=0.21.1", + "fastapi>=0.95.0", + "sse-starlette>=1.3.3", +] +test = ["pytest"] [tool.poetry.dependencies] python = "^3.8.1" @@ -33,12 +64,3 @@ scikit-build = "0.17.6" [tool.poetry.extras] server = ["uvicorn", "fastapi", "sse-starlette"] - -[build-system] -requires = [ - "setuptools>=42", - "scikit-build>=0.13", - "cmake>=3.18", - "ninja", -] -build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py deleted file mode 100644 index 20ebc95..0000000 --- a/setup.py +++ /dev/null @@ -1,32 +0,0 @@ -from skbuild import setup - -from pathlib import Path - -this_directory = Path(__file__).parent -long_description = (this_directory / "README.md").read_text(encoding="utf-8") - -setup( - name="llama_cpp_python", - description="A Python wrapper for llama.cpp", - long_description=long_description, - long_description_content_type="text/markdown", - version="0.1.59", - author="Andrei Betlen", - author_email="abetlen@gmail.com", - license="MIT", - package_dir={"llama_cpp": "llama_cpp", "llama_cpp.server": "llama_cpp/server"}, - packages=["llama_cpp", "llama_cpp.server"], - install_requires=["typing-extensions>=4.5.0", "numpy>=1.20.0", "diskcache>=5.6.1"], - extras_require={ - "server": ["uvicorn>=0.21.1", "fastapi>=0.95.0", "sse-starlette>=1.3.3"], - }, - python_requires=">=3.7", - classifiers=[ - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - ], -) From c12138f7bd39fed54d8df14fd2333b2ad8e79971 Mon Sep 17 00:00:00 2001 From: Andrei Betlen Date: Thu, 8 Jun 2023 21:53:38 -0400 Subject: [PATCH 2/6] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9546b1..e875183 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- (build-system) Migrate from scikit-build to scikit-build-core + ## [v0.1.59] ### Added From 43854e6a8336bf055fd74246c2b2baa198c14a92 Mon Sep 17 00:00:00 2001 From: Andrei Betlen Date: Thu, 8 Jun 2023 21:55:42 -0400 Subject: [PATCH 3/6] Update server dependencies --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3017d5c..86f7af6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,9 +37,9 @@ cmake.verbose = true [project.optional-dependencies] server = [ - "uvicorn>=0.21.1", - "fastapi>=0.95.0", - "sse-starlette>=1.3.3", + "uvicorn>=0.22.0", + "fastapi>=0.96.0", + "sse-starlette>=1.6.1", ] test = ["pytest"] From 1d6bdf8db651a0c078321b77d4490191340c9b44 Mon Sep 17 00:00:00 2001 From: Andrei Betlen Date: Thu, 8 Jun 2023 21:59:58 -0400 Subject: [PATCH 4/6] Update server dependencies --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 86f7af6..4fb3c8b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,9 +37,9 @@ cmake.verbose = true [project.optional-dependencies] server = [ - "uvicorn>=0.22.0", - "fastapi>=0.96.0", - "sse-starlette>=1.6.1", + "uvicorn", + "fastapi", + "sse-starlette", ] test = ["pytest"] From 146ca2c59f0ec1ed25626270fe869b4c714ecff6 Mon Sep 17 00:00:00 2001 From: Andrei Betlen Date: Thu, 8 Jun 2023 22:03:24 -0400 Subject: [PATCH 5/6] Add missing httpx --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4fb3c8b..2946143 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ server = [ "fastapi", "sse-starlette", ] -test = ["pytest"] +test = ["pytest", "httpx"] [tool.poetry.dependencies] python = "^3.8.1" From b025a859aea32d2bdf40758f0bc8927f33baae4e Mon Sep 17 00:00:00 2001 From: Andrei Betlen Date: Thu, 8 Jun 2023 22:11:01 -0400 Subject: [PATCH 6/6] Add full path to shared library installation path --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3255053..4760a74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,9 +25,9 @@ else() add_subdirectory(vendor/llama.cpp) install( TARGETS llama - LIBRARY DESTINATION llama_cpp - RUNTIME DESTINATION llama_cpp - ARCHIVE DESTINATION llama_cpp - FRAMEWORK DESTINATION llama_cpp + LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/llama_cpp + RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/llama_cpp + ARCHIVE DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/llama_cpp + FRAMEWORK DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/llama_cpp ) endif()