Skip to content

Commit

Permalink
Prepare for python package release (#42)
Browse files Browse the repository at this point in the history
* Use pyproject.toml for project packaging

* Adjust MANIFEST to reduce sdist size

* Add python release action
  • Loading branch information
li-plus committed Jul 8, 2023
1 parent 7223505 commit f0433b4
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

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.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build --sdist
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
15 changes: 15 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
global-include CMakeLists.txt *.cmake README.md LICENSE
include *.cpp *.h

# ggml
graft third_party/ggml/include
graft third_party/ggml/src

# pybind11
graft third_party/pybind11/include
graft third_party/pybind11/tools

# sentencepiece
graft third_party/sentencepiece/src
graft third_party/sentencepiece/third_party
include third_party/sentencepiece/*
20 changes: 11 additions & 9 deletions examples/cli_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@

def main():
parser = argparse.ArgumentParser()
parser.add_argument("-m", "--model", default=DEFAULT_MODEL_PATH, type=Path)
parser.add_argument("-p", "--prompt", default="你好", type=str)
parser.add_argument("-i", "--interactive", action="store_true")
parser.add_argument("-l", "--max_length", default=2048, type=int)
parser.add_argument("-c", "--max_context_length", default=512, type=int)
parser.add_argument("--top_k", default=0, type=int)
parser.add_argument("--top_p", default=0.7, type=float)
parser.add_argument("--temp", default=0.95, type=float)
parser.add_argument("-t", "--threads", default=0, type=int)
parser.add_argument("-m", "--model", default=DEFAULT_MODEL_PATH, type=Path, help="model path")
parser.add_argument("-p", "--prompt", default="你好", type=str, help="prompt to start generation with")
parser.add_argument("-i", "--interactive", action="store_true", help="run in interactive mode")
parser.add_argument(
"-l", "--max_length", default=2048, type=int, help="max total length including prompt and output"
)
parser.add_argument("-c", "--max_context_length", default=512, type=int, help="max context length")
parser.add_argument("--top_k", default=0, type=int, help="top-k sampling")
parser.add_argument("--top_p", default=0.7, type=float, help="top-p sampling")
parser.add_argument("--temp", default=0.95, type=float, help="temperature")
parser.add_argument("-t", "--threads", default=0, type=int, help="number of threads for inference")
args = parser.parse_args()

pipeline = chatglm_cpp.Pipeline(args.model)
Expand Down
32 changes: 32 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[build-system]
requires = [
"setuptools>=42",
"cmake>=3.12",
]
build-backend = "setuptools.build_meta"

[project]
name = "chatglm-cpp"
authors = [
{name = "Jiahao Li", email = "liplus17@163.com"},
]
maintainers = [
{name = "Jiahao Li", email = "liplus17@163.com"},
]
description = "C++ implementation of ChatGLM-6B & ChatGLM2-6B"
readme = "README.md"
requires-python = ">=3.7"
keywords = ["ChatGLM", "ChatGLM2", "Large Language Model"]
license = {text = "MIT License"}
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
]
dynamic = ["version"]

[project.urls]
Homepage = "https://github.com/li-plus/chatglm.cpp"
Repository = "https://github.com/li-plus/chatglm.cpp.git"
24 changes: 4 additions & 20 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def build_extension(self, ext: CMakeExtension) -> None:
f"-DCHATGLM_ENABLE_PYBIND=ON",
]

if "CMAKE_ARGS" in os.environ:
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]

build_temp = Path(self.build_temp) / ext.name
build_temp.mkdir(parents=True, exist_ok=True)

Expand All @@ -38,30 +41,11 @@ def build_extension(self, ext: CMakeExtension) -> None:


HERE = Path(__file__).resolve().parent
version = re.search(r'__version__ = "(.*?)"', (HERE / "chatglm_cpp/__init__.py").read_text()).group(1)
version = re.search(r'__version__ = "(.*?)"', (HERE / "chatglm_cpp/__init__.py").read_text(encoding="utf-8")).group(1)

setup(
name="chatglm-cpp",
version=version,
author="Jiahao Li",
author_email="liplus17@163.com",
maintainer="Jiahao Li",
maintainer_email="liplus17@163.com",
url="https://github.com/li-plus/chatglm.cpp",
description="C++ implementation of ChatGLM-6B",
long_description=(HERE / "README.md").read_text(),
long_description_content_type="text/markdown",
packages=find_packages(),
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
],
keywords=["chatglm", "large language model"],
license="MIT",
python_requires=">=3.7",
ext_modules=[CMakeExtension("chatglm_cpp._C")],
cmdclass={"build_ext": CMakeBuild},
)

0 comments on commit f0433b4

Please sign in to comment.