From 376725ce74d2d75490eed1840b41de00c0e4acd6 Mon Sep 17 00:00:00 2001 From: Woosuk Kwon Date: Mon, 5 Jun 2023 20:03:14 -0700 Subject: [PATCH] [PyPI] Packaging for PyPI distribution (#140) --- .gitignore | 1 + MANIFEST.in | 4 ++ cacheflow/__init__.py | 2 + cacheflow/core/__init__.py | 0 cacheflow/entrypoints/__init__.py | 0 cacheflow/entrypoints/openai/__init__.py | 0 cacheflow/model_executor/layers/__init__.py | 0 cacheflow/server/__init__.py | 0 cacheflow/worker/__init__.py | 0 docs/source/getting_started/installation.rst | 3 +- pyproject.toml | 9 +++ setup.py | 60 ++++++++++++++++++-- 12 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 MANIFEST.in create mode 100644 cacheflow/core/__init__.py create mode 100644 cacheflow/entrypoints/__init__.py create mode 100644 cacheflow/entrypoints/openai/__init__.py create mode 100644 cacheflow/model_executor/layers/__init__.py create mode 100644 cacheflow/server/__init__.py create mode 100644 cacheflow/worker/__init__.py create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore index c5f2bee7d4dd..d9dec081714e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ *.csv build/ docs/build/ +dist/ *.pkl *.png diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 000000000000..0c897cf147f1 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,4 @@ +include LICENSE +include requirements.txt + +recursive-include csrc * diff --git a/cacheflow/__init__.py b/cacheflow/__init__.py index 8220157f3555..cdc0c183d127 100644 --- a/cacheflow/__init__.py +++ b/cacheflow/__init__.py @@ -5,6 +5,8 @@ from cacheflow.server.arg_utils import ServerArgs from cacheflow.server.llm_server import LLMServer from cacheflow.server.ray_utils import initialize_cluster +__version__ = "0.1.0" + __all__ = [ "LLM", "SamplingParams", diff --git a/cacheflow/core/__init__.py b/cacheflow/core/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/cacheflow/entrypoints/__init__.py b/cacheflow/entrypoints/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/cacheflow/entrypoints/openai/__init__.py b/cacheflow/entrypoints/openai/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/cacheflow/model_executor/layers/__init__.py b/cacheflow/model_executor/layers/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/cacheflow/server/__init__.py b/cacheflow/server/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/cacheflow/worker/__init__.py b/cacheflow/worker/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/getting_started/installation.rst b/docs/source/getting_started/installation.rst index ee1215416c2f..326e69605ac2 100644 --- a/docs/source/getting_started/installation.rst +++ b/docs/source/getting_started/installation.rst @@ -32,7 +32,7 @@ You can install CacheFlow using pip: $ conda activate myenv $ # Install CacheFlow. - $ pip install cacheflow + $ pip install cacheflow # This may take 5-10 minutes. .. _build_from_source: @@ -46,5 +46,4 @@ You can also build and install CacheFlow from source. $ git clone https://github.com/WoosukKwon/cacheflow.git $ cd cacheflow - $ pip install -r requirements.txt $ pip install -e . # This may take 5-10 minutes. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000000..264566404f22 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,9 @@ +[build-system] +requires = [ + "ninja", + "packaging", + "setuptools", + "torch >= 2.0.0", + "wheel", +] +build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index 8526782168c6..80134e14c614 100644 --- a/setup.py +++ b/setup.py @@ -1,17 +1,24 @@ +import io +import os +import re import subprocess from typing import List, Set from packaging.version import parse, Version import setuptools import torch -from torch.utils.cpp_extension import BuildExtension, CUDAExtension -from torch.utils.cpp_extension import CUDA_HOME +from torch.utils.cpp_extension import BuildExtension, CUDAExtension, CUDA_HOME + +ROOT_DIR = os.path.dirname(__file__) # Compiler flags. -CXX_FLAGS = ["-g", "-O2"] +CXX_FLAGS = ["-g", "-O2", "-std=c++17"] # TODO(woosuk): Should we use -O3? -NVCC_FLAGS = ["-O2"] +NVCC_FLAGS = ["-O2", "-std=c++17"] +ABI = 1 if torch._C._GLIBCXX_USE_CXX11_ABI else 0 +CXX_FLAGS += [f"-D_GLIBCXX_USE_CXX11_ABI={ABI}"] +NVCC_FLAGS += [f"-D_GLIBCXX_USE_CXX11_ABI={ABI}"] if not torch.cuda.is_available(): raise RuntimeError( @@ -102,15 +109,58 @@ activation_extension = CUDAExtension( ext_modules.append(activation_extension) +def get_path(*filepath) -> str: + return os.path.join(ROOT_DIR, *filepath) + + +def find_version(filepath: str): + """Extract version information from the given filepath. + + Adapted from https://github.com/ray-project/ray/blob/0b190ee1160eeca9796bc091e07eaebf4c85b511/python/setup.py + """ + with open(filepath) as fp: + version_match = re.search( + r"^__version__ = ['\"]([^'\"]*)['\"]", fp.read(), re.M) + if version_match: + return version_match.group(1) + raise RuntimeError("Unable to find version string.") + + +def read_readme() -> str: + """Read the README file.""" + return io.open(get_path("README.md"), "r", encoding="utf-8").read() + + def get_requirements() -> List[str]: """Get Python package dependencies from requirements.txt.""" - with open("requirements.txt") as f: + with open(get_path("requirements.txt")) as f: requirements = f.read().strip().split("\n") return requirements setuptools.setup( name="cacheflow", + version=find_version(get_path("cacheflow", "__init__.py")), + author="CacheFlow Team", + author_email="cacheflow@gmail.com", + license="Apache 2.0", + description="CacheFlow: A high-performance LLM Serving System", + long_description=read_readme(), + long_description_content_type="text/markdown", + url="https://github.com/WoosukKwon/cacheflow", + project_urls={ + "Homepage": "https://github.com/WoosukKwon/cacheflow", + "Documentation": "https://cacheflow.readthedocs.io/en/latest/", + }, + classifiers=[ + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "License :: OSI Approved :: Apache Software License", + "Topic :: Scientific/Engineering :: Artificial Intelligence", + ], + packages=setuptools.find_packages( + exclude=("benchmarks", "csrc", "docs", "examples", "tests")), python_requires=">=3.8", install_requires=get_requirements(), ext_modules=ext_modules,